[hackers] [sbase] chmod: process file series behaviour || Hiltjo Posthuma

From: <git_AT_suckless.org>
Date: Thu, 24 Apr 2014 12:51:48 +0200

commit 90861840b76dd41da28c86da42a47e32ab97c8cf
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Wed Apr 23 22:00:08 2014 +0200

    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_AT_codemadness.org>

diff --git a/chmod.c b/chmod.c
index 63d800a..1f28a79 100644
--- a/chmod.c
+++ b/chmod.c
_AT_@ -11,6 +11,7 @@ static void chmodr(const char *);
 static bool rflag = false;
 static char *modestr = "";
 static mode_t mask = 0;
+static int ret = EXIT_SUCCESS;
 
 static void
 usage(void)
_AT_@ -55,7 +56,7 @@ done:
 
         for (; argc > 0; argc--, argv++)
                 chmodr(argv[0]);
- return EXIT_SUCCESS;
+ return ret;
 }
 
 void
_AT_@ -64,12 +65,17 @@ chmodr(const char *path)
         struct stat st;
         mode_t m;
 
- if(stat(path, &st) == -1)
- eprintf("stat %s:", path);
+ if(stat(path, &st) == -1) {
+ weprintf("stat %s:", path);
+ ret = EXIT_FAILURE;
+ return;
+ }
 
         m = parsemode(modestr, st.st_mode, mask);
- if(chmod(path, m) == -1)
+ if(chmod(path, m) == -1) {
                 weprintf("chmod %s:", path);
+ ret = EXIT_FAILURE;
+ }
         if(rflag)
                 recurse(path, chmodr);
 }
Received on Thu Apr 24 2014 - 12:51:48 CEST

This archive was generated by hypermail 2.3.0 : Thu Apr 24 2014 - 13:00:17 CEST