[Olsr-dev] [PATCH v1 12/43] lock_file: move olsrd_get_default_lockfile into its own file

Ferry Huberts (spam-protected)
Wed Nov 11 17:21:45 CET 2015


From: Ferry Huberts <(spam-protected)>

Signed-off-by: Ferry Huberts <(spam-protected)>
---
 src/cfgparser/Makefile                      |  2 +-
 src/cfgparser/cfgfile_gen.c                 |  1 +
 src/cfgparser/olsrd_conf.c                  | 19 +---------
 src/cfgparser/olsrd_conf.h                  | 12 ------
 src/{cfgparser/olsrd_conf.h => lock_file.c} | 59 +++++++++++------------------
 src/{misc.h => lock_file.h}                 | 18 +++------
 6 files changed, 32 insertions(+), 79 deletions(-)
 copy src/{cfgparser/olsrd_conf.h => lock_file.c} (69%)
 copy src/{misc.h => lock_file.h} (88%)

diff --git a/src/cfgparser/Makefile b/src/cfgparser/Makefile
index 6ace3c1..71f3dcf 100644
--- a/src/cfgparser/Makefile
+++ b/src/cfgparser/Makefile
@@ -57,7 +57,7 @@ else
 LIBNAME ?=	olsrd_cfgparser.so.0.1
 BINNAME ?=	olsrd_cfgparser
 
-OBJS +=		../ipcalc.o ../builddata.o ../common/autobuf.o
+OBJS +=		../ipcalc.o ../builddata.o ../common/autobuf.o ../lock_file.o
 endif
 
 
diff --git a/src/cfgparser/cfgfile_gen.c b/src/cfgparser/cfgfile_gen.c
index 4beb80f..f61e52c 100644
--- a/src/cfgparser/cfgfile_gen.c
+++ b/src/cfgparser/cfgfile_gen.c
@@ -44,6 +44,7 @@
 #include "../net_olsr.h"
 #include "../common/autobuf.h"
 #include "../egressTypes.h"
+#include "../lock_file.h"
 
 #include <stdarg.h>
 #include <stdio.h>
diff --git a/src/cfgparser/olsrd_conf.c b/src/cfgparser/olsrd_conf.c
index c9b01d5..b268d69 100644
--- a/src/cfgparser/olsrd_conf.c
+++ b/src/cfgparser/olsrd_conf.c
@@ -47,6 +47,7 @@
 #include "olsr.h"
 #include "egressTypes.h"
 #include "gateway.h"
+#include "lock_file.h"
 
 #include <assert.h>
 #include <stdio.h>
@@ -1371,24 +1372,6 @@ void set_derived_cnf(struct olsrd_config * cnf) {
   }
 }
 
-/**
- * @param cnf the olsrd configuration
- * @param ip_version the ip version
- * @return a malloc-ed string for the default lock file name
- */
-char * olsrd_get_default_lockfile(struct olsrd_config *cnf) {
-  char buf[FILENAME_MAX];
-  int ipv = (cnf->ip_version == AF_INET) ? 4 : 6;
-
-#ifndef DEFAULT_LOCKFILE_PREFIX
-  snprintf(buf, sizeof(buf), "%s-ipv%d.lock", cnf->configuration_file ? cnf->configuration_file : "olsrd", ipv);
-#else
-  snprintf(buf, sizeof(buf), "%s-ipv%d.lock", DEFAULT_LOCKFILE_PREFIX, ipv);
-#endif /* DEFAULT_LOCKFILE_PREFIX */
-
-  return strdup(buf);
-}
-
 /*
  * Local Variables:
  * c-basic-offset: 2
diff --git a/src/cfgparser/olsrd_conf.h b/src/cfgparser/olsrd_conf.h
index 0b5d17b..dec02d7 100644
--- a/src/cfgparser/olsrd_conf.h
+++ b/src/cfgparser/olsrd_conf.h
@@ -47,16 +47,6 @@
 
 #define PARSER_VERSION "0.1.2"
 
-#if defined __ANDROID__
-#define DEFAULT_LOCKFILE_PREFIX "/data/local/olsrd"
-#elif defined linux || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__
-#define DEFAULT_LOCKFILE_PREFIX "/var/run/olsrd"
-#elif defined _WIN32
-#define DEFAULT_LOCKFILE_PREFIX "C:\\olsrd"
-#else /* defined _WIN32 */
-#define DEFAULT_LOCKFILE_PREFIX "olsrd"
-#endif /* defined _WIN32 */
-
 extern int current_line;
 
 struct conf_token {
@@ -73,8 +63,6 @@ void set_default_cnf(struct olsrd_config *, char * configuration_file);
 
 void set_derived_cnf(struct olsrd_config * olsr_cnf);
 
-char * olsrd_get_default_lockfile(struct olsrd_config *cnf);
-
 #endif /* _OLSRD_CONF_H */
 
 /*
diff --git a/src/cfgparser/olsrd_conf.h b/src/lock_file.c
similarity index 69%
copy from src/cfgparser/olsrd_conf.h
copy to src/lock_file.c
index 0b5d17b..5873e63 100644
--- a/src/cfgparser/olsrd_conf.h
+++ b/src/lock_file.c
@@ -1,7 +1,6 @@
-
 /*
  * The olsr.org Optimized Link-State Routing daemon(olsrd)
- * Copyright (c) 2004, Andreas Tonnesen((spam-protected))
+ * Copyright (c) 2004-2009, the olsr.org team - see HISTORY file
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -39,47 +38,35 @@
  *
  */
 
-#ifndef _OLSRD_CONF_H
-#define _OLSRD_CONF_H
-
-#include "olsr_protocol.h"
-#include "olsr_cfg.h"
+#include "lock_file.h"
 
-#define PARSER_VERSION "0.1.2"
+#include <stdio.h>
+#include <string.h>
 
 #if defined __ANDROID__
-#define DEFAULT_LOCKFILE_PREFIX "/data/local/olsrd"
+  #define DEFAULT_LOCKFILE_PREFIX "/data/local/olsrd"
 #elif defined linux || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__
-#define DEFAULT_LOCKFILE_PREFIX "/var/run/olsrd"
+  #define DEFAULT_LOCKFILE_PREFIX "/var/run/olsrd"
 #elif defined _WIN32
-#define DEFAULT_LOCKFILE_PREFIX "C:\\olsrd"
+  #define DEFAULT_LOCKFILE_PREFIX "C:\\olsrd"
 #else /* defined _WIN32 */
-#define DEFAULT_LOCKFILE_PREFIX "olsrd"
+  #define DEFAULT_LOCKFILE_PREFIX "olsrd"
 #endif /* defined _WIN32 */
 
-extern int current_line;
-
-struct conf_token {
-  uint32_t integer;
-  float floating;
-  bool boolean;
-  char *string;
-};
-
-#define DEFAULT_STR(val) \
-(((!defcnf) && ((*((uint8_t *)(&cnfi->val)))==0))?" (d)":"")
-
-void set_default_cnf(struct olsrd_config *, char * configuration_file);
-
-void set_derived_cnf(struct olsrd_config * olsr_cnf);
-
-char * olsrd_get_default_lockfile(struct olsrd_config *cnf);
+/**
+ * @param cnf the olsrd configuration
+ * @param ip_version the ip version
+ * @return a malloc-ed string for the default lock file name
+ */
+char * olsrd_get_default_lockfile(struct olsrd_config *cnf) {
+  char buf[FILENAME_MAX];
+  int ipv = (cnf->ip_version == AF_INET) ? 4 : 6;
 
-#endif /* _OLSRD_CONF_H */
+#ifndef DEFAULT_LOCKFILE_PREFIX
+  snprintf(buf, sizeof(buf), "%s-ipv%d.lock", cnf->configuration_file ? cnf->configuration_file : "olsrd", ipv);
+#else
+  snprintf(buf, sizeof(buf), "%s-ipv%d.lock", DEFAULT_LOCKFILE_PREFIX, ipv);
+#endif /* DEFAULT_LOCKFILE_PREFIX */
 
-/*
- * Local Variables:
- * c-basic-offset: 2
- * indent-tabs-mode: nil
- * End:
- */
+  return strdup(buf);
+}
diff --git a/src/misc.h b/src/lock_file.h
similarity index 88%
copy from src/misc.h
copy to src/lock_file.h
index 9913b8a..868d996 100644
--- a/src/misc.h
+++ b/src/lock_file.h
@@ -1,7 +1,6 @@
-
 /*
  * The olsr.org Optimized Link-State Routing daemon(olsrd)
- * Copyright (c) 2004, Thomas Lopatic ((spam-protected))
+ * Copyright (c) 2004-2009, the olsr.org team - see HISTORY file
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -39,16 +38,11 @@
  *
  */
 
-#ifndef _OLSR_MISC_H
-#define _OLSR_MISC_H
+#ifndef SRC_LOCK_FILE_H_
+#define SRC_LOCK_FILE_H_
 
-void clear_console(void);
+#include "olsr_cfg.h"
 
-#endif /* _OLSR_MISC_H */
+char * olsrd_get_default_lockfile(struct olsrd_config *cnf);
 
-/*
- * Local Variables:
- * c-basic-offset: 2
- * indent-tabs-mode: nil
- * End:
- */
+#endif /* SRC_LOCK_FILE_H_ */
-- 
2.5.0




More information about the Olsr-dev mailing list