[e_info] add the "-pid" and the "-all" suboptions for the kill
authorKonstantin Drabeniuk <k.drabeniuk@samsung.com>
Thu, 27 Apr 2017 11:09:18 +0000 (14:09 +0300)
committerSooChan Lim <sc1.lim@samsung.com>
Thu, 25 May 2017 23:24:58 +0000 (08:24 +0900)
Change-Id: I304592eb6c1daf33e9203be1a15092d94b6f8006
Signed-off-by: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
src/bin/e_info_client.c
src/bin/e_info_server.c

index 2786c95e9d49b0f72cae3c03759ba2f07ffb7e1b..2f4112b82f69046f0c6fd76708af19dffe85764d 100644 (file)
@@ -2630,11 +2630,19 @@ arg_err:
 
 #define KILL_USAGE \
   "[COMMAND] [ARG]...\n" \
-  "\t-id                  : the identifier for the resource whose creator is to be killed. (Usage: enlightenment_info -kill -id [id])\n" \
-  "\t-name                : the name for the resource whose creator is to be killed. (Usage: enlightenment_info -kill -name [name])\n" \
-  "\t-pid(no implement)   : the pid for the resource whose creator is to be killed. (Usage: enlightenment_info -kill -pid [pid])\n" \
-  "\t-all(no implement)   : kill all clients with top level windows\n" \
+  "\t-id    : the identifier for the resource whose creator is to be killed.\n" \
+  "\t-name  : the name for the resource whose creator is to be killed.\n" \
+  "\t-pid   : the pid for the resource whose creator is to be killed.\n" \
+  "\t-all   : kill all clients with top level windows\n" \
   "\t-help\n" \
+  "Example:\n" \
+  "\tenlightenment_info -kill\n" \
+  "\tenlightenment_info -kill [win_id]\n" \
+  "\tenlightenment_info -kill -id [win_id]\n" \
+  "\tenlightenment_info -kill -name [win_name]\n" \
+  "\tenlightenment_info -kill -pid [pid]\n" \
+  "\tenlightenment_info -kill -all\n" \
+  "\tenlightenment_info -kill -help\n" \
 
 static void
 _e_info_client_proc_screen_rotation(int argc, char **argv)
@@ -2691,6 +2699,8 @@ _e_info_client_proc_kill_client(int argc, char **argv)
 {
    const static int KILL_ID_MODE = 1;
    const static int KILL_NAME_MODE = 2;
+   const static int KILL_PID_MODE = 3;
+   const static int KILL_ALL_MODE = 4;
    Eina_Bool res;
    uint64_t uint64_value;
    const char *str_value = "";
@@ -2706,6 +2716,23 @@ _e_info_client_proc_kill_client(int argc, char **argv)
              return;
           }
      }
+   else if (argc == 3)
+     {
+        if (eina_streq(argv[2], "-all"))
+          mode = KILL_ALL_MODE;
+        else if (eina_streq(argv[2], "-help"))
+          goto usage;
+        else
+          {
+             mode = KILL_ID_MODE;
+             if (strlen(argv[2]) >= 2 && argv[2][0] == '0' && argv[2][1] == 'x')
+               res = _util_string_to_ulong(argv[2], (unsigned long *)&uint64_value, 16);
+             else
+               res = _util_string_to_ulong(argv[2], (unsigned long *)&uint64_value, 10);
+
+             EINA_SAFETY_ON_FALSE_GOTO(res, usage);
+          }
+     }
    else if (argc == 4)
      {
         if (eina_streq(argv[2], "-id"))
@@ -2716,18 +2743,28 @@ _e_info_client_proc_kill_client(int argc, char **argv)
              else
                res = _util_string_to_ulong(argv[3], (unsigned long *)&uint64_value, 10);
 
-             EINA_SAFETY_ON_FALSE_RETURN(res);
+             EINA_SAFETY_ON_FALSE_GOTO(res, usage);
           }
         else if (eina_streq(argv[2], "-name"))
           {
              mode = KILL_NAME_MODE;
              str_value = argv[3];
           }
+        else if (eina_streq(argv[2], "-pid"))
+          {
+             mode = KILL_PID_MODE;
+             if (strlen(argv[3]) >= 2 && argv[3][0] == '0' && argv[3][1] == 'x')
+               res = _util_string_to_ulong(argv[3], (unsigned long *)&uint64_value, 16);
+             else
+               res = _util_string_to_ulong(argv[3], (unsigned long *)&uint64_value, 10);
+
+             EINA_SAFETY_ON_FALSE_GOTO(res, usage);
+          }
         else
-          goto arg_err;
+          goto usage;
      }
    else
-     goto arg_err;
+     goto usage;
 
    res = _e_info_client_eldbus_message_with_args("kill_client",
                                                  _e_info_client_cb_kill_client,
@@ -2736,7 +2773,7 @@ _e_info_client_proc_kill_client(int argc, char **argv)
    EINA_SAFETY_ON_FALSE_RETURN(res);
 
    return;
-arg_err:
+usage:
    printf("Usage: enlightenment_info %s", KILL_USAGE);
 }
 
index 7f1ae4ff32c790c8a649fe2124dddaf03f213f0d..486e900e854011eadf5a4332f6b3d7345938a938 100755 (executable)
@@ -3070,8 +3070,13 @@ _e_info_server_ec_find_by_win(Ecore_Window win)
    return NULL;
 }
 
+const static int KILL_ID_MODE = 1;
+const static int KILL_NAME_MODE = 2;
+const static int KILL_PID_MODE = 3;
+const static int KILL_ALL_MODE = 4;
+
 static int
-_e_info_server_ec_kill_by_name(const char *name, Eldbus_Message_Iter *array_of_string)
+_e_info_server_ec_kill(uint32_t mode, void *value, Eldbus_Message_Iter *array_of_string)
 {
    E_Client *ec;
    Evas_Object *o;
@@ -3088,17 +3093,37 @@ _e_info_server_ec_kill_by_name(const char *name, Eldbus_Message_Iter *array_of_s
 
         ec_name = e_client_util_name_get(ec) ?: "NO NAME";
 
-        find = strstr(ec_name, name);
+        if (mode == KILL_NAME_MODE)
+          {
+             find = strstr(ec_name, (const char *)value);
 
-        if (find)
+             if (!find)
+               continue;
+          }
+        else if (mode == KILL_PID_MODE)
           {
-             count++;
-             e_client_act_kill_begin(ec);
-             snprintf(result, sizeof(result),
-                       "[Server] killing creator(%s) of resource 0x%lx",
-                       ec_name, (unsigned long)e_client_util_win_get(ec));
-             eldbus_message_iter_arguments_append(array_of_string, VALUE_TYPE_REPLY_KILL, result);
+             pid_t pid = -1;
+             pid = ec->netwm.pid;
+             if (pid <= 0)
+               {
+                  if (ec->comp_data)
+                    {
+                       E_Comp_Wl_Client_Data *cdata = (E_Comp_Wl_Client_Data*)ec->comp_data;
+                       if (cdata->surface)
+                       wl_client_get_credentials(wl_resource_get_client(cdata->surface), &pid, NULL, NULL);
+                    }
+               }
+             if (pid != *(pid_t *)value)
+               continue;
           }
+
+        count++;
+        e_client_act_kill_begin(ec);
+
+        snprintf(result, sizeof(result),
+                 "[Server] killing creator(%s) of resource 0x%lx",
+                 ec_name, (unsigned long)e_client_util_win_get(ec));
+        eldbus_message_iter_arguments_append(array_of_string, VALUE_TYPE_REPLY_KILL, result);
      }
 
    return count;
@@ -3107,8 +3132,6 @@ _e_info_server_ec_kill_by_name(const char *name, Eldbus_Message_Iter *array_of_s
 static Eldbus_Message *
 _e_info_server_cb_kill_client(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
 {
-   const static int KILL_ID_MODE = 1;
-   const static int KILL_NAME_MODE = 2;
    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
    Eldbus_Message_Iter *iter = eldbus_message_iter_get(reply);
    Eina_Bool res;
@@ -3149,16 +3172,19 @@ _e_info_server_cb_kill_client(const Eldbus_Service_Interface *iface EINA_UNUSED,
                 "[Server] killing creator(%s) of resource 0x%lx",
                 e_client_util_name_get(ec) ?: "NO NAME", (unsigned long)win);
      }
-   else if (mode == KILL_NAME_MODE)
+   else if (mode >= KILL_NAME_MODE && mode <= KILL_ALL_MODE)
      {
-        count = _e_info_server_ec_kill_by_name(str_value, array_of_string);
+        if (mode == KILL_NAME_MODE)
+          count = _e_info_server_ec_kill(mode, (void *)str_value, array_of_string);
+        else
+          count = _e_info_server_ec_kill(mode, (void *)&uint64_value, array_of_string);
+
         snprintf(result, sizeof(result),
-                  "\n[Server] killed %d client(s)", count);
+                 "\n[Server] killed %d client(s)", count);
      }
    else
      {
-        snprintf(result, sizeof(result),
-                 "[Server] Error: wrong mode.");
+        snprintf(result, sizeof(result), "[Server] Error: wrong mode.");
      }
 
 finish: