Browse Source

strace: respect quietness setting when reporting unknown tracees

Since the situations where these processes can appear are relatively
normal, it makes little sense to print them irrespective of quietness
setting.

* strace.c (maybe_allocate_tcb): Put the message about exit of unknown
process under QUIET_EXIT check; put message about detach of unknown
process under QUIET_ATTACH check.
* tests/clone_parent--quiet-exit.c: New file.
* tests/clone_parent-q.c: Likewise.
* tests/clone_parent-qq.c: Likewise.
* tests/clone_ptrace--quiet-attach.c: Likewise.
* tests/clone_ptrace--quiet-exit.c: Likewise.
* tests/clone_ptrace-q.c: Likewise.
* tests/clone_ptrace-qq.c: Likewise.
* tests/.gitignore: Add clone_parent--quiet-exit, clone_parent-q,
clone_parent-qq, clone_ptrace--quiet-attach, clone_ptrace--quiet-exit,
clone_ptrace-q, and clone_ptrace-qq.
* tests/Makefile.am (check_PROGRAMS): Likewise.
* tests/gen_tests.in: Add clone_parent--quiet-exit, clone_parent-q,
clone_parent-qq, clone_ptrace--quiet-attach, clone_ptrace--quiet-exit,
clone_ptrace-q, and clone_ptrace-qq tests.
* tests/clone_parent.c [!QUIET_MSG] (QUIET_MSG): New macro.
(main): Print exit messages only if QUIET_MSG set to zero.
* tests/clone_ptrace.c [!QUIET_ATTACH] (QUIET_ATTACH): New macro.
[!QUIET_EXIT] (QUIET_EXIT): Likewise.
(main): Print information about unknown pid detach only if QUIET_ATTACH
is 0; print information about process exiting only if QUIET_EXIT is 0.
* tests/clone_ptrace.test: Add the first argument to args, add
"--quiet=personality" if it is empty.
Eugene Syromyatnikov 2 months ago
parent
commit
adaf331009

+ 9
- 6
strace.c View File

@@ -2399,11 +2399,13 @@ maybe_allocate_tcb(const int pid, int status)
2399 2399
 			strace_child = 0;
2400 2400
 			return NULL;
2401 2401
 		}
2402
-		/*
2403
-		 * This can happen if we inherited an unknown child.
2404
-		 * Example: (sleep 1 & exec strace true)
2405
-		 */
2406
-		error_msg("Exit of unknown pid %u ignored", pid);
2402
+		if (!is_number_in_set(QUIET_EXIT, quiet_set)) {
2403
+			/*
2404
+			 * This can happen if we inherited an unknown child.
2405
+			 * Example: (sleep 1 & exec strace true)
2406
+			 */
2407
+			error_msg("Exit of unknown pid %u ignored", pid);
2408
+		}
2407 2409
 		return NULL;
2408 2410
 	}
2409 2411
 	if (followfork) {
@@ -2422,7 +2424,8 @@ maybe_allocate_tcb(const int pid, int status)
2422 2424
 		 * observable stop here is the initial ptrace-stop.
2423 2425
 		 */
2424 2426
 		ptrace(PTRACE_DETACH, pid, NULL, 0L);
2425
-		error_msg("Detached unknown pid %d", pid);
2427
+		if (!is_number_in_set(QUIET_ATTACH, quiet_set))
2428
+			error_msg("Detached unknown pid %d", pid);
2426 2429
 		return NULL;
2427 2430
 	}
2428 2431
 }

+ 7
- 0
tests/.gitignore View File

@@ -53,7 +53,14 @@ clone3-success-Xabbrev
53 53
 clone3-success-Xraw
54 54
 clone3-success-Xverbose
55 55
 clone_parent
56
+clone_parent--quiet-exit
57
+clone_parent-q
58
+clone_parent-qq
56 59
 clone_ptrace
60
+clone_ptrace--quiet-attach
61
+clone_ptrace--quiet-exit
62
+clone_ptrace-q
63
+clone_ptrace-qq
57 64
 copy_file_range
58 65
 count-f
59 66
 creat

+ 7
- 0
tests/Makefile.am View File

@@ -90,7 +90,14 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \
90 90
 	check_sigblock \
91 91
 	check_sigign \
92 92
 	clone_parent \
93
+	clone_parent--quiet-exit \
94
+	clone_parent-q \
95
+	clone_parent-qq \
93 96
 	clone_ptrace \
97
+	clone_ptrace--quiet-attach \
98
+	clone_ptrace--quiet-exit \
99
+	clone_ptrace-q \
100
+	clone_ptrace-qq \
94 101
 	clone3-success \
95 102
 	clone3-success-Xabbrev \
96 103
 	clone3-success-Xraw \

+ 2
- 0
tests/clone_parent--quiet-exit.c View File

@@ -0,0 +1,2 @@
1
+#define QUIET_MSG 1
2
+#include "clone_parent.c"

+ 2
- 0
tests/clone_parent-q.c View File

@@ -0,0 +1,2 @@
1
+#define QUIET_MSG 0
2
+#include "clone_parent.c"

+ 2
- 0
tests/clone_parent-qq.c View File

@@ -0,0 +1,2 @@
1
+#define QUIET_MSG 1
2
+#include "clone_parent.c"

+ 8
- 0
tests/clone_parent.c View File

@@ -17,6 +17,10 @@
17 17
 #include <sys/wait.h>
18 18
 #include <unistd.h>
19 19
 
20
+#ifndef QUIET_MSG
21
+# define QUIET_MSG 0
22
+#endif
23
+
20 24
 static int
21 25
 child(void *const arg)
22 26
 {
@@ -56,10 +60,14 @@ main(void)
56 60
 	FILE *const fp = fdopen(3, "a");
57 61
 	if (!fp)
58 62
 		perror_msg_and_fail("fdopen");
63
+#if !QUIET_MSG
59 64
 	if (fprintf(fp, "%s: Exit of unknown pid %d ignored\n",
60 65
 		    getenv("STRACE_EXE") ?: "strace", pid) < 0)
61 66
 		perror_msg_and_fail("fprintf");
67
+#endif
62 68
 
69
+#if !QUIET_MSG
63 70
 	puts("+++ exited with 0 +++");
71
+#endif
64 72
 	return 0;
65 73
 }

+ 2
- 0
tests/clone_ptrace--quiet-attach.c View File

@@ -0,0 +1,2 @@
1
+#define QUIET_ATTACH 1
2
+#include "clone_ptrace.c"

+ 2
- 0
tests/clone_ptrace--quiet-exit.c View File

@@ -0,0 +1,2 @@
1
+#define QUIET_EXIT 1
2
+#include "clone_ptrace.c"

+ 2
- 0
tests/clone_ptrace-q.c View File

@@ -0,0 +1,2 @@
1
+#define QUIET_ATTACH 1
2
+#include "clone_ptrace.c"

+ 3
- 0
tests/clone_ptrace-qq.c View File

@@ -0,0 +1,3 @@
1
+#define QUIET_ATTACH 1
2
+#define QUIET_EXIT 1
3
+#include "clone_ptrace.c"

+ 13
- 1
tests/clone_ptrace.c View File

@@ -20,6 +20,13 @@
20 20
 
21 21
 static siginfo_t sinfo;
22 22
 
23
+#ifndef QUIET_ATTACH
24
+# define QUIET_ATTACH 0
25
+#endif
26
+#ifndef QUIET_EXIT
27
+# define QUIET_EXIT 0
28
+#endif
29
+
23 30
 static void
24 31
 handler(const int no, siginfo_t *const si, void *const uc)
25 32
 {
@@ -74,9 +81,11 @@ main(void)
74 81
 	FILE *const fp = fdopen(3, "a");
75 82
 	if (!fp)
76 83
 		perror_msg_and_fail("fdopen");
84
+#if !QUIET_ATTACH
77 85
 	if (fprintf(fp, "%s: Detached unknown pid %d\n",
78 86
 		    getenv("STRACE_EXE") ?: "strace", pid) < 0)
79 87
 		perror_msg_and_fail("fprintf");
88
+#endif
80 89
 
81 90
 	int status;
82 91
 	while (wait(&status) != pid) {
@@ -88,7 +97,10 @@ main(void)
88 97
 
89 98
 	printf("--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_KILLED, si_pid=%d"
90 99
 	       ", si_uid=%u, si_status=%s, si_utime=%u, si_stime=%u} ---\n"
91
-	       "+++ exited with 0 +++\n", pid, geteuid(), "SIGUSR1",
100
+#if !QUIET_EXIT
101
+	       "+++ exited with 0 +++\n"
102
+#endif
103
+	       , pid, geteuid(), "SIGUSR1",
92 104
 	       (unsigned int) sinfo.si_utime, (unsigned int) sinfo.si_stime);
93 105
 
94 106
 	return 0;

+ 1
- 1
tests/clone_ptrace.test View File

@@ -10,7 +10,7 @@
10 10
 . "${srcdir=.}/init.sh"
11 11
 
12 12
 run_prog > /dev/null 3>&1
13
-args="-e trace=none $args"
13
+args="-e trace=none ${1:---quiet=personality} $args"
14 14
 > "$LOG" || fail_ "failed to write $LOG"
15 15
 
16 16
 $STRACE -o "$LOG" $args > "$EXP" 2> "$OUT"-err 3> "$EXP"-err || {

+ 7
- 0
tests/gen_tests.in View File

@@ -39,6 +39,13 @@ clone3-success-Xabbrev	+clone3-success.test -a16 -Xabbrev
39 39
 clone3-success-Xraw	+clone3-success.test -a16 -Xraw
40 40
 clone3-success-Xverbose	+clone3-success.test -a16 -Xverbose
41 41
 clone_parent +clone_ptrace.test
42
+clone_parent--quiet-exit +clone_ptrace.test --quiet=exit,personality
43
+clone_parent-q +clone_ptrace.test -q
44
+clone_parent-qq +clone_ptrace.test -qq
45
+clone_ptrace--quiet-attach +clone_ptrace.test --quiet=attach,personality
46
+clone_ptrace--quiet-exit +clone_ptrace.test --quiet=exit,personality
47
+clone_ptrace-q +clone_ptrace.test -q
48
+clone_ptrace-qq +clone_ptrace.test -qq
42 49
 copy_file_range
43 50
 creat	-a20
44 51
 delete_module	-a23

Loading…
Cancel
Save