compositor: Add support for a command input.

This command is being executed in parallel with the westen instance,
just like the autolaunch config.

I recently came across the kiosk-shell and found out I could start a program exclusive
weston instance using it and that opened my eyes to new possibilities.

With the desktop-shell, it is necessary to set up quite a few options like the panel launchers,
the background image/color and a few other things and that indeed make the configuration file mandatory.

With the kiosk-shell all you really care about is the underlying program,
the vast majority of the configuration file options are not relevant for that shell.
That made me wonder how convenient it would be to forego the configuration file
and implement the autolaunch option directly in the weston program. That indeed worked pretty
well and that is why I decided to propose this merge request.

I think this avenue opens up a different set of uses cases for weston where rather than just have one
"big" desktop-shell instance, we could have multiple smaller and potentially specific usage instances.
Yes, it can be done with configuration files currently. But what it boils down to is convenience.
Maybe this convenience will enable other people to start more than just one weston instance
in the future. For instance, to quickly watch an image or opening up a pdf file.

This patch was made in a matter that is meant to be consistent with the intuitive
way other programs accept a command input, like so :

weston <some options> -- some_command option1 ... optionN

Further work would be necessary to remove the requirement for the '--'
option. To do that, we would need to check if the option is a valid command
and not just a mistyped option.

There may be some conflict with the current autolaunch implementation.
I'm not sure if both 'command' and 'autolaunch' could be used at the
same time using this implementation. I think it would be necessary to
have a distinct watch and pid variable in the 'wet' context variable
for the command to support this.

Signed-off-by: Nicholas Niro <blowfist@xroutine.net>
This commit is contained in:
Nicholas Niro 2023-10-21 16:18:16 -04:00 committed by Pekka Paalanen
parent 10a455f2ba
commit 288f552275

View file

@ -3917,6 +3917,37 @@ wet_xwayland_destroy(struct weston_compositor *comp, void *wet_xwl)
}
#endif
static int
execute_command(struct wet_compositor *wet, int argc, char **argv) {
/* alloca allocates in the stack rather than in the heap
* and we thus do not need to free this pointer.
*/
char **exec_args = alloca(sizeof(char*) * (argc + 1));
int i;
pid_t tmp_pid = -1;
wet->autolaunch_watch = true;
tmp_pid = fork();
if (tmp_pid == -1) {
weston_log("Failed to fork command line command process: %s\n", strerror(errno));
return -1;
} else if (tmp_pid == 0) {
for (i = 0; i < argc; i++)
exec_args[i] = argv[i + 1];
exec_args[i] = NULL;
cleanup_for_child_process();
execvp(exec_args[0], exec_args);
/* execvp shouldn't return */
fprintf(stderr, "Failed to execute command line command: %s\n", strerror(errno));
_exit(1);
}
wet->autolaunch_pid = tmp_pid;
return 0;
}
static int
execute_autolaunch(struct wet_compositor *wet, struct weston_config *config)
{
@ -4356,15 +4387,28 @@ wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_data)
}
}
for (i = 1; i < argc; i++)
weston_log("fatal: unhandled option: %s\n", argv[i]);
if (argc > 1)
goto out;
if (argc > 1 && strcmp(argv[1], "--") == 0) {
/* remove the '--' entry and move up the rest */
for (i = 1; i < argc; i++)
argv[i] = argv[i + 1];
argv[i] = NULL;
argc -= 1;
} else {
for (i = 1; i < argc; i++)
weston_log("fatal: unhandled option: %s\n", argv[i]);
if (argc > 1)
goto out;
}
weston_compositor_wake(wet.compositor);
if (execute_autolaunch(&wet, config) < 0)
goto out;
if (argc > 1) {
if (execute_command(&wet, argc, argv) < 0)
goto out;
} else {
if (execute_autolaunch(&wet, config) < 0)
goto out;
}
wl_display_run(display);