From: Pierre-Marc Fournier Date: Wed, 16 Sep 2009 04:52:38 +0000 (-0400) Subject: ustcomm: move function to destroy app socket to ustcomm X-Git-Tag: v1.9.1~911 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=803a4f584bbc64ff44173ced627636f9e6db6618;p=lttng-ust.git ustcomm: move function to destroy app socket to ustcomm --- diff --git a/libust/tracectl.c b/libust/tracectl.c index a52b208f..47ca7407 100644 --- a/libust/tracectl.c +++ b/libust/tracectl.c @@ -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 diff --git a/libustcomm/ustcomm.c b/libustcomm/ustcomm.c index e773f718..3b53471a 100644 --- a/libustcomm/ustcomm.c +++ b/libustcomm/ustcomm.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -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 == ' ') { diff --git a/libustcomm/ustcomm.h b/libustcomm/ustcomm.h index b7d88399..7e1960fb 100644 --- a/libustcomm/ustcomm.h +++ b/libustcomm/ustcomm.h @@ -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);