本文整理汇总了C++中parse_argv函数的典型用法代码示例。如果您正苦于以下问题:C++ parse_argv函数的具体用法?C++ parse_argv怎么用?C++ parse_argv使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_argv函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
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;
}
示例2: init_chibach
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;
}
示例3: main
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;
}
示例4: run
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");
}
示例5: main
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;
}
示例6: parse_config
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;
}
示例7: main
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;
}
示例8: main
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;
}
示例9: builtin_main
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;
}
示例10: main
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;
}
示例11: main
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;
}
示例12: main
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;
}
示例13: main
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;
}
示例14: main
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);
}
示例15: parse_argv_for_restore
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;
}
}
}