380df2f51a645fc1a8f56680322ff44c3455c6e7
5 #include <sys/socket.h>
16 #define UNIX_PATH_MAX 108
17 #define SOCK_DIR "/tmp/socks"
18 #define UST_SIGNAL SIGIO
22 static void signal_process(pid_t pid
)
26 result
= kill(pid
, UST_SIGNAL
);
35 /* pid: the pid of the trace process that must receive the msg
36 msg: pointer to a null-terminated message to send
37 reply: location where to put the null-terminated string of the reply;
38 it must be free'd after usage
41 int send_message(pid_t pid
, const char *msg
, char **reply
)
45 struct sockaddr_un addr
;
47 result
= fd
= socket(PF_UNIX
, SOCK_DGRAM
, 0);
53 addr
.sun_family
= AF_UNIX
;
55 result
= snprintf(addr
.sun_path
, UNIX_PATH_MAX
, "%s/%d", SOCK_DIR
, pid
);
56 if(result
>= UNIX_PATH_MAX
) {
57 fprintf(stderr
, "string overflow allocating socket name");
63 result
= sendto(fd
, msg
, strlen(msg
), 0, (struct sockaddr
*)&addr
, sizeof(addr
));
72 *reply
= (char *) malloc(MSG_MAX
+1);
73 result
= recvfrom(fd
, *reply
, MSG_MAX
, 0, NULL
, NULL
);
79 (*reply
)[result
] = '\0';
84 int ustcomm_app_recv_message(struct ustcomm_app
*app
, char **msg
)
88 struct sockaddr_un addr
;
90 *msg
= (char *) malloc(MSG_MAX
+1);
91 result
= recvfrom(app
->fd
, *msg
, MSG_MAX
, 0, NULL
, NULL
);
97 DBG("ustcomm_app_recv_message: result is %d, message[1] is %hhd", result
, (*msg
)[1]);
98 (*msg
)[result
] = '\0';
103 static int init_named_socket(char *name
, char **path_out
)
108 struct sockaddr_un addr
;
110 result
= fd
= socket(PF_UNIX
, SOCK_DGRAM
, 0);
116 addr
.sun_family
= AF_UNIX
;
118 strncpy(addr
.sun_path
, name
, UNIX_PATH_MAX
);
119 addr
.sun_path
[UNIX_PATH_MAX
-1] = '\0';
121 result
= bind(fd
, (struct sockaddr
*)&addr
, sizeof(addr
));
128 *path_out
= strdupa(addr
.sun_path
);
138 int ustcomm_init_app(pid_t pid
, struct ustcomm_app
*handle
)
143 result
= asprintf(&name
, "%s/%d", SOCK_DIR
, (int)pid
);
144 if(result
>= UNIX_PATH_MAX
) {
145 ERR("string overflow allocating socket name");
149 handle
->fd
= init_named_socket(name
, &handle
->socketpath
);
162 int ustcomm_init_ustd(struct ustcomm_ustd
*handle
)
164 handle
->fd
= init_named_socket("ustd", &handle
->socketpath
);
This page took 0.03618 seconds and 3 git commands to generate.