Module: sip-router
Branch: master
Commit: d2e6918acc75178d8669615bff068914bd34abfa
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=d2e6918…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Wed Aug 20 12:17:25 2014 +0200
lib/srutils: add sruid_next_safe() function
- checks to see if the sruid was initialized by same process and if not,
triggers a reinit
- pid is stored inside the sruid struct
---
lib/srutils/sruid.c | 10 ++++++++++
lib/srutils/sruid.h | 2 ++
2 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/lib/srutils/sruid.c b/lib/srutils/sruid.c
index db84550..ca67bfc 100644
--- a/lib/srutils/sruid.c
+++ b/lib/srutils/sruid.c
@@ -96,6 +96,7 @@ int sruid_init(sruid_t *sid, char sep, char *cid, int mode)
sid->out = sid->buf + i + 5;
sid->uid.s = sid->buf;
sid->mode = (sruid_mode_t)mode;
+ sid->pid = my_pid();
LM_DBG("root for sruid is [%.*s] (%u / %d)\n", i+5, sid->uid.s,
sid->counter, i+5);
return 0;
@@ -131,6 +132,7 @@ int sruid_reinit(sruid_t *sid, int mode)
sid->out = sid->buf + i + 5;
sid->uid.s = sid->buf;
sid->mode = (sruid_mode_t)mode;
+ sid->pid = my_pid();
LM_DBG("re-init root for sruid is [%.*s] (%u / %d)\n", i+5, sid->uid.s,
sid->counter, i+5);
return 0;
@@ -177,3 +179,11 @@ int sruid_next(sruid_t *sid)
return 0;
}
+/**
+ *
+ */
+int sruid_next_safe(sruid_t *sid)
+{
+ if(unlikely(sid->pid!=my_pid())) sruid_reinit(sid, sid->mode);
+ return sruid_next(sid);
+}
diff --git a/lib/srutils/sruid.h b/lib/srutils/sruid.h
index 8124d5c..a459188 100644
--- a/lib/srutils/sruid.h
+++ b/lib/srutils/sruid.h
@@ -36,10 +36,12 @@ typedef struct sruid {
char *out;
str uid;
unsigned int counter;
+ int pid;
sruid_mode_t mode;
} sruid_t;
int sruid_init(sruid_t *sid, char sep, char *cid, int mode);
int sruid_next(sruid_t *sid);
+int sruid_next_safe(sruid_t *sid);
#endif