add get/set commands for daemon socket path
authorAlexis Hallé <alexis.halle@polymtl.ca>
Wed, 14 Jul 2010 18:51:57 +0000 (14:51 -0400)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Wed, 21 Jul 2010 02:18:05 +0000 (22:18 -0400)
libust/tracectl.c
libustcmd/ustcmd.c
libustcmd/ustcmd.h
ustctl/ustctl.c

index 03220373c92dee9c7eea7ee259d231de8924b809..1b684445e63f1a2efa38bd59f0678f018adb6a9a 100644 (file)
@@ -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);
        }
index c2a98459ce6fb069730966a441da0cafee6d87f7..1c5894be4dd41657c88b721a62f1864db512fcb2 100644 (file)
@@ -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
  *
index c9ecb008fbee5e3c4a726fa76f0e5abfb9493a27..06e534526404bf343e3369dff25af92f6e5bb962 100644 (file)
@@ -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 */
index 822ef4c9f505b3be009856510bf4972b52457c96..50e0d012abff05ff861e0c1f9a9fe4546804975d 100644 (file)
@@ -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;
This page took 0.028524 seconds and 4 git commands to generate.