From: Lennart Poettering Date: Fri, 1 Jul 2005 23:15:56 +0000 (+0000) Subject: * add new option --check to daemons X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=41fd44c00e3368fe59c156e5eb70a00c8a99781f;p=catta * add new option --check to daemons git-svn-id: file:///home/lennart/svn/public/avahi/trunk@160 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- diff --git a/avahi-daemon/main.c b/avahi-daemon/main.c index fd95d93..ce82664 100644 --- a/avahi-daemon/main.c +++ b/avahi-daemon/main.c @@ -53,7 +53,8 @@ typedef enum { DAEMON_KILL, DAEMON_VERSION, DAEMON_HELP, - DAEMON_RELOAD + DAEMON_RELOAD, + DAEMON_CHECK } DaemonCommand; typedef struct { @@ -209,6 +210,7 @@ static void help(FILE *f, const gchar *argv0) { " -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", @@ -225,12 +227,13 @@ static gint parse_command_line(DaemonConfig *config, int argc, char *argv[]) { { "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': @@ -252,6 +255,9 @@ static gint parse_command_line(DaemonConfig *config, int argc, char *argv[]) { 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; @@ -709,7 +715,7 @@ int main(int argc, char *argv[]) { } 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)); @@ -718,7 +724,9 @@ int main(int argc, char *argv[]) { 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) { diff --git a/avahi-dnsconfd/main.c b/avahi-dnsconfd/main.c index 918beeb..dc867d8 100644 --- a/avahi-dnsconfd/main.c +++ b/avahi-dnsconfd/main.c @@ -62,7 +62,8 @@ static enum { DAEMON_KILL, DAEMON_RELOAD, DAEMON_VERSION, - DAEMON_HELP + DAEMON_HELP, + DAEMON_CHECK } command = DAEMON_RUN; static gboolean daemonize = FALSE; @@ -343,6 +344,7 @@ static void help(FILE *f, const gchar *argv0) { " -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); } @@ -356,10 +358,11 @@ static gint parse_command_line(int argc, char *argv[]) { { "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': @@ -377,6 +380,9 @@ static gint parse_command_line(int argc, char *argv[]) { case 'r': command = DAEMON_RELOAD; break; + case 'c': + command = DAEMON_CHECK; + break; default: fprintf(stderr, "Invalid command line argument: %c\n", c); return -1; @@ -575,26 +581,33 @@ gint main(gint argc, gchar *argv[]) { 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: