From: Maynard J. <may...@us...> - 2007-12-18 16:58:47
|
Update of /cvsroot/oprofile/oprofile/libopagent In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv19499/libopagent Modified Files: Tag: JIT_SUPPORT libopagent.c Log Message: Fix up error handling Index: libopagent.c =================================================================== RCS file: /cvsroot/oprofile/oprofile/libopagent/Attic/libopagent.c,v retrieving revision 1.1.2.17 retrieving revision 1.1.2.18 diff -u -p -d -r1.1.2.17 -r1.1.2.18 --- libopagent.c 17 Dec 2007 21:53:44 -0000 1.1.2.17 +++ libopagent.c 18 Dec 2007 16:58:44 -0000 1.1.2.18 @@ -48,7 +48,8 @@ op_agent_t op_open_agent(void) { char pad_bytes[7] = {0, 0, 0, 0, 0, 0, 0}; int pad_cnt; - char tmp[PATH_MAX + 16]; + char dump_path[PATH_MAX]; + char err_msg[PATH_MAX + 16]; struct stat dirstat; int rc; struct jitheader header; @@ -58,26 +59,25 @@ op_agent_t op_open_agent(void) rc = stat(AGENT_DIR, &dirstat); if (rc || !S_ISDIR(dirstat.st_mode)) { - if (rc) - perror(AGENT_DIR); - + if (!rc) + errno = ENOTDIR; fprintf(stderr,"libopagent: Jitdump agent directory %s " "missing\n", AGENT_DIR); fprintf(stderr,"libopagent: do opcontrol --setup or " "opcontrol --reset, first\n"); return NULL; } - snprintf(tmp, PATH_MAX, "Error opening %s/%i.dump", - AGENT_DIR, getpid()); + snprintf(dump_path, PATH_MAX, "%s/%i.dump", AGENT_DIR, getpid()); + snprintf(err_msg, PATH_MAX + 16, "Error opening %s\n", dump_path); // make the dump file only accessible for the user for security reason. - fd = creat(tmp, S_IRUSR|S_IWUSR); - if (!fd) { - perror(tmp); + fd = creat(dump_path, S_IRUSR|S_IWUSR); + if (fd == -1) { + fprintf(stderr, "%s\n", err_msg); return NULL; } dumpfile = fdopen(fd, "w"); if (!dumpfile) { - perror(tmp); + fprintf(stderr, "%s\n", err_msg); return NULL; } @@ -90,25 +90,24 @@ op_agent_t op_open_agent(void) header.bfd_arch = BFD_ARCH; header.bfd_mach = BFD_MACH; if (gettimeofday(&tv, NULL)) { - perror("gettimeofday failed"); + fprintf(stderr, "gettimeofday failed\n"); return NULL; } header.timestamp = tv.tv_sec; - snprintf(tmp, PATH_MAX, "Error writing to %s/%i.dump", - AGENT_DIR, getpid()); + snprintf(err_msg, PATH_MAX + 16, "Error writing to %s", dump_path); if (!fwrite(&header, sizeof(header), 1, dumpfile)) { - perror(tmp); + fprintf(stderr, "%s\n", err_msg); return NULL; } if (!fwrite(BFD_TARGET_NAME, strlen(BFD_TARGET_NAME) + 1, 1, dumpfile)) { - perror(tmp); + fprintf(stderr, "%s\n", err_msg); return NULL; } /* write padding '\0' if necessary */ if (pad_cnt && !fwrite(pad_bytes, pad_cnt, 1, dumpfile)) { - perror(tmp); + fprintf(stderr, "%s\n", err_msg); return NULL; } fflush(dumpfile); @@ -123,13 +122,12 @@ int op_close_agent(op_agent_t hdl) FILE * dumpfile = (FILE *) hdl; if (!dumpfile) { errno = EINVAL; - perror("Invalid hdl argument"); return -1; } rec.id = JIT_CODE_CLOSE; rec.total_size = sizeof(rec); if (gettimeofday(&tv, NULL)) { - perror("gettimeofday failed"); + fprintf(stderr, "gettimeofday failed\n"); return -1; } rec.timestamp = tv.tv_sec; @@ -153,7 +151,7 @@ int op_write_native_code(op_agent_t hdl, if (!dumpfile) { errno = EINVAL; - perror("Invalid hdl argument"); + fprintf(stderr, "Invalid hdl argument\n"); return -1; } sz_symb_name = strlen(symbol_name) + 1; @@ -166,7 +164,7 @@ int op_write_native_code(op_agent_t hdl, rec.pad_cnt = (((rec.total_size + 7) & 7) ^ 7); rec.total_size += rec.pad_cnt; if (gettimeofday(&tv, NULL)) { - perror("gettimeofday failed"); + fprintf(stderr, "gettimeofday failed\n"); return -1; } @@ -210,7 +208,7 @@ int op_write_debug_line_info(op_agent_t if (!dumpfile) { errno = EINVAL; - perror("Invalid hdl argument"); + fprintf(stderr, "Invalid hdl argument\n"); return -1; } @@ -220,7 +218,7 @@ int op_write_debug_line_info(op_agent_t rec.total_size = 0; rec.nr_entry = nr_entry; if (gettimeofday(&tv, NULL)) { - perror("gettimeofday failed"); + fprintf(stderr, "gettimeofday failed\n"); return -1; } @@ -275,7 +273,7 @@ int op_unload_native_code(op_agent_t hdl if (!dumpfile) { errno = EINVAL; - perror("Invalid hdl argument"); + fprintf(stderr, "Invalid hdl argument\n"); return -1; } @@ -283,7 +281,7 @@ int op_unload_native_code(op_agent_t hdl rec.code_addr = (uint64_t) (uintptr_t) code; rec.total_size = sizeof(rec); if (gettimeofday(&tv, NULL)) { - perror("gettimeofday failed"); + fprintf(stderr, "gettimeofday failed\n"); return -1; } rec.timestamp = tv.tv_sec; |