From: Alexis Hallé Date: Wed, 14 Jul 2010 18:51:57 +0000 (-0400) Subject: add get/set commands for daemon socket path X-Git-Tag: v1.9.1~571 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=b2fb2f91912b59447459eecc4b41baf8154be1bf;p=lttng-ust.git add get/set commands for daemon socket path --- diff --git a/libust/tracectl.c b/libust/tracectl.c index 03220373..1b684445 100644 --- a/libust/tracectl.c +++ b/libust/tracectl.c @@ -994,6 +994,25 @@ int process_client_cmd(char *recvbuf, struct ustcomm_source *src) free(reply); } + else if(nth_token_is(recvbuf, "get_sock_path", 0) == 1) { + char *reply = getenv("UST_DAEMON_SOCKET"); + if(!reply) { + asprintf(&reply, "%s/%s", SOCK_DIR, "ustd"); + result = ustcomm_send_reply(&ustcomm_app.server, reply, src); + free(reply); + } + else { + result = ustcomm_send_reply(&ustcomm_app.server, reply, src); + } + if(result) + ERR("ustcomm_send_reply failed"); + } + else if(nth_token_is(recvbuf, "set_sock_path", 0) == 1) { + char *sock_path = nth_token(recvbuf, 1); + result = setenv("UST_DAEMON_SOCKET", sock_path, 1); + if(result) + ERR("cannot set UST_DAEMON_SOCKET environment variable"); + } else { ERR("unable to parse message: %s", recvbuf); } diff --git a/libustcmd/ustcmd.c b/libustcmd/ustcmd.c index c2a98459..1c5894be 100644 --- a/libustcmd/ustcmd.c +++ b/libustcmd/ustcmd.c @@ -420,6 +420,56 @@ int ustcmd_get_cmsf(struct marker_status **cmsf, const pid_t pid) return 0; } +/** + * Set socket path + * + * @param sock_path Socket path + * @param pid Traced process ID + * @return 0 if successful, or error + */ +int ustcmd_set_sock_path(const char *sock_path, pid_t pid) +{ + char *cmd; + int result; + + asprintf(&cmd, "%s %s", "set_sock_path", sock_path); + + result = ustcmd_send_cmd(cmd, pid, NULL); + if (result != 1) { + free(cmd); + return USTCMD_ERR_GEN; + } + + free(cmd); + return 0; +} + +/** + * Get socket path + * + * @param sock_path Pointer to where the socket path will be returned + * @param pid Traced process ID + * @return 0 if successful, or error + */ +int ustcmd_get_sock_path(char **sock_path, pid_t pid) +{ + char *cmd, *reply; + int result; + + asprintf(&cmd, "%s", "get_sock_path"); + + result = ustcmd_send_cmd(cmd, pid, &reply); + if (result != 1) { + free(cmd); + free(reply); + return USTCMD_ERR_GEN; + } + + free(cmd); + *sock_path = reply; + return 0; +} + /** * Sends a given command to a traceable process * diff --git a/libustcmd/ustcmd.h b/libustcmd/ustcmd.h index c9ecb008..06e53452 100644 --- a/libustcmd/ustcmd.h +++ b/libustcmd/ustcmd.h @@ -62,5 +62,7 @@ extern int ustcmd_free_cmsf(struct marker_status *); extern unsigned int ustcmd_count_nl(const char *); extern int ustcmd_send_cmd(const char *, pid_t, char **); extern int ustcmd_get_cmsf(struct marker_status **, pid_t); +extern int ustcmd_set_sock_path(const char *, pid_t); +extern int ustcmd_get_sock_path(char **, pid_t); #endif /* _USTCMD_H */ diff --git a/ustctl/ustctl.c b/ustctl/ustctl.c index 822ef4c9..50e0d012 100644 --- a/ustctl/ustctl.c +++ b/ustctl/ustctl.c @@ -40,6 +40,8 @@ enum command { SET_SUBBUF_NUM, GET_SUBBUF_SIZE, GET_SUBBUF_NUM, + GET_SOCK_PATH, + SET_SOCK_PATH, UNKNOWN }; @@ -64,8 +66,10 @@ Commands:\n\ --destroy-trace\t\t\tDestroy the trace\n\ --set-subbuf-size \"CHANNEL/bytes\"\tSet the size of subbuffers per channel\n\ --set-subbuf-num \"CHANNEL/n\"\tSet the number of subbuffers per channel\n\ + --set-sock-path\t\t\tSet the path of the daemon socket\n\ --get-subbuf-size \"CHANNEL\"\t\tGet the size of subbuffers per channel\n\ --get-subbuf-num \"CHANNEL\"\t\tGet the number of subbuffers per channel\n\ + --get-sock-path\t\t\tGet the path of the daemon socket\n\ --enable-marker \"CHANNEL/MARKER\"\tEnable a marker\n\ --disable-marker \"CHANNEL/MARKER\"\tDisable a marker\n\ --list-markers\t\t\tList the markers of the process, their\n\t\t\t\t\t state and format string\n\ @@ -97,6 +101,8 @@ int parse_opts_long(int argc, char **argv, struct ust_opts *opts) { "set-subbuf-num", 1, 0, SET_SUBBUF_NUM }, { "get-subbuf-size", 1, 0, GET_SUBBUF_SIZE }, { "get-subbuf-num", 1, 0, GET_SUBBUF_NUM }, + { "get-sock-path", 0, 0, GET_SOCK_PATH }, + { "set-sock-path", 1, 0, SET_SOCK_PATH }, { 0, 0, 0, 0 } }; @@ -121,6 +127,7 @@ int parse_opts_long(int argc, char **argv, struct ust_opts *opts) case SET_SUBBUF_NUM: case GET_SUBBUF_SIZE: case GET_SUBBUF_NUM: + case SET_SOCK_PATH: opts->regex = strdup(optarg); break; @@ -161,6 +168,7 @@ int main(int argc, char *argv[]) { pid_t *pidit; int result; + char *tmp; struct ust_opts opts; progname = argv[0]; @@ -307,6 +315,23 @@ int main(int argc, char *argv[]) } break; + case GET_SOCK_PATH: + result = ustcmd_get_sock_path(&tmp, *pidit); + if (result) { + ERR("error while trying to get sock path for PID %u\n", (unsigned int) *pidit); + break; + } + printf("the socket path is %s\n", tmp); + free(tmp); + break; + + case SET_SOCK_PATH: + result = ustcmd_set_sock_path(opts.regex, *pidit); + if (result) { + ERR("error while trying to set sock path for PID %u\n", (unsigned int) *pidit); + } + break; + default: ERR("unknown command\n"); break;