Enhanced execve test error handling

This commit is contained in:
Bahadir Balban
2009-06-01 15:33:36 +03:00
parent 3b9cda968d
commit 78a5ec9d6d
+17 -3
View File
@@ -29,8 +29,21 @@ int exectest(void)
/* First create a new file and write the executable data to that file */ /* First create a new file and write the executable data to that file */
if ((fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, S_IRWXU)) < 0) { if ((fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, S_IRWXU)) < 0) {
err = errno; err = errno;
test_printf("OPEN: %d\n", errno); test_printf("OPEN: %d, for %s\n", errno, filename);
goto out_err; /* If it is a minor error like EEXIST, create one with different name */
if (errno == EEXIST) {
sprintf(filename, "/home/bahadir/execfile%d-2",
getpid());
if ((fd = open(filename,
O_RDWR | O_CREAT | O_TRUNC, S_IRWXU))
< 0) {
printf("OPEN: %d, failed twice, "
"last time for %s\n",
errno, filename);
goto out_err;
}
} else
goto out_err;
} }
left = size; left = size;
@@ -41,8 +54,9 @@ int exectest(void)
left -= cnt; left -= cnt;
} }
if ((err = close(fd)) < 0) if ((err = close(fd)) < 0) {
goto out_err; goto out_err;
}
/* Set up some arguments */ /* Set up some arguments */
argv[0] = "FIRST ARG"; argv[0] = "FIRST ARG";