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