Unverified Commit 6def4323 by Christian Brauner Committed by Stéphane Graber

conf: improve write_id_mapping()

parent 8aeafb41
...@@ -3581,27 +3581,33 @@ int lxc_assign_network(struct lxc_list *network, pid_t pid) ...@@ -3581,27 +3581,33 @@ int lxc_assign_network(struct lxc_list *network, pid_t pid)
static int write_id_mapping(enum idtype idtype, pid_t pid, const char *buf, static int write_id_mapping(enum idtype idtype, pid_t pid, const char *buf,
size_t buf_size) size_t buf_size)
{ {
char path[PATH_MAX]; char path[MAXPATHLEN];
int ret, closeret; int fd, ret;
FILE *f;
ret = snprintf(path, PATH_MAX, "/proc/%d/%cid_map", pid, idtype == ID_TYPE_UID ? 'u' : 'g'); ret = snprintf(path, MAXPATHLEN, "/proc/%d/%cid_map", pid,
if (ret < 0 || ret >= PATH_MAX) { idtype == ID_TYPE_UID ? 'u' : 'g');
fprintf(stderr, "%s: path name too long\n", __func__); if (ret < 0 || ret >= MAXPATHLEN) {
ERROR("failed to create path \"%s\"", path);
return -E2BIG; return -E2BIG;
} }
f = fopen(path, "w");
if (!f) { fd = open(path, O_WRONLY);
perror("open"); if (fd < 0) {
return -EINVAL; SYSERROR("failed to open \"%s\"", path);
return -1;
} }
ret = fwrite(buf, buf_size, 1, f);
if (ret < 0) errno = 0;
SYSERROR("writing id mapping"); ret = lxc_write_nointr(fd, buf, buf_size);
closeret = fclose(f); if (ret != buf_size) {
if (closeret) SYSERROR("failed to write %cid mapping to \"%s\"",
SYSERROR("writing id mapping"); idtype == ID_TYPE_UID ? 'u' : 'g', path);
return ret < 0 ? ret : closeret; close(fd);
return -1;
}
close(fd);
return 0;
} }
int lxc_map_ids(struct lxc_list *idmap, pid_t pid) int lxc_map_ids(struct lxc_list *idmap, pid_t pid)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment