diff options
-rw-r--r-- | src/pies.c | 201 | ||||
-rw-r--r-- | src/progman.c | 58 |
2 files changed, 209 insertions, 50 deletions
@@ -19,7 +19,6 @@ #include <configmake.h> #include "meta1lex.h" -char *conffile = SYSCONFDIR "/pies.conf"; int preprocess_only; /* Preprocess config, do nothing more */ int lint_mode; /* Test configuration syntax and exit */ int log_to_stderr_only; /* Use only stderr for logging */ @@ -28,11 +27,12 @@ char *log_tag; struct pies_privs pies_privs; int foreground; int command; +char *instance; +char *pidfile; +char *ctlfile; +char *statfile; +char *qotdfile; int inetd_mode; -char *pidfile = LOCALSTATEDIR "/pies.pid"; -char *ctlfile = LOCALSTATEDIR "/pies.ctl"; -char *statfile = LOCALSTATEDIR "/pies.stat"; -char *qotdfile = LOCALSTATEDIR "/pies.qotd"; mode_t pies_umask = 0; unsigned long shutdown_timeout = 5; size_t default_max_rate; @@ -47,6 +47,63 @@ struct obstack pp_stk; struct quoting_options *pp_qopt; +enum config_syntax + { + CONF_PIES, + CONF_META1, + CONF_INETD + }; + +struct config_file +{ + struct config_file *next; + enum config_syntax syntax; + char *name; +}; + +static struct config_file *conf_head, *conf_tail; + +struct config_syntax_descr +{ + const char *name; + enum config_syntax type; +}; + +static struct config_syntax_descr config_syntax_tab[] = { + { "pies" , CONF_PIES }, + { "meta1", CONF_META1 }, + { "inetd", CONF_INETD }, + { NULL } +}; + +int +str_to_config_syntax (const char *str, enum config_syntax *psynt) +{ + struct config_syntax_descr *p; + for (p = config_syntax_tab; p->name; p++) + if (strcmp (p->name, str) == 0) + { + *psynt = p->type; + return 0; + } + return 1; +} + +void +add_config (enum config_syntax syntax, const char *name) +{ + struct config_file *file = xmalloc (sizeof (file[0])); + file->next = NULL; + file->syntax = syntax; + file->name = xstrdup (name); + if (conf_tail) + conf_tail->next = file; + else + conf_head = file; + conf_tail = file; +} + + static void add_pp_option (const char *opt, const char *arg) { @@ -1396,6 +1453,7 @@ static char args_doc[] = ""; enum { OPT_FOREGROUND = 256, + OPT_SYNTAX, OPT_SYSLOG, OPT_STDERR, OPT_DUMP_PREREQ, @@ -1429,6 +1487,8 @@ static struct argp_option options[] = { N_("use FILE instead of the default configuration"), GRP + 1}, {"config-help", OPT_CONFIG_HELP, NULL, 0, N_("show configuration file summary"), GRP + 1}, + {"syntax", OPT_SYNTAX, "{pies|inetd|meta1}", 0, + N_("expect configuration files in the given syntax"), GRP+1 }, {"rate", OPT_RATE, N_("NUMBER"), 0, N_("set default maximum rate for inetd-style components"), GRP + 1}, @@ -1469,6 +1529,8 @@ static struct argp_option options[] = { {NULL} }; +static enum config_syntax current_syntax = CONF_PIES; + static error_t parse_opt (int key, char *arg, struct argp_state *state) { @@ -1477,7 +1539,7 @@ parse_opt (int key, char *arg, struct argp_state *state) switch (key) { case 'c': - conffile = arg; + add_config (current_syntax, arg); break; case 'D': @@ -1493,6 +1555,9 @@ parse_opt (int key, char *arg, struct argp_state *state) break; case 'i': + if (!instance) + instance = "inetd"; + current_syntax = CONF_INETD; inetd_mode = 1; break; @@ -1510,6 +1575,14 @@ parse_opt (int key, char *arg, struct argp_state *state) foreground = 1; break; + case OPT_SYNTAX: + if (str_to_config_syntax (arg, ¤t_syntax)) + { + logmsg (LOG_ERR, _("unknown syntax type: %s"), arg); + exit (EX_USAGE); + } + break; + case OPT_RELOAD: case OPT_STATUS: case OPT_STOP: @@ -1964,13 +2037,55 @@ There is NO WARRANTY, to the extent permitted by law.\n\ fprintf (stream, _("Written by %s.\n"), "Sergey Poznyakoff"); } +static char * +mkfilename (const char *dir, const char *name, const char *suf) +{ + size_t dirlen = strlen (dir); + char *s; + + while (dirlen > 0 && dir[dirlen-1] == '/') + dirlen--; + + s = xmalloc (dirlen + 1 + strlen (name) + strlen (suf) + 1); + strcpy (s, dir); + strcat (s, "/"); + strcat (s, name); + strcat (s, suf); + return s; +} + +void +set_file_names (const char *base) +{ + const char *p; + + p = strrchr (base, '/'); + if (p) + base = p + 1; + if (!conf_head) + { + char *name = mkfilename (SYSCONFDIR, base, ".conf"); + add_config (current_syntax, name); + free (name); + } + if (!pidfile) + pidfile = mkfilename (LOCALSTATEDIR, base, ".pid"); + if (!ctlfile) + ctlfile = mkfilename (LOCALSTATEDIR, base, ".ctl"); + if (!statfile) + statfile = mkfilename (LOCALSTATEDIR, base, ".stat"); + if (!qotdfile) + qotdfile = mkfilename (LOCALSTATEDIR, base, ".qotd"); +} + int main (int argc, char **argv) { int index; pid_t pid; extern char **environ; - + struct config_file *file; + set_program_name (argv[0]); #ifdef ENABLE_NLS setlocale (LC_ALL, ""); @@ -1990,44 +2105,56 @@ main (int argc, char **argv) if (argp_parse (&argp, argc, argv, 0, &index, NULL)) exit (EX_USAGE); - if (inetd_mode) + if (!instance) { - if (index == argc) - { - if (inetd_parse_conf (SYSCONFDIR "/inetd.conf")) - exit (EX_CONFIG); - } + instance = strrchr (program_name, '/'); + if (!instance) + instance = (char*) program_name; else - { - int i; - - for (i = index; i < argc; i++) - { - if (inetd_parse_conf (argv[i])) - exit (EX_CONFIG); - } - } - - index = argc; + instance++; } + set_file_names (instance); + + if (!DEFAULT_PREPROCESSOR) + grecs_preprocessor = NULL; else { - if (!DEFAULT_PREPROCESSOR) - grecs_preprocessor = NULL; - else + grecs_preprocessor = obstack_finish (&pp_stk); + free (pp_qopt); + } + + if (preprocess_only) + { + for (file = conf_head; file; file = file->next) { - grecs_preprocessor = obstack_finish (&pp_stk); - free (pp_qopt); + if (file->syntax == CONF_PIES + && grecs_preproc_run (file->name, grecs_preprocessor)) + exit (EX_CONFIG); } - - if (preprocess_only) - exit (grecs_preproc_run (conffile, grecs_preprocessor) - ? EX_CONFIG : 0); - - if (grecs_parse (conffile)) - exit (EX_CONFIG); + exit (0); } - + else + for (file = conf_head; file; file = file->next) + { + switch (file->syntax) + { + case CONF_PIES: + if (grecs_parse (file->name)) + exit (EX_CONFIG); + break; + + case CONF_INETD: + if (inetd_parse_conf (file->name)) + exit (EX_CONFIG); + break; + + case CONF_META1: + if (meta1_config_parse (file->name)) + exit (EX_CONFIG); + break; + } + } + set_mailer_argcv (); if (lint_mode) diff --git a/src/progman.c b/src/progman.c index 1235d81..89be1f5 100644 --- a/src/progman.c +++ b/src/progman.c @@ -2056,42 +2056,74 @@ progman_dump_stats (const char *filename) for (prog = proghead; prog; prog = prog->next) { int i; + char fbuf[5]; + int fidx = 0; + fprintf (fp, "%-16s ", prog->tag); switch (prog->type) { case TYPE_COMPONENT: - fprintf (fp, "component %s ", prog->tag); + fbuf[fidx++] = 'C'; + if (prog->v.p.comp->mode == pies_comp_inetd + && prog->v.p.listener) + fbuf[fidx++] = 'i'; + if (prog->pid) { - fprintf (fp, "%lu", (unsigned long) prog->pid); if (prog->v.p.status == status_stopping) - fprintf (fp, " (stopping)"); + fbuf[fidx++] = 'S'; + else + fbuf[fidx++] = 'R'; } else if (prog->v.p.status == status_sleeping) { - time_t t = prog->v.p.timestamp + SLEEPTIME; - fprintftime (fp, _("[disabled; scheduled for %c]"), - localtime (&t), 0, 0); + fbuf[fidx++] = 's'; } else if (prog->v.p.status == status_disabled) - fprintf (fp, _("[disabled]")); + fbuf[fidx++] = 'D'; else if (prog->v.p.status == status_listener) - fprintf (fp, _("[listener]")); + fbuf[fidx++] = 'I'; + break; + + case TYPE_REDIRECTOR: + fbuf[fidx++] = 'R'; + break; + + case TYPE_COMMAND: + fbuf[fidx++] = 'E'; + } + fbuf[fidx++] = 0; + fprintf (fp, "%-8.8s ", fbuf); + + switch (prog->type) + { + case TYPE_COMPONENT: + if (prog->pid) + fprintf (fp, "%10lu ", (unsigned long) prog->pid); + else if (prog->v.p.status == status_listener + && prog->v.p.comp->socket_url) + fprintf (fp, "%-10s ", prog->v.p.comp->socket_url->string); else - fprintf (fp, _("[not running]")); + fprintf (fp, "%-10s ", "N/A"); + + if (prog->v.p.status == status_sleeping) + { + time_t t = prog->v.p.timestamp + SLEEPTIME; + fprintftime (fp, "%H:%M:%S", localtime (&t), 0, 0); + } + for (i = 0; i < prog->v.p.comp->argc; i++) fprintf (fp, " %s", quotearg (prog->v.p.comp->argv[i])); - fputc ('\n', fp); break; case TYPE_REDIRECTOR: - fprintf (fp, _("redirector %s %lu\n"), prog->tag, - (unsigned long) prog->pid); + fprintf (fp, "%10lu ", (unsigned long) prog->pid); break; case TYPE_COMMAND: - fprintf (fp, _("command %s: %s\n"), prog->tag, prog->v.c.command); + fprintf (fp, "%s", prog->v.c.command); } + fputc ('\n', fp); } fclose (fp); unlink (filename); |