cgcreate \- create new cgroup(s)
.SH SYNOPSIS
-\fBcgcreate\fR [\fB-h\fR] [\fB-t\fR <\fItuid>:<tgid\fR>]
-[\fB-a\fR <\fIagid>:<auid\fR>] \fB-g\fR <\fIcontrollers>:<path\fR> [-g ...]
+\fBcgcreate\fR [\fB-h\fR] [\fB-s\fR] [\fB-t\fR <\fItuid>:<tgid\fR>]
+[\fB-a\fR <\fIagid>:<auid\fR>] [\fB-f\fR mode] [\fB-d\fR mode]
+\fB-g\fR <\fIcontrollers>:<path\fR> [-g ...]
.SH DESCRIPTION
The command creates new cgroup(s) defined by option
\fB-g\fR.
+
+
.TP
.B -t <tuid>:<tgid>
defines the name of the user and the group, which owns tasks
allowed to set subsystem parameters and create subgroups.
The default value is the same as has the parent cgroup.
+.TP
+.B -d, --dperm mode
+sets the permission mode of control groups directory.
+The mode have to be set using octal numbers e.g.
+\fB-d 775\fR.
+
+.TP
+.B -f, --fperm mode
+sets the permission mode of control groups files.
+The mode have to be set using octal numbers e.g.
+\fB-f 775\fR.
+
.TP
.B -g <controllers>:<path>
defines control groups which will be added.
#include <getopt.h>
#include "tools-common.h"
+
/*
* Display the usage
*/
" try %s -h' for more information.\n",
program_name);
} else {
- fprintf(stdout, "Usage: %s [-h] [-t <tuid>:<tgid>] "\
- "[-a <agid>:<auid>] -g <controllers>:<path> [-g ...]\n",
+ fprintf(stdout, "Usage: %s [-h] [-f mode] [-d mode] "\
+ "[-t <tuid>:<tgid>] [-a <agid>:<auid>] "\
+ "-g <controllers>:<path> [-g ...]\n",
program_name);
fprintf(stdout, " -t <tuid>:<tgid> Set "\
"the task permission\n");
"group which should be added\n");
fprintf(stdout, " -h,--help Display "\
"this help\n");
+ fprintf(stdout, " -f, --fperm mode Group "\
+ "file permissions\n");
+ fprintf(stdout, " -d, --dperm mode Group "\
+ "direrory permissions\n");
}
}
+/* allowed mode strings are octal version: "755" */
+
+int parse_mode(char *string, mode_t *pmode, const char *program_name)
+{
+ mode_t mode = 0;
+ int pos = 0; /* position of the number iin string */
+ int i;
+ int j = 64;
+
+ while (pos < 3) {
+ if ('0' <= string[pos] && string[pos] < '8') {
+ i = (int)string[pos] - (int)'0';
+ /* parse the permission triple*/
+ mode = mode + i*j;
+ j = j / 8;
+ } else {
+ fprintf(stdout, "%s wrong mode format %s",
+ program_name, string);
+ return -1;
+ }
+ pos++;
+ }
+
+ /* the string have contains three characters */
+ if (string[pos] != '\0') {
+ fprintf(stdout, "%s wrong mode format %s",
+ program_name, string);
+ return -1;
+ }
+ *pmode = mode;
+ return 0;
+}
int main(int argc, char *argv[])
{
{"task", required_argument, NULL, 't'},
{"admin", required_argument, NULL, 'a'},
{"", required_argument, NULL, 'g'},
+ {"dperm", required_argument, NULL, 'd'},
+ {"fperm", required_argument, NULL, 'f' },
{0, 0, 0, 0},
};
/* approximation of max. numbers of groups that will be created */
int capacity = argc;
+ /* permission variables */
+ mode_t dir_mode = 0;
+ mode_t file_mode = 0;
+ int dirm_change = 0;
+ int filem_change = 0;
+
/* no parametr on input */
if (argc < 2) {
usage(1, argv[0]);
}
/* parse arguments */
- while ((c = getopt_long(argc, argv, "a:t:g:h", long_opts, NULL)) > 0) {
+ while ((c = getopt_long(argc, argv, "a:t:g:hd:f:", long_opts, NULL))
+ > 0) {
switch (c) {
case 'h':
usage(0, argv[0]);
return -1;
}
break;
+ case 'd':
+ dirm_change = 1;
+ ret = parse_mode(optarg, &dir_mode, argv[0]);
+ break;
+ case 'f':
+ filem_change = 1;
+ ret = parse_mode(optarg, &file_mode, argv[0]);
+ break;
default:
usage(1, argv[0]);
return -1;
cgroup_free(&cgroup);
goto err;
}
+ if (dirm_change + filem_change > 0) {
+ ret = cg_chmod_recursive(cgroup, dir_mode, dirm_change,
+ file_mode, filem_change);
+ if (ret) {
+ fprintf(stderr, "%s: can't change permission " \
+ "of cgroup %s: %s\n", argv[0],
+ cgroup->name, cgroup_strerror(ret));
+ cgroup_free(&cgroup);
+ goto err;
+ }
+ }
cgroup_free(&cgroup);
}
err: