Merge branch 'master' into tree

This commit is contained in:
Axel Wagner 2010-12-26 15:27:32 +01:00
commit 3c85c514d4
3 changed files with 22 additions and 43 deletions

View File

@ -1,8 +1,13 @@
v0.6
=====
- Add manpage
- Implement hide-on-modifier
- Custom colors can be set from the commandline
- Use double-buffering
- Bugfix: Correctly render long text - Bugfix: Correctly render long text
- Bugfix: Don't segfault on SIGCHILD - Bugfix: Don't segfault on SIGCHILD
- Implement hide-on-modifier - Bugfix: Double-fork() to avoid zombies
- Use double-buffering - Some minor bugfixes
v0.5 v0.5
===== =====

View File

@ -1,7 +1,7 @@
i3bar(1) i3bar(1)
======== ========
Axel Wagner <mail+i3bar@merovius.de> Axel Wagner <mail+i3bar@merovius.de>
v0.5, September 2010 v0.6, September 2010
== NAME == NAME

View File

@ -12,7 +12,6 @@
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <signal.h> #include <signal.h>
#include <sys/wait.h>
#include <stdio.h> #include <stdio.h>
#include <fcntl.h> #include <fcntl.h>
#include <string.h> #include <string.h>
@ -101,29 +100,19 @@ void child_sig_cb(struct ev_loop *loop, ev_child *watcher, int revents) {
/* /*
* Start a child-process with the specified command and reroute stdin. * Start a child-process with the specified command and reroute stdin.
* We actually start a $SHELL to execute the command so we don't have to care * We actually start a $SHELL to execute the command so we don't have to care
* about arguments and such. * about arguments and such
* We also double-fork() to avoid zombies and pass the pid of the child through a
* temporary pipe back to i3bar
* *
*/ */
void start_child(char *command) { void start_child(char *command) {
child_pid = 0; child_pid = 0;
if (command != NULL) { if (command != NULL) {
int fd[2], tmp[2]; int fd[2];
/* This pipe will be used to communicate between e.g. i3status and i3bar */
pipe(fd); pipe(fd);
/* We also need this temporary pipe to get back the pid of i3status */ child_pid = fork();
pipe(tmp); switch (child_pid) {
switch (fork()) {
case -1: case -1:
ELOG("Couldn't fork()\n"); ELOG("Couldn't fork()\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
case 0:
/* Double-fork(), so the child gets reparented to init */
switch(child_pid = fork()) {
case -1:
ELOG("Couldn't fork() twice\n");
exit(EXIT_FAILURE);
case 0: case 0:
/* Child-process. Reroute stdout and start shell */ /* Child-process. Reroute stdout and start shell */
close(fd[0]); close(fd[0]);
@ -137,31 +126,15 @@ void start_child(char *command) {
execl(shell, shell, "-c", command, (char*) NULL); execl(shell, shell, "-c", command, (char*) NULL);
return; return;
default:
/* Temporary parent. We tell i3bar about the pid of i3status and exit */
write(tmp[1], &child_pid, sizeof(int));
close(tmp[0]);
close(tmp[1]);
exit(EXIT_SUCCESS);
}
default: default:
/* Parent-process. Rerout stdin */ /* Parent-process. Rerout stdin */
close(fd[1]); close(fd[1]);
dup2(fd[0], STDIN_FILENO); dup2(fd[0], STDIN_FILENO);
/* We also need to get the pid of i3status from the temporary pipe */
size_t rec = 0;
while (rec < sizeof(int)) {
rec += read(tmp[0], &child_pid, sizeof(int) - rec);
}
/* The temporary pipe is no longer needed */
close(tmp[0]);
close(tmp[1]);
break; break;
} }
} }
wait(0);
/* We set O_NONBLOCK because blocking is evil in event-driven software */ /* We set O_NONBLOCK because blocking is evil in event-driven software */
fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK); fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
@ -184,6 +157,7 @@ void start_child(char *command) {
*/ */
void kill_child() { void kill_child() {
if (child_pid != 0) { if (child_pid != 0) {
kill(child_pid, SIGCONT);
kill(child_pid, SIGTERM); kill(child_pid, SIGTERM);
} }
cleanup(); cleanup();