p = data->payload;
pack_int32(p, events_count);
+ /* FIXME events[i].type, events[i].code should be uint16_t */
for (i=0; i<events_count; i++){
pack_int32(p,id);
pack_int32(p, (int32_t) events[i].type);
void initialize_log(void)
{
int fd = open(DEBUG_LOGFILE, O_WRONLY | O_CREAT | O_TRUNC, 0777);
- if (fd > 0) {
+ if (fd != -1) {
close_on_exec_dup(fd, 1);
close_on_exec_dup(fd, 2);
static int parse_replay_event(struct msg_buf_t *msg,
struct replay_event_t *re)
{
+ uint32_t dummy;
if (!parse_timeval(msg, &re->ev.time)) {
LOGE("time parsing error\n");
return 0;
}
- if (!parse_int32(msg, (uint32_t *)&re->ev.type)) {
+ /* FIXME ev.type, ev.code should be uint16_t */
+ if (!parse_int32(msg, &dummy)) {
LOGE("type parsing error\n");
return 0;
}
+ re->ev.type = (uint16_t)dummy;
- if (!parse_int32(msg, (uint32_t *)&re->ev.code)) {
+ if (!parse_int32(msg, &dummy)) {
LOGE("code parsing error\n");
return 0;
}
+ re->ev.code = (uint16_t)dummy;
if (!parse_int32(msg, (uint32_t *)&re->ev.value)) {
LOGE("value parsing error\n");
f = open(buf, O_RDONLY);
if (f != -1) {
count = read(f, buf, sizeof(buf));
- if (count == 0)
- buf[0] = '\0';
+ if (count >= sizeof(buf))
+ count = sizeof(buf) - 1;
+ buf[count] = '\0';
close(f);
} else {
LOGE("file not found <%s>\n", buf);
if (!parse_int32(msg, &count)) {
LOGE("NMSG_GET_PROCESS_ADD_INFO error: No process count\n");
err_code = ERR_WRONG_MESSAGE_DATA;
- goto send_ack;
+ goto send_fail;
}
/* alloc array for pids */
cmd_line_arr = malloc(count * sizeof(*cmd_line_arr));
if (pidarr == NULL) {
LOGE("can not alloc pid array (%u)", count);
- goto send_ack;
+ goto send_fail;
}
if (cmd_line_arr == NULL) {
LOGE("can not alloc cmd line array (%u)", count);
- goto send_fail_parse;
+ goto send_fail;
}
/* parse all pids */
for (i = 0; i != count; i++) {
if (!parse_int32(msg, &pidarr[i])) {
LOGE("can not parse pid #%u", i);
- goto send_fail_parse;
+ goto send_fail;
}
}
payload = malloc(total_len);
if (payload == NULL)
- goto send_fail_payload;
+ goto send_fail;
/* pack payload data */
p = payload;
pack_int32(p, count);
/* success */
goto send_ack;
-send_fail_payload:
+send_fail:
+ /* fail */
+ total_len = 0;
+
+send_ack:
+ /* success */
+ sendACKToHost(NMSG_GET_PROCESS_ADD_INFO, err_code, payload, total_len);
+
+ /* free data */
if (payload != NULL) {
free(payload);
payload = NULL;
}
-send_fail_parse:
- /* fail */
if (pidarr != NULL) {
free(pidarr);
pidarr = NULL;
cmd_line_arr = NULL;
}
- total_len = 0;
-
-send_ack:
- /* success */
- sendACKToHost(NMSG_GET_PROCESS_ADD_INFO, err_code, payload, total_len);
return -(err_code != ERR_NO);
}
static int parse_inst_lib(struct msg_buf_t *msg, struct lib_list_t **dest)
{
+ int res = 1;
*dest = new_lib();
if (*dest == NULL) {
LOGE("lib alloc error\n");
- return 0;
+ res = 0;
+ goto exit;
};
if (!parse_string(msg, &((*dest)->lib->bin_path)) ||
!check_exec_path((*dest)->lib->bin_path))
{
LOGE("bin path parsing error\n");
- return 0;
+ goto exit_free_err;
}
if (!parse_func_inst_list(msg, (struct data_list_t *) *dest)) {
LOGE("funcs parsing error\n");
- return 0;
+ goto exit_free_err;
}
(*dest)->size += strlen((*dest)->lib->bin_path) + 1 + sizeof((*dest)->func_num);
(*dest)->hash = calc_lib_hash((*dest)->lib);
- return 1;
+
+ goto exit;
+
+exit_free_err:
+ res = 0;
+ free(*dest);
+
+exit:
+ return res;
}
int parse_inst_app(struct msg_buf_t *msg, struct app_list_t **dest)
{
+ int res = 1;
char *start, *end;
struct app_info_t *app_info = NULL;
*dest = new_app();
if (*dest == NULL) {
LOGE("lib alloc error\n");
- return 0;
+ res = 0;
+ goto exit;
};
app_info = (*dest)->app;
!check_app_type(app_info->app_type))
{
LOGE("app type parsing error <0x%X>\n", app_info->app_type);
- return 0;
+ goto exit_free_err;
}
if (!parse_string(msg, &app_info->app_id) ||
!check_app_id(app_info->app_type, app_info->app_id))
{
LOGE("app id parsing error\n");
- return 0;
+ goto exit_free_err;
}
+
if (!parse_string(msg, &app_info->exe_path) ||
((app_info->app_type != APP_TYPE_WEB) &&
((app_info->app_type != APP_TYPE_RUNNING) ||
!check_exec_path(app_info->exe_path)))
{
LOGE("exec path parsing error\n");
- return 0;
+ goto exit_free_err;
}
end = msg->cur_pos;
if (!parse_func_inst_list(msg, (struct data_list_t *)*dest)) {
LOGE("funcs parsing error\n");
- return 0;
+ goto exit_free_err;
}
(*dest)->size += (end - start) + sizeof((*dest)->func_num);
(*dest)->hash = calc_app_hash(app_info);
- return 1;
+ goto exit;
+
+exit_free_err:
+ res = 0;
+ free(*dest);
+exit:
+ return res;
}
int parse_app_inst_list(struct msg_buf_t *msg,
size_t len;
void *filemem;
char adj_filename[PATH_MAX];
+
suffix_filename(adj_filename, filename);
filemem = mmap_file(adj_filename, &len);
if (filemem) {
const Elf_Shdr *debug_header = elf_find_debug_header(filemem);
if (debug_header) {
- const char *debug_section =
- filemem + debug_header->sh_offset;
- const char *debug_section_end =
- debug_section + debug_header->sh_size;
- const char *p = debug_section;
+ const char *debug_section, *debug_section_end, *p;
+
+ debug_section = filemem + debug_header->sh_offset;
+ debug_section_end = debug_section + debug_header->sh_size;
+ p = debug_section;
+
/* `is_like_absolute_path' checks three chars forward. */
while (p < debug_section_end - 3) {
if (is_like_absolute_path(p)) {
snprintf(builddir, PATH_MAX, "%s", p);
+ munmap(filemem, len);
return;
}
p = 1 + memchr(p, '\0', debug_section_end - p);
if(!(taskdir = opendir(path)))
{
LOGE("task not found '%s'\n", path);
- return -1;
+ ret = -1;
+ goto exit;
}
node = find_node(inst_prochead, pid);
if (node == NULL) {
LOGE("inst node task not found '%s' pid = %d\n", path, pid);
- return -1;
+ ret = -1;
+ goto exit_close_dir;
}
thread_prochead = (procNode **)&(node->thread_prochead);
del_notfound_node(thread_prochead);
reset_found_node(*thread_prochead);
+exit_close_dir:
closedir(taskdir);
+exit:
return ret;
}