mcp.h: gemeinsamen Stand übernehmen (SIGCHLD-Fehler behoben)
This commit is contained in:
1 parent
82b6acf344
commit
2a54a86049
1 file changed
+23
-7
Vendored
+23
-7
@@ -175,6 +175,7 @@ char *mcp_handle(mcp_server *srv, const char *line);
|
||||
#include <netinet/in.h>
|
||||
#include <signal.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
@@ -1090,8 +1091,13 @@ int mcp_serve_http(mcp_server *srv, const char *host, int port)
|
||||
close(ls);
|
||||
return 1;
|
||||
}
|
||||
/* fork per connection: without this every finished child stays a zombie */
|
||||
signal(SIGCHLD, SIG_IGN);
|
||||
/* Ein Prozess je Verbindung. Dabei NICHT SIGCHLD auf SIG_IGN setzen: das
|
||||
* lässt den Kernel alle Kinder selbst einsammeln, und dann scheitert jedes
|
||||
* pclose() im Programm mit ECHILD — popen sieht einen Fehler, obwohl das
|
||||
* Kommando lief. Genau so scheiterten in skilld alle git-Aufrufe still.
|
||||
* Stattdessen doppelt forken: das Zwischenkind beendet sich sofort, der
|
||||
* Enkel gehört init und wird von dort eingesammelt. */
|
||||
|
||||
fprintf(stderr, "%s: http mcp on %s:%d (session %s)\n",
|
||||
srv->name ? srv->name : "mcp", host ? host : "0.0.0.0", port, session);
|
||||
for (;;) {
|
||||
@@ -1102,14 +1108,24 @@ int mcp_serve_http(mcp_server *srv, const char *host, int port)
|
||||
continue;
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
close(ls);
|
||||
mcp_http_serve_one(fd, srv, session);
|
||||
_exit(0);
|
||||
pid_t grand = fork();
|
||||
|
||||
if (grand == 0) {
|
||||
close(ls);
|
||||
mcp_http_serve_one(fd, srv, session);
|
||||
_exit(0);
|
||||
}
|
||||
_exit(0); /* Zwischenkind: sofort weg, kein Zombie */
|
||||
}
|
||||
if (pid > 0)
|
||||
if (pid > 0) {
|
||||
int wstatus;
|
||||
|
||||
close(fd);
|
||||
else
|
||||
while (waitpid(pid, &wstatus, 0) < 0 && errno == EINTR)
|
||||
;
|
||||
} else {
|
||||
mcp_http_serve_one(fd, srv, session);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user