aboutsummaryrefslogtreecommitdiffstats
path: root/testing/wpa_actiond/no_trampoline.patch
blob: 560f05aafb4a9d134093132da4040a23f653fd14 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
--- wpa_actiond-1.4-old/wpa_actiond.c
+++ wpa_actiond-1.4-new/wpa_actiond.c
@@ -72,6 +72,23 @@
   WPA_ACTIOND_LOG_CUSTOM_ERROR
 };
 
+/* wpa_supplicant control structure */
+static struct wpa_ctrl *ctrl;
+  
+/* states and events */
+static enum wpastate state = WPA_ACTIOND_STATE_UNDEFINED;
+static enum wpaevent ev;
+/* select stuff */
+static int ctrl_fd;
+static fd_set ctrl_fds;
+/* save ssid */
+static char ssid[SSIDLEN], old_ssid[SSIDLEN];
+static char idstr[IDSTRLEN], old_idstr[IDSTRLEN];
+/* for terminate handler*/
+static const char *iface;
+static const char *script;
+static const char *pidfile;
+
 static void logevent(enum wpa_actiond_logevent l, const char *iface, const char *arg) {
   static int isopen = 0, tostderr = 0;
 
@@ -270,48 +287,43 @@
   }
 }
 
-static void loop(const char *iface, const char *ctrlpath, const int disconnect_timeout, const char *script, const char *pidfile) {
-  /* wpa_supplicant control structure */
-  struct wpa_ctrl *ctrl;
+static void terminate(int s) {
+  if(state == WPA_ACTIOND_STATE_CONNECTED || state == WPA_ACTIOND_STATE_CONNECTION_LOST) {
+    logevent(WPA_ACTIOND_LOG_DISCONNECTED, iface, ssid);
+    action(WPA_ACTIOND_ACTION_DISCONNECT, iface, ssid, idstr, wpa_ctrl_get_fd(ctrl), script);
+  }
+  logevent(WPA_ACTIOND_LOG_TERMINATE, iface, "");
+
+  FD_ZERO(&ctrl_fds);
+  wpa_ctrl_detach(ctrl);
+  wpa_ctrl_close(ctrl);
+  unlink(pidfile);
+  exit(0);
+}
+
+static void loop(const char *_iface, const char *ctrlpath, const int disconnect_timeout, const char *_script, const char *_pidfile) {
   /* buffer for wpa_supplicant replies */
   char reply[BUFLEN];
   size_t reply_len;
-  /* states and events */
-  enum wpastate state = WPA_ACTIOND_STATE_UNDEFINED;
-  enum wpaevent ev;
-  /* select stuff */
-  int ctrl_fd;
-  fd_set ctrl_fds;
   int r;
   /* select timeout */
   struct timeval timeout;
   struct timeval ping_timeout;
-  /* save ssid */
-  char ssid[SSIDLEN], old_ssid[SSIDLEN];
-  char idstr[IDSTRLEN], old_idstr[IDSTRLEN];
   /* path to control socket */
   char *ctrlsock = NULL;
   int ctrlsocklen;
 
+  /* set up globals for terminate signal handler */
+  iface = _iface;
+  script = _script;
+  pidfile = _pidfile;
+
   ssid[0] = '\0';
   old_ssid[0] = '\0';
   idstr[0] = '\0';
   old_idstr[0] = '\0';
 
   /* set up signals */
-  void terminate(int s) {
-    if(state == WPA_ACTIOND_STATE_CONNECTED || state == WPA_ACTIOND_STATE_CONNECTION_LOST) {
-      logevent(WPA_ACTIOND_LOG_DISCONNECTED, iface, ssid);
-      action(WPA_ACTIOND_ACTION_DISCONNECT, iface, ssid, idstr, wpa_ctrl_get_fd(ctrl), script);
-    }
-    logevent(WPA_ACTIOND_LOG_TERMINATE, iface, "");
-
-    FD_ZERO(&ctrl_fds);
-    wpa_ctrl_detach(ctrl);
-    wpa_ctrl_close(ctrl);
-    unlink(pidfile);
-    exit(0);
-  }
   signal(SIGTERM, terminate);
   signal(SIGHUP, SIG_IGN);