All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Richard W.M. Jones" <rjones@redhat.com>
To: Thomas Huth <thuth@redhat.com>
Cc: qemu-devel@nongnu.org, lvivier@redhat.com, farosas@suse.de,
	pbonzini@redhat.com, berrange@redhat.com
Subject: Re: [PATCH v2 1/2] Implement -run-with exit-with-parent=on
Date: Mon, 18 May 2026 17:54:40 +0100	[thread overview]
Message-ID: <20260518165440.GX1447@redhat.com> (raw)
In-Reply-To: <59f45360-5676-41a7-8c4a-577c3e645aa7@redhat.com>

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	other threads:[~2026-05-18 16:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-09 16:12 [PATCH v2 0/2] Implement -run-with exit-with-parent=on Richard W.M. Jones
2025-10-09 16:12 ` [PATCH v2 1/2] " Richard W.M. Jones
2025-10-10 10:09   ` Daniel P. Berrangé
2026-05-18 16:49   ` Thomas Huth
2026-05-18 16:54     ` Richard W.M. Jones [this message]
2026-05-18 17:18       ` Thomas Huth
2026-05-18 17:00     ` Richard W.M. Jones
2025-10-09 16:12 ` [PATCH v2 2/2] tests/qtest: Use exit-with-parent=on in qtest invocations Richard W.M. Jones
2025-10-10 10:10   ` Daniel P. Berrangé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260518165440.GX1447@redhat.com \
    --to=rjones@redhat.com \
    --cc=berrange@redhat.com \
    --cc=farosas@suse.de \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.