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
e14459fa
Commit
e14459fa
authored
Sep 03, 2008
by
dlezcano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
*** empty log message ***
parent
5f59f4ba
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
32 deletions
+54
-32
conf.c
src/liblxc/conf.c
+52
-30
lxc_create.c
src/lxc/lxc_create.c
+2
-2
No files found.
src/liblxc/conf.c
View file @
e14459fa
...
@@ -792,7 +792,7 @@ static int setup_ip6_addr(const char *dirname, const char *ifname)
...
@@ -792,7 +792,7 @@ static int setup_ip6_addr(const char *dirname, const char *ifname)
static
int
setup_network_cb
(
const
char
*
name
,
const
char
*
dirname
,
static
int
setup_network_cb
(
const
char
*
name
,
const
char
*
dirname
,
const
char
*
file
,
void
*
data
)
const
char
*
file
,
void
*
data
)
{
{
char
*
path
;
char
path
[
MAXPATHLEN
]
;
char
strindex
[
MAXINDEXLEN
];
char
strindex
[
MAXINDEXLEN
];
char
ifname
[
IFNAMSIZ
];
char
ifname
[
IFNAMSIZ
];
char
newname
[
IFNAMSIZ
];
char
newname
[
IFNAMSIZ
];
...
@@ -800,7 +800,7 @@ static int setup_network_cb(const char *name, const char *dirname,
...
@@ -800,7 +800,7 @@ static int setup_network_cb(const char *name, const char *dirname,
char
*
current_ifname
=
ifname
;
char
*
current_ifname
=
ifname
;
int
ifindex
,
ret
=
-
1
;
int
ifindex
,
ret
=
-
1
;
asprintf
(
&
path
,
"%s/%s"
,
dirname
,
file
);
snprintf
(
path
,
MAXPATHLEN
,
"%s/%s"
,
dirname
,
file
);
if
(
read_info
(
path
,
"ifindex"
,
strindex
,
sizeof
(
strindex
)))
{
if
(
read_info
(
path
,
"ifindex"
,
strindex
,
sizeof
(
strindex
)))
{
lxc_log_error
(
"failed to read ifindex info"
);
lxc_log_error
(
"failed to read ifindex info"
);
...
@@ -809,21 +809,25 @@ static int setup_network_cb(const char *name, const char *dirname,
...
@@ -809,21 +809,25 @@ static int setup_network_cb(const char *name, const char *dirname,
ifindex
=
atoi
(
strindex
);
ifindex
=
atoi
(
strindex
);
if
(
!
ifindex
)
{
if
(
!
ifindex
)
{
lxc_log_error
(
"bad index %s"
,
strindex
);
if
(
!
read_info
(
path
,
"up"
,
strindex
,
sizeof
(
strindex
))
goto
out
;
if
(
device_up
(
"lo"
))
{
lxc_log_error
(
"failed to set the loopback up"
);
return
-
1
;
}
return
0
;
}
}
if
(
!
if_indextoname
(
ifindex
,
current_ifname
))
{
if
(
!
if_indextoname
(
ifindex
,
current_ifname
))
{
lxc_log_error
(
"no interface corresponding to index '%d'"
,
lxc_log_error
(
"no interface corresponding to index '%d'"
,
ifindex
);
ifindex
);
goto
out
;
return
-
1
;
}
}
if
(
!
read_info
(
path
,
"name"
,
newname
,
sizeof
(
newname
)))
{
if
(
!
read_info
(
path
,
"name"
,
newname
,
sizeof
(
newname
)))
{
if
(
device_rename
(
ifname
,
newname
))
{
if
(
device_rename
(
ifname
,
newname
))
{
lxc_log_error
(
"failed to rename %s->%s"
,
lxc_log_error
(
"failed to rename %s->%s"
,
ifname
,
newname
);
ifname
,
newname
);
goto
out
;
return
-
1
;
}
}
current_ifname
=
newname
;
current_ifname
=
newname
;
}
}
...
@@ -832,38 +836,36 @@ static int setup_network_cb(const char *name, const char *dirname,
...
@@ -832,38 +836,36 @@ static int setup_network_cb(const char *name, const char *dirname,
if
(
setup_hw_addr
(
hwaddr
,
current_ifname
))
{
if
(
setup_hw_addr
(
hwaddr
,
current_ifname
))
{
lxc_log_error
(
"failed to setup hw address for '%s'"
,
lxc_log_error
(
"failed to setup hw address for '%s'"
,
current_ifname
);
current_ifname
);
goto
out
;
return
-
1
;
}
}
}
}
if
(
setup_ip_addr
(
path
,
current_ifname
))
{
if
(
setup_ip_addr
(
path
,
current_ifname
))
{
lxc_log_error
(
"failed to setup ip addresses for '%s'"
,
lxc_log_error
(
"failed to setup ip addresses for '%s'"
,
ifname
);
ifname
);
goto
out
;
return
-
1
;
}
}
if
(
setup_ip6_addr
(
path
,
current_ifname
))
{
if
(
setup_ip6_addr
(
path
,
current_ifname
))
{
lxc_log_error
(
"failed to setup ipv6 addresses for '%s'"
,
lxc_log_error
(
"failed to setup ipv6 addresses for '%s'"
,
ifname
);
ifname
);
goto
out
;
return
-
1
;
}
}
if
(
!
read_info
(
path
,
"up"
,
strindex
,
sizeof
(
strindex
)))
{
if
(
!
read_info
(
path
,
"up"
,
strindex
,
sizeof
(
strindex
)))
{
if
(
device_up
(
current_ifname
))
{
if
(
device_up
(
current_ifname
))
{
lxc_log_error
(
"failed to set '%s' up"
,
current_ifname
);
lxc_log_error
(
"failed to set '%s' up"
,
current_ifname
);
goto
out
;
return
-
1
;
}
}
/* the network is up, make the loopback up too */
/* the network is up, make the loopback up too */
if
(
device_up
(
"lo"
))
{
if
(
device_up
(
"lo"
))
{
lxc_log_error
(
"failed to set the loopback up"
);
lxc_log_error
(
"failed to set the loopback up"
);
goto
out
;
return
-
1
;
}
}
}
}
ret
=
0
;
return
0
;
out:
return
ret
;
}
}
static
int
setup_network
(
const
char
*
name
)
static
int
setup_network
(
const
char
*
name
)
...
@@ -1007,12 +1009,12 @@ out:
...
@@ -1007,12 +1009,12 @@ out:
}
}
static
int
instanciate_macvlan
(
const
char
*
dirname
,
const
char
*
file
,
pid_t
pid
)
static
int
instanciate_macvlan
(
const
char
*
dirname
,
const
char
*
file
,
pid_t
pid
)
{
{
char
*
path
=
NULL
,
*
strindex
=
NULL
,
*
peer
=
NULL
;
char
path
[
MAXPATHLEN
]
,
*
strindex
=
NULL
,
*
peer
=
NULL
;
char
link
[
IFNAMSIZ
];
char
link
[
IFNAMSIZ
];
int
ifindex
,
ret
=
-
1
;
int
ifindex
,
ret
=
-
1
;
asprintf
(
&
peer
,
"%s~%d"
,
file
,
pid
);
asprintf
(
&
peer
,
"%s~%d"
,
file
,
pid
);
asprintf
(
&
path
,
"%s/%s"
,
dirname
,
file
);
snprintf
(
path
,
MAXPATHLEN
,
"%s/%s"
,
dirname
,
file
);
if
(
read_info
(
path
,
"link"
,
link
,
IFNAMSIZ
))
{
if
(
read_info
(
path
,
"link"
,
link
,
IFNAMSIZ
))
{
lxc_log_error
(
"failed to read bridge info"
);
lxc_log_error
(
"failed to read bridge info"
);
goto
out
;
goto
out
;
...
@@ -1037,19 +1039,17 @@ static int instanciate_macvlan(const char *dirname, const char *file, pid_t pid)
...
@@ -1037,19 +1039,17 @@ static int instanciate_macvlan(const char *dirname, const char *file, pid_t pid)
ret
=
0
;
ret
=
0
;
out:
out:
free
(
path
);
free
(
strindex
);
free
(
strindex
);
free
(
peer
);
return
ret
;
return
ret
;
}
}
static
int
instanciate_phys
(
const
char
*
dirname
,
const
char
*
file
,
pid_t
pid
)
static
int
instanciate_phys
(
const
char
*
dirname
,
const
char
*
file
,
pid_t
pid
)
{
{
char
*
path
=
NULL
,
*
strindex
=
NULL
;
char
path
[
MAXPATHLEN
]
,
*
strindex
=
NULL
;
char
link
[
IFNAMSIZ
];
char
link
[
IFNAMSIZ
];
int
ifindex
,
ret
=
-
1
;
int
ifindex
,
ret
=
-
1
;
asprintf
(
&
path
,
"%s/%s"
,
dirname
,
file
);
snprintf
(
path
,
MAXPATHLEN
,
"%s/%s"
,
dirname
,
file
);
if
(
read_info
(
path
,
"link"
,
link
,
IFNAMSIZ
))
{
if
(
read_info
(
path
,
"link"
,
link
,
IFNAMSIZ
))
{
lxc_log_error
(
"failed to read link info"
);
lxc_log_error
(
"failed to read link info"
);
goto
out
;
goto
out
;
...
@@ -1069,7 +1069,28 @@ static int instanciate_phys(const char *dirname, const char *file, pid_t pid)
...
@@ -1069,7 +1069,28 @@ static int instanciate_phys(const char *dirname, const char *file, pid_t pid)
ret
=
0
;
ret
=
0
;
out:
out:
free
(
path
);
free
(
strindex
);
return
ret
;
}
static
int
instanciate_empty
(
const
char
*
dirname
,
const
char
*
file
,
pid_t
pid
)
{
char
path
[
MAXPATHLEN
],
*
strindex
=
NULL
;
int
ret
=
-
1
;
snprintf
(
path
,
MAXPATHLEN
,
"%s/%s"
,
dirname
,
file
);
if
(
!
asprintf
(
&
strindex
,
"%d"
,
0
))
{
lxc_log_error
(
"not enough memory"
);
return
-
1
;
}
if
(
write_info
(
path
,
"ifindex"
,
strindex
))
{
lxc_log_error
(
"failed to write interface index to %s"
,
path
);
goto
out
;
}
ret
=
0
;
out:
free
(
strindex
);
free
(
strindex
);
return
ret
;
return
ret
;
}
}
...
@@ -1085,7 +1106,8 @@ static int instanciate_netdev_cb(const char *name, const char *dirname,
...
@@ -1085,7 +1106,8 @@ static int instanciate_netdev_cb(const char *name, const char *dirname,
return
instanciate_macvlan
(
dirname
,
file
,
*
pid
);
return
instanciate_macvlan
(
dirname
,
file
,
*
pid
);
else
if
(
!
strncmp
(
"phys"
,
file
,
strlen
(
"phys"
)))
else
if
(
!
strncmp
(
"phys"
,
file
,
strlen
(
"phys"
)))
return
instanciate_phys
(
dirname
,
file
,
*
pid
);
return
instanciate_phys
(
dirname
,
file
,
*
pid
);
else
if
(
!
strncmp
(
"empty"
,
file
,
strlen
(
"empty"
))
return
instanciate_empty
(
dirname
,
file
,
*
pid
);
return
-
1
;
return
-
1
;
}
}
...
@@ -1104,32 +1126,32 @@ static int instanciate_netdev(const char *name, pid_t pid)
...
@@ -1104,32 +1126,32 @@ static int instanciate_netdev(const char *name, pid_t pid)
static
int
move_netdev_cb
(
const
char
*
name
,
const
char
*
dirname
,
static
int
move_netdev_cb
(
const
char
*
name
,
const
char
*
dirname
,
const
char
*
file
,
void
*
data
)
const
char
*
file
,
void
*
data
)
{
{
char
*
path
,
ifname
[
IFNAMSIZ
],
strindex
[
MAXINDEXLEN
];
char
path
[
MAXPATHLEN
]
,
ifname
[
IFNAMSIZ
],
strindex
[
MAXINDEXLEN
];
pid_t
*
pid
=
data
;
pid_t
*
pid
=
data
;
int
ifindex
,
ret
=
-
1
;
int
ifindex
,
ret
=
-
1
;
asprintf
(
&
path
,
"%s/%s"
,
dirname
,
file
);
snprintf
(
path
,
MAXPATHLEN
,
"%s/%s"
,
dirname
,
file
);
if
(
read_info
(
path
,
"ifindex"
,
strindex
,
MAXINDEXLEN
)
<
0
)
{
if
(
read_info
(
path
,
"ifindex"
,
strindex
,
MAXINDEXLEN
)
<
0
)
{
lxc_log_error
(
"failed to read index to from %s"
,
path
);
lxc_log_error
(
"failed to read index to from %s"
,
path
);
goto
out
;
goto
out
;
}
}
ifindex
=
atoi
(
strindex
);
ifindex
=
atoi
(
strindex
);
if
(
!
ifindex
)
return
0
;
if
(
!
if_indextoname
(
ifindex
,
ifname
))
{
if
(
!
if_indextoname
(
ifindex
,
ifname
))
{
lxc_log_error
(
"interface with index %d does not exist"
,
lxc_log_error
(
"interface with index %d does not exist"
,
ifindex
);
ifindex
);
goto
out
;
return
-
1
;
}
}
if
(
device_move
(
ifname
,
*
pid
))
{
if
(
device_move
(
ifname
,
*
pid
))
{
lxc_log_error
(
"failed to move %s to %d"
,
ifname
,
*
pid
);
lxc_log_error
(
"failed to move %s to %d"
,
ifname
,
*
pid
);
goto
out
;
return
-
1
;
}
}
ret
=
0
;
return
0
;
out:
free
(
path
);
return
ret
;
}
}
static
int
move_netdev
(
const
char
*
name
,
pid_t
pid
)
static
int
move_netdev
(
const
char
*
name
,
pid_t
pid
)
...
...
src/lxc/lxc_create.c
View file @
e14459fa
...
@@ -59,7 +59,7 @@ int main(int argc, char *argv[])
...
@@ -59,7 +59,7 @@ int main(int argc, char *argv[])
}
}
}
}
if
(
!
name
||
!
file
)
if
(
!
name
)
usage
(
argv
[
0
]);
usage
(
argv
[
0
]);
if
(
lxc_config_init
(
&
lxc_conf
))
{
if
(
lxc_config_init
(
&
lxc_conf
))
{
...
@@ -67,7 +67,7 @@ int main(int argc, char *argv[])
...
@@ -67,7 +67,7 @@ int main(int argc, char *argv[])
return
1
;
return
1
;
}
}
if
(
lxc_config_read
(
file
,
&
lxc_conf
))
{
if
(
file
&&
lxc_config_read
(
file
,
&
lxc_conf
))
{
fprintf
(
stderr
,
"invalid configuration file
\n
"
);
fprintf
(
stderr
,
"invalid configuration file
\n
"
);
return
1
;
return
1
;
}
}
...
...
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