crash-stack: Fix Tizen Coding Style violations 80/129480/2 accepted/tizen/unified/20170517.014336 submit/tizen/20170517.000458 tizen_4.0.m1_release
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Tue, 16 May 2017 13:25:06 +0000 (15:25 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Tue, 16 May 2017 13:25:06 +0000 (15:25 +0200)
Rules at: https://wiki.tizen.org/wiki/Native_Platform_Coding_Idiom_and_Style_Guide

This commit brings no functional changes.

Change-Id: Ic95fd2d1e5508d602fa24ea33933448c52ce625d

src/crash-stack/crash-stack.c

index fd7bfbf..30a432c 100644 (file)
@@ -14,8 +14,8 @@
  * limitations under the License.
  *
  * Authors: Adrian Szyndela <adrian.s@samsung.com>
- *          Łukasz Stelmach <l.stelmach@samsung.com>
- *          Rafał Pietruch <r.pietruch@samsung.com>
+ *         Łukasz Stelmach <l.stelmach@samsung.com>
+ *         Rafał Pietruch <r.pietruch@samsung.com>
  */
 #define _GNU_SOURCE 1
 
@@ -216,16 +216,13 @@ static void __print_proc_file(pid_t pid, pid_t tid, const char *name)
        fprintf(outputfile, "%s:\n", buf);
 
        f = fopen(buf, "r");
-       if (NULL == f)
-       {
+       if (NULL == f) {
                fprintf(errfile, "Failed to open %s: %m\n", buf);
                return;
        }
 
        while ((r = fread(buf, 1, sizeof(buf), f)) > 0)
-       {
                fwrite(buf, r, 1, outputfile);
-       }
 
        fclose(f);
 
@@ -254,14 +251,12 @@ static Dwfl *__open_dwfl_with_pid(pid_t pid, pid_t tid)
        pid_t stopped_pid;
 
        status = __attachable(pid, tid);
-       if (-1 == status)
-       {
+       if (-1 == status) {
                fprintf(errfile, "failed to read /proc/%d/task/%d/stat: %m\n", pid, tid);
                return NULL;
        }
 
-       if (!status)
-       {
+       if (!status) {
                __print_not_attachable_process_info(pid, tid);
                return NULL;
        }
@@ -298,7 +293,7 @@ static Dwfl *__open_dwfl_with_pid(pid_t pid, pid_t tid)
                return NULL;
        }
 
-#if _ELFUTILS_PREREQ(0,158)
+#if _ELFUTILS_PREREQ(0, 158)
        if (dwfl_linux_proc_attach(dwfl, tid, true) < 0) {
                fprintf(errfile, "process %d : dwfl attach failed (%s)\n", tid, dwfl_errmsg(-1));
                dwfl_end(dwfl);
@@ -339,19 +334,41 @@ static int __get_registers_ptrace(pid_t pid)
  */
 static void __crash_stack_print_signal(int signo)
 {
+#define DEF_STR(name) [name] = #name
        const char* const signal_table[] = {
-               [SIGHUP]="SIGHUP", [SIGINT]="SIGINT", [SIGQUIT]="SIGQUIT",
-               [SIGILL]="SIGILL", [SIGTRAP]="SIGTRAP", [SIGABRT]="SIGABRT",
-               /* [SIGIOT]="SIGIOT", */ [SIGBUS]="SIGBUS", [SIGFPE]="SIGFPE",
-               [SIGKILL]="SIGKILL", [SIGUSR1]="SIGUSR1", [SIGSEGV]="SIGSEGV",
-               [SIGUSR2]="SIGUSR2", [SIGPIPE]="SIGPIPE", [SIGALRM]="SIGALRM",
-               [SIGTERM]="SIGTERM", [SIGSTKFLT]="SIGSTKFLT", [SIGCHLD]="SIGCHLD",
-               [SIGCONT]="SIGCONT", [SIGSTOP]="SIGSTOP", [SIGTSTP]="SIGTSTP",
-               [SIGTTIN]="SIGTTIN", [SIGTTOU]="SIGTTOU", [SIGURG]="SIGURG",
-               [SIGXCPU]="SIGXCPU", [SIGXFSZ]="SIGXFSZ", [SIGVTALRM]="SIGVTALRM",
-               [SIGPROF]="SIGPROF", [SIGWINCH]="SIGWINCH", [SIGIO]="SIGIO",
-               [SIGPWR]="SIGPWR", [SIGSYS]="SIGSYS", /* [SIGUNUSED]="SIGUNUSED", */
+               DEF_STR(SIGHUP),
+               DEF_STR(SIGINT),
+               DEF_STR(SIGQUIT),
+               DEF_STR(SIGILL),
+               DEF_STR(SIGTRAP),
+               DEF_STR(SIGABRT),
+               DEF_STR(SIGBUS),
+               DEF_STR(SIGFPE),
+               DEF_STR(SIGKILL),
+               DEF_STR(SIGUSR1),
+               DEF_STR(SIGUSR2),
+               DEF_STR(SIGPIPE),
+               DEF_STR(SIGSEGV),
+               DEF_STR(SIGTERM),
+               DEF_STR(SIGSTKFLT),
+               DEF_STR(SIGCHLD),
+               DEF_STR(SIGCONT),
+               DEF_STR(SIGSTOP),
+               DEF_STR(SIGTSTP),
+               DEF_STR(SIGTTIN),
+               DEF_STR(SIGTTOU),
+               DEF_STR(SIGURG),
+               DEF_STR(SIGXCPU),
+               DEF_STR(SIGXFSZ),
+               DEF_STR(SIGVTALRM),
+               DEF_STR(SIGPROF),
+               DEF_STR(SIGWINCH),
+               DEF_STR(SIGPOLL),
+               DEF_STR(SIGIO),
+               DEF_STR(SIGPWR),
+               DEF_STR(SIGSYS)
        };
+#undef DEF_STR
 
        if (SIGHUP > signo || signo > SIGSYS) {
                fprintf(errfile, "Invalid signal number: %d\n", signo);
@@ -393,10 +410,8 @@ static void __resolve_symbols_from_dwfl(ProcInfo *proc_info, Dwfl *dwfl)
                if (symbol) {
                        free(proc_info->name);
                        proc_info->name = strdup(symbol);
-               }
-               else if (proc_info->module_name != NULL) {
+               } else if (proc_info->module_name != NULL)
                        __find_symbol_in_elf(proc_info, mapping_start);
-               }
        }
 }
 
@@ -537,17 +552,15 @@ static void __crash_stack_print_exe(FILE* outputfile, pid_t pid)
  */
 static void __crash_stack_print_threads(FILE* outputfile, pid_t pid, pid_t tid)
 {
-       int threadnum=1;
+       int threadnum = 1;
        DIR *dir;
-       struct dirent *dentry=NULL;
+       struct dirent *dentry = NULL;
        char task_path[PATH_MAX];
        struct stat sb;
 
-
        snprintf(task_path, PATH_MAX, "/proc/%d/task", pid);
-       if (stat(task_path, &sb) == -1) {
+       if (stat(task_path, &sb) == -1)
                return;
-       }
 
        threadnum = sb.st_nlink - 2;
 
@@ -591,14 +604,13 @@ static void __crash_stack_print_maps(FILE* outputfile, pid_t pid)
 
        if ((fd = open(file_path, O_RDONLY)) < 0) {
                fprintf(errfile, "[crash-stack] cannot open %s\n", file_path);
-        } else {
-                /* parsing the maps to get code segment address*/
-                head = get_addr_list_from_maps(fd);
-                close(fd);
-        }
-       if (head == NULL) {
-               return;
+       } else {
+               /* parsing the maps to get code segment address*/
+               head = get_addr_list_from_maps(fd);
+               close(fd);
        }
+       if (head == NULL)
+               return;
 
        t_node = head;
        fprintf(outputfile, "\nMaps Information\n");
@@ -619,28 +631,27 @@ static void __crash_stack_print_maps(FILE* outputfile, pid_t pid)
 
 static struct addr_node *get_addr_list_from_maps(int fd)
 {
-        int fpath_len, result;
-        uintptr_t saddr;
-        uintptr_t eaddr;
-        char perm[PERM_LEN];
-        char path[PATH_MAX];
-        char addr[ADDR_LEN * 2 + 2];
-        char linebuf[BUF_SIZE];
-        struct addr_node *head = NULL;
-        struct addr_node *tail = NULL;
-        struct addr_node *t_node = NULL;
-
-        /* parsing the maps to get executable code address */
-        while (fgets_fd(linebuf, BUF_SIZE, fd) != NULL) {
-                memset(path, 0, PATH_MAX);
-                result = sscanf(linebuf, "%s %s %*s %*s %*s %s ", addr, perm, path);
-                if (result < 0)
-                        continue;
-                perm[PERM_LEN - 1] = 0;
-                /* rwxp */
-                if ((perm[2] == 'x' && path[0] == '/') ||
-                   (perm[1] == 'w' && path[0] != '/'))
-               {
+       int fpath_len, result;
+       uintptr_t saddr;
+       uintptr_t eaddr;
+       char perm[PERM_LEN];
+       char path[PATH_MAX];
+       char addr[ADDR_LEN * 2 + 2];
+       char linebuf[BUF_SIZE];
+       struct addr_node *head = NULL;
+       struct addr_node *tail = NULL;
+       struct addr_node *t_node = NULL;
+
+       /* parsing the maps to get executable code address */
+       while (fgets_fd(linebuf, BUF_SIZE, fd) != NULL) {
+               memset(path, 0, PATH_MAX);
+               result = sscanf(linebuf, "%s %s %*s %*s %*s %s ", addr, perm, path);
+               if (result < 0)
+                       continue;
+               perm[PERM_LEN - 1] = 0;
+               /* rwxp */
+               if ((perm[2] == 'x' && path[0] == '/') ||
+                   (perm[1] == 'w' && path[0] != '/')) {
                        char* addr2 = strchr(addr, '-');
                        *(addr2++) = '\0';
                        /* add addr node to list */
@@ -710,17 +721,17 @@ static void free_all_nodes(struct addr_node *start)
 
 static char *fgets_fd(char *str, int len, int fd)
 {
-        char ch;
-        register char *cs;
-        int num = 0;
-
-        cs = str;
-        while (--len > 0 && (num = read(fd, &ch, 1) > 0)) {
-                if ((*cs++ = ch) == '\n')
-                        break;
-        }
-        *cs = '\0';
-        return (num == 0 && cs == str) ? NULL : str;
+       char ch;
+       register char *cs;
+       int num = 0;
+
+       cs = str;
+       while (--len > 0 && (num = read(fd, &ch, 1) > 0)) {
+               if ((*cs++ = ch) == '\n')
+                       break;
+       }
+       *cs = '\0';
+       return (num == 0 && cs == str) ? NULL : str;
 }
 
 /**
@@ -739,72 +750,72 @@ static void __crash_stack_print_meminfo(FILE* outputfile, pid_t pid)
 
        fprintf(outputfile, "\nMemory information\n");
 
-        if ((fd = open("/proc/meminfo", O_RDONLY)) < 0) {
-                fprintf(errfile, "[crash-stack] cannot open /proc/meminfo\n");
-        } else {
-                while (fgets_fd(linebuf, BUF_SIZE, fd) != NULL) {
-                        sscanf(linebuf, "%s %s %*s", infoname, memsize);
-                        if (strcmp("MemTotal:", infoname) == 0) {
-                                fprintf(outputfile, "%s %8s KB\n", infoname, memsize);
-                        } else if (strcmp("MemFree:", infoname) == 0) {
-                                fprintf(outputfile, "%s  %8s KB\n", infoname, memsize);
-                        } else if (strcmp("Buffers:", infoname) == 0) {
-                                fprintf(outputfile, "%s  %8s KB\n", infoname, memsize);
-                        } else if (strcmp("Cached:", infoname) == 0) {
-                                fprintf(outputfile, "%s   %8s KB\n", infoname, memsize);
-                                break;
-                        }
-                }
-                close(fd);
-        }
+       if ((fd = open("/proc/meminfo", O_RDONLY)) < 0) {
+               fprintf(errfile, "[crash-stack] cannot open /proc/meminfo\n");
+       } else {
+               while (fgets_fd(linebuf, BUF_SIZE, fd) != NULL) {
+                       sscanf(linebuf, "%s %s %*s", infoname, memsize);
+                       if (strcmp("MemTotal:", infoname) == 0) {
+                               fprintf(outputfile, "%s %8s KB\n", infoname, memsize);
+                       } else if (strcmp("MemFree:", infoname) == 0) {
+                               fprintf(outputfile, "%s  %8s KB\n", infoname, memsize);
+                       } else if (strcmp("Buffers:", infoname) == 0) {
+                               fprintf(outputfile, "%s  %8s KB\n", infoname, memsize);
+                       } else if (strcmp("Cached:", infoname) == 0) {
+                               fprintf(outputfile, "%s   %8s KB\n", infoname, memsize);
+                               break;
+                       }
+               }
+               close(fd);
+       }
 
        snprintf(file_path, PATH_MAX, "/proc/%d/status", pid);
-        if ((fd = open(file_path, O_RDONLY)) < 0) {
-                fprintf(errfile, "[crash-stack] cannot open %s\n", file_path);
-        } else {
-                while (fgets_fd(linebuf, BUF_SIZE, fd) != NULL) {
-                        sscanf(linebuf, "%s %s %*s", infoname, memsize);
-                        if (strcmp("VmPeak:", infoname) == 0) {
-                                fprintf(outputfile, "%s   %8s KB\n", infoname,
-                                                memsize);
-                        } else if (strcmp("VmSize:", infoname) == 0) {
-                                fprintf(outputfile, "%s   %8s KB\n", infoname,
-                                                memsize);
-                        } else if (strcmp("VmLck:", infoname) == 0) {
-                                fprintf(outputfile, "%s    %8s KB\n", infoname,
-                                                memsize);
-                        } else if (strcmp("VmPin:", infoname) == 0) {
-                                fprintf(outputfile, "%s    %8s KB\n", infoname,
-                                                memsize);
-                        } else if (strcmp("VmHWM:", infoname) == 0) {
-                                fprintf(outputfile, "%s    %8s KB\n",
-                                                infoname, memsize);
-                        } else if (strcmp("VmRSS:", infoname) == 0) {
-                                fprintf(outputfile, "%s    %8s KB\n",
-                                                infoname, memsize);
-                        } else if (strcmp("VmData:", infoname) == 0) {
-                                fprintf(outputfile, "%s   %8s KB\n",
-                                                infoname, memsize);
-                        } else if (strcmp("VmStk:", infoname) == 0) {
-                                fprintf(outputfile, "%s    %8s KB\n",
-                                                infoname, memsize);
-                        } else if (strcmp("VmExe:", infoname) == 0) {
-                                fprintf(outputfile, "%s    %8s KB\n",
-                                                infoname, memsize);
-                        } else if (strcmp("VmLib:", infoname) == 0) {
-                                fprintf(outputfile, "%s    %8s KB\n",
-                                                infoname, memsize);
-                        } else if (strcmp("VmPTE:", infoname) == 0) {
-                                fprintf(outputfile, "%s    %8s KB\n",
-                                                infoname, memsize);
-                        } else if (strcmp("VmSwap:", infoname) == 0) {
-                                fprintf(outputfile, "%s   %8s KB\n",
-                                                infoname, memsize);
-                                break;
-                        }
-                }
-                close(fd);
-        }
+       if ((fd = open(file_path, O_RDONLY)) < 0) {
+               fprintf(errfile, "[crash-stack] cannot open %s\n", file_path);
+       } else {
+               while (fgets_fd(linebuf, BUF_SIZE, fd) != NULL) {
+                       sscanf(linebuf, "%s %s %*s", infoname, memsize);
+                       if (strcmp("VmPeak:", infoname) == 0) {
+                               fprintf(outputfile, "%s   %8s KB\n", infoname,
+                                               memsize);
+                       } else if (strcmp("VmSize:", infoname) == 0) {
+                               fprintf(outputfile, "%s   %8s KB\n", infoname,
+                                               memsize);
+                       } else if (strcmp("VmLck:", infoname) == 0) {
+                               fprintf(outputfile, "%s    %8s KB\n", infoname,
+                                               memsize);
+                       } else if (strcmp("VmPin:", infoname) == 0) {
+                               fprintf(outputfile, "%s    %8s KB\n", infoname,
+                                               memsize);
+                       } else if (strcmp("VmHWM:", infoname) == 0) {
+                               fprintf(outputfile, "%s    %8s KB\n",
+                                               infoname, memsize);
+                       } else if (strcmp("VmRSS:", infoname) == 0) {
+                               fprintf(outputfile, "%s    %8s KB\n",
+                                               infoname, memsize);
+                       } else if (strcmp("VmData:", infoname) == 0) {
+                               fprintf(outputfile, "%s   %8s KB\n",
+                                               infoname, memsize);
+                       } else if (strcmp("VmStk:", infoname) == 0) {
+                               fprintf(outputfile, "%s    %8s KB\n",
+                                               infoname, memsize);
+                       } else if (strcmp("VmExe:", infoname) == 0) {
+                               fprintf(outputfile, "%s    %8s KB\n",
+                                               infoname, memsize);
+                       } else if (strcmp("VmLib:", infoname) == 0) {
+                               fprintf(outputfile, "%s    %8s KB\n",
+                                               infoname, memsize);
+                       } else if (strcmp("VmPTE:", infoname) == 0) {
+                               fprintf(outputfile, "%s    %8s KB\n",
+                                               infoname, memsize);
+                       } else if (strcmp("VmSwap:", infoname) == 0) {
+                               fprintf(outputfile, "%s   %8s KB\n",
+                                               infoname, memsize);
+                               break;
+                       }
+               }
+               close(fd);
+       }
 }
 
 /**
@@ -875,9 +886,8 @@ static int find_crash_tid(int pid)
        struct stat sb;
 
        snprintf(task_path, PATH_MAX, "/proc/%d/task", pid);
-       if (stat(task_path, &sb) == -1) {
+       if (stat(task_path, &sb) == -1)
                return -1;
-       }
 
        threadnum = sb.st_nlink - 2;