From 3af406243bb2a4a6c8ac5b3f1d98a9cd7e0af295 Mon Sep 17 00:00:00 2001
From: yangchen <yangchen145@huawei.com>
Date: Wed, 20 Dec 2023 11:37:13 +0800
Subject: [PATCH] sigaction: fix deprecated signal flags

---
 src/lstack/api/lstack_signal.c | 10 +++++++++-
 src/lstack/core/lstack_lwip.c  |  7 ++++---
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/lstack/api/lstack_signal.c b/src/lstack/api/lstack_signal.c
index 6da6eb4..314c14c 100644
--- a/src/lstack/api/lstack_signal.c
+++ b/src/lstack/api/lstack_signal.c
@@ -57,7 +57,7 @@ static inline bool match_hijack_signal(int sig)
 
 static void lstack_sig_default_handler(int sig)
 {
-    LSTACK_LOG(ERR, LSTACK, "lstack dumped，caught signal：%d\n", sig);
+    LSTACK_LOG(ERR, LSTACK, "lstack dumped, caught signal: %d\n", sig);
     if (get_global_cfg_params() && get_global_cfg_params()->is_primary) {
         delete_primary_path();
     }
@@ -94,5 +94,13 @@ int lstack_sigaction(int sig_num, const struct sigaction *action, struct sigacti
         new_action.sa_handler = lstack_sig_default_handler;
         return posix_api->sigaction_fn(sig_num, &new_action, old_action);
     }
+
+    /* SA_INTERRUPT is deprecated, use SA_RESETHAND instead. */
+    if ((match_hijack_signal(sig_num) != 0) && (action && action->sa_flags == SA_INTERRUPT)) {
+        new_action = *action;
+        new_action.sa_flags |= SA_RESETHAND;
+        return posix_api->sigaction_fn(sig_num, &new_action, old_action);
+    }
+
     return posix_api->sigaction_fn(sig_num, action, old_action);
 }
diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c
index 34ec1bd..100f075 100644
--- a/src/lstack/core/lstack_lwip.c
+++ b/src/lstack/core/lstack_lwip.c
@@ -564,10 +564,11 @@ static ssize_t do_lwip_fill_sendring(struct lwip_sock *sock, const void *buf, si
     uint32_t write_avail = gazelle_ring_readable_count(sock->send_ring);
     struct wakeup_poll *wakeup = sock->wakeup;
 
-    if (!netconn_is_nonblocking(sock->conn)) {
-        while (write_avail < write_num) {
-            write_avail = gazelle_ring_readable_count(sock->send_ring);
+    while (!netconn_is_nonblocking(sock->conn) && (write_avail < write_num)) {
+        if (sock->errevent > 0) {
+            GAZELLE_RETURN(ENOTCONN);
         }
+        write_avail = gazelle_ring_readable_count(sock->send_ring);
     }
 
     /* send_ring is full, data attach last pbuf */
-- 
2.27.0

