From: Pierre-Marc Fournier Date: Wed, 9 Sep 2009 15:51:42 +0000 (-0400) Subject: ustd/ustcomm: allow to choose custom socket path X-Git-Tag: v0.1~150 X-Git-Url: http://git.lttng.org/?p=ust.git;a=commitdiff_plain;h=c97d443730716166051e0b6b95d26ab3faadf8dc ustd/ustcomm: allow to choose custom socket path This is chosen with the -s option of ustd and, in the traced app, with the UST_DAEMON_SOCKET environment variable. --- diff --git a/libustcomm/ustcomm.c b/libustcomm/ustcomm.c index 630f906..1f4bce9 100644 --- a/libustcomm/ustcomm.c +++ b/libustcomm/ustcomm.c @@ -109,8 +109,18 @@ int ustcomm_request_consumer(pid_t pid, const char *channel) char *msg=NULL; int retval = 0; struct ustcomm_connection conn; + char *explicit_daemon_socket_path; + + explicit_daemon_socket_path = getenv("UST_DAEMON_SOCKET"); + if(explicit_daemon_socket_path) { + /* user specified explicitly a socket path */ + result = snprintf(path, UNIX_PATH_MAX, "%s", explicit_daemon_socket_path); + } + else { + /* just use the default path */ + result = snprintf(path, UNIX_PATH_MAX, "%s/ustd", SOCK_DIR); + } - result = snprintf(path, UNIX_PATH_MAX, "%s/ustd", SOCK_DIR); if(result >= UNIX_PATH_MAX) { ERR("string overflow allocating socket name"); return -1; @@ -485,31 +495,31 @@ free_name: * can connect to it. */ -int ustcomm_init_ustd(struct ustcomm_ustd *handle) +int ustcomm_init_ustd(struct ustcomm_ustd *handle, const char *sock_path) { - int result; char *name; + int retval = 0; - result = asprintf(&name, "%s/%s", SOCK_DIR, "ustd"); - if(result >= UNIX_PATH_MAX) { - ERR("string overflow allocating socket name"); - return -1; + if(sock_path) { + asprintf(&name, "%s", sock_path); + } + else { + asprintf(&name, "%s/%s", SOCK_DIR, "ustd"); } handle->server.listen_fd = init_named_socket(name, &handle->server.socketpath); if(handle->server.listen_fd < 0) { ERR("error initializing named socket at %s", name); + retval = -1; goto free_name; } - free(name); INIT_LIST_HEAD(&handle->server.connections); - return 0; - free_name: free(name); - return -1; + + return retval; } static char *find_tok(char *str) diff --git a/libustcomm/ustcomm.h b/libustcomm/ustcomm.h index 83d8fae..7620940 100644 --- a/libustcomm/ustcomm.h +++ b/libustcomm/ustcomm.h @@ -64,7 +64,7 @@ extern int ustcomm_app_recv_message(struct ustcomm_app *app, char **msg, struct extern int ustcomm_init_app(pid_t pid, struct ustcomm_app *handle); -extern int ustcomm_init_ustd(struct ustcomm_ustd *handle); +extern int ustcomm_init_ustd(struct ustcomm_ustd *handle, const char *sock_path); extern int ustcomm_connect_app(pid_t pid, struct ustcomm_connection *conn); extern int ustcomm_connect_path(const char *path, struct ustcomm_connection *conn, pid_t signalpid); diff --git a/ustd/ustd.c b/ustd/ustd.c index 5b45b6c..a70f2f7 100644 --- a/ustd/ustd.c +++ b/ustd/ustd.c @@ -47,6 +47,8 @@ #define PUT_SUBBUF_DIED 0 #define PUT_SUBBUF_PUSHED 2 +char *sock_path=NULL; + int test_sigpipe(void) { sigset_t sigset;