tizne_2.0 merged
authorjuho <juho80.son@samsung.com>
Wed, 22 Aug 2012 12:38:54 +0000 (21:38 +0900)
committerjuho <juho80.son@samsung.com>
Wed, 22 Aug 2012 12:38:54 +0000 (21:38 +0900)
sys-assert/CMakeLists.txt
sys-assert/src/sys-assert.c
sys-assert/src/sys-assert.h

index 6eafd48f4562c470ee7e84027378db21bf7979bb..ed1c578a2d9f648b8c845007738c254a7ec82be6 100644 (file)
@@ -44,6 +44,7 @@ ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS})
 TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} -ldl)
 
 INSTALL(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION lib)
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/.debugmode DESTINATION /opt/etc)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/.debugmode DESTINATION /usr/opt/etc)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/sys-assert.init.sh DESTINATION /etc/opt/init)
 
 
index 06ff859d1862010bc09a0c8a239ba85ed347b048..b1ec59ce2f517e8ee8bef9a2c160a8ce49cf5a2e 100755 (executable)
@@ -44,6 +44,7 @@
 #include "sys-assert.h"
 
 #define VERINFO_PATH "/etc/info.ini"
+#define MEMINFO_PATH "/proc/meminfo"
 #define CS_DIR "/opt/share/hidden_storage/SLP_debug/"
 #define DBG_DIR        "/usr/lib/debug"
 #define MAPS_PATH "/proc/self/maps"
 /* permission for open file */
 #define FILE_PERMS (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
 
-int sig_to_handle[] = { /* SIGHUP, SIGINT, */ SIGQUIT, SIGILL, /*SIGTRAP, */ SIGABRT,  /*SIGIOT, */
-       SIGBUS,
+int sig_to_handle[] = { /* SIGHUP, SIGINT, */ SIGQUIT, SIGILL, /*SIGTRAP, */
+       SIGABRT,        /*SIGIOT, */SIGBUS,
        SIGFPE, /*SIGKILL, SIGUSR1 */ SIGSEGV,  /*SIGUSR2, */
        SIGPIPE                 /*SIGXCPU,SIGXFSZ,,, */
 };
 
-#define NUM_SIG_TO_HANDLE      ((int)(sizeof(sig_to_handle)/sizeof(sig_to_handle[0])))
+#define NUM_SIG_TO_HANDLE      \
+       ((int)(sizeof(sig_to_handle)/sizeof(sig_to_handle[0])))
 
 struct sigaction g_oldact[NUM_SIG_TO_HANDLE];
 
@@ -85,7 +87,7 @@ void sighandler(int signum, siginfo_t *info, void *context)
        int cnt_callstack = 0;
        /* for backtrace_symbols() */
        char **callstack_strings;
-       struct addr_node *head;
+       struct addr_node *head = NULL;
        int i;
        int csfd;               /* file descriptor for cs file */
        int mapsfd;             /* file descriptor for maps */
@@ -110,43 +112,46 @@ void sighandler(int signum, siginfo_t *info, void *context)
        pid_t tid;
        int thread_use;
        int redscreen_flg = 0;  /* for determine redscreen */
-       int lauched_by_avatar = 0;      /* for determine launched by avatar-factory or not */
+       int lauched_by_avatar = 0;
+       /* for determine launched by avatar-factory or not */
+
+       /* get time  */
+       time_t cur_time;
+       struct tm ctime;
+       char timestr[64];
+       cur_time = time(NULL);
+       gmtime_r(&cur_time, &ctime);
+       /*localtime_r(&cur_time, &ctime);*/
+       /*get_localtime(cur_time, &ctime);*/
+       fprintf(stderr, "[sys_assert]START of sighandler\n");
 
+       /* get pid */
        pid = getpid();
        tid = (long int)syscall(__NR_gettid);
 
-       fprintf(stderr, "[sys_assert]START of sighandler \n");
-
        /* thread check */
        if (pid == tid) {
                thread_use = false;
                fprintf(stderr,
-                       "[sys_assert]this thread is main thread. pid=%d\n",
-                       pid);
+                               "[sys_assert]this thread is main thread. pid=%d\n",
+                               pid);
        } else {
                thread_use = true;
                fprintf(stderr,
-                       "[sys_assert]this process is multi-thread process. pid=%d, tid=%d\n",
-                       pid, tid);
+                               "[sys_assert]this process is multi-thread process.\
+                               pid=%d, tid=%d\n", pid, tid);
        }
 
-       /* print time  */
-       time_t cur_time;
-       struct tm ctime;
-       char timestr[64]= {0, };
-       cur_time = time(NULL);
-       gmtime_r(&cur_time, &ctime);
-//     get_localtime(cur_time, &ctime);
-
        /* make debug directory if absent */
        if (access(CS_DIR, F_OK) == -1) {
                if (mkdir(CS_DIR, DIR_PERMS) < 0) {
                        fprintf(stderr,
-                               "[sys-assert]can't make dir : %s errno : %s\n",
-                               CS_DIR, strerror(errno));
+                                       "[sys-assert]can't make dir : %s errno : %s\n",
+                                       CS_DIR, strerror(errno));
                        return;
                }
        }
+
        memset(exe_path, 0, PATH_LEN);
 
        if ((cmdlinefd = open(CMDLINE_PATH, O_RDONLY)) < 0) {
@@ -154,45 +159,41 @@ void sighandler(int signum, siginfo_t *info, void *context)
        } else {
                read(cmdlinefd, exe_path, BUF_SIZE - 1);
                exename_p = remove_path(exe_path);
-               fprintf(stderr, "[sys-assert]exename = %s \n", exename_p);
+               fprintf(stderr, "[sys-assert]exename = %s\n", exename_p);
        }
 
-       /* added temporary from dpkg-deb */
-       if (!strcmp(exename_p, "dpkg-deb")) {
+       /* added temporary skip  when crash-worker is asserted */
+       if (!strcmp(exename_p, "crash-worker"))
                return;
-       }
-
        /* make directory name, file name */
        strftime(timestr, sizeof(timestr), "%Y%m%d%H%M%S", &ctime);
-       if (snprintf(temp_path, PATH_LEN, "%s_%d_%s", exename_p, pid, timestr) == 0) {
-//         (temp_path, PATH_LEN, "%s_%d_%02d%02d%02d%02d%02d%02d",
-//          exename_p, pid, ctime.tm_year, ctime.tm_mon, ctime.tm_mday,
-//          ctime.tm_hour, ctime.tm_min, ctime.tm_sec) == 0) {
+       if (snprintf(temp_path, PATH_LEN,
+                               "%s_%d_%s", exename_p, pid, timestr) == 0) {
                fprintf(stderr,
-                       "[sys-assert]can't make temp file name : %s%d\n",
-                       exename_p, pid);
+                               "[sys-assert]can't make temp file name : %s%d\n",
+                               exename_p, pid);
                return;
        }
 
-       if (snprintf(filename_cs, PATH_LEN, "%s.cs", temp_path) == 0) {
+       if (snprintf(filename_cs, PATH_LEN,
+                               "%s.cs", temp_path) == 0) {
                fprintf(stderr,
-                       "[sys-assert]can't make file name : %s%d\n",
-                       exename_p, pid);
+                               "[sys-assert]can't make file name : %s%d\n",
+                               exename_p, pid);
                return;
        }
 
-       if (snprintf(filepath_cs, PATH_LEN, "%s%s/", CS_DIR, temp_path)
-           == 0) {
+       if (snprintf(filepath_cs, PATH_LEN, "%s%s/", CS_DIR, temp_path) == 0) {
                fprintf(stderr,
-                       "[sys-assert]can't make file path : %s%s%d.cs\n",
-                       CS_DIR, exename_p, pid);
+                               "[sys-assert]can't make file path : %s%s%d.cs\n",
+                               CS_DIR, exename_p, pid);
                return;
        }
 
        /* make dir for cs file */
        if (mkdir(filepath_cs, DIR_PERMS) < 0) {
                fprintf(stderr, "[sys-assert]can't make dir : %s\n",
-                       filepath_cs);
+                               filepath_cs);
                return;
        }
 
@@ -202,50 +203,18 @@ void sighandler(int signum, siginfo_t *info, void *context)
        /* create cs file */
        if ((csfd = creat(filepath_cs, FILE_PERMS)) < 0) {
                fprintf(stderr,
-                       "[sys-assert]can't create %s. errno = %s\n",
-                       filepath_cs, strerror(errno));
+                               "[sys-assert]can't create %s. errno = %s\n",
+                               filepath_cs, strerror(errno));
                return;
        }
 #ifdef BTDEBUG
        else
                fprintf(stderr, "[sys-assert]create %s\n", filepath_cs);
 #endif
-
-       /* open maps file */
-       if ((mapsfd = open(MAPS_PATH, O_RDONLY)) < 0) {
-               fprintf_fd(csfd, "Failed to open (%s)\n", MAPS_PATH);
-               fprintf(stderr, "[sys-assert]can't open %s\n", MAPS_PATH);
-               close(csfd);
-               return;
-       }
-#ifdef BTDEBUG
-       else
-               fprintf(stderr, "[sys-assert]open %s\n", MAPS_PATH);
-#endif
-
-       /* parsing the maps to get code segment address */
-
-       head = get_addr_list_from_maps(mapsfd);
-#ifdef BTDEBUG
-       fprintf(stderr, "[sys-assert]after get_addr_list_from_maps\n");
-#endif
-
-       if (head == NULL) {
-               fprintf_fd(csfd, "Failed to get address list\n");
-               fprintf(stderr,
-                       ">>>>error : cannot get address list from maps\n");
-               close(csfd);
-               close(mapsfd);
-               return;
-       }
        /* check this process is vip/permanent */
        redscreen_flg = check_redscreen(pid);
-
-       fprintf_fd(csfd, "%s\n", redscreen_flg ? "RED SCREEN" : "BLUE SCREEN");
-
+       fprintf_fd(csfd, "%s\n\n", redscreen_flg ? "RED SCREEN" : "BLUE SCREEN");
        /* print version info */
-       fprintf_fd(csfd,
-                  "******************************\ns/w version\n******************************\n");
        if ((verinfo = open(VERINFO_PATH, O_RDONLY)) < 0) {
                fprintf(stderr, "[sys-assert]can't open %s\n", VERINFO_PATH);
        } else {
@@ -264,234 +233,226 @@ void sighandler(int signum, siginfo_t *info, void *context)
                        }
                }
                close(verinfo);
-
-       }
-       fprintf_fd(csfd, "*******************************\n");
-       fprintf_fd(csfd, "AppName : %s\n", exename_p);
-       fprintf_fd(csfd, "signal number : %d\n", info->si_signo);
-       fprintf_fd(csfd, "file name : %s\n", filename_cs);
-       fprintf_fd(csfd, "pid : %d\n", pid);
-
-       if ((meminfo = open("/proc/meminfo", O_RDONLY)) < 0) {
-               fprintf(stderr, "[sys-assert]can't open %s\n", "/proc/meminfo");
-       } else {
-               fprintf_fd(csfd,
-                          "*******************************\nMem information\n*******************************\n");
-               while (fgets_fd(linebuf, BUF_SIZE, meminfo) != NULL) {
-                       sscanf(linebuf, "%s %s %*s", infoname, memsize1);
-
-                       if (strcmp("MemTotal:", infoname) == 0) {
-                               fprintf_fd(csfd, "%s %s kB\n", infoname,
-                                          memsize1);
-                       } else if (strcmp("MemFree:", infoname) == 0) {
-                               fprintf_fd(csfd, "%s %s kB\n", infoname,
-                                          memsize1);
-                       } else if (strcmp("Buffers:", infoname) == 0) {
-                               fprintf_fd(csfd, "%s  %s kB\n",
-                                          infoname, memsize1);
-                       } else if (strcmp("Cached:", infoname) == 0) {
-                               fprintf_fd(csfd, "%s   %s kB\n",
-                                          infoname, memsize1);
-                       }
-               }
-               close(meminfo);
        }
 
-       /* print signal information */
-       fprintf_fd(csfd, "*******************************\nextra information\n\
-*******************************\n");
-
+       /* print app info */
+       fprintf_fd(csfd, "\nAppName : %s\n", exename_p);
+       fprintf_fd(csfd, "File name : %s\n", filename_cs);
+       fprintf_fd(csfd, "Pid : %d\n", pid);
        /* print time  */
-       strftime(timestr, sizeof(timestr), "%Y.%m.%d %H:%M:%S", &ctime);
-       fprintf_fd(csfd, "time = %s ( UTC )\n", timestr);
-
+       /*localtime_r(&cur_time, &ctime);*/
+       strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", &ctime);
+       fprintf_fd(csfd, "Date: %s ( UTC )\n", timestr);
        /* print exe path */
-       fprintf_fd(csfd, "exe path = %s\n", exe_path);
-       fprintf(stderr, "[sys assert]exe path = %s\n", exe_path);
+       fprintf_fd(csfd, "ExePath: %s\n", exe_path);
+       fprintf(stderr, "[sys assert]Exe Path: %s\n", exe_path);
        if (lauched_by_avatar)
                fprintf_fd(csfd, "this process is lauched by avatar-factory\n");
 
        /* print thread info */
        if (thread_use == true) {
                fprintf_fd(csfd,
-                          "this process is multi-thread process\npid=%d tid=%d\n",
-                          pid, tid);
+                               "this process is multi-thread process\npid=%d tid=%d\n",
+                               pid, tid);
        }
-
        /* print signal info */
        print_signal_info(info, csfd);
+       fsync(csfd);
 
        /* print additional info */
 #ifdef TARGET
        fprintf_fd(csfd,
-                  "r0 = 0x%08x, r1 = 0x%08x\nr2 = 0x%08x, r3 = 0x%08x\n",
-                  ucontext->uc_mcontext.arm_r0,
-                  ucontext->uc_mcontext.arm_r1,
-                  ucontext->uc_mcontext.arm_r2, ucontext->uc_mcontext.arm_r3);
+                       "\nr0 = 0x%08x, r1 = 0x%08x\nr2 = 0x%08x, r3 = 0x%08x\n",
+                       ucontext->uc_mcontext.arm_r0,
+                       ucontext->uc_mcontext.arm_r1,
+                       ucontext->uc_mcontext.arm_r2, ucontext->uc_mcontext.arm_r3);
        fprintf_fd(csfd,
-                  "r4 = 0x%08x, r5 = 0x%08x\nr6 = 0x%08x, r7 = 0x%08x\n",
-                  ucontext->uc_mcontext.arm_r4,
-                  ucontext->uc_mcontext.arm_r5,
-                  ucontext->uc_mcontext.arm_r6, ucontext->uc_mcontext.arm_r7);
+                       "r4 = 0x%08x, r5 = 0x%08x\nr6 = 0x%08x, r7 = 0x%08x\n",
+                       ucontext->uc_mcontext.arm_r4,
+                       ucontext->uc_mcontext.arm_r5,
+                       ucontext->uc_mcontext.arm_r6, ucontext->uc_mcontext.arm_r7);
        fprintf_fd(csfd,
-                  "r8 = 0x%08x, r9 = 0x%08x\nr10 = 0x%08x, fp = 0x%08x\n",
-                  ucontext->uc_mcontext.arm_r8,
-                  ucontext->uc_mcontext.arm_r9,
-                  ucontext->uc_mcontext.arm_r10, ucontext->uc_mcontext.arm_fp);
+                       "r8 = 0x%08x, r9 = 0x%08x\nr10 = 0x%08x, fp = 0x%08x\n",
+                       ucontext->uc_mcontext.arm_r8,
+                       ucontext->uc_mcontext.arm_r9,
+                       ucontext->uc_mcontext.arm_r10, ucontext->uc_mcontext.arm_fp);
        fprintf_fd(csfd,
-                  "ip = 0x%08x, sp = 0x%08x\nlr = 0x%08x, pc = 0x%08x\n",
-                  ucontext->uc_mcontext.arm_ip,
-                  ucontext->uc_mcontext.arm_sp,
-                  ucontext->uc_mcontext.arm_lr, ucontext->uc_mcontext.arm_pc);
+                       "ip = 0x%08x, sp = 0x%08x\nlr = 0x%08x, pc = 0x%08x\n",
+                       ucontext->uc_mcontext.arm_ip,
+                       ucontext->uc_mcontext.arm_sp,
+                       ucontext->uc_mcontext.arm_lr, ucontext->uc_mcontext.arm_pc);
        fprintf_fd(csfd, "cpsr = 0x%08x\n", ucontext->uc_mcontext.arm_cpsr);
 
 #ifdef BTDEBUG
-       fprintf_fd(csfd, "fault_address = %p\n",
-                  ucontext->uc_mcontext.fault_address);
+       fprintf_fd(csfd, "\nfault_address = %p\n",
+                       ucontext->uc_mcontext.fault_address);
        fprintf_fd(csfd, "uc_stack.ss_sp = %p\n", ucontext->uc_stack.ss_sp);
        fprintf_fd(csfd, "uc_stack.ss_size = %d\n", ucontext->uc_stack.ss_size);
 #endif
-       fprintf_fd(csfd, "*******************************\ncallstack information (PID:%d)\n\
-*******************************\n",
-                  pid);
-
-#ifndef SUPPORT_LIBC_BACKTRACE
-       /* backtrace using fp */
-       {
-               long *SP;       /* point to the top of stack */
-               long *PC;       /* point to the program counter */
-               long *BP = __libc_stack_end;
-               long *FP;
-               long *framep;
-               /* get sp , pc and bp */
-               SP = (long *)ucontext->uc_mcontext.arm_sp;
-               PC = (long *)ucontext->uc_mcontext.arm_pc;
-               FP = (long *)ucontext->uc_mcontext.arm_fp;
-               framep = (long *)FP;
-
-               callstack_addrs[cnt_callstack++] =
-                   (long *)ucontext->uc_mcontext.arm_pc;
+       fprintf_fd(csfd, "\n");
 
+       /* print meminfo */
+       if ((meminfo = open(MEMINFO_PATH, O_RDONLY)) < 0) {
+               fprintf(stderr, "[sys-assert]can't open %s\n", MEMINFO_PATH);
+       } else {
+               while (fgets_fd(linebuf, BUF_SIZE, meminfo) != NULL) {
+                       sscanf(linebuf, "%s %s %*s", infoname, memsize1);
+                       if (strcmp("MemTotal:", infoname) == 0) {
+                               fprintf_fd(csfd, "%s %s kB\n", infoname,
+                                               memsize1);
+                       } else if (strcmp("MemFree:", infoname) == 0) {
+                               fprintf_fd(csfd, "%s %s kB\n", infoname,
+                                               memsize1);
+                       } else if (strcmp("Buffers:", infoname) == 0) {
+                               fprintf_fd(csfd, "%s  %s kB\n",
+                                               infoname, memsize1);
+                       } else if (strcmp("Cached:", infoname) == 0) {
+                               fprintf_fd(csfd, "%s   %s kB\n",
+                                               infoname, memsize1);
+                               break;
+                       }
+               }
+               close(meminfo);
+       }
+       fprintf_fd(csfd, "\n");
+       /* open maps file */
+       if ((mapsfd = open(MAPS_PATH, O_RDONLY)) < 0) {
+               fprintf_fd(csfd, "Failed to open (%s)\n", MAPS_PATH);
+               fprintf(stderr, "[sys-assert]can't open %s\n", MAPS_PATH);
+       } else {
 #ifdef BTDEBUG
-               print_node_to_file(head, 2);
+               fprintf(stderr, "[sys-assert]open %s\n", MAPS_PATH);
 #endif
+               /* parsing the maps to get code segment address */
+               head = get_addr_list_from_maps(mapsfd);
+               close(mapsfd);
+       }
 
-               if (FP != NULL) {
-                       for (; framep < BP;) {
-                               if (is_valid_addr(framep, head) == false)
-                                       break;
+       if (head == NULL) {
+               fprintf_fd(csfd, "Failed to get address list\n");
+               fprintf(stderr, ">>>>error : cannot get address list from maps\n");
+       } else {
+               fprintf_fd(csfd, "\ncallstack information (PID:%d)\n", pid);
+#ifndef SUPPORT_LIBC_BACKTRACE
+               /* backtrace using fp */
+               {
+                       long *SP;       /* point to the top of stack */
+                       long *PC;       /* point to the program counter */
+                       long *BP = __libc_stack_end;
+                       long *FP;
+                       long *framep;
+                       /* get sp , pc and bp */
+                       SP = (long *)ucontext->uc_mcontext.arm_sp;
+                       PC = (long *)ucontext->uc_mcontext.arm_pc;
+                       FP = (long *)ucontext->uc_mcontext.arm_fp;
+                       framep = (long *)FP;
+
+                       callstack_addrs[cnt_callstack++] =
+                               (long *)ucontext->uc_mcontext.arm_pc;
+#ifdef BTDEBUG
+                       print_node_to_file(head, 2);
+#endif
+                       if (FP != NULL) {
+                               for (; framep < BP;) {
+                                       if (is_valid_addr(framep, head) == false)
+                                               break;
 
-                               if (is_valid_addr((long *)*framep, head)
-                                   == false)
-                                       break;
+                                       if (is_valid_addr((long *)*framep, head) == false)
+                                               break;
 
-                               callstack_addrs[cnt_callstack] =
-                                   (long *)*framep;
+                                       callstack_addrs[cnt_callstack] = (long *)*framep;
 
-                               framep--;
-                               framep = (long *)(*framep);
-                               cnt_callstack++;
+                                       framep--;
+                                       framep = (long *)(*framep);
+                                       cnt_callstack++;
 
-                               if (cnt_callstack == CALLSTACK_SIZE)
-                                       break;
-                               if (framep < FP)
-                                       break;
+                                       if (cnt_callstack == CALLSTACK_SIZE)
+                                               break;
+                                       if (framep < FP)
+                                               break;
+                               }
                        }
-
+                       fprintf_fd(csfd, "cnt_callstack = %d\n", cnt_callstack);
+                       /* print callstack */
+                       if (false ==
+                                       trace_symbols(callstack_addrs, cnt_callstack, head, csfd)) {
+                               callstack_strings =
+                                       backtrace_symbols(callstack_addrs, cnt_callstack);
+                               /* print callstack information */
+                               for (i = 0; i < cnt_callstack; i++)
+                                       fprintf_fd(csfd, "%2d: %s\n", i, callstack_strings[i]);
+                       }
+                       if (FP == NULL)
+                               fprintf_fd(csfd,
+                                               "there is no callstack because of fp == NULL\n");
+                       }
+#else          /*SUPPORT_LIBC_BACKTRACE*/
+               cnt_callstack = backtrace(callstack_addrs, CALLSTACK_SIZE);
+               if (cnt_callstack > 2) {
+                       cnt_callstack -= 2;
+               } else {
+                       callstack_addrs[2] = (long *)ucontext->uc_mcontext.arm_pc;
+                       callstack_addrs[3] = (long *)ucontext->uc_mcontext.arm_lr;
+                       cnt_callstack = 2;
                }
                fprintf_fd(csfd, "cnt_callstack = %d\n", cnt_callstack);
 
                /* print callstack */
                if (false ==
-                   trace_symbols(callstack_addrs, cnt_callstack, head, csfd)) {
-                       callstack_strings =
-                           backtrace_symbols(callstack_addrs, cnt_callstack);
-                       /* print callstack information */
-                       for (i = 0; i < cnt_callstack; i++) {
-                               fprintf_fd(csfd, "%2d: %s\n", i,
-                                          callstack_strings[i]);
-                       }
-               }
-
-               if (FP == NULL) {
-                       fprintf_fd(csfd,
-                                  "there is no callstack because of fp == NULL\n");
+                               trace_symbols(&callstack_addrs[2], cnt_callstack, head, csfd)) {
+                       fprintf(stderr, "[sys-assert] trace_symbols failed\n");
                }
-       }
-#else
-
-       cnt_callstack = backtrace(callstack_addrs, CALLSTACK_SIZE);
-       if (cnt_callstack > 2) {
-               cnt_callstack -= 2;
-       } else {
-               callstack_addrs[2] = (long *)ucontext->uc_mcontext.arm_pc;
-               callstack_addrs[3] = (long *)ucontext->uc_mcontext.arm_lr;
-               cnt_callstack = 2;
-       }
-       fprintf_fd(csfd, "cnt_callstack = %d\n", cnt_callstack);
-
-       /* print callstack */
-       if (false ==
-           trace_symbols(&callstack_addrs[2], cnt_callstack, head, csfd)) {
-               fprintf(stderr, "[sys-assert] trace_symbols failed \n");
-       }
 #endif
+               fprintf_fd(csfd, "end of call stack\n");
+               /* print maps information */
+               print_node_to_file(head, csfd);
+               free_all_nodes(head);
+               }
+#else          /* i386 */
+               fprintf_fd(csfd, "\ncallstack information (PID:%d)\n", pid);
 
-#else                          /* i386 */
-       fprintf_fd(csfd, "*******************************\ncallstack information (PID:%d)\n\
-*******************************\n",
-                  pid);
-
-       layout *ebp = ucontext->uc_mcontext.gregs[REG_EBP];
-       callstack_addrs[cnt_callstack++] =
-           (long *)ucontext->uc_mcontext.gregs[REG_EIP];
-       while (ebp) {
-               callstack_addrs[cnt_callstack++] = ebp->ret;
-               ebp = ebp->ebp;
-       }
-       callstack_strings = backtrace_symbols(callstack_addrs, cnt_callstack);
-       /* print callstack information */
-       for (i = 0; i < cnt_callstack; i++) {
-               fprintf_fd(csfd, "%2d: %s\n", i, callstack_strings[i]);
-       }
+               layout *ebp = ucontext->uc_mcontext.gregs[REG_EBP];
+               callstack_addrs[cnt_callstack++] =
+                       (long *)ucontext->uc_mcontext.gregs[REG_EIP];
+               while (ebp) {
+                       callstack_addrs[cnt_callstack++] = ebp->ret;
+                       ebp = ebp->ebp;
+               }
+               callstack_strings = backtrace_symbols(callstack_addrs, cnt_callstack);
+               /* print callstack information */
+               for (i = 0; i < cnt_callstack; i++)
+                       fprintf_fd(csfd, "%2d: %s\n", i, callstack_strings[i]);
+               fprintf_fd(csfd, "end of call stack\n");
 #endif
-       fprintf_fd(csfd, "end of call stack\n");
-
-       /* print maps information */
-       print_node_to_file(head, csfd);
-
+       /* cs file sync */
+       fsync(csfd);
        /* clean up */
-       free_all_nodes(head);
-       close(mapsfd);
-       close(csfd);
-
+       if (close(csfd) == -1)
+               fprintf(stderr, "[sys-assert] csfd close error!!\n");
+       /* core dump set */
        if (prctl(PR_GET_DUMPABLE) == 0) {
                fprintf(stderr, "[sys-assert]set PR_SET_DUMPABLE to 1\n");
                prctl(PR_SET_DUMPABLE, 1);
        }
-
+       /* INOTIFY BS */
        if ((curbs = open(INOTIFY_BS, O_RDWR | O_APPEND)) < 0) {
                fprintf(stderr, "[sys-assert]cannot make %s !\n", INOTIFY_BS);
        } else {
-               fprintf_fd(curbs, "%s %s\n", filepath_cs,
-                          redscreen_flg ? "RED" : "BLUE");
+               fprintf_fd(curbs, "%s %s\n",
+                               filepath_cs, redscreen_flg ? "RED" : "BLUE");
                close(curbs);
        }
-
        for (i = 0; i < NUM_SIG_TO_HANDLE; i++) {
                if (sig_to_handle[i] == signum) {
                        sigaction(signum, &g_oldact[i], NULL);
                        fprintf(stderr,
-                               "sighandler = %p, g_sig_oldact[i] = %p\n",
-                               (void *)sighandler, g_oldact[i].sa_handler);
-
+                                       "sighandler = %p, g_sig_oldact[i] = %p\n",
+                                       (void *)sighandler, g_oldact[i].sa_handler);
                        break;
                }
        }
        raise(signum);
-
        fprintf(stderr, "[sys_assert]END of sighandler\n");
-
 }
 
 __attribute__ ((constructor))
@@ -551,54 +512,53 @@ trace_symbols(void *const *array, int size, struct addr_node *start, int csfd)
                start_addr = (unsigned int)get_start_addr(array[cnt], start);
                addr = (unsigned int)array[cnt];
 
-               /* because of launchpad, 
-                * return value of dladdr when find executable is wrong. 
-                * so fix dli_fname here
-                */
+/* because of launchpad,
+ * return value of dladdr when find executable is wrong.
+ * so fix dli_fname here */
                if (info_funcs.dli_fbase == (void *)0x8000
                    &&
                    (strncmp
                     ("/opt/apps/", info_funcs.dli_fname,
                      strlen("/opt/apps/")) == 0)) {
                        fprintf(stderr,
-                               "[sys-assert][%d] fname = %s, fbase = %p, sname = %s, saddr = %p\n",
-                               cnt, info_funcs.dli_fname,
-                               info_funcs.dli_fbase,
-                               info_funcs.dli_sname, info_funcs.dli_saddr);
+                                       "[sys-assert][%d]\
+                                       fname = %s, fbase = %p, sname = %s, saddr = %p\n",
+                                       cnt, info_funcs.dli_fname,
+                                       info_funcs.dli_fbase,
+                                       info_funcs.dli_sname, info_funcs.dli_saddr);
                        info_funcs.dli_fname = get_fpath(array[cnt], start);
                        offset_addr = addr;
                        fprintf(stderr,
-                               "[sys-assert][%d] start_addr : %x, addr : %x, offset_addr : %x \n",
-                               cnt, start_addr, addr, offset_addr);
+                                       "[sys-assert][%d]\
+                                       start_addr : %x, addr : %x, offset_addr : %x \n",
+                                       cnt, start_addr, addr, offset_addr);
                } else {
                        offset_addr = addr - start_addr;
                }
-
                if (info_funcs.dli_sname == NULL) {
 #ifndef USE_SYMBOL_DB
-                       /* FIXME : get dbg file name from debuglink and search dbg file in DBG_DIR */
-
+/*FIXME : get dbg file name from debuglink and search dbg file in DBG_DIR */
                        strcpy(filename, DBG_DIR);
                        strncat(filename, info_funcs.dli_fname, 128);
 
                        fd = open(filename, O_RDONLY);
                        if (fd < 0) {
                                fprintf_fd(csfd,
-                                          "%2d: (%p) [%s]+%p\n",
-                                          cnt, array[cnt],
-                                          info_funcs.dli_fname, offset_addr);
+                                               "%2d: (%p) [%s]+%p\n",
+                                               cnt, array[cnt],
+                                               info_funcs.dli_fname, offset_addr);
                                continue;
                        }
 
                        ret = read(fd, &elf_h, sizeof(Elf32_Ehdr));
                        if (ret < sizeof(Elf32_Ehdr)) {
                                fprintf(stderr,
-                                       "[sys-assert]readnum = %d, [%s]\n",
-                                       ret, info_funcs.dli_fname);
+                                               "[sys-assert]readnum = %d, [%s]\n",
+                                               ret, info_funcs.dli_fname);
                                fprintf_fd(csfd,
-                                          "%2d: (%p) [%s]+%p\n",
-                                          cnt, array[cnt],
-                                          info_funcs.dli_fname, offset_addr);
+                                               "%2d: (%p) [%s]+%p\n",
+                                               cnt, array[cnt],
+                                               info_funcs.dli_fname, offset_addr);
                                continue;
                        }
 
@@ -619,9 +579,9 @@ trace_symbols(void *const *array, int size, struct addr_node *start, int csfd)
                        if (s_headers == NULL) {
                                fprintf(stderr, "[sys-assert]malloc failed\n");
                                fprintf_fd(csfd,
-                                          "%2d: (%p) [%s]+%p\n",
-                                          cnt, array[cnt],
-                                          info_funcs.dli_fname, offset_addr);
+                                               "%2d: (%p) [%s]+%p\n",
+                                               cnt, array[cnt],
+                                               info_funcs.dli_fname, offset_addr);
                                continue;
                        }
                        lseek(fd, elf_h.e_shoff, SEEK_SET);
@@ -634,7 +594,7 @@ trace_symbols(void *const *array, int size, struct addr_node *start, int csfd)
                                    read(fd, &s_headers[i], elf_h.e_shentsize);
                                if (ret < elf_h.e_shentsize) {
                                        fprintf(stderr,
-                                               "[sys-assert]read error\n");
+                                                       "[sys-assert]read error\n");
                                        munmap(s_headers,
                                               elf_h.e_shnum *
                                               sizeof(Elf32_Shdr));
@@ -643,13 +603,13 @@ trace_symbols(void *const *array, int size, struct addr_node *start, int csfd)
                        }
 
                        for (i = 0; i < elf_h.e_shnum; i++) {
-                               /* find out .symtab Section index */
+/* find out .symtab Section index */
                                if (s_headers[i].sh_type == SHT_SYMTAB) {
                                        symtab_index = i;
                                        num_st =
                                            s_headers[i].sh_size /
                                            s_headers[i].sh_entsize;
-                                       /* number of .symtab entry */
+/* number of .symtab entry */
                                        break;
                                }
                        }
@@ -676,8 +636,9 @@ trace_symbols(void *const *array, int size, struct addr_node *start, int csfd)
 
                                if (ret < sizeof(Elf32_Sym)) {
                                        fprintf(stderr,
-                                               "[sys-assert]symtab_entry[%d], num_st=%d, readnum = %d\n",
-                                               i, num_st, ret);
+                                                       "[sys-assert]symtab_entry[%d],\
+                                                       num_st=%d, readnum = %d\n",
+                                                       i, num_st, ret);
                                        break;
                                }
 
@@ -769,7 +730,8 @@ static struct addr_node *get_addr_list_from_maps(int mapsfd)
        struct addr_node *head = NULL;
        struct addr_node *tail = NULL;
        struct addr_node *t_node = NULL;
-       /* parsing the maps to get executable code address */
+
+/* parsing the maps to get executable code address */
        while (fgets_fd(linebuf, BUF_SIZE, mapsfd) != NULL) {
 #ifdef BTDEBUG
                fprintf(stderr, "%s", linebuf);
@@ -780,13 +742,13 @@ static struct addr_node *get_addr_list_from_maps(int mapsfd)
                perm[4] = 0;
 #ifdef BTDEBUG
                fprintf(stderr,
-                       "addr = %s, perm = %s, fpath = %s, length=%d\n",
-                       addr, perm, path, strlen(path));
+                               "addr = %s, perm = %s, fpath = %s, length=%d\n",
+                               addr, perm, path, strlen(path));
 #endif
-               /*if perm[2]=='x', addr is valid value so we have to store the address */
+/*if perm[2]=='x',addr is valid value so we have to store the address */
 #ifdef TARGET
                if ((perm[2] == 'x' && path[0] == '/')
-                   || (perm[1] == 'w' && path[0] != '/'))
+                               || (perm[1] == 'w' && path[0] != '/'))
 #else
                if (strncmp(perm, "r-xp", 4) == 0)
 #endif
@@ -859,14 +821,18 @@ static void print_node_to_file(struct addr_node *start, int fd)
 
        fprintf(stderr, "[sys-assert]start print_node_to_file\n");
 
-       fprintf_fd(fd,
-                  "******************************\nmaps  information\n******************************\n");
+       fprintf_fd(fd, "\nmaps  information\n\n");
        while (t_node) {
-               fprintf_fd(fd, "%08x %08x %s %s\n",
-                          (unsigned int)t_node->startaddr,
-                          (unsigned int)t_node->endaddr,
-                          t_node->perm, t_node->fpath);
-               t_node = t_node->next;
+               if (!strncmp("[anony]", t_node->fpath, strlen("[anony]"))
+                               && (0x4508a000 < (unsigned int)t_node->startaddr)) {
+                       t_node = t_node->next;
+               } else {
+                       fprintf_fd(fd, "%08x %08x %s %s\n",
+                               (unsigned int)t_node->startaddr,
+                               (unsigned int)t_node->endaddr,
+                               t_node->perm, t_node->fpath);
+                       t_node = t_node->next;
+               }
        }
        fprintf_fd(fd, "end of maps information\n");
 }
@@ -939,9 +905,9 @@ static long *get_start_addr(long *value, struct addr_node *start)
 #ifdef BTDEBUG
                        fprintf(stderr, "is valid address\n");
                        fprintf(stderr,
-                               "value = %p \n t_node->startaddr = %p\n t_node->fpath =%s\n",
-                               value, t_node->startaddr, t_node->fpath);
-
+                                       "value = %p \n t_node->startaddr = %p\n\
+                                       t_node->fpath =%s\n",
+                                       value, t_node->startaddr, t_node->fpath);
 #endif
                        return t_node->startaddr;
                } else {
@@ -963,16 +929,14 @@ static char *get_fpath(long *value, struct addr_node *start)
        struct addr_node *n_node;
        t_node = start;
        n_node = t_node->next;
-       if (value == 0 || start == NULL) {
+       if (value == 0 || start == NULL)
                return NULL;
-       }
 
        while (t_node) {
                if (t_node->endaddr <= value) {
                        /* next node */
-                       if (n_node == NULL) {
+                       if (n_node == NULL)
                                return NULL;
-                       }
                        t_node = n_node;
                        n_node = n_node->next;
                } else if (t_node->startaddr <= value) {
@@ -988,38 +952,38 @@ static void print_signal_info(const siginfo_t *info, int fd)
 {
 
        int signum = info->si_signo;
-       fprintf_fd(fd, "signal = %d ", signum);
+       fprintf_fd(fd, "\nSignal: %d\n", signum);
        switch (signum) {
        case SIGINT:
-               fprintf_fd(fd, "(SIGINT)\n");
+               fprintf_fd(fd, "      (SIGINT)\n");
                break;
        case SIGILL:
-               fprintf_fd(fd, "(SIGILL)\n");
+               fprintf_fd(fd, "      (SIGILL)\n");
                break;
        case SIGABRT:
-               fprintf_fd(fd, "(SIGABRT)\n");
+               fprintf_fd(fd, "      (SIGABRT)\n");
                break;
        case SIGBUS:
-               fprintf_fd(fd, "(SIGBUS)\n");
+               fprintf_fd(fd, "      (SIGBUS)\n");
                break;
        case SIGFPE:
-               fprintf_fd(fd, "(SIGFPE)\n");
+               fprintf_fd(fd, "      (SIGFPE)\n");
                break;
        case SIGKILL:
-               fprintf_fd(fd, "(SIGKILL)\n");
+               fprintf_fd(fd, "      (SIGKILL)\n");
                break;
        case SIGSEGV:
-               fprintf_fd(fd, "(SIGSEGV)\n");
+               fprintf_fd(fd, "      (SIGSEGV)\n");
                break;
        case SIGPIPE:
-               fprintf_fd(fd, "(SIGPIPE)\n");
+               fprintf_fd(fd, "      (SIGPIPE)\n");
                break;
        default:
                fprintf_fd(fd, "\n");
        }
 
        /* print signal si_code info */
-       fprintf_fd(fd, "si_code = %d\n", info->si_code);
+       fprintf_fd(fd, "      si_code: %d\n", info->si_code);
 
        if (info->si_code <= 0 || info->si_code >= 0x80) {
                switch (info->si_code) {
@@ -1027,22 +991,22 @@ static void print_signal_info(const siginfo_t *info, int fd)
                case SI_TKILL:
                        /* FIXME : print exe name displace with info->si_pid */
                        fprintf_fd(fd,
-                                  "signal sent by tkill (sent by pid %d, uid %d) \n",
+                                  "      signal sent by tkill (sent by pid %d, uid %d)\n",
                                   info->si_pid, info->si_uid);
-                       fprintf_fd(fd, "TIMER = %d\n", SI_TIMER);
+                       fprintf_fd(fd, "      TIMER: %d\n", SI_TIMER);
                        break;
 #endif
 #ifdef SI_USER
                case SI_USER:
                        /* FIXME : print exe name displace with info->si_pid */
                        fprintf_fd(fd,
-                                  "signal sent by kill (sent by pid %d, uid %d) \n",
+                                  "      signal sent by kill (sent by pid %d, uid %d)\n",
                                   info->si_pid, info->si_uid);
                        break;
 #endif
 #ifdef SI_KERNEL
                case SI_KERNEL:
-                       fprintf_fd(fd, "signal sent by the kernel\n");
+                       fprintf_fd(fd, "      signal sent by the kernel\n");
                        break;
 #endif
                }
@@ -1050,94 +1014,94 @@ static void print_signal_info(const siginfo_t *info, int fd)
        } else if (signum == SIGILL) {
                switch (info->si_code) {
                case ILL_ILLOPC:
-                       fprintf_fd(fd, "illegal opcode\n");
+                       fprintf_fd(fd, "      illegal opcode\n");
                        break;
                case ILL_ILLOPN:
-                       fprintf_fd(fd, "illegal operand\n");
+                       fprintf_fd(fd, "      illegal operand\n");
                        break;
                case ILL_ILLADR:
-                       fprintf_fd(fd, "illegal addressing mode\n");
+                       fprintf_fd(fd, "      illegal addressing mode\n");
                        break;
                case ILL_ILLTRP:
-                       fprintf_fd(fd, "illegal trap\n");
+                       fprintf_fd(fd, "      illegal trap\n");
                        break;
                case ILL_PRVOPC:
-                       fprintf_fd(fd, "privileged opcode\n");
+                       fprintf_fd(fd, "      privileged opcode\n");
                        break;
                case ILL_PRVREG:
-                       fprintf_fd(fd, "privileged register\n");
+                       fprintf_fd(fd, "      privileged register\n");
                        break;
                case ILL_COPROC:
-                       fprintf_fd(fd, "coprocessor error\n");
+                       fprintf_fd(fd, "      coprocessor error\n");
                        break;
                case ILL_BADSTK:
-                       fprintf_fd(fd, "internal stack error\n");
+                       fprintf_fd(fd, "      internal stack error\n");
                        break;
                default:
-                       fprintf_fd(fd, "illegal si_code = %d\n", info->si_code);
+                       fprintf_fd(fd, "      illegal si_code = %d\n", info->si_code);
                        break;
                }
-               fprintf_fd(fd, "si_addr = %p\n", info->si_addr);
+               fprintf_fd(fd, "      si_addr: %p\n", info->si_addr);
        } else if (signum == SIGFPE) {
                switch (info->si_code) {
                case FPE_INTDIV:
-                       fprintf_fd(fd, "integer divide by zero\n");
+                       fprintf_fd(fd, "      integer divide by zero\n");
                        break;
                case FPE_INTOVF:
-                       fprintf_fd(fd, "integer overflow\n");
+                       fprintf_fd(fd, "      integer overflow\n");
                        break;
                case FPE_FLTDIV:
-                       fprintf_fd(fd, "floating-point divide by zero\n");
+                       fprintf_fd(fd, "      floating-point divide by zero\n");
                        break;
                case FPE_FLTOVF:
-                       fprintf_fd(fd, "floating-point overflow\n");
+                       fprintf_fd(fd, "      floating-point overflow\n");
                        break;
                case FPE_FLTUND:
-                       fprintf_fd(fd, "floating-point underflow\n");
+                       fprintf_fd(fd, "      floating-point underflow\n");
                        break;
                case FPE_FLTRES:
-                       fprintf_fd(fd, "floating-point inexact result\n");
+                       fprintf_fd(fd, "      floating-point inexact result\n");
                        break;
                case FPE_FLTINV:
-                       fprintf_fd(fd, "invalid floating-point operation\n");
+                       fprintf_fd(fd, "      invalid floating-point operation\n");
                        break;
                case FPE_FLTSUB:
-                       fprintf_fd(fd, "subscript out of range\n");
+                       fprintf_fd(fd, "      subscript out of range\n");
                        break;
                default:
-                       fprintf_fd(fd, "illegal si_code = %d\n", info->si_code);
+                       fprintf_fd(fd, "      illegal si_code: %d\n", info->si_code);
                        break;
                }
        } else if (signum == SIGSEGV) {
                switch (info->si_code) {
                case SEGV_MAPERR:
-                       fprintf_fd(fd, "address not mapped to object\n");
+                       fprintf_fd(fd, "      address not mapped to object\n");
                        break;
                case SEGV_ACCERR:
                        fprintf_fd(fd,
-                                  "invalid permissions for mapped object\n");
+                                  "      invalid permissions for mapped object\n");
                        break;
                default:
-                       fprintf_fd(fd, "illegal si_code = %d\n", info->si_code);
+                       fprintf_fd(fd, "      illegal si_code: %d\n", info->si_code);
                        break;
                }
-               fprintf_fd(fd, "si_addr = %p\n", info->si_addr);
+               fprintf_fd(fd, "      si_addr = %p\n", info->si_addr);
        } else if (signum == SIGBUS) {
                switch (info->si_code) {
                case BUS_ADRALN:
-                       fprintf_fd(fd, "invalid address alignment\n");
+                       fprintf_fd(fd, "      invalid address alignment\n");
                        break;
                case BUS_ADRERR:
-                       fprintf_fd(fd, "nonexistent physical address\n");
+                       fprintf_fd(fd, "      nonexistent physical address\n");
                        break;
                case BUS_OBJERR:
-                       fprintf_fd(fd, "object-specific hardware error\n");
+                       fprintf_fd(fd, "      object-specific hardware error\n");
                        break;
                default:
-                       fprintf_fd(fd, "illegal si_code = %d\n", info->si_code);
+                       fprintf_fd(fd, "      illegal si_code: %d\n", info->si_code);
                        break;
                }
-               fprintf_fd(fd, "si_addr = %p\n", info->si_addr);
+               fprintf_fd(fd, "      si_addr: %p\n", info->si_addr);
 
        }
 }
@@ -1178,7 +1142,7 @@ static char *remove_path(const char *cmd)
        t = r = (char *)cmd;
 
        while (*t) {
-               if (*t == '/' || *t == '.')
+               if (*t == '/')
                        r = t + 1;
                t++;
        }
@@ -1224,9 +1188,9 @@ static int check_redscreen(int pid)
        return 0;
 
 }
-
-/* localtime() can not use in signal handler, so we need signal safe version of localtime */
-inline static void get_localtime(time_t cur_time, struct tm *ctime)
+/*localtime() can not use in signal handler,
+so we need signal safe version of localtime */
+static inline void get_localtime(time_t cur_time, struct tm *ctime)
 {
        int tday[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
        int time_var = cur_time;
@@ -1243,9 +1207,9 @@ inline static void get_localtime(time_t cur_time, struct tm *ctime)
        int year = 1970;
        int leak_year = 0;
 
-       while (time_var >
-              365 + (leak_year = (((year % 4) == 0) && ((year % 100) != 0))
-                     || ((year % 400) == 0))) {
+       while (time_var > 365 + (leak_year = (((year % 4) == 0)
+                                       && ((year % 100) != 0))
+                               || ((year % 400) == 0))) {
                time_var = time_var - 365 - leak_year;
                year++;
        }
@@ -1265,7 +1229,7 @@ inline static void get_localtime(time_t cur_time, struct tm *ctime)
        ctime->tm_mon = ++i;
        ctime->tm_mday = time_var;
 
-       fprintf(stderr, "local time %d %d %d %d:%d:%d \n",
-               ctime->tm_year, ctime->tm_mon, ctime->tm_mday,
-               ctime->tm_hour, ctime->tm_min, ctime->tm_sec);
+       fprintf(stderr, "local time %d %d %d %d:%d:%d\n",
+                       ctime->tm_year, ctime->tm_mon, ctime->tm_mday,
+                       ctime->tm_hour, ctime->tm_min, ctime->tm_sec);
 }
index 58c653a65a9db9423de2addec092be207e841b98..adb95dabee33f4b5ab00a5a5d2c4a392ab33c7ca 100755 (executable)
@@ -56,8 +56,7 @@ extern "C" {
        static int trace_symbols(void *const *array, int size,
                                 struct addr_node *start, int csfd);
 
-       static struct addr_node *get_addr_list_from_maps(int fd);
-
+       static struct addr_node *get_addr_list_from_maps(int mapsfd);
        static void print_node_to_file(struct addr_node *start, int fd);
 
 #ifdef BTDEBUG