Simulate faulted package
authorSung-jae Park <nicesj.park@samsung.com>
Thu, 10 Oct 2013 16:06:13 +0000 (01:06 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Fri, 11 Oct 2013 01:08:27 +0000 (10:08 +0900)
Change-Id: Icbf8b308e4cf66ec5381b97388ccc0dc6c223385

include/package.h
src/package.c
src/server.c
util_liveinfo/src/liveinfo.c
util_liveinfo/src/node.c

index df57123..ec9c172 100644 (file)
@@ -126,5 +126,6 @@ extern int package_init(void);
 extern int package_fini(void);
 
 extern int package_is_enabled(const char *appid);
+extern int package_faulted(struct pkg_info *info);
 
 /* End of a file */
index 366d806..13bbbf9 100644 (file)
@@ -1574,4 +1574,30 @@ HAPI int package_is_enabled(const char *appid)
        return enabled == true;
 }
 
+HAPI int package_faulted(struct pkg_info *pkg)
+{
+       Eina_List *l;
+       Eina_List *n;
+       struct slave_node *slave;
+       struct inst_info *inst;
+
+       slave = package_slave(pkg);
+       if (!slave) {
+               ErrPrint("Package has no slave?\n");
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       /* Emulated fault routine */
+       // (void)package_set_fault_info(pkg, util_timestamp(), slave_name(slave), __func__);
+       fault_broadcast_info(package_name(pkg), slave_name(slave), __func__);
+
+       DbgPrint("package: %s (forucely faulted %s)\n", package_name(pkg), slave_name(slave));
+       EINA_LIST_FOREACH_SAFE(pkg->inst_list, l, n, inst) {
+               DbgPrint("Destroy instance %p\n", inst);
+               instance_destroy(inst, INSTANCE_DESTROY_FAULT);
+       }
+
+       return LB_STATUS_SUCCESS;
+}
+
 /* End of a file */
index e4e4668..d474df9 100644 (file)
@@ -6586,6 +6586,22 @@ static struct packet *liveinfo_pkg_ctrl(pid_t pid, int handle, const struct pack
                        (void)instance_destroy(inst, INSTANCE_DESTROY_DEFAULT);
                        fprintf(fp, "%d\n", 0);
                }
+       } else if (!strcmp(cmd, "faultinst")) {
+               struct inst_info *inst;
+               inst = package_find_instance_by_id(pkgname, id);
+               if (!inst) {
+                       fprintf(fp, "%d\n", ENOENT);
+               } else {
+                       struct pkg_info *pkg;
+
+                       pkg = instance_package(inst);
+                       if (!pkg) {
+                               fprintf(fp, "%d\n", EFAULT);
+                       } else {
+                               (void)package_faulted(pkg);
+                               fprintf(fp, "%d\n", 0);
+                       }
+               }
        }
 
        fprintf(fp, "EOD\n");
index 9ca53b3..d01f00f 100644 (file)
@@ -170,8 +170,9 @@ static void provider_del_cb(struct node *node)
        struct slave *info;
 
        info = node_data(node);
-       if (!info)
+       if (!info) {
                return;
+       }
 
        free(info->pkgname);
        free(info->abi);
@@ -184,8 +185,9 @@ static void package_del_cb(struct node *node)
        struct package *info;
 
        info = node_data(node);
-       if (!info)
+       if (!info) {
                return;
+       }
 
        free(info->pkgid);
        free(info->slavename);
@@ -198,8 +200,9 @@ static void inst_del_cb(struct node *node)
        struct instance *info;
 
        info = node_data(node);
-       if (!info)
+       if (!info) {
                return;
+       }
 
        free(info->id);
        free(info->cluster);
@@ -269,16 +272,18 @@ static void ls(void)
 
                        printf(" %5.2f %6s %10s %10s %4dx%-4d ", info->period, info->state, info->cluster, info->category, info->width, info->height);
                        snprintf(buf, sizeof(buf), "/opt/usr/share/live_magazine/reader/%s", node_name(node));
-                       if (lstat(buf, &stat) < 0)
+                       if (lstat(buf, &stat) < 0) {
                                printf("%3d ERR ", errno);
-                       else
+                       } else {
                                printf("%2.2lf KB ", (double)stat.st_size / 1024.0f);
+                       }
                }
 
-               if (node_type(node) == NODE_DIR)
+               if (node_type(node) == NODE_DIR) {
                        printf("%s/", node_name(node));
-               else if (node_type(node) == NODE_FILE)
+               } else if (node_type(node) == NODE_FILE) {
                        printf("%s", node_name(node));
+               }
 
                printf("\n");
                node = node_next_sibling(node);
@@ -478,6 +483,56 @@ static void send_inst_delete(void)
        s_info.age++;
 }
 
+static void send_inst_fault(void)
+{
+       struct packet *packet;
+       struct node *parent;
+       const char *name;
+       struct instance *inst;
+       int ret;
+
+       if (s_info.cmd != NOP) {
+               printf("Previous command is not finished\n");
+               return;
+       }
+
+       parent = node_parent(s_info.targetdir);
+       if (!parent) {
+               printf("Invalid argument\n");
+               return;
+       }
+
+       if (!node_parent(parent)) {
+               printf("Invalid argument\n");
+               return;
+       }
+
+       name = node_name(node_parent(parent));
+       if (!name || strcmp(name, "package")) {
+               printf("Invalid argument\n");
+               return;
+       }
+
+       inst = node_data(s_info.targetdir);
+       name = node_name(parent);
+
+       packet = packet_create_noack("pkg_ctrl", "sss", "faultinst", name, inst->id);
+       if (!packet) {
+               printf("Failed to create a packet\n");
+               return;
+       }
+
+       ret = com_core_packet_send_only(s_info.fd, packet);
+       packet_destroy(packet);
+       if (ret < 0) {
+               printf("Failed to send a packet: %d\n", ret);
+               return;
+       }
+
+       s_info.cmd = INST_CTRL;
+       s_info.age++;
+}
+
 static void send_inst_list(const char *pkgname)
 {
        struct packet *packet;
@@ -533,8 +588,9 @@ static inline void init_directory(void)
 {
        struct node *node;
        s_info.rootdir = node_create(NULL, NULL, NODE_DIR);
-       if (!s_info.rootdir)
+       if (!s_info.rootdir) {
                return;
+       }
        node_set_mode(s_info.rootdir, NODE_READ | NODE_EXEC);
 
        node = node_create(s_info.rootdir, "provider", NODE_DIR);
@@ -562,7 +618,7 @@ static inline void fini_directory(void)
 {
 }
 
-static inline struct node *update_target_dir(const char *cmd)
+static struct node *update_target_dir(const char *cmd)
 {
        struct node *node;
 
@@ -577,8 +633,9 @@ static int get_token(const char *src, char *out)
        int len = 0;
        while (*src && *src == ' ') src++;
 
-       if (!*src)
+       if (!*src) {
                return 0;
+       }
 
        while (*src && *src != ' ') {
                *out++ = *src++;
@@ -707,7 +764,9 @@ static int do_set(const char *cmd)
        i = get_token(cmd, variable);
 
        cmd += i;
-       while (*cmd && *cmd == ' ') cmd++;
+       while (*cmd && *cmd == ' ') {
+               cmd++;
+       }
 
        if (!i || !*cmd) {
                printf("Invalid argument(%s): set [VAR] [VAL]\n", cmd);
@@ -739,8 +798,9 @@ static inline int do_ls(const char *cmd)
 
        cmd += 2;
 
-       while (*cmd && *cmd == ' ')
+       while (*cmd && *cmd == ' ') {
                cmd++;
+       }
 
        s_info.targetdir = *cmd ? update_target_dir(cmd) : s_info.curdir;
        if (!s_info.targetdir) {
@@ -790,11 +850,13 @@ static inline int do_cd(const char *cmd)
 {
        cmd += 2;
 
-       while (*cmd && *cmd == ' ')
+       while (*cmd && *cmd == ' ') {
                 cmd++;
+       }
 
-       if (!*cmd)
+       if (!*cmd) {
                return -1;
+       }
 
        if (s_info.cmd != NOP) {
                printf("Waiting the server response\n");
@@ -825,8 +887,9 @@ static inline int do_rm(const char *cmd)
 {
        cmd += 2;
        while (*cmd && *cmd == ' ') cmd++;
-       if (!*cmd)
+       if (!*cmd) {
                return -1;
+       }
 
        if (s_info.cmd != NOP) {
                printf("Waiting the server response\n");
@@ -848,6 +911,34 @@ static inline int do_rm(const char *cmd)
        return 0;
 }
 
+static inline int do_fault(const char *cmd)
+{
+       cmd += 5;
+       while (*cmd && *cmd == ' ') cmd++;
+       if (!*cmd) {
+               return -1;
+       }
+
+       if (s_info.cmd != NOP) {
+               printf("Waiting the server response\n");
+               return -EBUSY;
+       }
+
+       s_info.targetdir = update_target_dir(cmd);
+       if (!s_info.targetdir) {
+               printf("%s is not exists\n", cmd);
+               return -ENOENT;
+       }
+
+       if (!(node_mode(s_info.targetdir) & NODE_WRITE)) {
+               printf("Access denied %s\n", cmd);
+               return -EACCES;
+       }
+
+       send_inst_fault();
+       return 0;
+}
+
 #if !defined(WCOREDUMP)
 #define WCOREDUMP(a)   0
 #endif
@@ -858,9 +949,13 @@ static void do_sh(const char *cmd)
 
        cmd += 3;
 
-       while (*cmd && *cmd == ' ') cmd++;
-       if (!*cmd)
+       while (*cmd && *cmd == ' ') {
+               cmd++;
+       }
+
+       if (!*cmd) {
                return;
+       }
 
        pid = fork();
        if (pid == 0) {
@@ -868,12 +963,14 @@ static void do_sh(const char *cmd)
                int idx;
                idx = 0;
 
-               while (idx < (sizeof(command) - 1) && *cmd && *cmd != ' ')
+               while (idx < (sizeof(command) - 1) && *cmd && *cmd != ' ') {
                        command[idx++] = *cmd++;
+               }
                command[idx] = '\0';
 
-               if (execl(command, cmd, NULL) < 0)
+               if (execl(command, cmd, NULL) < 0) {
                        printf("Failed to execute: %s\n", strerror(errno));
+               }
 
                exit(0);
        } else if (pid < 0) {
@@ -903,13 +1000,17 @@ static inline int get_pixmap_size(Display *disp, Pixmap id, int *x, int *y, unsi
        int _x;
        int _y;
 
-       if (!x)
+       if (!x) {
                x = &_x;
-       if (!y)
+       }
+
+       if (!y) {
                y = &_y;
+       }
 
-       if (!XGetGeometry(disp, id, &dummy_win, x, y, w, h, &dummy_border, &dummy_depth))
+       if (!XGetGeometry(disp, id, &dummy_win, x, y, w, h, &dummy_border, &dummy_depth)) {
                return -EFAULT;
+       }
 
        return 0;
 }
@@ -946,8 +1047,9 @@ static inline int do_capture(Display *disp, Pixmap id, const char *filename)
        si.shmaddr = shmat(si.shmid, NULL, 0);
        if (si.shmaddr == (void *)-1) {
 
-               if (shmctl(si.shmid, IPC_RMID, 0) < 0)
+               if (shmctl(si.shmid, IPC_RMID, 0) < 0) {
                        printf("shmctl: %s\n", strerror(errno));
+               }
 
                return -EFAULT;
        }
@@ -958,11 +1060,13 @@ static inline int do_capture(Display *disp, Pixmap id, const char *filename)
         */
        xim = XShmCreateImage(disp, visual, 24 /* (depth << 3) */, ZPixmap, NULL, &si, w, h);
        if (xim == NULL) {
-               if (shmdt(si.shmaddr) < 0)
+               if (shmdt(si.shmaddr) < 0) {
                        printf("shmdt: %s\n", strerror(errno));
+               }
 
-               if (shmctl(si.shmid, IPC_RMID, 0) < 0)
+               if (shmctl(si.shmid, IPC_RMID, 0) < 0) {
                        printf("shmctl: %s\n", strerror(errno));
+               }
 
                return -EFAULT;
        }
@@ -975,10 +1079,13 @@ static inline int do_capture(Display *disp, Pixmap id, const char *filename)
 
        fd = open(filename, O_CREAT | O_RDWR, 0644);
        if (fd >= 0) {
-               if (write(fd, xim->data, bufsz) != bufsz)
+               if (write(fd, xim->data, bufsz) != bufsz) {
                        printf("Data is not fully written\n");
+               }
 
-               close(fd);
+               if (close(fd) < 0) {
+                       printf("close: %s\n", strerror(errno));
+               }
        } else {
                printf("Error: %sn\n", strerror(errno));
        }
@@ -986,11 +1093,13 @@ static inline int do_capture(Display *disp, Pixmap id, const char *filename)
        XShmDetach(disp, &si);
        XDestroyImage(xim);
 
-       if (shmdt(si.shmaddr) < 0)
+       if (shmdt(si.shmaddr) < 0) {
                printf("shmdt: %s\n", strerror(errno));
+       }
 
-       if (shmctl(si.shmid, IPC_RMID, 0) < 0)
+       if (shmctl(si.shmid, IPC_RMID, 0) < 0) {
                printf("shmctl: %s\n", strerror(errno));
+       }
 
        return 0;
 }
@@ -1001,9 +1110,13 @@ static void do_x(const char *cmd)
 
        cmd += 2;
 
-       while (*cmd && *cmd == ' ') cmd++;
-       if (!*cmd)
+       while (*cmd && *cmd == ' ') {
+               cmd++;
+       }
+
+       if (!*cmd) {
                return;
+       }
 
        disp = XOpenDisplay(NULL);
        if (!disp) {
@@ -1043,8 +1156,9 @@ static void do_x(const char *cmd)
                        printf("Invalid argument\nx capture WINID_DEC FILENAME (%s)\n", cmd);
                        return;
                }
-               if (do_capture(disp, winId, filename) == 0)
+               if (do_capture(disp, winId, filename) == 0) {
                        printf("Captured: %s\n", filename);
+               }
        } else if (!strncasecmp(cmd, "resize ", 7)) {
                unsigned int winId;
                int w;
@@ -1111,8 +1225,9 @@ static inline void put_command(const char *cmd)
 static inline const char *get_command(int idx)
 {
        idx = s_info.history_top + idx;
-       while (idx < 0)
+       while (idx < 0) {
                idx += (sizeof(s_info.history) / sizeof(s_info.history[0]));
+       }
 
        return s_info.history[idx];
 }
@@ -1120,28 +1235,39 @@ static inline const char *get_command(int idx)
 static inline void do_command(const char *cmd)
 {
        /* Skip the first spaces */
-       while (*cmd && *cmd == ' ') cmd++;
+       while (*cmd && *cmd == ' ') {
+               cmd++;
+       }
 
        if (strlen(cmd) && *cmd != '#') {
                if (!strncasecmp(cmd, "exit", 4) || !strncasecmp(cmd, "quit", 4)) {
                        ecore_main_loop_quit();
                } else if (!strncasecmp(cmd, "set ", 4)) {
-                       if (do_set(cmd) == 0)
+                       if (do_set(cmd) == 0) {
                                return;
+                       }
                } else if (!strncasecmp(cmd, "stat ", 5)) {
                        do_stat(cmd);
                } else if (!strncasecmp(cmd, "get ", 4)) {
-                       if (do_get(cmd) == 0)
+                       if (do_get(cmd) == 0) {
                                return;
+                       }
                } else if (!strncasecmp(cmd, "ls", 2)) {
-                       if (do_ls(cmd) == 0)
+                       if (do_ls(cmd) == 0) {
                                return;
+                       }
                } else if (!strncasecmp(cmd, "cd", 2)) {
-                       if (do_cd(cmd) == 0)
+                       if (do_cd(cmd) == 0) {
                                return;
+                       }
                } else if (!strncasecmp(cmd, "rm", 2)) {
-                       if (do_rm(cmd) == 0)
+                       if (do_rm(cmd) == 0) {
+                               return;
+                       }
+               } else if (!strncasecmp(cmd, "fault", 5)) {
+                       if (do_fault(cmd) == 0) {
                                return;
+                       }
                } else if (!strncasecmp(cmd, "sh ", 3)) {
                        do_sh(cmd);
                } else if (!strncasecmp(cmd, "x ", 2)) {
@@ -1202,8 +1328,9 @@ static Eina_Bool input_cb(void *data, Ecore_Fd_Handler *fd_handler)
                                }
                                break;
                        case 0x42: /* DOWN */
-                               if (s_info.history_idx >= 0)
+                               if (s_info.history_idx >= 0) {
                                        break;
+                               }
 
                                printf("%s2K%s1G", escape_str, escape_str);
                                tmp = get_command(++s_info.history_idx);
@@ -1255,8 +1382,9 @@ static Eina_Bool input_cb(void *data, Ecore_Fd_Handler *fd_handler)
                                idx = s_info.quick_idx;
                        }
 
-                       if (!s_info.quick_search_node)
+                       if (!s_info.quick_search_node) {
                                break;
+                       }
 
                        printf("%s2K%s1G", escape_str, escape_str);
                        strcpy(cmd_buffer + idx, node_name(s_info.quick_search_node));
@@ -1267,8 +1395,9 @@ static Eina_Bool input_cb(void *data, Ecore_Fd_Handler *fd_handler)
                case '\r':
                        cmd_buffer[idx] = '\0';
                        idx = 0;
-                       if (s_info.input_fd == STDIN_FILENO || s_info.verbose)
+                       if (s_info.input_fd == STDIN_FILENO || s_info.verbose) {
                                putc((int)'\n', stdout);
+                       }
                        do_command(cmd_buffer);
                        put_command(cmd_buffer);
                        memset(cmd_buffer, 0, sizeof(cmd_buffer));
@@ -1280,8 +1409,9 @@ static Eina_Bool input_cb(void *data, Ecore_Fd_Handler *fd_handler)
                default:
                        cmd_buffer[idx++] = ch;
 
-                       if (s_info.input_fd == STDIN_FILENO || s_info.verbose)
+                       if (s_info.input_fd == STDIN_FILENO || s_info.verbose) {
                                putc((int)ch, stdout);
+                       }
 
                        if (idx == sizeof(cmd_buffer) - 1) {
                                cmd_buffer[idx] = '\0';
@@ -1292,8 +1422,9 @@ static Eina_Bool input_cb(void *data, Ecore_Fd_Handler *fd_handler)
                }
        }
 
-       if (ret < 0 && !fd_handler)
+       if (ret < 0 && !fd_handler) {
                ecore_main_loop_quit();
+       }
 
        return ECORE_CALLBACK_RENEW;
 }
@@ -1340,8 +1471,9 @@ static void processing_line_buffer(const char *buffer)
                        }
 
                        pkginfo->pkgid = strdup("conf.file");
-                       if (!pkginfo->pkgid)
+                       if (!pkginfo->pkgid) {
                                printf("Error: %s\n", strerror(errno));
+                       }
 
                        pkginfo->primary = 1;
 
@@ -1372,12 +1504,14 @@ static void processing_line_buffer(const char *buffer)
                node_set_age(node, s_info.age);
 
                pkginfo->slavename = strdup(slavename);
-               if (!pkginfo->slavename)
+               if (!pkginfo->slavename) {
                        printf("Error: %s\n", strerror(errno));
+               }
 
                pkginfo->abi = strdup(abi);
-               if (!pkginfo->abi)
+               if (!pkginfo->abi) {
                        printf("Error: %s\n", strerror(errno));
+               }
 
                pkginfo->pid = pid;
                pkginfo->refcnt = refcnt;
@@ -1416,16 +1550,19 @@ static void processing_line_buffer(const char *buffer)
                free(slaveinfo->state);
 
                slaveinfo->pkgname = strdup(pkgname);
-               if (!slaveinfo->pkgname)
+               if (!slaveinfo->pkgname) {
                        printf("Error: %s\n", strerror(errno));
+               }
 
                slaveinfo->abi = strdup(abi);
-               if (!slaveinfo->abi)
+               if (!slaveinfo->abi) {
                        printf("Error: %s\n", strerror(errno));
+               }
 
                slaveinfo->state = strdup(state);
-               if (!slaveinfo->state)
+               if (!slaveinfo->state) {
                        printf("Error: %s\n", strerror(errno));
+               }
 
                slaveinfo->pid = pid;
                slaveinfo->secured = secured;
@@ -1472,20 +1609,24 @@ static void processing_line_buffer(const char *buffer)
                free(instinfo->state);
 
                instinfo->id = strdup(inst_id);
-               if (!instinfo->id)
+               if (!instinfo->id) {
                        printf("Error: %s\n", strerror(errno));
+               }
 
                instinfo->cluster = strdup(cluster);
-               if (!instinfo->cluster)
+               if (!instinfo->cluster) {
                        printf("Error: %s\n", strerror(errno));
+               }
 
                instinfo->category = strdup(category);
-               if (!instinfo->category)
+               if (!instinfo->category) {
                        printf("Error: %s\n", strerror(errno));
+               }
 
                instinfo->state = strdup(state);
-               if (!instinfo->state)
+               if (!instinfo->state) {
                        printf("Error: %s\n", strerror(errno));
+               }
 
                instinfo->period = period;
                instinfo->width = width;
@@ -1641,7 +1782,9 @@ static int ret_cb(pid_t pid, int handle, const struct packet *packet, void *data
        s_info.fd_handler = ecore_main_fd_handler_add(s_info.fifo_handle, ECORE_FD_READ, read_cb, NULL, NULL, NULL);
        if (!s_info.fd_handler) {
                printf("Failed to add a fd handler\n");
-               close(s_info.fifo_handle);
+               if (close(s_info.fifo_handle) < 0) {
+                       printf("close: %s\n", strerror(errno));
+               }
                s_info.fifo_handle = -EINVAL;
                ecore_main_loop_quit();
                return -EFAULT;
@@ -1650,8 +1793,9 @@ static int ret_cb(pid_t pid, int handle, const struct packet *packet, void *data
        prompt(NULL);
 
        if (s_info.input_fd == STDIN_FILENO) {
-               if (fcntl(s_info.input_fd, F_SETFL, O_NONBLOCK) < 0)
+               if (fcntl(s_info.input_fd, F_SETFL, O_NONBLOCK) < 0) {
                        printf("Error: %s\n", strerror(errno));
+               }
 
                s_info.in_handler = ecore_main_fd_handler_add(s_info.input_fd, ECORE_FD_READ, input_cb, NULL, NULL, NULL);
                if (!s_info.in_handler) {
@@ -1730,7 +1874,9 @@ int main(int argc, char *argv[])
 
                        if (s_info.input_fd != STDIN_FILENO) {
                                /* Close the previously, opened file */
-                               close(s_info.input_fd);
+                               if (close(s_info.input_fd) < 0) {
+                                       printf("close: %s\n", strerror(errno));
+                               }
                        }
 
                        s_info.input_fd = open(optarg, O_RDONLY);
@@ -1788,15 +1934,17 @@ int main(int argc, char *argv[])
                        ttystate.c_lflag &= ~(ICANON | ECHO);
                        ttystate.c_cc[VMIN] = 1;
 
-                       if (tcsetattr(s_info.input_fd, TCSANOW, &ttystate) < 0)
+                       if (tcsetattr(s_info.input_fd, TCSANOW, &ttystate) < 0) {
                                printf("Error: %s\n", strerror(errno));
+                       }
                }
        } else {
                printf("Batch mode enabled\n");
        }
 
-       if (setvbuf(stdout, (char *)NULL, _IONBF, 0) != 0)
+       if (setvbuf(stdout, (char *)NULL, _IONBF, 0) != 0) {
                printf("Error: %s\n", strerror(errno));
+       }
 
        init_directory();
 
@@ -1817,14 +1965,19 @@ int main(int argc, char *argv[])
 
        if (s_info.input_fd == STDIN_FILENO) {
                ttystate.c_lflag |= ICANON | ECHO;
-               if (tcsetattr(s_info.input_fd, TCSANOW, &ttystate) < 0)
+               if (tcsetattr(s_info.input_fd, TCSANOW, &ttystate) < 0) {
                        printf("Error: %s\n", strerror(errno));
+               }
        } else {
-               close(s_info.input_fd);
+               if (close(s_info.input_fd) < 0) {
+                       printf("close: %s\n", strerror(errno));
+               }
        }
 
        if (s_info.fifo_handle > 0) {
-               close(s_info.fifo_handle);
+               if (close(s_info.fifo_handle) < 0) {
+                       printf("close: %s\n", strerror(errno));
+               }
                s_info.fifo_handle = -EINVAL;
        }
 
index d68f096..bbe9929 100644 (file)
@@ -39,8 +39,9 @@ char *node_to_abspath(const struct node *node)
        }
 
        path = malloc(len + 3); /* '/' and '\0' */
-       if (!path)
+       if (!path) {
                return NULL;
+       }
 
        if (!len) {
                path[0] = '/';
@@ -64,14 +65,18 @@ char *node_to_abspath(const struct node *node)
 
 static inline int next_state(int from, char ch)
 {
-       switch ( ch )
-       {
-               case '\0':
-               case '/':
-                       return 1;
-               case '.':
-                       if ( from == 1 ) return 2;
-                       if ( from == 2 ) return 3;
+       switch (ch) {
+       case '\0':
+       case '/':
+               return 1;
+       case '.':
+               if (from == 1) {
+                       return 2;
+               }
+
+               if (from == 2) {
+                       return 3;
+               }
        }
 
        return 4;
@@ -85,45 +90,55 @@ static inline void abspath(const char* pBuffer, char* pRet)
        int src_idx = 0;
        int src_len = strlen(pBuffer);
        pRet[idx] = '/';
-       idx ++;
+       idx++;
 
        while (src_idx <= src_len) {
                from = state;
                state = next_state(from, pBuffer[src_idx]);
 
                switch (from) {
-                       case 1:
-                               if ( state != 1 ) {
-                                       pRet[idx] = pBuffer[src_idx];
-                                       idx ++;
-                               }
-                               break;
-                       case 2:
-                               if ( state == 1 ) {
-                                       if ( idx > 1 ) idx --;
-                               } else {
-                                       pRet[idx] = pBuffer[src_idx];
-                                       idx ++;
-                               }
-                               break;
-                       case 3:
-                               // Only can go to the 1 or 4
-                               if ( state == 1 ) {
-                                       idx -= 2;
-                                       if ( idx < 1 ) idx = 1;
-
-                                       while ( idx > 1 && pRet[idx] != '/' ) idx --; /* Remove .. */
-                                       if ( idx > 1 && pRet[idx] == '/' ) idx --;
-                                       while ( idx > 1 && pRet[idx] != '/' ) idx --; /* Remove parent folder */
+               case 1:
+                       if (state != 1) {
+                               pRet[idx] = pBuffer[src_idx];
+                               idx++;
+                       }
+                       break;
+               case 2:
+                       if (state == 1) {
+                               if (idx > 1) {
+                                       idx--;
                                }
-                       case 4:
+                       } else {
                                pRet[idx] = pBuffer[src_idx];
                                idx ++;
-                               break;
+                       }
+                       break;
+               case 3:
+                       // Only can go to the 1 or 4
+                       if (state == 1) {
+                               idx -= 2;
+                               if (idx < 1) {
+                                       idx = 1;
+                               }
+
+                               while (idx > 1 && pRet[idx] != '/') {
+                                       idx--; /* Remove .. */
+                               }
+                               if (idx > 1 && pRet[idx] == '/') {
+                                       idx--;
+                               }
+                               while (idx > 1 && pRet[idx] != '/') {
+                                       idx--; /* Remove parent folder */
+                               }
+                       }
+               case 4:
+                       pRet[idx] = pBuffer[src_idx];
+                       idx++;
+                       break;
                }
 
                pRet[idx] = '\0';
-               src_idx ++;
+               src_idx++;
        }
 }
 
@@ -135,8 +150,9 @@ struct node *node_find(const struct node *node, const char *path)
 
        if (*path != '/') {
                while (node->parent && path[0] == '.' && path[1] == '.') {
-                       if (path[2] != '/' && path[2] != '\0')
+                       if (path[2] != '/' && path[2] != '\0') {
                                break;
+                       }
 
                        path += 2;
                        path += (path[2] == '/');
@@ -156,8 +172,9 @@ struct node *node_find(const struct node *node, const char *path)
        do {
                ptr += (*ptr == '/');
                for (len = 0; ptr[len] && ptr[len] != '/'; len++);
-               if (!len)
+               if (!len) {
                        break;
+               }
 
                if (!strncmp("..", ptr, len)) {
                        ptr += len;
@@ -171,8 +188,9 @@ struct node *node_find(const struct node *node, const char *path)
                }
 
                node = node->child;
-               if (!node)
+               if (!node) {
                        break;
+               }
 
                while (node) {
                        if (!strncmp(node->name, ptr, len) && node->name[len] == '\0') {
@@ -223,8 +241,9 @@ struct node *node_create(struct node *parent, const char *name, enum node_type t
                if (parent->child) {
                        struct node *tmp;
                        tmp = parent->child;
-                       while (tmp->sibling.next)
+                       while (tmp->sibling.next) {
                                tmp = tmp->sibling.next;
+                       }
 
                        tmp->sibling.next = node;
                        node->sibling.prev = tmp;
@@ -252,19 +271,22 @@ void node_delete(struct node *node, void (del_cb)(struct node *node))
        struct node *next;
        struct node *parent;
 
-       if (node->sibling.prev)
+       if (node->sibling.prev) {
                node->sibling.prev->sibling.next = node->sibling.next;
+       }
 
-       if (node->sibling.next)
+       if (node->sibling.next) {
                node->sibling.next->sibling.prev = node->sibling.prev;
+       }
 
        /* Isolate the node */
        node->sibling.prev = NULL;
        node->sibling.next = NULL;
 
        if (node->parent) {
-               if (node->parent->child == node)
+               if (node->parent->child == node) {
                        node->parent->child = NULL;
+               }
 
                node->parent = NULL;
        }
@@ -272,25 +294,30 @@ void node_delete(struct node *node, void (del_cb)(struct node *node))
        tmp = node;
        while (tmp) {
                /* Reach to the leaf node */
-               while (tmp->child) tmp = tmp->child;
+               while (tmp->child) {
+                       tmp = tmp->child;
+               }
 
                parent = tmp->parent;
                next = tmp->sibling.next;
 
-               if (parent && parent->child == tmp)
+               if (parent && parent->child == tmp) {
                        parent->child = NULL;
+               }
 
-               if (del_cb)
+               if (del_cb) {
                        del_cb(tmp);
+               }
 
                node_destroy(tmp);
 
-               if (next)
+               if (next) {
                        tmp = next;
-               else if (parent)
+               } else if (parent) {
                        tmp = parent;
-               else
+               } else {
                        tmp = NULL;
+               }
        }
 }