blob: 8bc2386190d9f34db1691a76f1a6204dd112a475 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stddef.h>
#include <unistd.h>
#include <stdint.h>
#include <errno.h>
#include <assert.h>
#include <poll.h>
#include <stdbool.h>
#include "kdbus-test.h"
#include "kdbus-util.h"
#include "kdbus-enum.h"
int kdbus_test_daemon(struct kdbus_test_env *env)
{
struct pollfd fds[2];
int count;
int ret;
/* This test doesn't make any sense in non-interactive mode */
if (!kdbus_util_verbose)
return TEST_OK;
printf("Created connection %llu on bus '%s'\n",
(unsigned long long) env->conn->id, env->buspath);
ret = kdbus_name_acquire(env->conn, "com.example.kdbus-test", NULL);
ASSERT_RETURN(ret == 0);
printf(" Aquired name: com.example.kdbus-test\n");
fds[0].fd = env->conn->fd;
fds[1].fd = STDIN_FILENO;
printf("Monitoring connections:\n");
for (count = 0;; count++) {
int i, nfds = sizeof(fds) / sizeof(fds[0]);
for (i = 0; i < nfds; i++) {
fds[i].events = POLLIN | POLLPRI | POLLHUP;
fds[i].revents = 0;
}
ret = poll(fds, nfds, -1);
if (ret <= 0)
break;
if (fds[0].revents & POLLIN) {
ret = kdbus_msg_recv(env->conn, NULL, NULL);
ASSERT_RETURN(ret == 0);
}
/* stdin */
if (fds[1].revents & POLLIN)
break;
}
printf("Closing bus connection\n");
return TEST_OK;
}
|