Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
843d1221
Unverified
Commit
843d1221
authored
May 27, 2017
by
Christian Brauner
Committed by
Stéphane Graber
Jul 01, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
conf: improve write_id_mapping()
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
ccab7162
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
17 deletions
+23
-17
conf.c
src/lxc/conf.c
+23
-17
No files found.
src/lxc/conf.c
View file @
843d1221
...
@@ -3285,27 +3285,33 @@ int lxc_assign_network(const char *lxcpath, char *lxcname,
...
@@ -3285,27 +3285,33 @@ int lxc_assign_network(const char *lxcpath, char *lxcname,
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
;
}
}
/* Check whether a binary exist and has either CAP_SETUID, CAP_SETGID or both. */
/* Check whether a binary exist and has either CAP_SETUID, CAP_SETGID or both. */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment