Commit e4ccd113 by Serge Hallyn

userns: handle delayed write errors at fclose

As Kees pointed out, write() errors can be delayed and returned as close() errors. So don't ignore error on close when writing the userns id mapping. Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com>
parent dba104c8
...@@ -2447,7 +2447,7 @@ int lxc_assign_network(struct lxc_list *network, pid_t pid) ...@@ -2447,7 +2447,7 @@ int lxc_assign_network(struct lxc_list *network, pid_t pid)
int add_id_mapping(enum idtype idtype, pid_t pid, uid_t host_start, uid_t ns_start, int range) int add_id_mapping(enum idtype idtype, pid_t pid, uid_t host_start, uid_t ns_start, int range)
{ {
char path[PATH_MAX]; char path[PATH_MAX];
int ret; int ret, closeret;
FILE *f; FILE *f;
ret = snprintf(path, PATH_MAX, "/proc/%d/%cid_map", pid, idtype == ID_TYPE_UID ? 'u' : 'g'); ret = snprintf(path, PATH_MAX, "/proc/%d/%cid_map", pid, idtype == ID_TYPE_UID ? 'u' : 'g');
...@@ -2462,9 +2462,11 @@ int add_id_mapping(enum idtype idtype, pid_t pid, uid_t host_start, uid_t ns_sta ...@@ -2462,9 +2462,11 @@ int add_id_mapping(enum idtype idtype, pid_t pid, uid_t host_start, uid_t ns_sta
} }
ret = fprintf(f, "%d %d %d", ns_start, host_start, range); ret = fprintf(f, "%d %d %d", ns_start, host_start, range);
if (ret < 0) if (ret < 0)
perror("write"); SYSERROR("writing id mapping");
fclose(f); closeret = fclose(f);
return ret < 0 ? ret : 0; if (closeret)
SYSERROR("writing id mapping");
return ret < 0 ? ret : closeret;
} }
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