Print an error message if we could not execute the desired command, instead of
exiting silently. Also make sure the master process waits until the client attaches when using the -A and -c modes, so that the error message has a chance of being seen.
This commit is contained in:
parent
3b070abf7a
commit
5f6d552d2c
3
attach.c
3
attach.c
|
|
@ -34,9 +34,6 @@ static struct termios cur_term;
|
||||||
/* 1 if the window size changed */
|
/* 1 if the window size changed */
|
||||||
static int win_changed;
|
static int win_changed;
|
||||||
|
|
||||||
/* This hopefully moves to the bottom of the screen */
|
|
||||||
#define EOS "\033[999H"
|
|
||||||
|
|
||||||
/* Restores the original terminal settings. */
|
/* Restores the original terminal settings. */
|
||||||
static void
|
static void
|
||||||
restore_term(void)
|
restore_term(void)
|
||||||
|
|
|
||||||
5
dtach.h
5
dtach.h
|
|
@ -116,8 +116,11 @@ struct packet
|
||||||
*/
|
*/
|
||||||
#define BUFSIZE 4096
|
#define BUFSIZE 4096
|
||||||
|
|
||||||
|
/* This hopefully moves to the bottom of the screen */
|
||||||
|
#define EOS "\033[999H"
|
||||||
|
|
||||||
int attach_main(int noerror);
|
int attach_main(int noerror);
|
||||||
int master_main(char **argv);
|
int master_main(char **argv, int waitattach);
|
||||||
|
|
||||||
#ifdef sun
|
#ifdef sun
|
||||||
#define BROKEN_MASTER
|
#define BROKEN_MASTER
|
||||||
|
|
|
||||||
6
main.c
6
main.c
|
|
@ -243,10 +243,10 @@ main(int argc, char **argv)
|
||||||
return attach_main(0);
|
return attach_main(0);
|
||||||
}
|
}
|
||||||
else if (mode == 'n')
|
else if (mode == 'n')
|
||||||
return master_main(argv);
|
return master_main(argv, 0);
|
||||||
else if (mode == 'c')
|
else if (mode == 'c')
|
||||||
{
|
{
|
||||||
if (master_main(argv) != 0)
|
if (master_main(argv, 1) != 0)
|
||||||
return 1;
|
return 1;
|
||||||
return attach_main(0);
|
return attach_main(0);
|
||||||
}
|
}
|
||||||
|
|
@ -256,7 +256,7 @@ main(int argc, char **argv)
|
||||||
** socket. */
|
** socket. */
|
||||||
if (attach_main(1) != 0)
|
if (attach_main(1) != 0)
|
||||||
{
|
{
|
||||||
if (master_main(argv) != 0)
|
if (master_main(argv, 1) != 0)
|
||||||
return 1;
|
return 1;
|
||||||
return attach_main(0);
|
return attach_main(0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
33
master.c
33
master.c
|
|
@ -124,6 +124,8 @@ init_pty(char **argv)
|
||||||
{
|
{
|
||||||
/* Child.. Execute the program. */
|
/* Child.. Execute the program. */
|
||||||
execvp(*argv, argv);
|
execvp(*argv, argv);
|
||||||
|
printf(EOS "\r\n%s: could not execute %s: %s\r\n",
|
||||||
|
progname, *argv, strerror(errno));
|
||||||
exit(127);
|
exit(127);
|
||||||
}
|
}
|
||||||
/* Parent.. Finish up and return */
|
/* Parent.. Finish up and return */
|
||||||
|
|
@ -394,7 +396,7 @@ client_activity(struct client *p)
|
||||||
/* The master process - It watches over the pty process and the attached */
|
/* The master process - It watches over the pty process and the attached */
|
||||||
/* clients. */
|
/* clients. */
|
||||||
static void
|
static void
|
||||||
master_process(int s, char **argv)
|
master_process(int s, char **argv, int waitattach)
|
||||||
{
|
{
|
||||||
struct client *p, *next;
|
struct client *p, *next;
|
||||||
fd_set readfds;
|
fd_set readfds;
|
||||||
|
|
@ -440,11 +442,17 @@ master_process(int s, char **argv)
|
||||||
/* Re-initialize the file descriptor set for select. */
|
/* Re-initialize the file descriptor set for select. */
|
||||||
FD_ZERO(&readfds);
|
FD_ZERO(&readfds);
|
||||||
FD_SET(s, &readfds);
|
FD_SET(s, &readfds);
|
||||||
FD_SET(the_pty.fd, &readfds);
|
highest_fd = s;
|
||||||
if (s > the_pty.fd)
|
|
||||||
highest_fd = s;
|
if (clients && clients->attached)
|
||||||
else
|
waitattach = 0;
|
||||||
highest_fd = the_pty.fd;
|
if (!waitattach)
|
||||||
|
{
|
||||||
|
FD_SET(the_pty.fd, &readfds);
|
||||||
|
if (the_pty.fd > highest_fd)
|
||||||
|
highest_fd = the_pty.fd;
|
||||||
|
}
|
||||||
|
|
||||||
for (p = clients; p; p = p->next)
|
for (p = clients; p; p = p->next)
|
||||||
{
|
{
|
||||||
FD_SET(p->fd, &readfds);
|
FD_SET(p->fd, &readfds);
|
||||||
|
|
@ -458,10 +466,8 @@ master_process(int s, char **argv)
|
||||||
if (errno == EINTR || errno == EAGAIN)
|
if (errno == EINTR || errno == EAGAIN)
|
||||||
continue;
|
continue;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
/* pty activity? */
|
|
||||||
if (FD_ISSET(the_pty.fd, &readfds))
|
|
||||||
pty_activity(s);
|
|
||||||
/* New client? */
|
/* New client? */
|
||||||
if (FD_ISSET(s, &readfds))
|
if (FD_ISSET(s, &readfds))
|
||||||
control_activity(s);
|
control_activity(s);
|
||||||
|
|
@ -472,11 +478,14 @@ master_process(int s, char **argv)
|
||||||
if (FD_ISSET(p->fd, &readfds))
|
if (FD_ISSET(p->fd, &readfds))
|
||||||
client_activity(p);
|
client_activity(p);
|
||||||
}
|
}
|
||||||
|
/* pty activity? */
|
||||||
|
if (FD_ISSET(the_pty.fd, &readfds))
|
||||||
|
pty_activity(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
master_main(char **argv)
|
master_main(char **argv, int waitattach)
|
||||||
{
|
{
|
||||||
int s;
|
int s;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
@ -503,7 +512,7 @@ master_main(char **argv)
|
||||||
else if (pid == 0)
|
else if (pid == 0)
|
||||||
{
|
{
|
||||||
/* Child - this becomes the master */
|
/* Child - this becomes the master */
|
||||||
master_process(s, argv);
|
master_process(s, argv, waitattach);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* Parent - just return. */
|
/* Parent - just return. */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue