From f42fa2bea7560cdc4537b73cc0a7c69020a7945d Mon Sep 17 00:00:00 2001 From: Tormod Volden Date: Fri, 4 Nov 2016 23:11:43 +0100 Subject: [PATCH] Applications/util: Ensure all commands return exit code Also remove parentheses from return statements while we're at it. Signed-off-by: Tormod Volden --- Applications/util/dd.c | 39 ++++++++++++++++++++++-------------- Applications/util/du.c | 5 ++--- Applications/util/ed.c | 3 ++- Applications/util/factor.c | 1 + Applications/util/fforth.c | 2 +- Applications/util/id.c | 2 +- Applications/util/marksman.c | 1 + Applications/util/od.c | 2 +- Applications/util/passwd.c | 1 + Applications/util/prtroot.c | 2 +- Applications/util/reboot.c | 1 + Applications/util/sed.c | 2 +- Applications/util/sort.c | 2 +- Applications/util/ssh.c | 2 +- Applications/util/tar.c | 12 ++++------- Applications/util/tee.c | 2 +- Applications/util/termcap.c | 2 +- Applications/util/tr.c | 2 +- Applications/util/uniq.c | 2 +- Applications/util/uptime.c | 1 + Applications/util/uue.c | 2 +- 21 files changed, 49 insertions(+), 39 deletions(-) diff --git a/Applications/util/dd.c b/Applications/util/dd.c index be694f19..d1f94889 100644 --- a/Applications/util/dd.c +++ b/Applications/util/dd.c @@ -54,7 +54,7 @@ BOOL intflag; static char localbuf[8192]; -void main(int argc, char *argv[]) +int main(int argc, char *argv[]) { char *str; char *cp; @@ -73,6 +73,7 @@ void main(int argc, char *argv[]) long outtotal; long inmax; char *buf; + int ret = 1; infile = NULL; outfile = NULL; @@ -87,7 +88,7 @@ void main(int argc, char *argv[]) cp = strchr(str, '='); if (cp == NULL) { fprintf(stderr, "Bad dd argument\n"); - return; + return 1; } *cp++ = '\0'; @@ -100,7 +101,7 @@ void main(int argc, char *argv[]) case PAR_IF: if (infile) { fprintf(stderr, "Multiple input files illegal\n"); - return; + return 1; } infile = cp; break; @@ -108,7 +109,7 @@ void main(int argc, char *argv[]) case PAR_OF: if (outfile) { fprintf(stderr, "Multiple output files illegal\n"); - return; + return 1; } outfile = cp; break; @@ -117,7 +118,7 @@ void main(int argc, char *argv[]) blocksize = getnum(cp); if (blocksize <= 0) { fprintf(stderr, "Bad block size value\n"); - return; + return 1; } break; @@ -133,7 +134,7 @@ void main(int argc, char *argv[]) seekval = getnum(cp); if (seekval < 0) { fprintf(stderr, "Bad seek value\n"); - return; + return 1; } break; @@ -141,30 +142,30 @@ void main(int argc, char *argv[]) skipval = getnum(cp); if (skipval < 0) { fprintf(stderr, "Bad skip value\n"); - return; + return 1; } break; default: fprintf(stderr, "Unknown dd parameter\n"); - return; + return 1; } } if (infile == NULL) { fprintf(stderr, "No input file specified\n"); - return; + return 1; } if (outfile == NULL) { fprintf(stderr, "No output file specified\n"); - return; + return 1; } buf = localbuf; if (blocksize > sizeof(localbuf)) { buf = malloc(blocksize); if (buf == NULL) { fprintf(stderr, "Cannot allocate buffer\n"); - return; + return 1; } } intotal = 0; @@ -175,7 +176,7 @@ void main(int argc, char *argv[]) perror(infile); if (buf != localbuf) free(buf); - return; + return 1; } outfd = creat(outfile, 0666); if (outfd < 0) { @@ -183,7 +184,7 @@ void main(int argc, char *argv[]) close(infd); if (buf != localbuf) free(buf); - return; + return 1; } if (skipval) { if (lseek(infd, skipval * blocksize, 0) < 0) { @@ -230,14 +231,20 @@ void main(int argc, char *argv[]) break; } - if (incc < 0) + if (incc < 0) { perror(infile); + goto cleanup; + } + + ret = 0; cleanup: close(infd); - if (close(outfd) < 0) + if (close(outfd) < 0) { perror(outfile); + ret = 1; + } if (buf != localbuf) free(buf); @@ -247,6 +254,8 @@ void main(int argc, char *argv[]) printf("%d+%d records out\n", outtotal / blocksize, (outtotal % blocksize) != 0); + + return ret; } diff --git a/Applications/util/du.c b/Applications/util/du.c index 2ab2ed0a..5f505179 100644 --- a/Applications/util/du.c +++ b/Applications/util/du.c @@ -79,7 +79,7 @@ int makedname(char *d, char *f, char *out, int outlen) int length; length = strlen(f); - if (strlen(d) + length + 2 > outlen) return (0); + if (strlen(d) + length + 2 > outlen) return 0; for (cp = out; *d; *cp++ = *d++) ; if (*(cp - 1) != '/') *cp++ = '/'; while (length--) *cp++ = *f++; @@ -223,6 +223,5 @@ int main(int argc, char *argv[]) dodir(startdir, levels, 0); } while (optind < argc); - return (0); + return 0; } - diff --git a/Applications/util/ed.c b/Applications/util/ed.c index 301e304e..70b805ce 100644 --- a/Applications/util/ed.c +++ b/Applications/util/ed.c @@ -67,7 +67,7 @@ static LINE *findline(NUM); BOOL intflag; -void main(int argc, char *argv[]) +int main(int argc, char *argv[]) { if (!initedit()) return; @@ -91,6 +91,7 @@ void main(int argc, char *argv[]) docommands(); termedit(); + return 0; } diff --git a/Applications/util/factor.c b/Applications/util/factor.c index 631f99ad..19a3d485 100644 --- a/Applications/util/factor.c +++ b/Applications/util/factor.c @@ -96,4 +96,5 @@ int main(int argc,char *argv[]) if (NULL == gets_s(s, LINE_MAX)) break; factor(s); } + return 0; } diff --git a/Applications/util/fforth.c b/Applications/util/fforth.c index a212d6b0..4fb3eb9b 100644 --- a/Applications/util/fforth.c +++ b/Applications/util/fforth.c @@ -2356,5 +2356,5 @@ int main(int argc, const char* argv[]) #endif w->code(w); } + return 0; } - diff --git a/Applications/util/id.c b/Applications/util/id.c index c528a722..d4ae736a 100644 --- a/Applications/util/id.c +++ b/Applications/util/id.c @@ -48,5 +48,5 @@ int main(int argc, char *argv[]) printf("egid=%d ", egid); printf("\n"); - return(0); + return 0; } diff --git a/Applications/util/marksman.c b/Applications/util/marksman.c index b71d7597..344120c3 100644 --- a/Applications/util/marksman.c +++ b/Applications/util/marksman.c @@ -854,4 +854,5 @@ int main(int argc, char *argv[]) parse_line(buf); } parse_line(""); + return 0; } diff --git a/Applications/util/od.c b/Applications/util/od.c index a83ae928..6e582a29 100644 --- a/Applications/util/od.c +++ b/Applications/util/od.c @@ -304,5 +304,5 @@ int main(int argc, char *argv[]) addrout(off); printf("\n"); - return(0); + return 0; } diff --git a/Applications/util/passwd.c b/Applications/util/passwd.c index 62242fe7..8b6b5bde 100644 --- a/Applications/util/passwd.c +++ b/Applications/util/passwd.c @@ -137,4 +137,5 @@ int main(int argc, char *argv[]) } fprintf(stderr, "They don't match; try again.\n"); } + return 0; } diff --git a/Applications/util/prtroot.c b/Applications/util/prtroot.c index 431daacc..8ca4d605 100644 --- a/Applications/util/prtroot.c +++ b/Applications/util/prtroot.c @@ -87,6 +87,6 @@ int main(int argc, const char *argv[]) } } done(UNKNOWN_DEV, 1); - return (0); /* not reached */ + return 0; /* not reached */ } diff --git a/Applications/util/reboot.c b/Applications/util/reboot.c index e712b88f..90f92bc7 100644 --- a/Applications/util/reboot.c +++ b/Applications/util/reboot.c @@ -19,4 +19,5 @@ int main(int argc, char *argv[]) uadmin(A_REBOOT,0,0); /* If we get here there was an error! */ perror(argv[0]); + return 1; } diff --git a/Applications/util/sed.c b/Applications/util/sed.c index 348f7475..d0fbd387 100644 --- a/Applications/util/sed.c +++ b/Applications/util/sed.c @@ -326,7 +326,7 @@ int main(int argc, char *argv[]) resolve(); /* resolve label table indirections */ execute(); /* execute commands */ quit(0); /* everything was O.K. if we got here */ - return(0); + return 0; } diff --git a/Applications/util/sort.c b/Applications/util/sort.c index 829bb324..c99d2d98 100644 --- a/Applications/util/sort.c +++ b/Applications/util/sort.c @@ -440,7 +440,7 @@ int main(int argc, char **argv) exit(0); files_merge(nr_of_files); - return(0); + return 0; } /* Adjust_options() assigns all global variables set also in the fields diff --git a/Applications/util/ssh.c b/Applications/util/ssh.c index 2617c2f8..38f6b26f 100644 --- a/Applications/util/ssh.c +++ b/Applications/util/ssh.c @@ -267,7 +267,7 @@ int main(int argc, char *argval[]) /* Check for User-Requested Exit back to Login Prompt */ if (strcmp(cmd, "exit") == 0) - return (0); /* Quit if requested */ + return 0; /* Quit if requested */ /* Check for User request to change Current Working Directory */ else if (strcmp(cmd, "cd") == 0) { diff --git a/Applications/util/tar.c b/Applications/util/tar.c index be9ec59d..cb835813 100644 --- a/Applications/util/tar.c +++ b/Applications/util/tar.c @@ -301,7 +301,7 @@ static void storedir( char *name){ case S_IFIFO: h.type='6'; break; - defailt: + default: fprintf(stderr,"unhandled file type error\n"); exit(1); } @@ -610,7 +610,6 @@ static void create( char *argv[] ){ perror("writing end of archive"); /* close outfile */ close(outfile); - exit(0); } @@ -650,10 +649,7 @@ int main( int argc, char *argv[] ){ create( argv ); default: fprintf(stderr, "tar: option x,c, or t must be used\n" ); + exit(1); } - -} - - - - + exit(0); +} diff --git a/Applications/util/tee.c b/Applications/util/tee.c index cb56b541..44188501 100644 --- a/Applications/util/tee.c +++ b/Applications/util/tee.c @@ -100,5 +100,5 @@ int main(int argc, char *argv[]) for (i = 0; i < s; i++) /* Close all fd's */ close(fd[i]); - return(0); + return 0; } diff --git a/Applications/util/termcap.c b/Applications/util/termcap.c index c794345f..c858255a 100644 --- a/Applications/util/termcap.c +++ b/Applications/util/termcap.c @@ -94,7 +94,7 @@ char *argv[]; Print("Generated by numeric \"-\"", "k4"); Print("Generated by numeric \"5\"", "k5"); - return (0); + return 0; } diff --git a/Applications/util/tr.c b/Applications/util/tr.c index 72a98b2e..9642af93 100644 --- a/Applications/util/tr.c +++ b/Applications/util/tr.c @@ -74,7 +74,7 @@ int main(int argc, char *argv[]) convert(); - return (0); + return 0; } void convert(void) diff --git a/Applications/util/uniq.c b/Applications/util/uniq.c index 1eefe95c..3b401486 100644 --- a/Applications/util/uniq.c +++ b/Applications/util/uniq.c @@ -97,7 +97,7 @@ int main(int argc, char *argv[]) uniq(); fflush(stdout); - return (0); + return 0; } char *skip(char *s) diff --git a/Applications/util/uptime.c b/Applications/util/uptime.c index 44cdc40e..3bbbf33c 100644 --- a/Applications/util/uptime.c +++ b/Applications/util/uptime.c @@ -61,4 +61,5 @@ int main(int argc, char *argv[]) printload(loadavg[2]); } printf("\n"); + return 0; } diff --git a/Applications/util/uue.c b/Applications/util/uue.c index b5de9c8d..2812cda2 100644 --- a/Applications/util/uue.c +++ b/Applications/util/uue.c @@ -100,7 +100,7 @@ int main(int argc, char *argv[]) fprintf(outp, "end\n"); fclose(outp); - return (0); + return 0; } -- 2.34.1