summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
5e7a5e2)
This involves reworking setcloexec()'s implementation so that we can
reuse it.
We now treat a failure to set O_NONBLOCK in udp_make_socket as a
fatal, rather than recoverable, error. This is fine.
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
pipe_cloexec(p);
spw=p[1];
spr=p[0];
pipe_cloexec(p);
spw=p[1];
spr=p[0];
- if (fcntl(spw, F_SETFL, fcntl(spw, F_GETFL)|O_NONBLOCK)==-1) {
- fatal_perror("start_signal_handling: fcntl(O_NONBLOCK)");
- }
register_for_poll(NULL,signal_beforepoll,signal_afterpoll,"signal");
signal_handling=True;
register_for_poll(NULL,signal_beforepoll,signal_afterpoll,"signal");
signal_handling=True;
const char *message);
void setcloexec(int fd); /* cannot fail */
const char *message);
void setcloexec(int fd); /* cannot fail */
+void setnonblock(int fd); /* cannot fail */
void pipe_cloexec(int fd[2]); /* pipe(), setcloexec() twice; cannot fail */
extern int sys_cmd(const char *file, const char *argc, ...);
void pipe_cloexec(int fd[2]); /* pipe(), setcloexec() twice; cannot fail */
extern int sys_cmd(const char *file, const char *argc, ...);
us->fd=socket(addr->sa.sa_family, SOCK_DGRAM, IPPROTO_UDP);
if (us->fd<0) FAIL("socket");
us->fd=socket(addr->sa.sa_family, SOCK_DGRAM, IPPROTO_UDP);
if (us->fd<0) FAIL("socket");
- if (fcntl(us->fd, F_SETFL, fcntl(us->fd, F_GETFL)|O_NONBLOCK)==-1)
- FAIL("fcntl(set O_NONBLOCK)");
setcloexec(us->fd);
#ifdef CONFIG_IPV6
if (addr->sa.sa_family==AF_INET6) {
setcloexec(us->fd);
#ifdef CONFIG_IPV6
if (addr->sa.sa_family==AF_INET6) {
-void setcloexec(int fd) {
- int r=fcntl(fd, F_GETFD);
- if (r<0) fatal_perror("fcntl(,F_GETFD) failed");
- r=fcntl(fd, F_SETFD, r|FD_CLOEXEC);
- if (r<0) fatal_perror("fcntl(,F_SETFD,|FD_CLOEXEC) failed");
+#define DEFINE_SETFDFLAG(fn,FL,FLAG) \
+void fn(int fd) { \
+ int r=fcntl(fd, F_GET##FL); \
+ if (r<0) fatal_perror("fcntl(,F_GET" #FL ") failed"); \
+ r=fcntl(fd, F_SET##FL, r|FLAG); \
+ if (r<0) fatal_perror("fcntl(,F_SET" #FL ",|" #FLAG ") failed"); \
+DEFINE_SETFDFLAG(setcloexec,FD,FD_CLOEXEC);
+DEFINE_SETFDFLAG(setnonblock,FL,O_NONBLOCK);
+
void pipe_cloexec(int fd[2]) {
int r=pipe(fd);
if (r) fatal_perror("pipe");
void pipe_cloexec(int fd[2]) {
int r=pipe(fd);
if (r) fatal_perror("pipe");