Пример #1
0
static int
read_version_entry(char *page, char **start, off_t off, int count, int *eof,
		   void *data)
{
	int len = 0;

	/* data holds the NASID of the node */
	len = dump_version(page, (unsigned long)data);
	len = proc_calc_metrics(page, start, off, count, eof, len);
	return len;
}
Пример #2
0
static int
ifuse_process_opt(void *data, const char *arg, int key,
    unused struct fuse_args *args)
{
	struct fuse_core_opt *opt = data;
	struct stat st;
	int res;

	switch (key) {
		case KEY_DEBUG:
			return (0);
		case KEY_HELP:
		case KEY_HELP_WITHOUT_HEADER:
			dump_help();
			return (0);
		case KEY_VERSION:
			dump_version();
			return (1);
		case FUSE_OPT_KEY_NONOPT:
			if (opt->mp == NULL) {
				opt->mp = realpath(arg, opt->mp);
				if (opt->mp == NULL) {
					fprintf(stderr, "fuse: realpath: "
					    "%s : %s\n", arg, strerror(errno));
					return (-1);
				}

				res = stat(opt->mp, &st);
				if (res == -1) {
					fprintf(stderr, "fuse: bad mount point "
					    "%s : %s\n", arg, strerror(errno));
					return (-1);
				}

				if (!S_ISDIR(st.st_mode)) {
					fprintf(stderr, "fuse: bad mount point "
					    "%s : %s\n", arg,
					    strerror(ENOTDIR));
					return (-1);
				}
			} else {
				fprintf(stderr, "fuse: invalid argument %s\n",
				    arg);
				return (-1);
			}
			break;
		default:
			fprintf(stderr, "fuse: unknown option %s\n", arg);
			return (-1);
	}
	return (0);
}
static int
read_version_entry(char *page, char **start, off_t off, int count, int *eof,
		   void *data)
{
	int len = 0;

	MOD_INC_USE_COUNT;
	/* data holds the pointer to this node's FIT */
	len = dump_version(page, (unsigned long *)data);
	len = proc_calc_metrics(page, start, off, count, eof, len);
	MOD_DEC_USE_COUNT;
	return len;
}
Пример #4
0
int main(int argc, char* argv[])
{
  if (argc!=2) {
    show_usage();
    return 0;
  }

  //while(true) {
  MAPPED_FILE view = {0};
  if( 0 != map_file( argv[1], &view ) ) {
    printf( "open file failed: %s\n", argv[2]);
    return -1;
  }

  int pe = pe_open((const char*)view.data, view.size);
  if (pe == INVALID_PE) {
    printf( "file is not pe format");
    return -1;
  }

  dump_entry(pe);
  dump_version(pe);
  dump_section(pe);
  dump_export(pe);
  dump_import(pe);
  dump_overlay(pe);
  dump_resource(pe);

  char path[256] = {0};
  strcat(getcwd(path, sizeof(path) - 1), "\\sample.ico");
  dump_icon(pe, path);

  pe_close(pe);

  unmap_file(&view);
  //}
 
  system("pause");
  return 0;
}
Пример #5
0
int
main(int argc, char **argv)
{
	int port = 0;
	char *user = NULL;
	char *passwd = NULL;
	char *host = NULL;
	char *dbname = NULL;
	int trace = 0;
	int describe = 0;
	int functions = 0;
	int useinserts = 0;
	int c;
	Mapi mid;
	int quiet = 0;
	stream *out;
	char user_set_as_flag = 0;
	char *table = NULL;
	static struct option long_options[] = {
		{"host", 1, 0, 'h'},
		{"port", 1, 0, 'p'},
		{"database", 1, 0, 'd'},
		{"describe", 0, 0, 'D'},
		{"functions", 0, 0, 'f'},
		{"table", 1, 0, 't'},
		{"inserts", 0, 0, 'N'},
		{"Xdebug", 0, 0, 'X'},
		{"user", 1, 0, 'u'},
		{"quiet", 0, 0, 'q'},
		{"help", 0, 0, '?'},
		{0, 0, 0, 0}
	};

	parse_dotmonetdb(&user, &passwd, NULL, NULL, NULL, NULL);

	while ((c = getopt_long(argc, argv, "h:p:d:Dft:NXu:q?", long_options, NULL)) != -1) {
		switch (c) {
		case 'u':
			if (user)
				free(user);
			user = strdup(optarg);
			user_set_as_flag = 1;
			break;
		case 'h':
			host = optarg;
			break;
		case 'p':
			assert(optarg != NULL);
			port = atoi(optarg);
			break;
		case 'd':
			dbname = optarg;
			break;
		case 'D':
			describe = 1;
			break;
		case 'N':
			useinserts = 1;
			break;
		case 'f':
			if (table)
				usage(argv[0], -1);
			functions = 1;
			break;
		case 't':
			if (table || functions)
				usage(argv[0], -1);
			table = optarg;
			break;
		case 'q':
			quiet = 1;
			break;
		case 'X':
			trace = MAPI_TRACE;
			break;
		case '?':
			/* a bit of a hack: look at the option that the
			   current `c' is based on and see if we recognize
			   it: if -? or --help, exit with 0, else with -1 */
			usage(argv[0], strcmp(argv[optind - 1], "-?") == 0 || strcmp(argv[optind - 1], "--help") == 0 ? 0 : -1);
		default:
			usage(argv[0], -1);
		}
	}

	if (optind == argc - 1)
		dbname = argv[optind];
	else if (optind != argc)
		usage(argv[0], -1);

	/* when config file would provide defaults */
	if (user_set_as_flag)
		passwd = NULL;

	if (user == NULL)
		user = simple_prompt("user", BUFSIZ, 1, prompt_getlogin());
	if (passwd == NULL)
		passwd = simple_prompt("password", BUFSIZ, 0, NULL);

	mid = mapi_connect(host, port, user, passwd, "sql", dbname);
	if (user)
		free(user);
	if (passwd)
		free(passwd);
	if (mid == NULL) {
		fprintf(stderr, "failed to allocate Mapi structure\n");
		exit(2);
	}
	if (mapi_error(mid)) {
		mapi_explain(mid, stderr);
		exit(2);
	}
	if (!quiet) {
		char *motd = mapi_get_motd(mid);

		if (motd)
			fprintf(stderr, "%s", motd);
	}
	mapi_trace(mid, trace);
	mapi_cache_limit(mid, 10000);

	out = file_wastream(stdout, "stdout");
	if (out == NULL) {
		fprintf(stderr, "failed to allocate stream\n");
		exit(2);
	}
	if (!quiet) {
		char buf[27];
		time_t t = time(0);
		char *p;

#ifdef HAVE_CTIME_R3
		ctime_r(&t, buf, sizeof(buf));
#else
#ifdef HAVE_CTIME_R
		ctime_r(&t, buf);
#else
		strncpy(buf, ctime(&t), sizeof(buf));
#endif
#endif
		if ((p = strrchr(buf, '\n')) != NULL)
			*p = 0;
		mnstr_printf(out, "-- msqldump %s %s%s %s\n",
			     describe ? "describe" : "dump",
			     functions ? "functions" : table ? "table " : "database",
			     table ? table : "", buf);
		dump_version(mid, out, "--");
	}
	if (functions)
		c = dump_functions(mid, out, NULL, NULL);
	else if (table)
		c = dump_table(mid, NULL, table, out, describe, 1, useinserts);
	else
		c = dump_database(mid, out, describe, useinserts);
	mnstr_flush(out);

	mapi_destroy(mid);
	if (mnstr_errnr(out)) {
		fprintf(stderr, "%s: %s", argv[0], mnstr_error(out));
		return 1;
	}

	mnstr_destroy(out);
	return c;
}
Пример #6
0
int dump_help(FILE *stream) {
    dump_version(stream);
    dump_usage(stream);

    return 0;
}
Пример #7
0
/*
 * Pick out command-line options and set up appres.
 */
static void
parse_options(int *argcp, const char **argv)
{
	int i, j;
	int argc_out = 0;
	const char **argv_out =
	    (const char **) Malloc((*argcp + 1) * sizeof(char *));

	/* Parse the command-line options. */
	argv_out[argc_out++] = argv[0];

	for (i = 1; i < *argcp; i++) {
		for (j = 0; opts[j].name != CN; j++) {
			if (!strcmp(argv[i], opts[j].name))
				break;
		}
		if (opts[j].name == CN) {
			argv_out[argc_out++] = argv[i];
			continue;
		}

		switch (opts[j].type) {
		    case OPT_BOOLEAN:
			*(Boolean *)opts[j].aoff = opts[j].flag;
			if (opts[j].res_name != CN)
				add_resource(NewString(opts[j].name),
					     opts[j].flag? "True": "False");
			break;
		    case OPT_STRING:
			if (i == *argcp - 1) {	/* missing arg */
				popup_an_error("Missing value for '%s'",
					argv[i]);
				continue;
			}
			*(const char **)opts[j].aoff = argv[++i];
			if (opts[j].res_name != CN)
				add_resource(NewString(opts[j].res_name),
					     NewString(argv[i]));
			break;
		    case OPT_XRM:
			if (i == *argcp - 1) {	/* missing arg */
				popup_an_error("Missing value for '%s'",
					argv[i]);
				continue;
			}
			parse_xrm(argv[++i], "-xrm");
			break;
		    case OPT_SKIP2:
			argv_out[argc_out++] = argv[i++];
			if (i < *argcp)
				argv_out[argc_out++] = argv[i];
			break;
		    case OPT_NOP:
			break;
		    case OPT_INT:
			if (i == *argcp - 1) {	/* missing arg */
				popup_an_error("Missing value for '%s'",
					argv[i]);
				continue;
			}
			*(int *)opts[j].aoff = atoi(argv[++i]);
			if (opts[j].res_name != CN)
				add_resource(NewString(opts[j].name),
					     NewString(argv[i]));
			break;
		    case OPT_V:
			dump_version();
			break;
		    case OPT_DONE:
			while (i < *argcp)
				argv_out[argc_out++] = argv[i++];
			break;
		}
	}
	*argcp = argc_out;
	argv_out[argc_out] = CN;
	(void) memcpy((char *)argv, (char *)argv_out,
	    (argc_out + 1) * sizeof(char *));
	Free((char *)argv_out);
}
Пример #8
0
int
main(int argc, char *argv[]) {
    struct sigaction sa;
    char c;
    int option_index = 0;
    
    // Program name
    program_name = strrchr(argv[0], '/');
    if (program_name)
        program_name ++;
    else
        program_name = argv[0];
        
    // Parse command line options
    do {
        c = getopt_long(argc, argv, short_options, long_options, &option_index);

        switch (c) {

        case -1:
            break;
            
        case 'r':
            capture_file = fopen(optarg, "r");
            if (!capture_file) {
                LOGGER(ERROR, "Cannot open file '%s': %s\n", optarg,
                        strerror(errno));
                return EXIT_FAILURE;
                
            }
            break;
            
        case 'l':
            specified_addresses = 1;
            if (parse_addresses(optarg)) {
                LOGGER(ERROR, "Error parsing local addresses\n");
                return EXIT_FAILURE;
                
            }
            
            break;
            
        case 'p':
            port = strdup(optarg);
            break;
            
        case 'f':
            if (!check_format(optarg)) {
                LOGGER(ERROR, "Bad format provided: `%s'\n", optarg);
                return EXIT_FAILURE;
            }
            
            global_options.format = optarg;
            
            break;
            
        case 't':
            global_options.interval = strtoul(optarg, NULL, 10);
            if (interval <= 0 || interval >= MAX_OUTPUT_INTERVAL) {
                LOGGER(ERROR, "Bad interval provided\n");
                return EXIT_FAILURE;
            }
            
            break;
            
        case 'n':
            global_options.iterations = strtol(optarg, NULL, 10);
            if (interval < 0) {
                LOGGER(ERROR, "Bad iterations provided\n");
                return EXIT_FAILURE;
            }
            
            break;
            
        case 'T':
            global_options.threshold = strtol(optarg, NULL, 10) * 1000;
            if (global_options.threshold < 0) {
                LOGGER(ERROR, "Bad threshold provided\n");
                return EXIT_FAILURE;
            }
            
            break;

        case 'd':
            global_options.server = strdup(optarg);
            
            break;
        case 'i':
	        global_options.interface = strdup(optarg);

            break;


        case 'c':
            global_options.is_client = 1;
            break;

        case 's':
            global_options.header = optarg;
            global_options.show_header = 1;
            break;
            
        case 'S':
            global_options.show_header = 0;
            break;
            
        case 'h':
            dump_help(stdout);
            return EXIT_SUCCESS;

        case 'V':
            dump_version(stdout);
            return EXIT_SUCCESS;

        default:
            dump_usage(stderr);
            return EXIT_FAILURE;

        }

    }
    while (c != -1);
    
	if(! global_options.interface) {
        global_options.interface = "any";
	}

    if(global_options.is_client) {
        if(!global_options.server) {
            LOGGER(ERROR, "%s -d destination server is required.\n", argv[0]);
            return 0;
        }
    }
	if(global_options.server) {
		global_options.is_client = 1;
	} 
    if(!port) {
    	LOGGER(ERROR, "%s -p port is required.\n", argv[0]);
        return 0;
   	}

    // Set up signals
    sa.sa_handler = terminate;
    sigemptyset(&sa.sa_mask);
    sigaddset(&sa.sa_mask, SIGTERM);
    sigaddset(&sa.sa_mask, SIGINT);
    sa.sa_flags = 0;
    sa.sa_restorer = NULL;
    
    sigaction(SIGTERM, &sa, NULL);
    sigaction(SIGINT, &sa, NULL);
    
    // Get local addresses
    if (!specified_addresses && get_addresses() != 0)
        return EXIT_FAILURE;
    
    // Operations timestamp
    time(&timestamp);
    
    // Stats
    init_stats();
    
    if (capture_file) {
        output_offline_start(&global_options);

        offline_capture(capture_file);
        
        fclose(capture_file);
        
    }
    else {
        // Fire up capturing thread
        pthread_create(&capture_thread_id, NULL, capture, NULL);
        
		if(!global_options.threshold) {
        // Options thread
        	pthread_create(&output_thread_id, NULL, output_thread, &global_options);
        	pthread_kill(output_thread_id, SIGINT);
		}
        
        pthread_join(capture_thread_id, NULL);
        
    }
        
    free_stats();
    free_addresses();
	
	free(global_options.server);
    
    return EXIT_SUCCESS;

}
Пример #9
0
/*
 * int
 * main(int argc, char **argv)
 *	Start routine of unc_dmctl command.
 */
int
main(int argc, char **argv)
{
	pfc_cmdopt_t	*parser;
	cmdspec_t	*spec;
	const char	*conffile = UNCD_CONF_PATH;
	int		argidx, ret;
	char		c;

	/* Use C locale. */
	(void)setlocale(LC_ALL, "C");

	/* Set timezone. */
	tzset();

	/* Initialize signal. */
	signal_init();

	/* Create command line option parser. */
	parser = pfc_cmdopt_init(PROGNAME, argc, argv, option_spec,
				 arg_format, 0);
	if (PFC_EXPECT_FALSE(parser == NULL)) {
		fatal("Failed to create option parser.");
		/* NOTREACHED */
	}

	while ((c = pfc_cmdopt_next(parser)) != PFC_CMDOPT_EOF) {
		switch (c) {
		case OPTCHAR_CONF:
			conffile = pfc_cmdopt_arg_string(parser);
			if (PFC_EXPECT_FALSE(*conffile == '\0')) {
				fatal("Configuration file path is empty.");
				/* NOTREACHED */
			}
			break;

		case OPTCHAR_TIMEOUT:
			ipc_timeout = pfc_cmdopt_arg_uint32(parser);
			if (PFC_EXPECT_FALSE(ipc_timeout <
					     IPC_TIMEOUT_MIN)) {
				fatal("-%c: Timeout value must be greater than "
				      "or equal %u.", OPTCHAR_TIMEOUT,
				      IPC_TIMEOUT_MIN);
				/* NOTREACHED */
			}
			else if (PFC_EXPECT_FALSE(ipc_timeout >
						  IPC_TIMEOUT_MAX)) {
				fatal("-%c: Timeout value must be less than "
				      "or equal %u.", OPTCHAR_TIMEOUT,
				      IPC_TIMEOUT_MAX);
				/* NOTREACHED */
			}
			break;

		case OPTCHAR_CHANNEL:
			ipc_channel = pfc_cmdopt_arg_string(parser);
			if (PFC_EXPECT_FALSE(*ipc_channel == '\0')) {
				fatal("-%c: IPC channel name must not be "
				      "empty.", OPTCHAR_CHANNEL);
				/* NOTREACHED */
			}
			break;

		case OPTCHAR_DEBUG:
			debug_level++;
			break;

		case OPTCHAR_VERSION:
			dump_version();
			/* NOTREACHED */

		case PFC_CMDOPT_USAGE:
			pfc_cmdopt_usage(parser, stdout);
			exit(DMCTL_EX_OK);
			/* NOTREACHED */

		case PFC_CMDOPT_HELP:
			pfc_cmdopt_help(parser, stdout, HELP_MESSAGE);
			exit(DMCTL_EX_OK);
			/* NOTREACHED */

		case PFC_CMDOPT_ERROR:
			exit(DMCTL_EX_FATAL);
			/* NOTREACHED */

		default:
			fatal("Failed to parse command line options.");
			/* NOTREACHED */
		}
	}

	if ((argidx = pfc_cmdopt_validate(parser)) == -1) {
		fatal("Invalid command line options.");
		/* NOTREACHED */
	}

	argc -= argidx;
	argv += argidx;
	if (argc == 0) {
		dump_subcommands(parser);
		/* NOTREACHED */
	}
	pfc_cmdopt_destroy(parser);

	if (debug_level) {
		pfc_log_conf_t	cf;
		pfc_log_level_t	lvl = (debug_level == 1)
			? PFC_LOGLVL_DEBUG
			: PFC_LOGLVL_VERBOSE;

		pfc_logconf_early(&cf, PFC_CFBLK_INVALID, PROGNAME, stderr,
				  lvl, NULL);
		pfc_log_sysinit(&cf);
	}

	/* Determine subcommand. */
	spec = subcmd_find(*argv);
	if (PFC_EXPECT_FALSE(spec == NULL)) {
		fatal("Unknown subcommand: %s", *argv);
		/* NOTREACHED */
	}

	if (ipc_timeout == 0) {
		/* Use default timeout. */
		ipc_timeout = spec->cs_timeout;
	}

	/* Load system configuration file. */
	sysconf_init(conffile);

	if ((spec->cs_flags & CMDF_NOIPC) == 0) {
		int	err;

		/* Initialize IPC client. */
		err = ipc_init();
		if (PFC_EXPECT_FALSE(err != 0)) {
			return DMCTL_EX_FATAL;
		}
	}

	/* Dispatch subcommand. */
	current_cmd = spec;
	ret = spec->cs_func(spec, argc, argv);
	current_cmd = NULL;

	/* Tear down the command. */
	if ((spec->cs_flags & CMDF_NOIPC) == 0) {
		ipc_fini();
	}
	dmconf_cleanup();

	return ret;
}
Пример #10
0
/*
 * Pick out command-line options and set up appres.
 */
static void
parse_options(int *argcp, const char **argv)
{
    int i;
    unsigned j;
    int argc_out = 0;
    const char **argv_out =
	(const char **) Malloc((*argcp + 1) * sizeof(char *));
    optlist_t *o;
    opt_t *opts;

    /* Parse the command-line options. */
    argv_out[argc_out++] = argv[0];

    for (i = 1; i < *argcp; i++) {
	bool found = false;

	for (o = optlist; o != NULL && !found; o = o->next) {
	    opts = o->opts;
	    for (j = 0; j < o->count; j++) {
		if (!strcmp(argv[i], opts[j].name)) {
		    found = true;
		    break;
		}
	    }
	}
	if (!found) {
	    argv_out[argc_out++] = argv[i];
	    continue;
	}

	switch (opts[j].type) {
	case OPT_BOOLEAN:
	    *(bool *)opts[j].aoff = opts[j].flag;
	    if (opts[j].res_name != NULL) {
		add_resource(NewString(opts[j].name),
			opts[j].flag? "true": "false");
	    }
	    break;
	case OPT_STRING:
	    if (i == *argcp - 1) {	/* missing arg */
		popup_an_error("Missing value for '%s'", argv[i]);
		continue;
	    }
	    *(const char **)opts[j].aoff = argv[++i];
	    if (opts[j].res_name != NULL) {
		add_resource(NewString(opts[j].res_name), NewString(argv[i]));
	    }
	    break;
	case OPT_XRM:
	    if (i == *argcp - 1) {	/* missing arg */
		popup_an_error("Missing value for '%s'", argv[i]);
		continue;
	    }
	    parse_xrm(argv[++i], "-xrm");
	    break;
	case OPT_SKIP2:
	    argv_out[argc_out++] = argv[i++];
	    if (i < *argcp) {
		argv_out[argc_out++] = argv[i];
	    }
	    break;
	case OPT_NOP:
	    break;
	case OPT_INT:
	    if (i == *argcp - 1) {	/* missing arg */
		popup_an_error("Missing value for '%s'", argv[i]);
		continue;
	    }
	    *(int *)opts[j].aoff = atoi(argv[++i]);
	    if (opts[j].res_name != NULL) {
		add_resource(NewString(opts[j].name), NewString(argv[i]));
	    }
	    break;
	case OPT_V:
	    dump_version();
	    break;
	case OPT_DONE:
	    while (i < *argcp) {
		argv_out[argc_out++] = argv[i++];
	    }
	    break;
	}
    }
    *argcp = argc_out;
    argv_out[argc_out] = NULL;
    (void) memcpy((char *)argv, (char *)argv_out,
    (argc_out + 1) * sizeof(char *));
    Free((char *)argv_out);
}
Пример #11
0
/*
 * static void
 * setup(int argc, char **argv)
 *	Setup monitor environment.
 */
static void
setup(int argc, char **argv)
{
	pfc_cmdopt_t	*parser;
	pfc_refptr_t	*defconf, *dname, *defmconf, *defpfile;
	const char	*conffile;
	const char	*moncf;
	const char	*pidpath;
	monitor_ctx_t	*mp = &monitor_ctx;
	pfc_log_level_t	lvl = PFC_LOGLVL_NONE;
	int		argidx, do_kill = 0;
	uint32_t	ktout = KILL_TIMEOUT;
	char		c;

	/* Use C locale. */
	(void)setlocale(LC_ALL, "C");

	/* Set timezone. */
	tzset();

	if (PFC_EXPECT_TRUE(argc > 0)) {
		/* Initialize program name. */
		dname = progname_init(*argv, &progname);
		if (PFC_EXPECT_FALSE(dname == NULL)) {
			fatal("Failed to create daemon name.");
			/* NOTREACHED */
		}

		daemon_name = pfc_refptr_string_value(dname);
		daemon_rname = dname;
	}
	else {
		dname = NULL;
	}

	/* Construct default file paths. */
	defconf = pfc_refptr_sprintf(PFC_SYSCONFDIR "/%s.conf", daemon_name);
	if (PFC_EXPECT_FALSE(defconf == NULL)) {
		fatal("Failed to create default configuration file path.");
		/* NOTREACHED */
	}

	defmconf = pfc_refptr_sprintf(PFC_SYSCONFDIR "/%s.conf", progname);
	if (PFC_EXPECT_FALSE(defmconf == NULL)) {
		fatal("Failed to create default monitor configuration file "
		      "path.");
		/* NOTREACHED */
	}

	defpfile = pfc_refptr_sprintf(PFC_RUNDIR_PATH "/%s.pid", progname);
	if (PFC_EXPECT_FALSE(defpfile == NULL)) {
		fatal("Failed to create default PID file path.");
		/* NOTREACHED */
	}

	conffile = pfc_refptr_string_value(defconf);
	moncf = pfc_refptr_string_value(defmconf);
	pidpath = pfc_refptr_string_value(defpfile);
	copt_desc_update(conffile);
	mcopt_desc_update(moncf);
	popt_desc_update(pidpath);

	/* Create command line option parser. */
	parser = pfc_cmdopt_init(progname, argc, argv, option_spec, NULL, 0);
	if (PFC_EXPECT_FALSE(parser == NULL)) {
		fatal("Failed to create option parser.");
		/* NOTREACHED */
	}

	mp->mc_syslog = PFC_FALSE;

	while ((c = pfc_cmdopt_next(parser)) != PFC_CMDOPT_EOF) {
		switch (c) {
		case 'C':
			conffile = pfc_cmdopt_arg_string(parser);
			if (PFC_EXPECT_FALSE(*conffile == '\0')) {
				fatal("Configuration file path is empty.");
				/* NOTREACHED */
			}
			break;

		case 'c':
			moncf = pfc_cmdopt_arg_string(parser);
			if (PFC_EXPECT_FALSE(*moncf == '\0')) {
				fatal("Monitor configuration file path is "
				      "empty.");
				/* NOTREACHED */
			}
			break;

		case 'P':
			pidpath = pfc_cmdopt_arg_string(parser);
			if (PFC_EXPECT_FALSE(*pidpath == '\0')) {
				fatal("Monitor PID file path is empty.");
				/* NOTREACHED */
			}
			break;

		case 's':
			mp->mc_syslog = PFC_TRUE;
			break;

		case 'd':
			/* Run as debug mode. */
			monitor_debug++;
			lvl = (lvl == PFC_LOGLVL_NONE)
				? PFC_LOGLVL_DEBUG : PFC_LOGLVL_VERBOSE;
			break;

		case 'K':
			ktout = pfc_cmdopt_arg_uint32(parser);
			if (PFC_EXPECT_FALSE(ktout < KILL_TIMEOUT_MIN)) {
				fatal("kill-timeout must be greater than or "
				      "equal %u.", KILL_TIMEOUT_MIN);
				/* NOTREACHED */
			}
			else if (PFC_EXPECT_FALSE(ktout > KILL_TIMEOUT_MAX)) {
				fatal("kill-timeout must be less than or "
				      "equal %u.", KILL_TIMEOUT_MAX);
				/* NOTREACHED */
			}
			/* FALLTHROUGH */

		case 'k':
			do_kill = 1;
			break;

		case '\v':
			dump_version();
			/* NOTREACHED */

		case PFC_CMDOPT_USAGE:
			pfc_cmdopt_usage(parser, stdout);
			exit(MON_EX_OK);
			/* NOTREACHED */

		case PFC_CMDOPT_HELP:
			pfc_cmdopt_help_list(parser, stdout, HELP_MESSAGE_1,
					     daemon_name, HELP_MESSAGE_2,
					     daemon_name, HELP_MESSAGE_3,
					     NULL);
			exit(MON_EX_OK);
			/* NOTREACHED */

		case PFC_CMDOPT_ERROR:
			exit(MON_EX_FATAL);
			/* NOTREACHED */

		default:
			fatal("Failed to parse command line options.");
			/* NOTREACHED */
		}
	}

	if ((argidx = pfc_cmdopt_validate(parser)) == -1) {
		fatal("Invalid command line options.");
		/* NOTREACHED */
	}

	argc -= argidx;
	argv += argidx;
	if (PFC_EXPECT_FALSE(argc != 0)) {
		pfc_cmdopt_usage(parser, stderr);
		exit(MON_EX_FATAL);
		/* NOTREACHED */
	}

	pfc_cmdopt_destroy(parser);

	/* Close all inherited file descriptors. */
	pfc_closefrom(3);

	/*
	 * Initialize the logging system to dump early logs to the standard
	 * error output.
	 */
	pfc_log_init(progname, stderr, lvl, fatal_die);

	if (do_kill) {
		/* Kill the monitor process. */
		stop_monitor(pidpath, ktout);
		exit(MON_EX_OK);
		/* NOTREACHED */
	}

	mp->mc_conf = PFC_CONF_INVALID;
	mp->mc_cfpath = pfc_refptr_string_create(moncf);
	pfc_refptr_put(defmconf);
	if (PFC_EXPECT_FALSE(mp->mc_cfpath == NULL)) {
		fatal("Failed to create monitor configuration file path.");
		/* NOTREACHED */
	}

	mp->mc_mon_pidfile = pfc_refptr_string_create(pidpath);
	pfc_refptr_put(defpfile);
	if (PFC_EXPECT_FALSE(mp->mc_mon_pidfile == NULL)) {
		fatal("Failed to create PID file path.");
		/* NOTREACHED */
	}

	/* Load system configuration file. */
	sysconf_init(mp, conffile);
	pfc_refptr_put(defconf);

	/* Initialize syslog if non-debug mode. */
	if (monitor_debug) {
		mp->mc_syslog = PFC_FALSE;
	}
	else if (mp->mc_syslog) {
		syslog_init();
	}
}