]> gitweb.michael.orlitzky.com - apply-default-acl.git/blobdiff - src/apply-default-acl.c
Improve the error message for most types of inaccessible paths.
[apply-default-acl.git] / src / apply-default-acl.c
index ea3ef6491a2d1ab374d707f86822439c21809be3..a520aa9b6d4ebdc43b5055772292c1efe4b2b822 100644 (file)
@@ -9,6 +9,7 @@
 #define _XOPEN_SOURCE 500
 #define _GNU_SOURCE
 
+#include <errno.h>   /* EINVAL */
 #include <fcntl.h>   /* AT_FOO constants */
 #include <ftw.h>     /* nftw() et al. */
 #include <getopt.h>  /* getopt_long() */
@@ -67,10 +68,15 @@ bool path_accessible(const char* path) {
  *
  */
 void usage(const char* program_name) {
+  if (program_name == NULL) {
+    /* ??? */
+    return;
+  }
+
   printf("Apply any applicable default ACLs to the given files or "
-        "directories.\n\n");
+         "directories.\n\n");
   printf("Usage: %s [flags] <target1> [<target2> [ <target3>...]]\n\n",
-        program_name);
+         program_name);
   printf("Flags:\n");
   printf(" -h, --help         Print this help message\n");
   printf(" -r, --recursive    Act on any given directories recursively\n");
@@ -92,9 +98,16 @@ void usage(const char* program_name) {
  *
  */
 int apply_default_acl_nftw(const char *target,
-                          const struct stat *sp,
-                          int info,
-                          struct FTW *ftw) {
+                           const struct stat *sp,
+                           int info,
+                           struct FTW *ftw) {
+
+  if (target == NULL) {
+    errno = EINVAL;
+    perror("apply_default_acl_nftw (args)");
+    return ACL_ERROR;
+  }
+
 
   if (apply_default_acl_ex(target, sp, false) == ACL_ERROR) {
     /* I guess we do want to bail out for serious/unexpected errors? */
@@ -115,9 +128,15 @@ int apply_default_acl_nftw(const char *target,
  *
  */
 int apply_default_acl_nftw_x(const char *target,
-                            const struct stat *sp,
-                            int info,
-                            struct FTW *ftw) {
+                             const struct stat *sp,
+                             int info,
+                             struct FTW *ftw) {
+
+  if (target == NULL) {
+    errno = EINVAL;
+    perror("apply_default_acl_nftw_x (args)");
+    return ACL_ERROR;
+  }
 
   if (apply_default_acl_ex(target, sp, true) == ACL_ERROR) {
     /* I guess we do want to bail out for serious/unexpected errors? */
@@ -148,6 +167,12 @@ int apply_default_acl_nftw_x(const char *target,
  *   then we return @c ACL_ERROR. Otherwise, we return @c ACL_SUCCESS.
  */
 int apply_default_acl_recursive(const char *target, bool no_exec_mask) {
+  if (target == NULL) {
+    errno = EINVAL;
+    perror("apply_default_acl_recursive (args)");
+    return ACL_ERROR;
+  }
+
   int max_levels = 256;
   int flags = FTW_MOUNT | FTW_PHYS;
 
@@ -232,7 +257,7 @@ int main(int argc, char* argv[]) {
      * typos, too.
      */
     if (!path_accessible(target)) {
-      fprintf(stderr, "%s: %s: No such file or directory\n", argv[0], target);
+      perror(target);
       result = EXIT_FAILURE;
       continue;
     }