On 18/05/2026 18.54, Richard W.M. Jones wrote:
On Mon, May 18, 2026 at 06:49:11PM +0200, Thomas Huth wrote:
On 09/10/2025 18.12, Richard W.M. Jones wrote:
+static void *
+exit_with_parent_loop(void *vp)
+{
+ const pid_t ppid = getppid();
+ int fd;
+ struct kevent kev, res[1];
+ int r;
+
+ /* Register the kevent to wait for ppid to exit. */
+ fd = kqueue();
+ if (fd == -1) {
+ error_report("exit_with_parent_loop: kqueue: %m");
+ return NULL;
+ }
+ EV_SET(&kev, ppid, EVFILT_PROC, EV_ADD | EV_ENABLE, NOTE_EXIT, 0, NULL);
+ if (kevent(fd, &kev, 1, NULL, 0, NULL) == -1) {
+ error_report("exit_with_parent_loop: kevent: %m");
+ close(fd);
So in case of errors, fd is closed here ...
+ return NULL;
+ }
+
+ /* Wait for the kevent to happen. */
+ r = kevent(fd, 0, 0, res, 1, NULL);
+ if (r == 1 && res[0].ident == ppid) {
+ /* Behave like Linux and FreeBSD above, as if SIGTERM was sent */
+ qemu_system_killed(SIGTERM, ppid);
+ }
+
+ return NULL;
+}
... but if everything goes well, fd does not get closed? Should
there be a close(fd) after the kevent() here?
Yes .. although of course qemu as a whole will exit very soon
afterwards :-)
Do you want me to submit a patch or will you do it?
If you've got some spare minutes, I'd appreciate if you could send a patch.
Thanks,
Thomas