diff options
author | Theron Spiegl <tspiegl@gmail.com> | 2020-09-30 21:25:39 -0500 |
---|---|---|
committer | Theron Spiegl <tspiegl@gmail.com> | 2020-09-30 21:25:39 -0500 |
commit | 0cbb3a1da6038fb85810be7f334c9987c323eece (patch) | |
tree | 6822a5df491b761125bb1d4f4875ad7ad3c78a69 | |
parent | ee98a26f4e9df88cabeb11cfdbaf6f06b3aace30 (diff) |
don't compile regex in loopv1.0
-rw-r--r-- | src/attach.c | 4 | ||||
-rw-r--r-- | src/whatfiles.c | 7 | ||||
-rw-r--r-- | src/whatfiles.h | 2 |
3 files changed, 9 insertions, 4 deletions
diff --git a/src/attach.c b/src/attach.c index 7aad391..1846288 100644 --- a/src/attach.c +++ b/src/attach.c @@ -37,13 +37,9 @@ char read_status(pid_t pid) if (!h_status) return 0; read_file(str, 4096, h_status); - regex_t regex; int err; regmatch_t pmatch[2]; - if (regcomp(®ex, "State:\\W+([A-Za-z])", REG_EXTENDED) != 0) - SYS_ERR("regex compilation error"); err = regexec(®ex, str->data, 2, pmatch, 0); - regfree(®ex); if (err) { DEBUG("failed to find regex match in /proc/%d/status file\n", pid); } else { diff --git a/src/whatfiles.c b/src/whatfiles.c index fb9f291..0004308 100644 --- a/src/whatfiles.c +++ b/src/whatfiles.c @@ -1,4 +1,5 @@ #include <dirent.h> +#include <regex.h> #include <signal.h> #include <stddef.h> #include <string.h> @@ -14,6 +15,7 @@ FILE *Handle = (FILE*)NULL; int Debug = 0; +regex_t regex; LastSyscall_t LastSyscall; DebugStats_t DebugStats; @@ -92,6 +94,10 @@ int main(int argc, char* argv[]) HashMap hashmap = &hm; init_hashmap(hashmap); + if (regcomp(®ex, "State:\\W+([A-Za-z])", REG_EXTENDED) != 0) { + SYS_ERR("regex compilation error"); + } + int start_of_user_command = discover_flags(argc, argv); char *user_filename = parse_flags(start_of_user_command, argv, &pid, &stdout_override, &attach); if (start_of_user_command == argc && !attach) { @@ -210,6 +216,7 @@ int main(int argc, char* argv[]) } } + regfree(®ex); err = destroy(hashmap); HASH_ERR_CHECK(err, "tried to free null pointers in hashmap.\n") fclose(Handle); diff --git a/src/whatfiles.h b/src/whatfiles.h index 4561c11..a4ea9cd 100644 --- a/src/whatfiles.h +++ b/src/whatfiles.h @@ -2,6 +2,7 @@ #define WHATFILES_H #include <errno.h> +#include <regex.h> #include <stdbool.h> #include <stdlib.h> @@ -9,6 +10,7 @@ extern int Debug; extern FILE *Handle; +extern regex_t regex; #define MODE_LEN 32 #define OUTPUT(...) fprintf(Handle, __VA_ARGS__) |