ust: be able to list markers using ust
[ust.git] / ust / ust.c
CommitLineData
fbd8191b
PMF
1#include <unistd.h>
2#include <getopt.h>
3#include <stdlib.h>
4#include <stdio.h>
5#include <fcntl.h>
6#include <sys/types.h>
7#include <signal.h>
8#include <errno.h>
9#include <sys/socket.h>
10#include <sys/un.h>
11
12#define UNIX_PATH_MAX 108
13#define SOCK_DIR "/tmp/socks"
14#define UST_SIGNAL SIGIO
15
16struct ust_msg {
17 char *raw;
18};
19
20void parse_opts(int argc, char **argv)
21{
22 int flags, opt;
23 int nsecs, tfnd;
24
25 nsecs = 0;
26 tfnd = 0;
27 flags = 0;
28 while ((opt = getopt(argc, argv, "nt:")) != -1) {
29 switch (opt) {
30 case 'n':
31 flags = 1;
32 break;
33 case 't':
34 nsecs = atoi(optarg);
35 tfnd = 1;
36 break;
37 default: /* '?' */
38 fprintf(stderr, "Usage: %s [-t nsecs] [-n] name\n",
39 argv[0]);
40 exit(EXIT_FAILURE);
41 }
42 }
43
44 printf("flags=%d; tfnd=%d; optind=%d\n", flags, tfnd, optind);
45
46 if (optind >= argc) {
47 fprintf(stderr, "Expected argument after options\n");
48 exit(EXIT_FAILURE);
49 }
50
51 printf("name argument = %s\n", argv[optind]);
52
53 /* Other code omitted */
54
55 exit(EXIT_SUCCESS);
56
57}
58
59void signal_process(pid_t pid)
60{
61 int result;
62
63 result = kill(pid, UST_SIGNAL);
64 if(result == -1) {
65 perror("kill");
66 return;
67 }
68
69 sleep(1);
70}
71
72int send_message(pid_t pid, const char *msg)
73{
74 int fd;
75 int result;
76 struct sockaddr_un addr;
77
78 result = fd = socket(PF_UNIX, SOCK_DGRAM, 0);
79 if(result == -1) {
80 perror("socket");
81 return 1;
82 }
83
84 addr.sun_family = AF_UNIX;
85
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");
89 return 1;
90 }
91
92 char buf[] = "print_markers\n";
93
94 signal_process(pid);
95
96 result = sendto(fd, buf, sizeof(buf), 0, (struct sockaddr *)&addr, sizeof(addr));
97 if(result == -1) {
98 perror("sendto");
99 return 1;
100 }
101
102// result = fd = open(sockfile, O_RDWR);
103// if(result == -1 && errno == ENXIO) {
104// fprintf(stderr, "signalling process\n");
105//
106// result = fd = open(sockfile, O_RDWR);
107// if(result == -1) {
108// perror("open");
109// return 1;
110// }
111// }
112// else if(result == -1) {
113// perror("open");
114// return 1;
115// }
116
117}
118
119int main(int argc, char *argv[])
120{
121 pid_t pid = atoi(argv[1]);
122
123 char *msg = argv[2];
124
125 send_message(pid, msg);
126
127 return 0;
128}
This page took 0.026803 seconds and 4 git commands to generate.