[collectd] [PATCH] email plugin: Use strtok_r() instead of strtok().
Sebastian Harl
sh<span style="display: none;">.trailing-username</span>(a)<span style="display: none;">leading-domain.</span>tokkee.org
Thu Nov 30 12:02:46 CET 2006
strtok() internally uses a static buffer and thus is not thread-safe.
Signed-off-by: Sebastian Harl <sh<span style="display: none;">.trailing-username</span>(a)<span style="display: none;">leading-domain.</span>tokkee.org>
---
src/email.c | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/src/email.c b/src/email.c
index 27370ae..37194fb 100644
--- a/src/email.c
+++ b/src/email.c
@@ -361,8 +361,9 @@ static void *collect (void *arg)
}
if ('e' == line[0]) { /* e:<type>:<bytes> */
- char *type = strtok (line + 2, ":");
- char *tmp = strtok (NULL, ":");
+ char *ptr = NULL;
+ char *type = strtok_r (line + 2, ":", &ptr);
+ char *tmp = strtok_r (NULL, ":", &ptr);
int bytes = 0;
if (NULL == tmp) {
@@ -389,13 +390,14 @@ static void *collect (void *arg)
pthread_mutex_unlock (&score_mutex);
}
else if ('c' == line[0]) { /* c:<type1>[,<type2>,...] */
- char *type = strtok (line + 2, ",");
+ char *ptr = NULL;
+ char *type = strtok_r (line + 2, ",", &ptr);
do {
pthread_mutex_lock (&check_mutex);
type_list_incr (&check, type, 1);
pthread_mutex_unlock (&check_mutex);
- } while (NULL != (type = strtok (NULL, ",")));
+ } while (NULL != (type = strtok_r (NULL, ",", &ptr)));
}
else {
syslog (LOG_ERR, "email: unknown type '%c'", line[0]);
--
1.4.3.2
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20061130/a7d36b73/attachment.pgp
More information about the collectd
mailing list