*/
int cgroup_walk_tree_set_flags(void **handle, int flags);
+/**
+ * Read the value of the given variable for the specified
+ * controller and control group.
+ * The value is read up to newline character or at most max-1 characters,
+ * whichever comes first (i.e. similar to fgets()).
+ * @param controller Name of the controller for which stats are requested.
+ * @param path Path to control group, relative to hierarchy root.
+ * @param name is variable name.
+ * @param handle Handle to be used during iteration.
+ * @param buffer Buffer to read the value into.
+ * The buffer is always zero-terminated.
+ * @param max Maximal lenght of the buffer
+ * @return #ECGEOF when the stats file is empty.
+ */
+
+int cgroup_read_value_begin(const char *controller, const char *path,
+ char *name, void **handle, char *buffer, int max);
+
+/**
+ * Read the next string from the given variable handle
+ * which is generated by cgroup_read_stats_begin() function.
+ * the value is read up to newline character or at most max-1 characters,
+ * whichever comes first (i.e. similar to fgets()) per
+ * cgroup_read_stats_next() call
+ * @param handle Handle to be used during iteration.
+ * @param data returned the string.
+ * @param buffer Buffer to read the value into.
+ * The buffer is always zero-terminated.
+ * @param max Maximal lenght of the buffer
+ * @return #ECGEOF when the iterator finishes getting the list of stats.
+ */
+int cgroup_read_value_next(void **handle, char *buffer, int max);
+
+/**
+ * Release the iterator.
+ */
+int cgroup_read_value_end(void **handle);
+
/**
* @}
*
return ret;
}
+
+int cgroup_read_value_end(void **handle)
+{
+ FILE *fp;
+
+ if (!cgroup_initialized)
+ return ECGROUPNOTINITIALIZED;
+
+ if (!handle)
+ return ECGINVAL;
+
+ fp = (FILE *)*handle;
+ fclose(fp);
+
+ return 0;
+}
+
+int cgroup_read_value_next(void **handle, char *buffer, int max)
+{
+ int ret = 0;
+ char *ret_c;
+ FILE *fp;
+
+ if (!cgroup_initialized)
+ return ECGROUPNOTINITIALIZED;
+
+ if (!buffer || !handle)
+ return ECGINVAL;
+
+ fp = (FILE *)*handle;
+ ret_c = fgets(buffer, max, fp);
+ if (ret_c == NULL)
+ ret = ECGEOF;
+
+ return ret;
+}
+
+int cgroup_read_value_begin(const char *controller, const char *path,
+ char *name, void **handle, char *buffer, int max)
+{
+ int ret = 0;
+ char *ret_c = NULL;
+ char stat_file[FILENAME_MAX];
+ char stat_path[FILENAME_MAX];
+ FILE *fp;
+
+ if (!cgroup_initialized)
+ return ECGROUPNOTINITIALIZED;
+
+ if (!buffer || !handle)
+ return ECGINVAL;
+
+ if (!cg_build_path(path, stat_path, controller))
+ return ECGOTHER;
+
+ snprintf(stat_file, sizeof(stat_file), "%s/%s", stat_path,
+ name);
+ fp = fopen(stat_file, "re");
+ if (!fp) {
+ cgroup_dbg("fopen failed\n");
+ last_errno = errno;
+ *handle = NULL;
+ return ECGOTHER;
+ }
+
+ ret_c = fgets(buffer, max, fp);
+ if (ret_c == NULL)
+ ret = ECGEOF;
+
+ *handle = fp;
+ return 0;
+}
+
+
+
int cgroup_read_stats_end(void **handle)
{
FILE *fp;