Be less harsh and don't error out entirely - sinit - suckless init
 (HTM) git clone git://git.suckless.org/sinit
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit fd0f19b55727f4cc005bfa2c7959134e4a682617
 (DIR) parent 51664faebcc10b53a1a78cff95f0efc04a2c7f8e
 (HTM) Author: sin <sin@2f30.org>
       Date:   Thu,  6 Feb 2014 11:27:32 +0000
       
       Be less harsh and don't error out entirely
       
       Diffstat:
         M sinit.c                             |      28 ++++++++++++++--------------
         M util.h                              |       1 +
         M util/eprintf.c                      |      18 ++++++++++++++----
       
       3 files changed, 29 insertions(+), 18 deletions(-)
       ---
 (DIR) diff --git 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);
 (DIR) diff --git a/util.h b/util.h
       @@ -3,3 +3,4 @@
        
        void enprintf(int, const char *, ...);
        void eprintf(const char *, ...);
       +void weprintf(const char *, ...);
 (DIR) diff --git 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);
       +        }
       +}