[LTP] [PATCH 2/2] Use SAFE_RUNCMD()

Cyril Hrubis chrubis@suse.cz
Wed Mar 25 00:51:51 CET 2020


Hi!
> Something like this would work on whole PATH.
> It's just a question if we want to use it.
> 
> int tst_cmd_available(char *cmd)
> {
> 	char *dup = strdup(getenv("PATH"));
> 	char *s = dup;
> 	char *p = NULL;
> 	int ret = 0;
>     char path[PATH_MAX];
> 
> 	do {
> 		p = strchr(s, ':');
> 		if (p != NULL) {
> 			p[0] = 0;
> 		}
> 		snprintf(path, PATH_MAX, "%s/%s", s, cmd);
> 
> 		if (!access(path, X_OK)) {
> 			ret = 1;
> 			break;
> 		}
> 		s = p + 1;
> 	} while (p != NULL);
> 
> 	free(dup);
> 	return ret;
> }

We already do have tst_get_path() that does more or less the same.

Also if we are going to add this functionality it should be added as an
.needs_cmds array in the tst_test structure.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list