SHA256
8
0
forked from pool/FastCGI
Files
FastCGI/FastCGI-supervise_cgi-fcgi.patch
Marcus Rueckert 98fadf90a6 - Update to 2.4.6 (boo#1243325 CVE-2025-23016)
switch to https://github.com/FastCGI-Archives/fcgi2
  lots of small bugs fixes and incorporation of patches that
  distros carried in the past
- drop patches which are included upstream
  FastCGI-clientdata_pointer.patch
  FastCGI-gcc44.patch
  FastCGI-makefile.am_cppflags.patch
  FastCGI-supervise_cgi-fcgi.patch
  fastcgi-2.4.0_missing_call_to_fclose.patch
- drop patches obsoleted by changes to the perl building
  FastCGI-fix_deprecated_api.patch
  FastCGI-perl514.patch
  FastCGI-perl526.patch

OBS-URL: https://build.opensuse.org/package/show/devel:libraries:c_c++/FastCGI?expand=0&rev=51
2025-07-15 00:08:53 +00:00

122 lines
3.5 KiB
Diff
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Index: cgi-fcgi/cgi-fcgi.c
===================================================================
--- cgi-fcgi/cgi-fcgi.c.orig
+++ cgi-fcgi/cgi-fcgi.c
@@ -22,6 +22,8 @@
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
+#include <sys/wait.h>
+#include <signal.h>
#include "fcgi_config.h"
@@ -583,7 +585,7 @@
#define MAXARGS 16
static int ParseArgs(int argc, char *argv[],
int *doBindPtr, int *doStartPtr,
- char *connectPathPtr, char *appPathPtr, int *nServersPtr) {
+ char *connectPathPtr, char *appPathPtr, int *nServersPtr, int *doDaemonPtr) {
int i,
x,
err = 0,
@@ -599,6 +601,7 @@
*connectPathPtr = '\0';
*appPathPtr = '\0';
*nServersPtr = 0;
+ *doDaemonPtr = TRUE;
for(i = 0; i < MAXARGS; i++)
av[i] = NULL;
@@ -649,7 +652,7 @@
}
}
err = ParseArgs(ac, av, doBindPtr, doStartPtr,
- connectPathPtr, appPathPtr, nServersPtr);
+ connectPathPtr, appPathPtr, nServersPtr, doDaemonPtr);
for(x = 1; x < ac; x++) {
ASSERT(av[x] != NULL);
free(av[x]);
@@ -673,7 +676,9 @@
} else {
strcpy(connectPathPtr, argv[i]);
}
- } else {
+ } else if(!strcmp(argv[i], "-supervise")) {
+ *doDaemonPtr = FALSE;
+ } else {
fprintf(stderr, "Unknown option %s\n", argv[i]);
err++;
}
@@ -718,6 +723,15 @@
return err;
}
+void handle_shutdown(int s)
+{
+ /* Kill our children processes */
+ signal(s, SIG_IGN);
+ kill(0, s);
+
+ exit(0);
+}
+
int main(int argc, char **argv)
{
char **envp = environ;
@@ -728,20 +742,22 @@
int headerLen, valueLen;
char *equalPtr;
FCGI_BeginRequestRecord beginRecord;
- int doBind, doStart, nServers;
+ int doBind, doStart, nServers, doDaemon;
char appPath[MAXPATHLEN], bindPath[MAXPATHLEN];
+ int pid;
if(ParseArgs(argc, argv, &doBind, &doStart,
- (char *) &bindPath, (char *) &appPath, &nServers)) {
+ (char *) &bindPath, (char *) &appPath, &nServers, &doDaemon)) {
fprintf(stderr,
"Usage:\n"
" cgi-fcgi -f <cmdPath> , or\n"
" cgi-fcgi -connect <connName> <appPath> [<nServers>] , or\n"
-" cgi-fcgi -start -connect <connName> <appPath> [<nServers>] , or\n"
+" cgi-fcgi -start -connect [-supervise] <connName> <appPath> [<nServers>] , or\n"
" cgi-fcgi -bind -connect <connName> ,\n"
"where <connName> is either the pathname of a UNIX domain socket\n"
"or (if -bind is given) a hostName:portNumber specification\n"
-"or (if -start is given) a :portNumber specification (uses local host).\n");
+"or (if -start is given) a :portNumber specification (uses local host).\n"
+"-supervise is for running with runit or daemontools.\n");
exit(1);
}
@@ -757,12 +773,27 @@
bytesToRead = 0;
}
+ /* Become a process group leader */
+ setsid();
+
+ /* Register our signal handler */
+ signal(SIGHUP, handle_shutdown);
+ signal(SIGINT, handle_shutdown);
+ signal(SIGTERM, handle_shutdown);
+
if(doBind) {
appServerSock = OS_FcgiConnect(bindPath);
}
if(doStart && (!doBind || appServerSock < 0)) {
FCGI_Start(bindPath, appPath, nServers);
if(!doBind) {
+ if(!doDaemon) {
+ for(pid=nServers; pid != 0; pid--) {
+ wait(0);
+ }
+ }
+ signal(SIGTERM, SIG_IGN);
+ kill(0, SIGTERM);
exit(0);
} else {
appServerSock = OS_FcgiConnect(bindPath);