diff options
author | Calvin Lee <cyrus296@gmail.com> | 2017-12-31 14:32:28 -0700 |
---|---|---|
committer | Calvin Lee <cyrus296@gmail.com> | 2017-12-31 14:32:28 -0700 |
commit | 7196f59db0698a4d31ee99763a1f43a7e53f95cc (patch) | |
tree | 9aa14b5e53987451ad03d21788d0df57a444ff21 | |
parent | Merge pull request #1542 from emersion/swaymsg-output (diff) | |
download | sway-7196f59db0698a4d31ee99763a1f43a7e53f95cc.tar.gz sway-7196f59db0698a4d31ee99763a1f43a7e53f95cc.tar.zst sway-7196f59db0698a4d31ee99763a1f43a7e53f95cc.zip |
Consolidate WLR and Sway logging
See #1390
-rw-r--r-- | sway/main.c | 48 | ||||
-rw-r--r-- | sway/server.c | 13 |
2 files changed, 31 insertions, 30 deletions
diff --git a/sway/main.c b/sway/main.c index bd69395a..c18e2677 100644 --- a/sway/main.c +++ b/sway/main.c | |||
@@ -15,12 +15,12 @@ | |||
15 | #include <sys/capability.h> | 15 | #include <sys/capability.h> |
16 | #include <sys/prctl.h> | 16 | #include <sys/prctl.h> |
17 | #endif | 17 | #endif |
18 | #include <wlr/util/log.h> | ||
18 | #include "sway/config.h" | 19 | #include "sway/config.h" |
19 | #include "sway/server.h" | 20 | #include "sway/server.h" |
20 | #include "sway/layout.h" | 21 | #include "sway/layout.h" |
21 | #include "sway/ipc-server.h" | 22 | #include "sway/ipc-server.h" |
22 | #include "ipc-client.h" | 23 | #include "ipc-client.h" |
23 | #include "log.h" | ||
24 | #include "readline.h" | 24 | #include "readline.h" |
25 | #include "stringop.h" | 25 | #include "stringop.h" |
26 | #include "util.h" | 26 | #include "util.h" |
@@ -126,7 +126,7 @@ static void log_env() { | |||
126 | "SWAYSOCK" | 126 | "SWAYSOCK" |
127 | }; | 127 | }; |
128 | for (size_t i = 0; i < sizeof(log_vars) / sizeof(char *); ++i) { | 128 | for (size_t i = 0; i < sizeof(log_vars) / sizeof(char *); ++i) { |
129 | sway_log(L_INFO, "%s=%s", log_vars[i], getenv(log_vars[i])); | 129 | wlr_log(L_INFO, "%s=%s", log_vars[i], getenv(log_vars[i])); |
130 | } | 130 | } |
131 | } | 131 | } |
132 | 132 | ||
@@ -141,14 +141,14 @@ static void log_distro() { | |||
141 | for (size_t i = 0; i < sizeof(paths) / sizeof(char *); ++i) { | 141 | for (size_t i = 0; i < sizeof(paths) / sizeof(char *); ++i) { |
142 | FILE *f = fopen(paths[i], "r"); | 142 | FILE *f = fopen(paths[i], "r"); |
143 | if (f) { | 143 | if (f) { |
144 | sway_log(L_INFO, "Contents of %s:", paths[i]); | 144 | wlr_log(L_INFO, "Contents of %s:", paths[i]); |
145 | while (!feof(f)) { | 145 | while (!feof(f)) { |
146 | char *line; | 146 | char *line; |
147 | if (!(line = read_line(f))) { | 147 | if (!(line = read_line(f))) { |
148 | break; | 148 | break; |
149 | } | 149 | } |
150 | if (*line) { | 150 | if (*line) { |
151 | sway_log(L_INFO, "%s", line); | 151 | wlr_log(L_INFO, "%s", line); |
152 | } | 152 | } |
153 | free(line); | 153 | free(line); |
154 | } | 154 | } |
@@ -161,7 +161,7 @@ static void log_kernel() { | |||
161 | return; | 161 | return; |
162 | FILE *f = popen("uname -a", "r"); | 162 | FILE *f = popen("uname -a", "r"); |
163 | if (!f) { | 163 | if (!f) { |
164 | sway_log(L_INFO, "Unable to determine kernel version"); | 164 | wlr_log(L_INFO, "Unable to determine kernel version"); |
165 | return; | 165 | return; |
166 | } | 166 | } |
167 | while (!feof(f)) { | 167 | while (!feof(f)) { |
@@ -170,7 +170,7 @@ static void log_kernel() { | |||
170 | break; | 170 | break; |
171 | } | 171 | } |
172 | if (*line) { | 172 | if (*line) { |
173 | sway_log(L_INFO, "%s", line); | 173 | wlr_log(L_INFO, "%s", line); |
174 | } | 174 | } |
175 | free(line); | 175 | free(line); |
176 | } | 176 | } |
@@ -181,14 +181,14 @@ static void security_sanity_check() { | |||
181 | // TODO: Notify users visually if this has issues | 181 | // TODO: Notify users visually if this has issues |
182 | struct stat s; | 182 | struct stat s; |
183 | if (stat("/proc", &s)) { | 183 | if (stat("/proc", &s)) { |
184 | sway_log(L_ERROR, | 184 | wlr_log(L_ERROR, |
185 | "!! DANGER !! /proc is not available - sway CANNOT enforce security rules!"); | 185 | "!! DANGER !! /proc is not available - sway CANNOT enforce security rules!"); |
186 | } | 186 | } |
187 | #ifdef __linux__ | 187 | #ifdef __linux__ |
188 | cap_flag_value_t v; | 188 | cap_flag_value_t v; |
189 | cap_t cap = cap_get_proc(); | 189 | cap_t cap = cap_get_proc(); |
190 | if (!cap || cap_get_flag(cap, CAP_SYS_PTRACE, CAP_PERMITTED, &v) != 0 || v != CAP_SET) { | 190 | if (!cap || cap_get_flag(cap, CAP_SYS_PTRACE, CAP_PERMITTED, &v) != 0 || v != CAP_SET) { |
191 | sway_log(L_ERROR, | 191 | wlr_log(L_ERROR, |
192 | "!! DANGER !! Sway does not have CAP_SYS_PTRACE and cannot enforce security rules for processes running as other users."); | 192 | "!! DANGER !! Sway does not have CAP_SYS_PTRACE and cannot enforce security rules for processes running as other users."); |
193 | } | 193 | } |
194 | if (cap) { | 194 | if (cap) { |
@@ -204,13 +204,13 @@ static void executable_sanity_check() { | |||
204 | stat(exe, &sb); | 204 | stat(exe, &sb); |
205 | // We assume that cap_get_file returning NULL implies ENODATA | 205 | // We assume that cap_get_file returning NULL implies ENODATA |
206 | if (sb.st_mode & (S_ISUID|S_ISGID) && cap_get_file(exe)) { | 206 | if (sb.st_mode & (S_ISUID|S_ISGID) && cap_get_file(exe)) { |
207 | sway_log(L_ERROR, | 207 | wlr_log(L_ERROR, |
208 | "sway executable has both the s(g)uid bit AND file caps set."); | 208 | "sway executable has both the s(g)uid bit AND file caps set."); |
209 | sway_log(L_ERROR, | 209 | wlr_log(L_ERROR, |
210 | "This is strongly discouraged (and completely broken)."); | 210 | "This is strongly discouraged (and completely broken)."); |
211 | sway_log(L_ERROR, | 211 | wlr_log(L_ERROR, |
212 | "Please clear one of them (either the suid bit, or the file caps)."); | 212 | "Please clear one of them (either the suid bit, or the file caps)."); |
213 | sway_log(L_ERROR, | 213 | wlr_log(L_ERROR, |
214 | "If unsure, strip the file caps."); | 214 | "If unsure, strip the file caps."); |
215 | exit(EXIT_FAILURE); | 215 | exit(EXIT_FAILURE); |
216 | } | 216 | } |
@@ -221,16 +221,16 @@ static void executable_sanity_check() { | |||
221 | static void drop_permissions(bool keep_caps) { | 221 | static void drop_permissions(bool keep_caps) { |
222 | if (getuid() != geteuid() || getgid() != getegid()) { | 222 | if (getuid() != geteuid() || getgid() != getegid()) { |
223 | if (setgid(getgid()) != 0) { | 223 | if (setgid(getgid()) != 0) { |
224 | sway_log(L_ERROR, "Unable to drop root"); | 224 | wlr_log(L_ERROR, "Unable to drop root"); |
225 | exit(EXIT_FAILURE); | 225 | exit(EXIT_FAILURE); |
226 | } | 226 | } |
227 | if (setuid(getuid()) != 0) { | 227 | if (setuid(getuid()) != 0) { |
228 | sway_log(L_ERROR, "Unable to drop root"); | 228 | wlr_log(L_ERROR, "Unable to drop root"); |
229 | exit(EXIT_FAILURE); | 229 | exit(EXIT_FAILURE); |
230 | } | 230 | } |
231 | } | 231 | } |
232 | if (setuid(0) != -1) { | 232 | if (setuid(0) != -1) { |
233 | sway_log(L_ERROR, "Root privileges can be restored."); | 233 | wlr_log(L_ERROR, "Root privileges can be restored."); |
234 | exit(EXIT_FAILURE); | 234 | exit(EXIT_FAILURE); |
235 | } | 235 | } |
236 | #ifdef __linux__ | 236 | #ifdef __linux__ |
@@ -238,11 +238,11 @@ static void drop_permissions(bool keep_caps) { | |||
238 | // Drop every cap except CAP_SYS_PTRACE | 238 | // Drop every cap except CAP_SYS_PTRACE |
239 | cap_t caps = cap_init(); | 239 | cap_t caps = cap_init(); |
240 | cap_value_t keep = CAP_SYS_PTRACE; | 240 | cap_value_t keep = CAP_SYS_PTRACE; |
241 | sway_log(L_INFO, "Dropping extra capabilities"); | 241 | wlr_log(L_INFO, "Dropping extra capabilities"); |
242 | if (cap_set_flag(caps, CAP_PERMITTED, 1, &keep, CAP_SET) || | 242 | if (cap_set_flag(caps, CAP_PERMITTED, 1, &keep, CAP_SET) || |
243 | cap_set_flag(caps, CAP_EFFECTIVE, 1, &keep, CAP_SET) || | 243 | cap_set_flag(caps, CAP_EFFECTIVE, 1, &keep, CAP_SET) || |
244 | cap_set_proc(caps)) { | 244 | cap_set_proc(caps)) { |
245 | sway_log(L_ERROR, "Failed to drop extra capabilities"); | 245 | wlr_log(L_ERROR, "Failed to drop extra capabilities"); |
246 | exit(EXIT_FAILURE); | 246 | exit(EXIT_FAILURE); |
247 | } | 247 | } |
248 | } | 248 | } |
@@ -330,22 +330,22 @@ int main(int argc, char **argv) { | |||
330 | 330 | ||
331 | // TODO: switch logging over to wlroots? | 331 | // TODO: switch logging over to wlroots? |
332 | if (debug) { | 332 | if (debug) { |
333 | init_log(L_DEBUG); | 333 | wlr_log_init(L_DEBUG, NULL); |
334 | } else if (verbose || validate) { | 334 | } else if (verbose || validate) { |
335 | init_log(L_INFO); | 335 | wlr_log_init(L_INFO, NULL); |
336 | } else { | 336 | } else { |
337 | init_log(L_ERROR); | 337 | wlr_log_init(L_ERROR, NULL); |
338 | } | 338 | } |
339 | 339 | ||
340 | if (optind < argc) { // Behave as IPC client | 340 | if (optind < argc) { // Behave as IPC client |
341 | if(optind != 1) { | 341 | if(optind != 1) { |
342 | sway_log(L_ERROR, "Don't use options with the IPC client"); | 342 | wlr_log(L_ERROR, "Don't use options with the IPC client"); |
343 | exit(EXIT_FAILURE); | 343 | exit(EXIT_FAILURE); |
344 | } | 344 | } |
345 | drop_permissions(false); | 345 | drop_permissions(false); |
346 | char *socket_path = getenv("SWAYSOCK"); | 346 | char *socket_path = getenv("SWAYSOCK"); |
347 | if (!socket_path) { | 347 | if (!socket_path) { |
348 | sway_log(L_ERROR, "Unable to retrieve socket path"); | 348 | wlr_log(L_ERROR, "Unable to retrieve socket path"); |
349 | exit(EXIT_FAILURE); | 349 | exit(EXIT_FAILURE); |
350 | } | 350 | } |
351 | char *command = join_args(argv + optind, argc - optind); | 351 | char *command = join_args(argv + optind, argc - optind); |
@@ -359,7 +359,7 @@ int main(int argc, char **argv) { | |||
359 | if (getuid() != geteuid() || getgid() != getegid()) { | 359 | if (getuid() != geteuid() || getgid() != getegid()) { |
360 | // Retain capabilities after setuid() | 360 | // Retain capabilities after setuid() |
361 | if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0)) { | 361 | if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0)) { |
362 | sway_log(L_ERROR, "Cannot keep caps after setuid()"); | 362 | wlr_log(L_ERROR, "Cannot keep caps after setuid()"); |
363 | exit(EXIT_FAILURE); | 363 | exit(EXIT_FAILURE); |
364 | } | 364 | } |
365 | suid = true; | 365 | suid = true; |
@@ -380,7 +380,7 @@ int main(int argc, char **argv) { | |||
380 | // prevent ipc from crashing sway | 380 | // prevent ipc from crashing sway |
381 | signal(SIGPIPE, SIG_IGN); | 381 | signal(SIGPIPE, SIG_IGN); |
382 | 382 | ||
383 | sway_log(L_INFO, "Starting sway version " SWAY_VERSION "\n"); | 383 | wlr_log(L_INFO, "Starting sway version " SWAY_VERSION "\n"); |
384 | 384 | ||
385 | init_layout(); | 385 | init_layout(); |
386 | 386 | ||
diff --git a/sway/server.c b/sway/server.c index 32c8f03c..365094ef 100644 --- a/sway/server.c +++ b/sway/server.c | |||
@@ -10,12 +10,12 @@ | |||
10 | #include <wlr/types/wlr_wl_shell.h> | 10 | #include <wlr/types/wlr_wl_shell.h> |
11 | // TODO WLR: make Xwayland optional | 11 | // TODO WLR: make Xwayland optional |
12 | #include <wlr/xwayland.h> | 12 | #include <wlr/xwayland.h> |
13 | #include <wlr/util/log.h> | ||
13 | #include "sway/server.h" | 14 | #include "sway/server.h" |
14 | #include "sway/input/input-manager.h" | 15 | #include "sway/input/input-manager.h" |
15 | #include "log.h" | ||
16 | 16 | ||
17 | bool server_init(struct sway_server *server) { | 17 | bool server_init(struct sway_server *server) { |
18 | sway_log(L_DEBUG, "Initializing Wayland server"); | 18 | wlr_log(L_DEBUG, "Initializing Wayland server"); |
19 | 19 | ||
20 | server->wl_display = wl_display_create(); | 20 | server->wl_display = wl_display_create(); |
21 | server->wl_event_loop = wl_display_get_event_loop(server->wl_display); | 21 | server->wl_event_loop = wl_display_get_event_loop(server->wl_display); |
@@ -55,7 +55,8 @@ bool server_init(struct sway_server *server) { | |||
55 | server->wl_shell_surface.notify = handle_wl_shell_surface; | 55 | server->wl_shell_surface.notify = handle_wl_shell_surface; |
56 | 56 | ||
57 | server->socket = wl_display_add_socket_auto(server->wl_display); | 57 | server->socket = wl_display_add_socket_auto(server->wl_display); |
58 | if (!sway_assert(server->socket, "Unable to open wayland socket")) { | 58 | if (!server->socket) { |
59 | wlr_log(L_ERROR, "Unable to open wayland socket"); | ||
59 | wlr_backend_destroy(server->backend); | 60 | wlr_backend_destroy(server->backend); |
60 | return false; | 61 | return false; |
61 | } | 62 | } |
@@ -71,11 +72,11 @@ void server_fini(struct sway_server *server) { | |||
71 | } | 72 | } |
72 | 73 | ||
73 | void server_run(struct sway_server *server) { | 74 | void server_run(struct sway_server *server) { |
74 | sway_log(L_INFO, "Running compositor on wayland display '%s'", | 75 | wlr_log(L_INFO, "Running compositor on wayland display '%s'", |
75 | server->socket); | 76 | server->socket); |
76 | setenv("_WAYLAND_DISPLAY", server->socket, true); | 77 | setenv("_WAYLAND_DISPLAY", server->socket, true); |
77 | if (!sway_assert(wlr_backend_start(server->backend), | 78 | if (!wlr_backend_start(server->backend)) { |
78 | "Failed to start backend")) { | 79 | wlr_log(L_ERROR, "Failed to start backend"); |
79 | wlr_backend_destroy(server->backend); | 80 | wlr_backend_destroy(server->backend); |
80 | return; | 81 | return; |
81 | } | 82 | } |