ustcomm: move function to destroy app socket to ustcomm
authorPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Wed, 16 Sep 2009 04:52:38 +0000 (00:52 -0400)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Wed, 16 Sep 2009 04:52:38 +0000 (00:52 -0400)
libust/tracectl.c
libustcomm/ustcomm.c
libustcomm/ustcomm.h

index a52b208f34b369a6887a59f5ce95da94d48a85d4..47ca740781ebb0528c80d62c9e397702b8e415dc 100644 (file)
@@ -793,23 +793,6 @@ static int init_socket(void)
        return ustcomm_init_app(getpid(), &ustcomm_app);
 }
 
-/* FIXME: reenable this to delete socket file. */
-
-#if 0
-static void destroy_socket(void)
-{
-       int result;
-
-       if(mysocketfile[0] == '\0')
-               return;
-
-       result = unlink(mysocketfile);
-       if(result == -1) {
-               PERROR("unlink");
-       }
-}
-#endif
-
 static int init_signal_handler(void)
 {
        /* Attempt to handler SIGIO. If the main program wants to
index e773f7189fe313f78f0704f1ad907730a715aa38..3b53471ac6d69c81acd1379351d985b9b8ed177b 100644 (file)
@@ -23,6 +23,7 @@
 #include <sys/un.h>
 #include <unistd.h>
 #include <poll.h>
+#include <sys/stat.h>
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -378,8 +379,7 @@ static int init_named_socket(const char *name, char **path_out)
        }
 
        if(path_out) {
-               *path_out = "";
-               *path_out = strdupa(addr.sun_path);
+               *path_out = strdup(addr.sun_path);
        }
 
        return fd;
@@ -539,6 +539,32 @@ free_name:
        return retval;
 }
 
+void ustcomm_fini_app(struct ustcomm_app *handle)
+{
+       int result;
+       struct stat st;
+
+       /* Destroy socket */
+       ERR("socket path is: %s", handle->server.socketpath);
+       result = stat(handle->server.socketpath, &st);
+       if(result == -1) {
+               PERROR("stat (%s)", handle->server.socketpath);
+               return;
+       }
+
+       /* Paranoid check before deleting. */
+       result = S_ISSOCK(st.st_mode);
+       if(!result) {
+               ERR("The socket we are about to delete is not a socket.");
+               return;
+       }
+
+       result = unlink(handle->server.socketpath);
+       if(result == -1) {
+               PERROR("unlink");
+       }
+}
+
 static char *find_tok(char *str)
 {
        while(*str == ' ') {
index b7d8839928dd75f6f345f150e3182a15c8758075..7e1960fbc3ea0a4e0de19ac0a2fe5543a57fb15b 100644 (file)
@@ -63,6 +63,7 @@ extern int ustcomm_ustd_recv_message(struct ustcomm_ustd *ustd, char **msg, stru
 extern int ustcomm_app_recv_message(struct ustcomm_app *app, char **msg, struct ustcomm_source *src, int timeout);
 
 extern int ustcomm_init_app(pid_t pid, struct ustcomm_app *handle);
+extern void ustcomm_fini_app(struct ustcomm_app *handle);
 
 extern int ustcomm_init_ustd(struct ustcomm_ustd *handle, const char *sock_path);
 
This page took 0.026431 seconds and 4 git commands to generate.