Created
December 30, 2013 19:28
-
-
Save postwait/8186779 to your computer and use it in GitHub Desktop.
This file contains 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 <stdio.h> | |
#include <stdlib.h> | |
#include <signal.h> | |
#include <port.h> | |
#include <sys/lwp.h> | |
#include <pthread.h> | |
lwpid_t other = 0; | |
int port_fd = -1; | |
void *thr_port_get(void *unused;) { | |
uint_t nget = 1; | |
port_event_t ev; | |
other = _lwp_self(); | |
port_fd = port_create(); | |
if(port_fd < 0) { | |
fprintf(stderr, "Failed to port_create()\n"); | |
exit(-1); | |
} | |
port_getn(port_fd, &ev, 1, &nget, NULL); | |
fprintf(stderr, "Exiting... problem.\n"); | |
exit(-1); | |
} | |
void stop_n_close(int sig) { | |
_lwp_suspend(other); | |
close(port_fd); | |
kill(getpid(), sig); | |
} | |
int main() { | |
pthread_t tid; | |
pthread_create(&tid, NULL, thr_port_get, NULL); | |
sleep(1); | |
signal(SIGSEGV, stop_n_close); | |
kill(getpid(), SIGSEGV); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment