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
a6993015
Unverified
Commit
a6993015
authored
Jan 12, 2018
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools: lxc-autostart: non-functional changes
Closes #2073. Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
9267beba
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
80 additions
and
100 deletions
+80
-100
lxc_autostart.c
src/lxc/tools/lxc_autostart.c
+80
-100
No files found.
src/lxc/tools/lxc_autostart.c
View file @
a6993015
...
...
@@ -18,6 +18,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
...
...
@@ -144,14 +146,13 @@ int lists_contain_common_entry(struct lxc_list *p1, struct lxc_list *p2) {
return
0
;
}
/*
* This is a variation of get_list below it.
* This version allows two additional features.
* If a list is passed to it, it adds to it.
* It allows for empty entries (i.e. "group1,,group2") generating
* and empty list entry.
/* This is a variation of get_list below it. This version allows two additional
* features. If a list is passed to it, it adds to it. It allows for empty
* entries (i.e. "group1,,group2") generating and empty list entry.
*/
static
struct
lxc_list
*
accumulate_list
(
char
*
input
,
char
*
delimiter
,
struct
lxc_list
*
str_list
)
{
static
struct
lxc_list
*
accumulate_list
(
char
*
input
,
char
*
delimiter
,
struct
lxc_list
*
str_list
)
{
char
*
workstr
=
NULL
;
char
*
workptr
=
NULL
;
char
*
next_ptr
=
NULL
;
...
...
@@ -159,45 +160,33 @@ static struct lxc_list *accumulate_list(char *input, char *delimiter, struct lxc
struct
lxc_list
*
workstr_list
;
workstr
=
strdup
(
input
);
if
(
!
workstr
)
{
if
(
!
workstr
)
return
NULL
;
}
workstr_list
=
str_list
;
if
(
!
workstr_list
)
{
if
(
!
workstr_list
)
{
workstr_list
=
malloc
(
sizeof
(
*
workstr_list
));
lxc_list_init
(
workstr_list
);
}
for
(
workptr
=
workstr
;
workptr
;
workptr
=
next_ptr
)
{
/*
* We can't use strtok_r here because it collapses
* multiple delimiters into 1 making empty fields
* impossible...
/* We can't use strtok_r here because it collapses multiple
* delimiters into 1 making empty fields impossible...
*/
/* token = strtok_r(workptr, delimiter, &sptr); */
next_ptr
=
strchr
(
workptr
,
*
delimiter
);
if
(
next_ptr
)
{
next_ptr
=
strchr
(
workptr
,
*
delimiter
);
if
(
next_ptr
)
*
next_ptr
++
=
'\0'
;
}
/*
* At this point, we'd like to check to see if this
* group is already contained in the list and ignore
* it if it is... This also helps us with any
* corner cases where a string begins or ends with a
* delimiter.
/* At this point, we'd like to check to see if this group is
* already contained in the list and ignore it if it is... This
* also helps us with any corner cases where a string begins or
* ends with a delimiter.
*/
if
(
list_contains_entry
(
workptr
,
workstr_list
)
)
{
if
(
*
workptr
)
{
fprintf
(
stderr
,
"Duplicate group
\"
%s
\"
in list - ignoring
\n
"
,
workptr
);
fflush
(
stderr
);
}
else
{
fprintf
(
stderr
,
"Duplicate NULL group in list - ignoring
\n
"
);
fflush
(
stderr
);
}
if
(
list_contains_entry
(
workptr
,
workstr_list
))
{
if
(
*
workptr
)
fprintf
(
stderr
,
"Duplicate group
\"
%s
\"
in list - ignoring
\n
"
,
workptr
);
else
fprintf
(
stderr
,
"Duplicate NULL group in list - ignoring
\n
"
);
}
else
{
worklist
=
malloc
(
sizeof
(
*
worklist
));
if
(
!
worklist
)
...
...
@@ -218,7 +207,8 @@ static struct lxc_list *accumulate_list(char *input, char *delimiter, struct lxc
return
workstr_list
;
}
static
struct
lxc_list
*
get_list
(
char
*
input
,
char
*
delimiter
)
{
static
struct
lxc_list
*
get_list
(
char
*
input
,
char
*
delimiter
)
{
char
*
workstr
=
NULL
;
char
*
workptr
=
NULL
;
char
*
sptr
=
NULL
;
...
...
@@ -235,11 +225,10 @@ static struct lxc_list *get_list(char *input, char *delimiter) {
return
NULL
;
}
for
(
workptr
=
workstr
;;
workptr
=
NULL
)
{
for
(
workptr
=
workstr
;;
workptr
=
NULL
)
{
token
=
strtok_r
(
workptr
,
delimiter
,
&
sptr
);
if
(
!
token
)
{
if
(
!
token
)
break
;
}
worklist
=
malloc
(
sizeof
(
*
worklist
));
if
(
!
worklist
)
...
...
@@ -259,16 +248,17 @@ static struct lxc_list *get_list(char *input, char *delimiter) {
return
workstr_list
;
}
static
struct
lxc_list
*
get_config_list
(
struct
lxc_container
*
c
,
char
*
key
)
{
static
struct
lxc_list
*
get_config_list
(
struct
lxc_container
*
c
,
char
*
key
)
{
int
len
=
0
;
char
*
value
=
NULL
;
char
*
value
=
NULL
;
struct
lxc_list
*
config_list
=
NULL
;
len
=
c
->
get_config_item
(
c
,
key
,
NULL
,
0
);
if
(
len
<
0
)
return
NULL
;
value
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
len
+
1
);
value
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
len
+
1
);
if
(
value
==
NULL
)
return
NULL
;
...
...
@@ -288,16 +278,16 @@ static struct lxc_list *get_config_list(struct lxc_container *c, char *key) {
return
config_list
;
}
static
int
get_config_integer
(
struct
lxc_container
*
c
,
char
*
key
)
{
int
len
=
0
;
int
ret
=
0
;
char
*
value
=
NULL
;
static
int
get_config_integer
(
struct
lxc_container
*
c
,
char
*
key
)
{
int
len
=
0
,
ret
=
0
;
char
*
value
=
NULL
;
len
=
c
->
get_config_item
(
c
,
key
,
NULL
,
0
);
if
(
len
<
0
)
return
0
;
value
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
len
+
1
);
value
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
len
+
1
);
if
(
value
==
NULL
)
return
0
;
...
...
@@ -314,7 +304,8 @@ static int get_config_integer(struct lxc_container *c, char *key) {
return
ret
;
}
static
int
cmporder
(
const
void
*
p1
,
const
void
*
p2
)
{
static
int
cmporder
(
const
void
*
p1
,
const
void
*
p2
)
{
struct
lxc_container
*
c1
=
*
(
struct
lxc_container
**
)
p1
;
struct
lxc_container
*
c2
=
*
(
struct
lxc_container
**
)
p2
;
...
...
@@ -323,33 +314,33 @@ static int cmporder(const void *p1, const void *p2) {
if
(
c1_order
==
c2_order
)
return
strcmp
(
c1
->
name
,
c2
->
name
);
else
return
(
c1_order
-
c2_order
);
return
(
c1_order
-
c2_order
);
}
static
int
toss_list
(
struct
lxc_list
*
c_groups_list
)
{
static
int
toss_list
(
struct
lxc_list
*
c_groups_list
)
{
struct
lxc_list
*
it
,
*
next
;
if
(
c_groups_list
)
{
lxc_list_for_each_safe
(
it
,
c_groups_list
,
next
)
{
lxc_list_del
(
it
);
free
(
it
->
elem
);
free
(
it
);
}
free
(
c_groups_lis
t
);
if
(
!
c_groups_list
)
return
1
;
lxc_list_for_each_safe
(
it
,
c_groups_list
,
next
)
{
lxc_list_del
(
it
);
free
(
it
->
elem
);
free
(
i
t
);
}
free
(
c_groups_list
);
return
1
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
count
=
0
;
int
i
=
0
;
int
ret
=
0
;
int
count
=
0
,
i
=
0
,
ret
=
0
;
struct
lxc_list
*
cmd_group
;
struct
lxc_container
**
containers
=
NULL
;
struct
lxc_list
**
c_groups_lists
=
NULL
;
struct
lxc_list
*
cmd_group
;
struct
lxc_log
log
;
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
...
...
@@ -374,36 +365,29 @@ int main(int argc, char *argv[])
if
(
count
<
0
)
exit
(
EXIT_FAILURE
);
if
(
!
my_args
.
all
)
{
/* Allocate an array for our container group lists */
/* Allocate an array for our container group lists */
if
(
!
my_args
.
all
)
c_groups_lists
=
calloc
(
count
,
sizeof
(
struct
lxc_list
*
)
);
}
qsort
(
&
containers
[
0
],
count
,
sizeof
(
struct
lxc_container
*
),
cmporder
);
if
(
cmd_groups_list
&&
my_args
.
all
)
{
if
(
cmd_groups_list
&&
my_args
.
all
)
fprintf
(
stderr
,
"Specifying -a (all) with -g (groups) doesn't make sense. All option overrides.
\n
"
);
fflush
(
stderr
);
}
if
(
!
cmd_groups_list
)
{
/*
* We need a default cmd_groups_list even for the -a
* case in order to force a pass through the loop for
* the NULL group. This, someday, could be taken from
* a config file somewhere...
*/
/* We need a default cmd_groups_list even for the -a
* case in order to force a pass through the loop for
* the NULL group. This, someday, could be taken from
* a config file somewhere...
*/
if
(
!
cmd_groups_list
)
cmd_groups_list
=
accumulate_list
(
""
,
","
,
NULL
);
}
lxc_list_for_each
(
cmd_group
,
cmd_groups_list
)
{
/*
* Prograpmmers Note:
* Because we may take several passes through the container list
* We'll switch on if the container pointer is NULL and if we process a
* container (run it or decide to ignore it) and call lxc_container_put
* then we'll NULL it out and not check it again.
/* Because we may take several passes through the container list
* We'll switch on if the container pointer is NULL and if we
* process a container (run it or decide to ignore it) and call
* lxc_container_put then we'll NULL it out and not check it
* again.
*/
for
(
i
=
0
;
i
<
count
;
i
++
)
{
struct
lxc_container
*
c
=
containers
[
i
];
...
...
@@ -412,10 +396,9 @@ int main(int argc, char *argv[])
/* Skip - must have been already processed */
continue
;
/*
* We haven't loaded the container groups yet so
* these next two checks don't need to free them
* if they fail. They'll fail on the first pass.
/* We haven't loaded the container groups yet so these
* next two checks don't need to free them if they fail.
* They'll fail on the first pass.
*/
if
(
!
c
->
may_control
(
c
))
{
/* We're done with this container */
...
...
@@ -442,8 +425,10 @@ int main(int argc, char *argv[])
ret
=
list_contains_entry
(
cmd_group
->
elem
,
c_groups_lists
[
i
]);
if
(
ret
==
0
)
{
/* Not in the target group this pass */
/* Leave in the list for subsequent passes */
/* Not in the target group this pass so
* leave in the list for subsequent
* passes.
*/
continue
;
}
}
...
...
@@ -467,8 +452,7 @@ int main(int argc, char *argv[])
}
}
}
}
else
if
(
my_args
.
hardstop
)
{
}
else
if
(
my_args
.
hardstop
)
{
/* Kill the container */
if
(
c
->
is_running
(
c
))
{
if
(
my_args
.
list
)
{
...
...
@@ -482,8 +466,7 @@ int main(int argc, char *argv[])
}
}
}
}
else
if
(
my_args
.
reboot
)
{
}
else
if
(
my_args
.
reboot
)
{
/* Reboot the container */
if
(
c
->
is_running
(
c
))
{
if
(
my_args
.
list
)
{
...
...
@@ -500,8 +483,7 @@ int main(int argc, char *argv[])
sleep
(
get_config_integer
(
c
,
"lxc.start.delay"
));
}
}
}
else
{
}
else
{
/* Start the container */
if
(
!
c
->
is_running
(
c
))
{
if
(
my_args
.
list
)
{
...
...
@@ -525,9 +507,8 @@ int main(int argc, char *argv[])
* then we're done with this container... We can dump any
* c_groups_list and the container itself.
*/
if
(
lxc_container_put
(
c
)
>
0
)
{
if
(
lxc_container_put
(
c
)
>
0
)
containers
[
i
]
=
NULL
;
}
if
(
c_groups_lists
)
{
toss_list
(
c_groups_lists
[
i
]);
c_groups_lists
[
i
]
=
NULL
;
...
...
@@ -538,12 +519,11 @@ int main(int argc, char *argv[])
/* clean up any lingering detritus */
for
(
i
=
0
;
i
<
count
;
i
++
)
{
if
(
containers
[
i
]
)
{
if
(
containers
[
i
])
lxc_container_put
(
containers
[
i
]);
}
if
(
c_groups_lists
&&
c_groups_lists
[
i
]
)
{
if
(
c_groups_lists
&&
c_groups_lists
[
i
])
toss_list
(
c_groups_lists
[
i
]);
}
}
free
(
c_groups_lists
);
...
...
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