From patchwork Mon Sep 23 07:47:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Carrier X-Patchwork-Id: 1165833 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=orolia.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=orolia.com header.i=@orolia.com header.b="W9N6Rvsg"; dkim-atps=neutral Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46cGd9038gz9sP3 for ; Mon, 23 Sep 2019 17:47:40 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 5ECD020523; Mon, 23 Sep 2019 07:47:38 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vLsM4oer1WuX; Mon, 23 Sep 2019 07:47:34 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id 5695D203D1; Mon, 23 Sep 2019 07:47:34 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 053931BF3E8 for ; Mon, 23 Sep 2019 07:47:33 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 0088385C8F for ; Mon, 23 Sep 2019 07:47:33 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id N7OPaZMAtCtQ for ; Mon, 23 Sep 2019 07:47:31 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80088.outbound.protection.outlook.com [40.107.8.88]) by hemlock.osuosl.org (Postfix) with ESMTPS id 968C985A46 for ; Mon, 23 Sep 2019 07:47:30 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gahxewqmr7PqNgEEhDvo8MIOQrLYo7PQ+kjTQZzrDe8r3b3dcLic0KHuK3QVNCP6XMXJh9S48dU7h5qFMMgeAtdBOHdsSnMpmhRO1NouvNOL5WAEJiQco3VSe1f+oNTHZssKa0mxCmpiFs3HNJFRNZl41ThfsJKenS9JSj74NZKyqaNlK7C8iM10LvWd58u4dEOhntNRCEnsEo26FjQifji0dbR3tIxMFj+LYy4stsZ7U3wTRWiRnM3LeFLE0whTD+XB+lIVsH+RdIYmKEaegKy4eoIpXeMrgTvjDdtxHExwTmfIGSIll1qevsxeKmtg+2Rp6Tjp9wtujOJ34W7V3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UOs46dYSZE08qRSwu8ZxtoMY7ksM2nerE/1mH2OIqCY=; b=oCz9oMTh7dlE37Z99cFyScSY3CpzVHM6ha0IOPq/o1FbNZqBXq44PGn6rFKLdWtKr3u5C4KgxYhojDdV+8y5yy3PlJw2jF5sO0avzLciLzOpnUKCQEANtI1oW43XFD7NwV4hfIti2W/K2Gb2nLXbn0X0UuZ19RUPAoIQUoz/Alz3HHaCPj9lUICkPPthlRc2IpUTHpcsYDbMT64Fapzx/KCpasvZlze7+JGY6Y+PYn2GOcs6TBaX3C/VUSi359c8lc8YTseIgwRF6Vpe71QnRwxCThHOuAjQBeuRRdbmcCH/Sqjy4k2yxf1OgkNZE4emb/utgKrFj9ZxKseSQ9FxMw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=orolia.com; dmarc=pass action=none header.from=orolia.com; dkim=pass header.d=orolia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=orolia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UOs46dYSZE08qRSwu8ZxtoMY7ksM2nerE/1mH2OIqCY=; b=W9N6Rvsg36dt4/HiJDb0i8W2zUYV/U4VmSFcsbW02b40I/PwJohKd2c/A44nr2MqdjmU4AyBeQhNk6XZGZdiy/VpniTe8+N0U75L7rqgLXF8iw1azu5pGuIR5VhmLgpZTP/yadMOaYmp7dD4M8Bzdd6J/BfiefhnnhEqsWeNqXI= Received: from AM6PR06MB4341.eurprd06.prod.outlook.com (20.176.243.160) by AM6PR06MB6344.eurprd06.prod.outlook.com (20.179.247.212) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2284.26; Mon, 23 Sep 2019 07:47:27 +0000 Received: from AM6PR06MB4341.eurprd06.prod.outlook.com ([fe80::dfb:5522:e617:fdaf]) by AM6PR06MB4341.eurprd06.prod.outlook.com ([fe80::dfb:5522:e617:fdaf%5]) with mapi id 15.20.2284.023; Mon, 23 Sep 2019 07:47:27 +0000 From: Nicolas Carrier To: "buildroot@buildroot.org" Thread-Topic: [PATCH v2 1/1] package/apache: atomic creation of pid file. Thread-Index: AQHVceMlmAR668FvCk6R5JX00x7rhA== Date: Mon, 23 Sep 2019 07:47:27 +0000 Message-ID: <20190923074708.9269-1-nicolas.carrier@orolia.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: LO2P265CA0254.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:8a::26) To AM6PR06MB4341.eurprd06.prod.outlook.com (2603:10a6:20b:26::32) authentication-results: spf=none (sender IP is ) smtp.mailfrom=nicolas.carrier@orolia.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.20.1 x-originating-ip: [2a02:8433:3580:a701:b5b:35cf:7b3e:28e3] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 832a586d-76ac-4356-95af-08d73ffa4779 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(5600167)(711020)(4605104)(1401327)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7193020); SRVR:AM6PR06MB6344; x-ms-traffictypediagnostic: AM6PR06MB6344:|AM6PR06MB6344: x-ms-exchange-purlcount: 1 x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7691; x-forefront-prvs: 0169092318 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(376002)(366004)(346002)(39840400004)(136003)(396003)(189003)(199004)(8936002)(54906003)(966005)(7736002)(305945005)(25786009)(14454004)(4326008)(316002)(6436002)(6486002)(6512007)(6306002)(14444005)(5640700003)(107886003)(36756003)(1076003)(478600001)(256004)(6116002)(81166006)(1730700003)(81156014)(8676002)(66946007)(186003)(71190400001)(52116002)(86362001)(99286004)(386003)(6506007)(102836004)(486006)(476003)(2351001)(44832011)(46003)(6916009)(71200400001)(2906002)(2616005)(5660300002)(66476007)(50226002)(66556008)(64756008)(66446008)(2501003); DIR:OUT; SFP:1101; SCL:1; SRVR:AM6PR06MB6344; H:AM6PR06MB4341.eurprd06.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: orolia.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: yEs96r7BOljKQKx/zNO77BZQYn8Y9g1YpLQ3oDpDdy9GlxKaIqsIdMiqdZTkuR38nqGNmFx4DTbA1hrmxWRTgiOSG02oK0miqBgw77BTx9rgCby3D4Zo40hzBGixFrcVmZ8lBZrxSymxkGysc5X9rQEhHHRFEky4tGe9ef4Dzqn/g4hgZWlh6br+ewBCERGze/EuPYv0xZuIOnkVwJxb8hPlqIsvx97URa0Jg+xr+/9lXuvG8CABsy4tj5dBObIFqYAkp9rKl/FNlSuB8kUADpjNAm97RnSvkWPzvcLu3Ze/A20Xdqp3Bdl/6PdJK+dNbiYlQ39wcOaDp0+rIvz+1KWDWVCwWBjOvmfVqmY5e98HA7jPKzpP5UfuCud84mKNEpTLPuUKckzgShgdLo5U/SuCFr2FvRG41RIJ3CfS0fE= MIME-Version: 1.0 X-OriginatorOrg: orolia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 832a586d-76ac-4356-95af-08d73ffa4779 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Sep 2019 07:47:27.2097 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a263030c-9c1b-421f-9471-1dec0b29c664 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: yjusMoF03Yz/pAMnfaCLIXuap+zITShZlSr41WFPom0TG+eT6KRNui0AGSKKDJAxBXUtFokRRESNP8kYOaB1XRiD2hVNNFQYEAOyZC16lIg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR06MB6344 Subject: [Buildroot] [PATCH v2 1/1] package/apache: atomic creation of pid file. X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bernd Kuhls , Nicolas Carrier Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" The original pattern for creating the pid file was: open_create(pid_file) write(pid_file, pid) close(pid_file) But if a power outage occurs between open_create and write, the file will be empty and httpd will refuse to start afterwards unless the corrupt pid file is removed. This patch uses the pattern: open_create(temp_pid_file) write(temp_pid_file) close(temp_pid_file) rename(temp_pid_file, pid_file) which is guaranteed to be atomic, provided that temp_pid_file and pid_file are located in the same file system, which this patch does by creating a temporary file name with the pattern: pid_file_name + random_suffix This patch has been submitted upstream, but did receive no answer at all: https://bz.apache.org/bugzilla/show_bug.cgi?id=63140 Signed-off-by: Nicolas Carrier --- Changes v1 -> v2: - added signed-off-by in the patch file - patch title more conform to other commits (i.e. removed the apache: prefix) - generated patch from the 2.4.41 version, currently used in buildroot. - patch generated with `git format-patch HEAD~` .../0003-atomic-creation-of-pid-file.patch | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 package/apache/0003-atomic-creation-of-pid-file.patch diff --git a/package/apache/0003-atomic-creation-of-pid-file.patch b/package/apache/0003-atomic-creation-of-pid-file.patch new file mode 100644 index 0000000000..3d707bf772 --- /dev/null +++ b/package/apache/0003-atomic-creation-of-pid-file.patch @@ -0,0 +1,84 @@ +From 7dcc7d1a861c66cdcf2233cb522bd17ca89b455b Mon Sep 17 00:00:00 2001 +From: Nicolas Carrier +Date: Mon, 4 Feb 2019 11:49:19 +0100 +Subject: [PATCH] atomic creation of pid file. + +The original pattern for creating the pid file was: +open_create(pid_file) +write(pid_file, pid) +close(pid_file) + +But if a power outage occurs between open_create and write, the file will +be empty and httpd will refuse to start afterwards unless the corrupt pid +file is removed. + +This patch uses the pattern: +open_create(temp_pid_file) +write(temp_pid_file) +close(temp_pid_file) +rename(temp_pid_file, pid_file) +which is guaranteed to be atomic, provided that temp_pid_file and pid_file +are located in the same file system, which this patch does by creating +a temporary file name with the pattern: + pid_file_name + random_suffix + +Signed-off-by: Nicolas Carrier +--- + server/log.c | 18 ++++++++++++++---- + 1 file changed, 14 insertions(+), 4 deletions(-) + +diff --git a/server/log.c b/server/log.c +index 42d0b8fbe1..1b467d2a5c 100644 +--- a/server/log.c ++++ b/server/log.c +@@ -1598,6 +1598,8 @@ AP_DECLARE(void) ap_log_pid(apr_pool_t *p, const char *filename) + pid_t mypid; + apr_status_t rv; + const char *fname; ++ char *temp_fname; ++ apr_fileperms_t perms; + + if (!filename) { + return; +@@ -1609,6 +1611,10 @@ AP_DECLARE(void) ap_log_pid(apr_pool_t *p, const char *filename) + ap_server_conf, APLOGNO(00097) "Invalid PID file path %s, ignoring.", filename); + return; + } ++ temp_fname = apr_psprintf(p, "%s.XXXXXX", filename); ++ if (!temp_fname) { ++ return; ++ } + + mypid = getpid(); + if (mypid != saved_pid +@@ -1626,19 +1632,23 @@ AP_DECLARE(void) ap_log_pid(apr_pool_t *p, const char *filename) + fname); + } + +- if ((rv = apr_file_open(&pid_file, fname, +- APR_WRITE | APR_CREATE | APR_TRUNCATE, +- APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD, p)) ++ if ((rv = apr_file_mktemp(&pid_file, temp_fname, ++ APR_WRITE | APR_CREATE | APR_TRUNCATE, p)) + != APR_SUCCESS) { + ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL, APLOGNO(00099) +- "could not create %s", fname); ++ "could not create %s", temp_fname); + ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, APLOGNO(00100) + "%s: could not log pid to file %s", + ap_server_argv0, fname); + exit(1); + } ++ ++ perms = APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD; ++ apr_file_perms_set(temp_fname, perms); ++ + apr_file_printf(pid_file, "%" APR_PID_T_FMT APR_EOL_STR, mypid); + apr_file_close(pid_file); ++ apr_file_rename(temp_fname, fname, p); + saved_pid = mypid; + } + +-- +2.20.1 +