test-bus-server.c revision 151b9b9662a90455262ce575a8a8ae74bf4ff336
/*-*- 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-internal.h"
#include "bus-message.h"
#include "bus-util.h"
struct context {
int fds[2];
bool client_anonymous_auth;
bool server_anonymous_auth;
};
static void *server(void *p) {
struct context *c = p;
bool quit = false;
int r;
while (!quit) {
r = sd_bus_process(bus, &m);
if (r < 0) {
goto fail;
}
if (r == 0) {
if (r < 0) {
goto fail;
}
continue;
}
if (!m)
continue;
assert_se((sd_bus_can_send(bus, 'h') >= 1) == (c->server_negotiate_unix_fds && c->client_negotiate_unix_fds));
r = sd_bus_message_new_method_return(m, &reply);
if (r < 0) {
goto fail;
}
quit = true;
m,
&reply,
if (r < 0) {
goto fail;
}
}
if (reply) {
if (r < 0) {
goto fail;
}
}
}
r = 0;
fail:
if (bus) {
}
return INT_TO_PTR(r);
}
int r;
bus,
&m,
"/",
"Exit");
if (r < 0) {
return r;
}
if (r < 0) {
return r;
}
return 0;
}
bool client_anonymous_auth, bool server_anonymous_auth) {
struct context c;
pthread_t s;
void *p;
int r, q;
zero(c);
if (r != 0)
return -r;
r = client(&c);
q = pthread_join(s, &p);
if (q != 0)
return -q;
if (r < 0)
return r;
if (PTR_TO_INT(p) < 0)
return PTR_TO_INT(p);
return 0;
}
int r;
r = test_one(true, true, false, false);
assert_se(r >= 0);
r = test_one(true, false, false, false);
assert_se(r >= 0);
r = test_one(false, true, false, false);
assert_se(r >= 0);
r = test_one(false, false, false, false);
assert_se(r >= 0);
r = test_one(true, true, true, true);
assert_se(r >= 0);
r = test_one(true, true, false, true);
assert_se(r >= 0);
r = test_one(true, true, true, false);
return EXIT_SUCCESS;
}