From c11e62bfd425fe4bcbb1729215bf18f16f97f768 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Thu, 1 Dec 2011 18:59:54 -0200 Subject: [PATCH] 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. --- libkmod/libkmod-config.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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; -- 2.47.2