84
int lxc_rename_nsgroup(const char *name, pid_t pid)
88
int lxc_rename_nsgroup(const char *name, struct lxc_handler *handler)
86
90
char oldname[MAXPATHLEN];
87
char newname[MAXPATHLEN];
91
char *newname = handler->nsgroup;
88
92
char cgroup[MAXPATHLEN];
96
snprintf(oldname, MAXPATHLEN, "%s/%d", cgroup, pid);
100
snprintf(oldname, MAXPATHLEN, "%s/%d", cgroup, handler->pid);
97
101
snprintf(newname, MAXPATHLEN, "%s/%s", cgroup, name);
99
103
/* there is a previous cgroup, assume it is empty, otherwise
114
118
DEBUG("'%s' renamed to '%s'", oldname, newname);
119
int lxc_link_nsgroup(const char *name)
124
int lxc_unlink_nsgroup(const char *name)
121
char lxc[MAXPATHLEN];
122
126
char nsgroup[MAXPATHLEN];
123
127
char cgroup[MAXPATHLEN];
131
snprintf(lxc, MAXPATHLEN, LXCPATH "/%s/nsgroup", name);
132
135
snprintf(nsgroup, MAXPATHLEN, "%s/%s", cgroup, name);
135
ret = symlink(nsgroup, lxc);
136
ret = rmdir(nsgroup);
137
SYSERROR("failed to create symlink %s->%s", nsgroup, lxc);
138
SYSERROR("failed to remove cgroup '%s'", nsgroup);
139
DEBUG("'%s' linked to '%s'", nsgroup, lxc);
140
DEBUG("'%s' unlinked", nsgroup);
144
int lxc_unlink_nsgroup(const char *name)
145
int lxc_cgroup_path_get(char **path, const char *name)
146
char nsgroup[MAXPATHLEN];
147
char path[MAXPATHLEN];
150
snprintf(nsgroup, MAXPATHLEN, LXCPATH "/%s/nsgroup", name);
152
len = readlink(nsgroup, path, MAXPATHLEN-1);
147
char cgroup[MAXPATHLEN];
149
*path = &nsgroup_path[0];
152
* report nsgroup_path string if already set
157
if (get_cgroup_mount(MTAB, cgroup)) {
158
ERROR("cgroup is not mounted");
158
DEBUG("unlinking '%s'", nsgroup);
160
return unlink(nsgroup);
162
snprintf(nsgroup_path, MAXPATHLEN, "%s/%s", cgroup, name);
163
166
int lxc_cgroup_set(const char *name, const char *subsystem, const char *value)
165
168
int fd, ret = -1;
166
170
char path[MAXPATHLEN];
168
snprintf(path, MAXPATHLEN, LXCPATH "/%s/nsgroup/%s", name, subsystem);
172
ret = lxc_cgroup_path_get(&nsgroup, name);
176
snprintf(path, MAXPATHLEN, "%s/%s", nsgroup, subsystem);
170
178
fd = open(path, O_WRONLY);
188
196
char *value, size_t len)
190
198
int fd, ret = -1;
191
200
char path[MAXPATHLEN];
193
snprintf(path, MAXPATHLEN, LXCPATH "/%s/nsgroup/%s", name, subsystem);
202
ret = lxc_cgroup_path_get(&nsgroup, name);
206
snprintf(path, MAXPATHLEN, "%s/%s", nsgroup, subsystem);
195
208
fd = open(path, O_RDONLY);
201
if (read(fd, value, len) < 0) {
214
ret = read(fd, value, len);
202
216
ERROR("read %s : %s", path, strerror(errno));