[PATCH v6 0/3] [GSoC] Stop condition based on number of syscalls

Sahil Siddiq icegambit91 at gmail.com
Thu Mar 30 12:28:46 UTC 2023


Hi,

This patch adds the feature to detach strace after capturing a specified
number of syscalls.

On Thursday, 30 March 2023 10:25:22 IST Sahil Siddiq wrote:
> [...]
> In the ideal case, I would expect strace to terminate while the shell (such
> a bash) becomes the tracee's parent. I know one can use prctl() with
> "PR_SET_CHILD_SUBREAPER" to reparent an orphan process to the nearest
> living ancestor, but I do not know how to set this option for the shell.
> 
> The options I have thought of are:
> 
> 1. to simply let "init" become the parent of the orphaned tracee after
> strace terminates. But if the detached tracee is interactive, it may
> interfere with current shell.
> 
> 2. to stop the tracee after strace terminates (which is probably not
> desired).
> 
> 3. to let strace run and remain as the parent of the tracee without tracing
> more syscalls. In this case, strace would have detached from the tracees
> but it won't terminate. I have understood that "-b execve" is per-tracee
> and not global. However, I noticed that if every child/thread invokes
> execve and "-b execve" detaches from all of those threads, strace still
> remains the parent and does not terminate. In this case, strace would sleep
> for a minute even after detaching from tracee in "strace--syscall-limit.test"

This patch series implements approach 1. Versions 1 through 3 used approach 2.
The other versions up till the previous one used approach 3.

I am sending this patch in case you would like to test it.

Regards,
Sahil

Changes v5 -> v6:
 - src/strace.c:
   (next_event) "syscall_limit == 0" returns NULL
   (maybe_allocate_tcb): Remove "syscall_limit == 0" check
   (dispatch_event): Remove "syscall_limit == 0" check
 - NEWS: Move update to current NEWS section
 - tests/gen_tests.in: Modify rule for "strace--syscall-limit-status"
 - tests/strace--syscall-limit.c: Unify main() and helper() functions.
 - tests/strace--syscall-limit-path.c: Likewise
 - tests/strace--syscall-limit-status.c:
   - Likewise
   - Also, use fchdir instead of getcwd in child process
 - tests/strace--syscall-limit.test: Wait for dummy file creation and read
   file before comparing logs.

Sahil Siddiq (3):
  Introduce -l/--syscall-limit option
  Make relevant changes in NEWS and man page
  Add tests for the -l/--syscall-limit option

 NEWS                                 |  2 +
 doc/strace.1.in                      | 15 ++++++
 src/defs.h                           |  1 +
 src/strace.c                         | 20 +++++++-
 src/syscall.c                        |  3 ++
 tests/.gitignore                     |  3 ++
 tests/Makefile.am                    |  4 ++
 tests/gen_tests.in                   |  2 +
 tests/options-syntax.test            |  4 ++
 tests/strace--syscall-limit-path.c   | 65 ++++++++++++++++++++++++++
 tests/strace--syscall-limit-status.c | 68 ++++++++++++++++++++++++++++
 tests/strace--syscall-limit.c        | 56 +++++++++++++++++++++++
 tests/strace--syscall-limit.test     | 57 +++++++++++++++++++++++
 13 files changed, 299 insertions(+), 1 deletion(-)
 create mode 100644 tests/strace--syscall-limit-path.c
 create mode 100644 tests/strace--syscall-limit-status.c
 create mode 100644 tests/strace--syscall-limit.c
 create mode 100755 tests/strace--syscall-limit.test

-- 
2.40.0



More information about the Strace-devel mailing list