diff options
author | Mango0x45 <thomasvoss@live.com> | 2021-01-18 21:57:58 +0000 |
---|---|---|
committer | Mango0x45 <thomasvoss@live.com> | 2021-01-18 21:57:58 +0000 |
commit | b35df7c07c59f553de4fa2903dc3185136a45f1d (patch) | |
tree | eae31364fd1a6a06c513813134aadc21e717a53b /utils/math.c | |
parent | 660f1b7a2cdc32e90f33bfa6630ea7529001cc13 (diff) | |
download | steve-bot-b35df7c07c59f553de4fa2903dc3185136a45f1d.tar steve-bot-b35df7c07c59f553de4fa2903dc3185136a45f1d.tar.gz steve-bot-b35df7c07c59f553de4fa2903dc3185136a45f1d.tar.bz2 steve-bot-b35df7c07c59f553de4fa2903dc3185136a45f1d.tar.lz steve-bot-b35df7c07c59f553de4fa2903dc3185136a45f1d.tar.xz steve-bot-b35df7c07c59f553de4fa2903dc3185136a45f1d.tar.zst steve-bot-b35df7c07c59f553de4fa2903dc3185136a45f1d.zip |
Search for BC in the PATH
Diffstat (limited to '')
-rw-r--r-- | utils/math.c | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/utils/math.c b/utils/math.c index 25ae645..0eb1dc3 100644 --- a/utils/math.c +++ b/utils/math.c @@ -21,43 +21,43 @@ bool timeout = false, child_done = false; void timeout_hander(int UNUSED(sig)) { - timeout = true; + timeout = true; } void child_handler(int UNUSED(sig)) { - child_done = true; + child_done = true; } int main(void) { - pid_t pid = fork(); - switch (pid) { - case 0: - execl("/bin/bc", "", "-q", "bc_funcs/lib.bc", "bc_funcs/init.bc", - FILE_NAME, "bc_funcs/exit.bc", NULL); - fallthrough; - case -1: - perror("calc"); - return EXIT_FAILURE; - default: - /* Setup signal handlers after fork so the child doesnt inherit them */ - signal(SIGALRM, timeout_hander); - signal(SIGCHLD, child_handler); - alarm(TIMEOUT); - pause(); - - /* - * Wait for either the child process to terminate, or for 5 seconds to - * have passed - */ - if (timeout) { - puts("Error: 5 second timeout reached"); - kill(pid, 9); - } - - break; - } - - return EXIT_SUCCESS; -}
\ No newline at end of file + pid_t pid = fork(); + switch (pid) { + case 0: + execlp("bc", "bc", "-q", "bc_funcs/lib.bc", "bc_funcs/init.bc", + FILE_NAME, "bc_funcs/exit.bc", NULL); + fallthrough; + case -1: + perror("calc"); + return EXIT_FAILURE; + default: + /* Setup signal handlers after fork so the child doesnt inherit them */ + signal(SIGALRM, timeout_hander); + signal(SIGCHLD, child_handler); + alarm(TIMEOUT); + pause(); + + /* + * Wait for either the child process to terminate, or for 5 seconds to + * have passed + */ + if (timeout) { + puts("Error: 5 second timeout reached"); + kill(pid, 9); + } + + break; + } + + return EXIT_SUCCESS; +} |