From: Youngjae Cho Date: Thu, 17 Oct 2019 08:19:47 +0000 (+0900) Subject: Stop checking lock if process had been terminated X-Git-Tag: accepted/tizen/unified/20191111.105547~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5159c9a68c32b862217c40aa98df144945982928;p=platform%2Fcore%2Fsystem%2Fdeviced.git Stop checking lock if process had been terminated Change-Id: I960c850c033f6ab2297293ba092c101a1cf77775 Signed-off-by: Youngjae Cho --- diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index ad7e29c..ff8385e 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -133,9 +133,7 @@ static gboolean del_normal_cond(void *data); static gboolean del_dim_cond(void *data); static gboolean del_off_cond(void *data); -static gboolean pmlock_normal_check(void *data); -static gboolean pmlock_dim_check(void *data); -static gboolean pmlock_off_check(void *data); +static gboolean pmlock_check(void *data); static int default_proc_change_state(unsigned int cond, pid_t pid); static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state; @@ -161,10 +159,6 @@ static int trans_table[S_END][EVENT_END] = { { S_POWEROFF, S_POWEROFF }, /* S_POWEROFF */ }; -static GSourceFunc warning_cb[S_END] = { - NULL, pmlock_normal_check, pmlock_dim_check, pmlock_off_check, -}; - enum signal_type { SIGNAL_INVALID = 0, SIGNAL_PRE, @@ -251,6 +245,7 @@ typedef struct _pm_lock_node { pid_t pid; guint timeout_id; guint warning_id; + GVariant *warning_param; time_t time; bool holdkey_block; bool background; @@ -686,6 +681,7 @@ static PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, { guint warning_id = 0; PmLockNode *n; + GVariant *v = NULL; time_t now; n = (PmLockNode *) malloc(sizeof(PmLockNode)); @@ -694,14 +690,21 @@ static PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, return NULL; } - if (pid < INTERNAL_LOCK_BASE) - warning_id = g_timeout_add_seconds(display_conf.lightsensor_interval, - warning_cb[s_index], (void *)((intptr_t)pid)); + if (pid < INTERNAL_LOCK_BASE) { + v = g_variant_new("(ii)", s_index, pid); + if (v) { + warning_id = g_timeout_add_seconds(display_conf.lightsensor_interval, + pmlock_check, (void *)v); + } else { + _E("Failed to make GVariant."); + } + } time(&now); n->pid = pid; n->timeout_id = timeout_id; n->warning_id = warning_id; + n->warning_param = v; n->time = now; n->holdkey_block = holdkey_block; n->background = false; @@ -728,6 +731,10 @@ static int del_node(enum state_t s_index, PmLockNode *n) g_source_remove(n->warning_id); n->warning_id = 0; } + if (n->warning_param) { + g_variant_unref(n->warning_param); + n->warning_param = NULL; + } free(n); refresh_app_cond(); @@ -873,26 +880,57 @@ out: * or good process. so infinity or more then 1 min lock process, deviced * will be checked it to resoured. And then, it will be asked quit or maintain to user. */ -static void pmlock_check(void *data, char *st) +static gboolean pmlock_check(void *data) { const char *arr[2]; char chr_pid[PID_MAX]; + PmLockNode *node; + GVariant *v; + enum state_t state; pid_t pid; int ret; - if (!data || !st) - return; + if (!data) { + _E("Invalid parameter."); + return G_SOURCE_REMOVE; + } + + v = (GVariant*)data; + g_variant_get(v, "(ii)", &state, &pid); + + _D("Process %d requested state %d lock.", pid, state); - if (!strncmp(st, "lcdoff", 4) && backlight_ops.get_lcd_power() == DPMS_ON) { + if (state == S_LCDOFF && backlight_ops.get_lcd_power() == DPMS_ON) { _D("Lcd state is PM_LCD_POWER_ON"); - return; + return G_SOURCE_CONTINUE; + } + + /* Stop checking lock if process had been terminated */ + if (kill(pid, 0) == -1) { + node = find_node(state, pid); + del_node(state, node); + _I("Process %d not found. Stop checking lock.", pid); + return G_SOURCE_REMOVE; } - pid = (pid_t)((intptr_t)data); snprintf(chr_pid, sizeof(chr_pid), "%d", pid); arr[0] = chr_pid; - arr[1] = st; + switch (state) { + case S_NORMAL: + arr[1] = "normal"; + break; + case S_LCDDIM: + arr[1] = "lcddim"; + break; + case S_LCDOFF: + arr[1] = "lcdoff"; + break; + default: + _E("Invalid state."); + g_variant_unref(v); + return G_SOURCE_REMOVE; + } ret = dbus_handle_method_async_with_reply(RESOURCED_BUS_NAME, RESOURCED_PATH_PROCESS, @@ -901,23 +939,7 @@ static void pmlock_check(void *data, char *st) "is", arr, pmlock_check_cb, -1, NULL); if (ret < 0) _E("Failed to call dbus method"); -} -static gboolean pmlock_normal_check(void *data) -{ - pmlock_check(data, "normal"); - return G_SOURCE_CONTINUE; -} - -static gboolean pmlock_dim_check(void *data) -{ - pmlock_check(data, "lcddim"); - return G_SOURCE_CONTINUE; -} - -static gboolean pmlock_off_check(void *data) -{ - pmlock_check(data, "lcdoff"); return G_SOURCE_CONTINUE; } diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 6eaa984..cb6e375 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -135,9 +135,7 @@ static gboolean del_normal_cond(void *data); static gboolean del_dim_cond(void *data); static gboolean del_off_cond(void *data); -static gboolean pmlock_normal_check(void *data); -static gboolean pmlock_dim_check(void *data); -static gboolean pmlock_off_check(void *data); +static gboolean pmlock_check(void *data); static int default_proc_change_state(unsigned int cond, pid_t pid); static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state; @@ -163,10 +161,6 @@ static int trans_table[S_END][EVENT_END] = { { S_POWEROFF, S_POWEROFF }, /* S_POWEROFF */ }; -static GSourceFunc warning_cb[S_END] = { - NULL, pmlock_normal_check, pmlock_dim_check, pmlock_off_check, -}; - enum signal_type { SIGNAL_INVALID = 0, SIGNAL_PRE, @@ -253,6 +247,7 @@ typedef struct _pm_lock_node { pid_t pid; guint timeout_id; guint warning_id; + GVariant *warning_param; time_t time; bool holdkey_block; bool background; @@ -694,6 +689,7 @@ static PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, { guint warning_id = 0; PmLockNode *n; + GVariant *v = NULL; time_t now; n = (PmLockNode *) malloc(sizeof(PmLockNode)); @@ -702,14 +698,22 @@ static PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, return NULL; } - if (pid < INTERNAL_LOCK_BASE) - warning_id = g_timeout_add_seconds(display_conf.lightsensor_interval, - warning_cb[s_index], (void *)((intptr_t)pid)); + if (pid < INTERNAL_LOCK_BASE) { + v = g_variant_new("(ii)", s_index, pid); + if (v) { + warning_id = g_timeout_add_seconds(display_conf.lightsensor_interval, + pmlock_check, (void *)v); + } else { + _E("Failed to make GVariant."); + } + + } time(&now); n->pid = pid; n->timeout_id = timeout_id; n->warning_id = warning_id; + n->warning_param = v; n->time = now; n->holdkey_block = holdkey_block; n->background = false; @@ -736,6 +740,10 @@ static int del_node(enum state_t s_index, PmLockNode *n) g_source_remove(n->warning_id); n->warning_id = 0; } + if (n->warning_param) { + g_variant_unref(n->warning_param); + n->warning_param = NULL; + } free(n); refresh_app_cond(); @@ -881,26 +889,54 @@ out: * or good process. so infinity or more then 1 min lock process, deviced * will be checked it to resoured. And then, it will be asked quit or maintain to user. */ -static void pmlock_check(void *data, char *st) +static gboolean pmlock_check(void *data) { const char *arr[2]; char chr_pid[PID_MAX]; + PmLockNode *node; + GVariant *v; + enum state_t state; pid_t pid; int ret; - if (!data || !st) - return; + if (!data) { + _E("Invalid parameter."); + return G_SOURCE_REMOVE; + } + + v = (GVariant*)data; + g_variant_get(v, "(ii)", &state, &pid); - if (!strncmp(st, "lcdoff", 4) && backlight_ops.get_lcd_power() == DPMS_ON) { + if (state == S_LCDOFF && backlight_ops.get_lcd_power() == DPMS_ON) { _D("Lcd state is PM_LCD_POWER_ON"); - return; + return G_SOURCE_CONTINUE; } - pid = (pid_t)((intptr_t)data); - snprintf(chr_pid, sizeof(chr_pid), "%d", pid); + /* Stop checking lock if process had been terminated */ + if (kill(pid, 0) == -1) { + node = find_node(state, pid); + del_node(state, node); + _I("Process %d not found. Stop checking lock.", pid); + return G_SOURCE_REMOVE; + } + snprintf(chr_pid, sizeof(chr_pid), "%d", pid); arr[0] = chr_pid; - arr[1] = st; + switch (state) { + case S_NORMAL: + arr[1] = "normal"; + break; + case S_LCDDIM: + arr[1] = "lcddim"; + break; + case S_LCDOFF: + arr[1] = "lcdoff"; + break; + default: + _E("Invalid state."); + g_variant_unref(v); + return G_SOURCE_REMOVE; + } ret = dbus_handle_method_async_with_reply(RESOURCED_BUS_NAME, RESOURCED_PATH_PROCESS, @@ -909,23 +945,7 @@ static void pmlock_check(void *data, char *st) "is", arr, pmlock_check_cb, -1, NULL); if (ret < 0) _E("Failed to call dbus method"); -} -static gboolean pmlock_normal_check(void *data) -{ - pmlock_check(data, "normal"); - return G_SOURCE_CONTINUE; -} - -static gboolean pmlock_dim_check(void *data) -{ - pmlock_check(data, "lcddim"); - return G_SOURCE_CONTINUE; -} - -static gboolean pmlock_off_check(void *data) -{ - pmlock_check(data, "lcdoff"); return G_SOURCE_CONTINUE; } diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 2d94505..a520497 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -133,9 +133,7 @@ static gboolean del_normal_cond(void *data); static gboolean del_dim_cond(void *data); static gboolean del_off_cond(void *data); -static gboolean pmlock_normal_check(void *data); -static gboolean pmlock_dim_check(void *data); -static gboolean pmlock_off_check(void *data); +static gboolean pmlock_check(void *data); static int default_proc_change_state(unsigned int cond, pid_t pid); static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state; @@ -161,10 +159,6 @@ static int trans_table[S_END][EVENT_END] = { { S_POWEROFF, S_POWEROFF }, /* S_POWEROFF */ }; -static GSourceFunc warning_cb[S_END] = { - NULL, pmlock_normal_check, pmlock_dim_check, pmlock_off_check, -}; - enum signal_type { SIGNAL_INVALID = 0, SIGNAL_PRE, @@ -251,6 +245,7 @@ typedef struct _pm_lock_node { pid_t pid; guint timeout_id; guint warning_id; + GVariant *warning_param; time_t time; bool holdkey_block; bool background; @@ -686,6 +681,7 @@ static PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, { guint warning_id = 0; PmLockNode *n; + GVariant *v = NULL; time_t now; n = (PmLockNode *) malloc(sizeof(PmLockNode)); @@ -694,14 +690,21 @@ static PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, return NULL; } - if (pid < INTERNAL_LOCK_BASE) - warning_id = g_timeout_add_seconds(display_conf.lightsensor_interval, - warning_cb[s_index], (void *)((intptr_t)pid)); + if (pid < INTERNAL_LOCK_BASE) { + v = g_variant_new("(ii)", s_index, pid); + if (v) { + warning_id = g_timeout_add_seconds(display_conf.lightsensor_interval, + pmlock_check, (void *)v); + } else { + _E("Failed to make GVariant."); + } + } time(&now); n->pid = pid; n->timeout_id = timeout_id; n->warning_id = warning_id; + n->warning_param = v; n->time = now; n->holdkey_block = holdkey_block; n->background = false; @@ -728,6 +731,10 @@ static int del_node(enum state_t s_index, PmLockNode *n) g_source_remove(n->warning_id); n->warning_id = 0; } + if (n->warning_param) { + g_variant_unref(n->warning_param); + n->warning_param = NULL; + } free(n); refresh_app_cond(); @@ -873,26 +880,54 @@ out: * or good process. so infinity or more then 1 min lock process, deviced * will be checked it to resoured. And then, it will be asked quit or maintain to user. */ -static void pmlock_check(void *data, char *st) +static gboolean pmlock_check(void *data) { const char *arr[2]; char chr_pid[PID_MAX]; + PmLockNode *node; + GVariant *v; + enum state_t state; pid_t pid; int ret; - if (!data || !st) - return; + if (!data) { + _E("Invalid parameter."); + return G_SOURCE_REMOVE; + } + + v = (GVariant*)data; + g_variant_get(v, "(ii)", &state, &pid); - if (!strncmp(st, "lcdoff", 4) && backlight_ops.get_lcd_power() == DPMS_ON) { + if (state == S_LCDOFF && backlight_ops.get_lcd_power() == DPMS_ON) { _D("Lcd state is PM_LCD_POWER_ON"); - return; + return G_SOURCE_CONTINUE; } - pid = (pid_t)((intptr_t)data); - snprintf(chr_pid, sizeof(chr_pid), "%d", pid); + /* Stop checking lock if process had been terminated */ + if (kill(pid, 0) == -1) { + node = find_node(state, pid); + del_node(state, node); + _I("Process %d not found. Stop checking lock.", pid); + return G_SOURCE_REMOVE; + } + snprintf(chr_pid, sizeof(chr_pid), "%d", pid); arr[0] = chr_pid; - arr[1] = st; + switch (state) { + case S_NORMAL: + arr[1] = "normal"; + break; + case S_LCDDIM: + arr[1] = "lcddim"; + break; + case S_LCDOFF: + arr[1] = "lcdoff"; + break; + default: + _E("Invalid state."); + g_variant_unref(v); + return G_SOURCE_REMOVE; + } ret = dbus_handle_method_async_with_reply(RESOURCED_BUS_NAME, RESOURCED_PATH_PROCESS, @@ -901,23 +936,7 @@ static void pmlock_check(void *data, char *st) "is", arr, pmlock_check_cb, -1, NULL); if (ret < 0) _E("Failed to call dbus method"); -} -static gboolean pmlock_normal_check(void *data) -{ - pmlock_check(data, "normal"); - return G_SOURCE_CONTINUE; -} - -static gboolean pmlock_dim_check(void *data) -{ - pmlock_check(data, "lcddim"); - return G_SOURCE_CONTINUE; -} - -static gboolean pmlock_off_check(void *data) -{ - pmlock_check(data, "lcdoff"); return G_SOURCE_CONTINUE; } diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 1e5998c..68cc5f8 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -134,9 +134,7 @@ static gboolean del_normal_cond(void *data); static gboolean del_dim_cond(void *data); static gboolean del_off_cond(void *data); -static gboolean pmlock_normal_check(void *data); -static gboolean pmlock_dim_check(void *data); -static gboolean pmlock_off_check(void *data); +static gboolean pmlock_check(void *data); static int default_proc_change_state(unsigned int cond, pid_t pid); static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state; @@ -162,10 +160,6 @@ static int trans_table[S_END][EVENT_END] = { { S_POWEROFF, S_POWEROFF }, /* S_POWEROFF */ }; -static GSourceFunc warning_cb[S_END] = { - NULL, pmlock_normal_check, pmlock_dim_check, pmlock_off_check, -}; - enum signal_type { SIGNAL_INVALID = 0, SIGNAL_PRE, @@ -252,6 +246,7 @@ typedef struct _pm_lock_node { pid_t pid; guint timeout_id; guint warning_id; + GVariant *warning_param; time_t time; bool holdkey_block; bool background; @@ -693,6 +688,7 @@ static PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, { guint warning_id = 0; PmLockNode *n; + GVariant *v = NULL; time_t now; n = (PmLockNode *) malloc(sizeof(PmLockNode)); @@ -701,14 +697,21 @@ static PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, return NULL; } - if (pid < INTERNAL_LOCK_BASE) - warning_id = g_timeout_add_seconds(display_conf.lightsensor_interval, - warning_cb[s_index], (void *)((intptr_t)pid)); + if (pid < INTERNAL_LOCK_BASE) { + v = g_variant_new("(ii)", s_index, pid); + if (v) { + warning_id = g_timeout_add_seconds(display_conf.lightsensor_interval, + pmlock_check, (void *)v); + } else { + _E("Failed to make GVariant."); + } + } time(&now); n->pid = pid; n->timeout_id = timeout_id; n->warning_id = warning_id; + n->warning_param = v; n->time = now; n->holdkey_block = holdkey_block; n->background = false; @@ -735,6 +738,10 @@ static int del_node(enum state_t s_index, PmLockNode *n) g_source_remove(n->warning_id); n->warning_id = 0; } + if (n->warning_param) { + g_variant_unref(n->warning_param); + n->warning_param = NULL; + } free(n); refresh_app_cond(); @@ -880,26 +887,54 @@ out: * or good process. so infinity or more then 1 min lock process, deviced * will be checked it to resoured. And then, it will be asked quit or maintain to user. */ -static void pmlock_check(void *data, char *st) +static gboolean pmlock_check(void *data) { const char *arr[2]; char chr_pid[PID_MAX]; + PmLockNode *node; + GVariant *v; + enum state_t state; pid_t pid; int ret; - if (!data || !st) - return; + if (!data) { + _E("Invalid parameter."); + return G_SOURCE_REMOVE; + } + + v = (GVariant*)data; + g_variant_get(v, "(ii)", &state, &pid); - if (!strncmp(st, "lcdoff", 4) && backlight_ops.get_lcd_power() == DPMS_ON) { + if (state == S_LCDOFF && backlight_ops.get_lcd_power() == DPMS_ON) { _D("Lcd state is PM_LCD_POWER_ON"); - return; + return G_SOURCE_CONTINUE; } - pid = (pid_t)((intptr_t)data); - snprintf(chr_pid, sizeof(chr_pid), "%d", pid); + /* Stop checking lock if process had been terminated */ + if (kill(pid, 0) == -1) { + node = find_node(state, pid); + del_node(state, node); + _I("Process %d not found. Stop checking lock.", pid); + return G_SOURCE_REMOVE; + } + snprintf(chr_pid, sizeof(chr_pid), "%d", pid); arr[0] = chr_pid; - arr[1] = st; + switch (state) { + case S_NORMAL: + arr[1] = "normal"; + break; + case S_LCDDIM: + arr[1] = "lcddim"; + break; + case S_LCDOFF: + arr[1] = "lcdoff"; + break; + default: + _E("Invalid state."); + g_variant_unref(v); + return G_SOURCE_REMOVE; + } ret = dbus_handle_method_async_with_reply(RESOURCED_BUS_NAME, RESOURCED_PATH_PROCESS, @@ -908,23 +943,7 @@ static void pmlock_check(void *data, char *st) "is", arr, pmlock_check_cb, -1, NULL); if (ret < 0) _E("Failed to call dbus method"); -} -static gboolean pmlock_normal_check(void *data) -{ - pmlock_check(data, "normal"); - return G_SOURCE_CONTINUE; -} - -static gboolean pmlock_dim_check(void *data) -{ - pmlock_check(data, "lcddim"); - return G_SOURCE_CONTINUE; -} - -static gboolean pmlock_off_check(void *data) -{ - pmlock_check(data, "lcdoff"); return G_SOURCE_CONTINUE; }