aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbhackerozzo <bhackerozzo@3b445381-d045-0410-9223-e17ecdb95f4b>2008-08-29 23:04:27 +0000
committerbhackerozzo <bhackerozzo@3b445381-d045-0410-9223-e17ecdb95f4b>2008-08-29 23:04:27 +0000
commit8a34fa7c47579002e7e599fc7d7c8ecc2e316ce3 (patch)
treec56b7fcfb1a2dcd652f8d3c8790026a4482b4f00
parentf4fc87742f56e4c05b9340bb6eb99cd667483dcd (diff)
downloadcpulimit-8a34fa7c47579002e7e599fc7d7c8ecc2e316ce3.tar.gz
look_for_process_by_name() fixed for mac os
-rw-r--r--procutils.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/procutils.c b/procutils.c
index e7d4d89..d6dd438 100644
--- a/procutils.c
+++ b/procutils.c
@@ -380,7 +380,7 @@ int look_for_process_by_name(const char *process_name)
//the name of /proc/pid/exe symbolic link pointing to the executable file
char exelink[20];
//the name of the executable file
- char *exepath = malloc((PATH_MAX+1) * sizeof(char));
+ char exepath[PATH_MAX+1];
//whether the variable process_name is the absolute path or not
int is_absolute_path = process_name[0] == '/';
//flag indicating if the a process with given name was found
@@ -402,11 +402,13 @@ int look_for_process_by_name(const char *process_name)
//read the executable link
sprintf(exelink,"/proc/%d/exe",pid);
int size = readlink(exelink, exepath, sizeof(exepath));
+ exepath[size] = '\0';
#elif defined __APPLE__
//get the executable file name
if (GetProcessForPID(pid, &psn)) return -1;
if (GetProcessInformation(&psn, &info)) return -1;
int size = strlen(info.processName);
+ strcpy(exepath, info.processName);
#endif
if (size>0) {
found = 0;
@@ -433,7 +435,6 @@ int look_for_process_by_name(const char *process_name)
}
}
}
- free(exepath);
#ifdef __APPLE__
free(info.processName);
#endif
Un proyecto texto-plano.xyz