|
5 | 5 | * as possible (one .c file) and use as few external dependencies |
6 | 6 | * as possible |
7 | 7 | * |
8 | | - * Copyright (c) 2004-22 Simon Peter |
| 8 | + * Copyright (c) 2004-24 Simon Peter |
9 | 9 | * Portions Copyright (c) 2007 Alexander Larsson |
10 | 10 | * Portions from WjCryptLib_Md5 originally written by Alexander Peslyak, |
11 | 11 | modified by WaterJuice retaining Public Domain license |
@@ -441,14 +441,33 @@ char* find_fusermount() { |
441 | 441 | char* fusermount_full_path = malloc(strlen(dir) + strlen(entry->d_name) + 2); |
442 | 442 | sprintf(fusermount_full_path, "%s/%s", dir, entry->d_name); |
443 | 443 |
|
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; |
449 | 449 | } |
450 | 450 |
|
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 | + } |
452 | 471 | } |
453 | 472 | } |
454 | 473 | } |
|
0 commit comments