2004-07-16 19:56:36 +00:00
|
|
|
/***
|
2006-06-19 21:53:48 +00:00
|
|
|
This file is part of PulseAudio.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-02-13 15:35:19 +00:00
|
|
|
Copyright 2004-2006 Lennart Poettering
|
|
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is free software; you can redistribute it and/or modify
|
2004-11-14 14:58:54 +00:00
|
|
|
it under the terms of the GNU Lesser General Public License as published
|
2009-03-03 20:23:02 +00:00
|
|
|
by the Free Software Foundation; either version 2.1 of the License,
|
2004-07-16 19:56:36 +00:00
|
|
|
or (at your option) any later version.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is distributed in the hope that it will be useful, but
|
2004-07-16 19:56:36 +00:00
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
General Public License for more details.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-11-14 14:58:54 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2014-11-26 14:14:51 +01:00
|
|
|
along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
|
2004-07-16 19:56:36 +00:00
|
|
|
***/
|
|
|
|
|
|
2004-07-16 19:16:42 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-06-18 00:22:37 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <unistd.h>
|
2009-09-17 03:51:35 +02:00
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <errno.h>
|
2004-06-18 00:22:37 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulsecore/module.h>
|
|
|
|
|
#include <pulsecore/iochannel.h>
|
|
|
|
|
#include <pulsecore/cli.h>
|
|
|
|
|
#include <pulsecore/sioman.h>
|
|
|
|
|
#include <pulsecore/log.h>
|
|
|
|
|
#include <pulsecore/modargs.h>
|
2007-10-28 19:13:50 +00:00
|
|
|
#include <pulsecore/macro.h>
|
2009-09-17 03:51:35 +02:00
|
|
|
#include <pulsecore/core-util.h>
|
2006-02-16 19:19:58 +00:00
|
|
|
|
2007-11-09 18:25:40 +00:00
|
|
|
PA_MODULE_AUTHOR("Lennart Poettering");
|
|
|
|
|
PA_MODULE_DESCRIPTION("Command line interface");
|
|
|
|
|
PA_MODULE_VERSION(PACKAGE_VERSION);
|
2013-06-27 19:28:09 +02:00
|
|
|
PA_MODULE_LOAD_ONCE(true);
|
2007-11-09 18:25:40 +00:00
|
|
|
PA_MODULE_USAGE("exit_on_eof=<exit daemon after EOF?>");
|
2004-09-11 23:17:38 +00:00
|
|
|
|
2006-06-18 11:10:45 +00:00
|
|
|
static const char* const valid_modargs[] = {
|
|
|
|
|
"exit_on_eof",
|
|
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void eof_and_unload_cb(pa_cli*c, void *userdata) {
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_module *m = userdata;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(c);
|
|
|
|
|
pa_assert(m);
|
2004-07-04 17:40:15 +00:00
|
|
|
|
2013-06-27 19:28:09 +02:00
|
|
|
pa_module_unload_request(m, true);
|
2004-07-04 17:40:15 +00:00
|
|
|
}
|
2004-06-18 00:22:37 +00:00
|
|
|
|
2006-06-18 11:10:45 +00:00
|
|
|
static void eof_and_exit_cb(pa_cli*c, void *userdata) {
|
|
|
|
|
pa_module *m = userdata;
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(c);
|
|
|
|
|
pa_assert(m);
|
2006-06-18 11:10:45 +00:00
|
|
|
|
2013-06-27 19:28:09 +02:00
|
|
|
pa_core_exit(m->core, false, 0);
|
2006-06-18 11:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
int pa__init(pa_module*m) {
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_iochannel *io;
|
2006-06-18 11:10:45 +00:00
|
|
|
pa_modargs *ma;
|
2013-06-27 19:28:09 +02:00
|
|
|
bool exit_on_eof = false;
|
2011-06-23 22:21:03 +02:00
|
|
|
#ifndef OS_IS_WIN32
|
2009-09-17 03:51:35 +02:00
|
|
|
int fd;
|
2011-06-23 22:21:03 +02:00
|
|
|
#endif
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(m);
|
2004-06-18 00:22:37 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (m->core->running_as_daemon) {
|
2006-08-18 21:38:40 +00:00
|
|
|
pa_log_info("Running as daemon, refusing to load this module.");
|
2005-09-16 00:08:02 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-18 11:10:45 +00:00
|
|
|
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
|
2006-08-18 21:38:40 +00:00
|
|
|
pa_log("failed to parse module arguments.");
|
2006-06-18 11:10:45 +00:00
|
|
|
goto fail;
|
2004-07-11 22:20:08 +00:00
|
|
|
}
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-06-18 11:10:45 +00:00
|
|
|
if (pa_modargs_get_value_boolean(ma, "exit_on_eof", &exit_on_eof) < 0) {
|
2006-08-18 21:38:40 +00:00
|
|
|
pa_log("exit_on_eof= expects boolean argument.");
|
2006-06-18 11:10:45 +00:00
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-04 17:40:15 +00:00
|
|
|
if (pa_stdio_acquire() < 0) {
|
2009-09-17 04:04:54 +02:00
|
|
|
pa_log("STDIN/STDOUT already in use.");
|
2006-06-18 11:10:45 +00:00
|
|
|
goto fail;
|
2004-06-18 00:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
2009-09-17 03:51:35 +02:00
|
|
|
/* We try to open the controlling tty anew here. This has the
|
|
|
|
|
* benefit of giving us a new fd that doesn't share the O_NDELAY
|
|
|
|
|
* flag with fds 0, 1, or 2. Since pa_iochannel_xxx needs O_NDELAY
|
|
|
|
|
* on its fd using those fds directly could set O_NDELAY which
|
|
|
|
|
* fprintf() doesn't really like, resulting in truncated output
|
|
|
|
|
* of log messages, particularly because if stdout and stderr are
|
|
|
|
|
* dup'ed they share the same O_NDELAY, too. */
|
|
|
|
|
|
2011-01-06 00:51:33 +01:00
|
|
|
#ifndef OS_IS_WIN32
|
2009-10-30 04:54:19 +01:00
|
|
|
if ((fd = pa_open_cloexec("/dev/tty", O_RDWR|O_NONBLOCK, 0)) >= 0) {
|
2009-09-17 03:51:35 +02:00
|
|
|
io = pa_iochannel_new(m->core->mainloop, fd, fd);
|
|
|
|
|
pa_log_debug("Managed to open /dev/tty.");
|
2011-01-06 00:51:33 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
#endif
|
|
|
|
|
{
|
2009-09-17 03:51:35 +02:00
|
|
|
io = pa_iochannel_new(m->core->mainloop, STDIN_FILENO, STDOUT_FILENO);
|
2013-06-27 19:28:09 +02:00
|
|
|
pa_iochannel_set_noclose(io, true);
|
2009-09-17 03:51:35 +02:00
|
|
|
pa_log_debug("Failed to open /dev/tty, using stdin/stdout fds instead.");
|
|
|
|
|
}
|
2004-06-18 00:22:37 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
m->userdata = pa_cli_new(m->core, io, m);
|
2006-06-18 11:10:45 +00:00
|
|
|
pa_cli_set_eof_callback(m->userdata, exit_on_eof ? eof_and_exit_cb : eof_and_unload_cb, m);
|
|
|
|
|
|
|
|
|
|
pa_modargs_free(ma);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-06-18 00:22:37 +00:00
|
|
|
return 0;
|
2006-06-18 11:10:45 +00:00
|
|
|
|
|
|
|
|
fail:
|
|
|
|
|
|
|
|
|
|
if (ma)
|
|
|
|
|
pa_modargs_free(ma);
|
|
|
|
|
|
|
|
|
|
return -1;
|
2004-06-18 00:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
void pa__done(pa_module*m) {
|
|
|
|
|
pa_assert(m);
|
2004-06-18 00:22:37 +00:00
|
|
|
|
2009-09-17 04:04:54 +02:00
|
|
|
if (m->userdata) {
|
2005-09-16 00:08:02 +00:00
|
|
|
pa_cli_free(m->userdata);
|
|
|
|
|
pa_stdio_release();
|
|
|
|
|
}
|
2004-06-18 00:22:37 +00:00
|
|
|
}
|