From patchwork Thu Oct 13 06:50:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 9374463 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 802E160779 for ; Thu, 13 Oct 2016 07:25:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 73598298BF for ; Thu, 13 Oct 2016 07:25:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6616E298C4; Thu, 13 Oct 2016 07:25:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_TVD_MIME_EPI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CAD18298BF for ; Thu, 13 Oct 2016 07:25:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751335AbcJMHZC (ORCPT ); Thu, 13 Oct 2016 03:25:02 -0400 Received: from mx2.suse.de ([195.135.220.15]:38660 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751488AbcJMHZC (ORCPT ); Thu, 13 Oct 2016 03:25:02 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 9316EAAB9; Thu, 13 Oct 2016 06:50:28 +0000 (UTC) From: NeilBrown To: Steve Dickson Date: Thu, 13 Oct 2016 17:50:22 +1100 Cc: Linux NFS Mailing List Subject: [PATCH nfs-utils] nfs-server-generator: avoid using external services. User-Agent: Notmuch/0.22.1 (http://notmuchmail.org) Emacs/24.5.1 (x86_64-suse-linux-gnu) Message-ID: <8737k0215d.fsf@notabene.neil.brown.name> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP nfs-server-generator is run very early when a lot of services are not yet started, so it mustn't depend on them. Currently it can try to use hostname lookup and syslog. Hostname-lookup is not needed, as we don't use the host issue, and sending message to stderr is sufficient for the generator. Disabling syslog is easy - call a function that sets a static variable. Disabling hostname lookup isn't quite so easy, so add a static variable which can be set to disable it. Signed-off-by: NeilBrown --- hi, I contemplated passing another arg to export_read() and export_d_read() to resolve this, but it didn't seem worth it. Is this approach OK to people? Thanks, NeilBrown support/export/export.c | 12 ++++++++++-- support/include/exportfs.h | 1 + systemd/nfs-server-generator.c | 4 ++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/support/export/export.c b/support/export/export.c index 0b8a858c2c74..c65dc8807a4e 100644 --- a/support/export/export.c +++ b/support/export/export.c @@ -67,6 +67,14 @@ static void warn_duplicated_exports(nfs_export *exp, struct exportent *eep) } } +static int assume_canonical = 0; + +void +export_avoid_host_lookup(int i) +{ + assume_canonical = i; +} + /** * export_read - read entries from /etc/exports * @fname: name of file to read from @@ -83,9 +91,9 @@ export_read(char *fname) setexportent(fname, "r"); while ((eep = getexportent(0,1)) != NULL) { - exp = export_lookup(eep->e_hostname, eep->e_path, 0); + exp = export_lookup(eep->e_hostname, eep->e_path, assume_canonical); if (!exp) { - if (export_create(eep, 0)) + if (export_create(eep, assume_canonical)) /* possible complaints already logged */ volumes++; } diff --git a/support/include/exportfs.h b/support/include/exportfs.h index f033329b5fd2..ba45b2dee199 100644 --- a/support/include/exportfs.h +++ b/support/include/exportfs.h @@ -134,6 +134,7 @@ struct addrinfo * client_resolve(const struct sockaddr *sap); int client_member(const char *client, const char *name); +void export_avoid_host_lookup(int i); int export_read(char *fname); int export_d_read(const char *dname); void export_reset(nfs_export *); diff --git a/systemd/nfs-server-generator.c b/systemd/nfs-server-generator.c index af8bb52bfbd7..7ae6dd1c4b20 100644 --- a/systemd/nfs-server-generator.c +++ b/systemd/nfs-server-generator.c @@ -93,6 +93,10 @@ int main(int argc, char *argv[]) FILE *f, *fstab; struct mntent *mnt; + /* Avoid using any external services */ + xlog_syslog(0); + export_avoid_host_lookup(1); + if (argc != 4 || argv[1][0] != '/') { fprintf(stderr, "nfs-server-generator: create systemd dependencies for nfs-server\n"); fprintf(stderr, "Usage: normal-dir early-dir late-dir\n");