int main(int argc, char*argv[]) { _cleanup_bus_unref_ sd_bus *bus = NULL; int r; setlocale(LC_ALL, ""); log_parse_environment(); log_open(); r = parse_argv(argc, argv); if (r <= 0) goto finish; r = bus_open_transport(arg_transport, arg_host, false, &bus); if (r < 0) { log_error("Failed to create bus connection: %s", strerror(-r)); goto finish; } r = localectl_main(bus, argc, argv); finish: pager_close(); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
void init_chibach( int *argc, char ***argv ) { assert( argc != NULL ); assert( argv != NULL ); chibach_log = NULL; initialized = false; chibach_started = false; run_as_daemon = false; chibach_name = xstrdup( basename( *argv[ 0 ] ) ); parse_argv( argc, argv ); set_chibach_home(); set_chibach_tmp(); check_chibach_tmp(); if ( run_as_daemon ) { init_log( get_chibach_name(), get_chibach_log(), LOGGING_TYPE_FILE ); } else { init_log( get_chibach_name(), get_chibach_log(), LOGGING_TYPE_FILE | LOGGING_TYPE_STDOUT ); } ignore_sigpipe(); set_exit_handler(); set_usr1_handler(); init_stat(); init_timer(); init_messenger( get_chibach_tmp() ); if ( datapath_id != 0 ) { init_openflow_switch_interface( datapath_id, controller.ip, controller.port ); } initialized = true; }
int main(int argc, char*argv[]) { sd_bus *bus = NULL; int r; setlocale(LC_ALL, ""); log_parse_environment(); log_open(); r = parse_argv(argc, argv); if (r <= 0) goto finish; r = bus_connect_transport(arg_transport, arg_host, false, &bus); if (r < 0) { log_error_errno(r, "Failed to create bus connection: %m"); goto finish; } r = localectl_main(bus, argc, argv); finish: /* make sure we terminate the bus connection first, and then close the * pager, see issue #3543 for the details. */ sd_bus_flush_close_unref(bus); pager_close(); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
static int run(int argc, char *argv[]) { _cleanup_close_ int fd = -1, saved_stderr = -1; int r; log_parse_environment(); log_open(); r = parse_argv(argc, argv); if (r <= 0) return r; fd = sd_journal_stream_fd(arg_identifier, arg_priority, arg_level_prefix); if (fd < 0) return log_error_errno(fd, "Failed to create stream fd: %m"); saved_stderr = fcntl(STDERR_FILENO, F_DUPFD_CLOEXEC, 3); r = rearrange_stdio(STDIN_FILENO, fd, fd); /* Invalidates fd on succcess + error! */ TAKE_FD(fd); if (r < 0) return log_error_errno(r, "Failed to rearrange stdout/stderr: %m"); if (argc <= optind) (void) execl("/bin/cat", "/bin/cat", NULL); else (void) execvp(argv[optind], argv + optind); r = -errno; /* Let's try to restore a working stderr, so we can print the error message */ if (saved_stderr >= 0) (void) dup3(saved_stderr, STDERR_FILENO, 0); return log_error_errno(r, "Failed to execute process: %m"); }
int main(int argc, char* argv[]) { parse_argv(argc, argv); printf("listen address: %s:%d\n", inet_ntoa(server_address.sin_addr), ntohs(server_address.sin_port)); printf("broadcast address %s:%d\n", inet_ntoa(bcast_address.sin_addr), ntohs(bcast_address.sin_port)); printf("tftp address: %s\n", inet_ntoa(tftp_ip)); printf("nbp name: %s\n", nbp_name); /* install signal handler */ if (install_signal_handler() == -1) { perror("sigaction() failed"); exit(-1); } /* init sockets */ if (init_socket() == -1) { perror("init_socket()"); release_all(); exit(1); } if (foreground) { pdhcp(); } else { daemon(0,0); pdhcp(); } return 0; }
void parse_config(char *configfile,struct mfshell_user_options *opts) { FILE *fp; char **argv = NULL; // create our own argv int argc; // create one own argc int new_items = 0; fp = fopen(configfile,"r"); if(fp == NULL) return; // getopt_long() expect at least argc >= 1 and argv[0] != NULL argv = (char**)calloc(1,sizeof(char*)); argv[0] = strdup("mediafire-shell"); argc = 1; new_items = config_file_read(fp, &argc, &argv); fprintf(stderr,"argc = %d\n", argc); parse_argv(argc, argv, opts); if(new_items > 0) { string_array_free(argv); } else { free(argv[0]); free(argv); } return; }
int main(int argc, char *argv[]) { _cleanup_strv_free_erase_ char **l = NULL; usec_t timeout; char **p; int r; log_parse_environment(); log_open(); r = parse_argv(argc, argv); if (r <= 0) goto finish; if (arg_timeout > 0) timeout = now(CLOCK_MONOTONIC) + arg_timeout; else timeout = 0; r = ask_password_auto(arg_message, arg_icon, arg_id, arg_keyname, timeout, arg_flags, &l); if (r < 0) { log_error_errno(r, "Failed to query password: %m"); goto finish; } STRV_FOREACH(p, l) { puts(*p); if (!arg_multiple) break; }
int main(int argc, char *argv[]) { bool enabled; int r; r = parse_argv(argc, argv); if (r <= 0) goto finish; log_set_target(LOG_TARGET_AUTO); log_parse_environment(); log_open(); umask(0022); r = proc_cmdline_get_bool("systemd.firstboot", &enabled); if (r < 0) { log_error_errno(r, "Failed to parse systemd.firstboot= kernel command line argument, ignoring: %m"); goto finish; } if (r > 0 && !enabled) { r = 0; /* disabled */ goto finish; } r = process_locale(); if (r < 0) goto finish; r = process_keymap(); if (r < 0) goto finish; r = process_timezone(); if (r < 0) goto finish; r = process_hostname(); if (r < 0) goto finish; r = process_machine_id(); if (r < 0) goto finish; r = process_root_password(); if (r < 0) goto finish; finish: free(arg_root); free(arg_locale); free(arg_locale_messages); free(arg_keymap); free(arg_timezone); free(arg_hostname); string_erase(arg_root_password); free(arg_root_password); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
int builtin_main(int argc, char *argv[], void *userdata) { _cleanup_(sd_device_unrefp) sd_device *dev = NULL; enum udev_builtin_cmd cmd; int r; log_set_max_level(LOG_DEBUG); r = parse_argv(argc, argv); if (r <= 0) return r; udev_builtin_init(); cmd = udev_builtin_lookup(arg_command); if (cmd < 0) { log_error("Unknown command '%s'", arg_command); r = -EINVAL; goto finish; } r = find_device(arg_syspath, "/sys", &dev); if (r < 0) { log_error_errno(r, "Failed to open device '%s': %m", arg_syspath); goto finish; } r = udev_builtin_run(dev, cmd, arg_command, true); if (r < 0) log_debug_errno(r, "Builtin command '%s' fails: %m", arg_command); finish: udev_builtin_exit(); return r; }
int main(int argc, char *argv[]) { _cleanup_(evcat_freep) Evcat *e = NULL; int r; log_set_target(LOG_TARGET_AUTO); log_parse_environment(); log_open(); setlocale(LC_ALL, ""); if (!is_locale_utf8()) log_warning("Locale is not set to UTF-8. Codepoints will not be printed!"); r = parse_argv(argc, argv); if (r <= 0) goto finish; r = evcat_new(&e); if (r < 0) goto finish; r = evcat_run(e); finish: return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
int main(int argc, char *argv[]) { sd_bus *bus = NULL; int r; setlocale(LC_ALL, ""); log_parse_environment(); log_open(); r = parse_argv(argc, argv); if (r <= 0) goto finish; r = bus_connect_transport(arg_transport, arg_host, false, &bus); if (r < 0) { log_error_errno(r, "Failed to create bus connection: %m"); goto finish; } r = timedatectl_main(bus, argc, argv); finish: sd_bus_flush_close_unref(bus); pager_close(); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
int main(int argc, char *argv[]) { _cleanup_(proxy_freep) Proxy *p = NULL; int r; log_set_target(LOG_TARGET_JOURNAL_OR_KMSG); log_parse_environment(); log_open(); r = parse_argv(argc, argv); if (r <= 0) goto finish; r = proxy_new(&p, STDIN_FILENO, STDOUT_FILENO, arg_address); if (r < 0) goto finish; r = rename_service(p->destination_bus, p->local_bus); if (r < 0) log_debug_errno(r, "Failed to rename process: %m"); r = proxy_run(p); finish: sd_notify(false, "STOPPING=1\n" "STATUS=Shutting down."); free(arg_address); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
int main(int argc, char *argv[]) { int r, k; struct kmod_ctx *ctx; r = parse_argv(argc, argv); if (r <= 0) return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; log_set_target(LOG_TARGET_AUTO); log_parse_environment(); log_open(); umask(0022); if (parse_proc_cmdline(parse_proc_cmdline_item) < 0) return EXIT_FAILURE; ctx = kmod_new(NULL, NULL); if (!ctx) { log_error("Failed to allocate memory for kmod."); goto finish; } kmod_load_resources(ctx); kmod_set_log_fn(ctx, systemd_kmod_log, NULL); r = 0; if (argc > optind) { int i; for (i = optind; i < argc; i++) { k = apply_file(ctx, argv[i], false); if (k < 0 && r == 0) r = k; } } else { _cleanup_free_ char **files = NULL; char **fn, **i; STRV_FOREACH(i, arg_proc_cmdline_modules) { k = load_module(ctx, *i); if (k < 0 && r == 0) r = k; } k = conf_files_list_nulstr(&files, ".conf", NULL, conf_file_dirs); if (k < 0) { log_error("Failed to enumerate modules-load.d files: %s", strerror(-k)); if (r == 0) r = k; goto finish; } STRV_FOREACH(fn, files) { k = apply_file(ctx, *fn, true); if (k < 0 && r == 0) r = k; }
int main(int argc, char **argv) { struct manager *m = NULL; int r; srand(time(NULL)); r = parse_argv(argc, argv); if (r < 0) return EXIT_FAILURE; if (!r) return EXIT_SUCCESS; r = manager_new(&m); if (r < 0) goto finish; r = sd_notify(false, "READY=1\n" "STATUS=Running.."); if (r < 0) { log_vERR(r); goto finish; } r = manager_run(m); finish: sd_notify(false, "STATUS=Exiting.."); manager_free(m); log_debug("exiting.."); return abs(r); }
void parse_argv_for_restore(int argc, char * argv[], opts_restore_t * opts) { parse_argv(argc, argv, &(opts->base)); int c; opterr = 0; optind = 1; while ((c = getopt(argc, argv, "fri")) != -1) { switch (c) { case 'f': opts->strategy = STRATEGY_FLUSH; return; case 'r': opts->strategy = STRATEGY_REPLACE; return; case 'i': opts->strategy = STRATEGY_IGNORE; return; default: break; } } }
int main(int argc, char* argv[]) { int r; log_parse_environment(); log_open(); r = parse_argv(argc, argv); if (r <= 0) goto finish; if (argc > optind) { int i, q; for (i = optind; i < argc; i++) { q = print_home(argv[i]); if (q < 0) r = q; } } else r = list_homes(); finish: return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
int main(int argc, char *argv[]) { mmatic *mm; struct flowcalc *fc; void *h; struct module *mod; char *name, *s; tlist *ls; void *pdata; /* * initialization */ mm = mmatic_create(); fc = mmatic_zalloc(mm, sizeof *fc); fc->mm = mm; fc->modules = tlist_create(NULL, mm); /* read options */ if (parse_argv(fc, argc, argv)) return 1; /* enable all modules found in given directory */ if (tlist_count(fc->modules) == 0) { ls = pjf_ls(fc->dir, mm); tlist_iter_loop(ls, name) { s = strrchr(name, '.'); if (s && streq(s, ".so")) { *s = 0; tlist_push(fc->modules, name); } }
int main(int argc, char **argv) { int ret; parse_argv(argc, argv); /* seed random number generator */ srandom(time(NULL)); worker_init(); printf("testing single-proposer case...\n"); ret = run_paxos(0); if (ret) { fprintf(stderr, "run_paxos(0) failed with error code %d\n", ret); return EXIT_FAILURE; } printf("testing multi-proposer case...\n"); ret = run_paxos(1); if (ret) { fprintf(stderr, "run_paxos(1) failed with error code %d\n", ret); return EXIT_FAILURE; } return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { Context context = {}; int r, n, fd; log_parse_environment(); log_open(); r = parse_argv(argc, argv); if (r <= 0) goto finish; r = sd_event_default(&context.event); if (r < 0) { log_error_errno(r, "Failed to allocate event loop: %m"); goto finish; } r = sd_resolve_default(&context.resolve); if (r < 0) { log_error_errno(r, "Failed to allocate resolver: %m"); goto finish; } r = sd_resolve_attach_event(context.resolve, context.event, 0); if (r < 0) { log_error_errno(r, "Failed to attach resolver: %m"); goto finish; } sd_event_set_watchdog(context.event, true); n = sd_listen_fds(1); if (n < 0) { log_error("Failed to receive sockets from parent."); r = n; goto finish; } else if (n == 0) { log_error("Didn't get any sockets passed in."); r = -EINVAL; goto finish; } for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd++) { r = add_listen_socket(&context, fd); if (r < 0) goto finish; } r = sd_event_loop(context.event); if (r < 0) { log_error_errno(r, "Failed to run event loop: %m"); goto finish; } finish: context_free(&context); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
int main(int argc, char *argv[]) { const char *id = NULL; int retval = EXIT_SUCCESS; int r; /* This is mostly intended to be used for scripts which want * to detect whether we are being run in a virtualized * environment or not */ log_parse_environment(); log_open(); r = parse_argv(argc, argv); if (r <= 0) return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; switch (arg_mode) { case ANY_VIRTUALIZATION: { int v; v = detect_virtualization(&id); if (v < 0) { log_error("Failed to check for virtualization: %s", strerror(-v)); return EXIT_FAILURE; } retval = v != VIRTUALIZATION_NONE ? EXIT_SUCCESS : EXIT_FAILURE; break; } case ONLY_CONTAINER: r = detect_container(&id); if (r < 0) { log_error("Failed to check for container: %s", strerror(-r)); return EXIT_FAILURE; } retval = r > 0 ? EXIT_SUCCESS : EXIT_FAILURE; break; case ONLY_VM: r = detect_vm(&id); if (r < 0) { log_error("Failed to check for vm: %s", strerror(-r)); return EXIT_FAILURE; } retval = r > 0 ? EXIT_SUCCESS : EXIT_FAILURE; break; } if (!arg_quiet) puts(id ? id : "none"); return retval; }
int main(int argc, char *argv[]) { int r, accept_fd; uid_t uid, bus_uid; gid_t gid; log_set_target(LOG_TARGET_JOURNAL_OR_KMSG); log_parse_environment(); log_open(); bus_uid = getuid(); if (geteuid() == 0) { const char *user = "******"; r = get_user_creds(&user, &uid, &gid, NULL, NULL); if (r < 0) { log_error_errno(r, "Cannot resolve user name %s: %m", user); goto finish; } r = drop_privileges(uid, gid, 1ULL << CAP_IPC_OWNER); if (r < 0) { log_error_errno(r, "Cannot drop privileges: %m"); goto finish; } } r = parse_argv(argc, argv); if (r <= 0) goto finish; r = sd_listen_fds(0); if (r != 1) { log_error("Illegal number of file descriptors passed"); goto finish; } accept_fd = SD_LISTEN_FDS_START; r = fd_nonblock(accept_fd, false); if (r < 0) { log_error_errno(r, "Cannot mark accept-fd non-blocking: %m"); goto finish; } r = loop_clients(accept_fd, bus_uid); finish: sd_notify(false, "STOPPING=1\n" "STATUS=Shutting down."); strv_free(arg_configuration); free(arg_address); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
/* fullpath is full binary path for exec filename is argv[0] */ void do_fuzz (char *fullpath, char *filename, int fuzztype, int argc, char **argv) { static struct getopt_args getopt_args; static struct argv_args argv_args; static struct singleoption_args singleoption_args; switch (fuzztype) { case FUZZTYPE_ARGV0: printf ("Doing argv[0] fuzz\n"); if (!argv_args.initialized) /* uninitialized */ parse_argv (argc, argv, &argv_args); fuzzmethod_argvzero (fullpath, &argv_args); break; case FUZZTYPE_ARGV1: printf ("Doing argv[1] fuzz\n"); if (!argv_args.initialized) /* uninitialized */ parse_argv (argc, argv, &argv_args); fuzzmethod_argvone (fullpath, &argv_args); break; case FUZZTYPE_SINGLE: printf ("Doing unintelligent singleoption fuzz\n"); parse_singleoption(argc,argv,&singleoption_args); fuzzmethod_singleoption (fullpath,&singleoption_args); break; case FUZZTYPE_GETOPT: if (!getopt_args.optstring) /* uninitialized */ parse_getopt3 (argc, argv, &getopt_args); if (!getopt_args.optstring) { fuzzmethod_getopt3_usage (); } printf ("Doing getopt optstring fuzz [%s]\n", getopt_args.optstring); fuzzmethod_getopt3 (fullpath, &getopt_args); break; default: printf ("Fuzz type not implemented yet\n"); break; } return; }
int main(int argc, char *argv[]){ int t_wait; install_signal_handler(); /* Instala el manejador de CTRL + C */ parse_argv(argc,argv,&t_wait); /* Controla la linea de argumentos */ run(t_wait); /* Ejecuta el programa */ return EXIT_SUCCESS; }
int main (int argc, char *argv[]) { char *filename = NULL; install_signal_handler(); parse_argv(argc, argv, &filename); run(filename); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { _cleanup_(manager_freep) Manager *m = NULL; int r; log_set_target(LOG_TARGET_AUTO); log_parse_environment(); log_open(); umask(0022); r = parse_argv(argc, argv); if (r <= 0) return r; if (arg_quiet) log_set_max_level(LOG_WARNING); assert_se(sigprocmask_many(SIG_BLOCK, SIGTERM, SIGINT, -1) == 0); r = manager_new(&m, arg_interfaces, arg_ignore, arg_timeout); if (r < 0) { log_error_errno(r, "Could not create manager: %m"); goto finish; } if (manager_all_configured(m)) { r = 0; goto finish; } sd_notify(false, "READY=1\n" "STATUS=Waiting for network connections..."); r = sd_event_loop(m->event); if (r < 0) { log_error_errno(r, "Event loop failed: %m"); goto finish; } finish: strv_free(arg_interfaces); strv_free(arg_ignore); if (r >= 0) { sd_notify(false, "STATUS=All interfaces configured..."); return EXIT_SUCCESS; } else { sd_notify(false, "STATUS=Failed waiting for network connectivity..."); return EXIT_FAILURE; } }
int main (int argc, char *argv[]) { char *line = NULL, *pattern = NULL; int line_number; install_signal_handler(); parse_argv(argc, argv, &line, &line_number, &pattern); run(line, line_number, pattern); return EXIT_SUCCESS; }
bool run( const std::string & executable_name, int argc, char ** argv, const factory::Factory & factory){ if (argc < 2){ factory.usage(cerr, executable_name); return false; } std::string mode_name = argv[1]; if (mode_name == "help" || mode_name == "-h"){ if (argc > 2){ cerr << "ERROR: Mode \"help\" does not take command line options.\n"; factory.usage(cerr, executable_name); return false; } factory.usage(cout, executable_name); return true; } --argc, ++argv; const mode::BasicMode * mode = factory.mode(mode_name); if (!mode){ cerr << "ERROR: Unknown mode: " << mode_name << '\n'; factory.usage(cerr, executable_name); return false; } bool ret = false; auto_ptr<optentries::BasicOptentries> optentries = mode->optentries(); switch (parse_argv(argc, argv, *optentries)){ case 0: ret = mode->handle(*optentries); break; case 1: mode->usage(cerr, executable_name, *optentries); ret = false; break; case 2: ret = false; break; case 3: mode->usage(cout, executable_name, *optentries); ret = true; break; default: assert(false); ret = false; break; } return ret; }
static int run(int argc, char *argv[]) { int r; log_parse_environment(); log_open(); r = parse_argv(argc, argv); if (r <= 0) return r; return id128_main(argc, argv); }
int main(int argc, char *argv[]) { int r, fd = -1, saved_stderr = -1; log_parse_environment(); log_open(); r = parse_argv(argc, argv); if (r <= 0) goto finish; fd = sd_journal_stream_fd(arg_identifier, arg_priority, arg_level_prefix); if (fd < 0) { log_error("Failed to create stream fd: %s", strerror(-fd)); r = fd; goto finish; } saved_stderr = fcntl(STDERR_FILENO, F_DUPFD_CLOEXEC, 3); if (dup3(fd, STDOUT_FILENO, 0) < 0 || dup3(fd, STDERR_FILENO, 0) < 0) { log_error("Failed to duplicate fd: %m"); r = -errno; goto finish; } if (fd >= 3) close_nointr_nofail(fd); fd = -1; if (argc <= optind) execl("/bin/cat", "/bin/cat", NULL); else execvp(argv[optind], argv + optind); r = -errno; /* Let's try to restore a working stderr, so we can print the error message */ if (saved_stderr >= 0) dup3(saved_stderr, STDERR_FILENO, 0); log_error("Failed to execute process: %s", strerror(-r)); finish: if (fd >= 0) close_nointr_nofail(fd); if (saved_stderr >= 0) close_nointr_nofail(saved_stderr); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
int main(int argc, char *argv[]) { int r; log_parse_environment(); log_open(); r = parse_argv(argc, argv); if (r <= 0) return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; return machine_id_setup() < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }