4 #include <sys/socket.h>
11 #include "socket-helper.h"
13 int create_logd_socket()
16 struct sockaddr_un saun;
17 int old_umask = umask(~(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP));
18 struct group *group_entry = NULL;
21 if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
23 _E("Failed to create socket");
27 saun.sun_family = AF_UNIX;
28 strcpy(saun.sun_path, LOGD_SOCKET_PATH);
29 unlink(LOGD_SOCKET_PATH);
31 len = sizeof(saun.sun_family) + sizeof(saun.sun_path);
32 if (bind(sock, (const struct sockaddr*)&saun, len) < 0) {
34 _E("Failed bind socket");
39 group_entry = getgrnam("app");
40 if (group_entry == NULL) {
42 _E("can't find app group id");
45 if (chown(LOGD_SOCKET_PATH, -1, group_entry->gr_gid) < 0) {
47 _E("can't change group");
51 if (listen(sock, 5) < 0) {
53 _E("Failed listen socket");
63 int connect_to_logd_socket()
65 struct sockaddr_un saun;
69 if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
71 _E("Failed to create socket");
74 saun.sun_family = AF_UNIX;
75 strcpy(saun.sun_path, LOGD_SOCKET_PATH);
77 len = sizeof(saun.sun_family) + sizeof(saun.sun_path);
78 if (connect(sock, (const struct sockaddr*)&saun, len) < 0) {
88 int read_from_socket(int sock, void *buf, int size)
94 ret = recv(sock, buf + i, size - i, 0);
97 } else if (errno != EAGAIN)