浏览代码

CDP: Fix linking issues

Carsten Bock 8 年之前
父节点
当前提交
79df9e0075

+ 1 - 0
src/modules/cdp/acceptor.c

@@ -60,6 +60,7 @@
 #include "tcp_accept.h"
 #include "config.h"
 #include "worker.h"
+#include "diameter_peer.h"
 
 
 /* defined in ../diameter_peer.c */

+ 3 - 68
src/modules/cdp/diameter_peer.c

@@ -67,10 +67,9 @@ dp_config *config=0;		/**< Configuration for this diameter peer 	*/
 int *shutdownx=0;			/**< whether a shutdown is in progress		*/
 gen_lock_t *shutdownx_lock; /**< lock used on shutdown				*/
 
-pid_t *dp_first_pid;		/**< first pid that we started from		*/
-
-pid_list_head_t *pid_list;	/**< list of local processes			*/
-gen_lock_t *pid_list_lock;	/**< lock for list of local processes	*/
+pid_t *dp_first_pid = 0;		/**< first pid that we started from		*/
+pid_list_head_t *pid_list = 0;	/**< list of local processes			*/
+gen_lock_t *pid_list_lock = 0;	/**< lock for list of local processes	*/
 
 extern handler_list *handlers; 		/**< list of handlers */
 extern gen_lock_t *handlers_lock;	/**< lock for list of handlers */
@@ -78,70 +77,6 @@ extern gen_lock_t *handlers_lock;	/**< lock for list of handlers */
 extern peer_list_t *peer_list;		/**< list of peers */
 extern gen_lock_t *peer_list_lock;	/**< lock for the list of peers */
 
-
-/**
- * Add a pid to the local process list.
- * @param pid newly forked pid
- * @returns 1 on success or 0 on error
- */
-static inline int dp_add_pid(pid_t pid)
-{
-	pid_list_t *n;
-	lock_get(pid_list_lock);
-	n = shm_malloc(sizeof(pid_list_t));
-	if (!n){
-		LOG_NO_MEM("shm",sizeof(pid_list_t));
-		lock_release(pid_list_lock);
-		return 0;
-	}
-	n->pid = pid;
-	n->next = 0;
-	n->prev = pid_list->tail;
-	if (!pid_list->head) pid_list->head = n;
-	if (pid_list->tail) pid_list->tail->next = n;
-	pid_list->tail = n;
-	lock_release(pid_list_lock);
-	return 1;
-}
-
-/**
- * Returns the last pid in the local process list.
- */
-static inline int dp_last_pid()
-{
-	int pid;
-	lock_get(pid_list_lock);
-	if (pid_list->tail)	pid = pid_list->tail->pid;
-	else pid = -1;
-	lock_release(pid_list_lock);
-	return pid;
-}
-
-/**
- * Delete a pid from the process list
- * @param pid - the pid to remove
- */
-static inline void dp_del_pid(pid_t pid)
-{
-	pid_list_t *i;
-	lock_get(pid_list_lock);
-	i = pid_list->head;
-	if (!i) {
-		lock_release(pid_list_lock);
-		return;
-	}
-	while(i && i->pid!=pid) i = i->next;
-	if (i){
-		if (i->prev) i->prev->next = i->next;
-		else pid_list->head = i->next;
-		if (i->next) i->next->prev = i->prev;
-		else pid_list->tail = i->prev;
-		shm_free(i);
-	}
-	lock_release(pid_list_lock);
-}
-
-
 /**
  * Real initialization, called after the config is parsed
  */

+ 68 - 0
src/modules/cdp/diameter_peer.h

@@ -65,6 +65,11 @@ typedef struct {
 	pid_list_t *head,*tail;
 } pid_list_head_t;
 
+pid_t *dp_first_pid;		/**< first pid that we started from		*/
+
+pid_list_head_t *pid_list;	/**< list of local processes			*/
+gen_lock_t *pid_list_lock;	/**< lock for list of local processes	*/
+
 int diameter_peer_init_str(str config_str);
 int diameter_peer_init(char *cfg_filename);
 
@@ -72,4 +77,67 @@ int diameter_peer_start(int blocking);
 
 void diameter_peer_destroy();
 
+
+/**
+ * Add a pid to the local process list.
+ * @param pid newly forked pid
+ * @returns 1 on success or 0 on error
+ */
+static inline int dp_add_pid(pid_t pid)
+{
+	pid_list_t *n;
+	lock_get(pid_list_lock);
+	n = shm_malloc(sizeof(pid_list_t));
+	if (!n){
+		LOG_NO_MEM("shm",sizeof(pid_list_t));
+		lock_release(pid_list_lock);
+		return 0;
+	}
+	n->pid = pid;
+	n->next = 0;
+	n->prev = pid_list->tail;
+	if (!pid_list->head) pid_list->head = n;
+	if (pid_list->tail) pid_list->tail->next = n;
+	pid_list->tail = n;
+	lock_release(pid_list_lock);
+	return 1;
+}
+
+/**
+ * Returns the last pid in the local process list.
+ */
+static inline int dp_last_pid()
+{
+	int pid;
+	lock_get(pid_list_lock);
+	if (pid_list->tail)	pid = pid_list->tail->pid;
+	else pid = -1;
+	lock_release(pid_list_lock);
+	return pid;
+}
+
+/**
+ * Delete a pid from the process list
+ * @param pid - the pid to remove
+ */
+static inline void dp_del_pid(pid_t pid)
+{
+	pid_list_t *i;
+	lock_get(pid_list_lock);
+	i = pid_list->head;
+	if (!i) {
+		lock_release(pid_list_lock);
+		return;
+	}
+	while(i && i->pid!=pid) i = i->next;
+	if (i){
+		if (i->prev) i->prev->next = i->next;
+		else pid_list->head = i->next;
+		if (i->next) i->next->prev = i->prev;
+		else pid_list->tail = i->prev;
+		shm_free(i);
+	}
+	lock_release(pid_list_lock);
+}
+
 #endif

+ 2 - 0
src/modules/cdp/receiver.c

@@ -67,6 +67,8 @@
 
 #include "receiver.h"
 
+#include "diameter_peer.h"
+
 #include "../../core/cfg/cfg_struct.h"
 
 extern dp_config *config;		/**< Configuration for this diameter peer 	*/

+ 2 - 0
src/modules/cdp/timer.c

@@ -51,6 +51,8 @@
 
 #include "timer.h"
 
+#include "diameter_peer.h"
+
 #include "../../core/cfg/cfg_struct.h"
 
 

+ 1 - 0
src/modules/cdp/worker.c

@@ -54,6 +54,7 @@
 
 #include "worker.h"
 #include "diameter_api.h"
+#include "diameter_peer.h"
 
 #include "../../core/cfg/cfg_struct.h"
 #include "cdp_stats.h"