mirror of
https://github.com/tmate-io/tmate.git
synced 2025-04-24 03:19:47 +02:00
Synchronize forkpty master and child to avoid hang on AIX with fast exiting
child and output left in the queue, from J Raynor.
This commit is contained in:
parent
938d91d2c3
commit
4d53fd98a6
@ -23,16 +23,20 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stropts.h>
|
#include <stropts.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
pid_t
|
pid_t
|
||||||
forkpty(int *master, unused char *name, struct termios *tio, struct winsize *ws)
|
forkpty(int *master, unused char *name, struct termios *tio, struct winsize *ws)
|
||||||
{
|
{
|
||||||
int slave, fd;
|
int slave, fd, pipe_fd[2];
|
||||||
char *path;
|
char *path, dummy;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
|
if (pipe(pipe_fd) == -1)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
if ((*master = open("/dev/ptc", O_RDWR|O_NOCTTY)) == -1)
|
if ((*master = open("/dev/ptc", O_RDWR|O_NOCTTY)) == -1)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
@ -47,6 +51,13 @@ forkpty(int *master, unused char *name, struct termios *tio, struct winsize *ws)
|
|||||||
case 0:
|
case 0:
|
||||||
close(*master);
|
close(*master);
|
||||||
|
|
||||||
|
close(pipe_fd[1]);
|
||||||
|
while (read(pipe_fd[0], &dummy, 1) == -1) {
|
||||||
|
if (errno != EINTR)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
close(pipe_fd[0]);
|
||||||
|
|
||||||
fd = open(_PATH_TTY, O_RDWR|O_NOCTTY);
|
fd = open(_PATH_TTY, O_RDWR|O_NOCTTY);
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
ioctl(fd, TIOCNOTTY, NULL);
|
ioctl(fd, TIOCNOTTY, NULL);
|
||||||
@ -80,13 +91,20 @@ forkpty(int *master, unused char *name, struct termios *tio, struct winsize *ws)
|
|||||||
dup2(slave, 2);
|
dup2(slave, 2);
|
||||||
if (slave > 2)
|
if (slave > 2)
|
||||||
close(slave);
|
close(slave);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close(pipe_fd[0]);
|
||||||
|
close(pipe_fd[1]);
|
||||||
|
|
||||||
close(slave);
|
close(slave);
|
||||||
return (pid);
|
return (pid);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
close(pipe_fd[0]);
|
||||||
|
close(pipe_fd[1]);
|
||||||
|
|
||||||
if (*master != -1)
|
if (*master != -1)
|
||||||
close(*master);
|
close(*master);
|
||||||
if (slave != -1)
|
if (slave != -1)
|
||||||
|
Loading…
Reference in New Issue
Block a user