- 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) 2003-4 Kian Duffy <[email protected]>
|
||||||
|
* Copyright (c) 2004 Daniel Furrer <[email protected]>
|
||||||
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
|
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
@@ -28,6 +29,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <dirent.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -56,7 +58,7 @@ extern char **environ;
|
|||||||
|
|
||||||
char spawn_alert_msg [] = \
|
char spawn_alert_msg [] = \
|
||||||
"alert --stop " \
|
"alert --stop " \
|
||||||
"'MuTerminal Error!!\n\
|
"'Haiku Terminal Error!!\n\
|
||||||
Cannot execute shell [%s].\n\
|
Cannot execute shell [%s].\n\
|
||||||
Check \"Shell\" in preferance panel.' "\
|
Check \"Shell\" in preferance panel.' "\
|
||||||
"'Exec /bin/sh' 'Abort'";
|
"'Exec /bin/sh' 'Abort'";
|
||||||
@@ -118,15 +120,12 @@ typedef struct
|
|||||||
/* global varriables */
|
/* global varriables */
|
||||||
|
|
||||||
pid_t sh_pid;
|
pid_t sh_pid;
|
||||||
char tty_name[16];
|
char tty_name[B_PATH_NAME_LENGTH];
|
||||||
int pfd_num = 0;
|
|
||||||
|
|
||||||
int
|
int
|
||||||
spawn_shell (int row, int col, const char *command, const char *coding)
|
spawn_shell (int row, int col, const char *command, const char *coding)
|
||||||
{
|
{
|
||||||
int done = 0;
|
int done = 0;
|
||||||
char *s;
|
|
||||||
char *t = 0;
|
|
||||||
pid_t pgrp;
|
pid_t pgrp;
|
||||||
|
|
||||||
int master = 0;
|
int master = 0;
|
||||||
@@ -136,8 +135,6 @@ spawn_shell (int row, int col, const char *command, const char *coding)
|
|||||||
|
|
||||||
handshake_t handshake;
|
handshake_t handshake;
|
||||||
|
|
||||||
char pty_name[16];
|
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
time_t now_time_t;
|
time_t now_time_t;
|
||||||
struct tm *now_time;
|
struct tm *now_time;
|
||||||
@@ -152,34 +149,36 @@ spawn_shell (int row, int col, const char *command, const char *coding)
|
|||||||
signal(SIGTTOU, SIG_IGN);
|
signal(SIGTTOU, SIG_IGN);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get a psuedo-tty. We do this by cycling through all the possible
|
* Get a psuedo-tty. We do this by cycling through files in the
|
||||||
* names. The oparationg system will not allow us to open a master
|
* directory. The oparationg system will not allow us to open a master
|
||||||
* which is already in use, so we simply go until the open successed.
|
* which is already in use, so we simply go until the open succeeds.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (s = PTYCHAR1; *s != 0; s++) {
|
DIR *dir;
|
||||||
for (t = PTYCHAR2; *t != 0; t++) {
|
dir = opendir("/dev/pt/");
|
||||||
sprintf (pty_name, PTYDEV, *s, *t);
|
|
||||||
if ((master = open (pty_name, O_RDWR)) >= 0)
|
struct dirent *dir_entry;
|
||||||
goto out;
|
char pty_name[B_PATH_NAME_LENGTH];
|
||||||
pfd_num++;
|
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 master is still < 0 then we haven't found a tty we can use
|
||||||
/*
|
if (master < 0)
|
||||||
* If s and t are NULL, we ran out of pseudo ttys before we found
|
{
|
||||||
* one we can use
|
printf("didn't find any available pesudo ttys.");
|
||||||
*/
|
|
||||||
if ((*s == 0) && (*t == 0)) {
|
|
||||||
printf ("don't found pesudo ttys.");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Change "/dev/pt/XX (master) to "/dev/tt/XX" (slave). */
|
// Set the tty that corresponds to the pty we found
|
||||||
|
sprintf (tty_name, "/dev/tt/%s", dir_entry->d_name);
|
||||||
sprintf (pty_name,"%c%c", *s, *t);
|
|
||||||
sprintf (tty_name, TTYDEV, *s, *t);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the modes of the current terminal. We will duplicates these
|
* 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;
|
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. */
|
/* Fork a child process. */
|
||||||
if ((sh_pid = fork()) < 0) {
|
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.
|
* 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
|
* Make our controlling tty the pseudo tty. This hapens because
|
||||||
* we cleared our original controlling terminal above.
|
* 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);
|
Setenv ("SHELL=", *args);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Print Welcome MuTerm World! Message.
|
* Print Welcome Message.
|
||||||
* (But, Only print message when MuTerminal coding is UTF8.)
|
* (But, Only print message when MuTerminal coding is UTF8.)
|
||||||
*/
|
*/
|
||||||
now_time_t = time(NULL);
|
now_time_t = time(NULL);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2003-4 Kian Duffy <[email protected]>
|
* 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.
|
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
@@ -31,19 +32,6 @@
|
|||||||
#ifndef SPAWN_H
|
#ifndef SPAWN_H
|
||||||
#define 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
|
#define MAXPTTYS 16 * 4
|
||||||
|
|
||||||
#ifndef CEOF
|
#ifndef CEOF
|
||||||
|
|||||||
Reference in New Issue
Block a user