changeset 780:6cc69be43c42

Have error_msg() and friends set TT.exitval to 1 if it's still 0, clean out other places that were setting it that no longer need to.
author Rob Landley <rob@landley.net>
date Wed, 02 Jan 2013 02:00:35 -0600
parents 90e98cdb1b7c
children b300eb824c70
files lib/lib.c toys/other/dos2unix.c toys/other/losetup.c toys/other/realpath.c toys/other/truncate.c toys/posix/cat.c toys/posix/chgrp.c toys/posix/cksum.c toys/posix/cut.c toys/posix/df.c toys/posix/expand.c toys/posix/head.c toys/posix/kill.c toys/posix/mkdir.c toys/posix/mkfifo.c toys/posix/rm.c toys/posix/touch.c toys/posix/wc.c
diffstat 18 files changed, 16 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/lib/lib.c	Mon Dec 31 14:38:13 2012 -0600
+++ b/lib/lib.c	Wed Jan 02 02:00:35 2013 -0600
@@ -26,6 +26,7 @@
   else s+=2;
   if (err) fprintf(stderr, s, strerror(err));
   putc('\n', stderr);
+  if (!toys.exitval) toys.exitval++;
 }
 
 void error_msg(char *msg, ...)
@@ -61,7 +62,6 @@
   verror_msg(msg, 0, va);
   va_end(va);
 
-  if (!toys.exitval) toys.exitval++;
   if (toys.rebound) longjmp(*toys.rebound, 1);
   else exit(toys.exitval);
 }
@@ -76,7 +76,6 @@
   verror_msg(msg, errno, va);
   va_end(va);
 
-  if (!toys.exitval) toys.exitval++;
   if (toys.rebound) longjmp(*toys.rebound, 1);
   else exit(toys.exitval);
 }
--- a/toys/other/dos2unix.c	Mon Dec 31 14:38:13 2012 -0600
+++ b/toys/other/dos2unix.c	Wed Jan 02 02:00:35 2013 -0600
@@ -33,10 +33,7 @@
     int len, in, out;
 
     len = read(fd, toybuf+(sizeof(toybuf)/2), sizeof(toybuf)/2);
-    if (len<0) {
-      perror_msg("%s",name);
-      toys.exitval = 1;
-    }
+    if (len<0) perror_msg("%s",name);
     if (len<1) break;
 
     for (in = out = 0; in < len; in++) {
--- a/toys/other/losetup.c	Mon Dec 31 14:38:13 2012 -0600
+++ b/toys/other/losetup.c	Wed Jan 02 02:00:35 2013 -0600
@@ -61,7 +61,7 @@
 static void loopback_setup(char *device, char *file)
 {
   struct loop_info64 *loop = (void *)(toybuf+32);
-  int rc = 0, lfd = -1, ffd;
+  int lfd = -1, ffd;
   unsigned flags = toys.optflags;
 
   // Open file (ffd) and loop device (lfd)
@@ -89,7 +89,6 @@
     if (errno == ENXIO && (flags & (FLAG_a|FLAG_j))) return;
     if (errno != ENXIO || !file) {
       perror_msg("%s", device ? device : "-f");
-      rc = 1;
       goto done;
     }
   }
@@ -102,7 +101,6 @@
   if (flags & (FLAG_c|FLAG_d)) {
     if (ioctl(lfd, (flags & FLAG_c) ? LOOP_SET_CAPACITY : LOOP_CLR_FD, 0)) {
       perror_msg("%s", device);
-      rc = 1;
       goto done;
     }
   // Associate file with this device?
@@ -129,7 +127,6 @@
 done:
   if (file) close(ffd);
   if (lfd != -1) close(lfd);
-  toys.exitval |= rc;
 }
 
 // Perform an action on all currently existing loop devices
--- a/toys/other/realpath.c	Mon Dec 31 14:38:13 2012 -0600
+++ b/toys/other/realpath.c	Wed Jan 02 02:00:35 2013 -0600
@@ -20,9 +20,7 @@
   char **s = toys.optargs;
 
   for (s = toys.optargs; *s; s++) {
-    if (!realpath(*s, toybuf)) {
-      perror_msg("cannot access '%s'", *s);
-      toys.exitval = 1;
-    } else xputs(toybuf);
+    if (!realpath(*s, toybuf)) perror_msg("%s", *s);
+    else xputs(toybuf);
   }
 }
--- a/toys/other/truncate.c	Mon Dec 31 14:38:13 2012 -0600
+++ b/toys/other/truncate.c	Wed Jan 02 02:00:35 2013 -0600
@@ -26,10 +26,7 @@
 static void do_truncate(int fd, char *name)
 {
   if (fd<0) return;
-  if (ftruncate(fd, TT.size)) {
-    perror_msg("failed to set '%s' to '%ld'", name, TT.size);
-    toys.exitval = EXIT_FAILURE;
-  }
+  if (ftruncate(fd, TT.size)) perror_msg("'%s' to '%ld'", name, TT.size);
 }
 
 void truncate_main(void)
--- a/toys/posix/cat.c	Mon Dec 31 14:38:13 2012 -0600
+++ b/toys/posix/cat.c	Wed Jan 02 02:00:35 2013 -0600
@@ -25,10 +25,7 @@
 
   for (;;) {
     len = read(fd, toybuf, size);
-    if (len<0) {
-      perror_msg("%s",name);
-      toys.exitval = EXIT_FAILURE;
-    }
+    if (len<0) perror_msg("%s",name);
     if (len<1) break;
     xwrite(1, toybuf, len);
   }
--- a/toys/posix/chgrp.c	Mon Dec 31 14:38:13 2012 -0600
+++ b/toys/posix/chgrp.c	Wed Jan 02 02:00:35 2013 -0600
@@ -60,8 +60,7 @@
         toys.which->name[2]=='o' && TT.group_name ? ":" : "",
         TT.group_name ? TT.group_name : "", path);
     if (ret == -1 && !(toys.optflags & FLAG_f))
-      perror_msg("changing owner:group of '%s' to '%s:%s'", path,
-        TT.owner_name, TT.group_name);
+      perror_msg("'%s' to '%s:%s'", path, TT.owner_name, TT.group_name);
     free(path);
   }
   toys.exitval |= ret;
--- a/toys/posix/cksum.c	Mon Dec 31 14:38:13 2012 -0600
+++ b/toys/posix/cksum.c	Wed Jan 02 02:00:35 2013 -0600
@@ -51,10 +51,7 @@
     int len, i;
 
     len = read(fd, toybuf, sizeof(toybuf));
-    if (len<0) {
-      perror_msg("%s",name);
-      toys.exitval = EXIT_FAILURE;
-    }
+    if (len<0) perror_msg("%s", name);
     if (len<1) break;
 
     llen += len;
--- a/toys/posix/cut.c	Mon Dec 31 14:38:13 2012 -0600
+++ b/toys/posix/cut.c	Wed Jan 02 02:00:35 2013 -0600
@@ -127,7 +127,6 @@
         int fd = open(*argv, O_RDONLY, 0);
         if(fd < 0) {//if file not present then continue with other files.
           perror_msg(*argv);
-          toys.exitval = EXIT_FAILURE;
           continue;
         }
         do_cut(fd);
--- a/toys/posix/df.c	Mon Dec 31 14:38:13 2012 -0600
+++ b/toys/posix/df.c	Wed Jan 02 02:00:35 2013 -0600
@@ -120,7 +120,6 @@
       // Stat it (complain if we can't).
       if(stat(*next, &st)) {
         perror_msg("`%s'", *next);
-        toys.exitval = 1;
         continue;
       }
 
--- a/toys/posix/expand.c	Mon Dec 31 14:38:13 2012 -0600
+++ b/toys/posix/expand.c	Wed Jan 02 02:00:35 2013 -0600
@@ -39,7 +39,6 @@
     len = read(fd, toybuf, sizeof(toybuf));
     if (len<0) {
       perror_msg("%s", name);
-      toys.exitval = 1;
       return;
     }
     if (!len) break;
--- a/toys/posix/head.c	Mon Dec 31 14:38:13 2012 -0600
+++ b/toys/posix/head.c	Wed Jan 02 02:00:35 2013 -0600
@@ -39,10 +39,7 @@
 
   while (lines) {
     len = read(fd, toybuf, size);
-    if (len<0) {
-      perror_msg("%s",name);
-      toys.exitval = EXIT_FAILURE;
-    }
+    if (len<0) perror_msg("%s",name);
     if (len<1) break;
 
     for(i=0; i<len;) if (toybuf[i++] == '\n' && !--lines) break;
--- a/toys/posix/kill.c	Mon Dec 31 14:38:13 2012 -0600
+++ b/toys/posix/kill.c	Wed Jan 02 02:00:35 2013 -0600
@@ -62,9 +62,6 @@
     char *arg = *(args++);
 
     pid = strtol(arg, &tmp, 10);
-    if (*tmp || kill(pid, signum) < 0) {
-      error_msg("unknown pid '%s'", arg);
-      toys.exitval = EXIT_FAILURE;
-    }
+    if (*tmp || kill(pid, signum) < 0) error_msg("unknown pid '%s'", arg);
   }
 }
--- a/toys/posix/mkdir.c	Mon Dec 31 14:38:13 2012 -0600
+++ b/toys/posix/mkdir.c	Wed Jan 02 02:00:35 2013 -0600
@@ -69,10 +69,5 @@
 
   if(toys.optflags&FLAG_m) TT.mode = string_to_mode(TT.arg_mode, 0777);
 
-  for (s=toys.optargs; *s; s++) {
-    if (do_mkdir(*s)) {
-      perror_msg("'%s'", *s);
-      toys.exitval = 1;
-    }
-  }
+  for (s=toys.optargs; *s; s++) if (do_mkdir(*s)) perror_msg("'%s'", *s);
 }
--- a/toys/posix/mkfifo.c	Mon Dec 31 14:38:13 2012 -0600
+++ b/toys/posix/mkfifo.c	Wed Jan 02 02:00:35 2013 -0600
@@ -30,10 +30,6 @@
   TT.mode = 0666;
   if (toys.optflags & FLAG_m) TT.mode = string_to_mode(TT.m_string, 0);
 
-  for (s = toys.optargs; *s; s++) {
-    if (mknod(*s, S_IFIFO | TT.mode, 0) < 0) {
-      perror_msg("cannot create fifo '%s'", *s);
-      toys.exitval = 1;
-    }
-  }
+  for (s = toys.optargs; *s; s++)
+    if (mknod(*s, S_IFIFO | TT.mode, 0) < 0) perror_msg("%s", *s);
 }
--- a/toys/posix/rm.c	Mon Dec 31 14:38:13 2012 -0600
+++ b/toys/posix/rm.c	Wed Jan 02 02:00:35 2013 -0600
@@ -64,7 +64,6 @@
 skip:
   if (unlinkat(fd, try->name, using)) {
     perror_msg("%s", try->name);
-    toys.exitval = 1;
 nodelete:
     if (try->parent) try->parent->symlink = (char *)1;
   }
@@ -82,7 +81,6 @@
   for (s = toys.optargs; *s; s++) {
     if (!strcmp(*s, "/")) {
       error_msg("rm /. if you mean it");
-      toys.exitval = 1;
       continue;
     }
 
--- a/toys/posix/touch.c	Mon Dec 31 14:38:13 2012 -0600
+++ b/toys/posix/touch.c	Wed Jan 02 02:00:35 2013 -0600
@@ -116,9 +116,6 @@
     if ((!flag || !fetch(*ss, tv, flag)) && !utimes(*ss, tv)) ss++;
     else if (toys.optflags & FLAG_c) ss++;
     else if (-1 != (fd = open(*ss, O_CREAT, 0666))) close(fd);
-    else {
-      perror_msg("'%s'", *ss++);
-      toys.exitval = 1;
-    }
+    else perror_msg("'%s'", *ss++);
   }
 }
--- a/toys/posix/wc.c	Mon Dec 31 14:38:13 2012 -0600
+++ b/toys/posix/wc.c	Wed Jan 02 02:00:35 2013 -0600
@@ -52,10 +52,7 @@
 
   for (;;) {
     len = read(fd, toybuf, sizeof(toybuf));
-    if (len<0) {
-      perror_msg("%s",name);
-      toys.exitval = 1;
-    }
+    if (len<0) perror_msg("%s", name);
     if (len<1) break;
     for (i=0; i<len; i+=clen) {
       wchar_t wchar;