aboutsummaryrefslogtreecommitdiffstats
path: root/sway/main.c
diff options
context:
space:
mode:
authorLibravatar M Stoeckl <code@mstoeckl.com>2019-01-20 13:51:12 -0500
committerLibravatar emersion <contact@emersion.fr>2019-01-21 12:59:42 +0100
commit1211a81aad18bbc4d9e8fb9973238ad8e7e1f688 (patch)
tree5c3f60e0219cb8b4a1b7cafb760a871661866e32 /sway/main.c
parentLog libinput_config_status errors (diff)
downloadsway-1211a81aad18bbc4d9e8fb9973238ad8e7e1f688.tar.gz
sway-1211a81aad18bbc4d9e8fb9973238ad8e7e1f688.tar.zst
sway-1211a81aad18bbc4d9e8fb9973238ad8e7e1f688.zip
Replace wlr_log with sway_log
This commit mostly duplicates the wlr_log functions, although with a sway_* prefix. (This is very similar to PR #2009.) However, the logging function no longer needs to be replaceable, so sway_log_init's second argument is used to set the exit callback for sway_abort. wlr_log_init is still invoked in sway/main.c This commit makes it easier to remove the wlroots dependency for the helper programs swaymsg, swaybg, swaybar, and swaynag.
Diffstat (limited to 'sway/main.c')
-rw-r--r--sway/main.c39
1 files changed, 22 insertions, 17 deletions
diff --git a/sway/main.c b/sway/main.c
index 6e2f16db..4a92b25a 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -94,10 +94,10 @@ void detect_proprietary(int allow_unsupported_gpu) {
94 while (getline(&line, &line_size, f) != -1) { 94 while (getline(&line, &line_size, f) != -1) {
95 if (strstr(line, "nvidia")) { 95 if (strstr(line, "nvidia")) {
96 if (allow_unsupported_gpu) { 96 if (allow_unsupported_gpu) {
97 wlr_log(WLR_ERROR, 97 sway_log(SWAY_ERROR,
98 "!!! Proprietary Nvidia drivers are in use !!!"); 98 "!!! Proprietary Nvidia drivers are in use !!!");
99 } else { 99 } else {
100 wlr_log(WLR_ERROR, 100 sway_log(SWAY_ERROR,
101 "Proprietary Nvidia drivers are NOT supported. " 101 "Proprietary Nvidia drivers are NOT supported. "
102 "Use Nouveau. To launch sway anyway, launch with " 102 "Use Nouveau. To launch sway anyway, launch with "
103 "--my-next-gpu-wont-be-nvidia and DO NOT report issues."); 103 "--my-next-gpu-wont-be-nvidia and DO NOT report issues.");
@@ -107,10 +107,10 @@ void detect_proprietary(int allow_unsupported_gpu) {
107 } 107 }
108 if (strstr(line, "fglrx")) { 108 if (strstr(line, "fglrx")) {
109 if (allow_unsupported_gpu) { 109 if (allow_unsupported_gpu) {
110 wlr_log(WLR_ERROR, 110 sway_log(SWAY_ERROR,
111 "!!! Proprietary AMD drivers are in use !!!"); 111 "!!! Proprietary AMD drivers are in use !!!");
112 } else { 112 } else {
113 wlr_log(WLR_ERROR, "Proprietary AMD drivers do NOT support " 113 sway_log(SWAY_ERROR, "Proprietary AMD drivers do NOT support "
114 "Wayland. Use radeon. To try anyway, launch sway with " 114 "Wayland. Use radeon. To try anyway, launch sway with "
115 "--unsupported-gpu and DO NOT report issues."); 115 "--unsupported-gpu and DO NOT report issues.");
116 exit(EXIT_FAILURE); 116 exit(EXIT_FAILURE);
@@ -141,7 +141,7 @@ static void log_env(void) {
141 "SWAYSOCK" 141 "SWAYSOCK"
142 }; 142 };
143 for (size_t i = 0; i < sizeof(log_vars) / sizeof(char *); ++i) { 143 for (size_t i = 0; i < sizeof(log_vars) / sizeof(char *); ++i) {
144 wlr_log(WLR_INFO, "%s=%s", log_vars[i], getenv(log_vars[i])); 144 sway_log(SWAY_INFO, "%s=%s", log_vars[i], getenv(log_vars[i]));
145 } 145 }
146} 146}
147 147
@@ -153,7 +153,7 @@ static void log_file(FILE *f) {
153 if (line[nread - 1] == '\n') { 153 if (line[nread - 1] == '\n') {
154 line[nread - 1] = '\0'; 154 line[nread - 1] = '\0';
155 } 155 }
156 wlr_log(WLR_INFO, "%s", line); 156 sway_log(SWAY_INFO, "%s", line);
157 } 157 }
158 free(line); 158 free(line);
159} 159}
@@ -169,7 +169,7 @@ static void log_distro(void) {
169 for (size_t i = 0; i < sizeof(paths) / sizeof(char *); ++i) { 169 for (size_t i = 0; i < sizeof(paths) / sizeof(char *); ++i) {
170 FILE *f = fopen(paths[i], "r"); 170 FILE *f = fopen(paths[i], "r");
171 if (f) { 171 if (f) {
172 wlr_log(WLR_INFO, "Contents of %s:", paths[i]); 172 sway_log(SWAY_INFO, "Contents of %s:", paths[i]);
173 log_file(f); 173 log_file(f);
174 fclose(f); 174 fclose(f);
175 } 175 }
@@ -179,7 +179,7 @@ static void log_distro(void) {
179static void log_kernel(void) { 179static void log_kernel(void) {
180 FILE *f = popen("uname -a", "r"); 180 FILE *f = popen("uname -a", "r");
181 if (!f) { 181 if (!f) {
182 wlr_log(WLR_INFO, "Unable to determine kernel version"); 182 sway_log(SWAY_INFO, "Unable to determine kernel version");
183 return; 183 return;
184 } 184 }
185 log_file(f); 185 log_file(f);
@@ -190,16 +190,16 @@ static void log_kernel(void) {
190static bool drop_permissions(void) { 190static bool drop_permissions(void) {
191 if (getuid() != geteuid() || getgid() != getegid()) { 191 if (getuid() != geteuid() || getgid() != getegid()) {
192 if (setgid(getgid()) != 0) { 192 if (setgid(getgid()) != 0) {
193 wlr_log(WLR_ERROR, "Unable to drop root, refusing to start"); 193 sway_log(SWAY_ERROR, "Unable to drop root, refusing to start");
194 return false; 194 return false;
195 } 195 }
196 if (setuid(getuid()) != 0) { 196 if (setuid(getuid()) != 0) {
197 wlr_log(WLR_ERROR, "Unable to drop root, refusing to start"); 197 sway_log(SWAY_ERROR, "Unable to drop root, refusing to start");
198 return false; 198 return false;
199 } 199 }
200 } 200 }
201 if (setuid(0) != -1) { 201 if (setuid(0) != -1) {
202 wlr_log(WLR_ERROR, "Unable to drop root (we shouldn't be able to " 202 sway_log(SWAY_ERROR, "Unable to drop root (we shouldn't be able to "
203 "restore it after setuid), refusing to start"); 203 "restore it after setuid), refusing to start");
204 return false; 204 return false;
205 } 205 }
@@ -303,17 +303,22 @@ int main(int argc, char **argv) {
303 } 303 }
304 } 304 }
305 305
306 // As the 'callback' function for wlr_log is equivalent to that for
307 // sway, we do not need to override it.
306 if (debug) { 308 if (debug) {
309 sway_log_init(SWAY_DEBUG, sway_terminate);
307 wlr_log_init(WLR_DEBUG, NULL); 310 wlr_log_init(WLR_DEBUG, NULL);
308 } else if (verbose || validate) { 311 } else if (verbose || validate) {
312 sway_log_init(SWAY_INFO, sway_terminate);
309 wlr_log_init(WLR_INFO, NULL); 313 wlr_log_init(WLR_INFO, NULL);
310 } else { 314 } else {
315 sway_log_init(SWAY_ERROR, sway_terminate);
311 wlr_log_init(WLR_ERROR, NULL); 316 wlr_log_init(WLR_ERROR, NULL);
312 } 317 }
313 318
314 if (optind < argc) { // Behave as IPC client 319 if (optind < argc) { // Behave as IPC client
315 if (optind != 1) { 320 if (optind != 1) {
316 wlr_log(WLR_ERROR, "Don't use options with the IPC client"); 321 sway_log(SWAY_ERROR, "Don't use options with the IPC client");
317 exit(EXIT_FAILURE); 322 exit(EXIT_FAILURE);
318 } 323 }
319 if (!drop_permissions()) { 324 if (!drop_permissions()) {
@@ -321,7 +326,7 @@ int main(int argc, char **argv) {
321 } 326 }
322 char *socket_path = getenv("SWAYSOCK"); 327 char *socket_path = getenv("SWAYSOCK");
323 if (!socket_path) { 328 if (!socket_path) {
324 wlr_log(WLR_ERROR, "Unable to retrieve socket path"); 329 sway_log(SWAY_ERROR, "Unable to retrieve socket path");
325 exit(EXIT_FAILURE); 330 exit(EXIT_FAILURE);
326 } 331 }
327 char *command = join_args(argv + optind, argc - optind); 332 char *command = join_args(argv + optind, argc - optind);
@@ -349,7 +354,7 @@ int main(int argc, char **argv) {
349 // prevent ipc from crashing sway 354 // prevent ipc from crashing sway
350 signal(SIGPIPE, SIG_IGN); 355 signal(SIGPIPE, SIG_IGN);
351 356
352 wlr_log(WLR_INFO, "Starting sway version " SWAY_VERSION); 357 sway_log(SWAY_INFO, "Starting sway version " SWAY_VERSION);
353 358
354 root = root_create(); 359 root = root_create();
355 360
@@ -383,14 +388,14 @@ int main(int argc, char **argv) {
383 config->active = true; 388 config->active = true;
384 load_swaybars(); 389 load_swaybars();
385 // Execute commands until there are none left 390 // Execute commands until there are none left
386 wlr_log(WLR_DEBUG, "Running deferred commands"); 391 sway_log(SWAY_DEBUG, "Running deferred commands");
387 while (config->cmd_queue->length) { 392 while (config->cmd_queue->length) {
388 char *line = config->cmd_queue->items[0]; 393 char *line = config->cmd_queue->items[0];
389 list_t *res_list = execute_command(line, NULL, NULL); 394 list_t *res_list = execute_command(line, NULL, NULL);
390 for (int i = 0; i < res_list->length; ++i) { 395 for (int i = 0; i < res_list->length; ++i) {
391 struct cmd_results *res = res_list->items[i]; 396 struct cmd_results *res = res_list->items[i];
392 if (res->status != CMD_SUCCESS) { 397 if (res->status != CMD_SUCCESS) {
393 wlr_log(WLR_ERROR, "Error on line '%s': %s", line, res->error); 398 sway_log(SWAY_ERROR, "Error on line '%s': %s", line, res->error);
394 } 399 }
395 free_cmd_results(res); 400 free_cmd_results(res);
396 } 401 }
@@ -408,7 +413,7 @@ int main(int argc, char **argv) {
408 server_run(&server); 413 server_run(&server);
409 } 414 }
410 415
411 wlr_log(WLR_INFO, "Shutting down sway"); 416 sway_log(SWAY_INFO, "Shutting down sway");
412 417
413 server_fini(&server); 418 server_fini(&server);
414 root_destroy(root); 419 root_destroy(root);