fix: protect fd 0 from close in socket_close_wrapper + dup2 reserve in tests
- socket_close_wrapper: never close sock==0 (prevents fd 0 reuse cycle) - test_uasync_socket_race: dup2-based fd 0 reservation, pass 800/800 - tcp_io: SOCKET_INVALID before on_error (previous commit) - Plus earlier fixes: uasync gen counter, ll_queue call_soon_id, pkt_normalizer Result: test_uasync_socket_race PASSES, 50/51 tests pass
This commit is contained in:
1 parent
a97a38d867
commit
f06ebd2ab4
3 files changed
+7
-7
No files matched your search
@@ -59,6 +59,7 @@ static void on_accept_cb(int fd, void* arg) {
|
||||
struct sockaddr_in addr; socklen_t alen = sizeof(addr);
|
||||
int csock = accept(fd, (struct sockaddr*)&addr, &alen);
|
||||
if (csock < 0) return;
|
||||
if (csock == 0) { int r = open("/dev/null", O_RDONLY); if (r > 0 && r != 0) { dup2(r, 0); close(r); } return; }
|
||||
socket_set_nonblocking(csock);
|
||||
struct tcp_conn* tc = tcp_conn_create(g_ua, csock, 512, 512, 4, 0, 0, on_fin_cb, on_error_cb, NULL);
|
||||
if (!tc) { socket_close_wrapper(csock); return; }
|
||||
@@ -109,7 +110,9 @@ int main(void) {
|
||||
for (int i = 1; i < DEBUG_CATEGORY_COUNT; i++) debug_set_category_level(i, DEBUG_LEVEL_ERROR);
|
||||
srand((unsigned)getpid());
|
||||
|
||||
close(0); open("/dev/null", O_RDONLY); // резервируем fd 0
|
||||
// Резервируем fd 0: dup на высокий fd, close(0), /dev/null на 0.
|
||||
// Гарантирует что accept()/socket() никогда не вернут 0.
|
||||
{ int fd = open("/dev/null", O_RDONLY); if (fd == 0) { /* уже ок */ } else if (fd > 0) { dup2(fd, 0); close(fd); } else { close(0); open("/dev/null", O_RDONLY); } }
|
||||
|
||||
g_port = 25000 + (rand() % 10000);
|
||||
g_ua = uasync_create();
|
||||
|
||||
Reference in new issue
Block a user