xref: /freebsd/sys/contrib/openzfs/tests/zfs-tests/cmd/zed_fd_spill-zedlet.c (revision 924226fba12cc9a228c73b956e1b7fa24c60b055)
1 /*
2  * Permission to use, copy, modify, and/or distribute this software for
3  * any purpose with or without fee is hereby granted.
4  *
5  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
6  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
7  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
8  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
9  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
10  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
11  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
12  */
13 
14 #include <sys/types.h>
15 #include <sys/wait.h>
16 #include <fcntl.h>
17 #include <unistd.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <stdio.h>
21 
22 int main(void) {
23 	if (fork()) {
24 		int err;
25 		wait(&err);
26 		return (err);
27 	}
28 
29 	char buf[64];
30 	sprintf(buf, "/tmp/zts-zed_fd_spill-logdir/%d", getppid());
31 	dup2(creat(buf, 0644), STDOUT_FILENO);
32 
33 	snprintf(buf, sizeof (buf), "/proc/%d/fd", getppid());
34 	execlp("ls", "ls", buf, NULL);
35 	_exit(127);
36 }
37