From: Phil Sutter <phil@nwl.cc>
To: Florian Westphal <fw@strlen.de>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>, netfilter-devel@vger.kernel.org
Subject: Re: [nft PATCH v3] configure: Implement --enable-profiling option
Date: Thu, 12 Feb 2026 21:49:14 +0100 [thread overview]
Message-ID: <aY48ymBNNYGL46fR@orbyte.nwl.cc> (raw)
In-Reply-To: <aY0Z63yPjQoXYp9b@strlen.de>
On Thu, Feb 12, 2026 at 01:08:17AM +0100, Florian Westphal wrote:
> Phil Sutter <phil@nwl.cc> wrote:
> > This will set compiler flag --coverage so code coverage may be inspected
> > using gcov.
> >
> > In order to successfully profile processes which are killed or
> > interrupted as well, add a signal handler for those cases which calls
> > exit(). This is relevant for test cases invoking nft monitor.
> >
> > index 0000000000000..912ead9d7eb94
> > --- /dev/null
> > +++ b/src/profiling.c
> > @@ -0,0 +1,36 @@
> > +/*
> > + * Copyright (c) Red Hat GmbH. Author: Phil Sutter <phil@nwl.cc>
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License version 2 (or any
> > + * later) as published by the Free Software Foundation.
> > + */
> > +
> > +#include <nft.h>
> > +#include <profiling.h>
> > +
> > +#include <signal.h>
> > +#include <stdio.h>
> > +
> > +static void termhandler(int signo)
> > +{
> > + switch (signo) {
> > + case SIGTERM:
> > + exit(143);
> > + case SIGINT:
> > + exit(130);
>
> Unfortunately I can't find exit(3) in the list of async-signal safe
> functions, so I have to assume this isn't allowed.
You're right. At least since exit() runs atexit() callbacks, it is very
unlikely this is async-signal-safe.
> From a quick glance, I would suggest to either use self-pipe-trick, or,
> given nft is linux specific anyway, use signalfd(2) instead of a
> traditional handler; then, stuff the fd into mnl_nft_event_listener
> select().
I'll go with signalfd() as it's simpler than the self-pipe and hooking
into mnl_nft_event_listener is required in both cases.
> Sorry, I did not think of this earlier. If I'm wrong and this is safe,
Thanks for the pointers! I'm not very familiar with writing signal
handlers.
Cheers, Phil
prev parent reply other threads:[~2026-02-12 20:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-11 20:14 [nft PATCH v3] configure: Implement --enable-profiling option Phil Sutter
2026-02-12 0:08 ` Florian Westphal
2026-02-12 0:19 ` Florian Westphal
2026-02-12 20:49 ` Phil Sutter [this message]
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=aY48ymBNNYGL46fR@orbyte.nwl.cc \
--to=phil@nwl.cc \
--cc=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox