diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2014-04-07 19:55:47 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2014-04-07 19:55:47 +0000 |
commit | 31c84c8c33838894eb7d65f831a0845cbbc49029 (patch) | |
tree | 8cb8b64c98a8d5cf4600837c1e51bb45a82e1e1c /usr.sbin/iscsid | |
parent | b150313f898d0e86871d2d9cd2e3436e5a6abcfb (diff) |
To win the startup race on the control socket we need to listen to it as
well only then the connect() call from iscsictl will not fail. Move listen()
into the init function and rename control_listen() to control_event_init()
since it is now only doing that.
Diffstat (limited to 'usr.sbin/iscsid')
-rw-r--r-- | usr.sbin/iscsid/control.c | 20 | ||||
-rw-r--r-- | usr.sbin/iscsid/iscsid.c | 6 | ||||
-rw-r--r-- | usr.sbin/iscsid/iscsid.h | 4 |
3 files changed, 14 insertions, 16 deletions
diff --git a/usr.sbin/iscsid/control.c b/usr.sbin/iscsid/control.c index ba75afa31e3..9bb08e04c65 100644 --- a/usr.sbin/iscsid/control.c +++ b/usr.sbin/iscsid/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.4 2013/03/11 17:40:11 deraadt Exp $ */ +/* $OpenBSD: control.c,v 1.5 2014/04/07 19:55:46 claudio Exp $ */ /* * Copyright (c) 2010 Claudio Jeker <claudio@openbsd.org> @@ -99,6 +99,13 @@ control_init(char *path) return (-1); } + if (listen(fd, CONTROL_BACKLOG) == -1) { + log_warn("control_init: listen"); + close(fd); + (void)unlink(path); + return (-1); + } + socket_setblockmode(fd, 1); control_state->fd = fd; TAILQ_INIT(&controls); @@ -124,20 +131,13 @@ control_cleanup(char *path) free(control_state); } -int -control_listen(void) +void +control_event_init(void) { - if (listen(control_state->fd, CONTROL_BACKLOG) == -1) { - log_warn("control_listen: listen"); - return (-1); - } - event_set(&control_state->ev, control_state->fd, EV_READ, control_accept, NULL); event_add(&control_state->ev, NULL); evtimer_set(&control_state->evt, control_accept, NULL); - - return (0); } /* ARGSUSED */ diff --git a/usr.sbin/iscsid/iscsid.c b/usr.sbin/iscsid/iscsid.c index 446b37a8bcd..a73bd85846c 100644 --- a/usr.sbin/iscsid/iscsid.c +++ b/usr.sbin/iscsid/iscsid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: iscsid.c,v 1.9 2014/02/17 18:59:50 claudio Exp $ */ +/* $OpenBSD: iscsid.c,v 1.10 2014/04/07 19:55:46 claudio Exp $ */ /* * Copyright (c) 2009 Claudio Jeker <claudio@openbsd.org> @@ -138,9 +138,7 @@ main(int argc, char *argv[]) signal_add(&ev_sighup, NULL); signal(SIGPIPE, SIG_IGN); - if (control_listen() == -1) - fatalx("control socket listen failed"); - + control_event_init(); initiator = initiator_init(); event_dispatch(); diff --git a/usr.sbin/iscsid/iscsid.h b/usr.sbin/iscsid/iscsid.h index 469adbef1bf..6dd9d4ce66e 100644 --- a/usr.sbin/iscsid/iscsid.h +++ b/usr.sbin/iscsid/iscsid.h @@ -1,4 +1,4 @@ -/* $OpenBSD: iscsid.h,v 1.9 2011/05/04 21:00:04 claudio Exp $ */ +/* $OpenBSD: iscsid.h,v 1.10 2014/04/07 19:55:46 claudio Exp $ */ /* * Copyright (c) 2009 Claudio Jeker <claudio@openbsd.org> @@ -295,7 +295,7 @@ char *default_initiator_name(void); int control_init(char *); void control_cleanup(char *); -int control_listen(void); +void control_event_init(void); int control_queue(void *, struct pdu *); int control_compose(void *, u_int16_t, void *, size_t); |