Use an exit code of 1 instead of -1 for reasons noted in r319056
MFC after: 3 days Sponsored by: Dell EMC Isilon
This commit is contained in:
parent
ba6949f2bf
commit
ea252998ad
@ -61,7 +61,7 @@ do_accept(__unused void *arg)
|
||||
|
||||
accept_fd = accept(listen_fd, NULL, NULL);
|
||||
if (accept_fd < 0)
|
||||
err(-1, "accept");
|
||||
err(1, "accept");
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
@ -73,7 +73,7 @@ do_fork(void)
|
||||
|
||||
pid = fork();
|
||||
if (pid < 0)
|
||||
err(-1, "fork");
|
||||
err(1, "fork");
|
||||
if (pid > 0) {
|
||||
waitpid(pid, NULL, 0);
|
||||
exit(0);
|
||||
@ -84,15 +84,15 @@ do_fork(void)
|
||||
* listen_fd+1, and get back EBADF if it's not a valid descriptor,
|
||||
* and EINVAL if it is. This (currently) works fine in practice.
|
||||
*/
|
||||
if (ftruncate(listen_fd + 1, 0 < 0)) {
|
||||
if (ftruncate(listen_fd + 1, 0) < 0) {
|
||||
if (errno == EBADF)
|
||||
exit(0);
|
||||
else if (errno == EINVAL)
|
||||
errx(-1, "file descriptor still open in child");
|
||||
errx(1, "file descriptor still open in child");
|
||||
else
|
||||
err(-1, "unexpected error");
|
||||
err(1, "unexpected error");
|
||||
} else
|
||||
errx(-1, "ftruncate succeeded");
|
||||
errx(1, "ftruncate succeeded");
|
||||
}
|
||||
|
||||
int
|
||||
@ -103,18 +103,18 @@ main(__unused int argc, __unused char *argv[])
|
||||
|
||||
listen_fd = socket(PF_INET, SOCK_STREAM, 0);
|
||||
if (listen_fd < 0)
|
||||
err(-1, "socket");
|
||||
err(1, "socket");
|
||||
bzero(&sin, sizeof(sin));
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_len = sizeof(sin);
|
||||
sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||
sin.sin_port = htons(PORT);
|
||||
if (bind(listen_fd, (struct sockaddr *)&sin, sizeof(sin)) < 0)
|
||||
err(-1, "bind");
|
||||
err(1, "bind");
|
||||
if (listen(listen_fd, -1) <0)
|
||||
err(-1, "listen");
|
||||
err(1, "listen");
|
||||
if (pthread_create(&accept_thread, NULL, do_accept, NULL) != 0)
|
||||
err(-1, "pthread_create");
|
||||
err(1, "pthread_create");
|
||||
sleep(1); /* Easier than using a CV. */
|
||||
do_fork();
|
||||
exit(0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user