eb0a937
commit 1e9522c61c7a544d59db32cb7fbbd42e6793d848
eb0a937
Author: Florian Weimer <fweimer@redhat.com>
eb0a937
Date:   Thu Oct 5 18:14:27 2017 +0200
eb0a937
eb0a937
    nscd: Eliminate compilation time dependency in the build output
eb0a937
    
eb0a937
    Reviewed-by: Carlos O'Donell <carlos@redhat.com>
eb0a937
eb0a937
diff --git a/nscd/nscd_stat.c b/nscd/nscd_stat.c
eb0a937
index feb1c98ac31edcb8..b1bc81bd6d7d7fd1 100644
eb0a937
--- a/nscd/nscd_stat.c
eb0a937
+++ b/nscd/nscd_stat.c
eb0a937
@@ -35,9 +35,23 @@
eb0a937
 # include <selinux/avc.h>
eb0a937
 #endif /* HAVE_SELINUX */
eb0a937
 
eb0a937
+/* We use this to make sure the receiver is the same.  The lower 16
eb0a937
+   bits are reserved for flags indicating compilation variants.  This
eb0a937
+   version needs to be updated if the definition of struct statdata
eb0a937
+   changes.  */
eb0a937
+#define STATDATA_VERSION  0x01020000U
eb0a937
 
eb0a937
-/* We use this to make sure the receiver is the same.  */
eb0a937
-static const char compilation[21] = __DATE__ " " __TIME__;
eb0a937
+#ifdef HAVE_SELINUX
eb0a937
+# define STATDATA_VERSION_SELINUX_FLAG 0x0001U
eb0a937
+#else
eb0a937
+# define STATDATA_VERSION_SELINUX_FLAG 0x0000U
eb0a937
+#endif
eb0a937
+
eb0a937
+/* All flags affecting the struct statdata layout.  */
eb0a937
+#define STATDATA_VERSION_FLAGS STATDATA_VERSION_SELINUX_FLAG
eb0a937
+
eb0a937
+/* The full version number for struct statdata.  */
eb0a937
+#define STATDATA_VERSION_FULL (STATDATA_VERSION | STATDATA_VERSION_FLAGS)
eb0a937
 
eb0a937
 /* Statistic data for one database.  */
eb0a937
 struct dbstat
eb0a937
@@ -68,10 +82,11 @@ struct dbstat
eb0a937
   uintmax_t addfailed;
eb0a937
 };
eb0a937
 
eb0a937
-/* Record for transmitting statistics.  */
eb0a937
+/* Record for transmitting statistics.  If this definition changes,
eb0a937
+   update STATDATA_VERSION above.  */
eb0a937
 struct statdata
eb0a937
 {
eb0a937
-  char version[sizeof (compilation)];
eb0a937
+  unsigned int version;		/* Must be STATDATA_VERSION_FULL.  */
eb0a937
   int debug_level;
eb0a937
   time_t runtime;
eb0a937
   unsigned long int client_queued;
eb0a937
@@ -96,7 +111,7 @@ send_stats (int fd, struct database_dyn dbs[lastdb])
eb0a937
 
eb0a937
   memset (&data, 0, sizeof (data));
eb0a937
 
eb0a937
-  memcpy (data.version, compilation, sizeof (compilation));
eb0a937
+  data.version = STATDATA_VERSION_FULL;
eb0a937
   data.debug_level = debug_level;
eb0a937
   data.runtime = time (NULL) - start_time;
eb0a937
   data.client_queued = client_queued;
eb0a937
@@ -196,7 +211,7 @@ receive_print_stats (void)
eb0a937
 
eb0a937
   /* Read as much data as we expect.  */
eb0a937
   if (TEMP_FAILURE_RETRY (read (fd, &data, sizeof (data))) != sizeof (data)
eb0a937
-      || (memcmp (data.version, compilation, sizeof (compilation)) != 0
eb0a937
+      || (data.version != STATDATA_VERSION_FULL
eb0a937
 	  /* Yes, this is an assignment!  */
eb0a937
 	  && (errno = EINVAL)))
eb0a937
     {