/* Copyright (C) 2008 Emmanuel Varoquaux This file is part of XOS. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include #include 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)"); /* ETXTBSY */ 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)"); /* ETXTBSY */ close(fd); printf("Test 2-ok\n"); if (execv("toto", 0) < 0) perror("exec(\"toto\", 0)"); /* EINVAL */ return 0; }