Skip to content

Commit 95431c3

Browse files
committed
Child Listener
1. Stash a copy of wolfsshd's listenFd in the connection record. 2. After the fork, the child now closes the listenFd. 3. After the fork, the parent now closes the fd.
1 parent 1d46682 commit 95431c3

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

apps/wolfsshd/wolfsshd.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ typedef struct WOLFSSHD_CONNECTION {
102102
WOLFSSH_CTX* ctx;
103103
WOLFSSHD_AUTH* auth;
104104
int fd;
105+
int listenFd;
105106
char ip[INET_ADDRSTRLEN];
106107
} WOLFSSHD_CONNECTION;
107108

@@ -812,12 +813,14 @@ static int NewConnection(WOLFSSHD_CONNECTION* conn)
812813
if (ret == WS_SUCCESS) {
813814
if (pd == 0) {
814815
/* child process */
816+
WCLOSESOCKET(conn->listenFd);
815817
signal(SIGINT, SIG_DFL);
816818
(void)HandleConnection((void*)conn);
817819
exit(0);
818820
}
819821
else {
820822
wolfSSH_Log(WS_LOG_INFO, "[SSHD] Spawned new process %d\n", pd);
823+
WCLOSESOCKET(conn->fd);
821824
}
822825
}
823826

@@ -1049,6 +1052,7 @@ int main(int argc, char** argv)
10491052
socklen_t clientAddrSz = sizeof(clientAddr);
10501053
#endif
10511054
conn.auth = auth;
1055+
conn.listenFd = listenFd;
10521056

10531057
/* wait for a connection */
10541058
if (PendingConnection(listenFd)) {

0 commit comments

Comments
 (0)