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
1b0d4457
Unverified
Commit
1b0d4457
authored
Jul 26, 2017
by
Christian Brauner
Committed by
Stéphane Graber
Aug 14, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
utils: move helpers from cgfsng.c to utils.{c,h}
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
822ee637
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
53 deletions
+58
-53
cgfsng.c
src/lxc/cgroups/cgfsng.c
+0
-53
utils.c
src/lxc/utils.c
+47
-0
utils.h
src/lxc/utils.h
+11
-0
No files found.
src/lxc/cgroups/cgfsng.c
View file @
1b0d4457
...
...
@@ -118,36 +118,12 @@ static void free_string_list(char **clist)
}
}
/* Re-alllocate a pointer, do not fail */
static
void
*
must_realloc
(
void
*
orig
,
size_t
sz
)
{
void
*
ret
;
do
{
ret
=
realloc
(
orig
,
sz
);
}
while
(
!
ret
);
return
ret
;
}
/* Allocate a pointer, do not fail */
static
void
*
must_alloc
(
size_t
sz
)
{
return
must_realloc
(
NULL
,
sz
);
}
/* return copy of string @entry; do not fail. */
static
char
*
must_copy_string
(
const
char
*
entry
)
{
char
*
ret
;
if
(
!
entry
)
return
NULL
;
do
{
ret
=
strdup
(
entry
);
}
while
(
!
ret
);
return
ret
;
}
/*
* This is a special case - return a copy of @entry
* prepending 'name='. I.e. turn systemd into name=systemd.
...
...
@@ -259,8 +235,6 @@ struct hierarchy *get_hierarchy(const char *c)
return
NULL
;
}
static
char
*
must_make_path
(
const
char
*
first
,
...)
__attribute__
((
sentinel
));
#define BATCH_SIZE 50
static
void
batch_realloc
(
char
**
mem
,
size_t
oldlen
,
size_t
newlen
)
{
...
...
@@ -1187,33 +1161,6 @@ out_free:
return
NULL
;
}
/*
* Concatenate all passed-in strings into one path. Do not fail. If any piece is
* not prefixed with '/', add a '/'.
*/
static
char
*
must_make_path
(
const
char
*
first
,
...)
{
va_list
args
;
char
*
cur
,
*
dest
;
size_t
full_len
=
strlen
(
first
);
dest
=
must_copy_string
(
first
);
va_start
(
args
,
first
);
while
((
cur
=
va_arg
(
args
,
char
*
))
!=
NULL
)
{
full_len
+=
strlen
(
cur
);
if
(
cur
[
0
]
!=
'/'
)
full_len
++
;
dest
=
must_realloc
(
dest
,
full_len
+
1
);
if
(
cur
[
0
]
!=
'/'
)
strcat
(
dest
,
"/"
);
strcat
(
dest
,
cur
);
}
va_end
(
args
);
return
dest
;
}
static
int
cgroup_rmdir
(
char
*
dirname
)
{
struct
dirent
*
direntp
;
...
...
src/lxc/utils.c
View file @
1b0d4457
...
...
@@ -2337,3 +2337,50 @@ int run_command(char *buf, size_t buf_size, int (*child_fn)(void *), void *args)
return
fret
;
}
char
*
must_make_path
(
const
char
*
first
,
...)
{
va_list
args
;
char
*
cur
,
*
dest
;
size_t
full_len
=
strlen
(
first
);
dest
=
must_copy_string
(
first
);
va_start
(
args
,
first
);
while
((
cur
=
va_arg
(
args
,
char
*
))
!=
NULL
)
{
full_len
+=
strlen
(
cur
);
if
(
cur
[
0
]
!=
'/'
)
full_len
++
;
dest
=
must_realloc
(
dest
,
full_len
+
1
);
if
(
cur
[
0
]
!=
'/'
)
strcat
(
dest
,
"/"
);
strcat
(
dest
,
cur
);
}
va_end
(
args
);
return
dest
;
}
char
*
must_copy_string
(
const
char
*
entry
)
{
char
*
ret
;
if
(
!
entry
)
return
NULL
;
do
{
ret
=
strdup
(
entry
);
}
while
(
!
ret
);
return
ret
;
}
void
*
must_realloc
(
void
*
orig
,
size_t
sz
)
{
void
*
ret
;
do
{
ret
=
realloc
(
orig
,
sz
);
}
while
(
!
ret
);
return
ret
;
}
src/lxc/utils.h
View file @
1b0d4457
...
...
@@ -375,4 +375,15 @@ int lxc_unstack_mountpoint(const char *path, bool lazy);
*/
int
run_command
(
char
*
buf
,
size_t
buf_size
,
int
(
*
child_fn
)(
void
*
),
void
*
args
);
/* Concatenate all passed-in strings into one path. Do not fail. If any piece
* is not prefixed with '/', add a '/'.
*/
char
*
must_make_path
(
const
char
*
first
,
...)
__attribute__
((
sentinel
));
/* return copy of string @entry; do not fail. */
char
*
must_copy_string
(
const
char
*
entry
);
/* Re-alllocate a pointer, do not fail */
void
*
must_realloc
(
void
*
orig
,
size_t
sz
);
#endif
/* __LXC_UTILS_H */
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