mirror of https://github.com/wolfSSL/wolfssh.git
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.pull/457/head
parent
1d466823f3
commit
95431c3de1
|
@ -102,6 +102,7 @@ typedef struct WOLFSSHD_CONNECTION {
|
||||||
WOLFSSH_CTX* ctx;
|
WOLFSSH_CTX* ctx;
|
||||||
WOLFSSHD_AUTH* auth;
|
WOLFSSHD_AUTH* auth;
|
||||||
int fd;
|
int fd;
|
||||||
|
int listenFd;
|
||||||
char ip[INET_ADDRSTRLEN];
|
char ip[INET_ADDRSTRLEN];
|
||||||
} WOLFSSHD_CONNECTION;
|
} WOLFSSHD_CONNECTION;
|
||||||
|
|
||||||
|
@ -812,12 +813,14 @@ static int NewConnection(WOLFSSHD_CONNECTION* conn)
|
||||||
if (ret == WS_SUCCESS) {
|
if (ret == WS_SUCCESS) {
|
||||||
if (pd == 0) {
|
if (pd == 0) {
|
||||||
/* child process */
|
/* child process */
|
||||||
|
WCLOSESOCKET(conn->listenFd);
|
||||||
signal(SIGINT, SIG_DFL);
|
signal(SIGINT, SIG_DFL);
|
||||||
(void)HandleConnection((void*)conn);
|
(void)HandleConnection((void*)conn);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
wolfSSH_Log(WS_LOG_INFO, "[SSHD] Spawned new process %d\n", pd);
|
wolfSSH_Log(WS_LOG_INFO, "[SSHD] Spawned new process %d\n", pd);
|
||||||
|
WCLOSESOCKET(conn->fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1049,6 +1052,7 @@ int main(int argc, char** argv)
|
||||||
socklen_t clientAddrSz = sizeof(clientAddr);
|
socklen_t clientAddrSz = sizeof(clientAddr);
|
||||||
#endif
|
#endif
|
||||||
conn.auth = auth;
|
conn.auth = auth;
|
||||||
|
conn.listenFd = listenFd;
|
||||||
|
|
||||||
/* wait for a connection */
|
/* wait for a connection */
|
||||||
if (PendingConnection(listenFd)) {
|
if (PendingConnection(listenFd)) {
|
||||||
|
|
Loading…
Reference in New Issue