diff options
author | Angelo Marletta <angelo.marletta@gmail.com> | 2012-06-01 01:14:52 +0100 |
---|---|---|
committer | Angelo Marletta <angelo.marletta@gmail.com> | 2012-06-01 01:14:52 +0100 |
commit | 29b89baf08a0652b3e9f5d1d9399fb153280f38e (patch) | |
tree | 79dd6b81e5fda4b57f22a6da3c64cd20c861a745 /src | |
parent | 1970d7e05dc161e2d3fa72d98030f0af5aa63f61 (diff) | |
download | cpulimit-29b89baf08a0652b3e9f5d1d9399fb153280f38e.tar.gz |
file descriptor is now closed after iterating processes
Diffstat (limited to 'src')
-rw-r--r-- | src/procutils.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/procutils.c b/src/procutils.c index 2699aa2..fb7aaae 100644 --- a/src/procutils.c +++ b/src/procutils.c @@ -196,6 +196,18 @@ int init_process_iterator(struct process_iterator *i) { return 0; } +int close_process_iterator(struct process_iterator *i) { +#ifdef __linux__ + if (closedir(i->dip) == -1) { + perror("closedir"); + return 1; + } +#elif defined __APPLE__ + //TODO +#endif + return 0; +} + // reads the next user process from /process // automatic closing if the end of the list is reached int read_next_process(struct process_iterator *i) { @@ -404,8 +416,6 @@ int look_for_process_by_name(const char *process_name) init_process_iterator(&iter); pid_t pid = 0; -printf("name\n"); - while (read_next_process(&iter)==0) { pid = iter.current->pid; @@ -434,6 +444,7 @@ printf("name\n"); } } } + if (close_process_iterator(&iter) != 1) exit(1); if (found == 1) { //ok, the process was found return pid; @@ -447,6 +458,6 @@ printf("name\n"); return -pid; } //this MUST NOT happen - return 0; + exit(2); } |