aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-10-26 19:43:47 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2009-10-26 19:43:47 +0200
commite1038263368bc2a70ce59f1543e808b5b958c5cb (patch)
tree9dd4777cf0aaad6ce18dfbf1c6cc358156863207 /src
parentfd2468864b719af4cfb0266b1bb8c6b0dbd53aa0 (diff)
downloadpies-e1038263368bc2a70ce59f1543e808b5b958c5cb.tar.gz
pies-e1038263368bc2a70ce59f1543e808b5b958c5cb.tar.bz2
Improve diagnostic output.
* src/diag.c (diag_output): New variable. (diag_setup): New function. (vlogmsg): Use diag_output to decide where to output the message. Output to both stderr and syslog if diag_output says so. * src/pies.c (log_to_stderr): Rename to log_to_stderr_only. All uses changed. (log_setup): Remove. (main): Use diag_setup to initialize diagnostics. * src/pies.h (log_to_stderr): Remove. (DIAG_TO_SYSLOG, DIAG_TO_STDERR): New defines. (diag_setup): New function.
Diffstat (limited to 'src')
-rw-r--r--src/diag.c15
-rw-r--r--src/pies.c48
-rw-r--r--src/pies.h11
-rw-r--r--src/progman.c49
4 files changed, 73 insertions, 50 deletions
diff --git a/src/diag.c b/src/diag.c
index b2b4b31..0aebb7a 100644
--- a/src/diag.c
+++ b/src/diag.c
@@ -19,6 +19,16 @@
unsigned debug_level;
int source_info_option;
+int diag_output = DIAG_TO_STDERR;
+
+void
+diag_setup (int flags)
+{
+ if (flags)
+ diag_output = flags;
+ if (diag_output & DIAG_TO_SYSLOG)
+ openlog (log_tag, LOG_PID, log_facility);
+}
void
syslog_printer (int prio, const char *fmt, va_list ap)
@@ -35,12 +45,13 @@ syslog_printer (int prio, const char *fmt, va_list ap)
void
vlogmsg (int prio, const char *fmt, va_list ap)
{
- if (log_to_stderr)
+ if (DIAG_OUTPUT (DIAG_TO_STDERR))
{
+ fprintf (stderr, "%s: ", program_name);
vfprintf (stderr, fmt, ap);
fprintf (stderr, "\n");
}
- else
+ if (DIAG_OUTPUT (DIAG_TO_SYSLOG))
syslog_printer (prio, fmt, ap);
}
diff --git a/src/pies.c b/src/pies.c
index 0536824..a9f612f 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -22,7 +22,7 @@
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; /* Use stderr for logging */
+int log_to_stderr_only; /* Use only stderr for logging */
int log_facility = LOG_USER;
char *log_tag;
struct pies_privs pies_privs;
@@ -73,13 +73,6 @@ add_pp_option (const char *opt, const char *arg)
/* Logging */
-void
-log_setup (int want_stderr)
-{
- if (!want_stderr)
- openlog (log_tag, LOG_PID, log_facility);
-}
-
static int
stderr_closed_p ()
{
@@ -1235,7 +1228,7 @@ config_init ()
grecs_set_keywords (pies_keywords);
grecs_include_path_setup (DEFAULT_VERSION_INCLUDE_DIR,
DEFAULT_INCLUDE_DIR, NULL);
- grecs_log_to_stderr = log_to_stderr;
+ grecs_log_to_stderr = log_to_stderr_only;
if (DEFAULT_PREPROCESSOR)
{
obstack_init (&pp_stk);
@@ -1353,7 +1346,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
break;
case 't':
- log_to_stderr = 1;
+ log_to_stderr_only = 1;
lint_mode = 1;
break;
@@ -1362,7 +1355,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
exit (0);
case OPT_FOREGROUND:
- log_to_stderr = 1;
+ log_to_stderr_only = 1;
foreground = 1;
break;
@@ -1372,16 +1365,16 @@ parse_opt (int key, char *arg, struct argp_state *state)
case OPT_RESTART:
case OPT_DUMP_PREREQ:
case OPT_DUMP_DEPMAP:
- log_to_stderr = 1;
+ log_to_stderr_only = 1;
command = key;
break;
case OPT_SYSLOG:
- log_to_stderr = 0;
+ log_to_stderr_only = 0;
break;
case OPT_STDERR:
- log_to_stderr = 1;
+ log_to_stderr_only = 1;
break;
case 'x':
@@ -1830,8 +1823,8 @@ main (int argc, char **argv)
set_quoting_style (NULL, shell_quoting_style);
/* Set default logging */
- log_to_stderr = !stderr_closed_p ();
- log_setup (log_to_stderr);
+ diag_setup (DIAG_TO_SYSLOG | (stderr_closed_p () ? 0 : DIAG_TO_STDERR));
+
config_init ();
argp_program_version_hook = version;
if (argp_parse (&argp, argc, argv, 0, &index, NULL))
@@ -1860,8 +1853,8 @@ main (int argc, char **argv)
}
/* Re-setup logging: it might have been reset in the config file */
- log_setup (log_to_stderr);
-
+ diag_setup (log_to_stderr_only ? DIAG_TO_STDERR : 0);
+
if (argc != index && command != 'R')
{
logmsg (LOG_ERR, "extra command line arguments");
@@ -1921,20 +1914,19 @@ main (int argc, char **argv)
exit (EX_USAGE);
}
- if (!foreground)
- log_setup (log_to_stderr = 0);
-
logmsg (LOG_INFO, _("%s starting"), program_version);
if (!foreground)
- check_pidfile (pidfile);
-
- if (!foreground && daemon (0, 0) == -1)
{
- logmsg (LOG_ERR, _("cannot become a daemon: %s"), strerror (errno));
- exit (EX_SOFTWARE);
+ check_pidfile (pidfile);
+ if (daemon (0, 0) == -1)
+ {
+ logmsg (LOG_ERR, _("cannot become a daemon: %s"), strerror (errno));
+ exit (EX_SOFTWARE);
+ }
+ diag_setup (DIAG_TO_SYSLOG);
}
-
+
create_pidfile (pidfile);
if (argv[0][0] != '/')
@@ -1985,7 +1977,7 @@ main (int argc, char **argv)
if (action == ACTION_RESTART && argv[0][0] == '/')
{
- int minfd = log_to_stderr ? 2 : 0;
+ int minfd = DIAG_OUTPUT (DIAG_TO_STDERR) ? 2 : 0;
int i;
for (i = getmaxfd (); i > minfd; i--)
diff --git a/src/pies.h b/src/pies.h
index a8f400c..014bd81 100644
--- a/src/pies.h
+++ b/src/pies.h
@@ -168,7 +168,6 @@ struct component
struct action act_temp; /* Auxiliary object used during configuration */
};
-extern int log_to_stderr;
extern char *log_tag;
extern int log_facility;
extern unsigned long shutdown_timeout;
@@ -257,6 +256,16 @@ int meta1error (char *s);
int meta1parse (void);
+/* diag.c */
+#define DIAG_TO_SYSLOG 0x1
+#define DIAG_TO_STDERR 0x2
+
+extern int diag_output;
+
+#define DIAG_OUTPUT(x) (diag_output & (x))
+
+void diag_setup (int flags);
+
void logmsg (int prio, const char *fmt, ...);
void logmsg_printf (int prio, const char *fmt, ...);
void logmsg_vprintf (int prio, const char *fmt, va_list ap);
diff --git a/src/progman.c b/src/progman.c
index 8897c74..d0ea0d8 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -16,8 +16,12 @@
#include "pies.h"
-#define TYPE_COMPONENT 0
-#define TYPE_REDIRECTOR 1
+enum prog_type
+ {
+ TYPE_COMPONENT,
+ TYPE_REDIRECTOR,
+ TYPE_PROG
+ };
enum prog_status
{
@@ -33,7 +37,7 @@ enum prog_status
struct prog
{
struct prog *next, *prev;
- int type;
+ enum prog_type type;
pid_t pid; /* PID */
char *tag; /* Entry tag (for diagnostics purposes) */
int idx; /* Numeric identifier */
@@ -176,8 +180,8 @@ destroy_prog (struct prog **pp)
master->v.p.redir[0] = NULL;
else if (p == master->v.p.redir[1])
master->v.p.redir[1] = NULL;
- else
- logmsg (LOG_NOTICE, _("orphan redirector: %s"), p->tag);
+ /* else
+ logmsg (LOG_NOTICE, _("orphan redirector: %s"), p->tag);*/
}
}
unlink_prog (*pp);
@@ -224,16 +228,14 @@ void
update_redir (int type, struct prog *master, pid_t pid)
{
struct prog *pp;
- if (master->v.p.redir[type] == NULL)
- {
- pp = register_redir (type, master);
- master->v.p.redir[type] = pp;
- }
- else
+ if (master->v.p.redir[type])
{
pp = master->v.p.redir[type];
prog_stop (pp, SIGKILL); /* Just in case */
}
+
+ pp = register_redir (type, master);
+ master->v.p.redir[type] = pp;
pp->pid = pid;
}
@@ -405,7 +407,7 @@ open_redirector (struct prog *master, int stream)
close (i);
}
- log_setup (0);
+ diag_setup (0);
signal_setup (redir_exit);
close (p[1]);
@@ -425,6 +427,8 @@ open_redirector (struct prog *master, int stream)
return -1;
default:
+ debug (1, (_("redirector for %s started, pid=%lu"),
+ master->tag, (unsigned long) pid));
update_redir (stream, master, pid);
close (p[0]);
return p[1];
@@ -780,6 +784,7 @@ prog_start (struct prog *prog)
close (prog->v.p.socket);
prog->pid = pid;
prog->v.p.status = status_enabled;
+ debug (1, (_("%s started, pid=%lu"), prog->tag, (unsigned long) pid));
}
}
@@ -1235,7 +1240,7 @@ prog_stop_dependents (struct prog *prog)
continue;
if (!warned && dp->pid)
{
- debug (1, ("Stopping dependencies of %s", prog->tag));
+ debug (1, ("stopping dependencies of %s", prog->tag));
warned = 1;
}
prog_stop (dp, SIGTERM);
@@ -1257,7 +1262,7 @@ prog_stop (struct prog *prog, int sig)
recompute_alarm = 1;
}
}
- debug (1, ("Stopping %s (%lu)", prog->tag, (unsigned long) prog->pid));
+ debug (1, ("stopping %s (%lu)", prog->tag, (unsigned long) prog->pid));
kill (prog->pid, sig);
}
@@ -1266,7 +1271,7 @@ prog_stop_all (int sig)
{
struct prog *prog;
- debug (1, ("Stopping all components (signal %d)", sig));
+ debug (1, ("stopping all components (signal %d)", sig));
for (prog = progtail; prog; prog = prog->prev)
if (IS_PROG (prog)
&& (prog->v.p.status == status_enabled
@@ -1435,7 +1440,7 @@ send_msg (char *rcpts, const char *msg_text)
}
if (child_pid)
- /*FIXME: SIGCHLD Handler? */
+ /*FIXME: reg program */
return;
/* Child process */
@@ -1628,15 +1633,18 @@ progman_cleanup (int expect_term)
struct prog *prog = prog_lookup_by_pid (pid);
if (!prog)
{
+ print_status (_("subprocess"), pid, status, expect_term);
+ /*
logmsg (LOG_NOTICE,
_("subprocess %lu finished"),
(unsigned long) pid);
+ */
continue;
}
- print_status (prog->tag, prog->pid, status, expect_term);
prog->pid = 0;
if (IS_PROG (prog))
{
+ print_status (prog->tag, pid, status, expect_term);
if (prog->v.p.comp->mode == pies_comp_inetd)
{
prog_stop_redirectors (prog);
@@ -1709,8 +1717,11 @@ progman_cleanup (int expect_term)
}
else
{
- /* It was a redirector of an already finished inetd process. */
- debug (1, (_("removing inetd redirector %s"), prog->tag));
+ /* It was a redirector of an already finished process. */
+ if (!(WIFSIGNALED (status) && WTERMSIG (status) == SIGKILL))
+ print_status (prog->tag, pid, status, expect_term);
+ debug (1, (_("removing redirector %s, pid=%lu"),
+ prog->tag, (unsigned long)pid));
destroy_prog (&prog);
}
}

Return to:

Send suggestions and report system problems to the System administrator.