Skip to content

Commit

Permalink
Loaderutils only
Browse files Browse the repository at this point in the history
  • Loading branch information
michalbiesek committed Jun 26, 2023
1 parent 15d740a commit 3432fae
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
54 changes: 27 additions & 27 deletions src/loader/loaderutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,33 +346,33 @@ getpath(const char *cmd)
}

// try to resolve the cmd from PATH env variable
char *path_env_ptr = getenv("PATH");
if (!path_env_ptr) goto out;
path_env = strdup(path_env_ptr); // create a copy for strtok below
if (!path_env) goto out;

char *saveptr = NULL;
char *strtok_path = strtok_r(path_env, ":", &saveptr);
if (!strtok_path) goto out;

do {
char *path = NULL;
if (asprintf(&path, "%s/%s", strtok_path, cmd) < 0) {
break;
}
if ((stat(path, &buf) == -1) || // path doesn't exist
(!S_ISREG(buf.st_mode)) || // path isn't a file
((buf.st_mode & 0111) == 0)) { // path isn't executable

free(path);
continue;
}

// We found the cmd, and it's an executable file
ret_val = path;
break;

} while ((strtok_path = strtok_r(NULL, ":", &saveptr)));
// char *path_env_ptr = getenv("PATH");
// if (!path_env_ptr) goto out;
// path_env = strdup(path_env_ptr); // create a copy for strtok below
// if (!path_env) goto out;

// char *saveptr = NULL;
// char *strtok_path = strtok_r(path_env, ":", &saveptr);
// if (!strtok_path) goto out;

// do {
// char *path = NULL;
// if (asprintf(&path, "%s/%s", strtok_path, cmd) < 0) {
// break;
// }
// if ((stat(path, &buf) == -1) || // path doesn't exist
// (!S_ISREG(buf.st_mode)) || // path isn't a file
// ((buf.st_mode & 0111) == 0)) { // path isn't executable

// free(path);
// continue;
// }

// // We found the cmd, and it's an executable file
// ret_val = path;
// break;

// } while ((strtok_path = strtok_r(NULL, ":", &saveptr)));

out:
if (path_env) free(path_env);
Expand Down
4 changes: 4 additions & 0 deletions src/wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -3133,6 +3133,8 @@ getScopeExec(const char *pathname)
isgo = is_go(ebuf->buf);
}

// scopeLogError("getScopeExec %s isstat %d isgo %d\n", pathname, isstat, isgo);

// not really necessary since we're gonna exec
if (ebuf) freeElf(ebuf->buf, ebuf->len);

Expand All @@ -3153,6 +3155,8 @@ getScopeExec(const char *pathname)
return NULL;
}

// scopeLogError("scopexec = %s\n", scopexec);

return scopexec;
}

Expand Down

0 comments on commit 3432fae

Please sign in to comment.