From patchwork Thu Oct 5 14:49:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 821865 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-85446-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="cGvroyBB"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3y7G0755Z8z9t2l for ; Fri, 6 Oct 2017 01:50:15 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; q=dns; s=default; b= jx79ETs2Q4sYTiluL/2cYI886d9VkkTolLWVxNdShctcZc4TrZlMmPM+PtRfAAEK kzSoXTYjPK8E4NmtN+Wdh29n2uIGHGa6bGaOYLvh1byyFk+1dlEpF5KbNchR5PLs pblRVJfg/tKn/Vkwz50MKTtsb4P5Mr43wgGRYKaeoHc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; s=default; bh=s+ZPWs hf0fm7FXEpu2f343fHADU=; b=cGvroyBBiOnk7LKmtqw3mtGvKjUTjlCtQZILIs j1cUkFhj6sKRvzbsZ4DKFVmdEVAcwSH6HvlrsEzc50dkHKRIZOYvDIM735lWVgpg HITGynxK/x2iQYaE/4OhkhIaWvH1i/Hj4PiW/HVPmIAtCB0KpCMogmUvbygEl/Sh zua9U= Received: (qmail 11496 invoked by alias); 5 Oct 2017 14:50:08 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 11485 invoked by uid 89); 5 Oct 2017 14:50:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=reserved X-HELO: mx1.redhat.com DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0DF05765A7 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=fweimer@redhat.com Date: Thu, 05 Oct 2017 16:49:57 +0200 To: libc-alpha@sourceware.org Subject: [PATCH] nscd: Eliminate compilation time dependency in the build output User-Agent: Heirloom mailx 12.5 7/5/10 MIME-Version: 1.0 Message-Id: <20171005144957.6383142022590@oldenburg.str.redhat.com> From: fweimer@redhat.com (Florian Weimer) 2017-10-05 Florian Weimer 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. Reviewed-by: Carlos O'Donell 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 #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))) {