3 #include <sys/socket.h>
9 int main(int argc, char *argv[])
12 struct sockaddr_un sock_address;
17 err("No arguments given.\n");
19 char *sock_path = getenv(SOCKET_ENV_VAR);
20 if (sock_path != NULL && sizeof(sock_address.sun_path) <= strlen(sock_path))
21 err("The socket path can't fit into the socket address.\n");
23 sock_address.sun_family = AF_UNIX;
24 strncpy(sock_address.sun_path, (sock_path == NULL ? DEFAULT_SOCKET_PATH : sock_path), sizeof(sock_address.sun_path));
25 sock_address.sun_path[sizeof(sock_address.sun_path) - 1] = 0;
30 for (int offset = 0, rem = sizeof(msg), n = 0; argc > 0 && rem > 0; offset += n, rem -= n, argc--, argv++) {
31 n = snprintf(msg + offset, rem, "%s%c", *argv, 0);
35 if ((sock_fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
36 err("Failed to create the socket.\n");
38 if (connect(sock_fd, (struct sockaddr *) &sock_address, sizeof(sock_address)) == -1)
39 err("Failed to connect to the socket.\n");
41 if (send(sock_fd, msg, msg_len, 0) == -1)
42 err("Failed to send the data.\n");
44 int ret = EXIT_SUCCESS;
46 int n = recv(sock_fd, rsp, sizeof(rsp), 0);
48 err("Failed to get the response.\n");
50 if (n == 1 && rsp[0] == MESSAGE_FAILURE) {