[PATCH v4 1/3] Stop condition based on number of syscalls
    Dmitry V. Levin 
    ldv at strace.io
       
    Sat Mar 18 11:55:12 UTC 2023
    
    
  
Sorry for the long delay,
see more comments below.
On Sat, Mar 04, 2023 at 07:02:15PM +0530, Sahil Siddiq wrote:
> Add option to detach strace after capturing a specified
> number of syscalls.
I suggest changing the first line of the commit message
from "Stop condition based on number of syscalls"
to "Introduce -l/--syscall-limit option".
> * src/defs.h: Add syscall_limit variable.
* src/defs.h (syscall_limit): New variable declaration.
> * src/strace.c: Implementation of -l/--syscall-limit option.
This is too terse.
> * src/syscall.c: Move updation of syscall_limit here.
* src/syscall.c (syscall_exiting_trace): Update syscall_limit.
[...]
> --- a/src/strace.c
> +++ b/src/strace.c
> @@ -84,6 +84,7 @@ int Tflag_scale = 1000;
>  int Tflag_width = 6;
>  bool iflag;
>  bool count_wallclock;
> +unsigned long long syscall_limit = -1ULL;
>  static bool nflag;
>  static int tflag_scale = 1000000000;
>  static unsigned tflag_width = 0;
[...]
> @@ -2432,6 +2438,11 @@ init(int argc, char *argv[])
>  					  "build of strace");
>  #endif
>  			break;
> +		case 'l':
> +			syscall_limit = string_to_uint(optarg);
string_to_uint() returns int and therefore not suitable here,
let's use string_to_ulonglong() instead.
> +			if (syscall_limit <= 0)
> +				error_opt_arg(c, lopt, optarg);
Apparently, all our string_to_* primitives return signed integers,
this essentially means that syscall_limit has to be signed.
Please add a test line to tests/options-syntax.test
that would check that invalid -l arguments are rejected.
-- 
ldv
    
    
More information about the Strace-devel
mailing list