]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - disk-utils/fsck.c
fsck: use PATH or fallback to /sbin
[thirdparty/util-linux.git] / disk-utils / fsck.c
index 535184e811b89f560bc4f5e7799e69ffc01a9e01..299a775254d15ee855fe79b0bedf5bbba2561375 100644 (file)
@@ -54,6 +54,7 @@
 #include "c.h"
 #include "closestream.h"
 #include "fileutils.h"
+#include "monotonic.h"
 
 #define XALLOC_EXIT_CODE       FSCK_EX_ERROR
 #include "xalloc.h"
@@ -149,9 +150,10 @@ static int kill_sent;
 static char *fstype;
 static struct fsck_instance *instance_list;
 
-static const char fsck_prefix_path[] = FS_SEARCH_PATH;
+#define FSCK_DEFAULT_PATH "/sbin"
 static char *fsck_path;
 
+
 /* parsed fstab and mtab */
 static struct libmnt_table *fstab, *mtab;
 static struct libmnt_cache *mntcache;
@@ -450,10 +452,14 @@ static void fs_interpret_type(struct libmnt_fs *fs)
        device = fs_get_device(fs);
        if (device) {
                int ambi = 0;
+               char *tp;
+               struct libmnt_cache *cache = mnt_table_get_cache(fstab);
 
-               type = mnt_get_fstype(device, &ambi, mnt_table_get_cache(fstab));
+               tp = mnt_get_fstype(device, &ambi, cache);
                if (!ambi)
-                       mnt_fs_set_fstype(fs, type);
+                       mnt_fs_set_fstype(fs, tp);
+               if (!cache)
+                       free(tp);
        }
 }
 
@@ -573,20 +579,19 @@ static int progress_active(void)
  */
 static void print_stats(struct fsck_instance *inst)
 {
-       double time_diff;
+       struct timeval delta;
 
        if (!inst || !report_stats || noexecute)
                return;
 
-       time_diff = (inst->end_time.tv_sec  - inst->start_time.tv_sec)
-                 + (inst->end_time.tv_usec - inst->start_time.tv_usec) / 1E6;
+       timersub(&inst->end_time, &inst->start_time, &delta);
 
        fprintf(stdout, "%s: status %d, rss %ld, "
-                       "real %f, user %d.%06d, sys %d.%06d\n",
+                       "real %ld.%06ld, user %d.%06d, sys %d.%06d\n",
                fs_get_device(inst->fs),
                inst->exit_status,
                inst->rusage.ru_maxrss,
-               time_diff,
+               delta.tv_sec, delta.tv_usec,
                (int)inst->rusage.ru_utime.tv_sec,
                (int)inst->rusage.ru_utime.tv_usec,
                (int)inst->rusage.ru_stime.tv_sec,
@@ -672,7 +677,7 @@ static int execute(const char *progname, const char *progpath,
        inst->pid = pid;
        inst->prog = xstrdup(progname);
        inst->type = xstrdup(type);
-       gettimeofday(&inst->start_time, NULL);
+       gettime_monotonic(&inst->start_time);
        inst->next = NULL;
 
        /*
@@ -785,7 +790,7 @@ static struct fsck_instance *wait_one(int flags)
 
        inst->exit_status = status;
        inst->flags |= FLAG_DONE;
-       gettimeofday(&inst->end_time, NULL);
+       gettime_monotonic(&inst->end_time);
        memcpy(&inst->rusage, &rusage, sizeof(struct rusage));
 
        if (progress && (inst->flags & FLAG_PROGRESS) &&
@@ -1460,15 +1465,14 @@ static void parse_argv(int argc, char *argv[])
                                break;
                        case 'C':
                                progress = 1;
-                               if (arg[j+1]) {
+                               if (arg[j+1]) {                                 /* -C<fd> */
                                        progress_fd = string_to_int(arg+j+1);
                                        if (progress_fd < 0)
                                                progress_fd = 0;
                                        else
                                                goto next_arg;
-                               } else if ((i+1) < argc &&
-                                          !strncmp(argv[i+1], "-", 1) == 0) {
-                                       progress_fd = string_to_int(argv[i]);
+                               } else if (i+1 < argc && *argv[i+1] != '-') {   /* -C <fd> */
+                                       progress_fd = string_to_int(argv[i+1]);
                                        if (progress_fd < 0)
                                                progress_fd = 0;
                                        else {
@@ -1548,8 +1552,8 @@ int main(int argc, char *argv[])
 {
        int i, status = 0;
        int interactive = 0;
-       char *oldpath = getenv("PATH");
        struct libmnt_fs *fs;
+       const char *path = getenv("PATH");
 
        setvbuf(stdout, NULL, _IONBF, BUFSIZ);
        setvbuf(stderr, NULL, _IONBF, BUFSIZ);
@@ -1570,16 +1574,7 @@ int main(int argc, char *argv[])
 
        load_fs_info();
 
-       /* Update our search path to include uncommon directories. */
-       if (oldpath) {
-               fsck_path = xmalloc (strlen (fsck_prefix_path) + 1 +
-                                   strlen (oldpath) + 1);
-               strcpy (fsck_path, fsck_prefix_path);
-               strcat (fsck_path, ":");
-               strcat (fsck_path, oldpath);
-       } else {
-               fsck_path = xstrdup(fsck_prefix_path);
-       }
+       fsck_path = xstrdup(path && *path ? path : FSCK_DEFAULT_PATH);
 
        if ((num_devices == 1) || (serialize))
                interactive = 1;