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);
}
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
*
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 */
SET_SUBBUF_NUM,
GET_SUBBUF_SIZE,
GET_SUBBUF_NUM,
+ GET_SOCK_PATH,
+ SET_SOCK_PATH,
UNKNOWN
};
--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\
{ "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 }
};
case SET_SUBBUF_NUM:
case GET_SUBBUF_SIZE:
case GET_SUBBUF_NUM:
+ case SET_SOCK_PATH:
opts->regex = strdup(optarg);
break;
{
pid_t *pidit;
int result;
+ char *tmp;
struct ust_opts opts;
progname = argv[0];
}
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;