cleaner and safer getpty() I wrote long ago.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23390 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -40,29 +40,20 @@ SpawningUploadClient::Connect(const string& server, const string& login, const s
|
|||||||
bool
|
bool
|
||||||
SpawningUploadClient::SpawnCommand()
|
SpawningUploadClient::SpawnCommand()
|
||||||
{
|
{
|
||||||
|
char ptypath[20];
|
||||||
|
char ttypath[20];
|
||||||
//XXX: should use a system-provided TerminalCommand class
|
//XXX: should use a system-provided TerminalCommand class
|
||||||
BString shellcmd = "exec";
|
BString shellcmd = "exec";
|
||||||
const char *args[] = { "/bin/sh", "-c", NULL, NULL };
|
const char *args[] = { "/bin/sh", "-c", NULL, NULL };
|
||||||
char path[20];
|
int pty = getpty(ptypath, ttypath);
|
||||||
int pty;
|
if (pty < 0)
|
||||||
for (pty = 0; pty < 0x50; pty++) {
|
return B_ERROR;
|
||||||
int fd;
|
|
||||||
sprintf(path, "/dev/pt/%c%1x", 'p' + pty / 16, pty & 0x0f);
|
shellcmd << " 0<" << ttypath;
|
||||||
printf("trying %s\n", path);
|
shellcmd << " 1>" << ttypath;
|
||||||
fd = open(path, O_RDWR);
|
|
||||||
if (fd < 0)
|
|
||||||
continue;
|
|
||||||
fPty = fd;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (fPty < 0)
|
|
||||||
return false;
|
|
||||||
sprintf(path, "/dev/tt/%c%1x", 'p' + pty / 16, pty & 0x0f);
|
|
||||||
shellcmd << " 0<" << path;
|
|
||||||
shellcmd << " 1>" << path;
|
|
||||||
shellcmd += " 2>&1";
|
shellcmd += " 2>&1";
|
||||||
shellcmd << " ; ";
|
shellcmd << " ; ";
|
||||||
shellcmd << "export TTY=" << path << "; "; // BeOS hack
|
shellcmd << "export TTY=" << ttypath << "; "; // BeOS hack
|
||||||
shellcmd << "export LC_ALL=C; export LANG=C; ";
|
shellcmd << "export LC_ALL=C; export LANG=C; ";
|
||||||
shellcmd << "exec ";
|
shellcmd << "exec ";
|
||||||
shellcmd << fCommand.c_str();
|
shellcmd << fCommand.c_str();
|
||||||
@@ -112,6 +103,32 @@ SpawningUploadClient::ParseReply()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
SpawningUploadClient::getpty(char *pty, char *tty)
|
||||||
|
{
|
||||||
|
static const char major[] = "pqrs";
|
||||||
|
static const char minor[] = "0123456789abcdef";
|
||||||
|
uint32 i, j;
|
||||||
|
int32 fd = -1;
|
||||||
|
|
||||||
|
for (i = 0; i < sizeof(major); i++)
|
||||||
|
{
|
||||||
|
for (j = 0; j < sizeof(minor); j++)
|
||||||
|
{
|
||||||
|
sprintf(pty, "/dev/pt/%c%c", major[i], minor[j]);
|
||||||
|
sprintf(tty, "/dev/tt/%c%c", major[i], minor[j]);
|
||||||
|
fd = open(pty, O_RDONLY|O_NOCTTY);
|
||||||
|
if (fd >= 0)
|
||||||
|
{
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* the rest is empty */
|
/* the rest is empty */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ status_t SetCommandLine(const char *command);
|
|||||||
ssize_t SendCommand(const char *cmd);
|
ssize_t SendCommand(const char *cmd);
|
||||||
ssize_t ReadReply(BString *to);
|
ssize_t ReadReply(BString *to);
|
||||||
virtual status_t ParseReply();
|
virtual status_t ParseReply();
|
||||||
|
int getpty(char *pty, char *tty);
|
||||||
|
|
||||||
int InputPipe() const { return fPty; };
|
int InputPipe() const { return fPty; };
|
||||||
int OutputPipe() const { return fPty; };
|
int OutputPipe() const { return fPty; };
|
||||||
|
|||||||
Reference in New Issue
Block a user