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