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 <donfrutosgomez@gmail.com>
This commit is contained in:
committed by
Álvaro Torralba
parent
1f57a1f998
commit
60855b1569
@@ -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
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user