[PATCH v2 02/23] nscd: Extract dbtype and struct statdata types to separate headers
Carlos O'Donell
carlos@redhat.com
Mon Mar 23 15:43:49 GMT 2026
On 3/20/26 4:41 PM, Florian Weimer wrote:
> So that they can be used in test code which uses _ISOMAC (so not
> in internal tests).
LGTM. Refactor here makes sense.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
> ---
> nscd/nscd-dbtype.h | 32 ++++++++++++++
> nscd/nscd-statdata.h | 99 ++++++++++++++++++++++++++++++++++++++++++++
> nscd/nscd.h | 14 +------
> nscd/nscd_stat.c | 73 +-------------------------------
> 4 files changed, 133 insertions(+), 85 deletions(-)
> create mode 100644 nscd/nscd-dbtype.h
> create mode 100644 nscd/nscd-statdata.h
>
> diff --git a/nscd/nscd-dbtype.h b/nscd/nscd-dbtype.h
> new file mode 100644
> index 0000000000..7d553d020a
> --- /dev/null
> +++ b/nscd/nscd-dbtype.h
> @@ -0,0 +1,32 @@
> +/* Database types handled by nscd.
> + Copyright (c) 1998-2026 Free Software Foundation, Inc.
> + This file is part of the GNU C Library.
> +
> + The GNU C Library is free software; you can redistribute it and/or
> + modify it under the terms of the GNU Lesser General Public
> + License as published by the Free Software Foundation; either
> + version 2.1 of the License, or (at your option) any later version.
> +
> + The GNU C Library is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + Lesser General Public License for more details.
> +
> + You should have received a copy of the GNU Lesser General Public
> + License along with the GNU C Library; if not, see
> + <https://www.gnu.org/licenses/>. */
> +
> +#ifndef NSCD_DBTYPE_H
> +#define NSCD_DBTYPE_H
> +
> +typedef enum
> +{
> + pwddb,
> + grpdb,
> + hstdb,
> + servdb,
> + netgrdb,
> + lastdb
> +} dbtype;
> +
> +#endif /* NSCD_DBTYPE_H */
> diff --git a/nscd/nscd-statdata.h b/nscd/nscd-statdata.h
> new file mode 100644
> index 0000000000..255dcdfc54
> --- /dev/null
> +++ b/nscd/nscd-statdata.h
> @@ -0,0 +1,99 @@
> +/* Statistics data for nscd.
> + Copyright (c) 1998-2026 Free Software Foundation, Inc.
> + This file is part of the GNU C Library.
> +
> + The GNU C Library is free software; you can redistribute it and/or
> + modify it under the terms of the GNU Lesser General Public
> + License as published by the Free Software Foundation; either
> + version 2.1 of the License, or (at your option) any later version.
> +
> + The GNU C Library is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + Lesser General Public License for more details.
> +
> + You should have received a copy of the GNU Lesser General Public
> + License along with the GNU C Library; if not, see
> + <https://www.gnu.org/licenses/>. */
> +
> +#ifndef NSCD_STATDATA_H
> +#define NSCD_STATDATA_H
> +
> +#include <stddef.h>
> +#include <stdint.h>
> +
> +#ifdef HAVE_SELINUX
> +# include <selinux/selinux.h>
> +# include <selinux/avc.h>
> +#endif /* HAVE_SELINUX */
> +
> +#include "nscd-dbtype.h"
> +
> +/* We use this to make sure the receiver is the same. The lower 16
> + bits are reserved for flags indicating compilation variants. This
> + version needs to be updated if the definition of struct statdata
> + changes. */
> +#define STATDATA_VERSION 0x01020000U
> +
> +#ifdef HAVE_SELINUX
> +# define STATDATA_VERSION_SELINUX_FLAG 0x0001U
> +#else
> +# define STATDATA_VERSION_SELINUX_FLAG 0x0000U
> +#endif
> +
> +/* All flags affecting the struct statdata layout. */
> +#define STATDATA_VERSION_FLAGS STATDATA_VERSION_SELINUX_FLAG
> +
> +/* The full version number for struct statdata. */
> +#define STATDATA_VERSION_FULL (STATDATA_VERSION | STATDATA_VERSION_FLAGS)
> +
> +/* Statistic data for one database. */
> +struct dbstat
> +{
> + int enabled;
> + int check_file;
> + int shared;
> + int persistent;
> + size_t module;
> +
> + unsigned long int postimeout;
> + unsigned long int negtimeout;
> +
> + size_t nentries;
> + size_t maxnentries;
> + size_t maxnsearched;
> + size_t datasize;
> + size_t dataused;
> +
> + uintmax_t poshit;
> + uintmax_t neghit;
> + uintmax_t posmiss;
> + uintmax_t negmiss;
> +
> + uintmax_t rdlockdelayed;
> + uintmax_t wrlockdelayed;
> +
> + uintmax_t addfailed;
> +};
> +
> +/* Record for transmitting statistics. If this definition changes,
> + update STATDATA_VERSION above. */
> +struct statdata
> +{
> + unsigned int version; /* Must be STATDATA_VERSION_FULL. */
> + int debug_level;
> + time_t runtime;
> + unsigned long int client_queued;
> + int nthreads;
> + int max_nthreads;
> + int paranoia;
> + time_t restart_interval;
> + unsigned int reload_count;
> + int ndbs;
> + struct dbstat dbs[lastdb];
> +#ifdef HAVE_SELINUX
> + struct avc_cache_stats cstats;
> +#endif /* HAVE_SELINUX */
> +};
> +
> +#endif /* NSCD_STATDATA_H */
> diff --git a/nscd/nscd.h b/nscd/nscd.h
> index 7d1bac2dc1..fffcb7a719 100644
> --- a/nscd/nscd.h
> +++ b/nscd/nscd.h
> @@ -27,19 +27,7 @@
> "nscd-client.h", which should contain everything needed by client
> functions. */
> #include "nscd-client.h"
> -
> -
> -/* Handle databases. */
> -typedef enum
> -{
> - pwddb,
> - grpdb,
> - hstdb,
> - servdb,
> - netgrdb,
> - lastdb
> -} dbtype;
> -
> +#include "nscd-dbtype.h"
>
> /* Default limit on the number of times a value gets reloaded without
> being used in the meantime. NSCD does not throw a value out as
> diff --git a/nscd/nscd_stat.c b/nscd/nscd_stat.c
> index 3a0ed54617..d67910cd9e 100644
> --- a/nscd/nscd_stat.c
> +++ b/nscd/nscd_stat.c
> @@ -29,78 +29,7 @@
> #include "nscd.h"
> #include "dbg_log.h"
> #include "selinux.h"
> -#ifdef HAVE_SELINUX
> -# include <selinux/selinux.h>
> -# include <selinux/avc.h>
> -#endif /* HAVE_SELINUX */
> -
> -/* We use this to make sure the receiver is the same. The lower 16
> - bits are reserved for flags indicating compilation variants. This
> - version needs to be updated if the definition of struct statdata
> - changes. */
> -#define STATDATA_VERSION 0x01020000U
> -
> -#ifdef HAVE_SELINUX
> -# define STATDATA_VERSION_SELINUX_FLAG 0x0001U
> -#else
> -# define STATDATA_VERSION_SELINUX_FLAG 0x0000U
> -#endif
> -
> -/* All flags affecting the struct statdata layout. */
> -#define STATDATA_VERSION_FLAGS STATDATA_VERSION_SELINUX_FLAG
> -
> -/* The full version number for struct statdata. */
> -#define STATDATA_VERSION_FULL (STATDATA_VERSION | STATDATA_VERSION_FLAGS)
> -
> -/* Statistic data for one database. */
> -struct dbstat
> -{
> - int enabled;
> - int check_file;
> - int shared;
> - int persistent;
> - size_t module;
> -
> - unsigned long int postimeout;
> - unsigned long int negtimeout;
> -
> - size_t nentries;
> - size_t maxnentries;
> - size_t maxnsearched;
> - size_t datasize;
> - size_t dataused;
> -
> - uintmax_t poshit;
> - uintmax_t neghit;
> - uintmax_t posmiss;
> - uintmax_t negmiss;
> -
> - uintmax_t rdlockdelayed;
> - uintmax_t wrlockdelayed;
> -
> - uintmax_t addfailed;
> -};
> -
> -/* Record for transmitting statistics. If this definition changes,
> - update STATDATA_VERSION above. */
> -struct statdata
> -{
> - unsigned int version; /* Must be STATDATA_VERSION_FULL. */
> - int debug_level;
> - time_t runtime;
> - unsigned long int client_queued;
> - int nthreads;
> - int max_nthreads;
> - int paranoia;
> - time_t restart_interval;
> - unsigned int reload_count;
> - int ndbs;
> - struct dbstat dbs[lastdb];
> -#ifdef HAVE_SELINUX
> - struct avc_cache_stats cstats;
> -#endif /* HAVE_SELINUX */
> -};
> -
> +#include "nscd-statdata.h"
>
> void
> send_stats (int fd, struct database_dyn dbs[lastdb])
--
Cheers,
Carlos.
More information about the Libc-alpha
mailing list