Skip to content

Commit a0b2cf1

Browse files
authored
Use execvp
1 parent 1602c21 commit a0b2cf1

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

src/runtime/runtime.c

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* as possible (one .c file) and use as few external dependencies
66
* as possible
77
*
8-
* Copyright (c) 2004-22 Simon Peter
8+
* Copyright (c) 2004-24 Simon Peter
99
* Portions Copyright (c) 2007 Alexander Larsson
1010
* Portions from WjCryptLib_Md5 originally written by Alexander Peslyak,
1111
modified by WaterJuice retaining Public Domain license
@@ -441,14 +441,33 @@ char* find_fusermount() {
441441
char* fusermount_full_path = malloc(strlen(dir) + strlen(entry->d_name) + 2);
442442
sprintf(fusermount_full_path, "%s/%s", dir, entry->d_name);
443443

444-
// Check if the entry is executable
445-
if (access(fusermount_full_path, X_OK) == 0) {
446-
closedir(dir_ptr);
447-
free(path_copy);
448-
return fusermount_full_path;
444+
pid_t pid = fork();
445+
if (pid == -1) {
446+
perror("fork");
447+
free(fusermount_full_path);
448+
continue;
449449
}
450450

451-
free(fusermount_full_path);
451+
if (pid == 0) {
452+
// Child process
453+
char* args[] = {fusermount_full_path, NULL};
454+
execvp(fusermount_full_path, args);
455+
// If execvp returns, it means the executable was not found
456+
exit(1);
457+
} else {
458+
// Parent process
459+
int status;
460+
waitpid(pid, &status, 0);
461+
462+
if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
463+
// The executable was found and executed successfully
464+
closedir(dir_ptr);
465+
free(path_copy);
466+
return fusermount_full_path;
467+
}
468+
469+
free(fusermount_full_path);
470+
}
452471
}
453472
}
454473
}

0 commit comments

Comments
 (0)