FreeBSD/usr.sbin/watchdogd/watchdogd.c
/*
 * Handle the few command line arguments supported.
 */
Handle the few command line arguments supported.
Handle the few command line arguments supported .
static void
parseargs(int argc, char *argv[])
{
	int longindex;
	int c;
	const char *lopt;
	c = strlen(argv[0]);
	if (argv[0][c - 1] == 'd')
		is_daemon = 1;
	if (is_daemon)
		getopt_shortopts = "I:de:ns:t:ST:wx:?";
	else
		getopt_shortopts = "dt:?";
	while ((c = getopt_long(argc, argv, getopt_shortopts, longopts,
		    &longindex)) != -1) {
		switch (c) {
		case 'I':
			pidfile = optarg;
			break;
		case 'd':
			debugging = 1;
			break;
		case 'e':
			test_cmd = strdup(optarg);
			break;
		case 'n':
			is_dry_run = 1;
			break;
#ifdef notyet
		case 'p':
			passive = 1;
			break;
#endif
		case 's':
			nap = fetchtimeout(c, NULL, optarg, 0);
			break;
		case 'S':
			do_syslog = 0;
			break;
		case 't':
			timeout_sec = atoi(optarg);
			timeout = parse_timeout_to_pow2ns(c, NULL, optarg);
 			if (debugging)
 				printf("Timeout is 2^%d nanoseconds\n",
 				    timeout);
			break;
		case 'T':
			carp_thresh_seconds =
			    fetchtimeout(c, "NULL", optarg, 0);
			break;
		case 'w':
			do_timedog = 1;
			break;
		case 'x':
			exit_timeout = parse_timeout_to_pow2ns(c, NULL, optarg);
			if (exit_timeout != 0)
				exit_timeout |= WD_ACTIVE;
			break;
		case 0:
			lopt = longopts[longindex].name;
			if (!strcmp(lopt, "pretimeout")) {
				pretimeout = fetchtimeout(0, lopt, optarg, 0);
			} else if (!strcmp(lopt, "pretimeout-action")) {
				pretimeout_act = timeout_act_str2int(lopt,
				    optarg);
			} else if (!strcmp(lopt, "softtimeout-action")) {
				softtimeout_act = timeout_act_str2int(lopt,
				    optarg);
			} else {
			}
			break;
		case '?':
		default:
			usage();
		}
	}
	if (carp_thresh_seconds == -1)
		carp_thresh_seconds = nap;
	if (argc != optind)
		errx(EX_USAGE, "extra arguments.");
	if (is_daemon && timeout < WD_TO_1SEC)
		errx(EX_USAGE, "-t argument is less than one second.");
	if (pretimeout_set) {
		struct timespec ts;
		pow2ns_to_ts(timeout, &ts);
		if (pretimeout >= (uintmax_t)ts.tv_sec) {
			errx(EX_USAGE,
			    "pretimeout (%d) >= timeout (%d -> %ld)\n"
			    "see manual section TIMEOUT RESOLUTION",
			    pretimeout, timeout_sec, (long)ts.tv_sec);
		}
	}
}
static void parseargs ( int argc , char * argv [ ] ) { int longindex ; int c ; const char * lopt ; c = strlen ( argv [ 0 ] ) ; if ( argv [ 0 ] [ c - 1 ] == ' ' ) is_daemon = 1 ; if ( is_daemon ) getopt_shortopts = " " ; else getopt_shortopts = " " ; while ( ( c = getopt_long ( argc , argv , getopt_shortopts , longopts , & longindex ) ) != -1 ) { switch ( c ) { case ' ' : pidfile = optarg ; break ; case ' ' : debugging = 1 ; break ; case ' ' : test_cmd = strdup ( optarg ) ; break ; case ' ' : is_dry_run = 1 ; break ; #ifdef notyet case ' ' : passive = 1 ; break ; #endif case ' ' : nap = fetchtimeout ( c , NULL , optarg , 0 ) ; break ; case ' ' : do_syslog = 0 ; break ; case ' ' : timeout_sec = atoi ( optarg ) ; timeout = parse_timeout_to_pow2ns ( c , NULL , optarg ) ; if ( debugging ) printf ( " \n " , timeout ) ; break ; case ' ' : carp_thresh_seconds = fetchtimeout ( c , " " , optarg , 0 ) ; break ; case ' ' : do_timedog = 1 ; break ; case ' ' : exit_timeout = parse_timeout_to_pow2ns ( c , NULL , optarg ) ; if ( exit_timeout != 0 ) exit_timeout |= WD_ACTIVE ; break ; case 0 : lopt = longopts [ longindex ] . name ; if ( ! strcmp ( lopt , " " ) ) { pretimeout = fetchtimeout ( 0 , lopt , optarg , 0 ) ; } else if ( ! strcmp ( lopt , " " ) ) { pretimeout_act = timeout_act_str2int ( lopt , optarg ) ; } else if ( ! strcmp ( lopt , " " ) ) { softtimeout_act = timeout_act_str2int ( lopt , optarg ) ; } else { } break ; case ' ' : default : usage ( ) ; } } if ( carp_thresh_seconds == -1 ) carp_thresh_seconds = nap ; if ( argc != optind ) errx ( EX_USAGE , " " ) ; if ( is_daemon && timeout < WD_TO_1SEC ) errx ( EX_USAGE , " " ) ; if ( pretimeout_set ) { struct timespec ts ; pow2ns_to_ts ( timeout , & ts ) ; if ( pretimeout >= ( uintmax_t ) ts . tv_sec ) { errx ( EX_USAGE , " \n " " " , pretimeout , timeout_sec , ( long ) ts . tv_sec ) ; } } }
Handle the few command line arguments supported.
Handle the few command line arguments supported .
/*
	 * if we end with a 'd' aka 'watchdogd' then we are the daemon program,
	 * otherwise run as a command line utility.
	 */ /*		warnx("bad option at index %d: %s", optind,
				    argv[optind]);
				usage();
				*/ /* NOTREACHED */