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 AF95F5A0268 for ; Wed, 15 Feb 2023 07:57:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676444245; 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=yihc2nm5UAmMp7jF5f8rCEv3E79SyjU57Ktu/jUA0/A=; b=A1hUjh43Bjjy3LtGo70YRskPRNxk9XuSpNMXsqsZW0PJo7e9XUO40HWjKh2rf4YAOSDJyP ii0TW4eFnN7/5Xj7Fi4Aq34r2lmKgLEW+UsrcKfYy0a/EfxUJxAnNr1j3NmP6xMeVKtpzw E9xZWDG9N8kk4UkJmz7BiFDaUnQ9cUM= 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-619-16zrS6LvPEyCNtZLWIIlCg-1; Wed, 15 Feb 2023 01:57:24 -0500 X-MC-Unique: 16zrS6LvPEyCNtZLWIIlCg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 062E5811E9C for ; Wed, 15 Feb 2023 06:57:24 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.2.16.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id E6E6C40C1423 for ; Wed, 15 Feb 2023 06:57:23 +0000 (UTC) From: Laine Stump To: passt-dev@passt.top Subject: [PATCH v3 2/9] add die() to log an error message and exit with a single call Date: Wed, 15 Feb 2023 01:57:16 -0500 Message-Id: <20230215065723.108696-3-laine@redhat.com> In-Reply-To: <20230215065723.108696-1-laine@redhat.com> References: <20230215065723.108696-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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: 6ZQDXHCAYUX274YBOL4BA7MYZ2DZOR6Q X-Message-ID-Hash: 6ZQDXHCAYUX274YBOL4BA7MYZ2DZOR6Q 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 die() that will log an error and then exit. Signed-off-by: Laine Stump --- log.c | 14 +++++++++----- log.h | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/log.c b/log.c index 6dc6673..2920aba 100644 --- a/log.c +++ b/log.c @@ -44,7 +44,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; \ @@ -74,6 +74,9 @@ 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 */ @@ -86,10 +89,11 @@ const char *logfile_prefix[] = { " ", /* LOG_DEBUG */ }; -logfn(err, LOG_ERR) -logfn(warn, LOG_WARNING) -logfn(info, LOG_INFO) -logfn(debug, LOG_DEBUG) +logfn(die, LOG_ERR, 1) +logfn(err, LOG_ERR, 0) +logfn(warn, LOG_WARNING, 0) +logfn(info, LOG_INFO, 0) +logfn(debug,LOG_DEBUG, 0) /** * trace_init() - Set log_trace depending on trace (debug) mode diff --git a/log.h b/log.h index 987dc17..d4e9d85 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 die(const char *format, ...); void err(const char *format, ...); void warn(const char *format, ...); void info(const char *format, ...); -- 2.39.1