/* {{{ Declarations */
-#include <stdio.h>
+#include <stdio.h>
#include <stdlib.h> /* For errno, putenv, etc. */
#include <errno.h> /* For errno on SunOS systems */
#include <termios.h> /* tcgetattr(), struct termios, etc. */
/* Braindead tcsh can't redirect output to a file descriptor? */
char tcsh_fifo[sizeof "/tmp/mc.pipe.1234567890"];
-
+
#ifdef SYNC_PTY_SIDES
/* Used to wait for a SIGUSR1 signal from the subprocess */
sigset_t sigusr1_mask, old_mask;
subshell_alive = TRUE;
subshell_stopped = FALSE;
subshell_pid = fork ();
-
+
if (subshell_pid == -1)
{
perror (__FILE__": couldn't spawn the subshell process");
if (subshell_pid == 0) /* We are in the child process */
{
char *init_file = NULL;
-
+
setsid (); /* Get a fresh terminal session */
/* {{{ Open the slave side of the pty: again */
init_sigchld ();
- /* We could have received the SIGCHLD signal for the subshell
+ /* We could have received the SIGCHLD signal for the subshell
* before installing the init_sigchld */
pid = waitpid (subshell_pid, &status, WUNTRACED | WNOHANG);
if (pid == subshell_pid){
/* {{{ Fiddle with terminal modes */
static struct termios raw_mode = {0};
-
+
/* MC calls reset_shell_mode() in pre_exec() to set the real tty to its */
/* original settings. However, here we need to make this tty very raw, */
/* so that all keyboard signals, XON/XOFF, etc. will get through to the */
tcsetattr (STDOUT_FILENO, TCSANOW, &raw_mode);
/* }}} */
-
+
/* Make the subshell change to MC's working directory */
if (new_dir)
do_subshell_chdir (cpanel->cwd, TRUE, 1);
-
+
if (command == NULL) /* The user has done "C-o" from MC */
{
if (subshell_state == INACTIVE)
clear_now = TRUE;
if (!pty_buffer [i])
continue;
-
+
subshell_prompt[prompt_pos++] = pty_buffer[i];
if (prompt_pos == prompt_size)
subshell_prompt = (char *) realloc (subshell_prompt,
int exit_subshell (void)
{
int quit = TRUE;
-
+
if (subshell_state != INACTIVE && subshell_alive)
quit = !query_dialog (_(" Warning "), _(" The shell is still active. Quit anyway? "),
0, 2, _("&Yes"), _("&No"));
if (unlink (pty_buffer) == -1)
perror (__FILE__": couldn't remove named pipe /tmp/mc.pipe.NNN");
}
-
+
return quit;
}
void do_subshell_chdir (char *directory, int do_update, int reset_prompt)
{
char *temp;
-
+
if (!(subshell_state == INACTIVE && strcmp (subshell_cwd, cpanel->cwd))){
/* We have to repaint the subshell prompt if we read it from
* the main program. Please note that in the code after this
do_update_prompt ();
return;
}
-
+
/* The initial space keeps this out of the command history (in bash
because we set "HISTCONTROL=ignorespace") */
write (subshell_pty, " cd ", 4);
if (*directory) {
temp = name_quote (directory, 0);
- write (subshell_pty, temp, strlen (temp));
+ write (subshell_pty, temp, strlen (temp));
free (temp);
} else {
write (subshell_pty, "/", 1);
}
write (subshell_pty, "\n", 1);
-
+
subshell_state = RUNNING_COMMAND;
feed_subshell (QUIETLY, FALSE);
-
+
if (subshell_alive && strcmp (subshell_cwd, cpanel->cwd) && strcmp (cpanel->cwd, "."))
fprintf (stderr, _("Warning: Couldn't change to %s.\n"), cpanel->cwd);
#ifndef HAVE_X
#ifndef SCO_FLAVOR
pid = waitpid (cons_saver_pid, &status, WUNTRACED | WNOHANG);
-
+
if (pid == cons_saver_pid) {
/* {{{ Someone has stopped or killed cons.saver; restart it */
fd_set read_set; /* For `select' */
int bytes; /* For the return value from `read' */
int i; /* Loop counter */
-
+
struct timeval wtime; /* Maximum time we wait for the subshell */
struct timeval *wptr;
/* }}} */
/* we wait up to 10 seconds if fail_on_error */
wtime.tv_sec = 10;
wtime.tv_usec = 0;
-
+
for (wptr = fail_on_error ? &wtime : NULL;;)
{
if (!subshell_alive)
/* From now on: block forever on the select call */
wptr = NULL;
-
+
if (FD_ISSET (subshell_pty, &read_set))
/* {{{ Read from the subshell, write to stdout */
{
int pty_slave;
struct group *group_info = getgrnam ("terminal");
-
+
if (group_info != NULL)
{
/* The following two calls will only succeed if we are root */
close (pty_slave);
return -1;
}
-
+
if (!ioctl (pty_slave, I_FIND, "ldterm"))
if (ioctl (pty_slave, I_PUSH, "ldterm") == -1)
{