diff options
Diffstat (limited to 'src/pies.c')
-rw-r--r-- | src/pies.c | 161 |
1 files changed, 38 insertions, 123 deletions
@@ -1,5 +1,5 @@ /* This file is part of GNU Pies. - Copyright (C) 2008-2011, 2013-2015 Sergey Poznyakoff + Copyright (C) 2008-2011, 2013-2016 Sergey Poznyakoff GNU Pies is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -45,8 +45,6 @@ enum pies_command command; char *statedir = DEFAULT_STATE_DIR; char *instance; char *pidfile; -char *ctlfile; -char *statfile; char *qotdfile; int inetd_mode; mode_t pies_umask = 0; @@ -1581,16 +1579,16 @@ struct grecs_keyword pies_keywords[] = { }, {"control-file", NULL, - N_("Set location of the control file."), - grecs_type_string, GRECS_DFLT, - &ctlfile, 0, + N_("Ignored for compatibility with version 1.2."), + grecs_type_string, GRECS_DFLT|GRECS_INAC, + NULL, 0, NULL, }, {"stat-file", NULL, - N_("Set location of the statistics output file."), - grecs_type_string, GRECS_DFLT, - &statfile, 0, + N_("Ignored for compatibility with version 1.2."), + grecs_type_string, GRECS_DFLT|GRECS_INAC, + NULL, 0, NULL, }, {"qotd-file", @@ -1802,14 +1800,6 @@ sig_handler (int sig) case SIGALRM: got_alarm = 1; break; - - case SIGUSR1: - action = ACTION_COMPRELOAD; - break; - - case SIGUSR2: - action = ACTION_DUMPSTATS; - break; } } @@ -1839,8 +1829,6 @@ static int default_sigv[] = { SIGINT, SIGHUP, SIGALRM, - SIGUSR1, - SIGUSR2, SIGPIPE }; @@ -1924,86 +1912,49 @@ enum pies_status pies_check_status (pid_t *ppid) { pid_t pid = pidfile_read (0); - int i; - int rc; if (pid <= 0) return pies_status_ctr; *ppid = pid; - if (kill (pid, SIGUSR2)) + if (kill (pid, 0)) return pies_status_stale; - for (i = 0; i < 4 && (rc = access (statfile, R_OK)); i++) - sleep (1); - - if (rc) - return pies_status_noresp; return pies_status_running; } - void -stop_components () +request_restart_components (size_t cc, char **cv) { - FILE *fp; - size_t size = 0; - char *buf = NULL; - - logmsg (LOG_INFO, _("stopping components")); - - fp = fopen (ctlfile, "r"); - if (!fp) - { - logmsg (LOG_ERR, _("cannot open control file `%s': %s"), - ctlfile, strerror (errno)); - return; - } - if (unlink (ctlfile)) - { - logmsg (LOG_ERR, _("cannot unlink control file `%s': %s"), - ctlfile, strerror (errno)); - fclose (fp); - return; - } - - while (getline (&buf, &size, fp) > 0) - { - size_t len = strlen (buf); - if (len == 0) - continue; - if (buf[len - 1] == '\n') - buf[len - 1] = 0; - progman_stop_tag (buf); - } - - free (buf); - fclose (fp); + char **argv; + size_t i; + + argv = xcalloc (cc + 4, sizeof (*argv)); + argv[0] = "piesctl"; + argv[1] = "--url"; + argv[2] = (char*) pies_control_url (); + for (i = 0; i < cc; i++) + argv[3 + i] = cv[i]; + argv[3 + i] = NULL; + execv (argv[0], argv); + logmsg (LOG_ERR, "can't run piesctl: %s", strerror (errno)); + exit (EX_OSFILE); } -int -request_restart_components (char **argv) +void +list_components (void) { - FILE *fp; - pid_t pid = pidfile_read (1);//FIXME: useless in init mode, init has pid == 1 - - if (pid == -1) - return 1; - - fp = fopen (ctlfile, "w"); - if (!fp) - { - logmsg (LOG_ERR, _("cannot open control file `%s': %s"), - ctlfile, strerror (errno)); - return 1; - } - for (; *argv; argv++) - fprintf (fp, "%s\n", *argv); - fclose (fp); - - kill (pid, SIGUSR1); - return 0; + char *argv[5]; + + argv[0] = "piesctl"; + argv[1] = "--url"; + argv[2] = (char*) pies_control_url (); + argv[3] = "list"; + argv[4] = NULL; + execv (argv[0], argv); + logmsg (LOG_ERR, "can't run piesctl: %s", strerror (errno)); + exit (EX_OSFILE); } @@ -2026,11 +1977,7 @@ int pies_status () { pid_t pid; - FILE *fp; - if (unlink (statfile) && errno != ENOENT) - logmsg (LOG_ERR, _("cannot unlink statfile `%s': %s"), - statfile, strerror (errno)); switch (pies_check_status (&pid)) { case pies_status_ctr: @@ -2047,27 +1994,11 @@ pies_status () logmsg (LOG_INFO, _("pies seems to run with pid %lu, but is not responding"), (unsigned long) pid); - if (unlink (statfile)) - logmsg (LOG_ERR, _("cannot unlink statfile `%s': %s"), - statfile, strerror (errno)); return 2; case pies_status_running: - fp = fopen (statfile, "r"); - if (!fp) - logmsg (LOG_ERR, _("cannot open statfile `%s': %s"), - statfile, strerror (errno)); - else - { - char c; - - if (unlink (statfile)) - logmsg (LOG_ERR, _("cannot unlink statfile `%s': %s"), - statfile, strerror (errno)); - while ((c = fgetc (fp)) != EOF) - fputc (c, stdout); - fclose (fp); - } + list_components (); + break; } return 0; } @@ -2188,10 +2119,6 @@ set_state_file_names (const char *base) { if (!pidfile) pidfile = mkfilename (statedir, base, ".pid"); - if (!ctlfile) - ctlfile = mkfilename (statedir, base, ".ctl"); - if (!statfile) - statfile = mkfilename (statedir, base, ".stat"); if (!qotdfile) qotdfile = mkfilename (statedir, base, ".qotd"); } @@ -2366,8 +2293,8 @@ main (int argc, char **argv) pies_priv_setup (&pies_privs); if (pies_umask) umask (pies_umask); - exit (request_restart_components (argv + index)); - + request_restart_components (argc - index, argv + index); + case COM_RELOAD: exit (pies_reload ()); @@ -2458,18 +2385,6 @@ main (int argc, char **argv) pies_pause (); switch (action) { - case ACTION_COMPRELOAD: - stop_components (); - progman_cleanup (0); - progman_start (); - action = ACTION_CONT; - break; - - case ACTION_DUMPSTATS: - progman_dump_stats (statfile); - action = ACTION_CONT; - break; - case ACTION_STOP: case ACTION_RESTART: if (init_process) |