Allow admin to destroy fcoe interfaces only on SIGHUP, otherwise
leaves them intact due to any other or accidental exiting of fcoemon.

Signed-off-by: Vasu Dev <[email protected]>
---

 fcoemon.c               |    5 +++--
 include/fcoemon_utils.h |    2 +-
 lib/sa_select.c         |   22 ++++++++++++++--------
 3 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/fcoemon.c b/fcoemon.c
index ffe39ef..8709285 100644
--- a/fcoemon.c
+++ b/fcoemon.c
@@ -2226,7 +2226,7 @@ static void fcm_usage(void)
 
 static void fcm_sig(int sig)
 {
-       sa_select_exit();
+       sa_select_exit(sig);
 }
 
 static void fcm_pidfile_create(void)
@@ -2628,7 +2628,8 @@ int main(int argc, char **argv)
        }
        fcm_dcbd_shutdown();
        fcm_srv_destroy(&srv_info);
-       fcm_cleanup();
+       if (rc == SIGHUP)
+               fcm_cleanup();
        return 0;
 }
 
diff --git a/include/fcoemon_utils.h b/include/fcoemon_utils.h
index 8680f46..169272e 100644
--- a/include/fcoemon_utils.h
+++ b/include/fcoemon_utils.h
@@ -253,7 +253,7 @@ void sa_select_rem_fd(int fd);
 /*
  * Cause select loop to return.
  */
-void sa_select_exit(void);
+void sa_select_exit(int sig);
 
 /*
  * Convert 48-bit IEEE MAC address to 64-bit FC WWN.
diff --git a/lib/sa_select.c b/lib/sa_select.c
index 1b18a6e..126203e 100644
--- a/lib/sa_select.c
+++ b/lib/sa_select.c
@@ -31,7 +31,7 @@ static struct sa_sel_state {
        fd_set      ts_tx_fds;
        fd_set      ts_ex_fds;
        int         ts_max_fd;
-       u_char      ts_exit;
+       int         ts_sig;
        struct sa_sel_fd {
                void    (*ts_rx_handler)(void *);
                void    (*ts_tx_handler)(void *);
@@ -41,6 +41,12 @@ static struct sa_sel_state {
        void        (*ts_callback)(void);
 } sa_sel_state;
 
+/**
+ * sa_select_loop() - listens to registered descriptors
+ *
+ * Return value:
+ *     -1 on failure or interrupted signal number
+ */
 int sa_select_loop(void)
 {
        struct sa_sel_state *ss = &sa_sel_state;
@@ -52,10 +58,10 @@ int sa_select_loop(void)
        struct timeval *tvp;
        int rv, i;
 
-       ss->ts_exit = 0;
-       while (ss->ts_exit == 0) {
+       ss->ts_sig = 0;
+       while (ss->ts_sig == 0) {
                sa_timer_check(&tval);
-               if (ss->ts_exit)
+               if (ss->ts_sig)
                        break;
                if (tval.tv_sec == 0 && tval.tv_usec == 0)
                        tvp = NULL;
@@ -68,7 +74,7 @@ int sa_select_loop(void)
                if (rv == -1) {
                        if (errno == EINTR)
                                continue;
-                       return errno;
+                       return rv;
                }
 
                fp = ss->ts_fd;
@@ -101,7 +107,7 @@ int sa_select_loop(void)
                if (ss->ts_callback != NULL)
                        (*ss->ts_callback)();
        }
-       return 0;
+       return ss->ts_sig;
 }
 
 void
@@ -207,7 +213,7 @@ sa_select_set_callback(void (*cb)(void))
  * this cleanly, all lower-level protocol handlers should return first.
  */
 void
-sa_select_exit(void)
+sa_select_exit(int sig)
 {
-       sa_sel_state.ts_exit = 1;
+       sa_sel_state.ts_sig = sig;
 }

_______________________________________________
devel mailing list
[email protected]
http://www.open-fcoe.org/mailman/listinfo/devel

Reply via email to