test-bus-chat.c revision 49e5de64e22ea4794092b91393545ab08e658e0a
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 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 <assert.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <fcntl.h>
#include "log.h"
#include "util.h"
#include "macro.h"
#include "sd-bus.h"
#include "bus-message.h"
#include "bus-error.h"
int r;
if (error != 0)
return 0;
if (r < 0) {
return r;
}
if (r < 0) {
return r;
}
return 1;
}
return 0;
}
int r;
const char *unique;
r = sd_bus_open_user(&bus);
if (r < 0) {
goto fail;
}
if (r < 0) {
goto fail;
}
if (r < 0) {
goto fail;
}
if (r < 0) {
goto fail;
}
if (r < 0) {
goto fail;
}
return 0;
fail:
if (bus)
return r;
}
int r;
bool client1_gone = false, client2_gone = false;
while (!client1_gone || !client2_gone) {
r = sd_bus_process(bus, &m);
if (r < 0) {
goto fail;
}
if (r == 0) {
if (r < 0) {
goto fail;
}
continue;
}
if (!m)
continue;
sd_bus_message_get_pid(m, &pid);
log_info("Got message! member=%s pid=%lu label=%s", strna(sd_bus_message_get_member(m)), (unsigned long) pid, strna(sd_bus_message_get_label(m)));
/* bus_message_dump(m); */
/* sd_bus_message_rewind(m, true); */
const char *hello;
if (r < 0) {
goto fail;
}
if (r < 0) {
goto fail;
}
if (!lowercase) {
r = log_oom();
goto fail;
}
if (r < 0) {
goto fail;
}
if (r < 0) {
goto fail;
}
client1_gone = true;
if (r < 0) {
goto fail;
}
client2_gone = true;
if (r < 0) {
goto fail;
}
sleep(1);
int fd;
static const char x = 'X';
if (r < 0) {
goto fail;
}
log_error("Failed to write to fd: %m");
goto fail;
}
if (r < 0) {
goto fail;
}
const sd_bus_error e = SD_BUS_ERROR_INIT_CONST("org.freedesktop.DBus.Error.UnknownMethod", "Unknown method.");
if (r < 0) {
goto fail;
}
}
if (reply) {
if (r < 0) {
goto fail;
}
/* log_info("Sent"); */
/* bus_message_dump(reply); */
/* sd_bus_message_rewind(reply, true); */
}
}
r = 0;
fail:
if (bus) {
}
return r;
}
static void* client1(void*p) {
const char *hello;
int r;
char x;
r = sd_bus_open_user(&bus);
if (r < 0) {
goto finish;
}
bus,
"/",
"LowerCase",
&m);
if (r < 0) {
goto finish;
}
if (r < 0) {
goto finish;
}
if (r < 0) {
goto finish;
}
if (r < 0) {
goto finish;
}
log_error("Failed to allocate pipe: %m");
r = -errno;
goto finish;
}
m = NULL;
bus,
"/",
"FileDescriptor",
&m);
if (r < 0) {
goto finish;
}
if (r < 0) {
goto finish;
}
if (r < 0) {
goto finish;
}
errno = 0;
goto finish;
}
r = 0;
if (bus) {
bus,
"/",
"ExitClient1",
&q);
if (r < 0) {
goto finish;
}
}
close_pipe(pp);
return INT_TO_PTR(r);
}
bool *x = userdata;
*x = 1;
return 1;
}
static void* client2(void*p) {
bool quit = false;
const char *mid;
int r;
r = sd_bus_open_user(&bus);
if (r < 0) {
goto finish;
}
bus,
"org.object.test",
"Foobar",
&m);
if (r < 0) {
goto finish;
}
if (r < 0) {
goto finish;
}
m = NULL;
bus,
"/",
"org.freedesktop.DBus.Peer",
"GetMachineId",
&m);
if (r < 0) {
goto finish;
}
if (r < 0) {
goto finish;
}
if (r < 0) {
goto finish;
}
m = NULL;
bus,
"/",
"Slow",
&m);
if (r < 0) {
goto finish;
}
if (r < 0)
else
log_info("Slow call succeed.");
m = NULL;
bus,
"/",
"Slow",
&m);
if (r < 0) {
goto finish;
}
if (r < 0) {
goto finish;
}
while (!quit) {
if (r < 0) {
goto finish;
}
if (r == 0) {
if (r < 0) {
goto finish;
}
}
}
r = 0;
if (bus) {
bus,
"/",
"ExitClient2",
&q);
if (r < 0) {
goto finish;
}
}
return INT_TO_PTR(r);
}
void *p;
int q, r;
r = server_init(&bus);
if (r < 0) {
log_info("Failed to connect to bus, skipping tests.");
return EXIT_TEST_SKIP;
}
log_info("Initialized...");
if (r != 0)
return EXIT_FAILURE;
if (r != 0)
return EXIT_FAILURE;
q = pthread_join(c1, &p);
if (q != 0)
return EXIT_FAILURE;
q = pthread_join(c2, &p);
if (q != 0)
return EXIT_FAILURE;
if (r < 0)
return EXIT_FAILURE;
return EXIT_SUCCESS;
}