-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfdholderctl.c
53 lines (44 loc) · 996 Bytes
/
fdholderctl.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
#include <libgen.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/un.h>
#include <sys/socket.h>
#include "config.h"
int main(int argc, char **argv)
{
const char socket_path[] = SOCKET_PATH;
struct sockaddr_un addr;
int s;
int ret = 1;
if (argc < 2)
{
fprintf(stderr, "Usage: %s <file>\n", basename(argv[0]));
return 1;
}
s = socket(AF_UNIX, SOCK_STREAM, 0);
if (s == -1)
{
perror("socket");
goto socket_failed;
}
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, socket_path, sizeof(socket_path)-1);
if (connect(s, (struct sockaddr *)&addr, sizeof(addr)) == -1)
{
perror("connect");
goto connect_failed;
}
if (write(s, argv[1], strlen(argv[1])+1) == -1)
{
perror("write");
goto write_failed;
}
ret = 0;
write_failed:
connect_failed:
close(s);
socket_failed:
return ret;
}