imsg no longer associates file descriptors with the imsg they were sent with,

work around this for the moment (it is not clear if this is intentional).
This commit is contained in:
Nicholas Marriott 2024-11-22 09:58:47 +00:00
parent 1365f1ce52
commit 0f308bd18f
3 changed files with 25 additions and 7 deletions

27
proc.c
View File

@ -55,6 +55,7 @@ struct tmuxpeer {
struct tmuxproc *parent;
struct imsgbuf ibuf;
int lastfd;
struct event event;
uid_t uid;
@ -71,7 +72,7 @@ static int peer_check_version(struct tmuxpeer *, struct imsg *);
static void proc_update_event(struct tmuxpeer *);
static void
proc_event_cb(__unused int fd, short events, void *arg)
proc_event_cb(int fd, short events, void *arg)
{
struct tmuxpeer *peer = arg;
ssize_t n;
@ -89,12 +90,16 @@ proc_event_cb(__unused int fd, short events, void *arg)
}
if (n == 0)
break;
log_debug("peer %p message %d", peer, imsg.hdr.type);
fd = imsg_get_fd(&imsg);
log_debug("peer %p message %d fd %d", peer,
imsg.hdr.type, fd);
if (fd != -1) {
if (peer->lastfd != -1)
close(peer->lastfd);
peer->lastfd = fd;
}
if (peer_check_version(peer, &imsg) != 0) {
fd = imsg_get_fd(&imsg);
if (fd != -1)
close(fd);
imsg_free(&imsg);
break;
}
@ -308,6 +313,7 @@ proc_add_peer(struct tmuxproc *tp, int fd,
peer = xcalloc(1, sizeof *peer);
peer->parent = tp;
peer->lastfd = -1;
peer->dispatchcb = dispatchcb;
peer->arg = arg;
@ -336,6 +342,8 @@ proc_remove_peer(struct tmuxpeer *peer)
event_del(&peer->event);
imsgbuf_clear(&peer->ibuf);
if (peer->lastfd != -1)
close(peer->lastfd);
close(peer->ibuf.fd);
free(peer);
}
@ -387,3 +395,12 @@ proc_get_peer_uid(struct tmuxpeer *peer)
{
return (peer->uid);
}
int
proc_get_last_fd(struct tmuxpeer *peer)
{
int fd = peer->lastfd;
peer->lastfd = -1;
return (fd);
}

View File

@ -3559,13 +3559,13 @@ server_client_dispatch_identify(struct client *c, struct imsg *imsg)
case MSG_IDENTIFY_STDIN:
if (datalen != 0)
fatalx("bad MSG_IDENTIFY_STDIN size");
c->fd = imsg_get_fd(imsg);
c->fd = proc_get_last_fd(c->peer);
log_debug("client %p IDENTIFY_STDIN %d", c, c->fd);
break;
case MSG_IDENTIFY_STDOUT:
if (datalen != 0)
fatalx("bad MSG_IDENTIFY_STDOUT size");
c->out_fd = imsg_get_fd(imsg);
c->out_fd = proc_get_last_fd(c->peer);
log_debug("client %p IDENTIFY_STDOUT %d", c, c->out_fd);
break;
case MSG_IDENTIFY_ENVIRON:

1
tmux.h
View File

@ -2225,6 +2225,7 @@ void proc_flush_peer(struct tmuxpeer *);
void proc_toggle_log(struct tmuxproc *);
pid_t proc_fork_and_daemon(int *);
uid_t proc_get_peer_uid(struct tmuxpeer *);
int proc_get_last_fd(struct tmuxpeer *);
/* cfg.c */
extern int cfg_finished;