From: Lucas De Marchi Date: Thu, 1 Dec 2011 20:59:54 +0000 (-0200) Subject: Use strtok_r insteat of strtok X-Git-Tag: v1~148 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c11e62bfd425fe4bcbb1729215bf18f16f97f768;p=thirdparty%2Fkmod.git Use strtok_r insteat of strtok strtok is not thread-safe because it uses a static pointer to keep track of position in the string. Using strtok_r solves the problem. --- diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c index 65c4369f..462250d0 100644 --- a/libkmod/libkmod-config.c +++ b/libkmod/libkmod-config.c @@ -116,18 +116,18 @@ int kmod_parse_config_file(struct kmod_ctx *ctx, const char *filename, return errno; while ((line = getline_wrapped(fp, &linenum)) != NULL) { - char *cmd; + char *cmd, *saveptr; if (line[0] == '\0' || line[0] == '#') goto done_next; - cmd = strtok(line, "\t "); + cmd = strtok_r(line, "\t ", &saveptr); if (cmd == NULL) goto done_next; if (!strcmp(cmd, "alias")) { - char *alias = strtok(NULL, "\t "); - char *modname = strtok(NULL, "\t "); + char *alias = strtok_r(NULL, "\t ", &saveptr); + char *modname = strtok_r(NULL, "\t ", &saveptr); if (alias == NULL || modname == NULL) goto syntax_error; @@ -136,7 +136,7 @@ int kmod_parse_config_file(struct kmod_ctx *ctx, const char *filename, underscores(ctx, alias), underscores(ctx, modname)); } else if (!strcmp(cmd, "blacklist")) { - char *modname = strtok(NULL, "\t "); + char *modname = strtok_r(NULL, "\t ", &saveptr); if (modname == NULL) goto syntax_error;