Commit 3a3818de authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(add_flag): New static function, that checks the return values from

	fcntl properly.
(oop_signal_new): Use add_flag() to simplify code. Fail (return
	NULL) if any of the fcntl calls on the new pipe fails.
parent c8baf30f
......@@ -169,9 +169,18 @@ static void sig_cancel_signal(oop_source *source,int sig,
}
}
static int add_flag(int fd,
int get_op,
int set_op,
int val) {
int flags;
if ((flags = fcntl(fd,get_op,0)) == -1) return -1;
if ((fcntl(fd,set_op,flags|val)) == -1) return -1;
return 0;
}
oop_adapter_signal *oop_signal_new(oop_source *source) {
int i;
int flags;
oop_adapter_signal * const s = oop_malloc(sizeof(*s));
if (NULL == s) return NULL;
assert(NULL != source);
......@@ -180,14 +189,13 @@ oop_adapter_signal *oop_signal_new(oop_source *source) {
return NULL;
}
flags = fcntl(s->pipefd[0],F_GETFD,0);
fcntl(s->pipefd[0],F_SETFD,flags|FD_CLOEXEC);
flags = fcntl(s->pipefd[1],F_GETFD,0);
fcntl(s->pipefd[1],F_SETFD,flags|FD_CLOEXEC);
flags = fcntl(s->pipefd[0],F_GETFL,0);
fcntl(s->pipefd[0],F_SETFL,flags|O_NONBLOCK);
flags = fcntl(s->pipefd[1],F_GETFL,0);
fcntl(s->pipefd[1],F_SETFL,flags|O_NONBLOCK);
if (add_flag(s->pipefd[0],F_GETFD,F_SETFD,FD_CLOEXEC)
|| add_flag(s->pipefd[1],F_GETFD,F_SETFD,FD_CLOEXEC)
|| add_flag(s->pipefd[0],F_GETFL,F_SETFL,O_NONBLOCK)
|| add_flag(s->pipefd[1],F_GETFL,F_SETFL,O_NONBLOCK)) {
oop_free(s);
return NULL;
}
s->oop.on_fd = sig_on_fd;
s->oop.cancel_fd = sig_cancel_fd;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment