Ciao Manu,
Manuel Badzong --> dwm (2006-11-25 08:17:59 +0100):
> mkfifo dwm_pipe
> dwm < dwm_pipe > dwm_pipe
aka `dwm <>dwm_pipe', BTW...
> If dwm ever writes to stdout (does it?)
No, only some error message are written to stderr.
> After reading main.c
> I recognized that "broken pipe" actually means error or eof reading
> stdin. This definitely should be fixed.
Indeed.
> I mainly changed 5 little things in the main event loop:
[...]
> + I replaced fgets with read (I hate this FILE* crap). If for some
> reason you prefer ANSI C over UNIX IO use feof() to catch EOF.
[...]
Thanks for the cleanup. But now that dwm's reading from stdin isn't
line buffered anymore the read string shouldn't be required to have a
trailing newline. See attached patch.
Cheers, Jukka
--
bashian roulette:
$ ((RANDOM%6)) || rm -rf ~
diff -r 010118c94013 main.c
--- a/main.c Sat Nov 25 19:26:31 2006 +0100
+++ b/main.c Sun Nov 26 11:07:18 2006 +0100
@@ -274,9 +274,10 @@ main(int argc, char *argv[]) {
eprint("select failed\n");
}
if(FD_ISSET(STDIN_FILENO, &rd)) {
- switch(r = read(STDIN_FILENO, stext, sizeof(stext))) {
+ switch(r = read(STDIN_FILENO, stext, sizeof(stext)-1)) {
case -1:
strncpy(stext, strerror(errno), sizeof(stext));
+ stext[sizeof(stext)-1] = '\0';
readin = False;
break;
case 0:
@@ -284,7 +285,7 @@ main(int argc, char *argv[]) {
readin = False;
break;
default:
- stext[r-1] = 0;
+ stext[r-(stext[r-1]=='\n'?1:0)] = '\0';
}
drawstatus();
}