Skip to content

Instantly share code, notes, and snippets.

@hashbrowncipher
Created October 2, 2015 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hashbrowncipher/a0da32514f2f240cbbbf to your computer and use it in GitHub Desktop.
Save hashbrowncipher/a0da32514f2f240cbbbf to your computer and use it in GitHub Desktop.
diff --git a/include/types/global.h b/include/types/global.h
index cb04074..90173ad 100644
--- a/include/types/global.h
+++ b/include/types/global.h
@@ -204,6 +204,7 @@ struct global {
int cache_size;
} _51degrees;
#endif
+ int socketlock;
};
extern struct global global;
diff --git a/src/haproxy.c b/src/haproxy.c
index 465bb6a..78bc4fb 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -30,6 +30,7 @@
#include <unistd.h>
#include <string.h>
#include <ctype.h>
+#include <sys/file.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
@@ -197,6 +198,7 @@ struct global global = {
.cache_size = 0,
},
#endif
+ .socketlock = -1
/* others NULL OK */
};
@@ -1849,7 +1851,14 @@ int main(int argc, char **argv)
global.mode &= ~MODE_VERBOSE;
global.mode |= MODE_QUIET; /* ensure that we won't say anything from now */
}
- pid = getpid(); /* update child's pid */
+
+ {
+ char socketlockstr[100];
+ snprintf(socketlockstr, sizeof(socketlockstr), "/var/run/haproxy_pids/%d\n", ret);
+ global.socketlock = open(socketlockstr, O_CREAT | O_WRONLY | O_TRUNC, 0644);
+ ret = flock(global.socketlock, LOCK_EX | LOCK_NB);
+ }
+
setsid();
fork_poller();
}
diff --git a/src/proxy.c b/src/proxy.c
index fb62b7c..9ed4282 100644
--- a/src/proxy.c
+++ b/src/proxy.c
@@ -1075,6 +1075,10 @@ void pause_proxies(void)
prs = prs->next;
}
+ if(global.socketlock >= 0) {
+ flock(global.socketlock, LOCK_UN);
+ }
+
if (err) {
Warning("Some proxies refused to pause, performing soft stop now.\n");
send_log(p, LOG_WARNING, "Some proxies refused to pause, performing soft stop now.\n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment