Add new functions for managing process group 01/264701/2
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 28 Sep 2021 10:00:10 +0000 (19:00 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 29 Sep 2021 04:12:36 +0000 (13:12 +0900)
To manage oom score of child processes of the application properly,
AMD and resourced must know the process ID. When the child process calls
the aul_proc_group_add() function, AMD sends the app group signal to
resourced to notify the process group information.
If the oom score of the main process is changed, the oom score of the
child process is also changed by resourced.

Adds:
 - aul_proc_group_add()
 - aul_proc_group_remove()

Change-Id: Ic02f958bf32110e794efbdacc64c6cf8e3d8cfe4
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
include/aul_cmd.h
include/aul_proc_group.h [new file with mode: 0644]
src/aul_cmd.c
src/aul_proc_group.cc [new file with mode: 0644]
tool/aul_test/aul_test.c

index f9bbadd..a654f43 100644 (file)
@@ -210,6 +210,8 @@ enum app_cmd {
        RPC_PORT_DESTROY = 166,
        RPC_PORT_EXIST = 167,
        APP_WINDOW_ATTACH_BELOW = 168,
+       PROC_GROUP_ADD = 169,
+       PROC_GROUP_REMOVE = 170,
 
        APP_CMD_MAX
 };
diff --git a/include/aul_proc_group.h b/include/aul_proc_group.h
new file mode 100644 (file)
index 0000000..8297831
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __AUL_PROC_GROUP_H__
+#define __AUL_RPOC_GROUP_H__
+
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <aul.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Adds the process to the process group.
+ * @remarks This function is only for App Framework internally.
+ * @remarks If the pid is not equal to the process ID of the caller,
+ *          the caller MUST have a permission that is signed by platform certificate.
+ *          If the caller doesn't have the permission, the function returns AUL_R_EILLACC.
+ * @since_tizen 6.5
+ * @param[in]   pid             The process ID
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #AUL_R_OK Successful
+ * @retval #AUL_R_EINVAL Invalid parameter
+ * @retval #AUL_R_ECOMM Communication error on send
+ * @retval #AUL_R_EILLACC Permission denied
+ */
+int aul_proc_group_add(pid_t pid);
+
+/**
+ * @brief Removes the process from the process group.
+ * @remarks This function is only for App Framework internally.
+ * @remarks If the pid is not equal to the process ID of the caller,
+ *          the caller MUST have a permission that is signed by platform certificate.
+ *          If the caller doesn't have the permission, the function returns AUL_R_EILLACC.
+ * @since_tizen 6.5
+ * @param[in]   pid             The process ID
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #AUL_R_OK Successful
+ * @retval #AUL_R_EINVAL Invalid parameter
+ * @retval #AUL_R_ECOMM Communication error on send
+ * @retval #AUL_R_EILLACC Permission denied
+ */
+int aul_proc_group_remove(pid_t pid);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUL_PROC_GROUP_H__ */
index 540881f..7ba85f0 100644 (file)
@@ -212,6 +212,8 @@ API const char *aul_cmd_convert_to_string(int cmd)
                "RPC_PORT_DESTROY",
                "RPC_PORT_EXIST",
                "APP_WINDOW_ATTACH_BELOW",
+               "PROC_GROUP_ADD",
+               "PROC_GROUP_REMOVE",
 
                "CUSTOM_COMMAND"
        };
diff --git a/src/aul_proc_group.cc b/src/aul_proc_group.cc
new file mode 100644 (file)
index 0000000..eddae48
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/aul_proc_group.h"
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "app_request.h"
+#include "aul_api.h"
+#include "aul_util.h"
+#include "include/aul_error.h"
+#include "include/aul_sock.h"
+
+using namespace aul;
+using namespace aul::internal;
+
+extern "C" API int aul_proc_group_add(pid_t pid) {
+  if (pid < 1) {
+    _E("Invalid parameter");
+    return AUL_R_EINVAL;
+  }
+
+  int ret = AppRequest(PROC_GROUP_ADD, getuid())
+      .SetPid(pid)
+      .SendSimply();
+  if (ret < 0) {
+    _E("Failed to send the request. error(%d)", ret);
+    return aul_error_convert(ret);
+  }
+
+  return AUL_R_OK;
+}
+
+extern "C" API int aul_proc_group_remove(pid_t pid) {
+  if (pid < 1) {
+    _E("Invalid parameter");
+    return AUL_R_EINVAL;
+  }
+
+  int ret = AppRequest(PROC_GROUP_REMOVE, getuid())
+      .SetPid(pid)
+      .SendSimply();
+  if (ret < 0) {
+    _E("Failed to send the request. error(%d)", ret);
+    return aul_error_convert(ret);
+  }
+
+  return AUL_R_OK;
+}
index 93d4a1c..942505f 100644 (file)
@@ -27,6 +27,7 @@
 #include "aul/api/aul_app_lifecycle.h"
 #include "aul_svc.h"
 #include "aul_proc.h"
+#include "aul_proc_group.h"
 #include "menu_db_util.h"
 
 #define MAX_LOCAL_BUFSZ 128
@@ -895,6 +896,26 @@ static int get_proc_extra_test(void)
        return ret;
 }
 
+static int add_proc_group_test(void)
+{
+       int ret;
+
+       printf("[aul_proc_group_add] %s\n", gargv[2]);
+       ret = aul_proc_group_add(atoi(gargv[2]));
+
+       return ret;
+}
+
+static int remove_proc_group_test(void)
+{
+       int ret;
+
+       printf("[aul_proc_group_remove] %s\n", gargv[2]);
+       ret = aul_proc_group_remove(atoi(gargv[2]));
+
+       return ret;
+}
+
 static int test_regex()
 {
        char *token;
@@ -1049,6 +1070,10 @@ static test_func_t test_func[] = {
                "[usage] get_proc_name <pid>"},
        {"get_proc_extra", get_proc_extra_test, "aul_proc_get_extra",
                "[usage] get_proc_extra <pid>"},
+       {"add_proc_group", add_proc_group_test, "aul_proc_group_add",
+               "[usage] add_proc_group <pid>"},
+       {"remove_proc_group", remove_proc_group_test, "aul_proc_group_remove",
+               "[usage] remove_proc_group <pid>"},
 };
 
 int callfunc(char *testname)