]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: use xstrdup() if included xalloc.h
authorKarel Zak <kzak@redhat.com>
Thu, 2 Mar 2023 13:16:33 +0000 (14:16 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 2 Mar 2023 13:20:29 +0000 (14:20 +0100)
This commit improves code consistence.

Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/lsfd-bdev.c
misc-utils/lsfd-cdev.c
misc-utils/lsfd-fifo.c
misc-utils/lsfd-file.c
misc-utils/lsfd-sock-xinfo.c
misc-utils/lsfd-sock.c
misc-utils/lsfd-unkn.c
tests/helpers/test_mkfds.c

index b2fecdc8dc9687fb0fb5fab2bb71f0d89a9ab4f9..7be99dbde41cffd2756d3b9ea6ef023c836dc0d4 100644 (file)
@@ -50,7 +50,7 @@ static bool bdev_fill_column(struct proc *proc __attribute__((__unused__)),
        case COL_BLKDRV:
                devdrv = get_blkdrv(major(file->stat.st_rdev));
                if (devdrv)
-                       str = strdup(devdrv);
+                       str = xstrdup(devdrv);
                else
                        xasprintf(&str, "%u",
                                  major(file->stat.st_rdev));
@@ -64,7 +64,7 @@ static bool bdev_fill_column(struct proc *proc __attribute__((__unused__)),
        case COL_PARTITION:
                partition = get_partition(file->stat.st_rdev);
                if (partition) {
-                       str = strdup(partition);
+                       str = xstrdup(partition);
                        break;
                }
                devdrv = get_blkdrv(major(file->stat.st_rdev));
index 795536aca31150d90fab1ad747b0968f2a1ec915..4e35f1543f0a2221756a64b85b476a061dd205b4 100644 (file)
@@ -53,7 +53,7 @@ static bool cdev_fill_column(struct proc *proc __attribute__((__unused__)),
                if (devdrv && strcmp(devdrv, "misc") == 0) {
                        miscdev = get_miscdev(minor(file->stat.st_rdev));
                        if (miscdev)
-                               str = strdup(miscdev);
+                               str = xstrdup(miscdev);
                        else
                                xasprintf(&str, "%u",
                                          minor(file->stat.st_rdev));
@@ -68,7 +68,7 @@ static bool cdev_fill_column(struct proc *proc __attribute__((__unused__)),
        case COL_CHRDRV:
                devdrv = get_chrdrv(major(file->stat.st_rdev));
                if (devdrv)
-                       str = strdup(devdrv);
+                       str = xstrdup(devdrv);
                else
                        xasprintf(&str, "%u",
                                  major(file->stat.st_rdev));
index 484ffd6ebcbe1aa824e8521343413c4f6c7d1aee..f73619257706593683063b7fc99fb91474b24315 100644 (file)
@@ -61,7 +61,7 @@ static bool fifo_fill_column(struct proc *proc __attribute__((__unused__)),
        case COL_SOURCE:
                if (major(file->stat.st_dev) == 0
                    && strncmp(file->name, "pipe:", 5) == 0) {
-                       str = strdup("pipefs");
+                       str = xstrdup("pipefs");
                        break;
                }
                return false;
index f62aa7cc50c678d550a61b56b2710e16c84af61e..bdaac3fd8d19ffb4cc7337944cfe7b2de1c93023 100644 (file)
@@ -190,7 +190,7 @@ static bool file_fill_column(struct proc *proc,
        case COL_PARTITION:
                partition = get_partition(file->stat.st_dev);
                if (partition) {
-                       str = strdup(partition);
+                       str = xstrdup(partition);
                        break;
                }
                /* FALL THROUGH */
index 9b154ba19c40999680fd45f678ef1e585f853a97..4e2d7cce6847b62c5127f6496e338dafa9abb7f6 100644 (file)
@@ -310,7 +310,7 @@ static char *unix_get_type(struct sock_xinfo *sock_xinfo,
        struct unix_xinfo *ux = (struct unix_xinfo *)sock_xinfo;
 
        str = sock_decode_type(ux->type);
-       return strdup(str);
+       return xstrdup(str);
 }
 
 static char *unix_get_state(struct sock_xinfo *sock_xinfo,
@@ -320,10 +320,10 @@ static char *unix_get_state(struct sock_xinfo *sock_xinfo,
        struct unix_xinfo *ux = (struct unix_xinfo *)sock_xinfo;
 
        if (ux->acceptcon)
-               return strdup("listen");
+               return xstrdup("listen");
 
        str = unix_decode_state(ux->st);
-       return strdup(str);
+       return xstrdup(str);
 }
 
 static bool unix_get_listening(struct sock_xinfo *sock_xinfo,
@@ -347,7 +347,7 @@ static bool unix_fill_column(struct proc *proc __attribute__((__unused__)),
        switch (column_id) {
        case COL_UNIX_PATH:
                if (*ux->path) {
-                       *str = strdup(ux->path);
+                       *str = xstrdup(ux->path);
                        return true;
                }
                break;
@@ -538,7 +538,7 @@ struct l4_xinfo_class {
                }                                                       \
                                                                        \
                if (n && inet_ntop(class->family, n, s, sizeof(s))) {   \
-                       *STR = strdup(s);                               \
+                       *STR = xstrdup(s);                              \
                        r = true;                                       \
                }                                                       \
                r;                                                      \
@@ -586,13 +586,13 @@ static char *tcp_get_name(struct sock_xinfo *sock_xinfo,
 static char *tcp_get_type(struct sock_xinfo *sock_xinfo __attribute__((__unused__)),
                           struct sock *sock __attribute__((__unused__)))
 {
-       return strdup("stream");
+       return xstrdup("stream");
 }
 
 static char *tcp_get_state(struct sock_xinfo *sock_xinfo,
                           struct sock *sock __attribute__((__unused__)))
 {
-       return strdup(l4_decode_state(((struct l4_xinfo *)sock_xinfo)->st));
+       return xstrdup(l4_decode_state(((struct l4_xinfo *)sock_xinfo)->st));
 }
 
 static bool tcp_get_listening(struct sock_xinfo *sock_xinfo,
@@ -811,7 +811,7 @@ static char *udp_get_name(struct sock_xinfo *sock_xinfo,
 static char *udp_get_type(struct sock_xinfo *sock_xinfo __attribute__((__unused__)),
                          struct sock *sock __attribute__((__unused__)))
 {
-       return strdup("dgram");
+       return xstrdup("dgram");
 }
 
 static bool udp_fill_column(struct proc *proc __attribute__((__unused__)),
@@ -934,7 +934,7 @@ static char *raw_get_name(struct sock_xinfo *sock_xinfo,
 static char *raw_get_type(struct sock_xinfo *sock_xinfo __attribute__((__unused__)),
                          struct sock *sock __attribute__((__unused__)))
 {
-       return strdup("raw");
+       return xstrdup("raw");
 }
 
 static bool raw_fill_column(struct proc *proc __attribute__((__unused__)),
@@ -1028,7 +1028,7 @@ static char *ping_get_name(struct sock_xinfo *sock_xinfo,
 static char *ping_get_type(struct sock_xinfo *sock_xinfo __attribute__((__unused__)),
                           struct sock *sock __attribute__((__unused__)))
 {
-       return strdup("dgram");
+       return xstrdup("dgram");
 }
 
 static bool ping_fill_column(struct proc *proc __attribute__((__unused__)),
@@ -1467,7 +1467,7 @@ static char *netlink_get_name(struct sock_xinfo *sock_xinfo,
 static char *netlink_get_type(struct sock_xinfo *sock_xinfo __attribute__((__unused__)),
                              struct sock *sock __attribute__((__unused__)))
 {
-       return strdup("raw");
+       return xstrdup("raw");
 }
 
 static bool netlink_fill_column(struct proc *proc __attribute__((__unused__)),
@@ -1488,7 +1488,7 @@ static bool netlink_fill_column(struct proc *proc __attribute__((__unused__)),
                xasprintf(str, "%"PRIu32, nl->lportid);
                return true;
        case COL_NETLINK_PROTOCOL:
-               *str = strdup(netlink_decode_protocol(nl->protocol));
+               *str = xstrdup(netlink_decode_protocol(nl->protocol));
                return true;
        }
 
index 83f35e5d4fe1fa3117b505e9176f20ba89b7307d..32645169c8d159f09a865d77f3edc4d9fca80bac 100644 (file)
@@ -64,7 +64,7 @@ static bool sock_fill_column(struct proc *proc __attribute__((__unused__)),
        case COL_SOURCE:
                if (major(file->stat.st_dev) == 0
                    && strncmp(file->name, "socket:", 7) == 0) {
-                       str = strdup("sockfs");
+                       str = xstrdup("sockfs");
                        break;
                }
                return false;
index f4bba88178bd0d981956dadbb0986626a25d32f5..087e31dad2f287eb39a143f6cfe04b4785fdd3e8 100644 (file)
@@ -54,7 +54,7 @@ static char * anon_get_class(struct unkn *unkn)
        char *name;
 
        if (unkn->anon_ops->class)
-               return strdup(unkn->anon_ops->class);
+               return xstrdup(unkn->anon_ops->class);
 
        /* See unkn_init_content() */
        name = ((struct file *)unkn)->name + 11;
@@ -65,7 +65,7 @@ static char * anon_get_class(struct unkn *unkn)
                        return strndup(name + 1, len - 1);
        }
 
-       return strdup(name);
+       return xstrdup(name);
 }
 
 static bool unkn_fill_column(struct proc *proc,
@@ -97,7 +97,7 @@ static bool unkn_fill_column(struct proc *proc,
                return false;
        case COL_SOURCE:
                if (unkn->anon_ops) {
-                       str = strdup("anon_inodefs");
+                       str = xstrdup("anon_inodefs");
                        break;
                }
                return false;
@@ -232,14 +232,14 @@ static bool anon_pidfd_fill_column(struct proc *proc  __attribute__((__unused__)
                if (pidfd_proc)
                        pidfd_comm = pidfd_proc->command;
                if (pidfd_comm) {
-                       *str = strdup(pidfd_comm);
+                       *str = xstrdup(pidfd_comm);
                        return true;
                }
                break;
        }
        case COL_PIDFD_NSPID:
                if (data->nspid) {
-                       *str = strdup(data->nspid);
+                       *str = xstrdup(data->nspid);
                        return true;
                }
                break;
index 601cd3dcc8ff5345dbc81434013302819493b8e8..8a67e5568180a8ac55489a271ddc4c8cf3addb92 100644 (file)
@@ -736,11 +736,7 @@ static void *make_mmapped_packet_socket(const struct factory *factory, struct fd
                    "failed to specify a buffer spec to a packet socket");
        }
 
-       munmap_data = malloc(sizeof (*munmap_data));
-       if (munmap_data == NULL) {
-               close(sd);
-               errx(EXIT_FAILURE, "memory exhausted");
-       }
+       munmap_data = xmalloc(sizeof (*munmap_data));
        munmap_data->len = (size_t) req.tp_block_size * req.tp_block_nr;
        munmap_data->ptr = mmap(NULL, munmap_data->len, PROT_WRITE, MAP_SHARED, sd, 0);
        if (munmap_data->ptr == MAP_FAILED) {