aboutsummaryrefslogtreecommitdiff
path: root/src/diag.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-01-06 17:04:28 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2013-01-06 17:04:28 +0200
commit1bfa33ac7c167cd863b88a5cac7690d511851e6e (patch)
treea892e281cba3ea127af5faf5da81ff2cc0c3aae9 /src/diag.c
parent4f7c28158308563dcad912d87a0031d095d4690a (diff)
downloadpies-1bfa33ac7c167cd863b88a5cac7690d511851e6e.tar.gz
pies-1bfa33ac7c167cd863b88a5cac7690d511851e6e.tar.bz2
Fix runlevel transition algorithm, implement SysV-style fifo interface.
* src/prog.h: New file. * src/Makefile.am: Add new file. * src/cmdline.opt: New option --telinit (-T). * src/diag.c (vlogmsg): In sysvin it mode, write directly to the console. Close it when finished. * src/pies.c (_cb_initdefault, _cb_runlevels): Use is_valid_runlevel to check if the specified runlevels are ok. (main): In sysvinit mode, reset action to ACTION_CONT. * src/pies.h (progman_filter): New proto. (progman_accept,register_socket): Change signature. (deregister_socket): New proto. (register_program_socket): New proto. * src/progman.c: Move constant and adatatype definitions to prog.h (prog_stop): Remove static qualifier. (console_open): Likewise. (progman_accept): Use new socket API. (progman_stop): Correctly handle timeouts. (progman_foreach): New function. * src/socket.c: Register all sockets along with their handlers in a doubly-linked list. (sockinst): New struct. (register_socket,deregister_socket): New functions. (register_program_socket): New function. (pies_pause): Traverse the list to find which fd has changed. Use its registered handler to handle the event. * src/sysvinit.c: Include prog.h (is_valid_runlevel): New function. (sysvinit_fifo_handler,check_fifo): New static functions. (inittrans): Fix transition algorithm. (telinit): New function.
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.