-
Notifications
You must be signed in to change notification settings - Fork 1
/
dbus.c
32 lines (26 loc) · 856 Bytes
/
dbus.c
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
#include "util.h"
#include <stdio.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/un.h>
int dbus_create_socket(const char* dbus_socket_path) {
const int backlog = 50;
int sfd;
struct sockaddr_un my_addr;
sfd = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0);
if (sfd == -1)
handle_error("socket");
memset(&my_addr, 0, sizeof(my_addr));
/* Clear structure */
my_addr.sun_family = AF_UNIX;
strncpy(my_addr.sun_path, dbus_socket_path,
sizeof(my_addr.sun_path) - 1);
mode_t old_mode = umask(0000);
if (bind(sfd, (struct sockaddr *) &my_addr,
sizeof(my_addr)) == -1)
handle_error("bind");
umask(old_mode);
if (listen(sfd, backlog) == -1)
handle_error("listen");
return sfd;
}