From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 74EC45A005E for ; Mon, 13 Feb 2023 11:46:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676285182; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MeDUh85OLnuN39muth805WFI5JGBdXxP4K840DISRm8=; b=DhB8CUcdvVKaiv9IkKOxnFNaE87bfMu/d2nyU+152QTDMIAm9mdpMkXZewoKK+InL08HL0 HSokT113p9g/UY1QY+lovEKXSHFb5TlAt5iG0RlKxNmCbuUeiXTQBiLNIIyWiKF4ytwYcY /lRmU+mmUC77cshuGd3zIeFH8nq5W88= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-662-vUE0Kl6WP-29n_5jEnUb_A-1; Mon, 13 Feb 2023 05:46:21 -0500 X-MC-Unique: vUE0Kl6WP-29n_5jEnUb_A-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EAAC53C0E447; Mon, 13 Feb 2023 10:46:20 +0000 (UTC) Received: from maya.cloud.tilaa.com (unknown [10.33.32.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BC61518EC7; Mon, 13 Feb 2023 10:46:20 +0000 (UTC) Date: Mon, 13 Feb 2023 11:46:18 +0100 From: Stefano Brivio To: David Gibson , Laine Stump Subject: Re: [PATCH v2 2/9] add errexit() to log an error message and exit with a single call Message-ID: <20230213114618.40cf2021@elisabeth> In-Reply-To: References: <20230208174838.1680517-1-laine@redhat.com> <20230208174838.1680517-3-laine@redhat.com> <20230209184532.38ef1d4b@elisabeth> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: VPCOSMLUMXCMRMTAS6AS72SXRBUIEC3E X-Message-ID-Hash: VPCOSMLUMXCMRMTAS6AS72SXRBUIEC3E X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top, laine@laine.org X-Mailman-Version: 3.3.3 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Mon, 13 Feb 2023 14:22:33 +1100 David Gibson wrote: > On Thu, Feb 09, 2023 at 06:45:32PM +0100, Stefano Brivio wrote: > > On Wed, 8 Feb 2023 12:48:31 -0500 > > Laine Stump wrote: > > > > > Almost all occurences of err() are either immediately followed by > > > exit(EXIT_FAILURE), usage(argv[0]) (which itself then calls > > > exit(EXIT_FAILURE), or that is what's done immediately after returning > > > from the function that calls err(). Modify the errfn macro so that its > > > instantiations can include exit(EXIT_FAILURE) at the end, and use that > > > to create a new function errxit() that will log an error and then > > > exit. > > > > > > Signed-off-by: Laine Stump > > > --- > > > log.c | 13 ++++++++----- > > > log.h | 1 + > > > 2 files changed, 9 insertions(+), 5 deletions(-) > > > > > > diff --git a/log.c b/log.c > > > index 0ab0adf..4956914 100644 > > > --- a/log.c > > > +++ b/log.c > > > @@ -45,7 +45,7 @@ static char log_header[BUFSIZ]; /* File header, written back on cuts */ > > > static time_t log_start; /* Start timestamp */ > > > int log_trace; /* --trace mode enabled */ > > > > > > -#define logfn(name, level) \ > > > +#define logfn(name, level, doexit) \ > > > void name(const char *format, ...) { \ > > > struct timespec tp; \ > > > va_list args; \ > > > @@ -76,6 +76,8 @@ void name(const char *format, ...) { \ > > > if (format[strlen(format)] != '\n') \ > > > fprintf(stderr, "\n"); \ > > > } \ > > > + if (doexit) \ > > > > A blank line before this would make it more consistent. > > > > > + exit(EXIT_FAILURE); \ > > > } > > > > > > /* Prefixes for log file messages, indexed by priority */ > > > @@ -88,10 +90,11 @@ const char *logfile_prefix[] = { > > > " ", /* LOG_DEBUG */ > > > }; > > > > > > -logfn(err, LOG_ERR) > > > -logfn(warn, LOG_WARNING) > > > -logfn(info, LOG_INFO) > > > -logfn(debug, LOG_DEBUG) > > > +logfn(errexit, LOG_ERR, 1) > > > +logfn(err, LOG_ERR, 0) > > > +logfn(warn, LOG_WARNING, 0) > > > +logfn(info, LOG_INFO, 0) > > > +logfn(debug, LOG_DEBUG, 0) > > > > > > /** > > > * log_go_daemon() - tell logging subsystem that the process has been > > > diff --git a/log.h b/log.h > > > index a57c777..ed19415 100644 > > > --- a/log.h > > > +++ b/log.h > > > @@ -10,6 +10,7 @@ > > > #define LOGFILE_CUT_RATIO 30 /* When full, cut ~30% size */ > > > #define LOGFILE_SIZE_MIN (5UL * MAX(BUFSIZ, PAGE_SIZE)) > > > > > > +void errexit(const char *format, ...); > > > void err(const char *format, ...); > > > void warn(const char *format, ...); > > > void info(const char *format, ...); > > > > Other than that, this looks good to me. > > LGTM. Personally I like to call such functions "die()". I was about to suggest that (it's shorter and conveys the same meaning), then I thought die() would be a common library function. Actually, it's not -- so I would also favour die() here. -- Stefano