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
cb82ed39
Commit
cb82ed39
authored
Mar 30, 2016
by
Serge Hallyn
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #929 from brauner/2016-03-27/mmap_file_to_str
use smarter error handling for lxc_strmmap()
parents
42071d37
981f6029
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
19 deletions
+19
-19
utils.c
src/lxc/utils.c
+15
-16
utils.h
src/lxc/utils.h
+4
-3
No files found.
src/lxc/utils.c
View file @
cb82ed39
...
@@ -23,29 +23,29 @@
...
@@ -23,29 +23,29 @@
#include "config.h"
#include "config.h"
#include <assert.h>
#include <dirent.h>
#include <errno.h>
#include <errno.h>
#include <
unistd
.h>
#include <
fcntl
.h>
#include <
stdlib
.h>
#include <
libgen
.h>
#include <stddef.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/vfs.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/mman.h>
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/mount.h>
#include <
dirent
.h>
#include <
sys/param
.h>
#include <
fcn
tl.h>
#include <
sys/prc
tl.h>
#include <
libgen
.h>
#include <
sys/stat
.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/vfs.h>
#include <sys/wait.h>
#include <sys/wait.h>
#include <assert.h>
#include <sys/prctl.h>
#include "utils.h"
#include "log.h"
#include "log.h"
#include "lxclock.h"
#include "lxclock.h"
#include "namespace.h"
#include "namespace.h"
#include "utils.h"
#ifndef PR_SET_MM
#ifndef PR_SET_MM
#define PR_SET_MM 35
#define PR_SET_MM 35
...
@@ -1821,17 +1821,16 @@ void *lxc_strmmap(void *addr, size_t length, int prot, int flags, int fd,
...
@@ -1821,17 +1821,16 @@ void *lxc_strmmap(void *addr, size_t length, int prot, int flags, int fd,
* underlying file. The pages handed to us are zero filled. */
* underlying file. The pages handed to us are zero filled. */
tmp
=
mmap
(
addr
,
length
+
1
,
PROT_READ
,
MAP_PRIVATE
|
MAP_ANONYMOUS
,
-
1
,
0
);
tmp
=
mmap
(
addr
,
length
+
1
,
PROT_READ
,
MAP_PRIVATE
|
MAP_ANONYMOUS
,
-
1
,
0
);
if
(
tmp
==
MAP_FAILED
)
if
(
tmp
==
MAP_FAILED
)
goto
out
;
return
tmp
;
/* Now we establish a fixed-address mapping starting at the address we
/* Now we establish a fixed-address mapping starting at the address we
* received from our anonymous mapping and replace all bytes excluding
* received from our anonymous mapping and replace all bytes excluding
* the additional \0-byte with the file. This allows us to use normal
* the additional \0-byte with the file. This allows us to use normal
* string-handling function. */
* string-handling function
s
. */
overlap
=
mmap
(
tmp
,
length
,
prot
,
MAP_FIXED
|
flags
,
fd
,
offset
);
overlap
=
mmap
(
tmp
,
length
,
prot
,
MAP_FIXED
|
flags
,
fd
,
offset
);
if
(
overlap
==
MAP_FAILED
)
if
(
overlap
==
MAP_FAILED
)
goto
out
;
munmap
(
tmp
,
length
+
1
)
;
out
:
return
overlap
;
return
overlap
;
}
}
...
...
src/lxc/utils.h
View file @
cb82ed39
...
@@ -23,6 +23,8 @@
...
@@ -23,6 +23,8 @@
#ifndef __LXC_UTILS_H
#ifndef __LXC_UTILS_H
#define __LXC_UTILS_H
#define __LXC_UTILS_H
#include "config.h"
#include <errno.h>
#include <errno.h>
#include <stdarg.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdio.h>
...
@@ -31,7 +33,6 @@
...
@@ -31,7 +33,6 @@
#include <sys/types.h>
#include <sys/types.h>
#include <unistd.h>
#include <unistd.h>
#include "config.h"
#include "initutils.h"
#include "initutils.h"
/* returns 1 on success, 0 if there were any failures */
/* returns 1 on success, 0 if there were any failures */
...
@@ -253,11 +254,11 @@ extern size_t lxc_array_len(void **array);
...
@@ -253,11 +254,11 @@ extern size_t lxc_array_len(void **array);
extern
void
**
lxc_append_null_to_array
(
void
**
array
,
size_t
count
);
extern
void
**
lxc_append_null_to_array
(
void
**
array
,
size_t
count
);
/* mmap() wrapper. lxc_mmap() will take care to \0-terminate files so that
/* mmap() wrapper. lxc_
str
mmap() will take care to \0-terminate files so that
* normal string-handling functions can be used on the buffer. */
* normal string-handling functions can be used on the buffer. */
extern
void
*
lxc_strmmap
(
void
*
addr
,
size_t
length
,
int
prot
,
int
flags
,
int
fd
,
extern
void
*
lxc_strmmap
(
void
*
addr
,
size_t
length
,
int
prot
,
int
flags
,
int
fd
,
off_t
offset
);
off_t
offset
);
/* munmap() wrapper. Use it to free memory mmap()ed with lxc_mmap(). */
/* munmap() wrapper. Use it to free memory mmap()ed with lxc_
str
mmap(). */
extern
int
lxc_strmunmap
(
void
*
addr
,
size_t
length
);
extern
int
lxc_strmunmap
(
void
*
addr
,
size_t
length
);
//initialize rand with urandom
//initialize rand with urandom
...
...
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