Use the short way of opening a pty.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25136 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
cc6e7cb347
commit
1669306c8a
@ -283,44 +283,23 @@ Shell::_Spawn(int row, int col, const char *encoding, int argc, const char **arg
|
|||||||
|
|
||||||
signal(SIGTTOU, SIG_IGN);
|
signal(SIGTTOU, SIG_IGN);
|
||||||
|
|
||||||
/*
|
// get a pseudo-tty
|
||||||
* Get a pseudo-tty. We do this by cycling through files in the
|
int master = posix_openpt(O_RDWR | O_NOCTTY);
|
||||||
* directory. The operating system will not allow us to open a master
|
const char *ttyName;
|
||||||
* which is already in use, so we simply go until the open succeeds.
|
|
||||||
*/
|
|
||||||
char ttyName[B_PATH_NAME_LENGTH];
|
|
||||||
int master = -1;
|
|
||||||
DIR *dir = opendir("/dev/pt/");
|
|
||||||
if (dir != NULL) {
|
|
||||||
struct dirent *dirEntry;
|
|
||||||
while ((dirEntry = readdir(dir)) != NULL) {
|
|
||||||
// skip '.' and '..'
|
|
||||||
if (dirEntry->d_name[0] == '.')
|
|
||||||
continue;
|
|
||||||
|
|
||||||
char ptyName[B_PATH_NAME_LENGTH];
|
|
||||||
snprintf(ptyName, sizeof(ptyName), "/dev/pt/%s", dirEntry->d_name);
|
|
||||||
|
|
||||||
master = open(ptyName, O_RDWR);
|
|
||||||
if (master >= 0) {
|
|
||||||
// Set the tty that corresponds to the pty we found
|
|
||||||
snprintf(ttyName, sizeof(ttyName), "/dev/tt/%s", dirEntry->d_name);
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
// B_BUSY is a normal case
|
|
||||||
if (errno != B_BUSY)
|
|
||||||
fprintf(stderr, "could not open %s: %s\n", ptyName, strerror(errno));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir(dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (master < 0) {
|
if (master < 0) {
|
||||||
fprintf(stderr, "didn't find any available pseudo ttys.");
|
fprintf(stderr, "Didn't find any available pseudo ttys.");
|
||||||
return B_ERROR;
|
return errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
if (grantpt(master) != 0 || unlockpt(master) != 0
|
||||||
|
|| (ttyName = ptsname(master)) == NULL) {
|
||||||
|
close(master);
|
||||||
|
fprintf(stderr, "Failed to init pseudo tty.");
|
||||||
|
return errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
* Get the modes of the current terminal. We will duplicates these
|
* Get the modes of the current terminal. We will duplicates these
|
||||||
* on the pseudo terminal.
|
* on the pseudo terminal.
|
||||||
*/
|
*/
|
||||||
@ -352,10 +331,6 @@ Shell::_Spawn(int row, int col, const char *encoding, int argc, const char **arg
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* change pty owner and access mode. */
|
|
||||||
chown(ttyName, getuid(), getgid());
|
|
||||||
chmod(ttyName, S_IRUSR | S_IWUSR);
|
|
||||||
|
|
||||||
/* open slave pty */
|
/* open slave pty */
|
||||||
int slave = -1;
|
int slave = -1;
|
||||||
if ((slave = open(ttyName, O_RDWR)) < 0) {
|
if ((slave = open(ttyName, O_RDWR)) < 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user