]> granicus.if.org Git - strace/commitdiff
syslog: do not print bufp and len for commands that ignore them
authorEugene Syromyatnikov <evgsyr@gmail.com>
Wed, 26 Sep 2018 22:42:27 +0000 (00:42 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 5 Aug 2019 22:48:31 +0000 (22:48 +0000)
* syslog.c (SYS_FUNC(syslog)): Defer printing of comma after the first
argument to the specific command handlers, return RVAL_DECODED without
additional printing for SYSLOG_ACTION_CLOSE, SYSLOG_ACTION_OPEN,
SYSLOG_ACTION_CLEAR, SYSLOG_ACTION_CONSOLE_OFF,
SYSLOG_ACTION_CONSOLE_ON, SYSLOG_ACTION_SIZE_UNREAD,
SYSLOG_ACTION_SIZE_BUFFER.
* tests/syslog.c: Add checks.

syslog.c
tests/gen_tests.in
tests/syslog.c

index 626663eed169a9a458274d1736894aefbca5eb2c..92d68f2a32538b2210fb88a96287a687f3f41cae 100644 (file)
--- a/syslog.c
+++ b/syslog.c
@@ -18,22 +18,36 @@ SYS_FUNC(syslog)
                /* type */
                printxval_ex(syslog_action_type, type, "SYSLOG_ACTION_???",
                             XLAT_STYLE_VERBOSE | XLAT_STYLE_FMT_D);
-               tprints(", ");
        }
 
        switch (type) {
+       /* Those commands have bufp and len ignored */
+       case SYSLOG_ACTION_CLOSE:
+       case SYSLOG_ACTION_OPEN:
+       case SYSLOG_ACTION_CLEAR:
+       case SYSLOG_ACTION_CONSOLE_OFF:
+       case SYSLOG_ACTION_CONSOLE_ON:
+       case SYSLOG_ACTION_SIZE_UNREAD:
+       case SYSLOG_ACTION_SIZE_BUFFER:
+               return RVAL_DECODED;
+
        case SYSLOG_ACTION_READ:
        case SYSLOG_ACTION_READ_ALL:
        case SYSLOG_ACTION_READ_CLEAR:
-               if (entering(tcp))
+               if (entering(tcp)) {
+                       tprints(", ");
                        return 0;
+               }
                break;
        default:
+               tprints(", ");
                printaddr(tcp->u_arg[1]);
                tprintf(", %" PRI_klu, tcp->u_arg[2]);
                return RVAL_DECODED;
        }
 
+       /* syscall exit handler for SYSLOG_ACTION_READ* */
+
        /* bufp */
        if (syserror(tcp))
                printaddr(tcp->u_arg[1]);
index 4fdf4722c93d664fb7cc54ed02bf5196cbaf75bd..8ad044a831f3ca774ecb8336059576f4d8df917a 100644 (file)
@@ -500,7 +500,7 @@ sync        -a7
 sync_file_range
 sync_file_range2
 sysinfo        -a14
-syslog -a36
+syslog -a35
 tee
 time   -a10
 timer_create
index 028514b3f15bb6940dc8ba89607376e409cc2036..151880d1d64d2247390a20cb14dd7d3105b38507 100644 (file)
 int
 main(void)
 {
+       static const struct cmd_str {
+               unsigned int cmd;
+               const char *str;
+       } no_args[] = {
+               { 0,  "0 /* SYSLOG_ACTION_CLOSE */" },
+               { 1,  "1 /* SYSLOG_ACTION_OPEN */" },
+               { 5,  "5 /* SYSLOG_ACTION_CLEAR */" },
+               { 6,  "6 /* SYSLOG_ACTION_CONSOLE_OFF */" },
+               { 7,  "7 /* SYSLOG_ACTION_CONSOLE_ON */" },
+               { 9,  "9 /* SYSLOG_ACTION_SIZE_UNREAD */" },
+               { 10, "10 /* SYSLOG_ACTION_SIZE_BUFFER */" },
+       };
+       static const kernel_ulong_t high =
+               (kernel_ulong_t) 0xbadc0ded00000000ULL;
        const long addr = (long) 0xfacefeeddeadbeefULL;
-
-       int rc = syscall(__NR_syslog, SYSLOG_ACTION_READ, addr, -1);
+       int rc;
+       for (size_t i = 0; i < ARRAY_SIZE(no_args); i++) {
+               rc = syscall(__NR_syslog, high | no_args[i].cmd, addr, -1);
+               printf("syslog(%s) = %s\n",
+               no_args[i].str, sprintrc(rc));
+       }
+
+       rc = syscall(__NR_syslog, SYSLOG_ACTION_READ, addr, -1);
        printf("syslog(2 /* SYSLOG_ACTION_READ */, %#lx, -1) = %s\n",
               addr, sprintrc(rc));
 
-       rc = syscall(__NR_syslog, SYSLOG_ACTION_SIZE_BUFFER, NULL, 10);
-       printf("syslog(10 /* SYSLOG_ACTION_SIZE_BUFFER */, NULL, 10) = %s\n",
-              sprintrc(rc));
-
        puts("+++ exited with 0 +++");
        return 0;
 }