From f2c209c299889ad965ac995049704b1c46176c6d Mon Sep 17 00:00:00 2001 From: Nicolas Braud-Santoni Date: Tue, 1 May 2018 15:40:28 +0200 Subject: [PATCH 1/6] Install swaybar and swaybg under /usr/lib/sway --- swaybar/meson.build | 3 ++- swaybg/meson.build | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/swaybar/meson.build b/swaybar/meson.build index d65edb11e..f115ffa29 100644 --- a/swaybar/meson.build +++ b/swaybar/meson.build @@ -24,5 +24,6 @@ executable( wlroots, ], link_with: [lib_sway_common, lib_sway_client], - install: true + install: true, + install_dir: 'usr/lib/sway' ) diff --git a/swaybg/meson.build b/swaybg/meson.build index 8704de6d3..c1bb7d180 100644 --- a/swaybg/meson.build +++ b/swaybg/meson.build @@ -14,5 +14,6 @@ executable( wlroots, ], link_with: [lib_sway_common, lib_sway_client], - install: true + install: true, + install_dir: 'usr/lib/sway' ) From 7709340727fe2834f87b43aeeaef878694d5acd6 Mon Sep 17 00:00:00 2001 From: Nicolas Braud-Santoni Date: Tue, 1 May 2018 16:17:10 +0200 Subject: [PATCH 2/6] exec_always: Search for executables in /usr/lib/sway --- sway/commands/exec_always.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/sway/commands/exec_always.c b/sway/commands/exec_always.c index af4e4965a..af4bd7399 100644 --- a/sway/commands/exec_always.c +++ b/sway/commands/exec_always.c @@ -51,7 +51,41 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) { if ((pid = fork()) == 0) { // Fork child process again setsid(); + if ((*child = fork()) == 0) { + // Acquire the current PATH + char *path = getenv("PATH"); + const char *extra_path = ":/usr/lib/sway"; + const size_t extra_size = sizeof("/usr/lib/sway") + 1; + + if (!path) { + size_t n = confstr(_CS_PATH, NULL, 0); + path = malloc(n + extra_size); + if (!path) { + return cmd_results_new(CMD_FAILURE, "exec_always", "Unable to allocate PATH"); + } + confstr(_CS_PATH, path, n); + + } else { + size_t n = strlen(path) + 1; + char *tmp = malloc(n + extra_size); + if (!tmp) { + return cmd_results_new(CMD_FAILURE, "exec_always", "Unable to allocate PATH"); + } + + strncpy(tmp, path, n); + path = tmp; + } + + // Append /usr/lib/sway to PATH + strcat(path, extra_path); + if (!setenv("PATH", path, 1)) { + free(path); + return cmd_results_new(CMD_FAILURE, "exec_always", "Unable to set PATH"); + } + free(path); + + // Execute the command execl("/bin/sh", "/bin/sh", "-c", cmd, (void *)NULL); // Not reached } From 1670b46bf6e56d37e69ab0fa32c6799e83397020 Mon Sep 17 00:00:00 2001 From: Nicolas Braud-Santoni Date: Tue, 1 May 2018 16:49:15 +0200 Subject: [PATCH 3/6] Make the LIBDIR path configurable --- meson.build | 7 +++++++ meson_options.txt | 1 + sway/commands/exec_always.c | 4 ++-- swaybar/meson.build | 2 +- swaybg/meson.build | 2 +- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/meson.build b/meson.build index bf266e5f9..57dbea02e 100644 --- a/meson.build +++ b/meson.build @@ -19,6 +19,13 @@ is_freebsd = host_machine.system().startswith('freebsd') datadir = get_option('datadir') sysconfdir = get_option('sysconfdir') prefix = get_option('prefix') +instlibdir = get_option('instlibdir') + +if instlibdir == '' + instlibdir = join_paths(prefix, 'lib/sway') +endif +add_project_arguments('-DINSTLIBDIR="/@0@"'.format(instlibdir), language : 'c') + jsonc = dependency('json-c', version: '>=0.13') pcre = dependency('libpcre') diff --git a/meson_options.txt b/meson_options.txt index 541ccf138..6c3dcd584 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,3 +1,4 @@ +option('instlibdir', type: 'string', description: 'Installation path for sway-internal executables, such as swaybg or swaybar. (Default: prefix/lib/sway)') option('sway_version', type : 'string', description: 'The version string reported in `sway --version`.') option('default_wallpaper', type: 'boolean', value: true, description: 'Install the default wallpaper.') option('zsh_completions', type: 'boolean', value: true, description: 'Install zsh shell completions.') diff --git a/sway/commands/exec_always.c b/sway/commands/exec_always.c index af4bd7399..3f3a7940a 100644 --- a/sway/commands/exec_always.c +++ b/sway/commands/exec_always.c @@ -55,8 +55,8 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) { if ((*child = fork()) == 0) { // Acquire the current PATH char *path = getenv("PATH"); - const char *extra_path = ":/usr/lib/sway"; - const size_t extra_size = sizeof("/usr/lib/sway") + 1; + const char *extra_path = ":" INSTLIBDIR; + const size_t extra_size = sizeof(INSTLIBDIR) + 1; if (!path) { size_t n = confstr(_CS_PATH, NULL, 0); diff --git a/swaybar/meson.build b/swaybar/meson.build index f115ffa29..ad7ed5fe1 100644 --- a/swaybar/meson.build +++ b/swaybar/meson.build @@ -25,5 +25,5 @@ executable( ], link_with: [lib_sway_common, lib_sway_client], install: true, - install_dir: 'usr/lib/sway' + install_dir: instlibdir ) diff --git a/swaybg/meson.build b/swaybg/meson.build index c1bb7d180..e994da8fd 100644 --- a/swaybg/meson.build +++ b/swaybg/meson.build @@ -15,5 +15,5 @@ executable( ], link_with: [lib_sway_common, lib_sway_client], install: true, - install_dir: 'usr/lib/sway' + install_dir: instlibdir ) From 830c4ef74c00dbe448da46cdbc576178abc5728e Mon Sep 17 00:00:00 2001 From: Nicolas Braud-Santoni Date: Tue, 1 May 2018 20:47:55 +0200 Subject: [PATCH 4/6] Meson: Replace option `instlibdir` with `libexecdir` Derive a value from it, called `rundir` rather than writing join_paths(libexecdir, 'sway') all over the place. --- meson.build | 9 +++++---- meson_options.txt | 1 - sway/commands/exec_always.c | 4 ++-- swaybar/meson.build | 2 +- swaybg/meson.build | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/meson.build b/meson.build index 57dbea02e..bd20ca993 100644 --- a/meson.build +++ b/meson.build @@ -19,12 +19,13 @@ is_freebsd = host_machine.system().startswith('freebsd') datadir = get_option('datadir') sysconfdir = get_option('sysconfdir') prefix = get_option('prefix') -instlibdir = get_option('instlibdir') +libexecdir = get_option('libexecdir') -if instlibdir == '' - instlibdir = join_paths(prefix, 'lib/sway') +if libexecdir == '' + libexecdir = 'lib' endif -add_project_arguments('-DINSTLIBDIR="/@0@"'.format(instlibdir), language : 'c') +sway_libexecdir = join_paths(prefix, libexecdir, 'sway') +add_project_arguments('-DSWAY_LIBEXECDIR="/@0@"'.format(sway_libexecdir), language : 'c') jsonc = dependency('json-c', version: '>=0.13') diff --git a/meson_options.txt b/meson_options.txt index 6c3dcd584..541ccf138 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,4 +1,3 @@ -option('instlibdir', type: 'string', description: 'Installation path for sway-internal executables, such as swaybg or swaybar. (Default: prefix/lib/sway)') option('sway_version', type : 'string', description: 'The version string reported in `sway --version`.') option('default_wallpaper', type: 'boolean', value: true, description: 'Install the default wallpaper.') option('zsh_completions', type: 'boolean', value: true, description: 'Install zsh shell completions.') diff --git a/sway/commands/exec_always.c b/sway/commands/exec_always.c index 3f3a7940a..aaee940ba 100644 --- a/sway/commands/exec_always.c +++ b/sway/commands/exec_always.c @@ -55,8 +55,8 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) { if ((*child = fork()) == 0) { // Acquire the current PATH char *path = getenv("PATH"); - const char *extra_path = ":" INSTLIBDIR; - const size_t extra_size = sizeof(INSTLIBDIR) + 1; + const char *extra_path = ":" SWAY_LIBEXECDIR; + const size_t extra_size = sizeof(SWAY_LIBEXECDIR) + 1; if (!path) { size_t n = confstr(_CS_PATH, NULL, 0); diff --git a/swaybar/meson.build b/swaybar/meson.build index ad7ed5fe1..41c81a88c 100644 --- a/swaybar/meson.build +++ b/swaybar/meson.build @@ -25,5 +25,5 @@ executable( ], link_with: [lib_sway_common, lib_sway_client], install: true, - install_dir: instlibdir + install_dir: sway_libexecdir ) diff --git a/swaybg/meson.build b/swaybg/meson.build index e994da8fd..716178d2b 100644 --- a/swaybg/meson.build +++ b/swaybg/meson.build @@ -15,5 +15,5 @@ executable( ], link_with: [lib_sway_common, lib_sway_client], install: true, - install_dir: instlibdir + install_dir: sway_libexecdir ) From 177c67e6b89404d9d477b82c00c1353cd4696096 Mon Sep 17 00:00:00 2001 From: Nicolas Braud-Santoni Date: Wed, 2 May 2018 12:33:16 +0200 Subject: [PATCH 5/6] command/exec_always: Use wlr_log for logging errors in the child process --- sway/commands/exec_always.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sway/commands/exec_always.c b/sway/commands/exec_always.c index aaee940ba..b30786405 100644 --- a/sway/commands/exec_always.c +++ b/sway/commands/exec_always.c @@ -11,6 +11,7 @@ #include "log.h" #include "stringop.h" + struct cmd_results *cmd_exec_always(int argc, char **argv) { struct cmd_results *error = NULL; if (!config->active) return cmd_results_new(CMD_DEFER, NULL, NULL); @@ -62,7 +63,8 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) { size_t n = confstr(_CS_PATH, NULL, 0); path = malloc(n + extra_size); if (!path) { - return cmd_results_new(CMD_FAILURE, "exec_always", "Unable to allocate PATH"); + wlr_log(L_ERROR, "exec_always: Unable to allocate PATH"); + exit(EXIT_FAILURE); } confstr(_CS_PATH, path, n); @@ -70,7 +72,8 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) { size_t n = strlen(path) + 1; char *tmp = malloc(n + extra_size); if (!tmp) { - return cmd_results_new(CMD_FAILURE, "exec_always", "Unable to allocate PATH"); + wlr_log(L_ERROR, "exec_always: Unable to allocate PATH"); + exit(EXIT_FAILURE); } strncpy(tmp, path, n); @@ -81,7 +84,8 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) { strcat(path, extra_path); if (!setenv("PATH", path, 1)) { free(path); - return cmd_results_new(CMD_FAILURE, "exec_always", "Unable to set PATH"); + wlr_log(L_ERROR, "exec_always: Unable to set PATH"); + exit(EXIT_FAILURE); } free(path); From b4249166f309a46c15dd3a5734594aee961b723b Mon Sep 17 00:00:00 2001 From: Nicolas Braud-Santoni Date: Sat, 5 May 2018 17:05:27 +0200 Subject: [PATCH 6/6] security.d: Update install paths for swaybar and swaybg --- meson.build | 1 + security.d/00-defaults.in | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index bd20ca993..e40dc33c7 100644 --- a/meson.build +++ b/meson.build @@ -121,6 +121,7 @@ config = configuration_data() config.set('sysconfdir', join_paths(prefix, sysconfdir)) config.set('datadir', join_paths(prefix, datadir)) config.set('prefix', prefix) +config.set('sway_libexecdir', sway_libexecdir) configure_file( configuration: config, diff --git a/security.d/00-defaults.in b/security.d/00-defaults.in index e46264773..b5ae11492 100644 --- a/security.d/00-defaults.in +++ b/security.d/00-defaults.in @@ -11,9 +11,9 @@ # Configures enabled compositor features for specific programs permit * fullscreen keyboard mouse permit @prefix@/bin/swaylock lock -permit @prefix@/bin/swaybg background permit @prefix@/bin/swaygrab screenshot -permit @prefix@/bin/swaybar panel +permit @sway_libexecdir@/swaybg background +permit @sway_libexecdir@/swaybar panel # Configures enabled IPC features for specific programs ipc @prefix@/bin/swaymsg { @@ -24,7 +24,7 @@ ipc @prefix@/bin/swaymsg { } } -ipc @prefix@/bin/swaybar { +ipc @sway_libexecdir@/swaybar { bar-config enabled outputs enabled workspaces enabled