forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LibC: Remove 'int* aslave' parameter from forkpty()
Only keep track of that (and eventually close() it) internally instead. This argument is not present on other systems, so we were running into compatibility issues with ports. Also bring the implementation closer to Linux and OpenBSD by making sure to close the slave pty fd in the fork()'d child as well as _exit()'ing on login_tty() failure - it's non-POSIX, so those are our references here. :^)
- Loading branch information
Showing
3 changed files
with
22 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* | ||
* Copyright (c) 2018-2020, Andreas Kling <[email protected]> | ||
* Copyright (c) 2021, Gunnar Beutner <[email protected]> | ||
* Copyright (c) 2021, Linus Groh <[email protected]> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
@@ -66,20 +67,27 @@ int openpty(int* amaster, int* aslave, char* name, const struct termios* termp, | |
return 0; | ||
} | ||
|
||
pid_t forkpty(int* amaster, int* aslave, char* name, const struct termios* termp, const struct winsize* winp) | ||
pid_t forkpty(int* amaster, char* name, const struct termios* termp, const struct winsize* winp) | ||
{ | ||
int rc = openpty(amaster, aslave, name, termp, winp); | ||
if (rc < 0) | ||
return rc; | ||
rc = fork(); | ||
if (rc < 0) { | ||
close(*amaster); | ||
close(*aslave); | ||
int master; | ||
int slave; | ||
if (openpty(&master, &slave, name, termp, winp) < 0) | ||
return -1; | ||
pid_t pid = fork(); | ||
if (pid < 0) { | ||
close(master); | ||
close(slave); | ||
return -1; | ||
} | ||
if (pid == 0) { | ||
close(master); | ||
if (login_tty(slave) < 0) | ||
_exit(1); | ||
return 0; | ||
} | ||
if (rc == 0) | ||
rc = login_tty(*aslave); | ||
return rc; | ||
*amaster = master; | ||
close(slave); | ||
return pid; | ||
} | ||
|
||
int login_tty(int fd) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters