diff options
Diffstat (limited to 'sway/main.c')
-rw-r--r-- | sway/main.c | 104 |
1 files changed, 22 insertions, 82 deletions
diff --git a/sway/main.c b/sway/main.c index a0033c45..1c4939aa 100644 --- a/sway/main.c +++ b/sway/main.c | |||
@@ -1,4 +1,3 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
2 | #include <getopt.h> | 1 | #include <getopt.h> |
3 | #include <pango/pangocairo.h> | 2 | #include <pango/pangocairo.h> |
4 | #include <signal.h> | 3 | #include <signal.h> |
@@ -49,44 +48,6 @@ void sig_handler(int signal) { | |||
49 | sway_terminate(EXIT_SUCCESS); | 48 | sway_terminate(EXIT_SUCCESS); |
50 | } | 49 | } |
51 | 50 | ||
52 | void detect_proprietary(int allow_unsupported_gpu) { | ||
53 | FILE *f = fopen("/proc/modules", "r"); | ||
54 | if (!f) { | ||
55 | return; | ||
56 | } | ||
57 | char *line = NULL; | ||
58 | size_t line_size = 0; | ||
59 | while (getline(&line, &line_size, f) != -1) { | ||
60 | if (strncmp(line, "nvidia ", 7) == 0) { | ||
61 | if (allow_unsupported_gpu) { | ||
62 | sway_log(SWAY_ERROR, | ||
63 | "!!! Proprietary Nvidia drivers are in use !!!"); | ||
64 | } else { | ||
65 | sway_log(SWAY_ERROR, | ||
66 | "Proprietary Nvidia drivers are NOT supported. " | ||
67 | "Use Nouveau. To launch sway anyway, launch with " | ||
68 | "--unsupported-gpu and DO NOT report issues."); | ||
69 | exit(EXIT_FAILURE); | ||
70 | } | ||
71 | break; | ||
72 | } | ||
73 | if (strstr(line, "fglrx")) { | ||
74 | if (allow_unsupported_gpu) { | ||
75 | sway_log(SWAY_ERROR, | ||
76 | "!!! Proprietary AMD drivers are in use !!!"); | ||
77 | } else { | ||
78 | sway_log(SWAY_ERROR, "Proprietary AMD drivers do NOT support " | ||
79 | "Wayland. Use radeon. To try anyway, launch sway with " | ||
80 | "--unsupported-gpu and DO NOT report issues."); | ||
81 | exit(EXIT_FAILURE); | ||
82 | } | ||
83 | break; | ||
84 | } | ||
85 | } | ||
86 | free(line); | ||
87 | fclose(f); | ||
88 | } | ||
89 | |||
90 | void run_as_ipc_client(char *command, char *socket_path) { | 51 | void run_as_ipc_client(char *command, char *socket_path) { |
91 | int socketfd = ipc_open_socket(socket_path); | 52 | int socketfd = ipc_open_socket(socket_path); |
92 | uint32_t len = strlen(command); | 53 | uint32_t len = strlen(command); |
@@ -150,27 +111,17 @@ static void log_kernel(void) { | |||
150 | pclose(f); | 111 | pclose(f); |
151 | } | 112 | } |
152 | 113 | ||
153 | 114 | static bool detect_suid(void) { | |
154 | static bool drop_permissions(void) { | 115 | if (geteuid() != 0 && getegid() != 0) { |
155 | if (getuid() != geteuid() || getgid() != getegid()) { | 116 | return false; |
156 | sway_log(SWAY_ERROR, "!!! DEPRECATION WARNING: " | ||
157 | "SUID privilege drop will be removed in a future release, please migrate to seatd-launch"); | ||
158 | |||
159 | // Set the gid and uid in the correct order. | ||
160 | if (setgid(getgid()) != 0) { | ||
161 | sway_log(SWAY_ERROR, "Unable to drop root group, refusing to start"); | ||
162 | return false; | ||
163 | } | ||
164 | if (setuid(getuid()) != 0) { | ||
165 | sway_log(SWAY_ERROR, "Unable to drop root user, refusing to start"); | ||
166 | return false; | ||
167 | } | ||
168 | } | 117 | } |
169 | if (setgid(0) != -1 || setuid(0) != -1) { | 118 | |
170 | sway_log(SWAY_ERROR, "Unable to drop root (we shouldn't be able to " | 119 | if (getuid() == geteuid() && getgid() == getegid()) { |
171 | "restore it after setuid), refusing to start"); | ||
172 | return false; | 120 | return false; |
173 | } | 121 | } |
122 | |||
123 | sway_log(SWAY_ERROR, "SUID operation is no longer supported, refusing to start. " | ||
124 | "This check will be removed in a future release."); | ||
174 | return true; | 125 | return true; |
175 | } | 126 | } |
176 | 127 | ||
@@ -202,11 +153,7 @@ void restore_nofile_limit(void) { | |||
202 | } | 153 | } |
203 | 154 | ||
204 | void enable_debug_flag(const char *flag) { | 155 | void enable_debug_flag(const char *flag) { |
205 | if (strcmp(flag, "damage=highlight") == 0) { | 156 | if (strcmp(flag, "noatomic") == 0) { |
206 | debug.damage = DAMAGE_HIGHLIGHT; | ||
207 | } else if (strcmp(flag, "damage=rerender") == 0) { | ||
208 | debug.damage = DAMAGE_RERENDER; | ||
209 | } else if (strcmp(flag, "noatomic") == 0) { | ||
210 | debug.noatomic = true; | 157 | debug.noatomic = true; |
211 | } else if (strcmp(flag, "txn-wait") == 0) { | 158 | } else if (strcmp(flag, "txn-wait") == 0) { |
212 | debug.txn_wait = true; | 159 | debug.txn_wait = true; |
@@ -214,8 +161,8 @@ void enable_debug_flag(const char *flag) { | |||
214 | debug.txn_timings = true; | 161 | debug.txn_timings = true; |
215 | } else if (strncmp(flag, "txn-timeout=", 12) == 0) { | 162 | } else if (strncmp(flag, "txn-timeout=", 12) == 0) { |
216 | server.txn_timeout_ms = atoi(&flag[12]); | 163 | server.txn_timeout_ms = atoi(&flag[12]); |
217 | } else if (strcmp(flag, "noscanout") == 0) { | 164 | } else if (strcmp(flag, "legacy-wl-drm") == 0) { |
218 | debug.noscanout = true; | 165 | debug.legacy_wl_drm = true; |
219 | } else { | 166 | } else { |
220 | sway_log(SWAY_ERROR, "Unknown debug flag: %s", flag); | 167 | sway_log(SWAY_ERROR, "Unknown debug flag: %s", flag); |
221 | } | 168 | } |
@@ -265,7 +212,7 @@ static const char usage[] = | |||
265 | "\n"; | 212 | "\n"; |
266 | 213 | ||
267 | int main(int argc, char **argv) { | 214 | int main(int argc, char **argv) { |
268 | static bool verbose = false, debug = false, validate = false, allow_unsupported_gpu = false; | 215 | static bool verbose = false, debug = false, validate = false; |
269 | 216 | ||
270 | char *config_path = NULL; | 217 | char *config_path = NULL; |
271 | 218 | ||
@@ -304,7 +251,7 @@ int main(int argc, char **argv) { | |||
304 | case 'V': // verbose | 251 | case 'V': // verbose |
305 | verbose = true; | 252 | verbose = true; |
306 | break; | 253 | break; |
307 | case 'p': ; // --get-socketpath | 254 | case 'p': // --get-socketpath |
308 | if (getenv("SWAYSOCK")) { | 255 | if (getenv("SWAYSOCK")) { |
309 | printf("%s\n", getenv("SWAYSOCK")); | 256 | printf("%s\n", getenv("SWAYSOCK")); |
310 | exit(EXIT_SUCCESS); | 257 | exit(EXIT_SUCCESS); |
@@ -319,6 +266,11 @@ int main(int argc, char **argv) { | |||
319 | } | 266 | } |
320 | } | 267 | } |
321 | 268 | ||
269 | // SUID operation is deprecated, so block it for now. | ||
270 | if (detect_suid()) { | ||
271 | exit(EXIT_FAILURE); | ||
272 | } | ||
273 | |||
322 | // Since wayland requires XDG_RUNTIME_DIR to be set, abort with just the | 274 | // Since wayland requires XDG_RUNTIME_DIR to be set, abort with just the |
323 | // clear error message (when not running as an IPC client). | 275 | // clear error message (when not running as an IPC client). |
324 | if (!getenv("XDG_RUNTIME_DIR") && optind == argc) { | 276 | if (!getenv("XDG_RUNTIME_DIR") && optind == argc) { |
@@ -357,9 +309,6 @@ int main(int argc, char **argv) { | |||
357 | "`sway -d 2>sway.log`."); | 309 | "`sway -d 2>sway.log`."); |
358 | exit(EXIT_FAILURE); | 310 | exit(EXIT_FAILURE); |
359 | } | 311 | } |
360 | if (!drop_permissions()) { | ||
361 | exit(EXIT_FAILURE); | ||
362 | } | ||
363 | char *socket_path = getenv("SWAYSOCK"); | 312 | char *socket_path = getenv("SWAYSOCK"); |
364 | if (!socket_path) { | 313 | if (!socket_path) { |
365 | sway_log(SWAY_ERROR, "Unable to retrieve socket path"); | 314 | sway_log(SWAY_ERROR, "Unable to retrieve socket path"); |
@@ -371,17 +320,6 @@ int main(int argc, char **argv) { | |||
371 | return 0; | 320 | return 0; |
372 | } | 321 | } |
373 | 322 | ||
374 | detect_proprietary(allow_unsupported_gpu); | ||
375 | |||
376 | if (!server_privileged_prepare(&server)) { | ||
377 | return 1; | ||
378 | } | ||
379 | |||
380 | if (!drop_permissions()) { | ||
381 | server_fini(&server); | ||
382 | exit(EXIT_FAILURE); | ||
383 | } | ||
384 | |||
385 | increase_nofile_limit(); | 323 | increase_nofile_limit(); |
386 | 324 | ||
387 | // handle SIGTERM signals | 325 | // handle SIGTERM signals |
@@ -393,12 +331,14 @@ int main(int argc, char **argv) { | |||
393 | 331 | ||
394 | sway_log(SWAY_INFO, "Starting sway version " SWAY_VERSION); | 332 | sway_log(SWAY_INFO, "Starting sway version " SWAY_VERSION); |
395 | 333 | ||
396 | root = root_create(); | ||
397 | |||
398 | if (!server_init(&server)) { | 334 | if (!server_init(&server)) { |
399 | return 1; | 335 | return 1; |
400 | } | 336 | } |
401 | 337 | ||
338 | if (server.linux_dmabuf_v1) { | ||
339 | wlr_scene_set_linux_dmabuf_v1(root->root_scene, server.linux_dmabuf_v1); | ||
340 | } | ||
341 | |||
402 | if (validate) { | 342 | if (validate) { |
403 | bool valid = load_main_config(config_path, false, true); | 343 | bool valid = load_main_config(config_path, false, true); |
404 | free(config_path); | 344 | free(config_path); |