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