commit 8fcc4a561cbdbfb4bf67a2b3f7574d35b7c10e49
Author: Roberto E. Vargas Caballero <[email protected]>
Date:   Sun Feb 22 16:30:21 2015 +0000

    Add utmp string in error messages
    
    Utmp may be executed from st, and sometimes is difficult to see
    who generate the error, so this patch helps.

diff --git a/bsd.c b/bsd.c
index a882f31..1367c64 100644
--- a/bsd.c
+++ b/bsd.c
@@ -26,17 +26,17 @@ addutmp(void)
                host = "-";
 
        if (strlen(pw->pw_name) > sizeof(utmp.ut_name))
-               die("incorrect username %s", pw->pw_name);
+               die("utmp:incorrect username %s", pw->pw_name);
 
        if ((pts = ttyname(STDIN_FILENO)) == NULL)
-               die("error getting pty name:%s", strerror(errno));
+               die("utmp:error getting pty name:%s", strerror(errno));
 
        for (cp = pts + strlen(pts) - 1; isdigit(*cp); --cp)
                /* nothing */;
 
        ptyid = atoi(++cp);
        if (ptyid > 999 || strlen(pts + 5) > sizeof(utmp.ut_line))
-               die("Incorrect pts name %s\n", pts);
+               die("utmp:Incorrect pts name %s\n", pts);
 
        /* remove /dev/ from pts */
        strncpy(utmp.ut_line, pts + 5, sizeof(utmp.ut_line));
diff --git a/posix.c b/posix.c
index 9d8b562..3cc368e 100644
--- a/posix.c
+++ b/posix.c
@@ -70,17 +70,17 @@ addutmp(void)
        char *pts, *cp, buf[5] = {'x'};
 
        if (strlen(pw->pw_name) > sizeof(utmp.ut_user))
-               die("incorrect username %s", pw->pw_name);
+               die("utmp:incorrect username %s", pw->pw_name);
 
        if ((pts = ttyname(STDIN_FILENO)) == NULL)
-               die("error getting pty name\n");
+               die("utmp:error getting pty name\n");
 
        for (cp = pts + strlen(pts) - 1; isdigit(*cp); --cp)
                /* nothing */;
 
        ptyid = atoi(++cp);
        if (ptyid > 999 || strlen(pts + 5) > sizeof(utmp.ut_line))
-               die("Incorrect pts name %s\n", pts);
+               die("utmp:Incorrect pts name %s\n", pts);
        sprintf(buf + 1, "%03d", ptyid);
        strncpy(utmp.ut_id, buf, 4);
 
@@ -99,7 +99,7 @@ addutmp(void)
 
        setegid(egid);
        if(!pututxline(&utmp))
-               die("error adding utmp entry:%s", strerror(errno));
+               die("utmp:error adding utmp entry:%s", strerror(errno));
        setegid(gid);
        endutxent();
 }
@@ -115,7 +115,7 @@ delutmp(void)
                r->ut_tv.tv_usec = r->ut_tv.tv_sec = 0;
                setgid(egid);
                if (!pututxline(r))
-                       die("error removing utmp entry:%s", strerror(errno));
+                       die("utmp:error removing utmp entry:%s", 
strerror(errno));
                setgid(gid);
        }
        endutxent();
diff --git a/utmp.c b/utmp.c
index 9493e36..de54683 100644
--- a/utmp.c
+++ b/utmp.c
@@ -46,9 +46,9 @@ main(int argc, char *argv[])
        errno = 0;
        if ((pw = getpwuid(uid = getuid())) == NULL) {
                if(errno)
-                       die("getpwuid:%s", strerror(errno));
+                       die("utmp:getpwuid:%s", strerror(errno));
                else
-                       die("who are you?");
+                       die("utmp:who are you?");
        }
 
        setenv("LOGNAME", pw->pw_name, 1);
@@ -83,7 +83,7 @@ main(int argc, char *argv[])
                sigprocmask(SIG_UNBLOCK, &set, NULL);
 
                if (wait(&status) == -1)
-                       perror("error waiting child");
+                       perror("utmp:error waiting child");
                delutmp();
        }
        return (WIFEXITED(status)) ? WEXITSTATUS(status) : EXIT_FAILURE;

Reply via email to