Merge pull request #1213 from arandomhuman/wlr_log_get_verbosity

Add wlr_log_get_verbosity method
This commit is contained in:
Drew DeVault 2018-09-03 11:15:12 -04:00 committed by GitHub
commit 73423c988c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 5 deletions

View File

@ -35,8 +35,13 @@ typedef void (*wlr_log_func_t)(enum wlr_log_importance importance,
// Will log all messages less than or equal to `verbosity` // Will log all messages less than or equal to `verbosity`
// If `callback` is NULL, wlr will use its default logger. // If `callback` is NULL, wlr will use its default logger.
// The function can be called multiple times to update the verbosity or
// callback function.
void wlr_log_init(enum wlr_log_importance verbosity, wlr_log_func_t callback); void wlr_log_init(enum wlr_log_importance verbosity, wlr_log_func_t callback);
// Returns the log verbosity provided to wlr_log_init
enum wlr_log_importance wlr_log_get_verbosity(void);
#ifdef __GNUC__ #ifdef __GNUC__
#define _WLR_ATTRIB_PRINTF(start, end) __attribute__((format(printf, start, end))) #define _WLR_ATTRIB_PRINTF(start, end) __attribute__((format(printf, start, end)))
#else #else

View File

@ -26,7 +26,10 @@ static void usage(const char *name, int ret) {
" See `rootston.ini.example` for config\n" " See `rootston.ini.example` for config\n"
" file documentation.\n" " file documentation.\n"
" -E <COMMAND> Command that will be ran at startup.\n" " -E <COMMAND> Command that will be ran at startup.\n"
" -D Enable damage tracking debugging.\n", " -D Enable damage tracking debugging.\n"
" -l <LEVEL> Set log verbosity, where,\n"
" 0:SILENT, 1:ERROR, 2:INFO, 3+:DEBUG\n"
" (default: DEBUG)\n",
name); name);
exit(ret); exit(ret);
@ -455,7 +458,8 @@ struct roots_config *roots_config_create_from_args(int argc, char *argv[]) {
wl_list_init(&config->bindings); wl_list_init(&config->bindings);
int c; int c;
while ((c = getopt(argc, argv, "C:E:hD")) != -1) { unsigned int log_verbosity = WLR_DEBUG;
while ((c = getopt(argc, argv, "C:E:hDl:")) != -1) {
switch (c) { switch (c) {
case 'C': case 'C':
config->config_path = strdup(optarg); config->config_path = strdup(optarg);
@ -466,11 +470,18 @@ struct roots_config *roots_config_create_from_args(int argc, char *argv[]) {
case 'D': case 'D':
config->debug_damage_tracking = true; config->debug_damage_tracking = true;
break; break;
case 'l':
log_verbosity = strtoul(optarg, NULL, 10);
if (log_verbosity >= WLR_LOG_IMPORTANCE_LAST) {
log_verbosity = WLR_LOG_IMPORTANCE_LAST - 1;
}
break;
case 'h': case 'h':
case '?': case '?':
usage(argv[0], c != 'h'); usage(argv[0], c != 'h');
} }
} }
wlr_log_init(log_verbosity, NULL);
if (!config->config_path) { if (!config->config_path) {
// get the config path from the current directory // get the config path from the current directory

View File

@ -85,3 +85,7 @@ const char *_wlr_strip_path(const char *filepath) {
} }
return filepath; return filepath;
} }
enum wlr_log_importance wlr_log_get_verbosity(void) {
return log_importance;
}

View File

@ -74,6 +74,7 @@ static int fill_arg(char ***argv, const char *fmt, ...) {
return len; return len;
} }
_Noreturn
static void exec_xwayland(struct wlr_xwayland *wlr_xwayland) { static void exec_xwayland(struct wlr_xwayland *wlr_xwayland) {
if (unset_cloexec(wlr_xwayland->x_fd[0]) || if (unset_cloexec(wlr_xwayland->x_fd[0]) ||
unset_cloexec(wlr_xwayland->x_fd[1]) || unset_cloexec(wlr_xwayland->x_fd[1]) ||
@ -123,9 +124,26 @@ static void exec_xwayland(struct wlr_xwayland *wlr_xwayland) {
wlr_xwayland->wl_fd[1], wlr_xwayland->display, wlr_xwayland->x_fd[0], wlr_xwayland->wl_fd[1], wlr_xwayland->display, wlr_xwayland->x_fd[0],
wlr_xwayland->x_fd[1], wlr_xwayland->wm_fd[1]); wlr_xwayland->x_fd[1], wlr_xwayland->wm_fd[1]);
// TODO: close stdout/err depending on log level // Closes stdout/stderr depending on log verbosity
enum wlr_log_importance verbosity = wlr_log_get_verbosity();
int devnull = open("/dev/null", O_WRONLY | O_CREAT, 0666);
if (devnull < 0) {
wlr_log_errno(WLR_ERROR, "XWayland: failed to open /dev/null");
_exit(EXIT_FAILURE);
}
if (verbosity < WLR_INFO) {
dup2(devnull, STDOUT_FILENO);
}
if (verbosity < WLR_ERROR) {
dup2(devnull, STDERR_FILENO);
}
// This returns if and only if the call fails
execvp("Xwayland", argv); execvp("Xwayland", argv);
wlr_log_errno(WLR_ERROR, "failed to exec Xwayland");
close(devnull);
_exit(EXIT_FAILURE);
} }
static void xwayland_finish_server(struct wlr_xwayland *wlr_xwayland) { static void xwayland_finish_server(struct wlr_xwayland *wlr_xwayland) {
@ -346,8 +364,6 @@ static bool xwayland_start_server(struct wlr_xwayland *wlr_xwayland) {
sigprocmask(SIG_BLOCK, &sigset, NULL); sigprocmask(SIG_BLOCK, &sigset, NULL);
if ((pid = fork()) == 0) { if ((pid = fork()) == 0) {
exec_xwayland(wlr_xwayland); exec_xwayland(wlr_xwayland);
wlr_log_errno(WLR_ERROR, "failed to exec Xwayland");
_exit(EXIT_FAILURE);
} }
if (pid < 0) { if (pid < 0) {
wlr_log_errno(WLR_ERROR, "second fork failed"); wlr_log_errno(WLR_ERROR, "second fork failed");