stdio-bridge.c revision 264ad849a4a0acf1ca392da62b7018d4fe7b66b3
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <stddef.h>
#include "log.h"
#include "util.h"
#include "socket-util.h"
#include "sd-daemon.h"
#include "sd-bus.h"
#include "bus-internal.h"
#include "bus-message.h"
bool is_unix;
int r;
if (argc > 1) {
log_error("This program takes no argument.");
return EXIT_FAILURE;
}
log_open();
is_unix =
r = sd_bus_new(&a);
if (r < 0) {
goto finish;
}
r = sd_bus_set_address(a, "unix:path=/run/dbus/system_bus_socket");
if (r < 0) {
goto finish;
}
r = sd_bus_negotiate_fds(a, is_unix);
if (r < 0) {
goto finish;
}
r = sd_bus_start(a);
if (r < 0) {
goto finish;
}
r = sd_bus_get_server_id(a, &server_id);
if (r < 0) {
goto finish;
}
r = sd_bus_new(&b);
if (r < 0) {
goto finish;
}
if (r < 0) {
goto finish;
}
if (r < 0) {
goto finish;
}
r = sd_bus_negotiate_fds(b, is_unix);
if (r < 0) {
goto finish;
}
r = sd_bus_set_anonymous(b, true);
if (r < 0) {
goto finish;
}
r = sd_bus_start(b);
if (r < 0) {
goto finish;
}
for (;;) {
r = sd_bus_process(a, &m);
if (r < 0) {
goto finish;
}
if (m) {
r = sd_bus_send(b, m, NULL);
if (r < 0) {
goto finish;
}
}
if (r > 0)
continue;
r = sd_bus_process(b, &m);
if (r < 0) {
goto finish;
}
if (m) {
r = sd_bus_send(a, m, NULL);
if (r < 0) {
goto finish;
}
}
if (r > 0)
continue;
fd = sd_bus_get_fd(a);
if (fd < 0) {
goto finish;
}
events_a = sd_bus_get_events(a);
if (events_a < 0) {
goto finish;
}
r = sd_bus_get_timeout(a, &timeout_a);
if (r < 0) {
goto finish;
}
events_b = sd_bus_get_events(b);
if (events_b < 0) {
goto finish;
}
r = sd_bus_get_timeout(b, &timeout_b);
if (r < 0) {
goto finish;
}
t = timeout_a;
t = timeout_b;
if (t == (uint64_t) -1)
else {
if (t > nw)
t -= nw;
else
t = 0;
}
{
struct pollfd p[3] = {
}
if (r < 0) {
log_error("ppoll() failed: %m");
goto finish;
}
}
r = 0;
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}