aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sinit.c28
-rw-r--r--util.h1
-rw-r--r--util/eprintf.c18
3 files changed, 29 insertions, 18 deletions
diff --git a/sinit.c b/sinit.c
index dee71b1..e9b12e3 100644
--- a/sinit.c
+++ b/sinit.c
@@ -58,19 +58,21 @@ main(void)
unlink(fifopath);
umask(0);
if (mkfifo(fifopath, 0600) < 0)
- eprintf("mkfifo %s:");
+ weprintf("sinit: mkfifo %s:");
fd = open(fifopath, O_RDWR | O_NONBLOCK);
if (fd < 0)
- eprintf("open %s:", fifopath);
- while (1) {
- FD_ZERO(&rfds);
- FD_SET(fd, &rfds);
- n = select(fd + 1, &rfds, NULL, NULL, NULL);
- if (n < 0)
- eprintf("select:");
- if (FD_ISSET(fd, &rfds))
- dispatchcmd(fd);
+ weprintf("sinit: open %s:", fifopath);
+ if (fd >= 0) {
+ while (1) {
+ FD_ZERO(&rfds);
+ FD_SET(fd, &rfds);
+ n = select(fd + 1, &rfds, NULL, NULL, NULL);
+ if (n < 0)
+ eprintf("sinit: select:");
+ if (FD_ISSET(fd, &rfds))
+ dispatchcmd(fd);
+ }
}
return EXIT_SUCCESS;
@@ -97,9 +99,7 @@ dispatchcmd(int fd)
n = read(fd, buf, sizeof(buf) - 1);
if (n < 0)
- eprintf("read:");
- if (n == 0)
- return;
+ weprintf("sinit: read:");
buf[n] = '\0';
p = strchr(buf, '\n');
if (p)
@@ -119,7 +119,7 @@ spawn(const char *file, char *const argv[])
pid = fork();
if (pid < 0)
- eprintf("fork:");
+ weprintf("sinit: fork:");
if (pid == 0) {
setsid();
setpgid(0, 0);
diff --git a/util.h b/util.h
index 4fe1391..af96e0e 100644
--- a/util.h
+++ b/util.h
@@ -3,3 +3,4 @@
void enprintf(int, const char *, ...);
void eprintf(const char *, ...);
+void weprintf(const char *, ...);
diff --git a/util/eprintf.c b/util/eprintf.c
index 6d6fa65..af05686 100644
--- a/util/eprintf.c
+++ b/util/eprintf.c
@@ -6,8 +6,6 @@
#include "../util.h"
-char *argv0;
-
static void venprintf(int, const char *, va_list);
void
@@ -33,8 +31,6 @@ enprintf(int status, const char *fmt, ...)
void
venprintf(int status, const char *fmt, va_list ap)
{
- fprintf(stderr, "%s: ", argv0);
-
vfprintf(stderr, fmt, ap);
if(fmt[0] && fmt[strlen(fmt)-1] == ':') {
@@ -44,3 +40,17 @@ venprintf(int status, const char *fmt, va_list ap)
exit(status);
}
+
+void
+weprintf(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
+ fputc(' ', stderr);
+ perror(NULL);
+ }
+}