From nobody Sun Feb 13 17:26:33 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id A658419C586C for ; Sun, 13 Feb 2022 17:26:42 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JxZ5s6y8kz4YBC for ; Sun, 13 Feb 2022 17:26:41 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Received: by mail-wr1-f42.google.com with SMTP id v12so23424790wrv.2 for ; Sun, 13 Feb 2022 09:26:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=MGareZesc3TTss1KlvrZhY+xryilVRSmyWHCKMP2TfQ=; b=mhElJbbFdYrYUiDAUgxnw4aoCceROwc8p9p31UZB3P1sbkHyAmwWUQkZJpqVZ3Agtq Tv2aR+JO9t755Rpn4c4Cwi47Ueg2NcGszDNBQbu9pfjYzedHLlll4qU1aS2s63kqqUAP jaC3BPHh1PMRaiA6FsdDIMLTRA5JH65m2MLcNyikIwurKJeOKoTuGGxRyQhHSGEcZE8j D7URTQziIJDSg3GgyRvtgeR6XIUedi6b4JzywtLuk1vUucE3jM4lsCkfxynRtQDHt0QV YsribqQnpmeQV9OdUb1jg6HMtm56HJTMkB3Da9VnqQfCRo+CwLabX0musTWk0HN6ac+p KM9w== X-Gm-Message-State: AOAM532QH+c5VOtGQt47seXoPXshoTftjf3DM4CCXwei2mDvX0SRxooh TpmAW9UyUCQALt613sPMTOyOMQ== X-Google-Smtp-Source: ABdhPJx6O7zG7eiUXABzx2WFoZ3jc1zVvjS8b4arocqpyNxyIrstYsB/AbX0e3MJWpq3nsy6FAeREQ== X-Received: by 2002:a5d:50cb:: with SMTP id f11mr8332055wrt.178.1644773195112; Sun, 13 Feb 2022 09:26:35 -0800 (PST) Received: from smtpclient.apple (global-5-143.nat-2.net.cam.ac.uk. [131.111.5.143]) by smtp.gmail.com with ESMTPSA id l26sm9579815wms.24.2022.02.13.09.26.34 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Feb 2022 09:26:34 -0800 (PST) Content-Type: text/plain; charset=us-ascii List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org Mime-Version: 1.0 (Mac OS X Mail 15.0 \(3693.40.0.1.81\)) Subject: Re: git: 93885bb04182 - main - Better help message if locate database does not exists From: Jessica Clarke In-Reply-To: <202202131705.21DH5XG4094170@gitrepo.freebsd.org> Date: Sun, 13 Feb 2022 17:26:33 +0000 Cc: "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" Content-Transfer-Encoding: quoted-printable Message-Id: <38127DA5-9FEC-416F-8F1B-97CBA5D070CA@freebsd.org> References: <202202131705.21DH5XG4094170@gitrepo.freebsd.org> To: Wolfram Schneider X-Mailer: Apple Mail (2.3693.40.0.1.81) X-Rspamd-Queue-Id: 4JxZ5s6y8kz4YBC X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of jrtc27@jrtc27.com designates 209.85.221.42 as permitted sender) smtp.mailfrom=jrtc27@jrtc27.com X-Spamd-Result: default: False [-2.50 / 15.00]; TO_DN_EQ_ADDR_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; MV_CASE(0.50)[]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17]; RCVD_COUNT_THREE(0.00)[3]; NEURAL_HAM_SHORT(-1.00)[-1.000]; FORGED_SENDER(0.30)[jrtc27@freebsd.org,jrtc27@jrtc27.com]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; MID_RHS_MATCH_FROM(0.00)[]; FROM_NEQ_ENVFROM(0.00)[jrtc27@freebsd.org,jrtc27@jrtc27.com]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; FREEFALL_USER(0.00)[jrtc27]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[dev-commits-src-all@freebsd.org]; DMARC_NA(0.00)[freebsd.org]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[209.85.221.42:from]; MLMMJ_DEST(0.00)[dev-commits-src-all]; RWL_MAILSPIKE_POSSIBLE(0.00)[209.85.221.42:from]; RCVD_TLS_ALL(0.00)[] X-ThisMailContainsUnwantedMimeParts: N On 13 Feb 2022, at 17:05, Wolfram Schneider wrote: > The branch main has been updated by wosch: >=20 > URL: = https://cgit.FreeBSD.org/src/commit/?id=3D93885bb04182c104be1ec410a5ccb105= f1ec5ff2 >=20 > commit 93885bb04182c104be1ec410a5ccb105f1ec5ff2 > Author: Wolfram Schneider > AuthorDate: 2022-02-13 17:00:22 +0000 > Commit: Wolfram Schneider > CommitDate: 2022-02-13 17:00:22 +0000 >=20 > Better help message if locate database does not exists >=20 > PR: 211501 > Reported by: Oliver Peter > Reviewed by: Pau Amma > Differential Revision: https://reviews.freebsd.org/D34243 > --- > usr.bin/locate/locate/locate.c | 36 = ++++++++++++++++++++++++++---------- > usr.bin/locate/locate/util.c | 36 = ++++++++++++++++++++++++++++++++++++ > 2 files changed, 62 insertions(+), 10 deletions(-) >=20 > diff --git a/usr.bin/locate/locate/locate.c = b/usr.bin/locate/locate/locate.c > index 0bbd95ac696d..014fa7bcc301 100644 > --- a/usr.bin/locate/locate/locate.c > +++ b/usr.bin/locate/locate/locate.c > @@ -124,6 +124,8 @@ extern int getwf(FILE *); > extern u_char *tolower_word(u_char *); > extern int check_bigram_char(int); > extern char *patprep(char *); > +extern void rebuild_message(char *db); > +extern int check_size(char *db); >=20 > int > main(int argc, char **argv) > @@ -216,7 +218,6 @@ main(int argc, char **argv) > exit(0); > } >=20 > - > /* > * Arguments: > * db database > @@ -235,8 +236,16 @@ search_fopen(char *db, char **s) > *(s+1) =3D NULL; > } > }=20 > - else if ((fp =3D fopen(db, "r")) =3D=3D NULL) > - err(1, "`%s'", db); > + else {=20 > + if (!check_size(db)) > + exit(1); > + > + if ((fp =3D fopen(db, "r")) =3D=3D NULL) { > + warn("`%s'", db); > + rebuild_message(db); > + exit(1); > + } > + } >=20 > /* count only chars or lines */ > if (f_statistic) { > @@ -261,6 +270,7 @@ search_fopen(char *db, char **s) > }=20 >=20 > #ifdef MMAP > + Stray blank line; closing #endif is flush with }. > /* > * Arguments: > * db database > @@ -273,14 +283,20 @@ search_mmap(char *db, char **s) > int fd; > caddr_t p; > off_t len; > - if ((fd =3D open(db, O_RDONLY)) =3D=3D -1 || > - fstat(fd, &sb) =3D=3D -1) > - err(1, "`%s'", db); > + > + if (!check_size(db)) > + exit(1); > + > + if (stat(db, &sb) =3D=3D -1) > + err(1, "stat"); > + > len =3D sb.st_size; > - if (len < (2*NBG)) > - errx(1, > - "database too small: %s\nRun = /usr/libexec/locate.updatedb", > - db); > + > + if ((fd =3D open(db, O_RDONLY)) =3D=3D -1) { > + warn("%s", db); > + rebuild_message(db); > + exit(1); > + } >=20 > if ((p =3D mmap((caddr_t)0, (size_t)len, > PROT_READ, MAP_SHARED, > diff --git a/usr.bin/locate/locate/util.c = b/usr.bin/locate/locate/util.c > index 1d15f83b6826..aba90b1deda7 100644 > --- a/usr.bin/locate/locate/util.c > +++ b/usr.bin/locate/locate/util.c > @@ -41,8 +41,10 @@ > #include > #include > #include > +#include >=20 > #include "locate.h" > +#include "pathnames.h" >=20 > char **colon(char **, char*, char*); > char *patprep(char *); > @@ -268,3 +270,37 @@ getwf(fp) > } > return(word); > } > + > + Stray blank line. > +void > +rebuild_message(char *db) > +{ > + /* only for the default locate database */ > + if (strcmp(_PATH_FCODES, db) =3D=3D 0) { > + fprintf(stderr, "\nTo create a new database, please run = the following command as root:\n\n"); > + fprintf(stderr, " = /etc/periodic/weekly/310.locate\n\n"); > + } > +} > + > +int > +check_size(char *db)=20 > +{ > + struct stat sb; > + off_t len; > + > + if (stat(db, &sb) =3D=3D -1) { > + warnx("the locate database '%s' does not exists.", db); stat(2) can fail for other reasons. But also s/exists/exist/. > + rebuild_message(db); > + return(0); return (0); > + } > + len =3D sb.st_size; > + > + if (len < (2 * NBG)) { > + warnx("the locate database '%s' is less than %d bytes = large.", db, (2 * NBG)); Sounds clumsy; "... is smaller than %d bytes."? > + rebuild_message(db); > + return(0); return (0); > + } > + > + return(1); return (1); > +} > + Stray blank line? Jess