* [PATCH] nscd: Eliminate compilation time dependency in the build output
@ 2017-10-05 14:50 Florian Weimer
2017-10-05 15:12 ` Zack Weinberg
2017-10-05 16:14 ` Carlos O'Donell
0 siblings, 2 replies; 3+ messages in thread
From: Florian Weimer @ 2017-10-05 14:50 UTC (permalink / raw)
To: libc-alpha
2017-10-05 Florian Weimer <fweimer@redhat.com>
nscd: Eliminate compilation time dependency in the build output.
* nscd/nscd_stat.c (STATDATA_VERSION)
(STATDATA_VERSION_SELINUX_FLAG, STATDATA_VERSION_FLAGS)
(STATDATA_VERSION_FULL): New macro definitions.
(compilation): Remove.
(struct statdata): Adjust version member.
(send_stats): Set version from STATDATA_VERSION_FULL.
(receive_print_stats): Verify version against STATDATA_VERSION_FULL.
diff --git a/nscd/nscd_stat.c b/nscd/nscd_stat.c
index feb1c98ac3..b1bc81bd6d 100644
--- a/nscd/nscd_stat.c
+++ b/nscd/nscd_stat.c
@@ -35,9 +35,23 @@
# 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
-/* We use this to make sure the receiver is the same. */
-static const char compilation[21] = __DATE__ " " __TIME__;
+#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
@@ -68,10 +82,11 @@ struct dbstat
uintmax_t addfailed;
};
-/* Record for transmitting statistics. */
+/* Record for transmitting statistics. If this definition changes,
+ update STATDATA_VERSION above. */
struct statdata
{
- char version[sizeof (compilation)];
+ unsigned int version; /* Must be STATDATA_VERSION_FULL. */
int debug_level;
time_t runtime;
unsigned long int client_queued;
@@ -96,7 +111,7 @@ send_stats (int fd, struct database_dyn dbs[lastdb])
memset (&data, 0, sizeof (data));
- memcpy (data.version, compilation, sizeof (compilation));
+ data.version = STATDATA_VERSION_FULL;
data.debug_level = debug_level;
data.runtime = time (NULL) - start_time;
data.client_queued = client_queued;
@@ -196,7 +211,7 @@ receive_print_stats (void)
/* Read as much data as we expect. */
if (TEMP_FAILURE_RETRY (read (fd, &data, sizeof (data))) != sizeof (data)
- || (memcmp (data.version, compilation, sizeof (compilation)) != 0
+ || (data.version != STATDATA_VERSION_FULL
/* Yes, this is an assignment! */
&& (errno = EINVAL)))
{
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] nscd: Eliminate compilation time dependency in the build output
2017-10-05 14:50 [PATCH] nscd: Eliminate compilation time dependency in the build output Florian Weimer
@ 2017-10-05 15:12 ` Zack Weinberg
2017-10-05 16:14 ` Carlos O'Donell
1 sibling, 0 replies; 3+ messages in thread
From: Zack Weinberg @ 2017-10-05 15:12 UTC (permalink / raw)
To: Florian Weimer; +Cc: GNU C Library
On Thu, Oct 5, 2017 at 10:49 AM, Florian Weimer <fweimer@redhat.com> wrote:
> 2017-10-05 Florian Weimer <fweimer@redhat.com>
>
> nscd: Eliminate compilation time dependency in the build output.
I'm not qualified to review this code, but I am in favor of making a
change with this effect.
zw
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] nscd: Eliminate compilation time dependency in the build output
2017-10-05 14:50 [PATCH] nscd: Eliminate compilation time dependency in the build output Florian Weimer
2017-10-05 15:12 ` Zack Weinberg
@ 2017-10-05 16:14 ` Carlos O'Donell
1 sibling, 0 replies; 3+ messages in thread
From: Carlos O'Donell @ 2017-10-05 16:14 UTC (permalink / raw)
To: Florian Weimer, libc-alpha
On 10/05/2017 07:49 AM, Florian Weimer wrote:
> 2017-10-05 Florian Weimer <fweimer@redhat.com>
>
> nscd: Eliminate compilation time dependency in the build output.
> * nscd/nscd_stat.c (STATDATA_VERSION)
> (STATDATA_VERSION_SELINUX_FLAG, STATDATA_VERSION_FLAGS)
> (STATDATA_VERSION_FULL): New macro definitions.
> (compilation): Remove.
> (struct statdata): Adjust version member.
> (send_stats): Set version from STATDATA_VERSION_FULL.
> (receive_print_stats): Verify version against STATDATA_VERSION_FULL.
Looks good to me.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
--
Cheers,
Carlos.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-10-05 16:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-05 14:50 [PATCH] nscd: Eliminate compilation time dependency in the build output Florian Weimer
2017-10-05 15:12 ` Zack Weinberg
2017-10-05 16:14 ` Carlos O'Donell
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 read-only IMAP folder(s) and NNTP newsgroup(s).