move functions that send messages to traced processes to libustcomm (which is linked...
authorPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Mon, 23 Feb 2009 20:14:42 +0000 (15:14 -0500)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Mon, 23 Feb 2009 20:14:42 +0000 (15:14 -0500)
libustcomm/ustcomm.c [new file with mode: 0644]
libustcomm/ustcomm.h [new file with mode: 0644]
ust/ust.c

diff --git a/libustcomm/ustcomm.c b/libustcomm/ustcomm.c
new file mode 100644 (file)
index 0000000..3843921
--- /dev/null
@@ -0,0 +1,63 @@
+#include <sys/types.h>
+#include <signal.h>
+#include <errno.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#define UNIX_PATH_MAX 108
+#define SOCK_DIR "/tmp/socks"
+#define UST_SIGNAL SIGIO
+
+static void signal_process(pid_t pid)
+{
+       int result;
+
+       result = kill(pid, UST_SIGNAL);
+       if(result == -1) {
+               perror("kill");
+               return;
+       }
+
+       sleep(1);
+}
+
+int send_message(pid_t pid, const char *msg, const char *reply)
+{
+       int fd;
+       int result;
+       struct sockaddr_un addr;
+       char *buf;
+
+       result = fd = socket(PF_UNIX, SOCK_DGRAM, 0);
+       if(result == -1) {
+               perror("socket");
+               return 1;
+       }
+
+       addr.sun_family = AF_UNIX;
+
+       result = snprintf(addr.sun_path, UNIX_PATH_MAX, "%s/%d", SOCK_DIR, pid);
+       if(result >= UNIX_PATH_MAX) {
+               fprintf(stderr, "string overflow allocating socket name");
+               return 1;
+       }
+
+       asprintf(&buf, "%s\n", msg);
+
+       signal_process(pid);
+
+       result = sendto(fd, buf, strlen(buf), 0, (struct sockaddr *)&addr, sizeof(addr));
+       if(result == -1) {
+               perror("sendto");
+               return 1;
+       }
+
+       free(buf);
+
+       return 0;
+}
+
+
diff --git a/libustcomm/ustcomm.h b/libustcomm/ustcomm.h
new file mode 100644 (file)
index 0000000..adbd0ae
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef USTCOMM_H
+#define USTCOMM_H
+
+#include <sys/types.h>
+
+int send_message(pid_t pid, const char *msg, const char *reply);
+
+#endif /* USTCOMM_H */
index 015629481b8bbe5aadef0d35b02479b3cd310164..766a2fa2c01e20d20c4b3acd8c921a1aa135db0e 100644 (file)
--- a/ust/ust.c
+++ b/ust/ust.c
@@ -3,19 +3,8 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <fcntl.h>
-#include <sys/types.h>
-#include <signal.h>
-#include <errno.h>
-#include <sys/socket.h>
-#include <sys/un.h>
 
-#define UNIX_PATH_MAX 108
-#define SOCK_DIR "/tmp/socks"
-#define UST_SIGNAL SIGIO
-
-struct ust_msg {
-       char *raw;
-};
+#include "ustcomm.h"
 
 void parse_opts(int argc, char **argv)
 {
@@ -56,77 +45,13 @@ void parse_opts(int argc, char **argv)
 
 }
 
-void signal_process(pid_t pid)
-{
-       int result;
-
-       result = kill(pid, UST_SIGNAL);
-       if(result == -1) {
-               perror("kill");
-               return;
-       }
-
-       sleep(1);
-}
-
-int send_message(pid_t pid, const char *msg)
-{
-       int fd;
-       int result;
-       struct sockaddr_un addr;
-
-       result = fd = socket(PF_UNIX, SOCK_DGRAM, 0);
-       if(result == -1) {
-               perror("socket");
-               return 1;
-       }
-
-       addr.sun_family = AF_UNIX;
-
-       result = snprintf(addr.sun_path, UNIX_PATH_MAX, "%s/%d", SOCK_DIR, pid);
-       if(result >= UNIX_PATH_MAX) {
-               fprintf(stderr, "string overflow allocating socket name");
-               return 1;
-       }
-
-       char *buf;
-
-       asprintf(&buf, "%s\n", msg);
-
-       signal_process(pid);
-
-       result = sendto(fd, buf, strlen(buf), 0, (struct sockaddr *)&addr, sizeof(addr));
-       if(result == -1) {
-               perror("sendto");
-               return 1;
-       }
-
-       free(buf);
-
-//     result = fd = open(sockfile, O_RDWR);
-//     if(result == -1 && errno == ENXIO) {
-//             fprintf(stderr, "signalling process\n");
-//
-//             result = fd = open(sockfile, O_RDWR);
-//             if(result == -1) {
-//                     perror("open");
-//                     return 1;
-//             }
-//     }
-//     else if(result == -1) {
-//             perror("open");
-//             return 1;
-//     }
-
-}
-
 int main(int argc, char *argv[])
 {
        pid_t pid = atoi(argv[1]);
 
        char *msg = argv[2];
 
-       send_message(pid, msg);
+       send_message(pid, msg, NULL);
 
        return 0;
 }
This page took 0.030657 seconds and 4 git commands to generate.