From cc16948c8598e8b9aa98506dcdad66967dc28712 Mon Sep 17 00:00:00 2001 From: sghctoma Date: Thu, 30 Aug 2018 09:29:05 +0200 Subject: [PATCH 1/7] Fix feature macros for FreeBSD On FreeBSD, snprintf and vsnprintf are visible only if _XOPEN_SOURCE >= 600. --- client/pool-buffer.c | 2 +- sway/commands.c | 2 +- sway/commands/bar.c | 2 +- sway/commands/output/background.c | 2 +- sway/tree/workspace.c | 2 +- swaybar/ipc.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client/pool-buffer.c b/client/pool-buffer.c index fa468c0d6..6555a3ae8 100644 --- a/client/pool-buffer.c +++ b/client/pool-buffer.c @@ -1,4 +1,4 @@ -#define _XOPEN_SOURCE 500 +#define _XOPEN_SOURCE 600 #include #include #include diff --git a/sway/commands.c b/sway/commands.c index d9c54adc4..f321a8743 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -1,4 +1,4 @@ -#define _XOPEN_SOURCE 500 +#define _XOPEN_SOURCE 600 #include #include #include diff --git a/sway/commands/bar.c b/sway/commands/bar.c index f6a70c175..9d62dc837 100644 --- a/sway/commands/bar.c +++ b/sway/commands/bar.c @@ -1,4 +1,4 @@ -#define _XOPEN_SOURCE 500 +#define _XOPEN_SOURCE 600 #include #include #include diff --git a/sway/commands/output/background.c b/sway/commands/output/background.c index 748948120..900a5e753 100644 --- a/sway/commands/output/background.c +++ b/sway/commands/output/background.c @@ -1,4 +1,4 @@ -#define _XOPEN_SOURCE 500 +#define _XOPEN_SOURCE 600 #include #include #include diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 60256336f..e7c1e36b8 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -1,4 +1,4 @@ -#define _XOPEN_SOURCE 500 +#define _XOPEN_SOURCE 600 #include #include #include diff --git a/swaybar/ipc.c b/swaybar/ipc.c index c2d05920f..972869c6f 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c @@ -1,4 +1,4 @@ -#define _XOPEN_SOURCE 500 +#define _XOPEN_SOURCE 600 #include #include #include From 462e15d9a506f2265d4b20bfbc1c245be5f82a17 Mon Sep 17 00:00:00 2001 From: sghctoma Date: Thu, 30 Aug 2018 09:40:35 +0200 Subject: [PATCH 2/7] Make libcap an optional dependency FreeBSD does not have libcap, so without "required: false" Sway fails to build. --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index d5b33e6ba..61fcff420 100644 --- a/meson.build +++ b/meson.build @@ -38,7 +38,7 @@ pango = dependency('pango') pangocairo = dependency('pangocairo') gdk_pixbuf = dependency('gdk-pixbuf-2.0', required: false) pixman = dependency('pixman-1') -libcap = dependency('libcap') +libcap = dependency('libcap', required: false) libinput = dependency('libinput', version: '>=1.6.0') libpam = cc.find_library('pam') systemd = dependency('libsystemd', required: false) From 6942f5b6845b2cc572ec378365771a34caf50ba1 Mon Sep 17 00:00:00 2001 From: sghctoma Date: Thu, 30 Aug 2018 09:44:24 +0200 Subject: [PATCH 3/7] Fix SYSCONFDIR to include "prefix" SYSCONFDIR is used to determine the path of the default configuration file. 'sysconfdir' is set to 'prefix/sysconfdir' later (on line 139), so configuration files are installed under 'prefix', but SYSCONFDIR did not reflect it. --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 61fcff420..57b024c87 100644 --- a/meson.build +++ b/meson.build @@ -104,7 +104,7 @@ if scdoc.found() endforeach endif -add_project_arguments('-DSYSCONFDIR="/@0@"'.format(sysconfdir), language : 'c') +add_project_arguments('-DSYSCONFDIR="/@0@/@1@"'.format(prefix, sysconfdir), language : 'c') version = get_option('sway_version') if version != '' From 6de777a986e1b8d38e5030106f2abb937eca6232 Mon Sep 17 00:00:00 2001 From: sghctoma Date: Thu, 30 Aug 2018 09:58:57 +0200 Subject: [PATCH 4/7] Add FreeBSD-specific PAM configuration The "login" PAM configuration means somathing entirely different on FreeBSD than on Linux: if you try to authenticate as the calling user, it OKs the request without prompting for password. The "passwd" config implements the desired functionality, therefore it should be used by swaylock. --- swaylock/meson.build | 17 +++++++++++++---- swaylock/pam/swaylock.freebsd | 6 ++++++ swaylock/pam/{swaylock => swaylock.linux} | 0 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 swaylock/pam/swaylock.freebsd rename swaylock/pam/{swaylock => swaylock.linux} (100%) diff --git a/swaylock/meson.build b/swaylock/meson.build index 63f694b94..675b8c697 100644 --- a/swaylock/meson.build +++ b/swaylock/meson.build @@ -24,7 +24,16 @@ executable( install: true ) -install_data( - 'pam/swaylock', - install_dir: sysconfdir + '/pam.d/' -) +if is_freebsd + install_data( + 'pam/swaylock.freebsd', + install_dir: sysconfdir + '/pam.d/', + rename: 'swaylock' + ) +else + install_data( + 'pam/swaylock.linux', + install_dir: sysconfdir + '/pam.d/', + rename: 'swaylock' + ) +endif diff --git a/swaylock/pam/swaylock.freebsd b/swaylock/pam/swaylock.freebsd new file mode 100644 index 000000000..603fc1850 --- /dev/null +++ b/swaylock/pam/swaylock.freebsd @@ -0,0 +1,6 @@ +# +# PAM configuration file for the swaylock screen locker. By default, it includes +# the 'passwd' configuration file (see /etc/pam.d/passwd) +# + +auth include passwd diff --git a/swaylock/pam/swaylock b/swaylock/pam/swaylock.linux similarity index 100% rename from swaylock/pam/swaylock rename to swaylock/pam/swaylock.linux From ac7a0aa038fd40472823c4514a846996c7fd2857 Mon Sep 17 00:00:00 2001 From: sghctoma Date: Thu, 30 Aug 2018 10:05:04 +0200 Subject: [PATCH 5/7] Add missing destroy calls to server_fini Rootston calls "wlr_xwayland_destroy" and "wl_display_destroy_clients" on shutdown, but these were not called by Sway. Without them, Sway crashes on exit before the display destroy event handler could be called. This causes two problems: - The TTY is not reset, and it locks up after exiting Sway. - drmDropMaster is not called, and the implicit drop (that should occur when the DRM fd is closed) seems not to be working in some scenarios (e.g. if you have a tmux session running - maybe the fd is retained somehow by tmux?). In other words, it you exit Sway, you can't start it (or any other program that wants to be DRM master) again until you close all your tmux sessions. --- sway/server.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sway/server.c b/sway/server.c index 7fa6007ec..92ed5595e 100644 --- a/sway/server.c +++ b/sway/server.c @@ -142,6 +142,10 @@ bool server_init(struct sway_server *server) { void server_fini(struct sway_server *server) { // TODO: free sway-specific resources +#ifdef HAVE_XWAYLAND + wlr_xwayland_destroy(server->xwayland.wlr_xwayland); +#endif + wl_display_destroy_clients(server->wl_display); wl_display_destroy(server->wl_display); list_free(server->dirty_containers); list_free(server->transactions); From 67188b7cba2a985926647e049ed32c72b6ee98c8 Mon Sep 17 00:00:00 2001 From: sghctoma Date: Thu, 30 Aug 2018 10:33:48 +0200 Subject: [PATCH 6/7] Enable privilege dropping of FreeBSD Privilege dropping works on FreeBSD too, so only the caps parts need to be Linux-only. --- sway/main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sway/main.c b/sway/main.c index 7ed10c86c..2f05dc383 100644 --- a/sway/main.c +++ b/sway/main.c @@ -366,13 +366,15 @@ int main(int argc, char **argv) { return 1; } -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) if (getuid() != geteuid() || getgid() != getegid()) { +#ifdef __linux__ // Retain capabilities after setuid() if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0)) { wlr_log(WLR_ERROR, "Cannot keep caps after setuid()"); exit(EXIT_FAILURE); } +#endif suid = true; } #endif @@ -382,7 +384,7 @@ int main(int argc, char **argv) { detect_proprietary(); detect_raspi(); -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) drop_permissions(suid); #endif // handle SIGTERM signals From 073dcb3a8650ee45bb98701fccd6530d9dd1a3f4 Mon Sep 17 00:00:00 2001 From: sghctoma Date: Mon, 3 Sep 2018 09:08:49 +0200 Subject: [PATCH 7/7] Change _XOPEN_SOURCE defines to _POSIX_C_SOURCE --- client/pool-buffer.c | 2 +- sway/commands.c | 2 +- sway/commands/bar.c | 2 +- sway/commands/output/background.c | 2 +- sway/tree/workspace.c | 2 +- swaybar/ipc.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client/pool-buffer.c b/client/pool-buffer.c index 6555a3ae8..588bd06cf 100644 --- a/client/pool-buffer.c +++ b/client/pool-buffer.c @@ -1,4 +1,4 @@ -#define _XOPEN_SOURCE 600 +#define _POSIX_C_SOURCE 200809 #include #include #include diff --git a/sway/commands.c b/sway/commands.c index 9e0fda552..e72b89167 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -1,4 +1,4 @@ -#define _XOPEN_SOURCE 600 +#define _POSIX_C_SOURCE 200809 #include #include #include diff --git a/sway/commands/bar.c b/sway/commands/bar.c index 9d62dc837..f760888e4 100644 --- a/sway/commands/bar.c +++ b/sway/commands/bar.c @@ -1,4 +1,4 @@ -#define _XOPEN_SOURCE 600 +#define _POSIX_C_SOURCE 200809 #include #include #include diff --git a/sway/commands/output/background.c b/sway/commands/output/background.c index 900a5e753..ddad679df 100644 --- a/sway/commands/output/background.c +++ b/sway/commands/output/background.c @@ -1,4 +1,4 @@ -#define _XOPEN_SOURCE 600 +#define _POSIX_C_SOURCE 200809 #include #include #include diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index e7c1e36b8..1957d94fc 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -1,4 +1,4 @@ -#define _XOPEN_SOURCE 600 +#define _POSIX_C_SOURCE 200809 #include #include #include diff --git a/swaybar/ipc.c b/swaybar/ipc.c index 972869c6f..0e60c10c4 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c @@ -1,4 +1,4 @@ -#define _XOPEN_SOURCE 600 +#define _POSIX_C_SOURCE 200809 #include #include #include