Difference between
modified post 8ad53a3 by Anonymous on Fri 22nd Feb 2019 15:44
original post 92b6 by Anonymous on Thu 17th Jan 2019 08:44
Download diff
Show
old version |
new version |
both versions
| 1 | 1 | #include <pthread.h> | |
| 2 | 2 | #include <stdio.h> | |
| 3 | 3 | #include <stdlib.h> | |
| 4 | 4 | #include <unistd.h> | |
| 5 | 5 | #include <signal.h> | |
| 6 | 6 | #include <errno.h> | |
| 7 | 7 | ||
| 8 | 8 | /* Simple error handling functions */ | |
| 9 | 9 | ||
| 10 | 10 | #define handle_error_en(en, msg) \ | |
| 11 | 11 | do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0) | |
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | 14 | int main(int ac, char *av[]) | |
| 15 | 15 | { | |
| 16 | 16 | sigset_t set; | |
| 17 | 17 | int i; | |
| 18 | 18 | char buff[512]; | |
| 19 | 19 | ||
| 20 | 20 | (void)puts("#start"); | |
| 21 | 21 | ||
| 22 | 22 | sigemptyset(&set); | |
| 23 | 23 | sigaddset(&set, SIGRTMIN+2); | |
| 24 | 24 | sigaddset(&set, SIGRTMIN+3); | |
| 25 | 25 | i = pthread_sigmask(SIG_BLOCK, &set, NULL); | |
| 26 | 26 | if (i != 0) | |
| 27 | 27 | handle_error_en(i, "pthread_sigmask() failed"); | |
| 28 | 28 | ||
| 29 | 29 | (void)puts("#mark1"); | |
| 30 | 30 | ||
| 31 | 31 | /* | |
| 32 | 32 | * stupid /bin/kill in Linux cannot handle realtime signal | |
| 33 | 33 | * *names*, so we pass the signal number instead | |
| 34 | 34 | */ | |
| 35 | - | (void)snprintf(buff, sizeof(buff), "kill -s %d %d", SIGRTMIN+2, getpid()); | |
| 35 | + | (void)snprintf(buff, sizeof(buff), "kill -s %d %ld", (int)SIGRTMIN+2, (long)getpid()); | |
| 36 | - | (void)printf("# executing %s\n", buff); | |
| 36 | + | (void)printf("# executing '%s'\n", buff); | |
| 37 | 37 | (void)system(buff); | |
| 38 | 38 | ||
| 39 | 39 | (void)puts("#mark2"); | |
| 40 | 40 | ||
| 41 | 41 | (void)sleep(2); | |
| 42 | 42 | (void)puts("#mark3"); | |
| 43 | 43 | ||
| 44 | 44 | i = pthread_sigmask(SIG_UNBLOCK, &set, NULL); | |
| 45 | 45 | if (i != 0) | |
| 46 | 46 | handle_error_en(i, "pthread_sigmask() failed"); | |
| 47 | 47 | ||
| 48 | 48 | /* | |
| 49 | 49 | * unblocking the SIGRTMIN signals will trigger the default handler for | |
| 50 | 50 | * the SIGRT signals, which terminates the process, so we will never reach | |
| 51 | 51 | * this point in the program | |
| 52 | 52 | */ | |
| 53 | 53 | (void)puts("#notreached"); | |
| 54 | 54 | ||
| 55 | 55 | return EXIT_SUCCESS; | |
| 56 | 56 | } | |
| 57 | 57 | ||
| 58 | 58 |
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
eckelmann.kpaste.net RSS