From e54fdb501e5a5db832b0d6be0f147560a9a2485b Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Fri, 11 Nov 2016 19:16:23 +0900 Subject: [PATCH] fix buxton_update_client_label step - In update_client_label request, find all clients by pid and update each client's label. Change-Id: I4465d3a2df8b7427a4ce305da71e081c8387f77e Signed-off-by: Jiwoong Im --- daemon/daemon.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/daemon/daemon.c b/daemon/daemon.c index c7a212d..6cc5587 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -503,22 +503,28 @@ static void proc_get_priv(struct bxt_client *cli, resp->val = val; } -static int update_label(struct bxt_client *cli) +static void update_label(gpointer key, gpointer value, gpointer user_data) { int fd; int ret; char buf[1024]; char path[1024]; + struct bxt_client *cli = (struct bxt_client *)value; + int pid = *(int *)user_data; + + if (cli->cred.pid != pid) + return; + snprintf(path, sizeof(path), "/proc/%d/attr/current", cli->cred.pid); fd = open(path, O_RDONLY); if (fd < 0) - return -1; + return; ret = read(fd, buf, sizeof(buf) - 1); if (ret <= 0) { close(fd); - return -1; + return; } else { buf[ret] = 0; } @@ -528,7 +534,12 @@ static int update_label(struct bxt_client *cli) if (cli->label) free(cli->label); cli->label = strdup(buf); +} +static int update_client_label(struct bxt_client *cli) +{ + g_hash_table_foreach(cli->bxtd->clients, (GHFunc)update_label, + &(cli->cred.pid)); return 0; } @@ -551,7 +562,7 @@ static void proc_control(struct bxt_client *cli, resp->res = 0; return; } else if (!strcmp(rqst->key, "update_client_label")) { - resp->res = update_label(cli); + resp->res = update_client_label(cli); return; } resp->res = ENOTSUP; -- 2.7.4