/* 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:
}
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;
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;
reply_header->result =
process_trace_cmd(recv_header->command,
- trace_inf->trace);
+ trace_inf->field);
goto send_response;
}
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;
*/
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);
{
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;
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);
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;
}
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;
-}
-
STOP_TRACE,
};
-struct ustcomm_trace_info {
- char *trace;
+struct ustcomm_single_field {
+ char *field;
char data[USTCOMM_DATA_SIZE];
};
char data[USTCOMM_DATA_SIZE];
};
-struct ustcomm_sock_path {
- char *sock_path;
- char data[USTCOMM_DATA_SIZE];
-};
-
struct ustcomm_pidunique {
s64 pidunique;
};
(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,
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 */