Bring back some "unused" functions for module use 51/217351/2
authorMichal Bloch <m.bloch@partner.samsung.com>
Fri, 8 Nov 2019 13:11:14 +0000 (14:11 +0100)
committerMichal Bloch <m.bloch@partner.samsung.com>
Tue, 12 Nov 2019 11:53:18 +0000 (12:53 +0100)
These are used in freezer.

This partially reverts ced08db5bb62fd4ba35f0fbc38799097d2da3240.

Change-Id: I2ca2b63c51f2aae6ed576a9a01d9630ef429b1de
Signed-off-by: Michal Bloch <m.bloch@partner.samsung.com>
src/common/cgroup.c
src/common/cgroup.h
src/common/config-parser.c
src/common/config-parser.h

index e2d85d3..2ea45a3 100644 (file)
@@ -84,6 +84,14 @@ resourced_ret_c cgroup_write_pid_fullpath(const char *cgroup_full_path,
        return RESOURCED_ERROR_NONE;
 }
 
+resourced_ret_c cgroup_write_pid(const char *cgroup_subsystem,
+       const char *cgroup_name, const int pid)
+{
+       char buf[MAX_PATH_LENGTH];
+       snprintf(buf, sizeof(buf), "%s/%s", cgroup_subsystem, cgroup_name);
+       return cgroup_write_pid_fullpath(buf, pid);
+}
+
 int cgroup_write_node_uint32(const char *cgroup_name,
                const char *file_name, uint32_t value)
 {
index ca50f2e..873740a 100644 (file)
@@ -111,6 +111,9 @@ int cgroup_mount_subsystem(char* source, char* mount_point, char* opts);
 resourced_ret_c cgroup_write_pid_fullpath(const char *cgroup_full_path,
        const int pid);
 
+resourced_ret_c cgroup_write_pid(const char *cgroup_subsystem,
+       const char *cgroup_name, const int pid);
+
 /**
  * @desc this function sets release agent path into cgroup subsystem
  * and enables this mechanism
index 6c9306d..0e4e8fa 100644 (file)
@@ -318,6 +318,46 @@ finish:
        return r;
 }
 
+int config_parse_dir(const char *dir, ConfigParseFunc fp, void *data)
+{
+       _cleanup_closedir_ DIR *d = NULL;
+       struct dirent *de;
+
+       d = opendir(dir);
+       if (!d) {
+               _E("Failed to open dir: %s", dir);
+               return errno;
+       }
+
+       for (errno = 0, de = readdir(d);; errno = 0, de = readdir(d)) {
+               if (!de) {
+                       if (errno > 0)
+                               return -errno;
+                       break;
+               } else if (streq(de->d_name, ".") || streq(de->d_name, "..")) {
+                       continue;
+               }
+
+               _cleanup_free_ char *path = NULL;
+               int r;
+
+               if (de->d_type != DT_REG)
+                       continue;
+
+               r = asprintf(&path, "%s/%s", dir, de->d_name);
+               if (r < 0)
+                       return -ENOMEM;
+
+               r = fp(path, data);
+               /* Do not just break loop until parse all file of
+                * dir. Just only put log */
+               if (r < 0)
+                       _D("Failed to parse config: %s", de->d_name);
+       }
+
+       return 0;
+}
+
 int config_parse_bool(const char *filename,
                      unsigned line,
                      const char *section,
@@ -368,6 +408,7 @@ int config_parse_bool(const char *filename,
 
 DEFINE_PARSER(int, int, atoi)
 DEFINE_PARSER(float, float, atof)
+DEFINE_PARSER(long, long, atol)
 
 int config_parse_string(const char *filename,
                        unsigned line,
@@ -424,3 +465,38 @@ int config_parse_bytes(const char *filename,
 
        return 0;
 }
+
+int config_parse_strv(const char *filename,
+                     unsigned line,
+                     const char *section,
+                     const char *lvalue,
+                     int ltype,
+                     const char *rvalue,
+                     void *data)
+{
+       char ***strv = data;
+       char **o = NULL, **v = NULL, **vv = NULL;
+       int r;
+
+       assert(filename);
+       assert(lvalue);
+       assert(rvalue);
+       assert(data);
+
+       if (is_empty(rvalue))
+               return 0;
+
+       r = str_to_strv(rvalue, &v, WHITESPACE);
+       if (r < 0)
+               return r;
+
+       o = *strv;
+
+       r = strv_attach(o, v, &vv, true);
+       if (r < 0)
+               return r;
+
+       *strv = vv;
+
+       return 0;
+}
index 9c5548c..e425c5a 100644 (file)
@@ -70,10 +70,13 @@ typedef struct ConfigTableItem {
 } ConfigTableItem;
 
 int config_parse_new(const char *filename, void *table);
+int config_parse_dir(const char *dir, ConfigParseFunc fp, void *data);
 
 int config_parse_bool(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data);
 int config_parse_int(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data);
 int config_parse_string(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data);
 int config_parse_bytes(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data);
 int config_parse_float(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data);
+int config_parse_long(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data);
+int config_parse_strv(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data);
 #endif