Move device number printing code into a separate routine

* 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>
This commit is contained in:
Eugene Syromyatnikov 2016-12-26 15:25:35 +03:00 committed by Dmitry V. Levin
parent 54f2397c84
commit 32e813144c
6 changed files with 55 additions and 18 deletions

View 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 \

1
defs.h
View File

@ -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);

17
dm.c
View File

@ -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("}");

View File

@ -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;
}
}

37
print_dev_t.c Normal file
View File

@ -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));
}

View 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);