]> granicus.if.org Git - strace/commitdiff
Move device number printing code into a separate routine
authorEugene Syromyatnikov <evgsyr@gmail.com>
Mon, 26 Dec 2016 12:25:35 +0000 (15:25 +0300)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 29 Dec 2016 00:11:24 +0000 (00:11 +0000)
* print_dev_t.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* defs.h (print_dev_t): New prototype.
* dm.c: Do not include <sys/sysmacros.h>.
(dm_decode_device, dm_print_dev, dm_decode_dm_name_list): Use
print_dev_t function for printing device numbers.
* mknod.c: Do not include <sys/sysmacros.h>.
(decode_mknod): Use print_dev_t function for printing device number.
* print_struct_stat.c: Do not include <sys/sysmacros.h>.
(print_struct_stat): Use print_dev_t function for printing device
numbers.

Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
Makefile.am
defs.h
dm.c
mknod.c
print_dev_t.c [new file with mode: 0644]
print_struct_stat.c

index 4840b93771fa634da507c6dedf79899e23e127d0..2b01d3dc472dcb604332ec7862e8d889ad934e75 100644 (file)
@@ -182,6 +182,7 @@ strace_SOURCES =    \
        pkeys.c         \
        poll.c          \
        prctl.c         \
+       print_dev_t.c   \
        print_mq_attr.c \
        print_msgbuf.c  \
        print_sigevent.c \
diff --git a/defs.h b/defs.h
index 9591e171cfe5df18b3810fbd8c43887c5c99c23f..1e056068ce3be39a2e1794fcea615184dcec9ff2 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -581,6 +581,7 @@ extern const char *sprinttime(time_t);
 extern void print_symbolic_mode_t(unsigned int);
 extern void print_numeric_umode_t(unsigned short);
 extern void print_numeric_long_umask(unsigned long);
+extern void print_dev_t(unsigned long long dev);
 
 extern void
 dumpiov_in_msghdr(struct tcb *, kernel_ulong_t addr, kernel_ulong_t data_size);
diff --git a/dm.c b/dm.c
index 7a1dc3c2899d8d0ce82ec9476cc240f3559a57c0..41380041a40046f0d0c5a2175771c748bafd3726 100644 (file)
--- a/dm.c
+++ b/dm.c
@@ -5,8 +5,6 @@
 # include <linux/dm-ioctl.h>
 # include <linux/ioctl.h>
 
-# include <sys/sysmacros.h>
-
 # if DM_VERSION_MAJOR == 4
 
 /* Definitions for command which have been added later */
@@ -31,9 +29,10 @@ dm_decode_device(const unsigned int code, const struct dm_ioctl *ioc)
        case DM_LIST_VERSIONS:
                break;
        default:
-               if (ioc->dev)
-                       tprintf(", dev=makedev(%u, %u)",
-                               major(ioc->dev), minor(ioc->dev));
+               if (ioc->dev) {
+                       tprints(", dev=");
+                       print_dev_t(ioc->dev);
+               }
                if (ioc->name[0]) {
                        tprints(", name=");
                        print_quoted_string(ioc->name, DM_NAME_LEN,
@@ -171,7 +170,7 @@ dm_print_dev(struct tcb *tcp, void *dev_ptr, size_t dev_size, void *dummy)
 {
        uint64_t *dev = (uint64_t *) dev_ptr;
 
-       tprintf("makedev(%u, %u)", major(*dev), minor(*dev));
+       print_dev_t(*dev);
 
        return 1;
 }
@@ -255,8 +254,10 @@ dm_decode_dm_name_list(struct tcb *const tcp, const kernel_ulong_t addr,
                        break;
                }
 
-               tprintf("{dev=makedev(%u, %u), name=", major(s.dev),
-                       minor(s.dev));
+               tprints("{dev=");
+               print_dev_t(s.dev);
+
+               tprints("name=");
                printstr_ex(tcp, addr + offset_end, ioc->data_size - offset_end,
                            QUOTE_0_TERMINATED);
                tprints("}");
diff --git a/mknod.c b/mknod.c
index 9b903116364bfce168fbf756ae3283d95b17bdb9..3edcd8480ccd7827397520d7d59b26db6060e34e 100644 (file)
--- a/mknod.c
+++ b/mknod.c
@@ -35,7 +35,6 @@
 
 #include <fcntl.h>
 #include <sys/stat.h>
-#include <sys/sysmacros.h>
 
 static void
 decode_mknod(struct tcb *tcp, int offset)
@@ -50,7 +49,8 @@ decode_mknod(struct tcb *tcp, int offset)
        case S_IFCHR:
        case S_IFBLK:
                dev = tcp->u_arg[offset + 2];
-               tprintf(", makedev(%u, %u)", major(dev), minor(dev));
+               tprints(", ");
+               print_dev_t(dev);
                break;
        }
 }
diff --git a/print_dev_t.c b/print_dev_t.c
new file mode 100644 (file)
index 0000000..9b62f84
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Device number printing routine.
+ *
+ * Copyright (c) 2016 The strace developers.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "defs.h"
+#include <sys/sysmacros.h>
+
+void
+print_dev_t(const unsigned long long dev)
+{
+       tprintf("makedev(%u, %u)", major(dev), minor(dev));
+}
index 7b23ec8a8bcda7b35134b4366d810f057c868013..7e9e2338005ace5fe03fc91665e9302dc5d0cd81 100644 (file)
@@ -34,7 +34,6 @@
 
 #include "defs.h"
 #include <sys/stat.h>
-#include <sys/sysmacros.h>
 #include "stat.h"
 
 void
@@ -42,10 +41,9 @@ print_struct_stat(struct tcb *tcp, const struct strace_stat *const st)
 {
        tprints("{");
        if (!abbrev(tcp)) {
-               tprintf("st_dev=makedev(%u, %u), st_ino=%llu, st_mode=",
-                       (unsigned int) major(st->dev),
-                       (unsigned int) minor(st->dev),
-                       st->ino);
+               tprints("st_dev=");
+               print_dev_t(st->dev);
+               tprintf(", st_ino=%llu, st_mode=", st->ino);
                print_symbolic_mode_t(st->mode);
                tprintf(", st_nlink=%llu, st_uid=%llu, st_gid=%llu",
                        st->nlink, st->uid, st->gid);
@@ -58,9 +56,8 @@ print_struct_stat(struct tcb *tcp, const struct strace_stat *const st)
 
        switch (st->mode & S_IFMT) {
        case S_IFCHR: case S_IFBLK:
-               tprintf(", st_rdev=makedev(%u, %u)",
-                       (unsigned int) major(st->rdev),
-                       (unsigned int) minor(st->rdev));
+               tprints(", st_rdev=");
+               print_dev_t(st->rdev);
                break;
        default:
                tprintf(", st_size=%llu", st->size);