Changeset: f0f628ca4d9e for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f0f628ca4d9e
Modified Files:
tools/merovingian/client/monetdb.c
tools/merovingian/daemon/argvcmds.c
tools/merovingian/utils/utils.c
Branch: Nov2019
Log Message:
Avoid strtok, use strtok_r instead.
strtok is not thread-safe, strtok_r is.
diffs (106 lines):
diff --git a/tools/merovingian/client/monetdb.c
b/tools/merovingian/client/monetdb.c
--- a/tools/merovingian/client/monetdb.c
+++ b/tools/merovingian/client/monetdb.c
@@ -213,6 +213,7 @@ MEROgetStatus(sabdb **ret, char *databas
char *p;
char *buf;
char *e;
+ char *sp;
if (database == NULL)
database = "#all";
@@ -224,14 +225,14 @@ MEROgetStatus(sabdb **ret, char *databas
sw = malloc(sizeof(sabdb *) * swlen);
orig = NULL;
- if ((p = strtok(buf, "\n")) != NULL) {
+ if ((p = strtok_r(buf, "\n", &sp)) != NULL) {
if (strcmp(p, "OK") != 0) {
p = strdup(p);
free(buf);
free(sw);
return(p);
}
- for (swpos = 0; (p = strtok(NULL, "\n")) != NULL; swpos++) {
+ for (swpos = 0; (p = strtok_r(NULL, "\n", &sp)) != NULL;
swpos++) {
e = msab_deserialise(&stats, p);
if (e != NULL) {
printf("WARNING: failed to parse response from "
@@ -898,6 +899,7 @@ command_discover(int argc, char *argv[])
size_t posloc = 0;
size_t loclen = 0;
char **locations = malloc(sizeof(char*) * numlocs);
+ char *sp;
if (argc == 0) {
exit(2);
@@ -921,14 +923,14 @@ command_discover(int argc, char *argv[])
exit(2);
}
- if ((p = strtok(buf, "\n")) != NULL) {
+ if ((p = strtok_r(buf, "\n", &sp)) != NULL) {
if (strcmp(p, "OK") != 0) {
fprintf(stderr, "%s: %s\n", argv[0], p);
exit(1);
}
if (twidth > 0)
location = malloc(twidth + 1);
- while ((p = strtok(NULL, "\n")) != NULL) {
+ while ((p = strtok_r(NULL, "\n", &sp)) != NULL) {
if ((q = strchr(p, '\t')) == NULL) {
/* doesn't look correct */
printf("%s: WARNING: discarding incorrect line:
%s\n",
@@ -1376,9 +1378,10 @@ command_get(int argc, char *argv[])
} else {
/* check validity of properties before printing them */
if (stats == orig) {
+ char *sp;
snprintf(vbuf, sizeof(vbuf), "%s", property);
buf = vbuf;
- while ((p = strtok(buf, ",")) != NULL) {
+ while ((p = strtok_r(buf, ",", &sp)) != NULL) {
buf = NULL;
if (strcmp(p, "name") == 0)
continue;
@@ -1394,7 +1397,8 @@ command_get(int argc, char *argv[])
if (stats == orig)
printf(" name prop source
value\n");
- while ((p = strtok(buf, ",")) != NULL) {
+ char *sp;
+ while ((p = strtok_r(buf, ",", &sp)) != NULL) {
buf = NULL;
/* filter properties based on object type */
diff --git a/tools/merovingian/daemon/argvcmds.c
b/tools/merovingian/daemon/argvcmds.c
--- a/tools/merovingian/daemon/argvcmds.c
+++ b/tools/merovingian/daemon/argvcmds.c
@@ -209,7 +209,8 @@ command_get(confkeyval *ckv, int argc, c
}
printf(" property value\n");
- while ((p = strtok(property, ",")) != NULL) {
+ char *sp;
+ while ((p = strtok_r(property, ",", &sp)) != NULL) {
property = NULL;
if (strcmp(p, "dbfarm") == 0) {
value = dbfarm;
diff --git a/tools/merovingian/utils/utils.c b/tools/merovingian/utils/utils.c
--- a/tools/merovingian/utils/utils.c
+++ b/tools/merovingian/utils/utils.c
@@ -96,10 +96,11 @@ readConfFileFull(confkeyval *list, FILE
while (fgets(buf, sizeof(buf), cnf) != NULL) {
if (strlen(buf) > 1 && buf[0] != '#') {
/* tokenize */
- key = strtok(buf, separator);
- val = strtok(NULL, separator);
+ char *sp;
+ key = strtok_r(buf, separator, &sp);
+ val = strtok_r(NULL, separator, &sp);
/* strip trailing newline */
- val = strtok(val, "\n");
+ val = strtok_r(val, "\n", &sp);
if ((err = setConfValForKey(t, key, val)) != NULL) {
if (strstr(err, "is not recognized") != NULL) {
/* If we already have PROPLENGTH
entries in the list, ignore
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list