public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH 3/8] linux_dep: Move close_range() conditional handling to linux_dep.h
Date: Thu, 7 Nov 2024 07:56:06 +1100	[thread overview]
Message-ID: <ZyvX5ue_rgbeGCWO@zatzit> (raw)
In-Reply-To: <20241106201053.5eab2fd2@elisabeth>

[-- Attachment #1: Type: text/plain, Size: 3559 bytes --]

On Wed, Nov 06, 2024 at 08:10:53PM +0100, Stefano Brivio wrote:
> On Wed,  6 Nov 2024 17:54:16 +1100
> David Gibson <david@gibson.dropbear.id.au> wrote:
> 
> > util.h has some #ifdefs and weak definitions to handle compatibility with
> > various kernel versions.  Move this to linux_dep.h which handles several
> > other similar cases.
> > 
> > Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> > ---
> >  linux_dep.h | 20 ++++++++++++++++++++
> >  util.h      | 19 -------------------
> >  2 files changed, 20 insertions(+), 19 deletions(-)
> > 
> > diff --git a/linux_dep.h b/linux_dep.h
> > index eae9c3c..3a41e42 100644
> > --- a/linux_dep.h
> > +++ b/linux_dep.h
> > @@ -125,4 +125,24 @@ struct tcp_info_linux {
> >  #define FALLOC_FL_COLLAPSE_RANGE	0x08
> >  #endif
> >  
> > +#include <linux/close_range.h>
> > +
> > +#ifdef CLOSE_RANGE_UNSHARE	/* Linux kernel >= 5.9 */
> > +/* glibc < 2.34 and musl as of 1.2.5 need these */
> > +#ifndef SYS_close_range
> > +#define SYS_close_range		436
> > +#endif
> > +__attribute__ ((weak))
> > +/* cppcheck-suppress funcArgNamesDifferent */
> > +int close_range(unsigned int first, unsigned int last, int flags) {
> > +	return syscall(SYS_close_range, first, last, flags);
> > +}
> > +#else
> > +/* No reasonable fallback option */
> > +/* cppcheck-suppress funcArgNamesDifferent */
> > +int close_range(unsigned int first, unsigned int last, int flags) {
> > +	return 0;
> > +}
> > +#endif
> > +
> >  #endif /* LINUX_DEP_H */
> > diff --git a/util.h b/util.h
> > index 2858b10..fdc3af8 100644
> > --- a/util.h
> > +++ b/util.h
> > @@ -17,7 +17,6 @@
> >  #include <arpa/inet.h>
> >  #include <unistd.h>
> >  #include <sys/syscall.h>
> > -#include <linux/close_range.h>
> >  
> >  #include "log.h"
> >  
> > @@ -158,24 +157,6 @@ int do_clone(int (*fn)(void *), char *stack_area, size_t stack_size, int flags,
> >  
> >  struct ctx;
> >  
> > -#ifdef CLOSE_RANGE_UNSHARE	/* Linux kernel >= 5.9 */
> > -/* glibc < 2.34 and musl as of 1.2.5 need these */
> > -#ifndef SYS_close_range
> > -#define SYS_close_range		436
> > -#endif
> > -__attribute__ ((weak))
> > -/* cppcheck-suppress funcArgNamesDifferent */
> > -int close_range(unsigned int first, unsigned int last, int flags) {
> > -	return syscall(SYS_close_range, first, last, flags);
> > -}
> > -#else
> > -/* No reasonable fallback option */
> > -/* cppcheck-suppress funcArgNamesDifferent */
> > -int close_range(unsigned int first, unsigned int last, int flags) {
> > -	return 0;
> > -}
> > -#endif
> > -
> 
> This breaks the build on Alpine as well:
> 
> util.c: In function 'close_open_files':
> util.c:729:22: error: implicit declaration of function 'close_range'; did you mean 'SYS_close_range'? [-Wimplicit-function-declaration]
>   729 |                 rc = close_range(STDERR_FILENO + 1, ~0U, CLOSE_RANGE_UNSHARE);
>       |                      ^~~~~~~~~~~
>       |                      SYS_close_range
> util.c:729:58: error: 'CLOSE_RANGE_UNSHARE' undeclared (first use in this function)
>   729 |                 rc = close_range(STDERR_FILENO + 1, ~0U, CLOSE_RANGE_UNSHARE);
>       |                                                          ^~~~~~~~~~~~~~~~~~~
> 
> and is fixed by including "linux_dep.h" from util.c.

Oops again, adjusted.

-- 
David Gibson (he or they)	| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you, not the other way
				| around.
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2024-11-06 21:16 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-06  6:54 [PATCH 0/8] Avoid running cppcheck on system headers David Gibson
2024-11-06  6:54 ` [PATCH 1/8] linux_dep: Generalise tcp_info.h to handling Linux extension compatibility David Gibson
2024-11-06  6:54 ` [PATCH 2/8] log: Only check for FALLOC_FL_COLLAPSE_RANGE availability at runtime David Gibson
2024-11-06 19:10   ` Stefano Brivio
2024-11-06 20:54     ` David Gibson
2024-11-06  6:54 ` [PATCH 3/8] linux_dep: Move close_range() conditional handling to linux_dep.h David Gibson
2024-11-06 19:10   ` Stefano Brivio
2024-11-06 20:56     ` David Gibson [this message]
2024-11-06  6:54 ` [PATCH 4/8] linux_dep: Fix CLOSE_RANGE_UNSHARE availability handling David Gibson
2024-11-06 19:12   ` Stefano Brivio
2024-11-06 21:01     ` David Gibson
2024-11-07  7:03       ` Stefano Brivio
2024-11-06  6:54 ` [PATCH 5/8] ndp: Use const pointer for ndp_ns packet David Gibson
2024-11-06  6:54 ` [PATCH 6/8] udp: Don't dereference uflow before NULL check in udp_reply_sock_handler() David Gibson
2024-11-06  6:54 ` [PATCH 7/8] util: Work around cppcheck bug 6936 David Gibson
2024-11-06  6:54 ` [PATCH 8/8] cppcheck: Don't check the system headers David Gibson
2024-11-07 14:55 ` [PATCH 0/8] Avoid running cppcheck on " Stefano Brivio
2024-11-07 23:58   ` David Gibson

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=ZyvX5ue_rgbeGCWO@zatzit \
    --to=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    --cc=sbrivio@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.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).