33
35
#include <pulsecore/log.h>
34
36
#include <pulsecore/modargs.h>
35
37
#include <pulsecore/macro.h>
38
#include <pulsecore/core-util.h>
39
#include <pulsecore/core-error.h>
37
41
#include "module-cli-symdef.h"
90
95
if (pa_stdio_acquire() < 0) {
91
pa_log("STDIN/STDUSE already in use.");
96
pa_log("STDIN/STDOUT already in use.");
95
io = pa_iochannel_new(m->core->mainloop, STDIN_FILENO, STDOUT_FILENO);
96
pa_iochannel_set_noclose(io, 1);
100
/* We try to open the controlling tty anew here. This has the
101
* benefit of giving us a new fd that doesn't share the O_NDELAY
102
* flag with fds 0, 1, or 2. Since pa_iochannel_xxx needs O_NDELAY
103
* on its fd using those fds directly could set O_NDELAY which
104
* fprintf() doesn't really like, resulting in truncated output
105
* of log messages, particularly because if stdout and stderr are
106
* dup'ed they share the same O_NDELAY, too. */
108
if ((fd = open("/dev/tty", O_RDWR|O_CLOEXEC|O_NONBLOCK)) >= 0) {
109
io = pa_iochannel_new(m->core->mainloop, fd, fd);
110
pa_log_debug("Managed to open /dev/tty.");
112
io = pa_iochannel_new(m->core->mainloop, STDIN_FILENO, STDOUT_FILENO);
113
pa_iochannel_set_noclose(io, TRUE);
114
pa_log_debug("Failed to open /dev/tty, using stdin/stdout fds instead.");
98
117
m->userdata = pa_cli_new(m->core, io, m);
100
118
pa_cli_set_eof_callback(m->userdata, exit_on_eof ? eof_and_exit_cb : eof_and_unload_cb, m);
102
120
pa_modargs_free(ma);