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