]> granicus.if.org Git - strace/commitdiff
strace.c: move pathtrace_select calls to a later initialisation stage
authorEugene Syromiatnikov <esyr@redhat.com>
Mon, 25 Dec 2017 22:57:36 +0000 (23:57 +0100)
committerEugene Syromyatnikov <evgsyr@gmail.com>
Wed, 27 Feb 2019 16:30:51 +0000 (17:30 +0100)
Since pathtrace initialisation (more speicifically, path name
resolution) is specific to the tracing backend (especially in case
tracees are remote), let's first collect the list of paths to trace
in a temporary array and add it later during the initialisation.

* strace.c (init): Add pathtrace_paths temporary array, with its
element count stored in pathtrace_count and size in pathtrace_size.
(init) <case 'P'>: Store argument in pathtrace_paths, grow it if needed.
(init): Iterate over pathtrace_paths and call pathtrace_select for each
element. Free the array.

strace.c

index 2ca18e2f06d443506c61a7f0029b23dea702a92c..64480734e11f6f32a52ef92d29512bb58d373935 100644 (file)
--- a/strace.c
+++ b/strace.c
@@ -1632,6 +1632,18 @@ init(int argc, char *argv[])
        int c, i;
        int optF = 0;
 
+       /*
+        * We can initialise global_path_set only after tracing backend
+        * initialisation, so we store pointers to all the paths from
+        * command-line arguments during parsing in this array and then, after
+        * the successful backend initialisation, iterate over it in order
+        * to add them to global_path_set.
+        */
+       const char **pathtrace_paths = NULL;
+       size_t pathtrace_size = 0;
+       size_t pathtrace_count = 0;
+       size_t cnt;
+
        if (!program_invocation_name || !*program_invocation_name) {
                static char name[] = "strace";
                program_invocation_name =
@@ -1732,7 +1744,12 @@ init(int argc, char *argv[])
                        process_opt_p_list(optarg);
                        break;
                case 'P':
-                       pathtrace_select(optarg);
+                       if (pathtrace_count >= pathtrace_size)
+                               pathtrace_paths = xgrowarray(pathtrace_paths,
+                                       &pathtrace_size,
+                                       sizeof(pathtrace_paths[0]));
+
+                       pathtrace_paths[pathtrace_count++] = optarg;
                        break;
                case 'q':
                        qflag++;
@@ -1837,6 +1854,10 @@ init(int argc, char *argv[])
                        error_msg("-%c has no effect with -c", 'y');
        }
 
+       for (cnt = 0; cnt < pathtrace_count; cnt++)
+               pathtrace_select(pathtrace_paths[cnt]);
+       free(pathtrace_paths);
+
        acolumn_spaces = xmalloc(acolumn + 1);
        memset(acolumn_spaces, ' ', acolumn);
        acolumn_spaces[acolumn] = '\0';