mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
log: set syslog facility to LOG_DAEMON when run in server mode
This commit is contained in:
parent
4f4ee5b39d
commit
55a23a5b29
3 changed files with 17 additions and 5 deletions
15
log.c
15
log.c
|
|
@ -13,16 +13,21 @@
|
||||||
|
|
||||||
static bool colorize = false;
|
static bool colorize = false;
|
||||||
|
|
||||||
static void __attribute__((constructor))
|
void
|
||||||
init(void)
|
log_init(enum log_facility syslog_facility)
|
||||||
{
|
{
|
||||||
|
static const int facility_map[] = {
|
||||||
|
[LOG_FACILITY_USER] = LOG_USER,
|
||||||
|
[LOG_FACILITY_DAEMON] = LOG_DAEMON,
|
||||||
|
};
|
||||||
|
|
||||||
colorize = isatty(STDOUT_FILENO);
|
colorize = isatty(STDOUT_FILENO);
|
||||||
openlog(NULL, /*LOG_PID*/0, LOG_USER);
|
openlog(NULL, /*LOG_PID*/0, facility_map[syslog_facility]);
|
||||||
setlogmask(LOG_UPTO(LOG_WARNING));
|
setlogmask(LOG_UPTO(LOG_WARNING));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __attribute__((destructor))
|
void
|
||||||
fini(void)
|
log_deinit(void)
|
||||||
{
|
{
|
||||||
closelog();
|
closelog();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
4
log.h
4
log.h
|
|
@ -1,7 +1,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
enum log_facility { LOG_FACILITY_USER, LOG_FACILITY_DAEMON };
|
||||||
enum log_class { LOG_CLASS_ERROR, LOG_CLASS_WARNING, LOG_CLASS_INFO, LOG_CLASS_DEBUG };
|
enum log_class { LOG_CLASS_ERROR, LOG_CLASS_WARNING, LOG_CLASS_INFO, LOG_CLASS_DEBUG };
|
||||||
|
|
||||||
|
void log_init(enum log_facility syslog_facility);
|
||||||
|
void log_deinit(void);
|
||||||
|
|
||||||
void log_msg(enum log_class log_class, const char *module,
|
void log_msg(enum log_class log_class, const char *module,
|
||||||
const char *file, int lineno,
|
const char *file, int lineno,
|
||||||
const char *fmt, ...) __attribute__((format (printf, 5, 6)));
|
const char *fmt, ...) __attribute__((format (printf, 5, 6)));
|
||||||
|
|
|
||||||
3
main.c
3
main.c
|
|
@ -190,6 +190,8 @@ main(int argc, char *const *argv)
|
||||||
struct server *server = NULL;
|
struct server *server = NULL;
|
||||||
struct shutdown_context shutdown_ctx = {.term = &term, .exit_code = EXIT_FAILURE};
|
struct shutdown_context shutdown_ctx = {.term = &term, .exit_code = EXIT_FAILURE};
|
||||||
|
|
||||||
|
log_init(as_server ? LOG_FACILITY_DAEMON : LOG_FACILITY_USER);
|
||||||
|
|
||||||
/* This ensures we keep a set of fonts in the cache */
|
/* This ensures we keep a set of fonts in the cache */
|
||||||
if (!initialize_fonts(&conf, fonts))
|
if (!initialize_fonts(&conf, fonts))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
@ -241,5 +243,6 @@ out:
|
||||||
font_destroy(fonts[i]);
|
font_destroy(fonts[i]);
|
||||||
|
|
||||||
config_free(conf);
|
config_free(conf);
|
||||||
|
log_deinit();
|
||||||
return ret == EXIT_SUCCESS && !as_server ? shutdown_ctx.exit_code : ret;
|
return ret == EXIT_SUCCESS && !as_server ? shutdown_ctx.exit_code : ret;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue