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
228aeaca
Unverified
Commit
228aeaca
authored
Oct 10, 2017
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init: rework dumb init
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
650f4468
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
142 additions
and
142 deletions
+142
-142
Makefile.am
src/lxc/Makefile.am
+1
-2
initutils.c
src/lxc/initutils.c
+106
-0
initutils.h
src/lxc/initutils.h
+34
-9
lxc_init.c
src/lxc/lxc_init.c
+0
-1
lxccontainer.c
src/lxc/lxccontainer.c
+1
-0
utils.c
src/lxc/utils.c
+0
-129
utils.h
src/lxc/utils.h
+0
-1
No files found.
src/lxc/Makefile.am
View file @
228aeaca
...
@@ -289,8 +289,7 @@ endif
...
@@ -289,8 +289,7 @@ endif
if
HAVE_STATIC_LIBCAP
if
HAVE_STATIC_LIBCAP
sbin_PROGRAMS
+=
init.lxc.static
sbin_PROGRAMS
+=
init.lxc.static
init_lxc_static_SOURCES
=
lxc_init.c error.c log.c initutils.c caps.c
\
init_lxc_static_SOURCES
=
lxc_init.c error.c log.c initutils.c caps.c
tools/arguments.c
if
!HAVE_GETLINE
if
!HAVE_GETLINE
if
HAVE_FGETLN
if
HAVE_FGETLN
...
...
src/lxc/initutils.c
View file @
228aeaca
...
@@ -21,6 +21,8 @@
...
@@ -21,6 +21,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
*/
#include <sys/prctl.h>
#include "initutils.h"
#include "initutils.h"
#include "log.h"
#include "log.h"
...
@@ -296,3 +298,107 @@ FILE *fopen_cloexec(const char *path, const char *mode)
...
@@ -296,3 +298,107 @@ FILE *fopen_cloexec(const char *path, const char *mode)
errno
=
saved_errno
;
errno
=
saved_errno
;
return
ret
;
return
ret
;
}
}
/*
* Sets the process title to the specified title. Note that this may fail if
* the kernel doesn't support PR_SET_MM_MAP (kernels <3.18).
*/
int
setproctitle
(
char
*
title
)
{
static
char
*
proctitle
=
NULL
;
char
buf
[
2048
],
*
tmp
;
FILE
*
f
;
int
i
,
len
,
ret
=
0
;
/* We don't really need to know all of this stuff, but unfortunately
* PR_SET_MM_MAP requires us to set it all at once, so we have to
* figure it out anyway.
*/
unsigned
long
start_data
,
end_data
,
start_brk
,
start_code
,
end_code
,
start_stack
,
arg_start
,
arg_end
,
env_start
,
env_end
,
brk_val
;
struct
prctl_mm_map
prctl_map
;
f
=
fopen_cloexec
(
"/proc/self/stat"
,
"r"
);
if
(
!
f
)
{
return
-
1
;
}
tmp
=
fgets
(
buf
,
sizeof
(
buf
),
f
);
fclose
(
f
);
if
(
!
tmp
)
{
return
-
1
;
}
/* Skip the first 25 fields, column 26-28 are start_code, end_code,
* and start_stack */
tmp
=
strchr
(
buf
,
' '
);
for
(
i
=
0
;
i
<
24
;
i
++
)
{
if
(
!
tmp
)
return
-
1
;
tmp
=
strchr
(
tmp
+
1
,
' '
);
}
if
(
!
tmp
)
return
-
1
;
i
=
sscanf
(
tmp
,
"%lu %lu %lu"
,
&
start_code
,
&
end_code
,
&
start_stack
);
if
(
i
!=
3
)
return
-
1
;
/* Skip the next 19 fields, column 45-51 are start_data to arg_end */
for
(
i
=
0
;
i
<
19
;
i
++
)
{
if
(
!
tmp
)
return
-
1
;
tmp
=
strchr
(
tmp
+
1
,
' '
);
}
if
(
!
tmp
)
return
-
1
;
i
=
sscanf
(
tmp
,
"%lu %lu %lu %*u %*u %lu %lu"
,
&
start_data
,
&
end_data
,
&
start_brk
,
&
env_start
,
&
env_end
);
if
(
i
!=
5
)
return
-
1
;
/* Include the null byte here, because in the calculations below we
* want to have room for it. */
len
=
strlen
(
title
)
+
1
;
proctitle
=
realloc
(
proctitle
,
len
);
if
(
!
proctitle
)
return
-
1
;
arg_start
=
(
unsigned
long
)
proctitle
;
arg_end
=
arg_start
+
len
;
brk_val
=
syscall
(
__NR_brk
,
0
);
prctl_map
=
(
struct
prctl_mm_map
)
{
.
start_code
=
start_code
,
.
end_code
=
end_code
,
.
start_stack
=
start_stack
,
.
start_data
=
start_data
,
.
end_data
=
end_data
,
.
start_brk
=
start_brk
,
.
brk
=
brk_val
,
.
arg_start
=
arg_start
,
.
arg_end
=
arg_end
,
.
env_start
=
env_start
,
.
env_end
=
env_end
,
.
auxv
=
NULL
,
.
auxv_size
=
0
,
.
exe_fd
=
-
1
,
};
ret
=
prctl
(
PR_SET_MM
,
PR_SET_MM_MAP
,
(
long
)
&
prctl_map
,
sizeof
(
prctl_map
),
0
);
if
(
ret
==
0
)
strcpy
((
char
*
)
arg_start
,
title
);
else
INFO
(
"setting cmdline failed - %s"
,
strerror
(
errno
));
return
ret
;
}
src/lxc/initutils.h
View file @
228aeaca
...
@@ -25,17 +25,16 @@
...
@@ -25,17 +25,16 @@
#define __LXC_INITUTILS_H
#define __LXC_INITUTILS_H
#include <errno.h>
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mount.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include "config.h"
#include "config.h"
...
@@ -44,11 +43,37 @@
...
@@ -44,11 +43,37 @@
#define DEFAULT_ZFSROOT "lxc"
#define DEFAULT_ZFSROOT "lxc"
#define DEFAULT_RBDPOOL "lxc"
#define DEFAULT_RBDPOOL "lxc"
#ifndef PR_SET_MM
#define PR_SET_MM 35
#endif
#ifndef PR_SET_MM_MAP
#define PR_SET_MM_MAP 14
struct
prctl_mm_map
{
uint64_t
start_code
;
uint64_t
end_code
;
uint64_t
start_data
;
uint64_t
end_data
;
uint64_t
start_brk
;
uint64_t
brk
;
uint64_t
start_stack
;
uint64_t
arg_start
;
uint64_t
arg_end
;
uint64_t
env_start
;
uint64_t
env_end
;
uint64_t
*
auxv
;
uint32_t
auxv_size
;
uint32_t
exe_fd
;
};
#endif
extern
void
lxc_setup_fs
(
void
);
extern
void
lxc_setup_fs
(
void
);
extern
const
char
*
lxc_global_config_value
(
const
char
*
option_name
);
extern
const
char
*
lxc_global_config_value
(
const
char
*
option_name
);
/* open a file with O_CLOEXEC */
/* open a file with O_CLOEXEC */
extern
void
remove_trailing_slashes
(
char
*
p
);
extern
void
remove_trailing_slashes
(
char
*
p
);
FILE
*
fopen_cloexec
(
const
char
*
path
,
const
char
*
mode
);
extern
FILE
*
fopen_cloexec
(
const
char
*
path
,
const
char
*
mode
);
extern
int
setproctitle
(
char
*
title
);
#endif
/* __LXC_INITUTILS_H */
#endif
/* __LXC_INITUTILS_H */
src/lxc/lxc_init.c
View file @
228aeaca
...
@@ -36,7 +36,6 @@
...
@@ -36,7 +36,6 @@
#include <lxc/lxccontainer.h>
#include <lxc/lxccontainer.h>
#include "log.h"
#include "log.h"
#include "arguments.h"
#include "error.h"
#include "error.h"
#include "initutils.h"
#include "initutils.h"
...
...
src/lxc/lxccontainer.c
View file @
228aeaca
...
@@ -48,6 +48,7 @@
...
@@ -48,6 +48,7 @@
#include "confile.h"
#include "confile.h"
#include "console.h"
#include "console.h"
#include "criu.h"
#include "criu.h"
#include "initutils.h"
#include "log.h"
#include "log.h"
#include "lxc.h"
#include "lxc.h"
#include "lxccontainer.h"
#include "lxccontainer.h"
...
...
src/lxc/utils.c
View file @
228aeaca
...
@@ -50,31 +50,6 @@
...
@@ -50,31 +50,6 @@
#include "parse.h"
#include "parse.h"
#include "utils.h"
#include "utils.h"
#ifndef PR_SET_MM
#define PR_SET_MM 35
#endif
#ifndef PR_SET_MM_MAP
#define PR_SET_MM_MAP 14
struct
prctl_mm_map
{
uint64_t
start_code
;
uint64_t
end_code
;
uint64_t
start_data
;
uint64_t
end_data
;
uint64_t
start_brk
;
uint64_t
brk
;
uint64_t
start_stack
;
uint64_t
arg_start
;
uint64_t
arg_end
;
uint64_t
env_start
;
uint64_t
env_end
;
uint64_t
*
auxv
;
uint32_t
auxv_size
;
uint32_t
exe_fd
;
};
#endif
#ifndef O_PATH
#ifndef O_PATH
#define O_PATH 010000000
#define O_PATH 010000000
#endif
#endif
...
@@ -1372,110 +1347,6 @@ char *get_template_path(const char *t)
...
@@ -1372,110 +1347,6 @@ char *get_template_path(const char *t)
}
}
/*
/*
* Sets the process title to the specified title. Note that this may fail if
* the kernel doesn't support PR_SET_MM_MAP (kernels <3.18).
*/
int
setproctitle
(
char
*
title
)
{
static
char
*
proctitle
=
NULL
;
char
buf
[
2048
],
*
tmp
;
FILE
*
f
;
int
i
,
len
,
ret
=
0
;
/* We don't really need to know all of this stuff, but unfortunately
* PR_SET_MM_MAP requires us to set it all at once, so we have to
* figure it out anyway.
*/
unsigned
long
start_data
,
end_data
,
start_brk
,
start_code
,
end_code
,
start_stack
,
arg_start
,
arg_end
,
env_start
,
env_end
,
brk_val
;
struct
prctl_mm_map
prctl_map
;
f
=
fopen_cloexec
(
"/proc/self/stat"
,
"r"
);
if
(
!
f
)
{
return
-
1
;
}
tmp
=
fgets
(
buf
,
sizeof
(
buf
),
f
);
fclose
(
f
);
if
(
!
tmp
)
{
return
-
1
;
}
/* Skip the first 25 fields, column 26-28 are start_code, end_code,
* and start_stack */
tmp
=
strchr
(
buf
,
' '
);
for
(
i
=
0
;
i
<
24
;
i
++
)
{
if
(
!
tmp
)
return
-
1
;
tmp
=
strchr
(
tmp
+
1
,
' '
);
}
if
(
!
tmp
)
return
-
1
;
i
=
sscanf
(
tmp
,
"%lu %lu %lu"
,
&
start_code
,
&
end_code
,
&
start_stack
);
if
(
i
!=
3
)
return
-
1
;
/* Skip the next 19 fields, column 45-51 are start_data to arg_end */
for
(
i
=
0
;
i
<
19
;
i
++
)
{
if
(
!
tmp
)
return
-
1
;
tmp
=
strchr
(
tmp
+
1
,
' '
);
}
if
(
!
tmp
)
return
-
1
;
i
=
sscanf
(
tmp
,
"%lu %lu %lu %*u %*u %lu %lu"
,
&
start_data
,
&
end_data
,
&
start_brk
,
&
env_start
,
&
env_end
);
if
(
i
!=
5
)
return
-
1
;
/* Include the null byte here, because in the calculations below we
* want to have room for it. */
len
=
strlen
(
title
)
+
1
;
proctitle
=
realloc
(
proctitle
,
len
);
if
(
!
proctitle
)
return
-
1
;
arg_start
=
(
unsigned
long
)
proctitle
;
arg_end
=
arg_start
+
len
;
brk_val
=
syscall
(
__NR_brk
,
0
);
prctl_map
=
(
struct
prctl_mm_map
)
{
.
start_code
=
start_code
,
.
end_code
=
end_code
,
.
start_stack
=
start_stack
,
.
start_data
=
start_data
,
.
end_data
=
end_data
,
.
start_brk
=
start_brk
,
.
brk
=
brk_val
,
.
arg_start
=
arg_start
,
.
arg_end
=
arg_end
,
.
env_start
=
env_start
,
.
env_end
=
env_end
,
.
auxv
=
NULL
,
.
auxv_size
=
0
,
.
exe_fd
=
-
1
,
};
ret
=
prctl
(
PR_SET_MM
,
PR_SET_MM_MAP
,
(
long
)
&
prctl_map
,
sizeof
(
prctl_map
),
0
);
if
(
ret
==
0
)
strcpy
((
char
*
)
arg_start
,
title
);
else
INFO
(
"setting cmdline failed - %s"
,
strerror
(
errno
));
return
ret
;
}
/*
* @path: a pathname where / replaced with '\0'.
* @path: a pathname where / replaced with '\0'.
* @offsetp: pointer to int showing which path segment was last seen.
* @offsetp: pointer to int showing which path segment was last seen.
* Updated on return to reflect the next segment.
* Updated on return to reflect the next segment.
...
...
src/lxc/utils.h
View file @
228aeaca
...
@@ -442,7 +442,6 @@ int print_to_file(const char *file, const char *content);
...
@@ -442,7 +442,6 @@ int print_to_file(const char *file, const char *content);
bool
switch_to_ns
(
pid_t
pid
,
const
char
*
ns
);
bool
switch_to_ns
(
pid_t
pid
,
const
char
*
ns
);
int
is_dir
(
const
char
*
path
);
int
is_dir
(
const
char
*
path
);
char
*
get_template_path
(
const
char
*
t
);
char
*
get_template_path
(
const
char
*
t
);
int
setproctitle
(
char
*
title
);
int
safe_mount
(
const
char
*
src
,
const
char
*
dest
,
const
char
*
fstype
,
int
safe_mount
(
const
char
*
src
,
const
char
*
dest
,
const
char
*
fstype
,
unsigned
long
flags
,
const
void
*
data
,
const
char
*
rootfs
);
unsigned
long
flags
,
const
void
*
data
,
const
char
*
rootfs
);
int
lxc_mount_proc_if_needed
(
const
char
*
rootfs
);
int
lxc_mount_proc_if_needed
(
const
char
*
rootfs
);
...
...
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