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?

I'll fix the equivalent code in nbdkit.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
nbdkit - Flexible, fast NBD server with plugins
https://gitlab.com/nbdkit/nbdkit


Reply via email to