mirror of
https://codeberg.org/dwl/dwl.git
synced 2024-12-26 03:06:30 +00:00
set O_NONBLOCK flag to stdout
This commit is contained in:
parent
2b4893a0ad
commit
71f11e6cf6
3 changed files with 23 additions and 0 deletions
6
dwl.c
6
dwl.c
|
@ -2190,6 +2190,12 @@ run(char *startup_cmd)
|
||||||
close(piperw[1]);
|
close(piperw[1]);
|
||||||
close(piperw[0]);
|
close(piperw[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Mark stdout as non-blocking to avoid people who does not close stdin
|
||||||
|
* nor consumes it in their startup script getting dwl frozen */
|
||||||
|
if (fd_set_nonblock(STDOUT_FILENO) < 0)
|
||||||
|
close(STDOUT_FILENO);
|
||||||
|
|
||||||
printstatus();
|
printstatus();
|
||||||
|
|
||||||
/* At this point the outputs are initialized, choose initial selmon based on
|
/* At this point the outputs are initialized, choose initial selmon based on
|
||||||
|
|
16
util.c
16
util.c
|
@ -3,6 +3,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
@ -33,3 +34,18 @@ ecalloc(size_t nmemb, size_t size)
|
||||||
die("calloc:");
|
die("calloc:");
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
fd_set_nonblock(int fd) {
|
||||||
|
int flags = fcntl(fd, F_GETFL);
|
||||||
|
if (flags < 0) {
|
||||||
|
perror("fcntl(F_GETFL):");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
|
||||||
|
perror("fcntl(F_SETFL):");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
1
util.h
1
util.h
|
@ -2,3 +2,4 @@
|
||||||
|
|
||||||
void die(const char *fmt, ...);
|
void die(const char *fmt, ...);
|
||||||
void *ecalloc(size_t nmemb, size_t size);
|
void *ecalloc(size_t nmemb, size_t size);
|
||||||
|
int fd_set_nonblock(int fd);
|
||||||
|
|
Loading…
Reference in a new issue