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 C23285A0268 for ; Wed, 8 Feb 2023 18:48:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675878522; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bVQywyppQPAHpDsObXT7UH0qODihNdycW/tnEbkg3eI=; b=fVxB2xwrRq+g6BVYtRtfzQqD544mu7GhtLDqOV6DoAFpXcQesVUhxt2Yk41VPyNbnk2pEF HwkPH5234YOp6VCJL1tbUtuBkxAYIcyYOM2WFS41uBp/4dqneVOw755NbhyT5TY5484xqA +AA6ns5VwtE128t5Lt+SopBLLiileKw= 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-596-qEJyUXX7Pe23EJ9njIUzYg-1; Wed, 08 Feb 2023 12:48:39 -0500 X-MC-Unique: qEJyUXX7Pe23EJ9njIUzYg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6FC37886461; Wed, 8 Feb 2023 17:48:39 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.2.17.81]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5509D2166B29; Wed, 8 Feb 2023 17:48:39 +0000 (UTC) From: Laine Stump To: passt-dev@passt.top, laine@laine.org Subject: [PATCH v2 2/9] add errexit() to log an error message and exit with a single call Date: Wed, 8 Feb 2023 12:48:31 -0500 Message-Id: <20230208174838.1680517-3-laine@redhat.com> In-Reply-To: <20230208174838.1680517-1-laine@redhat.com> References: <20230208174838.1680517-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: KIR66CPA2YTWAA2AWAKXIS7RJK4QNGCI X-Message-ID-Hash: KIR66CPA2YTWAA2AWAKXIS7RJK4QNGCI X-MailFrom: laine@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 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: 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) \ + 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, ...); -- 2.39.1