DAEMON_KILL,
DAEMON_VERSION,
DAEMON_HELP,
- DAEMON_RELOAD
+ DAEMON_RELOAD,
+ DAEMON_CHECK
} DaemonCommand;
typedef struct {
" -D --daemonize Daemonize after startup\n"
" -k --kill Kill a running daemon\n"
" -r --reload Request a running daemon to reload static services\n"
+ " -c --check Return 0 if a daemon is already running\n"
" -V --version Show version\n"
" -f --file=FILE Load the specified configuration file instead of\n"
" "AVAHI_CONFIG_FILE"\n",
{ "version", no_argument, NULL, 'V' },
{ "file", required_argument, NULL, 'f' },
{ "reload", no_argument, NULL, 'r' },
+ { "check", no_argument, NULL, 'c' },
};
g_assert(config);
opterr = 0;
- while ((c = getopt_long(argc, argv, "hDkVf:r", long_options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "hDkVf:rc", long_options, NULL)) >= 0) {
switch(c) {
case 'h':
case 'r':
config->command = DAEMON_RELOAD;
break;
+ case 'c':
+ config->command = DAEMON_CHECK;
+ break;
default:
fprintf(stderr, "Invalid command line argument: %c\n", c);
return -1;
}
r = 0;
-
+
} else if (config.command == DAEMON_RELOAD) {
if (daemon_pid_file_kill(SIGHUP) < 0) {
avahi_log_warn("Failed to kill daemon: %s", strerror(errno));
r = 0;
- } else if (config.command == DAEMON_RUN) {
+ } else if (config.command == DAEMON_CHECK)
+ r = (daemon_pid_file_is_running() >= 0) ? 0 : 1;
+ else if (config.command == DAEMON_RUN) {
pid_t pid;
if (getuid() != 0) {
DAEMON_KILL,
DAEMON_RELOAD,
DAEMON_VERSION,
- DAEMON_HELP
+ DAEMON_HELP,
+ DAEMON_CHECK
} command = DAEMON_RUN;
static gboolean daemonize = FALSE;
" -D --daemonize Daemonize after startup\n"
" -k --kill Kill a running daemon\n"
" -r --reload Request a running daemon to reload static services\n"
+ " -c --check Return 0 if a daemon is already running\n"
" -V --version Show version\n",
argv0);
}
{ "kill", no_argument, NULL, 'k' },
{ "version", no_argument, NULL, 'V' },
{ "reload", no_argument, NULL, 'r' },
+ { "check", no_argument, NULL, 'c' },
};
opterr = 0;
- while ((c = getopt_long(argc, argv, "hDkVr", long_options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "hDkVrc", long_options, NULL)) >= 0) {
switch(c) {
case 'h':
case 'r':
command = DAEMON_RELOAD;
break;
+ case 'c':
+ command = DAEMON_CHECK;
+ break;
default:
fprintf(stderr, "Invalid command line argument: %c\n", c);
return -1;
if (run_daemon() < 0)
goto finish;
+ r = 0;
} else if (command == DAEMON_HELP) {
help(stdout, argv0);
+ r = 0;
} else if (command == DAEMON_VERSION) {
printf("%s "PACKAGE_VERSION"\n", argv0);
+ r = 0;
} else if (command == DAEMON_KILL) {
if (daemon_pid_file_kill_wait(SIGTERM, 5) < 0) {
daemon_log(LOG_WARNING, "Failed to kill daemon: %s", strerror(errno));
goto finish;
}
+ r = 0;
} else if (command == DAEMON_RELOAD) {
if (daemon_pid_file_kill(SIGHUP) < 0) {
daemon_log(LOG_WARNING, "Failed to kill daemon: %s", strerror(errno));
goto finish;
}
- }
- r = 0;
+ r = 0;
+ } else if (command == DAEMON_CHECK)
+ r = (daemon_pid_file_is_running() >= 0) ? 0 : 1;
+
+
finish: