Generalize some ustcomm functionality
authorNils Carlson <nils.carlson@ericsson.com>
Wed, 29 Dec 2010 14:01:06 +0000 (15:01 +0100)
committerNils Carlson <nils.carlson@ericsson.com>
Wed, 29 Dec 2010 14:02:04 +0000 (15:02 +0100)
There were multiple cases of only a single text field being sent
with ustcomm. This commit merges these into a single case.

Signed-off-by: Nils Carlson <nils.carlson@ericsson.com>
libust/tracectl.c
libustcmd/ustcmd.c
libustcomm/ustcomm.c
libustcomm/ustcomm.h

index 7c054670e41de5a186f02f4c4bceb2b09bee8f16..a7da94569a896d464227f50315a364d42e105a37 100644 (file)
@@ -548,20 +548,18 @@ static void force_subbuf_switch()
 /* Simple commands are those which need only respond with a return value. */
 static int process_simple_client_cmd(int command, char *recv_buf)
 {
+       int result;
+
        switch(command) {
        case SET_SOCK_PATH:
        {
-               struct ustcomm_sock_path *sock_msg;
-               sock_msg = (struct ustcomm_sock_path *)recv_buf;
-               sock_msg->sock_path =
-                       ustcomm_restore_ptr(sock_msg->sock_path,
-                                           sock_msg->data,
-                                           sizeof(sock_msg->data));
-               if (!sock_msg->sock_path) {
-
-                       return -EINVAL;
+               struct ustcomm_single_field *sock_msg;
+               sock_msg = (struct ustcomm_single_field *)recv_buf;
+               result = ustcomm_unpack_single_field(sock_msg);
+               if (result < 0) {
+                       return result;
                }
-               return setenv("UST_DAEMON_SOCKET", sock_msg->sock_path, 1);
+               return setenv("UST_DAEMON_SOCKET", sock_msg->field, 1);
        }
 
        case FORCE_SUBBUF_SWITCH:
@@ -999,22 +997,22 @@ static void process_client_cmd(struct ustcomm_header *recv_header,
        }
        case GET_SOCK_PATH:
        {
-               struct ustcomm_sock_path *sock_msg;
+               struct ustcomm_single_field *sock_msg;
                char *sock_path_env;
 
-               sock_msg = (struct ustcomm_sock_path *)send_buf;
+               sock_msg = (struct ustcomm_single_field *)send_buf;
 
                sock_path_env = getenv("UST_DAEMON_SOCKET");
 
                if (!sock_path_env) {
-                       result = ustcomm_pack_sock_path(reply_header,
-                                                       sock_msg,
-                                                       SOCK_DIR "/ustd");
+                       result = ustcomm_pack_single_field(reply_header,
+                                                          sock_msg,
+                                                          SOCK_DIR "/ustd");
 
                } else {
-                       result = ustcomm_pack_sock_path(reply_header,
-                                                       sock_msg,
-                                                       sock_path_env);
+                       result = ustcomm_pack_single_field(reply_header,
+                                                          sock_msg,
+                                                          sock_path_env);
                }
                reply_header->result = result;
 
@@ -1028,10 +1026,10 @@ static void process_client_cmd(struct ustcomm_header *recv_header,
        case STOP_TRACE:
        case DESTROY_TRACE:
        {
-               struct ustcomm_trace_info *trace_inf =
-                       (struct ustcomm_trace_info *)recv_buf;
+               struct ustcomm_single_field *trace_inf =
+                       (struct ustcomm_single_field *)recv_buf;
 
-               result = ustcomm_unpack_trace_info(trace_inf);
+               result = ustcomm_unpack_single_field(trace_inf);
                if (result < 0) {
                        ERR("couldn't unpack trace info");
                        reply_header->result = -EINVAL;
@@ -1040,7 +1038,7 @@ static void process_client_cmd(struct ustcomm_header *recv_header,
 
                reply_header->result =
                        process_trace_cmd(recv_header->command,
-                                         trace_inf->trace);
+                                         trace_inf->field);
                goto send_response;
 
        }
index bffd3c237235144c12211e26b93246d15337811b..2c16e754da425d2f9c1fcc9b71fdb84f0db77347 100644 (file)
@@ -303,12 +303,12 @@ int ustcmd_get_subbuf_size(const char *trace, const char *channel, pid_t pid)
 static int do_trace_cmd(const char *trace, pid_t pid, int command)
 {
        struct ustcomm_header req_header, res_header;
-       struct ustcomm_trace_info trace_inf;
+       struct ustcomm_single_field trace_inf;
        int result;
 
-       result = ustcomm_pack_trace_info(&req_header,
-                                        &trace_inf,
-                                        trace);
+       result = ustcomm_pack_single_field(&req_header,
+                                          &trace_inf,
+                                          trace);
        if (result < 0) {
                errno = -result;
                return -1;
@@ -607,20 +607,19 @@ int ustcmd_get_tes(struct trace_event_status **tes,
  */
 int ustcmd_set_sock_path(const char *sock_path, pid_t pid)
 {
-       int offset = 0;
+       int result;
        struct ustcomm_header req_header, res_header;
-       struct ustcomm_sock_path sock_path_msg;
+       struct ustcomm_single_field sock_path_msg;
 
-       sock_path_msg.sock_path = ustcomm_print_data(sock_path_msg.data,
-                                                    sizeof(sock_path_msg.data),
-                                                    &offset,
-                                                    sock_path);
-       if (sock_path_msg.sock_path == USTCOMM_POISON_PTR) {
+       result = ustcomm_pack_single_field(&req_header,
+                                          &sock_path_msg,
+                                          sock_path);
+       if (result < 0) {
+               errno = -result;
                return -1;
        }
 
        req_header.command = SET_SOCK_PATH;
-       req_header.size = COMPUTE_MSG_SIZE(&sock_path_msg, offset);
 
        return do_cmd(pid, &req_header, (char *)&sock_path_msg,
                      &res_header, NULL);
@@ -637,7 +636,7 @@ int ustcmd_get_sock_path(char **sock_path, pid_t pid)
 {
        int result;
        struct ustcomm_header req_header, res_header;
-       struct ustcomm_sock_path *sock_path_msg;
+       struct ustcomm_single_field *sock_path_msg;
 
        req_header.command = GET_SOCK_PATH;
        req_header.size = 0;
@@ -648,12 +647,12 @@ int ustcmd_get_sock_path(char **sock_path, pid_t pid)
                return -1;
        }
 
-       result = ustcomm_unpack_sock_path(sock_path_msg);
+       result = ustcomm_unpack_single_field(sock_path_msg);
        if (result < 0) {
                return result;
        }
 
-       *sock_path = strdup(sock_path_msg->sock_path);
+       *sock_path = strdup(sock_path_msg->field);
 
        free(sock_path_msg);
 
index 63eed5fa8b63d19fc2957e1105ed0338aad898ca..9b1d83a9a4d86bde829f45830b404872a7fe8e1c 100644 (file)
@@ -621,33 +621,32 @@ char * ustcomm_restore_ptr(char *ptr, char *data_field, int data_field_size)
        return data_field + (long)ptr;
 }
 
-int ustcomm_pack_trace_info(struct ustcomm_header *header,
-                           struct ustcomm_trace_info *trace_inf,
-                           const char *trace)
+int ustcomm_pack_single_field(struct ustcomm_header *header,
+                             struct ustcomm_single_field *single_field,
+                             const char *string)
 {
        int offset = 0;
 
-       trace_inf->trace = ustcomm_print_data(trace_inf->data,
-                                             sizeof(trace_inf->data),
-                                             &offset,
-                                             trace);
+       single_field->field = ustcomm_print_data(single_field->data,
+                                                sizeof(single_field->data),
+                                                &offset,
+                                                string);
 
-       if (trace_inf->trace == USTCOMM_POISON_PTR) {
+       if (single_field->field == USTCOMM_POISON_PTR) {
                return -ENOMEM;
        }
 
-       header->size = COMPUTE_MSG_SIZE(trace_inf, offset);
+       header->size = COMPUTE_MSG_SIZE(single_field, offset);
 
        return 0;
 }
 
-
-int ustcomm_unpack_trace_info(struct ustcomm_trace_info *trace_inf)
+int ustcomm_unpack_single_field(struct ustcomm_single_field *single_field)
 {
-       trace_inf->trace = ustcomm_restore_ptr(trace_inf->trace,
-                                              trace_inf->data,
-                                              sizeof(trace_inf->data));
-       if (!trace_inf->trace) {
+       single_field->field = ustcomm_restore_ptr(single_field->field,
+                                                 single_field->data,
+                                                 sizeof(single_field->data));
+       if (!single_field->field) {
                return -EINVAL;
        }
 
@@ -825,37 +824,3 @@ int ustcomm_unpack_marker_info(struct ustcomm_marker_info *marker_inf)
        return 0;
 }
 
-int ustcomm_pack_sock_path(struct ustcomm_header *header,
-                          struct ustcomm_sock_path *sock_path_inf,
-                          const char *socket_path)
-{
-       int offset = 0;
-
-       sock_path_inf->sock_path =
-               ustcomm_print_data(sock_path_inf->data,
-                                  sizeof(sock_path_inf->data),
-                                  &offset,
-                                  socket_path);
-
-       if (sock_path_inf->sock_path == USTCOMM_POISON_PTR) {
-               return -ENOMEM;
-       }
-
-       header->size = COMPUTE_MSG_SIZE(sock_path_inf, offset);
-
-       return 0;
-}
-
-int ustcomm_unpack_sock_path(struct ustcomm_sock_path *sock_path_inf)
-{
-       sock_path_inf->sock_path =
-               ustcomm_restore_ptr(sock_path_inf->sock_path,
-                                   sock_path_inf->data,
-                                   sizeof(sock_path_inf->data));
-       if (!sock_path_inf->sock_path) {
-               return -EINVAL;
-       }
-
-       return 0;
-}
-
index 689c151a5b300920cbf97b4d4177622afe30058e..0ec04fc6e5edfd83458e021ecf835c0b5f429eaa 100644 (file)
@@ -78,8 +78,8 @@ enum tracectl_commands {
        STOP_TRACE,
 };
 
-struct ustcomm_trace_info {
-       char *trace;
+struct ustcomm_single_field {
+       char *field;
        char data[USTCOMM_DATA_SIZE];
 };
 
@@ -109,11 +109,6 @@ struct ustcomm_marker_info {
        char data[USTCOMM_DATA_SIZE];
 };
 
-struct ustcomm_sock_path {
-       char *sock_path;
-       char data[USTCOMM_DATA_SIZE];
-};
-
 struct ustcomm_pidunique {
        s64 pidunique;
 };
@@ -180,11 +175,11 @@ extern char * ustcomm_restore_ptr(char *ptr, char *data_field,
        (size_t) (long)(struct_ptr)->data - (long)(struct_ptr) + (offset)
 
 /* Packing and unpacking functions, making life easier */
-extern int ustcomm_pack_trace_info(struct ustcomm_header *header,
-                                  struct ustcomm_trace_info *trace_inf,
+extern int ustcomm_pack_single_field(struct ustcomm_header *header,
+                                  struct ustcomm_single_field *sf,
                                   const char *trace);
 
-extern int ustcomm_unpack_trace_info(struct ustcomm_trace_info *trace_inf);
+extern int ustcomm_unpack_single_field(struct ustcomm_single_field *sf);
 
 extern int ustcomm_pack_channel_info(struct ustcomm_header *header,
                                     struct ustcomm_channel_info *ch_inf,
@@ -209,11 +204,4 @@ extern int ustcomm_pack_marker_info(struct ustcomm_header *header,
 
 extern int ustcomm_unpack_marker_info(struct ustcomm_marker_info *marker_inf);
 
-
-extern int ustcomm_pack_sock_path(struct ustcomm_header *header,
-                                 struct ustcomm_sock_path *sock_path_inf,
-                                 const char *socket_path);
-
-extern int ustcomm_unpack_sock_path(struct ustcomm_sock_path *sock_path_inf);
-
 #endif /* USTCOMM_H */
This page took 0.03306 seconds and 4 git commands to generate.