resource: process-group: Add PROCESS_GROUP_ATTR_COMM_LIST attribute 14/272914/3
authorDongwoo Lee <dwoo08.lee@samsung.com>
Wed, 23 Mar 2022 10:34:03 +0000 (19:34 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Mon, 28 Mar 2022 09:36:07 +0000 (18:36 +0900)
Change-Id: I977281252290f1d92d028db3a38390f5feac0848
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
lib/tmonitor/tmonitor.h
src/resource/resource-process-group.c

index 4992e11..f299485 100644 (file)
@@ -126,6 +126,7 @@ extern "C" {
 
 /* Process List Resource */
 #define PROCESS_GROUP_ATTR_PID_LIST            BIT(0)  /* DATA_TYPE_ARRAY(INT) */
+#define PROCESS_GROUP_ATTR_COMM_LIST           BIT(1)  /* DATA_TYPE_ARRAY(STRING) */
 
 #define PROCESS_GROUP_CTRL_ROOT_PID            BIT(0)
 
index 9934442..90dec08 100644 (file)
@@ -77,6 +77,54 @@ static int process_group_get_pid_list(const struct resource *res,
        return 0;
 }
 
+static int process_group_get_comm_list(const struct resource *res,
+                               const struct resource_attribute *attr,
+                               void *data)
+{
+       struct process_group_context *ctx;
+       struct array_value *list = data;
+       struct process_info *pi;
+       char **data_array;
+       int i;
+
+       if (!res || !res->priv || !attr || !data)
+               return -EINVAL;
+
+       ctx = res->priv;
+
+       if (!ctx->pi_list)
+               return -EINVAL;
+
+       if (list->data) {
+               data_array = list->data;
+               for (i = 0; data_array[i] != NULL; i++)
+                       free(data_array[i]);
+               free(data_array);
+       }
+
+       /* last item will be null for boundary check */
+       data_array = list->data = calloc(ctx->pi_list->len + 1, sizeof(char *));
+       if (!data_array)
+               return -ENOMEM;
+
+       list->type = DATA_TYPE_STRING;
+       list->length = ctx->pi_list->len;
+
+       for (i = 0; i < list->length; i++) {
+               pi = g_ptr_array_index(ctx->pi_list, i);
+               data_array[i] = strdup(pi->comm);
+               if (!data_array[i]) {
+                       while (i > 0)
+                               free(data_array[--i]);
+                       free(data_array);
+                       list->data = NULL;
+                       return -ENOMEM;
+               }
+       }
+
+       return 0;
+}
+
 static const struct resource_attribute process_group_attrs[] = {
        {
                .name   = "PROCESS_GROUP_ATTR_PID_LIST",
@@ -87,6 +135,15 @@ static const struct resource_attribute process_group_attrs[] = {
                        .is_supported = resource_attr_supported_always,
                },
        },
+       {
+               .name   = "PROCESS_GROUP_ATTR_COMM_LIST",
+               .id     = PROCESS_GROUP_ATTR_COMM_LIST,
+               .type   = DATA_TYPE_ARRAY,
+               .ops    = {
+                       .get = process_group_get_comm_list,
+                       .is_supported = resource_attr_supported_always,
+               },
+       },
 };
 
 static int process_group_setup_root_pid(const struct resource *res,