diff --git a/sbin/iscsid/iscsid_globals.h b/sbin/iscsid/iscsid_globals.h index 6aa11298f634..38c39e6cb94f 100644 --- a/sbin/iscsid/iscsid_globals.h +++ b/sbin/iscsid/iscsid_globals.h @@ -1,4 +1,4 @@ -/* $NetBSD: iscsid_globals.h,v 1.5 2012/05/27 17:27:33 riz Exp $ */ +/* $NetBSD: iscsid_globals.h,v 1.6 2012/05/27 22:03:16 riz Exp $ */ /*- * Copyright (c) 2005,2006,2011 The NetBSD Foundation, Inc. @@ -399,13 +399,8 @@ int debug_level; /* How much info to display */ #define LOCK_SESSIONS verify_sessions() #define UNLOCK_SESSIONS #endif -#ifdef ISCSI_NOTHREAD -#define LOCK_SESSIONS event_handler(NULL) -#define UNLOCK_SESSIONS do {} while(0) -#else -#define LOCK_SESSIONS pthread_mutex_lock(&sesslist_lock) -#define UNLOCK_SESSIONS pthread_mutex_unlock(&sesslist_lock) -#endif +#define LOCK_SESSIONS if (nothreads) event_handler(NULL); else pthread_mutex_lock(&sesslist_lock) +#define UNLOCK_SESSIONS if (!nothreads) pthread_mutex_unlock(&sesslist_lock) /* Check whether ID is present */ diff --git a/sbin/iscsid/iscsid_main.c b/sbin/iscsid/iscsid_main.c index 2bb1d0ccf682..ea39069d8c0c 100644 --- a/sbin/iscsid/iscsid_main.c +++ b/sbin/iscsid/iscsid_main.c @@ -1,4 +1,4 @@ -/* $NetBSD: iscsid_main.c,v 1.5 2012/05/27 20:05:04 christos Exp $ */ +/* $NetBSD: iscsid_main.c,v 1.6 2012/05/27 22:03:16 riz Exp $ */ /*- * Copyright (c) 2005,2006,2011 The NetBSD Foundation, Inc. @@ -477,15 +477,14 @@ process_message(iscsid_request_t *req, iscsid_response_t **prsp, int *prsp_temp) void exit_daemon(void) { - if (nothreads) { - LOCK_SESSIONS; - } + LOCK_SESSIONS; deregister_event_handler(); #ifndef ISCSI_MINIMAL dereg_all_isns_servers(); #endif + close(client_sock); printf("iSCSI Daemon Exits\n"); exit(0); } @@ -559,9 +558,13 @@ main(int argc, char **argv) len = sizeof(iscsid_request_t); if (nothreads) { - ret = recvfrom(client_sock, req, len, MSG_PEEK | - MSG_WAITALL, (struct sockaddr *)(void *)&from, - &fromlen); + do { + ret = recvfrom(client_sock, req, len, MSG_PEEK | + MSG_WAITALL, (struct sockaddr *)(void *)&from, + &fromlen); + if (ret == -1) + event_handler(NULL); + } while (ret == -1 && errno == EAGAIN); } else { do { ret = recvfrom(client_sock, req, len, MSG_PEEK |