#include <fcntl.h>
#include <sys/wait.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
int main(int argc, char **argv)
{
static char timer[] = "/bin/timer";
int fd;
int pid;
if (!(pid = fork())) {
argv[0] = timer;
execv("/bin/timer", argv);
}
if ((fd = open("/bin/timer", O_RDONLY)) < 0)
perror("open(\"/bin/timer\", O_RDONLY)");
else
close(fd);
printf("Test 1-ETXTBSY\n");
if ((fd = open("/bin/timer", O_WRONLY)) < 0)
perror("open(\"/bin/timer\", O_WRONLY)");
else
close(fd);
kill(pid, SIGKILL);
waitpid(pid, NULL, 0);
printf("Test 1-ok\n");
if ((fd = open("/bin/timer", O_WRONLY)) < 0)
perror("open(\"/bin/timer\", O_WRONLY)");
else
close(fd);
if ((fd = open("toto", O_WRONLY | O_CREAT)) < 0) {
perror("open(\"toto\", O_WRONLY)");
return 1;
}
printf("Test 2-ETXTBSY\n");
if (execv("toto", 0) < 0)
perror("exec(\"toto\", 0)");
close(fd);
printf("Test 2-ok\n");
if (execv("toto", 0) < 0)
perror("exec(\"toto\", 0)");
return 0;
}