Created
June 6, 2020 21:14
-
-
Save ridiculousfish/1b28af43ae2a3a871a5f4aa43a3811f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <signal.h> | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <spawn.h> | |
| #include <sys/wait.h> | |
| static void show_sigmask(const char *when) { | |
| sigset_t sigs; | |
| sigemptyset(&sigs); | |
| int err = sigprocmask(SIG_SETMASK, 0, &sigs); | |
| if (err) { | |
| perror("sigprocmask"); | |
| exit(EXIT_FAILURE); | |
| } | |
| printf("sigmask %s\n", when); | |
| int numset = 0; | |
| for (int i=0; i < 31; i++) { | |
| if (sigismember(&sigs, i)) { | |
| printf(" %d\n", i); | |
| numset++; | |
| } | |
| } | |
| if (numset == 0) { | |
| printf(" (empty)\n"); | |
| } | |
| } | |
| int main(void) { | |
| int pid = -1; | |
| char arg1[] = "/bin/echo"; | |
| char arg2[] = "hello"; | |
| char *argv[] = {arg1, arg2, NULL}; | |
| char *envp[] = {NULL}; | |
| show_sigmask("before posix_spawn"); | |
| (void)posix_spawn(&pid, "/bin/echo", NULL, NULL, argv, envp); | |
| show_sigmask("after posix_spawn"); | |
| if (pid >= 0) waitpid(pid, NULL, 0); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment