]> git.sur5r.net Git - i3/i3/blobdiff - i3bar/src/child.c
Added Unicode-Support
[i3/i3] / i3bar / src / child.c
index 5fe9ca8c6f2f9486880ea8dc29fd1b06f10fa645..362a56d464bde42e9863edc2c6dac3a9594cdf09 100644 (file)
@@ -81,7 +81,7 @@ void child_io_cb(struct ev_loop *loop, ev_io *watcher, int revents) {
     strip_dzen_formats(buffer);
     FREE(statusline);
     statusline = buffer;
-    printf("%s", buffer);
+    printf("%s\n", buffer);
     draw_bars();
 }
 
@@ -91,45 +91,52 @@ void child_sig_cb(struct ev_loop *loop, ev_child *watcher, int revents) {
 }
 
 void start_child(char *command) {
-    int fd[2];
-    pipe(fd);
-    child_pid = fork();
-    switch (child_pid) {
-        case -1:
-            printf("ERROR: Couldn't fork()");
-            exit(EXIT_FAILURE);
-        case 0:
-            close(fd[0]);
+    child_pid = 0;
+    if (command != NULL) {
+        int fd[2];
+        pipe(fd);
+        child_pid = fork();
+        switch (child_pid) {
+            case -1:
+                printf("ERROR: Couldn't fork()");
+                exit(EXIT_FAILURE);
+            case 0:
+                close(fd[0]);
+
+                dup2(fd[1], STDOUT_FILENO);
 
-            dup2(fd[1], STDOUT_FILENO);
+                static const char *shell = NULL;
 
-            static const char *shell = NULL;
+                if ((shell = getenv("SHELL")) == NULL)
+                    shell = "/bin/sh";
 
-            if ((shell = getenv("SHELL")) == NULL)
-                shell = "/bin/sh";
+                execl(shell, shell, "-c", command, (char*) NULL);
+                return;
+            default:
+                close(fd[1]);
 
-            execl(shell, shell, "-c", command, (char*) NULL);
-            break;
-        default:
-            close(fd[1]);
+                dup2(fd[0], STDIN_FILENO);
+
+                break;
+        }
+    }
 
-            dup2(fd[0], STDIN_FILENO);
-            fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
+    fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
 
-            child_io = malloc(sizeof(ev_io));
-            ev_io_init(child_io, &child_io_cb, STDIN_FILENO, EV_READ);
-            ev_io_start(main_loop, child_io);
+    child_io = malloc(sizeof(ev_io));
+    ev_io_init(child_io, &child_io_cb, STDIN_FILENO, EV_READ);
+    ev_io_start(main_loop, child_io);
 
-            /* We must cleanup, if the child unexpectedly terminates */
-            child_sig = malloc(sizeof(ev_io));
-            ev_child_init(child_sig, &child_sig_cb, child_pid, 0);
-            ev_child_start(main_loop, child_sig);
+    /* We must cleanup, if the child unexpectedly terminates */
+    child_sig = malloc(sizeof(ev_io));
+    ev_child_init(child_sig, &child_sig_cb, child_pid, 0);
+    ev_child_start(main_loop, child_sig);
 
-            break;
-    }
 }
 
 void kill_child() {
-    kill(child_pid, SIGQUIT);
+    if (child_pid != 0) {
+        kill(child_pid, SIGQUIT);
+    }
     cleanup();
 }