- rewrote the code that searches the for a free pty/tty - it is much cleaner now, as we talked about on the mailing list some time ago. \n- started to apply our styling guide \n- some changes not worth mentioning here and there ;)
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9534 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2003-4 Kian Duffy <[email protected]>
|
||||
* Copyright (c) 2004 Daniel Furrer <[email protected]>
|
||||
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
@@ -28,6 +29,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <dirent.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/file.h>
|
||||
#include <stdio.h>
|
||||
@@ -56,7 +58,7 @@ extern char **environ;
|
||||
|
||||
char spawn_alert_msg [] = \
|
||||
"alert --stop " \
|
||||
"'MuTerminal Error!!\n\
|
||||
"'Haiku Terminal Error!!\n\
|
||||
Cannot execute shell [%s].\n\
|
||||
Check \"Shell\" in preferance panel.' "\
|
||||
"'Exec /bin/sh' 'Abort'";
|
||||
@@ -118,15 +120,12 @@ typedef struct
|
||||
/* global varriables */
|
||||
|
||||
pid_t sh_pid;
|
||||
char tty_name[16];
|
||||
int pfd_num = 0;
|
||||
char tty_name[B_PATH_NAME_LENGTH];
|
||||
|
||||
int
|
||||
spawn_shell (int row, int col, const char *command, const char *coding)
|
||||
{
|
||||
int done = 0;
|
||||
char *s;
|
||||
char *t = 0;
|
||||
pid_t pgrp;
|
||||
|
||||
int master = 0;
|
||||
@@ -136,8 +135,6 @@ spawn_shell (int row, int col, const char *command, const char *coding)
|
||||
|
||||
handshake_t handshake;
|
||||
|
||||
char pty_name[16];
|
||||
|
||||
int i = 0;
|
||||
time_t now_time_t;
|
||||
struct tm *now_time;
|
||||
@@ -152,34 +149,36 @@ spawn_shell (int row, int col, const char *command, const char *coding)
|
||||
signal(SIGTTOU, SIG_IGN);
|
||||
|
||||
/*
|
||||
* Get a psuedo-tty. We do this by cycling through all the possible
|
||||
* names. The oparationg system will not allow us to open a master
|
||||
* which is already in use, so we simply go until the open successed.
|
||||
* Get a psuedo-tty. We do this by cycling through files in the
|
||||
* directory. The oparationg system will not allow us to open a master
|
||||
* which is already in use, so we simply go until the open succeeds.
|
||||
*/
|
||||
|
||||
for (s = PTYCHAR1; *s != 0; s++) {
|
||||
for (t = PTYCHAR2; *t != 0; t++) {
|
||||
sprintf (pty_name, PTYDEV, *s, *t);
|
||||
if ((master = open (pty_name, O_RDWR)) >= 0)
|
||||
goto out;
|
||||
pfd_num++;
|
||||
}
|
||||
DIR *dir;
|
||||
dir = opendir("/dev/pt/");
|
||||
|
||||
struct dirent *dir_entry;
|
||||
char pty_name[B_PATH_NAME_LENGTH];
|
||||
while(NULL != (dir_entry = readdir(dir)))
|
||||
{
|
||||
if (dir_entry->d_name[0] == '.') // skip . and ..
|
||||
continue;
|
||||
sprintf(pty_name, "/dev/pt/%s", dir_entry->d_name);
|
||||
printf("%s\n", pty_name);
|
||||
master = open(pty_name, O_RDWR);
|
||||
if (master >= 0)
|
||||
break;
|
||||
}
|
||||
|
||||
out:
|
||||
/*
|
||||
* If s and t are NULL, we ran out of pseudo ttys before we found
|
||||
* one we can use
|
||||
*/
|
||||
if ((*s == 0) && (*t == 0)) {
|
||||
printf ("don't found pesudo ttys.");
|
||||
// If master is still < 0 then we haven't found a tty we can use
|
||||
if (master < 0)
|
||||
{
|
||||
printf("didn't find any available pesudo ttys.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Change "/dev/pt/XX (master) to "/dev/tt/XX" (slave). */
|
||||
|
||||
sprintf (pty_name,"%c%c", *s, *t);
|
||||
sprintf (tty_name, TTYDEV, *s, *t);
|
||||
// Set the tty that corresponds to the pty we found
|
||||
sprintf (tty_name, "/dev/tt/%s", dir_entry->d_name);
|
||||
|
||||
/*
|
||||
* Get the modes of the current terminal. We will duplicates these
|
||||
@@ -192,13 +191,6 @@ spawn_shell (int row, int col, const char *command, const char *coding)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* If set prosess group ID is MuTerminal process ID, MuTerminal
|
||||
* ignore SIGINT for exec Terminal.
|
||||
*
|
||||
* pgrp = getpid ();
|
||||
* setpgid (0, pgrp);
|
||||
*/
|
||||
|
||||
/* Fork a child process. */
|
||||
if ((sh_pid = fork()) < 0) {
|
||||
@@ -211,11 +203,6 @@ spawn_shell (int row, int col, const char *command, const char *coding)
|
||||
* Now in child process.
|
||||
*/
|
||||
|
||||
/* close master pty and control tty. */
|
||||
// close (tty);
|
||||
// for (i = 0; i <= 2; i++)
|
||||
// close (i);
|
||||
|
||||
/*
|
||||
* Make our controlling tty the pseudo tty. This hapens because
|
||||
* we cleared our original controlling terminal above.
|
||||
@@ -405,7 +392,7 @@ spawn_shell (int row, int col, const char *command, const char *coding)
|
||||
Setenv ("SHELL=", *args);
|
||||
|
||||
/*
|
||||
* Print Welcome MuTerm World! Message.
|
||||
* Print Welcome Message.
|
||||
* (But, Only print message when MuTerminal coding is UTF8.)
|
||||
*/
|
||||
now_time_t = time(NULL);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2003-4 Kian Duffy <[email protected]>
|
||||
* Copyright (c) 2004 Daniel Furrer <[email protected]>
|
||||
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
@@ -31,19 +32,6 @@
|
||||
#ifndef SPAWN_H
|
||||
#define SPAWN_H
|
||||
|
||||
/*
|
||||
* allow for mobility of the pty master/slave directories
|
||||
*/
|
||||
|
||||
#define PTYDEV "/dev/pt/%c%c"
|
||||
#define TTYDEV "/dev/tt/%c%c"
|
||||
|
||||
#define PTYCHAR1 "pqrs"
|
||||
#define PTYCHAR2 "0123456789abcdef"
|
||||
|
||||
#define TTYFORMAT "/dev/tt/%d"
|
||||
#define PTYFORMAT "/dev/pt/%d"
|
||||
|
||||
#define MAXPTTYS 16 * 4
|
||||
|
||||
#ifndef CEOF
|
||||
|
||||
Reference in New Issue
Block a user