contrib/package/olsrd-luci: remove garbage from 140-olsrd-optimize-size.patch
[project/luci.git] / contrib / package / olsrd-luci / patches / 150-add-watchdog.patch
1 diff -Nur olsrd-0-5-6-fc691af9a18d.orig/Makefile olsrd-0-5-6-fc691af9a18d/Makefile
2 --- olsrd-0-5-6-fc691af9a18d.orig/Makefile      2009-03-14 22:39:09.000000000 +0000
3 +++ olsrd-0-5-6-fc691af9a18d/Makefile   2009-03-16 16:44:28.000000000 +0000
4 @@ -148,7 +148,7 @@
5  ifeq ($(OS),win32)
6  SUBDIRS := dot_draw httpinfo mini pgraph secure txtinfo
7  else
8 -SUBDIRS := bmf dot_draw dyn_gw dyn_gw_plain httpinfo mini nameservice pgraph secure txtinfo
9 +SUBDIRS := bmf dot_draw dyn_gw dyn_gw_plain httpinfo mini nameservice pgraph secure txtinfo watchdog
10  endif
11  endif
12  
13 @@ -229,6 +229,11 @@
14                 $(MAKECMD) -C lib/arprefresh
15                 $(MAKECMD) -C lib/arprefresh DESTDIR=$(DESTDIR) install
16  
17 +watchdog:
18 +               $(MAKECMD) -C lib/watchdog clean
19 +               $(MAKECMD) -C lib/watchdog
20 +               $(MAKECMD) -C lib/watchdog DESTDIR=$(DESTDIR) install
21 +
22  build_all:     all switch libs
23  install_all:   install install_libs
24  clean_all:     uberclean clean_libs
25 diff -Nur olsrd-0-5-6-fc691af9a18d.orig/lib/watchdog/Makefile olsrd-0-5-6-fc691af9a18d/lib/watchdog/Makefile
26 --- olsrd-0-5-6-fc691af9a18d.orig/lib/watchdog/Makefile 1970-01-01 00:00:00.000000000 +0000
27 +++ olsrd-0-5-6-fc691af9a18d/lib/watchdog/Makefile      2009-03-13 17:13:45.000000000 +0000
28 @@ -0,0 +1,56 @@
29 +# The olsr.org Optimized Link-State Routing daemon(olsrd)
30 +# Copyright (c) 2004-2009, the olsr.org team - see HISTORY file
31 +# All rights reserved.
32 +#
33 +# Redistribution and use in source and binary forms, with or without
34 +# modification, are permitted provided that the following conditions
35 +# are met:
36 +#
37 +# * Redistributions of source code must retain the above copyright
38 +#   notice, this list of conditions and the following disclaimer.
39 +# * Redistributions in binary form must reproduce the above copyright
40 +#   notice, this list of conditions and the following disclaimer in
41 +#   the documentation and/or other materials provided with the
42 +#   distribution.
43 +# * Neither the name of olsr.org, olsrd nor the names of its
44 +#   contributors may be used to endorse or promote products derived
45 +#   from this software without specific prior written permission.
46 +#
47 +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
48 +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
49 +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
50 +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
51 +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
52 +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
53 +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
54 +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
55 +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
57 +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
58 +# POSSIBILITY OF SUCH DAMAGE.
59 +#
60 +# Visit http://www.olsr.org for more information.
61 +#
62 +# If you find this software useful feel free to make a donation
63 +# to the project. For more information see the website or contact
64 +# the copyright holders.
65 +#
66 +
67 +OLSRD_PLUGIN = true
68 +PLUGIN_NAME =  olsrd_watchdog
69 +PLUGIN_VER =   0.1
70 +
71 +TOPDIR = ../..
72 +include $(TOPDIR)/Makefile.inc
73 +
74 +default_target: $(PLUGIN_FULLNAME)
75 +
76 +$(PLUGIN_FULLNAME): $(OBJS) version-script.txt
77 +               $(CC) $(LDFLAGS) -o $(PLUGIN_FULLNAME) $(OBJS) $(LIBS)
78 +
79 +install:       $(PLUGIN_FULLNAME)
80 +               $(STRIP) $(PLUGIN_FULLNAME)
81 +               $(INSTALL_LIB)
82 +
83 +clean:
84 +               rm -f $(OBJS) $(SRCS:%.c=%.d) $(PLUGIN_FULLNAME)
85 diff -Nur olsrd-0-5-6-fc691af9a18d.orig/lib/watchdog/README_WATCHDOG olsrd-0-5-6-fc691af9a18d/lib/watchdog/README_WATCHDOG
86 --- olsrd-0-5-6-fc691af9a18d.orig/lib/watchdog/README_WATCHDOG  1970-01-01 00:00:00.000000000 +0000
87 +++ olsrd-0-5-6-fc691af9a18d/lib/watchdog/README_WATCHDOG       2009-03-13 17:13:45.000000000 +0000
88 @@ -0,0 +1,34 @@
89 +---------------------------------------------------------------------
90 +Watchdog PLUGIN FOR OLSRD
91 +by Henning Rogge <hrogge@googlemail.com>
92 +---------------------------------------------------------------------
93 +
94 +This plugin is used for detecting a total freeze of the olsrd by an external script.
95 +Once per timeinterval (configurable) it writes the current time into
96 +a file.
97 +
98 +---------------------------------------------------------------------
99 +PLUGIN PARAMETERS (PlParam)
100 +---------------------------------------------------------------------
101 +
102 +PlParam "file" "/tmp/olsrd.watchdog"
103 +       Name of the "still alive" file written by the watchdog
104 +PlParam "interval" "5"
105 +       Overwrite the file every X seconds
106 +
107 +
108 +---------------------------------------------------------------------
109 +SAMPLE CONFIG
110 +---------------------------------------------------------------------
111 +
112 +add in /etc/olsrd.conf:
113 +
114 +LoadPlugin "olsrd_watchdog.so.0.1"
115 +{
116 +  PlParam "file" "/tmp/olsrd.watchdog"
117 +  PlParam "interval" "5"
118 +}
119 +
120 +
121 +---------------------------------------------------------------------
122 +EOF / 26.05.2005
123 diff -Nur olsrd-0-5-6-fc691af9a18d.orig/lib/watchdog/src/olsrd_plugin.c olsrd-0-5-6-fc691af9a18d/lib/watchdog/src/olsrd_plugin.c
124 --- olsrd-0-5-6-fc691af9a18d.orig/lib/watchdog/src/olsrd_plugin.c       1970-01-01 00:00:00.000000000 +0000
125 +++ olsrd-0-5-6-fc691af9a18d/lib/watchdog/src/olsrd_plugin.c    2009-03-16 16:51:34.000000000 +0000
126 @@ -0,0 +1,145 @@
127 +
128 +/*
129 + * The olsr.org Optimized Link-State Routing daemon(olsrd)
130 + * Copyright (c) 2004-2009, the olsr.org team - see HISTORY file
131 + * All rights reserved.
132 + *
133 + * Redistribution and use in source and binary forms, with or without
134 + * modification, are permitted provided that the following conditions
135 + * are met:
136 + *
137 + * * Redistributions of source code must retain the above copyright
138 + *   notice, this list of conditions and the following disclaimer.
139 + * * Redistributions in binary form must reproduce the above copyright
140 + *   notice, this list of conditions and the following disclaimer in
141 + *   the documentation and/or other materials provided with the
142 + *   distribution.
143 + * * Neither the name of olsr.org, olsrd nor the names of its
144 + *   contributors may be used to endorse or promote products derived
145 + *   from this software without specific prior written permission.
146 + *
147 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
148 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
149 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
150 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
151 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
152 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
153 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
154 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
155 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
156 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
157 + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
158 + * POSSIBILITY OF SUCH DAMAGE.
159 + *
160 + * Visit http://www.olsr.org for more information.
161 + *
162 + * If you find this software useful feel free to make a donation
163 + * to the project. For more information see the website or contact
164 + * the copyright holders.
165 + *
166 + */
167 +
168 +
169 + /*
170 +  * Example plugin for olsrd.org OLSR daemon
171 +  * Only the bare minimum
172 +  */
173 +
174 +
175 +#include "olsrd_plugin.h"
176 +#include "plugin_util.h"
177 +#include "olsr.h"
178 +#include "defs.h"
179 +#include "scheduler.h"
180 +#include "olsr_cookie.h"
181 +
182 +
183 +#include <stdio.h>
184 +#include <string.h>
185 +#include <stdlib.h>
186 +#include <time.h>
187 +#define PLUGIN_INTERFACE_VERSION 5
188 +
189 +static struct olsr_cookie_info *watchdog_timer_cookie;
190 +
191 +static char watchdog_filename[FILENAME_MAX + 1] = "/tmp/olsr.watchdog";
192 +static int watchdog_interval = 5;
193 +
194 +/**
195 + * Plugin interface version
196 + * Used by main olsrd to check plugin interface version
197 + */
198 +int
199 +olsrd_plugin_interface_version(void)
200 +{
201 +  return PLUGIN_INTERFACE_VERSION;
202 +}
203 +
204 +
205 +static int
206 +set_watchdog_file(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused)))
207 +{
208 +  strncpy(watchdog_filename, value, FILENAME_MAX);
209 +  return 0;
210 +}
211 +
212 +static int
213 +set_watchdog_interval(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon
214 +                      __attribute__ ((unused)))
215 +{
216 +  watchdog_interval = atoi(value);
217 +  return 0;
218 +}
219 +
220 +/**
221 + * Register parameters from config file
222 + * Called for all plugin parameters
223 + */
224 +static const struct olsrd_plugin_parameters plugin_parameters[] = {
225 +  {.name = "file",.set_plugin_parameter = &set_watchdog_file,.data = NULL},
226 +  {.name = "interval",.set_plugin_parameter = &set_watchdog_interval,.data = NULL},
227 +};
228 +
229 +void
230 +olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size)
231 +{
232 +  *params = plugin_parameters;
233 +  *size = ARRAYSIZE(plugin_parameters);
234 +}
235 +
236 +static void
237 +olsr_watchdog_write_alivefile(void *foo __attribute__ ((unused)))
238 +{
239 +  FILE *file = fopen(watchdog_filename, "w");
240 +  if (file == NULL) {
241 +    OLSR_PRINTF(3, "Error, cannot write watchdog alivefile");
242 +  } else {
243 +    fprintf(file, "%ld\n", (long)time(NULL));
244 +    fflush(file);
245 +    fclose(file);
246 +  }
247 +}
248 +
249 +/**
250 + * Initialize plugin
251 + * Called after all parameters are passed
252 + */
253 +int
254 +olsrd_plugin_init(void)
255 +{
256 +  /* create the cookie */
257 +  watchdog_timer_cookie = olsr_alloc_cookie("Watchdog: write alive-file", OLSR_COOKIE_TYPE_TIMER);
258 +
259 +  /* Register the GW check */
260 +  olsr_start_timer(watchdog_interval * MSEC_PER_SEC, 0, OLSR_TIMER_PERIODIC,
261 +                   &olsr_watchdog_write_alivefile, NULL, watchdog_timer_cookie->ci_id);
262 +
263 +  return 1;
264 +}
265 +
266 +/*
267 + * Local Variables:
268 + * c-basic-offset: 2
269 + * indent-tabs-mode: nil
270 + * End:
271 + */
272 diff -Nur olsrd-0-5-6-fc691af9a18d.orig/lib/watchdog/src/olsrd_plugin.h olsrd-0-5-6-fc691af9a18d/lib/watchdog/src/olsrd_plugin.h
273 --- olsrd-0-5-6-fc691af9a18d.orig/lib/watchdog/src/olsrd_plugin.h       1970-01-01 00:00:00.000000000 +0000
274 +++ olsrd-0-5-6-fc691af9a18d/lib/watchdog/src/olsrd_plugin.h    2009-03-13 17:13:45.000000000 +0000
275 @@ -0,0 +1,69 @@
276 +
277 +/*
278 + * The olsr.org Optimized Link-State Routing daemon(olsrd)
279 + * Copyright (c) 2004-2009, the olsr.org team - see HISTORY file
280 + * All rights reserved.
281 + *
282 + * Redistribution and use in source and binary forms, with or without
283 + * modification, are permitted provided that the following conditions
284 + * are met:
285 + *
286 + * * Redistributions of source code must retain the above copyright
287 + *   notice, this list of conditions and the following disclaimer.
288 + * * Redistributions in binary form must reproduce the above copyright
289 + *   notice, this list of conditions and the following disclaimer in
290 + *   the documentation and/or other materials provided with the
291 + *   distribution.
292 + * * Neither the name of olsr.org, olsrd nor the names of its
293 + *   contributors may be used to endorse or promote products derived
294 + *   from this software without specific prior written permission.
295 + *
296 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
297 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
298 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
299 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
300 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
301 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
302 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
303 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
304 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
305 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
306 + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
307 + * POSSIBILITY OF SUCH DAMAGE.
308 + *
309 + * Visit http://www.olsr.org for more information.
310 + *
311 + * If you find this software useful feel free to make a donation
312 + * to the project. For more information see the website or contact
313 + * the copyright holders.
314 + *
315 + */
316 +
317 +/*
318 + * Dynamic linked library for the olsr.org olsr daemon
319 + */
320 +
321 +#ifndef _OLSRD_PLUGIN_MINI
322 +#define _OLSRD_PLUGIN_MINI
323 +
324 +
325 +/****************************************************************************
326 + *                Functions that the plugin MUST provide                    *
327 + ****************************************************************************/
328 +
329 +
330 +/* Initialization function */
331 +int
332 +  olsrd_plugin_init(void);
333 +
334 +int
335 +  olsrd_plugin_interface_version(void);
336 +
337 +#endif
338 +
339 +/*
340 + * Local Variables:
341 + * c-basic-offset: 2
342 + * indent-tabs-mode: nil
343 + * End:
344 + */
345 diff -Nur olsrd-0-5-6-fc691af9a18d.orig/lib/watchdog/version-script.txt olsrd-0-5-6-fc691af9a18d/lib/watchdog/version-script.txt
346 --- olsrd-0-5-6-fc691af9a18d.orig/lib/watchdog/version-script.txt       1970-01-01 00:00:00.000000000 +0000
347 +++ olsrd-0-5-6-fc691af9a18d/lib/watchdog/version-script.txt    2009-03-13 17:13:45.000000000 +0000
348 @@ -0,0 +1,10 @@
349 +VERS_1.0
350 +{
351 +  global:
352 +    olsrd_plugin_interface_version;
353 +    olsrd_plugin_init;
354 +    olsrd_get_plugin_parameters;
355 +
356 +  local:
357 +    *;
358 +};