Print this page
15291 zfs-tests errno flaws exposed by 15220

*** 22,31 **** --- 22,35 ---- /* * 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,118 **** 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) { (void) fprintf(stderr, "mkdir(%s) failed." "\n[%d]: %s.\n", dname, errno, strerror(errno)); ! exit(errno); } /* * No sub-directory need be created, only create files in it. */ --- 109,123 ---- 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(exitcode); } /* * No sub-directory need be created, only create files in it. */
*** 147,156 **** --- 152,162 ---- 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,190 **** int offset = i * strlen(context); (void) snprintf(pbuf+offset, size-offset, "%s", context); } if ((fd = open(pname, O_CREAT|O_RDWR, 0777)) < 0) { (void) fprintf(stderr, "open(%s, O_CREAT|O_RDWR, 0777) failed." "\n[%d]: %s.\n", pname, errno, strerror(errno)); ! exit(errno); } if (write(fd, pbuf, 1024) < 1024) { (void) fprintf(stderr, "write(fd, pbuf, 1024) failed." "\n[%d]: %s.\n", errno, strerror(errno)); ! exit(errno); } if ((afd = openat(fd, "xattr", O_CREAT | O_RDWR | O_XATTR, 0777)) < 0) { (void) fprintf(stderr, "openat failed.\n[%d]: %s.\n", errno, strerror(errno)); ! exit(errno); } if (write(afd, pbuf, 1024) < 1024) { (void) fprintf(stderr, "write(afd, pbuf, 1024) failed." "\n[%d]: %s.\n", errno, strerror(errno)); ! exit(errno); } (void) close(afd); (void) close(fd); free(pbuf); --- 168,200 ---- 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(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(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(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(exitcode); } (void) close(afd); (void) close(fd); free(pbuf);