mirror of
https://github.com/drasko/codezero.git
synced 2026-10-13 01:47:00 +02:00
Enhanced execve test error handling
This commit is contained in:
@@ -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";
|
||||||
|
|||||||
Reference in New Issue
Block a user