From 77368158bbbbdf027c10e701bda0baf8a480361b Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 3 Feb 2021 10:26:03 -0500 Subject: [PATCH] Use MT-safe strtok_r in spawn viewer library helper MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Even though its current callers are all in single-threaded context (lttng view and lttng-crash commands), it is a good practice to use MT-safe APIs in library functions, in case those are ever used within a multithreaded context in the future. Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau Change-Id: If419fd24b3bf6532f2c75a728a9ec395e365c626 --- src/common/spawn-viewer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/spawn-viewer.c b/src/common/spawn-viewer.c index 781886503..1d668157f 100644 --- a/src/common/spawn-viewer.c +++ b/src/common/spawn-viewer.c @@ -69,7 +69,7 @@ static char **alloc_argv_from_user_opts(char *opts, const char *trace_path) { int i = 0, ignore_space = 0; unsigned int num_opts = 1; - char **argv, *token = opts; + char **argv, *token = opts, *saveptr; /* Count number of arguments. */ do { @@ -91,13 +91,13 @@ static char **alloc_argv_from_user_opts(char *opts, const char *trace_path) goto error; } - token = strtok(opts, " "); + token = strtok_r(opts, " ", &saveptr); while (token != NULL) { argv[i] = strdup(token); if (argv[i] == NULL) { goto error; } - token = strtok(NULL, " "); + token = strtok_r(NULL, " ", &saveptr); i++; } -- 2.34.1