Fix potential exit status wraparound in chgrp(1)

This commit is contained in:
sin 2014-11-22 11:13:53 +00:00
parent 5c821d43ef
commit bf8e37625a

11
chgrp.c
View File

@ -11,8 +11,8 @@
#include "util.h" #include "util.h"
static int gid; static int gid;
static int failures = 0; static int status;
static int rflag = 0; static int rflag;
static struct stat st; static struct stat st;
static void static void
@ -26,7 +26,7 @@ chgrp(const char *path)
{ {
if (chown(path, st.st_uid, gid) < 0) { if (chown(path, st.st_uid, gid) < 0) {
weprintf("chown %s:", path); weprintf("chown %s:", path);
failures++; status = 1;
} }
if (rflag) if (rflag)
recurse(path, chgrp); recurse(path, chgrp);
@ -59,11 +59,10 @@ main(int argc, char *argv[])
while (*++argv) { while (*++argv) {
if (stat(*argv, &st) < 0) { if (stat(*argv, &st) < 0) {
weprintf("stat %s:", *argv); weprintf("stat %s:", *argv);
failures++; status = 1;
continue; continue;
} }
chgrp(*argv); chgrp(*argv);
} }
return status;
return failures;
} }