X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=libustcomm%2Fustcomm.c;h=e773f7189fe313f78f0704f1ad907730a715aa38;hb=79cb25368d3d2069c7189c45ccb751c9f9fcc59d;hp=630f90609cb403ec136f8120edb8b85c171f99ee;hpb=08230db7e2e536bddf0015fa663b6d10abea30f1;p=lttng-ust.git diff --git a/libustcomm/ustcomm.c b/libustcomm/ustcomm.c index 630f9060..e773f718 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; @@ -181,6 +191,23 @@ int ustcomm_send_reply(struct ustcomm_server *server, char *msg, struct ustcomm_ return 0; } +/* Called after a fork. */ + +int ustcomm_close_all_connections(struct ustcomm_server *server) +{ + struct ustcomm_connection *conn; + struct ustcomm_connection *deletable_conn = NULL; + + list_for_each_entry(conn, &server->connections, list) { + free(deletable_conn); + deletable_conn = conn; + close(conn->fd); + list_del(&conn->list); + } + + return 0; +} + /* @timeout: max blocking time in milliseconds, -1 means infinity * * returns 1 to indicate a message was received @@ -485,31 +512,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)