[make-initrd] ueventd: Pass the program name when initializing the logger
Alexey Gladkov
gladkov.alexey at gmail.com
Sat May 6 22:45:03 MSK 2023
Signed-off-by: Alexey Gladkov <gladkov.alexey at gmail.com>
---
datasrc/ueventd/logging.c | 11 +++++++----
datasrc/ueventd/ueventd.c | 2 +-
datasrc/ueventd/ueventd.h | 2 +-
3 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/datasrc/ueventd/logging.c b/datasrc/ueventd/logging.c
index 525ff7fd..ac316aab 100644
--- a/datasrc/ueventd/logging.c
+++ b/datasrc/ueventd/logging.c
@@ -10,6 +10,7 @@
int log_priority = LOG_INFO;
int log_fd = STDERR_FILENO;
+const char *log_progname = NULL;
int rd_logging_level(const char *name)
{
@@ -20,10 +21,11 @@ int rd_logging_level(const char *name)
return log_priority;
}
-void rd_logging_init(int fd, int loglevel)
+void rd_logging_init(int fd, int loglevel, const char *progname)
{
log_priority = loglevel;
log_fd = fd;
+ log_progname = progname;
}
void rd_logging_close(void)
@@ -37,10 +39,11 @@ void rd_message(int priority, const char *fmt, ...)
if (priority <= log_priority) {
time_t ts = time(NULL);
struct tm *t = localtime(&ts);
- dprintf(log_fd, "[%04d-%02d-%02d %02d:%02d:%02d] %s: ",
+ dprintf(log_fd, "[%04d-%02d-%02d %02d:%02d:%02d] ",
t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
- t->tm_hour, t->tm_min, t->tm_sec,
- program_invocation_short_name);
+ t->tm_hour, t->tm_min, t->tm_sec);
+ if (log_progname)
+ dprintf(log_fd, "%s: ", log_progname);
vdprintf(log_fd, fmt, ap);
dprintf(log_fd, "\n");
}
diff --git a/datasrc/ueventd/ueventd.c b/datasrc/ueventd/ueventd.c
index d015d3da..0ce5be00 100644
--- a/datasrc/ueventd/ueventd.c
+++ b/datasrc/ueventd/ueventd.c
@@ -491,7 +491,7 @@ int main(int argc, char **argv)
stderr = cons;
}
- rd_logging_init(fileno(stderr), loglevel);
+ rd_logging_init(fileno(stderr), loglevel, program_invocation_short_name);
rd_info("starting server ...");
diff --git a/datasrc/ueventd/ueventd.h b/datasrc/ueventd/ueventd.h
index a783d48d..ddba98bf 100644
--- a/datasrc/ueventd/ueventd.h
+++ b/datasrc/ueventd/ueventd.h
@@ -56,7 +56,7 @@ extern int is_dot_dir(struct dirent *ent) __attribute__((nonnull(1)));
#include <syslog.h>
#include <stdlib.h>
-extern void rd_logging_init(int log_fd, int level);
+extern void rd_logging_init(int log_fd, int level, const char *progname);
extern void rd_logging_close(void);
extern int rd_logging_level(const char *lvl) __attribute__((nonnull(1)));
extern void rd_message(int priority, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
--
2.33.7
More information about the Make-initrd
mailing list