Print this page
15291 zfs-tests errno flaws exposed by 15220
@@ -22,10 +22,14 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
+/*
+ * Copyright 2022 MNX Cloud, Inc.
+ */
+
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
@@ -105,14 +109,15 @@
for (d = 0; d < ndir; d++) {
(void) memset(dname, '\0', sizeof (dname));
(void) strcpy(dname, getfdname(pdir, TYPE_D, level, d, 0));
if (mkdir(dname, 0777) != 0) {
+ int exitcode = errno;
(void) fprintf(stderr, "mkdir(%s) failed."
"\n[%d]: %s.\n",
dname, errno, strerror(errno));
- exit(errno);
+ exit(exitcode);
}
/*
* No sub-directory need be created, only create files in it.
*/
@@ -147,10 +152,11 @@
crtfile(char *pname)
{
int fd = -1;
int afd = -1;
int i, size;
+ int exitcode;
char *context = "0123456789ABCDF";
char *pbuf;
if (pname == NULL) {
exit(1);
@@ -162,29 +168,33 @@
int offset = i * strlen(context);
(void) snprintf(pbuf+offset, size-offset, "%s", context);
}
if ((fd = open(pname, O_CREAT|O_RDWR, 0777)) < 0) {
+ exitcode = errno;
(void) fprintf(stderr, "open(%s, O_CREAT|O_RDWR, 0777) failed."
"\n[%d]: %s.\n", pname, errno, strerror(errno));
- exit(errno);
+ exit(exitcode);
}
if (write(fd, pbuf, 1024) < 1024) {
+ exitcode = errno;
(void) fprintf(stderr, "write(fd, pbuf, 1024) failed."
"\n[%d]: %s.\n", errno, strerror(errno));
- exit(errno);
+ exit(exitcode);
}
if ((afd = openat(fd, "xattr", O_CREAT | O_RDWR | O_XATTR, 0777)) < 0) {
+ exitcode = errno;
(void) fprintf(stderr, "openat failed.\n[%d]: %s.\n",
errno, strerror(errno));
- exit(errno);
+ exit(exitcode);
}
if (write(afd, pbuf, 1024) < 1024) {
+ exitcode = errno;
(void) fprintf(stderr, "write(afd, pbuf, 1024) failed."
"\n[%d]: %s.\n", errno, strerror(errno));
- exit(errno);
+ exit(exitcode);
}
(void) close(afd);
(void) close(fd);
free(pbuf);