aboutsummaryrefslogtreecommitdiff
path: root/src/diag.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/diag.c')
-rw-r--r--src/diag.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/src/diag.c b/src/diag.c
index fe057d0..bb64ab9 100644
--- a/src/diag.c
+++ b/src/diag.c
@@ -42,17 +42,42 @@ syslog_printer (int prio, const char *fmt, va_list ap)
#endif
}
+static FILE *
+stderr_open ()
+{
+ if (!init_process)
+ return stderr;
+ else
+ {
+ int fd = console_open (O_WRONLY|O_NOCTTY|O_NDELAY);
+ if (fd == -1)
+ return NULL;
+ return fdopen (fd, "w");
+ }
+}
+
+static void
+stderr_close (FILE *fp)
+{
+ if (init_process)
+ fclose (fp);
+}
+
void
vlogmsg (int prio, const char *fmt, va_list ap)
{
if (DIAG_OUTPUT (DIAG_TO_STDERR))
{
va_list aq;
- fprintf (stderr, "%s: ", program_name);
+ FILE *fp = stderr_open ();
+ if (!fp)
+ return;
+ fprintf (fp, "%s: ", program_name);
va_copy (aq, ap);
- vfprintf (stderr, fmt, aq);
+ vfprintf (fp, fmt, aq);
va_end (aq);
- fprintf (stderr, "\n");
+ fprintf (fp, "\n");
+ stderr_close (fp);
}
if (DIAG_OUTPUT (DIAG_TO_SYSLOG))

Return to:

Send suggestions and report system problems to the System administrator.