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
24d57315
Unverified
Commit
24d57315
authored
Mar 01, 2019
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initutils: remove fgets() from setproctitle()
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
13aa24dd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
43 deletions
+45
-43
initutils.c
src/lxc/initutils.c
+45
-43
No files found.
src/lxc/initutils.c
View file @
24d57315
...
...
@@ -240,62 +240,64 @@ out:
*/
int
setproctitle
(
char
*
title
)
{
__do_fclose
FILE
*
f
=
NULL
;
int
i
,
fd
,
len
;
char
*
buf_ptr
;
char
buf
[
LXC_LINELEN
];
int
ret
=
0
;
ssize_t
bytes_read
=
0
;
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
/*
* 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
;
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
)
{
if
(
!
f
)
return
-
1
;
}
tmp
=
fgets
(
buf
,
sizeof
(
buf
),
f
);
fclose
(
f
);
if
(
!
tmp
)
{
fd
=
fileno
(
f
);
if
(
fd
<
0
)
return
-
1
;
}
bytes_read
=
lxc_read_nointr
(
fd
,
buf
,
sizeof
(
buf
)
-
1
);
if
(
bytes_read
<=
0
)
return
-
1
;
buf
[
bytes_read
]
=
'\0'
;
/* Skip the first 25 fields, column 26-28 are start_code, end_code,
* and start_stack */
tmp
=
strchr
(
buf
,
' '
);
buf_ptr
=
strchr
(
buf
,
' '
);
for
(
i
=
0
;
i
<
24
;
i
++
)
{
if
(
!
tmp
)
if
(
!
buf_ptr
)
return
-
1
;
tmp
=
strchr
(
tmp
+
1
,
' '
);
buf_ptr
=
strchr
(
buf_ptr
+
1
,
' '
);
}
if
(
!
tmp
)
if
(
!
buf_ptr
)
return
-
1
;
i
=
sscanf
(
tmp
,
"%lu %lu %lu"
,
&
start_code
,
&
end_code
,
&
start_stack
);
i
=
sscanf
(
buf_ptr
,
"%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
)
if
(
!
buf_ptr
)
return
-
1
;
tmp
=
strchr
(
tmp
+
1
,
' '
);
buf_ptr
=
strchr
(
buf_ptr
+
1
,
' '
);
}
if
(
!
tmp
)
if
(
!
buf_ptr
)
return
-
1
;
i
=
sscanf
(
tmp
,
"%lu %lu %lu %*u %*u %lu %lu"
,
&
start_data
,
&
end_data
,
&
start_brk
,
&
env_start
,
&
env_end
);
i
=
sscanf
(
buf_ptr
,
"%lu %lu %lu %*u %*u %lu %lu"
,
&
start_data
,
&
end_data
,
&
start_brk
,
&
env_start
,
&
env_end
);
if
(
i
!=
5
)
return
-
1
;
...
...
@@ -307,32 +309,32 @@ int setproctitle(char *title)
if
(
!
proctitle
)
return
-
1
;
arg_start
=
(
unsigned
long
)
proctitle
;
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
,
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
,
prctl_arg
(
PR_SET_MM_MAP
),
prctl_arg
(
&
prctl_map
),
prctl_arg
(
sizeof
(
prctl_map
)),
prctl_arg
(
0
));
if
(
ret
==
0
)
(
void
)
strlcpy
((
char
*
)
arg_start
,
title
,
len
);
(
void
)
strlcpy
((
char
*
)
arg_start
,
title
,
len
);
else
SYSWARN
(
"Failed to set cmdline"
);
...
...
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