command: add exec command

Add exec command and use it to start the session manager by default
This commit is contained in:
Wim Taymans 2018-10-02 09:17:07 +02:00
parent 575e177a48
commit eb765b26b3
2 changed files with 50 additions and 3 deletions

View file

@ -1,13 +1,12 @@
#load-module libpipewire-module-protocol-dbus #load-module libpipewire-module-protocol-dbus
#load-module libpipewire-module-rtkit load-module libpipewire-module-rtkit
load-module libpipewire-module-protocol-native load-module libpipewire-module-protocol-native
load-module libpipewire-module-suspend-on-idle
load-module libpipewire-module-spa-monitor alsa/libspa-alsa alsa-monitor alsa load-module libpipewire-module-spa-monitor alsa/libspa-alsa alsa-monitor alsa
load-module libpipewire-module-spa-monitor v4l2/libspa-v4l2 v4l2-monitor v4l2 load-module libpipewire-module-spa-monitor v4l2/libspa-v4l2 v4l2-monitor v4l2
load-module libpipewire-module-spa-monitor bluez5/libspa-bluez5 bluez5-monitor bluez5 load-module libpipewire-module-spa-monitor bluez5/libspa-bluez5 bluez5-monitor bluez5
#load-module libpipewire-module-spa-node videotestsrc/libspa-videotestsrc videotestsrc videotestsrc Spa:POD:Object:Props:patternType=Spa:POD:Object:Props:patternType:snow #load-module libpipewire-module-spa-node videotestsrc/libspa-videotestsrc videotestsrc videotestsrc Spa:POD:Object:Props:patternType=Spa:POD:Object:Props:patternType:snow
load-module libpipewire-module-client-node load-module libpipewire-module-client-node
load-module libpipewire-module-flatpak load-module libpipewire-module-flatpak
load-module libpipewire-module-media-session
load-module libpipewire-module-audio-dsp load-module libpipewire-module-audio-dsp
load-module libpipewire-module-link-factory load-module libpipewire-module-link-factory
exec build/src/examples/media-session

View file

@ -21,6 +21,8 @@
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h>
#include <limits.h>
#include <pipewire/pipewire.h> #include <pipewire/pipewire.h>
#include <pipewire/utils.h> #include <pipewire/utils.h>
@ -33,6 +35,7 @@
static struct pw_command *parse_command_help(const char *line, char **err); static struct pw_command *parse_command_help(const char *line, char **err);
static struct pw_command *parse_command_module_load(const char *line, char **err); static struct pw_command *parse_command_module_load(const char *line, char **err);
static struct pw_command *parse_command_exec(const char *line, char **err);
struct impl { struct impl {
struct pw_command this; struct pw_command this;
@ -49,6 +52,7 @@ struct command_parse {
static const struct command_parse parsers[] = { static const struct command_parse parsers[] = {
{"help", "Show this help", parse_command_help}, {"help", "Show this help", parse_command_help},
{"load-module", "Load a module", parse_command_module_load}, {"load-module", "Load a module", parse_command_module_load},
{"exec", "Execute a program", parse_command_exec},
{NULL, NULL, NULL } {NULL, NULL, NULL }
}; };
@ -127,6 +131,50 @@ static struct pw_command *parse_command_module_load(const char *line, char **err
return NULL; return NULL;
} }
static int
execute_command_exec(struct pw_command *command, struct pw_core *core, char **err)
{
int pid;
pid = fork();
if (pid == 0) {
pw_log_info("exec %s", command->args[1]);
execv(command->args[1], command->args);
}
else {
pw_log_info("exec got pid %d", pid);
}
return 0;
}
static struct pw_command *parse_command_exec(const char *line, char **err)
{
struct impl *impl;
struct pw_command *this;
impl = calloc(1, sizeof(struct impl));
if (impl == NULL)
goto no_mem;
this = &impl->this;
this->func = execute_command_exec;
this->args = pw_split_strv(line, whitespace, INT_MAX, &this->n_args);
if (this->n_args < 1)
goto no_executable;
return this;
no_executable:
asprintf(err, "requires an executable name");
pw_free_strv(this->args);
return NULL;
no_mem:
asprintf(err, "no memory");
return NULL;
}
/** Free command /** Free command
* *
* \param command a command to free * \param command a command to free