summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry V. Levin <ldv@strace.io>2021-11-23 08:00:00 +0000
committerDmitry V. Levin <ldv@strace.io>2021-11-23 08:00:00 +0000
commit463643b710b11032b90cdc1457b51e4213c133a2 (patch)
treed30af2b17e78260532087ca15b00006d91f83d11
parent06e75fd0bdcff9b233c9de2b020932cec1098765 (diff)
downloadstrace-463643b710b11032b90cdc1457b51e4213c133a2.tar.gz
Fix formatting of --decode-pids=comm output
Do not print an extra space between the pid number and the comm string when the number is less than 10000. * src/strace.c (printleader) <print_pid_pfx && len>: Print pid using %u format instead of %-5u. * tests/strace--decode-pids-comm.c (do_default_action): Update expected output. * tests/strace-p1-Y-p.c (main): Likewise.
-rw-r--r--src/strace.c15
-rw-r--r--tests/strace--decode-pids-comm.c16
-rw-r--r--tests/strace-p1-Y-p.c2
3 files changed, 19 insertions, 14 deletions
diff --git a/src/strace.c b/src/strace.c
index 1e30d32f9..0b919cfa6 100644
--- a/src/strace.c
+++ b/src/strace.c
@@ -812,13 +812,18 @@ printleader(struct tcb *tcp)
current_tcp->curcol = 0;
if (print_pid_pfx || (nprocs > 1 && !outfname)) {
- if (print_pid_pfx)
- tprintf("%-5u", tcp->pid);
- else
- tprintf("[pid %5u", tcp->pid);
-
size_t len = is_number_in_set(DECODE_PID_COMM, decode_pid_set)
? strlen(tcp->comm) : 0;
+
+ if (print_pid_pfx) {
+ if (len)
+ tprintf("%u", tcp->pid);
+ else
+ tprintf("%-5u", tcp->pid);
+ } else {
+ tprintf("[pid %5u", tcp->pid);
+ }
+
print_comm_str(tcp->comm, len);
if (!print_pid_pfx)
diff --git a/tests/strace--decode-pids-comm.c b/tests/strace--decode-pids-comm.c
index ce1fa8187..e1b343024 100644
--- a/tests/strace--decode-pids-comm.c
+++ b/tests/strace--decode-pids-comm.c
@@ -45,7 +45,7 @@ do_default_action(void)
pid_t pid = getpid();
pid_t ppid = getppid();
- printf("%-5d<%s> getppid() = %d<%s>\n", pid, comm, ppid, "strace");
+ printf("%u<%s> getppid() = %d<%s>\n", pid, comm, ppid, "strace");
fflush(stdout);
pid_t child = fork();
@@ -54,7 +54,7 @@ do_default_action(void)
else if (child == 0) {
pid = getpid();
ppid = getppid();
- printf("%-5d<%s> getppid() = %d<%s>\n", pid, comm, ppid, ocomm);
+ printf("%u<%s> getppid() = %d<%s>\n", pid, comm, ppid, ocomm);
const char *names[] = {
"foo\33[2Jbar",
@@ -67,12 +67,12 @@ do_default_action(void)
prctl(PR_GET_NAME, comm);
ppid = getppid();
- printf("%-5d<", pid);
+ printf("%u<", pid);
print_quoted_memory_ex(comm, strlen(comm), 0, "<>");
printf("> getppid() = %d<%s>\n", ppid, ocomm);
long rc = syscall(__NR_tgkill, pid, pid, SIGCONT);
- printf("%-5d<", pid);
+ printf("%u<", pid);
print_quoted_memory_ex(comm, strlen(comm), 0, "<>");
printf("> tgkill(%d<", pid);
print_quoted_memory_ex(comm, strlen(comm), 0, "<>");
@@ -82,7 +82,7 @@ do_default_action(void)
}
long rc = syscall(__NR_tgkill, ppid, ppid, SIGCONT);
- printf("%-5d<%s> tgkill(%d<%s>, %d<%s>, SIGCONT) = %s\n",
+ printf("%u<%s> tgkill(%d<%s>, %d<%s>, SIGCONT) = %s\n",
pid, comm, ppid, ocomm, ppid, ocomm, sprintrc(rc));
fflush(stdout);
@@ -96,11 +96,11 @@ do_default_action(void)
continue;
perror_msg_and_fail("waitpid: %d", child);
}
- printf("%-5d<exe> +++ exited with 0 +++\n", child);
+ printf("%u<exe> +++ exited with 0 +++\n", child);
ppid = getppid();
- printf("%-5d<%s> getppid() = %d<%s>\n", pid, comm, ppid, "strace");
- printf("%-5d<%s> +++ exited with 0 +++\n", pid, comm);
+ printf("%u<%s> getppid() = %d<%s>\n", pid, comm, ppid, "strace");
+ printf("%u<%s> +++ exited with 0 +++\n", pid, comm);
return WEXITSTATUS(status);
}
return 0;
diff --git a/tests/strace-p1-Y-p.c b/tests/strace-p1-Y-p.c
index 32bdf749a..a02236e14 100644
--- a/tests/strace-p1-Y-p.c
+++ b/tests/strace-p1-Y-p.c
@@ -33,7 +33,7 @@ main(int ac, char **av)
if (!fp)
error_msg_and_fail("fdopen(3, \"a\")");
- fprintf(fp, "%-5u<%s> +++ exited with 0 +++\n", getpid(), MY_COMM);
+ fprintf(fp, "%u<%s> +++ exited with 0 +++\n", getpid(), MY_COMM);
fclose(fp);
if (sleep(seconds))