git: de3deff65c5b - main - libiscsiutil: Add log_warnc() and log_errc() functions
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 30 Jan 2025 15:49:09 UTC
The branch main has been updated by jhb:
URL: https://cgit.FreeBSD.org/src/commit/?id=de3deff65c5b407ab29b45780f2585b3bc24bbd6
commit de3deff65c5b407ab29b45780f2585b3bc24bbd6
Author: John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2025-01-30 15:15:39 +0000
Commit: John Baldwin <jhb@FreeBSD.org>
CommitDate: 2025-01-30 15:15:39 +0000
libiscsiutil: Add log_warnc() and log_errc() functions
These are similar to warnc() and errc() in that they take an explicit
error code instead of using the value of the errno global.
Reviewed by: mav, asomers
Sponsored by: Chelsio Communications
Differential Revision: https://reviews.freebsd.org/D48648
---
lib/libiscsiutil/libiscsiutil.h | 4 ++++
lib/libiscsiutil/log.c | 22 ++++++++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/lib/libiscsiutil/libiscsiutil.h b/lib/libiscsiutil/libiscsiutil.h
index 8da6ead73fce..c091c1d9753a 100644
--- a/lib/libiscsiutil/libiscsiutil.h
+++ b/lib/libiscsiutil/libiscsiutil.h
@@ -162,9 +162,13 @@ void log_set_peer_name(const char *name);
void log_set_peer_addr(const char *addr);
void log_err(int, const char *, ...)
__dead2 __printflike(2, 3);
+void log_errc(int, int, const char *, ...)
+ __dead2 __printflike(3, 4);
void log_errx(int, const char *, ...)
__dead2 __printflike(2, 3);
void log_warn(const char *, ...) __printflike(1, 2);
+void log_warnc(int, const char *, ...)
+ __printflike(2, 3);
void log_warnx(const char *, ...) __printflike(1, 2);
void log_debugx(const char *, ...) __printflike(1, 2);
diff --git a/lib/libiscsiutil/log.c b/lib/libiscsiutil/log.c
index a69c979c3cce..cead4ab2d709 100644
--- a/lib/libiscsiutil/log.c
+++ b/lib/libiscsiutil/log.c
@@ -152,6 +152,18 @@ log_err(int eval, const char *fmt, ...)
exit(eval);
}
+void
+log_errc(int eval, int code, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ log_common(LOG_CRIT, code, fmt, ap);
+ va_end(ap);
+
+ exit(eval);
+}
+
void
log_errx(int eval, const char *fmt, ...)
{
@@ -174,6 +186,16 @@ log_warn(const char *fmt, ...)
va_end(ap);
}
+void
+log_warnc(int code, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ log_common(LOG_WARNING, code, fmt, ap);
+ va_end(ap);
+}
+
void
log_warnx(const char *fmt, ...)
{