015629481b8bbe5aadef0d35b02479b3cd310164
9 #include <sys/socket.h>
12 #define UNIX_PATH_MAX 108
13 #define SOCK_DIR "/tmp/socks"
14 #define UST_SIGNAL SIGIO
20 void parse_opts(int argc
, char **argv
)
28 while ((opt
= getopt(argc
, argv
, "nt:")) != -1) {
38 fprintf(stderr
, "Usage: %s [-t nsecs] [-n] name\n",
44 printf("flags=%d; tfnd=%d; optind=%d\n", flags
, tfnd
, optind
);
47 fprintf(stderr
, "Expected argument after options\n");
51 printf("name argument = %s\n", argv
[optind
]);
53 /* Other code omitted */
59 void signal_process(pid_t pid
)
63 result
= kill(pid
, UST_SIGNAL
);
72 int send_message(pid_t pid
, const char *msg
)
76 struct sockaddr_un addr
;
78 result
= fd
= socket(PF_UNIX
, SOCK_DGRAM
, 0);
84 addr
.sun_family
= AF_UNIX
;
86 result
= snprintf(addr
.sun_path
, UNIX_PATH_MAX
, "%s/%d", SOCK_DIR
, pid
);
87 if(result
>= UNIX_PATH_MAX
) {
88 fprintf(stderr
, "string overflow allocating socket name");
94 asprintf(&buf
, "%s\n", msg
);
98 result
= sendto(fd
, buf
, strlen(buf
), 0, (struct sockaddr
*)&addr
, sizeof(addr
));
106 // result = fd = open(sockfile, O_RDWR);
107 // if(result == -1 && errno == ENXIO) {
108 // fprintf(stderr, "signalling process\n");
110 // result = fd = open(sockfile, O_RDWR);
111 // if(result == -1) {
116 // else if(result == -1) {
123 int main(int argc
, char *argv
[])
125 pid_t pid
= atoi(argv
[1]);
129 send_message(pid
, msg
);
This page took 0.046133 seconds and 3 git commands to generate.