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.129.124]) by passt.top (Postfix) with ESMTP id 2A8C55A026A for ; Thu, 9 Feb 2023 18:45:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675964737; 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=tM3IrFsQmG3B4MUBE6daQYq+fNVoH+lTZrHOCyF9Qb8=; b=INozUfP9TaM2ZLrCYNvGQEq2BRTSAPhgAIwevVBnmEduRv4P4dz3OP4yK0/uPQMnE2p8fk 6KLBhheaxS6WHrOXvs9m/AXqJcfDLHWlOr6xZ7nhVkBQj/GWHc4kvJJeDDp01Jh3Ucjfj3 KZBRD4zqjn6UhuWlJEYThiY0ahVXDbc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-135-0b5hH-YaO5KjTO-Uf0Ko4A-1; Thu, 09 Feb 2023 12:45:35 -0500 X-MC-Unique: 0b5hH-YaO5KjTO-Uf0Ko4A-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8955B800050; Thu, 9 Feb 2023 17:45:35 +0000 (UTC) Received: from maya.cloud.tilaa.com (ovpn-208-4.brq.redhat.com [10.40.208.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 50A011121318; Thu, 9 Feb 2023 17:45:35 +0000 (UTC) Date: Thu, 9 Feb 2023 18:45:32 +0100 From: Stefano Brivio To: Laine Stump Subject: Re: [PATCH v2 2/9] add errexit() to log an error message and exit with a single call Message-ID: <20230209184532.38ef1d4b@elisabeth> In-Reply-To: <20230208174838.1680517-3-laine@redhat.com> References: <20230208174838.1680517-1-laine@redhat.com> <20230208174838.1680517-3-laine@redhat.com> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: QNITYWHTTWBGDRGBM32C6EX6NDAFTSYP X-Message-ID-Hash: QNITYWHTTWBGDRGBM32C6EX6NDAFTSYP 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 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. -- Stefano