From 60855b1569ef5b57de8ecc06b8507046dfb57ced Mon Sep 17 00:00:00 2001 From: Alvarito050506 Date: Thu, 24 Jun 2021 03:50:53 +0000 Subject: [PATCH] compositor: Added autolaunch support. The value of the `path` parameter is executed right before wl_display_run. The `watch` parameter is meant for things like tests using the headless backend and the kiosk shell. Fixes https://gitlab.freedesktop.org/wayland/weston/-/issues/171 Signed-off-by: Alvarito050506 --- compositor/main.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ man/weston.ini.man | 13 ++++++++++++ 2 files changed, 64 insertions(+) diff --git a/compositor/main.c b/compositor/main.c index 646fb3a6..88900789 100644 --- a/compositor/main.c +++ b/compositor/main.c @@ -123,6 +123,8 @@ struct wet_compositor { bool init_failed; struct wl_list layoutput_list; /**< wet_layoutput::compositor_link */ struct wl_list child_process_list; + pid_t autolaunch_pid; + bool autolaunch_watch; }; static FILE *weston_logfile = NULL; @@ -360,6 +362,13 @@ sigchld_handler(int signal_number, void *data) pid_t pid; while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { + if (wet->autolaunch_pid != -1 && wet->autolaunch_pid == pid) { + if (wet->autolaunch_watch) + wl_display_terminate(wet->compositor->wl_display); + wet->autolaunch_pid = -1; + continue; + } + wl_list_for_each(p, &wet->child_process_list, link) { if (p->pid == pid) break; @@ -3116,6 +3125,45 @@ wet_load_xwayland(struct weston_compositor *comp) } #endif +static int +execute_autolaunch(struct wet_compositor *wet, struct weston_config *config) +{ + int ret = -1; + pid_t tmp_pid = -1; + char *autolaunch_path = NULL; + struct weston_config_section *section = NULL; + + section = weston_config_get_section(config, "autolaunch", NULL, NULL); + weston_config_section_get_string(section, "path", &autolaunch_path, ""); + weston_config_section_get_bool(section, "watch", &wet->autolaunch_watch, false); + + if (!strlen(autolaunch_path)) + goto out_ok; + + if (access(autolaunch_path, X_OK) != 0) { + weston_log("Specified autolaunch path (%s) is not executable\n", autolaunch_path); + goto out; + } + + tmp_pid = fork(); + if (tmp_pid == -1) { + weston_log("Failed to fork autolaunch process: %s\n", strerror(errno)); + goto out; + } else if (tmp_pid == 0) { + execl(autolaunch_path, autolaunch_path, NULL); + /* execl shouldn't return */ + fprintf(stderr, "Failed to execute autolaunch: %s\n", strerror(errno)); + _exit(1); + } + +out_ok: + ret = 0; +out: + wet->autolaunch_pid = tmp_pid; + free(autolaunch_path); + return ret; +} + static void weston_log_setup_scopes(struct weston_log_context *log_ctx, struct weston_log_subscriber *subscriber, @@ -3449,6 +3497,9 @@ wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_data) weston_compositor_wake(wet.compositor); + if (execute_autolaunch(&wet, config) < 0) + goto out; + wl_display_run(display); /* Allow for setting return exit code after diff --git a/man/weston.ini.man b/man/weston.ini.man index 515995d8..9319e6c7 100644 --- a/man/weston.ini.man +++ b/man/weston.ini.man @@ -78,6 +78,7 @@ The section headers are: .BR "terminal " "Terminal application options" .BR "xwayland " "XWayland options" .BR "screen-share " "Screen sharing options" +.BR "autolaunch " "Autolaunch options" .fi .RE .PP @@ -661,6 +662,18 @@ sets the path to the xserver to run (string). sets the command to start a fullscreen-shell server for screen sharing (string). .RE .RE +.SH "AUTOLAUNCH SECTION" +.TP 7 +.BI "path=" "/usr/bin/echo" +Path to an executable file to run after startup. This file is executed in +parallel to Weston, so it does not have to immediately exit. Defaults to empty. +.RE +.TP 7 +.BI "watch=" "false" +If set to true, quit Weston after the auto-launched executable exits. Set to false +by default. +.RE +.RE .SH "SEE ALSO" .BR weston (1), .BR weston-bindings (7),