diff --git a/src/apps/codycam/SpawningUploadClient.cpp b/src/apps/codycam/SpawningUploadClient.cpp index c4e9d971e2..9d5accffd4 100644 --- a/src/apps/codycam/SpawningUploadClient.cpp +++ b/src/apps/codycam/SpawningUploadClient.cpp @@ -40,29 +40,20 @@ SpawningUploadClient::Connect(const string& server, const string& login, const s bool SpawningUploadClient::SpawnCommand() { + char ptypath[20]; + char ttypath[20]; //XXX: should use a system-provided TerminalCommand class BString shellcmd = "exec"; const char *args[] = { "/bin/sh", "-c", NULL, NULL }; - char path[20]; - int pty; - for (pty = 0; pty < 0x50; pty++) { - int fd; - sprintf(path, "/dev/pt/%c%1x", 'p' + pty / 16, pty & 0x0f); - printf("trying %s\n", path); - 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; + int pty = getpty(ptypath, ttypath); + if (pty < 0) + return B_ERROR; + + shellcmd << " 0<" << ttypath; + shellcmd << " 1>" << ttypath; shellcmd += " 2>&1"; shellcmd << " ; "; - shellcmd << "export TTY=" << path << "; "; // BeOS hack + shellcmd << "export TTY=" << ttypath << "; "; // BeOS hack shellcmd << "export LC_ALL=C; export LANG=C; "; shellcmd << "exec "; 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 */ diff --git a/src/apps/codycam/SpawningUploadClient.h b/src/apps/codycam/SpawningUploadClient.h index bf083b3e39..b2e1c60785 100644 --- a/src/apps/codycam/SpawningUploadClient.h +++ b/src/apps/codycam/SpawningUploadClient.h @@ -35,6 +35,7 @@ status_t SetCommandLine(const char *command); ssize_t SendCommand(const char *cmd); ssize_t ReadReply(BString *to); virtual status_t ParseReply(); +int getpty(char *pty, char *tty); int InputPipe() const { return fPty; }; int OutputPipe() const { return fPty; };