From: Nicholas Marriott Subject: Re: use imsg_get_fd in file and tmux To: Nicholas Marriott , tech Date: Tue, 16 Jan 2024 12:58:45 +0000 looks fine, ok nicm On Tue, 16 Jan 2024, 11:26 Claudio Jeker, wrote: > On Wed, Dec 13, 2023 at 12:53:57PM +0100, Claudio Jeker wrote: > > Use imsg_get_fd() from the new imsg API in file and tmux. > > > > In tmux it shows how using imsg_get_fd() everywhere will allow to > simplify > > fd handling with imsgs since the code in proc.c will become redundant in > > the future. > > > > file regress still pass and tmux still works for me. > > ping > > -- > :wq Claudio > > Index: usr.bin/file/file.c > =================================================================== > RCS file: /cvs/src/usr.bin/file/file.c,v > diff -u -p -r1.69 file.c > --- usr.bin/file/file.c 30 Nov 2019 14:01:45 -0000 1.69 > +++ usr.bin/file/file.c 13 Dec 2023 10:06:43 -0000 > @@ -418,12 +418,12 @@ child(int fd, pid_t parent, int argc, ch > inf.msg = msg; > > inf.path = argv[idx]; > - inf.fd = imsg.fd; > + inf.fd = imsg_get_fd(&imsg); > > test_file(&inf, width); > > - if (imsg.fd != -1) > - close(imsg.fd); > + if (inf.fd != -1) > + close(inf.fd); > imsg_free(&imsg); > > ack.idx = idx; > Index: usr.bin/tmux/proc.c > =================================================================== > RCS file: /cvs/src/usr.bin/tmux/proc.c,v > diff -u -p -r1.22 proc.c > --- usr.bin/tmux/proc.c 30 May 2022 12:48:57 -0000 1.22 > +++ usr.bin/tmux/proc.c 13 Dec 2023 10:10:46 -0000 > @@ -92,8 +92,9 @@ proc_event_cb(__unused int fd, short eve > log_debug("peer %p message %d", peer, > imsg.hdr.type); > > if (peer_check_version(peer, &imsg) != 0) { > - if (imsg.fd != -1) > - close(imsg.fd); > + int fd = imsg_get_fd(&imsg); > + if (fd != -1) > + close(fd); > imsg_free(&imsg); > break; > } > Index: usr.bin/tmux/server-client.c > =================================================================== > RCS file: /cvs/src/usr.bin/tmux/server-client.c,v > diff -u -p -r1.402 server-client.c > --- usr.bin/tmux/server-client.c 2 Sep 2023 20:03:10 -0000 > 1.402 > +++ usr.bin/tmux/server-client.c 13 Dec 2023 10:09:29 -0000 > @@ -3000,14 +3000,14 @@ server_client_dispatch_identify(struct c > case MSG_IDENTIFY_STDIN: > if (datalen != 0) > fatalx("bad MSG_IDENTIFY_STDIN size"); > - c->fd = imsg->fd; > - log_debug("client %p IDENTIFY_STDIN %d", c, imsg->fd); > + c->fd = imsg_get_fd(imsg); > + 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->fd; > - log_debug("client %p IDENTIFY_STDOUT %d", c, imsg->fd); > + c->out_fd = imsg_get_fd(imsg); > + log_debug("client %p IDENTIFY_STDOUT %d", c, c->out_fd); > break; > case MSG_IDENTIFY_ENVIRON: > if (datalen == 0 || data[datalen - 1] != '\0') > > >