Mercurial > xbps-search-tv
comparison spawn.cpp @ 2:00b62a080354
fix numerous bugs
| author | Yasuri <yasuri@charliesmp.net> |
|---|---|
| date | Sun, 13 Sep 2026 19:40:11 +0000 |
| parents | 21b543c7aa14 |
| children |
comparison
equal
deleted
inserted
replaced
| 1:a17d9d25e9ea | 2:00b62a080354 |
|---|---|
| 4 #include <spawn.h> | 4 #include <spawn.h> |
| 5 #include <cstring> | 5 #include <cstring> |
| 6 #include <string> | 6 #include <string> |
| 7 #include "process.h" | 7 #include "process.h" |
| 8 extern char** environ; // idk what this does | 8 extern char** environ; // idk what this does |
| 9 std::string spawn(char* const argv[], const char* path) | 9 std::string spawn(char* const argv[]) |
| 10 { | 10 { |
| 11 pid_t pid; | 11 pid_t pid; |
| 12 int status; | 12 int status; |
| 13 status = posix_spawn(&pid, path, NULL, NULL, const_cast<char* const*>(argv), environ); | 13 status = posix_spawnp(&pid, argv[0], NULL, NULL, const_cast<char* const*>(argv), environ); |
| 14 if (status != 0) { | 14 if (status != 0) { |
| 15 std::cerr << "posix_spawn failed:" << strerror(status) << std::endl; | 15 std::cerr << "posix_spawnp failed for " << argv[0] << ": " << strerror(status) << std::endl; |
| 16 return "error"; | 16 return "error"; |
| 17 } | 17 } |
| 18 if (waitpid(pid, &status, 0) == -1) { | 18 if (waitpid(pid, &status, 0) == -1) { |
| 19 perror("waitpid"); | 19 perror("waitpid"); |
| 20 return "error"; | 20 return "error"; |
| 21 } | 21 } |
| 22 if (WIFEXITED(status)) { | 22 if (WIFEXITED(status)) { |
| 23 return std::to_string(WEXITSTATUS(status)); | 23 return std::to_string(WEXITSTATUS(status)); |
| 24 } | 24 } |
| 25 if (WIFSIGNALED(status)) { | 25 if (WIFSIGNALED(status)) { |
| 26 return std::to_string(WTERMSIG(status)); | 26 return "sig:" + std::to_string(WTERMSIG(status)); |
| 27 } | 27 } |
| 28 return "success"; | 28 return "success"; |
| 29 } | 29 } |
