From 662a267c9b52f256b027d0f176a846b1d973ab99 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 2 Jan 2013 02:00:35 -0600 Subject: 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. --- lib/lib.c | 3 +-- toys/other/dos2unix.c | 5 +---- toys/other/losetup.c | 5 +---- toys/other/realpath.c | 6 ++---- toys/other/truncate.c | 5 +---- toys/posix/cat.c | 5 +---- toys/posix/chgrp.c | 3 +-- toys/posix/cksum.c | 5 +---- toys/posix/cut.c | 1 - toys/posix/df.c | 1 - toys/posix/expand.c | 1 - toys/posix/head.c | 5 +---- toys/posix/kill.c | 5 +---- toys/posix/mkdir.c | 7 +------ toys/posix/mkfifo.c | 8 ++------ toys/posix/rm.c | 2 -- toys/posix/touch.c | 5 +---- toys/posix/wc.c | 5 +---- 18 files changed, 16 insertions(+), 61 deletions(-) diff --git a/lib/lib.c b/lib/lib.c index 5b591d44..a21f6024 100644 --- a/lib/lib.c +++ b/lib/lib.c @@ -26,6 +26,7 @@ void verror_msg(char *msg, int err, va_list va) 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 @@ void error_exit(char *msg, ...) 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 @@ void perror_exit(char *msg, ...) verror_msg(msg, errno, va); va_end(va); - if (!toys.exitval) toys.exitval++; if (toys.rebound) longjmp(*toys.rebound, 1); else exit(toys.exitval); } diff --git a/toys/other/dos2unix.c b/toys/other/dos2unix.c index 59cd6a53..3e1feb0e 100644 --- a/toys/other/dos2unix.c +++ b/toys/other/dos2unix.c @@ -33,10 +33,7 @@ static void do_dos2unix(int fd, char *name) 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++) { diff --git a/toys/other/losetup.c b/toys/other/losetup.c index aa62222c..b455f355 100644 --- a/toys/other/losetup.c +++ b/toys/other/losetup.c @@ -61,7 +61,7 @@ todo: basic /dev file association 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 @@ static void loopback_setup(char *device, char *file) 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 @@ static void loopback_setup(char *device, char *file) 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 @@ static void loopback_setup(char *device, char *file) done: if (file) close(ffd); if (lfd != -1) close(lfd); - toys.exitval |= rc; } // Perform an action on all currently existing loop devices diff --git a/toys/other/realpath.c b/toys/other/realpath.c index dc75840b..ec981082 100644 --- a/toys/other/realpath.c +++ b/toys/other/realpath.c @@ -20,9 +20,7 @@ void realpath_main(void) 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); } } diff --git a/toys/other/truncate.c b/toys/other/truncate.c index 5ed9f61b..123ae553 100644 --- a/toys/other/truncate.c +++ b/toys/other/truncate.c @@ -26,10 +26,7 @@ GLOBALS( 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) diff --git a/toys/posix/cat.c b/toys/posix/cat.c index 431c7751..78881c4c 100644 --- a/toys/posix/cat.c +++ b/toys/posix/cat.c @@ -25,10 +25,7 @@ static void do_cat(int fd, char *name) 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); } diff --git a/toys/posix/chgrp.c b/toys/posix/chgrp.c index 6e1e16f0..e416f27f 100644 --- a/toys/posix/chgrp.c +++ b/toys/posix/chgrp.c @@ -60,8 +60,7 @@ static int do_chgrp(struct dirtree *node) 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; diff --git a/toys/posix/cksum.c b/toys/posix/cksum.c index 1192077c..9f6aa42b 100644 --- a/toys/posix/cksum.c +++ b/toys/posix/cksum.c @@ -51,10 +51,7 @@ static void do_cksum(int fd, char *name) 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; diff --git a/toys/posix/cut.c b/toys/posix/cut.c index af4a1d9a..6f813102 100644 --- a/toys/posix/cut.c +++ b/toys/posix/cut.c @@ -127,7 +127,6 @@ static void get_data(void) 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); diff --git a/toys/posix/df.c b/toys/posix/df.c index 5641ff34..957e80b2 100644 --- a/toys/posix/df.c +++ b/toys/posix/df.c @@ -120,7 +120,6 @@ void df_main(void) // Stat it (complain if we can't). if(stat(*next, &st)) { perror_msg("`%s'", *next); - toys.exitval = 1; continue; } diff --git a/toys/posix/expand.c b/toys/posix/expand.c index 789364bb..7bc37169 100644 --- a/toys/posix/expand.c +++ b/toys/posix/expand.c @@ -39,7 +39,6 @@ static void expand_file(int fd, char *name) len = read(fd, toybuf, sizeof(toybuf)); if (len<0) { perror_msg("%s", name); - toys.exitval = 1; return; } if (!len) break; diff --git a/toys/posix/head.c b/toys/posix/head.c index ba7b7385..e8517d44 100644 --- a/toys/posix/head.c +++ b/toys/posix/head.c @@ -39,10 +39,7 @@ static void do_head(int fd, char *name) 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; iname, using)) { perror_msg("%s", try->name); - toys.exitval = 1; nodelete: if (try->parent) try->parent->symlink = (char *)1; } @@ -82,7 +81,6 @@ void rm_main(void) for (s = toys.optargs; *s; s++) { if (!strcmp(*s, "/")) { error_msg("rm /. if you mean it"); - toys.exitval = 1; continue; } diff --git a/toys/posix/touch.c b/toys/posix/touch.c index e350e754..76884be2 100644 --- a/toys/posix/touch.c +++ b/toys/posix/touch.c @@ -116,9 +116,6 @@ void touch_main(void) 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++); } } diff --git a/toys/posix/wc.c b/toys/posix/wc.c index 56c9673a..3a6540b1 100644 --- a/toys/posix/wc.c +++ b/toys/posix/wc.c @@ -52,10 +52,7 @@ static void do_wc(int fd, char *name) 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