summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorflu0r1ne <flu0r1ne@flu0r1ne.net>2023-09-10 03:50:27 -0500
committerflu0r1ne <flu0r1ne@flu0r1ne.net>2023-09-10 04:03:23 -0500
commit8b8aae2ac99bc91a72a32ca2040302f785e10e2b (patch)
tree22b4bea45744b9756b816df6a13fb2a753120194
parent93ce8e8489bda4a7ebe5161020c83a68f744481f (diff)
downloadfcgiwrap-8b8aae2ac99bc91a72a32ca2040302f785e10e2b.tar.xz
fcgiwrap-8b8aae2ac99bc91a72a32ca2040302f785e10e2b.zip
close() always results in a duplicate call
Remove close as it always results in a duplicated call, simplify logic
-rw-r--r--fcgiwrap.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/fcgiwrap.c b/fcgiwrap.c
index 8310284..cfb7797 100644
--- a/fcgiwrap.c
+++ b/fcgiwrap.c
@@ -62,6 +62,8 @@
# define NORETURN
#endif
+#define FCGI_FD 0
+
extern char **environ;
static char * const * inherited_environ;
static const char **allowed_programs;
@@ -706,8 +708,8 @@ static int listen_on_fd(int fd) {
perror("Failed to enable SO_REUSEADDR");
return -1;
}
- if (dup2(fd, 0) < 0) {
- perror("Failed to move socket to fd 0");
+ if (dup2(fd, FCGI_FD) < 0) {
+ fprintf(stderr, "Failed to move socket to fd %d", FCGI_FD);
return -1;
}
if (close(fd) < 0) {
@@ -809,7 +811,7 @@ int main(int argc, char **argv)
{
int nchildren = 1;
char *socket_url = NULL;
- int fd = 0;
+ int fd = FCGI_FD;
int c;
while ((c = getopt(argc, argv, "c:hfs:p:")) != -1) {
@@ -860,6 +862,10 @@ int main(int argc, char **argv)
#ifdef HAVE_SYSTEMD
if (sd_listen_fds(true) > 0) {
+ if(socket_url) {
+ perror("warning: a systemd socket has been provding, ignoring '-s'\n");
+ }
+
/* systemd woke us up. we should never see more than one FD passed to us. */
if (listen_on_fd(SD_LISTEN_FDS_START) < 0) {
return 1;
@@ -876,16 +882,15 @@ int main(int argc, char **argv)
prefork(nchildren);
fcgiwrap_main();
- if (fd) {
- const char *p = socket_url;
- close(fd);
+ close(FCGI_FD);
- if (socket_url) {
- if (!strncmp(p, "unix:", sizeof("unix:") - 1)) {
- p += sizeof("unix:") - 1;
- unlink(p);
- }
+ if (fd && socket_url) { // fd > 0 indicates a socket was setup by us
+ const char *p = socket_url;
+ if (!strncmp(p, "unix:", sizeof("unix:") - 1)) {
+ p += sizeof("unix:") - 1;
+ unlink(p);
}
}
+
return 0;
}