]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
misc: use %m in format string instead of %s and strerror(errno)
authorPetr Uzel <petr.uzel@suse.cz>
Thu, 22 Sep 2011 10:12:37 +0000 (12:12 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 27 Sep 2011 13:46:07 +0000 (15:46 +0200)
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
21 files changed:
Documentation/TODO
disk-utils/fsck.minix.c
disk-utils/raw.c
fdisk/fdisk.c
fdisk/gpt.c
hwclock/cmos.c
include/c.h
libblkid/src/devname.c
libblkid/src/verify.c
libmount/src/context.c
login-utils/login.c
login-utils/vipw.c
misc-utils/blkid.c
misc-utils/uuidd.c
mount/fstab.c
mount/lomount.c
mount/mount.c
mount/umount.c
sys-utils/chcpu.c
sys-utils/readprofile.c
term-utils/ttymsg.c

index 555f80d2fb123733a1bfde52d0d5ebd956b3a0de..4620e8a915d698dacff28bc0fbcb1155391dd0a8 100644 (file)
@@ -149,9 +149,6 @@ login-utils:
 libblkid
 --------
 
- - remove strerrr() from debug messages (use %m) to make BLKID_DEBUG= output
-   thread-safe
-
  - (!) don't use internally blkid_loff_t, rather use off_t, size_t, ssize_t,
        stdint.h types and so on...
 
index 0c6cfa4c59d90d2a36d6c7f446fe63617f0cbd74..eb02f9ea6def0e3a912af580747310a5202f9ead 100644 (file)
@@ -1306,7 +1306,7 @@ main(int argc, char ** argv) {
        }
        IN = open(device_name,repair?O_RDWR:O_RDONLY);
        if (IN < 0)
-               die(_("unable to open '%s': %s"), device_name, strerror(errno));
+               die(_("unable to open '%s': %m"), device_name);
        for (count=0 ; count<3 ; count++)
                sync();
        read_superblock();
index 4cb74ca6f4f8e9986f86c0402c1273ed50a38d8a..84a71ecd7929b0a48a8d4c05f89b12d4f5338edf 100644 (file)
@@ -142,8 +142,8 @@ int main(int argc, char *argv[])
                err = stat(block_name, &statbuf);
                if (err) {
                        fprintf (stderr,
-                                _("Cannot locate block device '%s' (%s)\n"),
-                                block_name, strerror(errno));
+                                _("Cannot locate block device '%s' (%m)\n"),
+                                block_name);
                        exit(2);
                }
 
@@ -201,8 +201,8 @@ static int query(int minor_raw, const char *raw_name, int quiet)
 
                err = stat(raw_name, &statbuf);
                if (err) {
-                       fprintf (stderr, _("Cannot locate raw device '%s' (%s)\n"),
-                                raw_name, strerror(errno));
+                       fprintf (stderr, _("Cannot locate raw device '%s' (%m)\n"),
+                                raw_name);
                        exit(2);
                }
 
@@ -227,8 +227,7 @@ static int query(int minor_raw, const char *raw_name, int quiet)
                if (has_worked && errno == EINVAL)
                        return 0;
                fprintf (stderr,
-                        _("Error querying raw device (%s)\n"),
-                        strerror(errno));
+                        _("Error querying raw device (%m)\n"));
                exit(3);
        }
        /* If one query has worked, mark that fact so that we don't
@@ -253,8 +252,7 @@ static int bind(int minor_raw, int block_major, int block_minor)
        err = ioctl(master_fd, RAW_SETBIND, &rq);
        if (err < 0) {
                fprintf (stderr,
-                        _("Error setting raw device (%s)\n"),
-                        strerror(errno));
+                        _("Error setting raw device (%m)\n"));
                exit(3);
        }
        printf (_("%sraw%d:  bound to major %d, minor %d\n"),
index 1c1f49211ff0492f6e46c51e9d99a281d4644de2..249de71011e060b15974e2a0f1ad3a0f30a88a04 100644 (file)
@@ -2631,10 +2631,10 @@ reread_partition_table(int leave) {
         }
 
        if (i) {
-               printf(_("\nWARNING: Re-reading the partition table failed with error %d: %s.\n"
+               printf(_("\nWARNING: Re-reading the partition table failed with error %d: %m.\n"
                         "The kernel still uses the old table. The new table will be used at\n"
                         "the next reboot or after you run partprobe(8) or kpartx(8)\n"),
-                       errno, strerror(errno));
+                       errno);
        }
 
        if (dos_changed)
index ff659fd8ecaf778b0f53237f60e55e3f7aa88821..aeacd662456997f3251d13bdac48fa63987aca83 100644 (file)
@@ -106,8 +106,7 @@ last_lba(int fd)
        rc = fstat(fd, &s);
        if (rc == -1)
        {
-               fprintf(stderr, "last_lba() could not stat: %s\n",
-                       strerror(errno));
+               fprintf(stderr, "last_lba() could not stat: %m\n");
                return 0;
        }
        if (S_ISBLK(s.st_mode))
index 09b1555dddc9ee1e28728f8774cb0f012e629337..90da9874ea89ad49bd23493c5204c15f5afce7df 100644 (file)
@@ -316,13 +316,13 @@ static inline unsigned long cmos_read(unsigned long reg)
                lseek(dev_port_fd, clock_ctl_addr, 0);
                if (write(dev_port_fd, &v, 1) == -1 && debug)
                        printf(_
-                              ("cmos_read(): write to control address %X failed: %s\n"),
-                              clock_ctl_addr, strerror(errno));
+                              ("cmos_read(): write to control address %X failed: %m\n"),
+                              clock_ctl_addr);
                lseek(dev_port_fd, clock_data_addr, 0);
                if (read(dev_port_fd, &v, 1) == -1 && debug)
                        printf(_
-                              ("cmos_read(): read data address %X failed: %s\n"),
-                              clock_data_addr, strerror(errno));
+                              ("cmos_read(): read data address %X failed: %m\n"),
+                              clock_data_addr);
                return v;
        } else {
                /*
@@ -359,14 +359,14 @@ static inline unsigned long cmos_write(unsigned long reg, unsigned long val)
                lseek(dev_port_fd, clock_ctl_addr, 0);
                if (write(dev_port_fd, &v, 1) == -1 && debug)
                        printf(_
-                              ("cmos_write(): write to control address %X failed: %s\n"),
-                              clock_ctl_addr, strerror(errno));
+                              ("cmos_write(): write to control address %X failed: %m\n"),
+                              clock_ctl_addr);
                v = (val & 0xff);
                lseek(dev_port_fd, clock_data_addr, 0);
                if (write(dev_port_fd, &v, 1) == -1 && debug)
                        printf(_
-                              ("cmos_write(): write to data address %X failed: %s\n"),
-                              clock_data_addr, strerror(errno));
+                              ("cmos_write(): write to data address %X failed: %m\n"),
+                              clock_data_addr);
        } else {
                outb(reg, clock_ctl_addr);
                outb(val, clock_data_addr);
index 74d34608da1b64c829748580eb1b2b68e4c1d3fa..f5b4bcd44d562454cde7c8184bd6e83ffe0cc349 100644 (file)
@@ -153,7 +153,7 @@ errmsg(char doexit, int excode, char adderr, const char *fmt, ...)
                        fprintf(stderr, ": ");
        }
        if (adderr)
-               fprintf(stderr, "%s", strerror(errno));
+               fprintf(stderr, "%m");
        fprintf(stderr, "\n");
        if (doexit)
                exit(excode);
index f824a1795c18612afde946d19751677187a54628..42a8c19a9dfb92d613254957c982370b118b333a 100644 (file)
@@ -260,8 +260,7 @@ static dev_t lvm_get_devno(const char *lvm_device)
 
        DBG(DEBUG_DEVNAME, printf("opening %s\n", lvm_device));
        if ((lvf = fopen(lvm_device, "r")) == NULL) {
-               DBG(DEBUG_DEVNAME, printf("%s: (%d) %s\n", lvm_device, errno,
-                                         strerror(errno)));
+               DBG(DEBUG_DEVNAME, printf("%s: (%d) %m\n", lvm_device, errno));
                return 0;
        }
 
index a0cb3fea2f2ddaefac000b2d13f26b34b3120247..49cc6f17385bcaffa46a8104c57725dcc147eb05 100644 (file)
@@ -60,8 +60,8 @@ blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev)
 
        if (stat(dev->bid_name, &st) < 0) {
                DBG(DEBUG_PROBE,
-                   printf("blkid_verify: error %s (%d) while "
-                          "trying to stat %s\n", strerror(errno), errno,
+                   printf("blkid_verify: error %m (%d) while "
+                          "trying to stat %s\n", errno,
                           dev->bid_name));
        open_err:
                if ((errno == EPERM) || (errno == EACCES) || (errno == ENOENT)) {
@@ -113,8 +113,8 @@ blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev)
 
        fd = open(dev->bid_name, O_RDONLY);
        if (fd < 0) {
-               DBG(DEBUG_PROBE, printf("blkid_verify: error %s (%d) while "
-                                       "opening %s\n", strerror(errno), errno,
+               DBG(DEBUG_PROBE, printf("blkid_verify: error %m (%d) while "
+                                       "opening %s\n", errno,
                                        dev->bid_name));
                goto open_err;
        }
index e3158e48f82163449e8b1c7c6d443602bc2c825e..47d3f85ce3ac4588dc3b1866ebbcbf84ad520d1f 100644 (file)
@@ -1734,7 +1734,7 @@ int test_mount(struct libmnt_test *ts, int argc, char *argv[])
 
        rc = mnt_context_mount(cxt);
        if (rc)
-               printf("failed to mount %s\n", strerror(errno));
+               printf("failed to mount: %m\n");
        else
                printf("successfully mounted\n");
 
index de56f2dcd6cbc012b329c33f160e7851c16dec19..966233669a035c68f6a072e1be707518099b2cf1 100644 (file)
@@ -198,8 +198,7 @@ opentty(const char * tty) {
 
        fd = open(tty, O_RDWR | O_NONBLOCK);
        if (fd == -1) {
-               syslog(LOG_ERR, _("FATAL: can't reopen tty: %s"),
-                      strerror(errno));
+               syslog(LOG_ERR, _("FATAL: can't reopen tty: %m"));
                sleepexit(EXIT_FAILURE);
        }
 
index d3ae51ef9c0e2cf3582e8ce8c119de814d2ec41b..ddca49a5f91e27979f28c670fef8e8b8cdc24b80 100644 (file)
@@ -173,8 +173,7 @@ pw_lock(void) {
        lockfd = open(orig_file, O_RDONLY, 0);
 
        if (lockfd < 0) {
-               (void)fprintf(stderr, "%s: %s: %s\n",
-                   progname, orig_file, strerror(errno));
+               (void)fprintf(stderr, "%s: %s: %m\n", progname, orig_file);
                unlink(tmp_file);
                exit(EXIT_FAILURE);
        }
index a850ac9bd69e1db3709c097c63e1bfc7e0cf3bc1..3608304a5c0a7da0655c01c0096c9645fe5dc88a 100644 (file)
@@ -504,7 +504,7 @@ static int lowprobe_device(blkid_probe pr, const char *devname,
 
        fd = open(devname, O_RDONLY);
        if (fd < 0) {
-               fprintf(stderr, "error: %s: %s\n", devname, strerror(errno));
+               fprintf(stderr, "error: %s: %m\n", devname);
                return 2;
        }
        if (blkid_probe_set_device(pr, fd, offset, size))
index 453287c5bd0301a28b38120b8df7e320dd5ac86e..492ae4d03a13ce6a49b7357f9adee29fd8d25ba4 100644 (file)
@@ -223,8 +223,8 @@ static void server_loop(const char *socket_path, const char *pidfile_path,
        fd_pidfile = open(pidfile_path, O_CREAT | O_RDWR, 0664);
        if (fd_pidfile < 0) {
                if (!quiet)
-                       fprintf(stderr, _("Failed to open/create %s: %s\n"),
-                               pidfile_path, strerror(errno));
+                       fprintf(stderr, _("Failed to open/create %s: %m\n"),
+                               pidfile_path);
                exit(EXIT_FAILURE);
        }
        cleanup_pidfile = pidfile_path;
@@ -240,8 +240,7 @@ static void server_loop(const char *socket_path, const char *pidfile_path,
                if ((errno == EAGAIN) || (errno == EINTR))
                        continue;
                if (!quiet)
-                       fprintf(stderr, _("Failed to lock %s: %s\n"),
-                               pidfile_path, strerror(errno));
+                       fprintf(stderr, _("Failed to lock %s: %m\n"), pidfile_path);
                exit(EXIT_FAILURE);
        }
        ret = call_daemon(socket_path, 0, reply_buf, sizeof(reply_buf), 0, 0);
@@ -255,8 +254,7 @@ static void server_loop(const char *socket_path, const char *pidfile_path,
 
        if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
                if (!quiet)
-                       fprintf(stderr, _("Couldn't create unix stream "
-                                         "socket: %s"), strerror(errno));
+                       fprintf(stderr, _("Couldn't create unix stream socket: %m"));
                exit(EXIT_FAILURE);
        }
 
@@ -282,8 +280,7 @@ static void server_loop(const char *socket_path, const char *pidfile_path,
                 sizeof(struct sockaddr_un)) < 0) {
                if (!quiet)
                        fprintf(stderr,
-                               _("Couldn't bind unix socket %s: %s\n"),
-                               socket_path, strerror(errno));
+                               _("Couldn't bind unix socket %s: %m\n"), socket_path);
                exit(EXIT_FAILURE);
        }
        umask(save_umask);
@@ -291,8 +288,7 @@ static void server_loop(const char *socket_path, const char *pidfile_path,
        if (listen(s, SOMAXCONN) < 0) {
                if (!quiet)
                        fprintf(stderr, _("Couldn't listen on unix "
-                                         "socket %s: %s\n"), socket_path,
-                               strerror(errno));
+                                         "socket %s: %m\n"), socket_path);
                exit(EXIT_FAILURE);
        }
 
@@ -539,8 +535,7 @@ int main(int argc, char **argv)
                ret = call_daemon(socket_path, do_type + 2, buf,
                                  sizeof(buf), &num, &err_context);
                if (ret < 0) {
-                       printf(_("Error calling uuidd daemon (%s): %s\n"),
-                              err_context, strerror(errno));
+                       printf(_("Error calling uuidd daemon (%s): %m\n"), err_context);
                        return EXIT_FAILURE;
                }
                if (do_type == UUIDD_OP_TIME_UUID) {
@@ -568,8 +563,7 @@ int main(int argc, char **argv)
                ret = call_daemon(socket_path, do_type, (char *) &uu,
                                  sizeof(uu), 0, &err_context);
                if (ret < 0) {
-                       printf(_("Error calling uuidd daemon (%s): %s\n"),
-                              err_context, strerror(errno));
+                       printf(_("Error calling uuidd daemon (%s): %m\n"), err_context);
                        return EXIT_FAILURE;
                }
                if (ret != sizeof(uu))
@@ -589,8 +583,7 @@ int main(int argc, char **argv)
                                if (!quiet)
                                        fprintf(stderr,
                                                _("Couldn't kill uuidd running "
-                                                 "at pid %d: %s\n"), do_kill,
-                                               strerror(errno));
+                                                 "at pid %d: %m\n"), do_kill);
                                return EXIT_FAILURE;
                        }
                        if (!quiet)
index 6c0e89f3054be5a26942fe7e80ad3b4b10d09ffb..078401ccccdc9b843edcc18f3f2e57e8ef9f420e 100644 (file)
@@ -1103,7 +1103,7 @@ main(int argc, char **argv)
        nloops = atoi(argv[4]);
 
        if (stat(filename, &st) < -1)
-               die(EXIT_FAILURE, "%s: %s\n", filename, strerror(errno));
+               die(EXIT_FAILURE, "%s: %m\n", filename);
 
        fprintf(stderr, "%05d (pid=%05d): START\n", id, pid);
 
index 74a874929afd3454ac96b604d73ecdb27c5d656e..ff99413e90d28065e55438ca2e78f6a12c1ad009 100644 (file)
@@ -875,8 +875,7 @@ set_loop(const char *device, const char *file, unsigned long long offset,
 
                if (errno == EBUSY) {
                        if (verbose)
-                               printf(_("ioctl LOOP_SET_FD failed: %s\n"),
-                                                       strerror(errno));
+                               printf(_("ioctl LOOP_SET_FD failed: %m\n"));
                        rc = 2;
                } else
                        perror("ioctl: LOOP_SET_FD");
index d2ecb1de691788d94b6c68dc2abd4834f766148a..d74da2c74ec01d59e3a02cfe7f48d0e9930a1e0c 100644 (file)
@@ -781,10 +781,10 @@ check_special_mountprog(const char *spec, const char *node, const char *type, in
                        int i = 0;
 
                        if (setgid(getgid()) < 0)
-                               die(EX_FAIL, _("mount: cannot set group id: %s"), strerror(errno));
+                               die(EX_FAIL, _("mount: cannot set group id: %m"));
 
                        if (setuid(getuid()) < 0)
-                               die(EX_FAIL, _("mount: cannot set user id: %s"), strerror(errno));
+                               die(EX_FAIL, _("mount: cannot set user id: %m"));
 
                        oo = fix_opts_string (flags, extra_opts, NULL);
                        mountargs[i++] = mountprog;                     /* 1 */
@@ -1470,8 +1470,7 @@ cdrom_setspeed(const char *spec) {
                            _("mount: cannot open %s for setting speed"),
                            spec);
                if (ioctl(cdrom, CDROM_SELECT_SPEED, speed) < 0)
-                       die(EX_FAIL, _("mount: cannot set speed: %s"),
-                           strerror(errno));
+                       die(EX_FAIL, _("mount: cannot set speed: %m"));
                close(cdrom);
        }
 }
index 5000aa5692b99e490b8db0fa553817f07881d677..c7ebf7d3c863e51f556260cc6afd173a61a4936c 100644 (file)
@@ -129,10 +129,10 @@ check_special_umountprog(const char *node,
                                int i = 0;
 
                                if(setgid(getgid()) < 0)
-                                       die(EX_FAIL, _("umount: cannot set group id: %s"), strerror(errno));
+                                       die(EX_FAIL, _("umount: cannot set group id: %m"));
 
                                if(setuid(getuid()) < 0)
-                                       die(EX_FAIL, _("umount: cannot set user id: %s"), strerror(errno));
+                                       die(EX_FAIL, _("umount: cannot set user id: %m"));
 
                                umountargs[i++] = umountprog;
                                umountargs[i++] = xstrdup(node);
@@ -244,12 +244,10 @@ static const char *chdir_to_parent(const char *node, char **resbuf)
        }
 
        if (chdir(parent) == -1)
-               die (2, _("umount: failed to chdir to %s: %s"),
-                                       parent, strerror(errno));
+               die (2, _("umount: failed to chdir to %s: %m"), parent);
 
        if (!getcwd(buf, sizeof(buf)))
-               die (2, _("umount: failed to obtain current directory: %s"),
-                       strerror(errno));
+               die (2, _("umount: failed to obtain current directory: %m"));
 
        if (strcmp(buf, parent) != 0)
                die (2, _("umount: mountpoint moved (%s -> %s)"), parent, buf);
index 2cf015fb4b288e65d1530d65905caf4f85d0bdc3..475c1cec66a92359c36090de49ad0fbaa2971433 100644 (file)
@@ -96,8 +96,7 @@ static int cpu_enable(cpu_set_t *cpu_set, size_t setsize, int enable)
                                printf(_("CPU %d enable failed "
                                         "(CPU is deconfigured)\n"), cpu);
                        else if (rc == -1)
-                               printf(_("CPU %d enable failed (%s)\n"), cpu,
-                                       strerror(errno));
+                               printf(_("CPU %d enable failed (%m)\n"), cpu);
                        else
                                printf(_("CPU %d enabled\n"), cpu);
                } else {
@@ -108,8 +107,7 @@ static int cpu_enable(cpu_set_t *cpu_set, size_t setsize, int enable)
                        }
                        rc = path_writestr("0", _PATH_SYS_CPU "/cpu%d/online", cpu);
                        if (rc == -1)
-                               printf(_("CPU %d disable failed (%s)\n"), cpu,
-                                       strerror(errno));
+                               printf(_("CPU %d disable failed (%m)\n"), cpu);
                        else {
                                printf(_("CPU %d disabled\n"), cpu);
                                if (onlinecpus)
@@ -181,15 +179,13 @@ static int cpu_configure(cpu_set_t *cpu_set, size_t setsize, int configure)
                if (configure) {
                        rc = path_writestr("1", _PATH_SYS_CPU "/cpu%d/configure", cpu);
                        if (rc == -1)
-                               printf(_("CPU %d configure failed (%s)\n"), cpu,
-                                       strerror(errno));
+                               printf(_("CPU %d configure failed (%m)\n"), cpu);
                        else
                                printf(_("CPU %d configured\n"), cpu);
                } else {
                        rc = path_writestr("0", _PATH_SYS_CPU "/cpu%d/configure", cpu);
                        if (rc == -1)
-                               printf(_("CPU %d deconfigure failed (%s)\n"), cpu,
-                                       strerror(errno));
+                               printf(_("CPU %d deconfigure failed (%m)\n"), cpu);
                        else
                                printf(_("CPU %d deconfigured\n"), cpu);
                }
index 0e124bc7168cd7b39449be3bedb12aeadc8af121..49f0cbd6c8591950a485cd5b420d03de05a6181a 100644 (file)
@@ -211,8 +211,8 @@ main(int argc, char **argv) {
                        exit(1);
                }
                if (write(fd, &multiplier, to_write) != to_write) {
-                       fprintf(stderr, _("readprofile: error writing %s: %s\n"),
-                               defaultpro, strerror(errno));
+                       fprintf(stderr, _("readprofile: error writing %s: %m\n"),
+                               defaultpro);
                        exit(1);
                }
                close(fd);
@@ -225,7 +225,7 @@ main(int argc, char **argv) {
        if (((proFd=open(proFile,O_RDONLY)) < 0)
            || ((int)(len=lseek(proFd,0,SEEK_END)) < 0)
            || (lseek(proFd,0,SEEK_SET) < 0)) {
-               fprintf(stderr,"%s: %s: %s\n",prgname,proFile,strerror(errno));
+               fprintf(stderr,"%s: %s: %m\n", prgname, proFile);
                exit(1);
        }
 
@@ -233,7 +233,7 @@ main(int argc, char **argv) {
 
        rc = read(proFd,buf,len);
        if (rc < 0 || (size_t) rc != len) {
-               fprintf(stderr,"%s: %s: %s\n",prgname,proFile,strerror(errno));
+               fprintf(stderr,"%s: %s: %m\n", prgname, proFile);
                exit(1);
        }
        close(proFd);
index b5c19732712fd0a110745dc31f9ced556731c9ed..5253f7a5cadc6f802580cd53c92d23799a1c60ab 100644 (file)
@@ -97,7 +97,7 @@ ttymsg(struct iovec *iov, size_t iovcnt, char *line, int tmout) {
                        return (NULL);
                if (strlen(strerror(errno)) > 1000)
                        return (NULL);
-               (void) sprintf(errbuf, "%s: %s", device, strerror(errno));
+               (void) sprintf(errbuf, "%s: %m", device);
                errbuf[1024] = 0;
                return (errbuf);
        }