diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-06-23 16:26:20 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-06-23 16:26:20 +1000 |
commit | b11c9199a61775d7ed441c68238e11e93fbd6d21 (patch) | |
tree | 57c20e5ed9254c8025854175087033347aae768c | |
parent | Implement atomic layout updates for tree operations (diff) | |
parent | Merge pull request #2155 from ael-code/fix_output_command_failure (diff) | |
download | sway-b11c9199a61775d7ed441c68238e11e93fbd6d21.tar.gz sway-b11c9199a61775d7ed441c68238e11e93fbd6d21.tar.zst sway-b11c9199a61775d7ed441c68238e11e93fbd6d21.zip |
Merge remote-tracking branch 'upstream/master' into atomic
-rw-r--r-- | include/sway/server.h | 2 | ||||
-rw-r--r-- | sway/commands/output/background.c | 21 | ||||
-rw-r--r-- | sway/main.c | 5 | ||||
-rw-r--r-- | sway/server.c | 13 |
4 files changed, 31 insertions, 10 deletions
diff --git a/include/sway/server.h b/include/sway/server.h index f5f88a5a..b07e86a7 100644 --- a/include/sway/server.h +++ b/include/sway/server.h | |||
@@ -54,6 +54,8 @@ struct sway_server { | |||
54 | 54 | ||
55 | struct sway_server server; | 55 | struct sway_server server; |
56 | 56 | ||
57 | /* Prepares an unprivileged server_init by performing all privileged operations in advance */ | ||
58 | bool server_privileged_prepare(struct sway_server *server); | ||
57 | bool server_init(struct sway_server *server); | 59 | bool server_init(struct sway_server *server); |
58 | void server_fini(struct sway_server *server); | 60 | void server_fini(struct sway_server *server); |
59 | void server_run(struct sway_server *server); | 61 | void server_run(struct sway_server *server); |
diff --git a/sway/commands/output/background.c b/sway/commands/output/background.c index 0c5c164f..82bccf68 100644 --- a/sway/commands/output/background.c +++ b/sway/commands/output/background.c | |||
@@ -3,6 +3,7 @@ | |||
3 | #include <strings.h> | 3 | #include <strings.h> |
4 | #include <unistd.h> | 4 | #include <unistd.h> |
5 | #include <wordexp.h> | 5 | #include <wordexp.h> |
6 | #include <errno.h> | ||
6 | #include "sway/commands.h" | 7 | #include "sway/commands.h" |
7 | #include "sway/config.h" | 8 | #include "sway/config.h" |
8 | #include "log.h" | 9 | #include "log.h" |
@@ -71,21 +72,27 @@ struct cmd_results *output_cmd_background(int argc, char **argv) { | |||
71 | if (conf) { | 72 | if (conf) { |
72 | char *conf_path = dirname(conf); | 73 | char *conf_path = dirname(conf); |
73 | src = malloc(strlen(conf_path) + strlen(src) + 2); | 74 | src = malloc(strlen(conf_path) + strlen(src) + 2); |
74 | if (src) { | 75 | if (!src) { |
75 | sprintf(src, "%s/%s", conf_path, p.we_wordv[0]); | 76 | free(conf); |
76 | } else { | 77 | wordfree(&p); |
77 | wlr_log(L_ERROR, | 78 | wlr_log(L_ERROR, |
78 | "Unable to allocate background source"); | 79 | "Unable to allocate resource: Not enough memory"); |
80 | return cmd_results_new(CMD_FAILURE, "output", | ||
81 | "Unable to allocate resources"); | ||
79 | } | 82 | } |
83 | sprintf(src, "%s/%s", conf_path, p.we_wordv[0]); | ||
80 | free(conf); | 84 | free(conf); |
81 | } else { | 85 | } else { |
82 | wlr_log(L_ERROR, "Unable to allocate background source"); | 86 | wlr_log(L_ERROR, "Unable to allocate background source"); |
83 | } | 87 | } |
84 | } | 88 | } |
85 | if (!src || access(src, F_OK) == -1) { | 89 | |
90 | if (access(src, F_OK) == -1) { | ||
91 | struct cmd_results *cmd_res = cmd_results_new(CMD_FAILURE, "output", | ||
92 | "Unable to access background file '%s': %s", src, strerror(errno)); | ||
93 | free(src); | ||
86 | wordfree(&p); | 94 | wordfree(&p); |
87 | return cmd_results_new(CMD_INVALID, "output", | 95 | return cmd_res; |
88 | "Background file unreadable (%s).", src); | ||
89 | } | 96 | } |
90 | 97 | ||
91 | output->background = strdup(src); | 98 | output->background = strdup(src); |
diff --git a/sway/main.c b/sway/main.c index a83660d5..61ae6a5f 100644 --- a/sway/main.c +++ b/sway/main.c | |||
@@ -360,6 +360,11 @@ int main(int argc, char **argv) { | |||
360 | 360 | ||
361 | executable_sanity_check(); | 361 | executable_sanity_check(); |
362 | bool suid = false; | 362 | bool suid = false; |
363 | |||
364 | if (!server_privileged_prepare(&server)) { | ||
365 | return 1; | ||
366 | } | ||
367 | |||
363 | #ifdef __linux__ | 368 | #ifdef __linux__ |
364 | if (getuid() != geteuid() || getgid() != getegid()) { | 369 | if (getuid() != geteuid() || getgid() != getegid()) { |
365 | // Retain capabilities after setuid() | 370 | // Retain capabilities after setuid() |
diff --git a/sway/server.c b/sway/server.c index a13f2c3a..86d4a643 100644 --- a/sway/server.c +++ b/sway/server.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <wlr/types/wlr_idle.h> | 11 | #include <wlr/types/wlr_idle.h> |
12 | #include <wlr/types/wlr_layer_shell.h> | 12 | #include <wlr/types/wlr_layer_shell.h> |
13 | #include <wlr/types/wlr_linux_dmabuf.h> | 13 | #include <wlr/types/wlr_linux_dmabuf.h> |
14 | #include <wlr/types/wlr_export_dmabuf_v1.h> | ||
14 | #include <wlr/types/wlr_primary_selection.h> | 15 | #include <wlr/types/wlr_primary_selection.h> |
15 | #include <wlr/types/wlr_screenshooter.h> | 16 | #include <wlr/types/wlr_screenshooter.h> |
16 | #include <wlr/types/wlr_server_decoration.h> | 17 | #include <wlr/types/wlr_server_decoration.h> |
@@ -26,9 +27,8 @@ | |||
26 | #include "sway/tree/layout.h" | 27 | #include "sway/tree/layout.h" |
27 | 28 | ||
28 | 29 | ||
29 | bool server_init(struct sway_server *server) { | 30 | bool server_privileged_prepare(struct sway_server *server) { |
30 | wlr_log(L_DEBUG, "Initializing Wayland server"); | 31 | wlr_log(L_DEBUG, "Preparing Wayland server initialization"); |
31 | |||
32 | server->wl_display = wl_display_create(); | 32 | server->wl_display = wl_display_create(); |
33 | server->wl_event_loop = wl_display_get_event_loop(server->wl_display); | 33 | server->wl_event_loop = wl_display_get_event_loop(server->wl_display); |
34 | server->backend = wlr_backend_autocreate(server->wl_display, NULL); | 34 | server->backend = wlr_backend_autocreate(server->wl_display, NULL); |
@@ -37,6 +37,12 @@ bool server_init(struct sway_server *server) { | |||
37 | wlr_log(L_ERROR, "Unable to create backend"); | 37 | wlr_log(L_ERROR, "Unable to create backend"); |
38 | return false; | 38 | return false; |
39 | } | 39 | } |
40 | return true; | ||
41 | } | ||
42 | |||
43 | bool server_init(struct sway_server *server) { | ||
44 | wlr_log(L_DEBUG, "Initializing Wayland server"); | ||
45 | |||
40 | struct wlr_renderer *renderer = wlr_backend_get_renderer(server->backend); | 46 | struct wlr_renderer *renderer = wlr_backend_get_renderer(server->backend); |
41 | assert(renderer); | 47 | assert(renderer); |
42 | 48 | ||
@@ -98,6 +104,7 @@ bool server_init(struct sway_server *server) { | |||
98 | deco_manager, WLR_SERVER_DECORATION_MANAGER_MODE_SERVER); | 104 | deco_manager, WLR_SERVER_DECORATION_MANAGER_MODE_SERVER); |
99 | 105 | ||
100 | wlr_linux_dmabuf_create(server->wl_display, renderer); | 106 | wlr_linux_dmabuf_create(server->wl_display, renderer); |
107 | wlr_export_dmabuf_manager_v1_create(server->wl_display); | ||
101 | 108 | ||
102 | server->socket = wl_display_add_socket_auto(server->wl_display); | 109 | server->socket = wl_display_add_socket_auto(server->wl_display); |
103 | if (!server->socket) { | 110 | if (!server->socket) { |