mirror_zfs/tests/zfs-tests/cmd/zed_fd_spill-zedlet.c
Richard Yao 570ca4441e
Miscellaneous ZTS fixes
Coverity had various complaints about minor issues. They are all fairly
straightforward to understand without reading additional files, with the
exception of the draid.c issue. vdev_draid_rand() takes a 128-bit
starting seed, but we were passing a pointer to a 64-bit value, which
understandably made Coverity complain. This is perhaps the only
significant issue fixed in this patch, since it causes stack corruption.

These are not all of the issues in the ZTS that Coverity caught, but a
number of them are already fixed in other PRs. There is also a class of
TOUTOC complaints that involve very minor things in the ZTS (e.g.
access() before unlink()). I have yet to decide whether they are false
positives (since this is not security sensitive code) or something to
cleanup.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Neal Gompa <ngompa@datto.com>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #13943
2022-09-29 08:56:42 -07:00

50 lines
1.4 KiB
C

/*
* Permission to use, copy, modify, and/or distribute this software for
* any purpose with or without fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int main(void) {
if (fork()) {
int err;
wait(&err);
return (err);
}
char buf[64];
sprintf(buf, "/tmp/zts-zed_fd_spill-logdir/%d", getppid());
int fd = creat(buf, 0644);
if (fd == -1) {
(void) fprintf(stderr, "creat(%s) failed: %s\n", buf,
strerror(errno));
exit(EXIT_FAILURE);
}
if (dup2(fd, STDOUT_FILENO) == -1) {
close(fd);
(void) fprintf(stderr, "dup2(%s, STDOUT_FILENO) failed: %s\n",
buf, strerror(errno));
exit(EXIT_FAILURE);
}
snprintf(buf, sizeof (buf), "/proc/%d/fd", getppid());
execlp("ls", "ls", buf, NULL);
_exit(127);
}