From: Your Name <[email protected]> This patch adds permission change function int cg_chmod_recursive(struct cgroup *cgroup, mode_t dir_mode, int dirm_change, mode_t file_mode, int filem_change);
It changes the directory and files permissions to values. If dirm_change is nonzero, then directory permissions will be set to the second parameter dir_mode. If filem_change is nonzero, then directory permissions will be set to the second parameter file_mode. Signed-off-by: Ivana Hutarova Varekova<[email protected]> --- include/libcgroup/groups.h | 11 +++++++ src/api.c | 70 ++++++++++++++++++++++++++++++++++++++++++++ src/libcgroup.map | 1 + 3 files changed, 82 insertions(+), 0 deletions(-) diff --git a/include/libcgroup/groups.h b/include/libcgroup/groups.h index d212ec0..5bfa485 100644 --- a/include/libcgroup/groups.h +++ b/include/libcgroup/groups.h @@ -519,6 +519,17 @@ char *cgroup_get_value_name(struct cgroup_controller *controller, int index); int cgroup_get_procs(char *name, char *controller, pid_t **pids, int *size); /** + * Change permission of files and directories of given group group + * @param cgroup The cgroup which permissions should be changed + * @param dir_mode The permission mode of group directory + * @param dirm_change Denotes whether the directory change should be done + * @param file_mode The permission mode of group files + * @param filem_change Denotes whether the directory change should be done + */ +int cg_chmod_recursive(struct cgroup *cgroup, mode_t dir_mode, + int dirm_change, mode_t file_mode, int filem_change); + +/** * @} * @} */ diff --git a/src/api.c b/src/api.c index 6e79db0..4ccab74 100644 --- a/src/api.c +++ b/src/api.c @@ -171,6 +171,76 @@ static int cg_chown_recursive(char **path, uid_t owner, gid_t group) return ret; } +int cg_chmod_file(FTS *fts, FTSENT *ent, mode_t dir_mode, + int dirm_change, mode_t file_mode, int filem_change) +{ + int ret = 0; + const char *filename = fts->fts_path; + cgroup_dbg("chmod: seeing file %s\n", filename); + switch (ent->fts_info) { + case FTS_ERR: + errno = ent->fts_errno; + break; + case FTS_D: + case FTS_DC: + case FTS_DNR: + case FTS_DP: + if (dirm_change) + ret = chmod(filename, dir_mode); + break; + case FTS_F: + case FTS_NSOK: + case FTS_NS: + case FTS_DEFAULT: + if (filem_change) + ret = chmod(filename, file_mode); + break; + } + return ret; +} + + +/* + * TODO: Need to decide a better place to put this function. + */ +int cg_chmod_recursive(struct cgroup *cgroup, mode_t dir_mode, + int dirm_change, mode_t file_mode, int filem_change) +{ + int ret = 0; + FTS *fts; + char *fts_path[2]; + char *path = NULL; + + cgroup_dbg("chmod: path is %s\n", *path); + fts_path[0] = (char *)malloc(FILENAME_MAX); + if (!fts_path[0]) { + last_errno = errno; + return ECGOTHER; + } + fts_path[1] = NULL; + path = fts_path[0]; + + if (!cg_build_path(cgroup->name, path, + cgroup->controller[0]->name)) + return -1; + + fts = fts_open(fts_path, FTS_PHYSICAL | FTS_NOCHDIR | + FTS_NOSTAT, NULL); + while (1) { + FTSENT *ent; + ent = fts_read(fts); + if (!ent) { + cgroup_dbg("fts_read failed\n"); + break; + } + ret = cg_chmod_file(fts, ent, dir_mode, dirm_change, + file_mode, filem_change); + } + fts_close(fts); + return ret; +} + + static char *cgroup_basename(const char *path) { char *base; diff --git a/src/libcgroup.map b/src/libcgroup.map index 60970ca..2a3439f 100644 --- a/src/libcgroup.map +++ b/src/libcgroup.map @@ -94,4 +94,5 @@ CGROUP_0.37 { cgroup_read_value_begin; cgroup_read_value_next; cgroup_read_value_end; + cg_chmod_recursive; } CGROUP_0.36; ------------------------------------------------------------------------------ Nokia and AT&T present the 2010 Calling All Innovators-North America contest Create new apps & games for the Nokia N8 for consumers in U.S. and Canada $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store http://p.sf.net/sfu/nokia-dev2dev _______________________________________________ Libcg-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/libcg-devel
