From 6f4fbc11ec5c2bf78a5db0c36aa88b678c21fcc5 Mon Sep 17 00:00:00 2001 From: Vitaliy Cherepanov Date: Fri, 3 Apr 2015 15:06:50 +0300 Subject: [PATCH] [FIX] search launched app by binary path Change-Id: Ic5a6e5420a4bab23b5e5e1fe68238ae4459f5a52 Signed-off-by: Vitaliy Cherepanov --- daemon/utils.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/daemon/utils.c b/daemon/utils.c index 81432d5..c253b28 100644 --- a/daemon/utils.c +++ b/daemon/utils.c @@ -254,17 +254,19 @@ void kill_app_web(const char *app_id) } } -#define SUB_1(x) (x-1) -#define STRDEFINE(x) #x +#define STRDEFINE_L2(x) #x +#define STRDEFINE(x) STRDEFINE_L2(x) + // find process id from executable binary path static pid_t find_pid_from_path(const char *path) { - char buf[BUFFER_MAX]; + char buf[BUFFER_MAX + 1]; char cmdline[PATH_MAX]; DIR *proc; FILE *fp = NULL; - static char dirent_buffer[ sizeof(struct dirent) + PATH_MAX + 1 ] = {0,}; - static struct dirent *dirent_r = (struct dirent *)dirent_buffer; + static const char scan_format[] = "%" STRDEFINE(BUFFER_MAX) "s"; + char dirent_buffer[ sizeof(struct dirent) + PATH_MAX + 1 ] = {0,}; + struct dirent *dirent_r = (struct dirent *)dirent_buffer; struct dirent *entry; int found, len = strlen(path); pid_t pid = 0; @@ -287,7 +289,7 @@ static pid_t find_pid_from_path(const char *path) continue; found = 0; - if (fscanf(fp, "%" STRDEFINE(SUB_1(BUFFER_MAX)) "s", buf) != EOF) /* read only argv[0] */ + if (fscanf(fp, scan_format, buf) != EOF) /* read only argv[0] */ found = (strncmp(path, buf, len) == 0); fclose(fp); -- 2.7.4