From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on sa.local.altlinux.org X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683402310; x=1685994310; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=dO/jtplwzsktHSMiAirhPcSmsehROgYcFXw/2JmkRts=; b=YlrLgL/iCgXRc1Ze49KcJUvq+wYPbGg2qxwRsPr6c43bMwL3pW06O5htcLyUUAfBLk wcDSN3b/HiRi4fHeEuIkBvyI2x6/WWT0zkFyamJuLyeIqEsJ59PfnqFedZ0KGeNsvxKt 4NTptqmy1gE6+hhQs7jRkd/lNjDZLwGGt+bvF23cwmHLXx7N6/LB34PSIoeqMoF2pq5W 1v7YlDjKRwbscc+1eHuumGakW5Uy017icbLBbM2T+/bpvKXjcWTvHpplR5n1gZUpTT6A 5teo+UjEXSQ9bqIb31e8MQ51jtGtNOXQM6D3jm9zyaOu8JbXpAbnsESdHbcdvGG7BWK4 rTHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683402310; x=1685994310; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dO/jtplwzsktHSMiAirhPcSmsehROgYcFXw/2JmkRts=; b=BJjsgOCeccouDdMGb0pgyfddxEXiUr5It+DrGKZlD3My7TXFexcOcJqVwN/5tHU9+E sphhJJG9fVZUQ/+93oIznr0DETmDPczPTj8D+D6V0TKfZs51T4orQAYcKm9G7BNaGmyS aV4RtAKPSkG/V3ThLPV3URAR6a5tD5JrcfcOGe2/EvlUW9gXDD6QgYs6oflt84KHfJce 6F9Nj4R8aTvvpMbgaMtImX0VcMnTqVa0mFSqNkIjiXEUV8CHMUgoamtk2p3QvWG5UxtI OPrf4cIW4sK9kyjB8dOmP6Imb+d733KfjcbmbgT/QkVYtw4MX/sUpEV+ULe9GQrsHKyu uITw== X-Gm-Message-State: AC+VfDyPdnXjACa5tX5M4+/0bgIG9LuVxSfgCBHQPHBkPn4ij2R69XMD CbYeIM+v5jZEwumfOTjJMT6ATMB2jWM= X-Google-Smtp-Source: ACHHUZ7qnutIqQeY7sQf/Si7h5RekHihErxdbbdZsG2uBxWewfWz+F/+QuHNnMga30DbUeuitvsTjg== X-Received: by 2002:a05:600c:248:b0:3ea:f73e:9d8a with SMTP id 8-20020a05600c024800b003eaf73e9d8amr3713740wmj.30.1683402310033; Sat, 06 May 2023 12:45:10 -0700 (PDT) From: Alexey Gladkov To: make-initrd@lists.altlinux.org Date: Sat, 6 May 2023 21:45:02 +0200 Message-Id: <20230506194504.1471267-2-gladkov.alexey@gmail.com> X-Mailer: git-send-email 2.33.7 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [make-initrd] ueventd: Allow to configure the log destination X-BeenThere: make-initrd@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: make-initrd@lists.altlinux.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 06 May 2023 19:45:13 -0000 Archived-At: List-Archive: Signed-off-by: Alexey Gladkov --- datasrc/ueventd/logging.c | 27 ++++++--------------------- datasrc/ueventd/ueventd.c | 19 ++++++++++++++++++- datasrc/ueventd/ueventd.h | 2 +- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/datasrc/ueventd/logging.c b/datasrc/ueventd/logging.c index 3a04a5a9..525ff7fd 100644 --- a/datasrc/ueventd/logging.c +++ b/datasrc/ueventd/logging.c @@ -8,9 +8,8 @@ #include "ueventd.h" -#define default_logfile "/var/log/ueventd.log" - int log_priority = LOG_INFO; +int log_fd = STDERR_FILENO; int rd_logging_level(const char *name) { @@ -21,24 +20,10 @@ int rd_logging_level(const char *name) return log_priority; } -void rd_logging_init(int loglevel) +void rd_logging_init(int fd, int loglevel) { - if (!getenv("UEVENTD_USE_STDERR")) { - char *rdlog = getenv("RDLOG"); - const char *logfile = default_logfile; - - if (rdlog && !strcasecmp(rdlog, "console")) - logfile = "/dev/console"; - - FILE *cons = fopen(logfile, "w+"); - if (!cons) - rd_fatal("open(%s): %m", logfile); - - fclose(stderr); - stderr = cons; - } - log_priority = loglevel; + log_fd = fd; } void rd_logging_close(void) @@ -52,12 +37,12 @@ void rd_message(int priority, const char *fmt, ...) if (priority <= log_priority) { time_t ts = time(NULL); struct tm *t = localtime(&ts); - fprintf(stderr, "[%04d-%02d-%02d %02d:%02d:%02d] %s: ", + dprintf(log_fd, "[%04d-%02d-%02d %02d:%02d:%02d] %s: ", t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, program_invocation_short_name); - vfprintf(stderr, fmt, ap); - fprintf(stderr, "\n"); + vdprintf(log_fd, fmt, ap); + dprintf(log_fd, "\n"); } va_end(ap); } diff --git a/datasrc/ueventd/ueventd.c b/datasrc/ueventd/ueventd.c index f4b89cb9..d015d3da 100644 --- a/datasrc/ueventd/ueventd.c +++ b/datasrc/ueventd/ueventd.c @@ -21,6 +21,8 @@ #include "ueventd.h" +#define default_logfile "/var/log/ueventd.log" + char *uevent_confdb; char *filter_dir; char *uevent_dir; @@ -474,7 +476,22 @@ int main(int argc, char **argv) if (optind == argc) rd_fatal("specify handler program"); - rd_logging_init(loglevel); + if (!getenv("UEVENTD_USE_STDERR")) { + char *rdlog = getenv("RDLOG"); + const char *logfile = default_logfile; + + if (rdlog && !strcasecmp(rdlog, "console")) + logfile = "/dev/console"; + + FILE *cons = fopen(logfile, "w+"); + if (!cons) + rd_fatal("open(%s): %m", logfile); + + fclose(stderr); + stderr = cons; + } + + rd_logging_init(fileno(stderr), loglevel); rd_info("starting server ..."); diff --git a/datasrc/ueventd/ueventd.h b/datasrc/ueventd/ueventd.h index e7ee1a8b..a783d48d 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 #include -extern void rd_logging_init(int level); +extern void rd_logging_init(int log_fd, int level); 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