| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
#include <stdio.h> |
| 8 |
#define _GNU_SOURCE |
| 9 |
#include <stdio.h> |
| 10 |
#include <stdlib.h> |
| 11 |
#include <stdarg.h> |
| 12 |
#include <sys/types.h> |
| 13 |
#include <sys/stat.h> |
| 14 |
#include <dlfcn.h> |
| 15 |
#include <dirent.h> |
| 16 |
#include <string.h> |
| 17 |
#include <fcntl.h> |
| 18 |
#include <unistd.h> |
| 19 |
#include <sys/signal.h> |
| 20 |
#include <sys/mman.h> |
| 21 |
#include <pthread.h> |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
static void *openclosetest(void *p) { |
| 29 |
int fd; |
| 30 |
if (-1 == (fd = open("a", O_WRONLY))) { |
| 31 |
perror("open"); |
| 32 |
return "success"; |
| 33 |
} |
| 34 |
|
| 35 |
if (5 != write(fd, "test\n", 5)) { |
| 36 |
perror("write"); |
| 37 |
return NULL; |
| 38 |
} |
| 39 |
if (-1 == close(fd)) { |
| 40 |
perror("close"); |
| 41 |
return NULL; |
| 42 |
} |
| 43 |
return NULL; |
| 44 |
} |
| 45 |
|
| 46 |
int main(int argc, char **argv) { |
| 47 |
|
| 48 |
void *ret; |
| 49 |
pthread_t pth; |
| 50 |
|
| 51 |
unlink(".ilist"); |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
pthread_create(&pth, NULL, openclosetest, NULL); |
| 56 |
if (!openclosetest(NULL)) { |
| 57 |
fprintf(stderr, "parent thread failure\n"); |
| 58 |
return 1; |
| 59 |
} |
| 60 |
if (!pthread_join(pth, &ret)) { |
| 61 |
if (!ret) { |
| 62 |
fprintf(stderr, "child thread failure\n"); |
| 63 |
return 1; |
| 64 |
} |
| 65 |
} else { |
| 66 |
perror("pthread_join"); |
| 67 |
return 1; |
| 68 |
} |
| 69 |
return 0; |
| 70 |
} |