Modify error handling logic 48/145948/1 accepted/tizen/unified/20170905.184607 submit/tizen/20170905.050440
authorYunmi Ha <yunmi.ha@samsung.com>
Thu, 24 Aug 2017 08:09:34 +0000 (17:09 +0900)
committerYunmi Ha <yunmi.ha@samsung.com>
Thu, 24 Aug 2017 08:28:21 +0000 (17:28 +0900)
1. Fix timer handle leak

2. If session error is occured during termination,
skip the logic related session object.

Change-Id: If2462e9d923e087648009608d91b5aa57819b4a0
Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
src/daemon/tlm-dbus-observer.c
src/daemon/tlm-main.c [changed mode: 0755->0644]
src/daemon/tlm-manager.c [changed mode: 0755->0644]
src/daemon/tlm-seat.c [changed mode: 0755->0644]
src/daemon/tlm-seat.h
src/daemon/tlm-session-remote.c [changed mode: 0755->0644]

index e1c0c40..4e9da0b 100644 (file)
@@ -508,7 +508,7 @@ _process_request (
                 dbus_req->password, dbus_req->environment);
         break;
     case TLM_DBUS_REQUEST_TYPE_LOGOUT_USER:
-        ret = tlm_seat_terminate_session (seat);
+        ret = tlm_seat_terminate_session (seat, FALSE);
         break;
     case TLM_DBUS_REQUEST_TYPE_SWITCH_USER:
         // Refuse request if the request's username is same to
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
index 72e7bed..f9200dd
@@ -826,7 +826,7 @@ tlm_manager_stop (TlmManager *manager)
                                   "session-terminated",
                                   G_CALLBACK (_session_terminated_cb),
                                   manager);
-        if (!tlm_seat_terminate_session ((TlmSeat *) value)) {
+        if (!tlm_seat_terminate_session ((TlmSeat *) value, TRUE)) {
             g_hash_table_remove (manager->priv->seats, key);
             g_hash_table_iter_init (&iter, manager->priv->seats);
         } else {
old mode 100755 (executable)
new mode 100644 (file)
index 8268df5..64ec5f6
@@ -82,6 +82,7 @@ struct _TlmSeatPrivate
     TlmDbusObserver *dbus_observer; /* dbus server accessed only by user who has
     active session */
     TlmDbusObserver *prev_dbus_observer;
+    gboolean manager_stop;
 };
 
 typedef struct _DelayClosure
@@ -203,9 +204,10 @@ _handle_error (
     DBG ("Error : %d:%s", error->code, error->message);
     g_signal_emit (self, signals[SIG_SESSION_ERROR],  0, error->code);
 
-    if (error->code == TLM_ERROR_PAM_AUTH_FAILURE ||
+    if ((error->code == TLM_ERROR_PAM_AUTH_FAILURE ||
         error->code == TLM_ERROR_SESSION_CREATION_FAILURE ||
-        error->code == TLM_ERROR_SESSION_TERMINATION_FAILURE) {
+        error->code == TLM_ERROR_SESSION_TERMINATION_FAILURE)
+        && (!(self->priv->manager_stop))) {
         DBG ("Destroy the session in case of creation/termination failure");
         _close_active_session (self);
         g_clear_object (&self->priv->dbus_observer);
@@ -446,6 +448,7 @@ tlm_seat_init (TlmSeat *seat)
     priv->id = priv->path = priv->default_user = NULL;
     priv->dbus_observer = priv->prev_dbus_observer = NULL;
     priv->default_active = FALSE;
+    priv->manager_stop = FALSE;
     seat->priv = priv;
 }
 
@@ -502,7 +505,7 @@ tlm_seat_switch_user (TlmSeat *seat,
     priv->next_password = g_strdup (password);
     priv->next_environment = g_hash_table_ref (environment);
 
-    return tlm_seat_terminate_session (seat);
+    return tlm_seat_terminate_session (seat, FALSE);
 }
 
 static gchar *
@@ -737,7 +740,7 @@ tlm_seat_create_session (TlmSeat *seat,
 }
 
 gboolean
-tlm_seat_terminate_session (TlmSeat *seat)
+tlm_seat_terminate_session (TlmSeat *seat, gboolean stop)
 {
     g_return_val_if_fail (seat && TLM_IS_SEAT(seat), FALSE);
     g_return_val_if_fail (seat->priv, FALSE);
@@ -750,6 +753,9 @@ tlm_seat_terminate_session (TlmSeat *seat)
                 seat->priv->default_user);
     }
 
+    if (!(seat->priv->manager_stop))
+        seat->priv->manager_stop = stop;
+
     if (!seat->priv->session ||
         !tlm_session_remote_terminate (seat->priv->session)) {
         WARN ("No active session to terminate");
index 36ff036..0a57f86 100644 (file)
@@ -89,7 +89,7 @@ tlm_seat_create_session (TlmSeat *seat,
                          GHashTable *environment);
 
 gboolean
-tlm_seat_terminate_session (TlmSeat *seat);
+tlm_seat_terminate_session (TlmSeat *seat, gboolean stop);
 
 G_END_DECLS
 
old mode 100755 (executable)
new mode 100644 (file)
index 328cfc6..7a28ff0
@@ -562,16 +562,20 @@ tlm_session_remote_terminate (
     }
 
     DBG ("Terminate child session process");
-    if (kill (priv->cpid, SIGHUP) < 0)
-    {
-        gchar strerr_buf[MAX_STRERROR_LEN] = {0,};
-        WARN ("kill(%u, SIGHUP): %s", priv->cpid, strerror_r(errno, strerr_buf, MAX_STRERROR_LEN));
-    }
-    priv->last_sig = SIGHUP;
-    priv->timer_id = g_timeout_add_seconds (
-            tlm_config_get_uint (priv->config, TLM_CONFIG_GENERAL,
-                    TLM_CONFIG_GENERAL_TERMINATE_TIMEOUT, 3),
-            _terminate_timeout, self);
+    if (!(priv->timer_id)) {
+        if (kill (priv->cpid, SIGHUP) < 0)
+        {
+            gchar strerr_buf[MAX_STRERROR_LEN] = {0,};
+            WARN ("kill(%u, SIGHUP): %s", priv->cpid, strerror_r(errno, strerr_buf, MAX_STRERROR_LEN));
+        }
+        priv->last_sig = SIGHUP;
+        priv->timer_id = g_timeout_add_seconds (
+                tlm_config_get_uint (priv->config, TLM_CONFIG_GENERAL,
+                        TLM_CONFIG_GENERAL_TERMINATE_TIMEOUT, 3),
+                _terminate_timeout, self);
+    } else
+        WARN ("child session process is already terminating. timer_id=%d", priv->timer_id);
+
     return TRUE;
 }