51 lines
1.4 KiB
Diff
Executable File
51 lines
1.4 KiB
Diff
Executable File
Index: iptables-1.4.16.3/iptables/xtables-multi.c
|
|
===================================================================
|
|
--- iptables-1.4.16.3.orig/iptables/xtables-multi.c 2012-10-18 16:50:00.000000000 +0800
|
|
+++ iptables-1.4.16.3/iptables/xtables-multi.c 2017-05-17 13:40:26.493983903 +0800
|
|
@@ -1,8 +1,12 @@
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
+#include <sys/socket.h>
|
|
+#include <sys/un.h>
|
|
+#include <unistd.h>
|
|
#include "xshared.h"
|
|
|
|
+#include "xtables.h"
|
|
#include "xtables-multi.h"
|
|
|
|
#ifdef ENABLE_IPV4
|
|
@@ -35,7 +39,31 @@
|
|
{NULL},
|
|
};
|
|
|
|
+#define XTMSOCKET_NAME "xtables_multi"
|
|
+#define XTMSOCKET_LEN 14
|
|
+
|
|
int main(int argc, char **argv)
|
|
{
|
|
- return subcmd_main(argc, argv, multi_subcommands);
|
|
+ int i = 0, ret, xtm_socket;
|
|
+ struct sockaddr_un xtm_addr;
|
|
+
|
|
+ memset(&xtm_addr, 0, sizeof(xtm_addr));
|
|
+ xtm_addr.sun_family = AF_UNIX;
|
|
+ strcpy(xtm_addr.sun_path+1, XTMSOCKET_NAME);
|
|
+ xtm_socket = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
+ /* If we can't even create a socket, just revert to prior (lockless) behavior */
|
|
+ if (xtm_socket < 0)
|
|
+ return subcmd_main(argc, argv, multi_subcommands);
|
|
+
|
|
+ do {
|
|
+ ret = bind(xtm_socket, (struct sockaddr*)&xtm_addr,
|
|
+ offsetof(struct sockaddr_un, sun_path)+XTMSOCKET_LEN);
|
|
+ if (ret == 0)
|
|
+ return subcmd_main(argc, argv, multi_subcommands);
|
|
+ i++;
|
|
+ usleep(50000);
|
|
+ } while (i < 100);
|
|
+
|
|
+ fprintf(stderr, "ERROR: unable to obtain lock - another instance is already running\n");
|
|
+ exit(RESOURCE_PROBLEM);
|
|
}
|