chmod: process file series behaviour

continue processing files if a chmod on a file in a series failed, but return with an error status code.

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
This commit is contained in:
Hiltjo Posthuma 2014-04-23 22:00:08 +02:00 committed by sin
parent bd99b92e91
commit 90861840b7

14
chmod.c
View File

@ -11,6 +11,7 @@ static void chmodr(const char *);
static bool rflag = false; static bool rflag = false;
static char *modestr = ""; static char *modestr = "";
static mode_t mask = 0; static mode_t mask = 0;
static int ret = EXIT_SUCCESS;
static void static void
usage(void) usage(void)
@ -55,7 +56,7 @@ done:
for (; argc > 0; argc--, argv++) for (; argc > 0; argc--, argv++)
chmodr(argv[0]); chmodr(argv[0]);
return EXIT_SUCCESS; return ret;
} }
void void
@ -64,12 +65,17 @@ chmodr(const char *path)
struct stat st; struct stat st;
mode_t m; mode_t m;
if(stat(path, &st) == -1) if(stat(path, &st) == -1) {
eprintf("stat %s:", path); weprintf("stat %s:", path);
ret = EXIT_FAILURE;
return;
}
m = parsemode(modestr, st.st_mode, mask); m = parsemode(modestr, st.st_mode, mask);
if(chmod(path, m) == -1) if(chmod(path, m) == -1) {
weprintf("chmod %s:", path); weprintf("chmod %s:", path);
ret = EXIT_FAILURE;
}
if(rflag) if(rflag)
recurse(path, chmodr); recurse(path, chmodr);
} }