[LTP] [PATCH 4/6] lib: extend PATH as part of test setup
Cyril Hrubis
chrubis@suse.cz
Tue Oct 10 17:18:52 CEST 2017
Hi!
> +static void add_paths(void)
> +{
> + char *old_path = getenv("PATH");
> + const char *start_dir;
> + char *new_path;
> + int new_path_size;
> +
> + start_dir = tst_get_startwd();
> +
> + /* ".:" + "$start_dir" + '\0' */
> + new_path_size = 2 + strlen(start_dir) + 1;
> + if (old_path)
> + /* ":" + "$old_path" */
> + new_path_size += 1 + strlen(old_path);
> +
> + new_path = SAFE_MALLOC(new_path_size);
> + strcpy(new_path, ".:");
> + strcat(new_path, start_dir);
> +
> + if (old_path) {
> + strcat(new_path, ":");
> + strcat(new_path, old_path);
> + }
I do not like the strcat() function much, I would have probably handled
these with asprintf();
if (old_path)
SAFE_ASPRINTF(&new_path, "%s::%s", old_path, start_dir);
else
SAFE_ASPRINTF(&new_path, "::%s", start_dir);
The rest of the patchset looks good.
BTW, we should also drop the note about setting $PATH from the
documentation once this is merged.
> + SAFE_SETENV("PATH", new_path, 1);
> + free(new_path);
> +}
> +
> static void testrun(void)
> {
> unsigned int i = 0;
> unsigned long long stop_time = 0;
> int cont = 1;
>
> + add_paths();
> do_test_setup();
>
> if (duration > 0)
> --
> 1.8.3.1
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list