]> err.no Git - util-linux/commitdiff
fsck/mkfs/mount: unify default search paths for helpers
authorMike Frysinger <vapier@gentoo.org>
Mon, 25 Jan 2010 03:36:55 +0000 (22:36 -0500)
committerKarel Zak <kzak@redhat.com>
Tue, 2 Feb 2010 13:37:32 +0000 (14:37 +0100)
Rather than each fs util having its own search policy, unify the paths in
configure and allow them to be tweaked by downstream.  In the process,
drop the /etc paths as no one has ever really used these.

[kzak@redhat.com: - backport to autoconf < 2.64
                    (remove AS_{SET,IF,CASE,APPEND} macros)]

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
configure.ac
disk-utils/mkfs.c
fsck/fsck.c
mount/mount.c

index 1fef94445deae5ffc8236e899ef7ca6d9ceed1ad..e36b8f6b885b0b8f020cf6b9ad689a64cedb5c59 100644 (file)
@@ -960,6 +960,34 @@ if test "x$enable_require_password" = xyes; then
 fi
 
 
+AC_DEFUN([FS_PATHS_DEFAULT], [/sbin:/sbin/fs.d:/sbin/fs])
+AC_ARG_ENABLE([fs-paths-default],
+  AS_HELP_STRING([--enable-fs-paths-default=paths], [default search path for fs helpers @<:@FS_PATHS_DEFAULT@:>@]),
+  [case "$enableval" in
+     yes) fs_paths_defaults="FS_PATHS_DEFAULT" ;;
+      no) fs_paths_defaults="" ;;
+       *) fs_paths_defaults="$enableval" ;;
+   esac],
+  [fs_paths_defaults="FS_PATHS_DEFAULT"]
+)
+AC_ARG_ENABLE([fs-paths-extra],
+  AS_HELP_STRING([--enable-fs-paths-extra=paths], [additional search paths for fs helpers]),
+  [case "$enableval" in
+     yes|no) fs_paths_extra="" ;;
+          *) fs_paths_extra="$enableval" ;;
+    esac],
+  [fs_paths_extra=""]
+)
+fs_paths="$fs_paths_defaults"
+if test "x$fs_paths_extra" != "x"; then
+  if test "x$fs_paths" != "x"; then
+    fs_paths="${fs_paths}:"
+  fi
+  fs_paths="${fs_paths}${fs_paths_extra}"
+fi
+AC_DEFINE_UNQUOTED([FS_SEARCH_PATH], "$fs_paths", [search path for fs helpers])
+
+
 AC_ARG_ENABLE([use-tty-group],
   AS_HELP_STRING([--disable-use-tty-group], [do not install wall and write setgid tty]),
   [], enable_use_tty_group=yes
index 120da0636b6317a5706c672db9743d69894dd1f4..a0ccd16f6c426bb2c012275791fcfc31f2fde9d3 100644 (file)
@@ -27,7 +27,7 @@
 # define DEFAULT_FSTYPE                "ext2"
 #endif
 
-#define SEARCH_PATH    "PATH=/sbin:/sbin/fs:/sbin/fs.d:/etc/fs:/etc"
+#define SEARCH_PATH    "PATH=" FS_SEARCH_PATH
 #define PROGNAME       "mkfs.%s"
 
 
index 66c027c7eb2602acc0fba938718a4bc5797698b1..45d8484a0d10697b862d62720e9cacc26070ccbf 100644 (file)
@@ -105,7 +105,7 @@ char *progname;
 char *fstype = NULL;
 struct fs_info *filesys_info = NULL, *filesys_last = NULL;
 struct fsck_instance *instance_list;
-const char *fsck_prefix_path = "/sbin:/sbin/fs.d:/sbin/fs:/etc/fs:/etc";
+const char fsck_prefix_path[] = FS_SEARCH_PATH;
 char *fsck_path = 0;
 
 static char *string_copy(const char *s)
index 0cef101abc350977a5d655cd81024a6e6f6cbd55..5cefdccc064c976d81e78c58e9ea742b6e1924a5 100644 (file)
@@ -639,74 +639,89 @@ do_mount (struct mountargs *args, int *special, int *status) {
 static int
 check_special_mountprog(const char *spec, const char *node, const char *type, int flags,
                        char *extra_opts, int *status) {
-  char mountprog[120];
-  struct stat statbuf;
-  int res;
-
-  if (!external_allowed)
-      return 0;
-
-  if (type == NULL || strcmp(type, "none") == 0)
-         return 0;
-
-  if (strlen(type) < 100) {
-       sprintf(mountprog, "/sbin/mount.%s", type);
-       if (stat(mountprog, &statbuf) == 0) {
-           if (verbose)
-                fflush(stdout);
-           res = fork();
-           if (res == 0) {
-                char *oo, *mountargs[10];
-                int i = 0;
-
-                if(setgid(getgid()) < 0)
-                        die(EX_FAIL, _("mount: cannot set group id: %s"), strerror(errno));
-
-                if(setuid(getuid()) < 0)
-                        die(EX_FAIL, _("mount: cannot set user id: %s"), strerror(errno));
-
-                oo = fix_opts_string (flags, extra_opts, NULL);
-                mountargs[i++] = mountprog;                            /* 1 */
-                mountargs[i++] = (char *) spec;                        /* 2 */
-                mountargs[i++] = (char *) node;                        /* 3 */
-                if (sloppy && strncmp(type, "nfs", 3) == 0)
-                     mountargs[i++] = "-s";                            /* 4 */
-                if (fake)
-                     mountargs[i++] = "-f";                            /* 5 */
-                if (nomtab)
-                     mountargs[i++] = "-n";                            /* 6 */
-                if (verbose)
-                     mountargs[i++] = "-v";                            /* 7 */
-                if (oo && *oo) {
-                     mountargs[i++] = "-o";                            /* 8 */
-                     mountargs[i++] = oo;                              /* 9 */
-                }
-                mountargs[i] = NULL;                                   /* 10 */
-
-                if (verbose > 2) {
-                       i = 0;
-                       while(mountargs[i]) {
-                               printf("mount: external mount: argv[%d] = \"%s\"\n",
-                                       i, mountargs[i]);
-                               i++;
-                       }
+       char search_path[] = FS_SEARCH_PATH;
+       char *path, mountprog[150];
+       struct stat statbuf;
+       int res;
+
+       if (!external_allowed)
+               return 0;
+
+       if (type == NULL || strcmp(type, "none") == 0)
+               return 0;
+
+       path = strtok(search_path, ":");
+       while (path) {
+               res = snprintf(mountprog, sizeof(mountprog), "%s/mount.%s",
+                              path, type);
+               path = strtok(NULL, ":");
+               if (res >= sizeof(mountprog) || res < 0)
+                       continue;
+
+               if (stat(mountprog, &statbuf))
+                       continue;
+
+               if (verbose)
                        fflush(stdout);
-                }
-
-                execv(mountprog, mountargs);
-                exit(1);       /* exec failed */
-           } else if (res != -1) {
-                int st;
-                wait(&st);
-                *status = (WIFEXITED(st) ? WEXITSTATUS(st) : EX_SYSERR);
-                return 1;
-           } else {
-                int errsv = errno;
-                error(_("mount: cannot fork: %s"), strerror(errsv));
-           }
-       }
-  }
-  return 0;
+
+               switch (fork()) {
+               case 0: { /* child */
+                       char *oo, *mountargs[10];
+                       int i = 0;
+
+                       if (setgid(getgid()) < 0)
+                               die(EX_FAIL, _("mount: cannot set group id: %s"), strerror(errno));
+
+                       if (setuid(getuid()) < 0)
+                               die(EX_FAIL, _("mount: cannot set user id: %s"), strerror(errno));
+
+                       oo = fix_opts_string (flags, extra_opts, NULL);
+                       mountargs[i++] = mountprog;                     /* 1 */
+                       mountargs[i++] = (char *) spec;                 /* 2 */
+                       mountargs[i++] = (char *) node;                 /* 3 */
+                       if (sloppy && strncmp(type, "nfs", 3) == 0)
+                               mountargs[i++] = "-s";                  /* 4 */
+                       if (fake)
+                               mountargs[i++] = "-f";                  /* 5 */
+                       if (nomtab)
+                               mountargs[i++] = "-n";                  /* 6 */
+                       if (verbose)
+                               mountargs[i++] = "-v";                  /* 7 */
+                       if (oo && *oo) {
+                               mountargs[i++] = "-o";                  /* 8 */
+                               mountargs[i++] = oo;                    /* 9 */
+                       }
+                       mountargs[i] = NULL;                            /* 10 */
+
+                       if (verbose > 2) {
+                               i = 0;
+                               while (mountargs[i]) {
+                                       printf("mount: external mount: argv[%d] = \"%s\"\n",
+                                               i, mountargs[i]);
+                                       i++;
+                               }
+                               fflush(stdout);
+                       }
+
+                       execv(mountprog, mountargs);
+                       exit(1);        /* exec failed */
+               }
+
+               default: { /* parent */
+                       int st;
+                       wait(&st);
+                       *status = (WIFEXITED(st) ? WEXITSTATUS(st) : EX_SYSERR);
+                       return 1;
+               }
+
+               case -1: { /* error */
+                       int errsv = errno;
+                       error(_("mount: cannot fork: %s"), strerror(errsv));
+               }
+               }
+       }
+
+       return 0;
 }