From: Nils Carlson Date: Wed, 29 Dec 2010 14:01:06 +0000 (+0100) Subject: Generalize some ustcomm functionality X-Git-Tag: v0.10~5 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=28c1bb4003ca120888a1d61d5ec71eac426ae490;p=ust.git Generalize some ustcomm functionality 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 --- diff --git a/libust/tracectl.c b/libust/tracectl.c index 7c05467..a7da945 100644 --- a/libust/tracectl.c +++ b/libust/tracectl.c @@ -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; } diff --git a/libustcmd/ustcmd.c b/libustcmd/ustcmd.c index bffd3c2..2c16e75 100644 --- a/libustcmd/ustcmd.c +++ b/libustcmd/ustcmd.c @@ -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); diff --git a/libustcomm/ustcomm.c b/libustcomm/ustcomm.c index 63eed5f..9b1d83a 100644 --- a/libustcomm/ustcomm.c +++ b/libustcomm/ustcomm.c @@ -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; -} - diff --git a/libustcomm/ustcomm.h b/libustcomm/ustcomm.h index 689c151..0ec04fc 100644 --- a/libustcomm/ustcomm.h +++ b/libustcomm/ustcomm.h @@ -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 */