mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-04-29 16:58:17 +00:00
Initial revision
This commit is contained in:
commit
5e97c3fcce
7
.cvsignore
Normal file
7
.cvsignore
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
Makefile
|
||||||
|
Makefile.in
|
||||||
|
configure
|
||||||
|
config.status
|
||||||
|
config.log
|
||||||
|
autom4te.cache
|
||||||
|
aclocal.m4
|
504
COPYING
Normal file
504
COPYING
Normal file
@ -0,0 +1,504 @@
|
|||||||
|
GNU LESSER GENERAL PUBLIC LICENSE
|
||||||
|
Version 2.1, February 1999
|
||||||
|
|
||||||
|
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
[This is the first released version of the Lesser GPL. It also counts
|
||||||
|
as the successor of the GNU Library Public License, version 2, hence
|
||||||
|
the version number 2.1.]
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The licenses for most software are designed to take away your
|
||||||
|
freedom to share and change it. By contrast, the GNU General Public
|
||||||
|
Licenses are intended to guarantee your freedom to share and change
|
||||||
|
free software--to make sure the software is free for all its users.
|
||||||
|
|
||||||
|
This license, the Lesser General Public License, applies to some
|
||||||
|
specially designated software packages--typically libraries--of the
|
||||||
|
Free Software Foundation and other authors who decide to use it. You
|
||||||
|
can use it too, but we suggest you first think carefully about whether
|
||||||
|
this license or the ordinary General Public License is the better
|
||||||
|
strategy to use in any particular case, based on the explanations below.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom of use,
|
||||||
|
not price. Our General Public Licenses are designed to make sure that
|
||||||
|
you have the freedom to distribute copies of free software (and charge
|
||||||
|
for this service if you wish); that you receive source code or can get
|
||||||
|
it if you want it; that you can change the software and use pieces of
|
||||||
|
it in new free programs; and that you are informed that you can do
|
||||||
|
these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to make restrictions that forbid
|
||||||
|
distributors to deny you these rights or to ask you to surrender these
|
||||||
|
rights. These restrictions translate to certain responsibilities for
|
||||||
|
you if you distribute copies of the library or if you modify it.
|
||||||
|
|
||||||
|
For example, if you distribute copies of the library, whether gratis
|
||||||
|
or for a fee, you must give the recipients all the rights that we gave
|
||||||
|
you. You must make sure that they, too, receive or can get the source
|
||||||
|
code. If you link other code with the library, you must provide
|
||||||
|
complete object files to the recipients, so that they can relink them
|
||||||
|
with the library after making changes to the library and recompiling
|
||||||
|
it. And you must show them these terms so they know their rights.
|
||||||
|
|
||||||
|
We protect your rights with a two-step method: (1) we copyright the
|
||||||
|
library, and (2) we offer you this license, which gives you legal
|
||||||
|
permission to copy, distribute and/or modify the library.
|
||||||
|
|
||||||
|
To protect each distributor, we want to make it very clear that
|
||||||
|
there is no warranty for the free library. Also, if the library is
|
||||||
|
modified by someone else and passed on, the recipients should know
|
||||||
|
that what they have is not the original version, so that the original
|
||||||
|
author's reputation will not be affected by problems that might be
|
||||||
|
introduced by others.
|
||||||
|
|
||||||
|
Finally, software patents pose a constant threat to the existence of
|
||||||
|
any free program. We wish to make sure that a company cannot
|
||||||
|
effectively restrict the users of a free program by obtaining a
|
||||||
|
restrictive license from a patent holder. Therefore, we insist that
|
||||||
|
any patent license obtained for a version of the library must be
|
||||||
|
consistent with the full freedom of use specified in this license.
|
||||||
|
|
||||||
|
Most GNU software, including some libraries, is covered by the
|
||||||
|
ordinary GNU General Public License. This license, the GNU Lesser
|
||||||
|
General Public License, applies to certain designated libraries, and
|
||||||
|
is quite different from the ordinary General Public License. We use
|
||||||
|
this license for certain libraries in order to permit linking those
|
||||||
|
libraries into non-free programs.
|
||||||
|
|
||||||
|
When a program is linked with a library, whether statically or using
|
||||||
|
a shared library, the combination of the two is legally speaking a
|
||||||
|
combined work, a derivative of the original library. The ordinary
|
||||||
|
General Public License therefore permits such linking only if the
|
||||||
|
entire combination fits its criteria of freedom. The Lesser General
|
||||||
|
Public License permits more lax criteria for linking other code with
|
||||||
|
the library.
|
||||||
|
|
||||||
|
We call this license the "Lesser" General Public License because it
|
||||||
|
does Less to protect the user's freedom than the ordinary General
|
||||||
|
Public License. It also provides other free software developers Less
|
||||||
|
of an advantage over competing non-free programs. These disadvantages
|
||||||
|
are the reason we use the ordinary General Public License for many
|
||||||
|
libraries. However, the Lesser license provides advantages in certain
|
||||||
|
special circumstances.
|
||||||
|
|
||||||
|
For example, on rare occasions, there may be a special need to
|
||||||
|
encourage the widest possible use of a certain library, so that it becomes
|
||||||
|
a de-facto standard. To achieve this, non-free programs must be
|
||||||
|
allowed to use the library. A more frequent case is that a free
|
||||||
|
library does the same job as widely used non-free libraries. In this
|
||||||
|
case, there is little to gain by limiting the free library to free
|
||||||
|
software only, so we use the Lesser General Public License.
|
||||||
|
|
||||||
|
In other cases, permission to use a particular library in non-free
|
||||||
|
programs enables a greater number of people to use a large body of
|
||||||
|
free software. For example, permission to use the GNU C Library in
|
||||||
|
non-free programs enables many more people to use the whole GNU
|
||||||
|
operating system, as well as its variant, the GNU/Linux operating
|
||||||
|
system.
|
||||||
|
|
||||||
|
Although the Lesser General Public License is Less protective of the
|
||||||
|
users' freedom, it does ensure that the user of a program that is
|
||||||
|
linked with the Library has the freedom and the wherewithal to run
|
||||||
|
that program using a modified version of the Library.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow. Pay close attention to the difference between a
|
||||||
|
"work based on the library" and a "work that uses the library". The
|
||||||
|
former contains code derived from the library, whereas the latter must
|
||||||
|
be combined with the library in order to run.
|
||||||
|
|
||||||
|
GNU LESSER GENERAL PUBLIC LICENSE
|
||||||
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
|
0. This License Agreement applies to any software library or other
|
||||||
|
program which contains a notice placed by the copyright holder or
|
||||||
|
other authorized party saying it may be distributed under the terms of
|
||||||
|
this Lesser General Public License (also called "this License").
|
||||||
|
Each licensee is addressed as "you".
|
||||||
|
|
||||||
|
A "library" means a collection of software functions and/or data
|
||||||
|
prepared so as to be conveniently linked with application programs
|
||||||
|
(which use some of those functions and data) to form executables.
|
||||||
|
|
||||||
|
The "Library", below, refers to any such software library or work
|
||||||
|
which has been distributed under these terms. A "work based on the
|
||||||
|
Library" means either the Library or any derivative work under
|
||||||
|
copyright law: that is to say, a work containing the Library or a
|
||||||
|
portion of it, either verbatim or with modifications and/or translated
|
||||||
|
straightforwardly into another language. (Hereinafter, translation is
|
||||||
|
included without limitation in the term "modification".)
|
||||||
|
|
||||||
|
"Source code" for a work means the preferred form of the work for
|
||||||
|
making modifications to it. For a library, complete source code means
|
||||||
|
all the source code for all modules it contains, plus any associated
|
||||||
|
interface definition files, plus the scripts used to control compilation
|
||||||
|
and installation of the library.
|
||||||
|
|
||||||
|
Activities other than copying, distribution and modification are not
|
||||||
|
covered by this License; they are outside its scope. The act of
|
||||||
|
running a program using the Library is not restricted, and output from
|
||||||
|
such a program is covered only if its contents constitute a work based
|
||||||
|
on the Library (independent of the use of the Library in a tool for
|
||||||
|
writing it). Whether that is true depends on what the Library does
|
||||||
|
and what the program that uses the Library does.
|
||||||
|
|
||||||
|
1. You may copy and distribute verbatim copies of the Library's
|
||||||
|
complete source code as you receive it, in any medium, provided that
|
||||||
|
you conspicuously and appropriately publish on each copy an
|
||||||
|
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||||
|
all the notices that refer to this License and to the absence of any
|
||||||
|
warranty; and distribute a copy of this License along with the
|
||||||
|
Library.
|
||||||
|
|
||||||
|
You may charge a fee for the physical act of transferring a copy,
|
||||||
|
and you may at your option offer warranty protection in exchange for a
|
||||||
|
fee.
|
||||||
|
|
||||||
|
2. You may modify your copy or copies of the Library or any portion
|
||||||
|
of it, thus forming a work based on the Library, and copy and
|
||||||
|
distribute such modifications or work under the terms of Section 1
|
||||||
|
above, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The modified work must itself be a software library.
|
||||||
|
|
||||||
|
b) You must cause the files modified to carry prominent notices
|
||||||
|
stating that you changed the files and the date of any change.
|
||||||
|
|
||||||
|
c) You must cause the whole of the work to be licensed at no
|
||||||
|
charge to all third parties under the terms of this License.
|
||||||
|
|
||||||
|
d) If a facility in the modified Library refers to a function or a
|
||||||
|
table of data to be supplied by an application program that uses
|
||||||
|
the facility, other than as an argument passed when the facility
|
||||||
|
is invoked, then you must make a good faith effort to ensure that,
|
||||||
|
in the event an application does not supply such function or
|
||||||
|
table, the facility still operates, and performs whatever part of
|
||||||
|
its purpose remains meaningful.
|
||||||
|
|
||||||
|
(For example, a function in a library to compute square roots has
|
||||||
|
a purpose that is entirely well-defined independent of the
|
||||||
|
application. Therefore, Subsection 2d requires that any
|
||||||
|
application-supplied function or table used by this function must
|
||||||
|
be optional: if the application does not supply it, the square
|
||||||
|
root function must still compute square roots.)
|
||||||
|
|
||||||
|
These requirements apply to the modified work as a whole. If
|
||||||
|
identifiable sections of that work are not derived from the Library,
|
||||||
|
and can be reasonably considered independent and separate works in
|
||||||
|
themselves, then this License, and its terms, do not apply to those
|
||||||
|
sections when you distribute them as separate works. But when you
|
||||||
|
distribute the same sections as part of a whole which is a work based
|
||||||
|
on the Library, the distribution of the whole must be on the terms of
|
||||||
|
this License, whose permissions for other licensees extend to the
|
||||||
|
entire whole, and thus to each and every part regardless of who wrote
|
||||||
|
it.
|
||||||
|
|
||||||
|
Thus, it is not the intent of this section to claim rights or contest
|
||||||
|
your rights to work written entirely by you; rather, the intent is to
|
||||||
|
exercise the right to control the distribution of derivative or
|
||||||
|
collective works based on the Library.
|
||||||
|
|
||||||
|
In addition, mere aggregation of another work not based on the Library
|
||||||
|
with the Library (or with a work based on the Library) on a volume of
|
||||||
|
a storage or distribution medium does not bring the other work under
|
||||||
|
the scope of this License.
|
||||||
|
|
||||||
|
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||||
|
License instead of this License to a given copy of the Library. To do
|
||||||
|
this, you must alter all the notices that refer to this License, so
|
||||||
|
that they refer to the ordinary GNU General Public License, version 2,
|
||||||
|
instead of to this License. (If a newer version than version 2 of the
|
||||||
|
ordinary GNU General Public License has appeared, then you can specify
|
||||||
|
that version instead if you wish.) Do not make any other change in
|
||||||
|
these notices.
|
||||||
|
|
||||||
|
Once this change is made in a given copy, it is irreversible for
|
||||||
|
that copy, so the ordinary GNU General Public License applies to all
|
||||||
|
subsequent copies and derivative works made from that copy.
|
||||||
|
|
||||||
|
This option is useful when you wish to copy part of the code of
|
||||||
|
the Library into a program that is not a library.
|
||||||
|
|
||||||
|
4. You may copy and distribute the Library (or a portion or
|
||||||
|
derivative of it, under Section 2) in object code or executable form
|
||||||
|
under the terms of Sections 1 and 2 above provided that you accompany
|
||||||
|
it with the complete corresponding machine-readable source code, which
|
||||||
|
must be distributed under the terms of Sections 1 and 2 above on a
|
||||||
|
medium customarily used for software interchange.
|
||||||
|
|
||||||
|
If distribution of object code is made by offering access to copy
|
||||||
|
from a designated place, then offering equivalent access to copy the
|
||||||
|
source code from the same place satisfies the requirement to
|
||||||
|
distribute the source code, even though third parties are not
|
||||||
|
compelled to copy the source along with the object code.
|
||||||
|
|
||||||
|
5. A program that contains no derivative of any portion of the
|
||||||
|
Library, but is designed to work with the Library by being compiled or
|
||||||
|
linked with it, is called a "work that uses the Library". Such a
|
||||||
|
work, in isolation, is not a derivative work of the Library, and
|
||||||
|
therefore falls outside the scope of this License.
|
||||||
|
|
||||||
|
However, linking a "work that uses the Library" with the Library
|
||||||
|
creates an executable that is a derivative of the Library (because it
|
||||||
|
contains portions of the Library), rather than a "work that uses the
|
||||||
|
library". The executable is therefore covered by this License.
|
||||||
|
Section 6 states terms for distribution of such executables.
|
||||||
|
|
||||||
|
When a "work that uses the Library" uses material from a header file
|
||||||
|
that is part of the Library, the object code for the work may be a
|
||||||
|
derivative work of the Library even though the source code is not.
|
||||||
|
Whether this is true is especially significant if the work can be
|
||||||
|
linked without the Library, or if the work is itself a library. The
|
||||||
|
threshold for this to be true is not precisely defined by law.
|
||||||
|
|
||||||
|
If such an object file uses only numerical parameters, data
|
||||||
|
structure layouts and accessors, and small macros and small inline
|
||||||
|
functions (ten lines or less in length), then the use of the object
|
||||||
|
file is unrestricted, regardless of whether it is legally a derivative
|
||||||
|
work. (Executables containing this object code plus portions of the
|
||||||
|
Library will still fall under Section 6.)
|
||||||
|
|
||||||
|
Otherwise, if the work is a derivative of the Library, you may
|
||||||
|
distribute the object code for the work under the terms of Section 6.
|
||||||
|
Any executables containing that work also fall under Section 6,
|
||||||
|
whether or not they are linked directly with the Library itself.
|
||||||
|
|
||||||
|
6. As an exception to the Sections above, you may also combine or
|
||||||
|
link a "work that uses the Library" with the Library to produce a
|
||||||
|
work containing portions of the Library, and distribute that work
|
||||||
|
under terms of your choice, provided that the terms permit
|
||||||
|
modification of the work for the customer's own use and reverse
|
||||||
|
engineering for debugging such modifications.
|
||||||
|
|
||||||
|
You must give prominent notice with each copy of the work that the
|
||||||
|
Library is used in it and that the Library and its use are covered by
|
||||||
|
this License. You must supply a copy of this License. If the work
|
||||||
|
during execution displays copyright notices, you must include the
|
||||||
|
copyright notice for the Library among them, as well as a reference
|
||||||
|
directing the user to the copy of this License. Also, you must do one
|
||||||
|
of these things:
|
||||||
|
|
||||||
|
a) Accompany the work with the complete corresponding
|
||||||
|
machine-readable source code for the Library including whatever
|
||||||
|
changes were used in the work (which must be distributed under
|
||||||
|
Sections 1 and 2 above); and, if the work is an executable linked
|
||||||
|
with the Library, with the complete machine-readable "work that
|
||||||
|
uses the Library", as object code and/or source code, so that the
|
||||||
|
user can modify the Library and then relink to produce a modified
|
||||||
|
executable containing the modified Library. (It is understood
|
||||||
|
that the user who changes the contents of definitions files in the
|
||||||
|
Library will not necessarily be able to recompile the application
|
||||||
|
to use the modified definitions.)
|
||||||
|
|
||||||
|
b) Use a suitable shared library mechanism for linking with the
|
||||||
|
Library. A suitable mechanism is one that (1) uses at run time a
|
||||||
|
copy of the library already present on the user's computer system,
|
||||||
|
rather than copying library functions into the executable, and (2)
|
||||||
|
will operate properly with a modified version of the library, if
|
||||||
|
the user installs one, as long as the modified version is
|
||||||
|
interface-compatible with the version that the work was made with.
|
||||||
|
|
||||||
|
c) Accompany the work with a written offer, valid for at
|
||||||
|
least three years, to give the same user the materials
|
||||||
|
specified in Subsection 6a, above, for a charge no more
|
||||||
|
than the cost of performing this distribution.
|
||||||
|
|
||||||
|
d) If distribution of the work is made by offering access to copy
|
||||||
|
from a designated place, offer equivalent access to copy the above
|
||||||
|
specified materials from the same place.
|
||||||
|
|
||||||
|
e) Verify that the user has already received a copy of these
|
||||||
|
materials or that you have already sent this user a copy.
|
||||||
|
|
||||||
|
For an executable, the required form of the "work that uses the
|
||||||
|
Library" must include any data and utility programs needed for
|
||||||
|
reproducing the executable from it. However, as a special exception,
|
||||||
|
the materials to be distributed need not include anything that is
|
||||||
|
normally distributed (in either source or binary form) with the major
|
||||||
|
components (compiler, kernel, and so on) of the operating system on
|
||||||
|
which the executable runs, unless that component itself accompanies
|
||||||
|
the executable.
|
||||||
|
|
||||||
|
It may happen that this requirement contradicts the license
|
||||||
|
restrictions of other proprietary libraries that do not normally
|
||||||
|
accompany the operating system. Such a contradiction means you cannot
|
||||||
|
use both them and the Library together in an executable that you
|
||||||
|
distribute.
|
||||||
|
|
||||||
|
7. You may place library facilities that are a work based on the
|
||||||
|
Library side-by-side in a single library together with other library
|
||||||
|
facilities not covered by this License, and distribute such a combined
|
||||||
|
library, provided that the separate distribution of the work based on
|
||||||
|
the Library and of the other library facilities is otherwise
|
||||||
|
permitted, and provided that you do these two things:
|
||||||
|
|
||||||
|
a) Accompany the combined library with a copy of the same work
|
||||||
|
based on the Library, uncombined with any other library
|
||||||
|
facilities. This must be distributed under the terms of the
|
||||||
|
Sections above.
|
||||||
|
|
||||||
|
b) Give prominent notice with the combined library of the fact
|
||||||
|
that part of it is a work based on the Library, and explaining
|
||||||
|
where to find the accompanying uncombined form of the same work.
|
||||||
|
|
||||||
|
8. You may not copy, modify, sublicense, link with, or distribute
|
||||||
|
the Library except as expressly provided under this License. Any
|
||||||
|
attempt otherwise to copy, modify, sublicense, link with, or
|
||||||
|
distribute the Library is void, and will automatically terminate your
|
||||||
|
rights under this License. However, parties who have received copies,
|
||||||
|
or rights, from you under this License will not have their licenses
|
||||||
|
terminated so long as such parties remain in full compliance.
|
||||||
|
|
||||||
|
9. You are not required to accept this License, since you have not
|
||||||
|
signed it. However, nothing else grants you permission to modify or
|
||||||
|
distribute the Library or its derivative works. These actions are
|
||||||
|
prohibited by law if you do not accept this License. Therefore, by
|
||||||
|
modifying or distributing the Library (or any work based on the
|
||||||
|
Library), you indicate your acceptance of this License to do so, and
|
||||||
|
all its terms and conditions for copying, distributing or modifying
|
||||||
|
the Library or works based on it.
|
||||||
|
|
||||||
|
10. Each time you redistribute the Library (or any work based on the
|
||||||
|
Library), the recipient automatically receives a license from the
|
||||||
|
original licensor to copy, distribute, link with or modify the Library
|
||||||
|
subject to these terms and conditions. You may not impose any further
|
||||||
|
restrictions on the recipients' exercise of the rights granted herein.
|
||||||
|
You are not responsible for enforcing compliance by third parties with
|
||||||
|
this License.
|
||||||
|
|
||||||
|
11. If, as a consequence of a court judgment or allegation of patent
|
||||||
|
infringement or for any other reason (not limited to patent issues),
|
||||||
|
conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot
|
||||||
|
distribute so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you
|
||||||
|
may not distribute the Library at all. For example, if a patent
|
||||||
|
license would not permit royalty-free redistribution of the Library by
|
||||||
|
all those who receive copies directly or indirectly through you, then
|
||||||
|
the only way you could satisfy both it and this License would be to
|
||||||
|
refrain entirely from distribution of the Library.
|
||||||
|
|
||||||
|
If any portion of this section is held invalid or unenforceable under any
|
||||||
|
particular circumstance, the balance of the section is intended to apply,
|
||||||
|
and the section as a whole is intended to apply in other circumstances.
|
||||||
|
|
||||||
|
It is not the purpose of this section to induce you to infringe any
|
||||||
|
patents or other property right claims or to contest validity of any
|
||||||
|
such claims; this section has the sole purpose of protecting the
|
||||||
|
integrity of the free software distribution system which is
|
||||||
|
implemented by public license practices. Many people have made
|
||||||
|
generous contributions to the wide range of software distributed
|
||||||
|
through that system in reliance on consistent application of that
|
||||||
|
system; it is up to the author/donor to decide if he or she is willing
|
||||||
|
to distribute software through any other system and a licensee cannot
|
||||||
|
impose that choice.
|
||||||
|
|
||||||
|
This section is intended to make thoroughly clear what is believed to
|
||||||
|
be a consequence of the rest of this License.
|
||||||
|
|
||||||
|
12. If the distribution and/or use of the Library is restricted in
|
||||||
|
certain countries either by patents or by copyrighted interfaces, the
|
||||||
|
original copyright holder who places the Library under this License may add
|
||||||
|
an explicit geographical distribution limitation excluding those countries,
|
||||||
|
so that distribution is permitted only in or among countries not thus
|
||||||
|
excluded. In such case, this License incorporates the limitation as if
|
||||||
|
written in the body of this License.
|
||||||
|
|
||||||
|
13. The Free Software Foundation may publish revised and/or new
|
||||||
|
versions of the Lesser General Public License from time to time.
|
||||||
|
Such new versions will be similar in spirit to the present version,
|
||||||
|
but may differ in detail to address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the Library
|
||||||
|
specifies a version number of this License which applies to it and
|
||||||
|
"any later version", you have the option of following the terms and
|
||||||
|
conditions either of that version or of any later version published by
|
||||||
|
the Free Software Foundation. If the Library does not specify a
|
||||||
|
license version number, you may choose any version ever published by
|
||||||
|
the Free Software Foundation.
|
||||||
|
|
||||||
|
14. If you wish to incorporate parts of the Library into other free
|
||||||
|
programs whose distribution conditions are incompatible with these,
|
||||||
|
write to the author to ask for permission. For software which is
|
||||||
|
copyrighted by the Free Software Foundation, write to the Free
|
||||||
|
Software Foundation; we sometimes make exceptions for this. Our
|
||||||
|
decision will be guided by the two goals of preserving the free status
|
||||||
|
of all derivatives of our free software and of promoting the sharing
|
||||||
|
and reuse of software generally.
|
||||||
|
|
||||||
|
NO WARRANTY
|
||||||
|
|
||||||
|
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||||
|
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||||
|
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||||
|
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||||
|
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||||
|
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||||
|
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||||
|
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||||
|
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||||
|
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||||
|
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||||
|
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||||
|
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||||
|
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||||
|
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||||
|
DAMAGES.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Libraries
|
||||||
|
|
||||||
|
If you develop a new library, and you want it to be of the greatest
|
||||||
|
possible use to the public, we recommend making it free software that
|
||||||
|
everyone can redistribute and change. You can do so by permitting
|
||||||
|
redistribution under these terms (or, alternatively, under the terms of the
|
||||||
|
ordinary General Public License).
|
||||||
|
|
||||||
|
To apply these terms, attach the following notices to the library. It is
|
||||||
|
safest to attach them to the start of each source file to most effectively
|
||||||
|
convey the exclusion of warranty; and each file should have at least the
|
||||||
|
"copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the library's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or your
|
||||||
|
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||||
|
necessary. Here is a sample; alter the names:
|
||||||
|
|
||||||
|
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||||
|
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||||
|
|
||||||
|
<signature of Ty Coon>, 1 April 1990
|
||||||
|
Ty Coon, President of Vice
|
||||||
|
|
||||||
|
That's all there is to it!
|
||||||
|
|
||||||
|
|
234
INSTALL
Normal file
234
INSTALL
Normal file
@ -0,0 +1,234 @@
|
|||||||
|
Installation Instructions
|
||||||
|
*************************
|
||||||
|
|
||||||
|
Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005,
|
||||||
|
2006 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
This file is free documentation; the Free Software Foundation gives
|
||||||
|
unlimited permission to copy, distribute and modify it.
|
||||||
|
|
||||||
|
Basic Installation
|
||||||
|
==================
|
||||||
|
|
||||||
|
Briefly, the shell commands `./configure; make; make install' should
|
||||||
|
configure, build, and install this package. The following
|
||||||
|
more-detailed instructions are generic; see the `README' file for
|
||||||
|
instructions specific to this package.
|
||||||
|
|
||||||
|
The `configure' shell script attempts to guess correct values for
|
||||||
|
various system-dependent variables used during compilation. It uses
|
||||||
|
those values to create a `Makefile' in each directory of the package.
|
||||||
|
It may also create one or more `.h' files containing system-dependent
|
||||||
|
definitions. Finally, it creates a shell script `config.status' that
|
||||||
|
you can run in the future to recreate the current configuration, and a
|
||||||
|
file `config.log' containing compiler output (useful mainly for
|
||||||
|
debugging `configure').
|
||||||
|
|
||||||
|
It can also use an optional file (typically called `config.cache'
|
||||||
|
and enabled with `--cache-file=config.cache' or simply `-C') that saves
|
||||||
|
the results of its tests to speed up reconfiguring. Caching is
|
||||||
|
disabled by default to prevent problems with accidental use of stale
|
||||||
|
cache files.
|
||||||
|
|
||||||
|
If you need to do unusual things to compile the package, please try
|
||||||
|
to figure out how `configure' could check whether to do them, and mail
|
||||||
|
diffs or instructions to the address given in the `README' so they can
|
||||||
|
be considered for the next release. If you are using the cache, and at
|
||||||
|
some point `config.cache' contains results you don't want to keep, you
|
||||||
|
may remove or edit it.
|
||||||
|
|
||||||
|
The file `configure.ac' (or `configure.in') is used to create
|
||||||
|
`configure' by a program called `autoconf'. You need `configure.ac' if
|
||||||
|
you want to change it or regenerate `configure' using a newer version
|
||||||
|
of `autoconf'.
|
||||||
|
|
||||||
|
The simplest way to compile this package is:
|
||||||
|
|
||||||
|
1. `cd' to the directory containing the package's source code and type
|
||||||
|
`./configure' to configure the package for your system.
|
||||||
|
|
||||||
|
Running `configure' might take a while. While running, it prints
|
||||||
|
some messages telling which features it is checking for.
|
||||||
|
|
||||||
|
2. Type `make' to compile the package.
|
||||||
|
|
||||||
|
3. Optionally, type `make check' to run any self-tests that come with
|
||||||
|
the package.
|
||||||
|
|
||||||
|
4. Type `make install' to install the programs and any data files and
|
||||||
|
documentation.
|
||||||
|
|
||||||
|
5. You can remove the program binaries and object files from the
|
||||||
|
source code directory by typing `make clean'. To also remove the
|
||||||
|
files that `configure' created (so you can compile the package for
|
||||||
|
a different kind of computer), type `make distclean'. There is
|
||||||
|
also a `make maintainer-clean' target, but that is intended mainly
|
||||||
|
for the package's developers. If you use it, you may have to get
|
||||||
|
all sorts of other programs in order to regenerate files that came
|
||||||
|
with the distribution.
|
||||||
|
|
||||||
|
Compilers and Options
|
||||||
|
=====================
|
||||||
|
|
||||||
|
Some systems require unusual options for compilation or linking that the
|
||||||
|
`configure' script does not know about. Run `./configure --help' for
|
||||||
|
details on some of the pertinent environment variables.
|
||||||
|
|
||||||
|
You can give `configure' initial values for configuration parameters
|
||||||
|
by setting variables in the command line or in the environment. Here
|
||||||
|
is an example:
|
||||||
|
|
||||||
|
./configure CC=c99 CFLAGS=-g LIBS=-lposix
|
||||||
|
|
||||||
|
*Note Defining Variables::, for more details.
|
||||||
|
|
||||||
|
Compiling For Multiple Architectures
|
||||||
|
====================================
|
||||||
|
|
||||||
|
You can compile the package for more than one kind of computer at the
|
||||||
|
same time, by placing the object files for each architecture in their
|
||||||
|
own directory. To do this, you can use GNU `make'. `cd' to the
|
||||||
|
directory where you want the object files and executables to go and run
|
||||||
|
the `configure' script. `configure' automatically checks for the
|
||||||
|
source code in the directory that `configure' is in and in `..'.
|
||||||
|
|
||||||
|
With a non-GNU `make', it is safer to compile the package for one
|
||||||
|
architecture at a time in the source code directory. After you have
|
||||||
|
installed the package for one architecture, use `make distclean' before
|
||||||
|
reconfiguring for another architecture.
|
||||||
|
|
||||||
|
Installation Names
|
||||||
|
==================
|
||||||
|
|
||||||
|
By default, `make install' installs the package's commands under
|
||||||
|
`/usr/local/bin', include files under `/usr/local/include', etc. You
|
||||||
|
can specify an installation prefix other than `/usr/local' by giving
|
||||||
|
`configure' the option `--prefix=PREFIX'.
|
||||||
|
|
||||||
|
You can specify separate installation prefixes for
|
||||||
|
architecture-specific files and architecture-independent files. If you
|
||||||
|
pass the option `--exec-prefix=PREFIX' to `configure', the package uses
|
||||||
|
PREFIX as the prefix for installing programs and libraries.
|
||||||
|
Documentation and other data files still use the regular prefix.
|
||||||
|
|
||||||
|
In addition, if you use an unusual directory layout you can give
|
||||||
|
options like `--bindir=DIR' to specify different values for particular
|
||||||
|
kinds of files. Run `configure --help' for a list of the directories
|
||||||
|
you can set and what kinds of files go in them.
|
||||||
|
|
||||||
|
If the package supports it, you can cause programs to be installed
|
||||||
|
with an extra prefix or suffix on their names by giving `configure' the
|
||||||
|
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
|
||||||
|
|
||||||
|
Optional Features
|
||||||
|
=================
|
||||||
|
|
||||||
|
Some packages pay attention to `--enable-FEATURE' options to
|
||||||
|
`configure', where FEATURE indicates an optional part of the package.
|
||||||
|
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
|
||||||
|
is something like `gnu-as' or `x' (for the X Window System). The
|
||||||
|
`README' should mention any `--enable-' and `--with-' options that the
|
||||||
|
package recognizes.
|
||||||
|
|
||||||
|
For packages that use the X Window System, `configure' can usually
|
||||||
|
find the X include and library files automatically, but if it doesn't,
|
||||||
|
you can use the `configure' options `--x-includes=DIR' and
|
||||||
|
`--x-libraries=DIR' to specify their locations.
|
||||||
|
|
||||||
|
Specifying the System Type
|
||||||
|
==========================
|
||||||
|
|
||||||
|
There may be some features `configure' cannot figure out automatically,
|
||||||
|
but needs to determine by the type of machine the package will run on.
|
||||||
|
Usually, assuming the package is built to be run on the _same_
|
||||||
|
architectures, `configure' can figure that out, but if it prints a
|
||||||
|
message saying it cannot guess the machine type, give it the
|
||||||
|
`--build=TYPE' option. TYPE can either be a short name for the system
|
||||||
|
type, such as `sun4', or a canonical name which has the form:
|
||||||
|
|
||||||
|
CPU-COMPANY-SYSTEM
|
||||||
|
|
||||||
|
where SYSTEM can have one of these forms:
|
||||||
|
|
||||||
|
OS KERNEL-OS
|
||||||
|
|
||||||
|
See the file `config.sub' for the possible values of each field. If
|
||||||
|
`config.sub' isn't included in this package, then this package doesn't
|
||||||
|
need to know the machine type.
|
||||||
|
|
||||||
|
If you are _building_ compiler tools for cross-compiling, you should
|
||||||
|
use the option `--target=TYPE' to select the type of system they will
|
||||||
|
produce code for.
|
||||||
|
|
||||||
|
If you want to _use_ a cross compiler, that generates code for a
|
||||||
|
platform different from the build platform, you should specify the
|
||||||
|
"host" platform (i.e., that on which the generated programs will
|
||||||
|
eventually be run) with `--host=TYPE'.
|
||||||
|
|
||||||
|
Sharing Defaults
|
||||||
|
================
|
||||||
|
|
||||||
|
If you want to set default values for `configure' scripts to share, you
|
||||||
|
can create a site shell script called `config.site' that gives default
|
||||||
|
values for variables like `CC', `cache_file', and `prefix'.
|
||||||
|
`configure' looks for `PREFIX/share/config.site' if it exists, then
|
||||||
|
`PREFIX/etc/config.site' if it exists. Or, you can set the
|
||||||
|
`CONFIG_SITE' environment variable to the location of the site script.
|
||||||
|
A warning: not all `configure' scripts look for a site script.
|
||||||
|
|
||||||
|
Defining Variables
|
||||||
|
==================
|
||||||
|
|
||||||
|
Variables not defined in a site shell script can be set in the
|
||||||
|
environment passed to `configure'. However, some packages may run
|
||||||
|
configure again during the build, and the customized values of these
|
||||||
|
variables may be lost. In order to avoid this problem, you should set
|
||||||
|
them in the `configure' command line, using `VAR=value'. For example:
|
||||||
|
|
||||||
|
./configure CC=/usr/local2/bin/gcc
|
||||||
|
|
||||||
|
causes the specified `gcc' to be used as the C compiler (unless it is
|
||||||
|
overridden in the site shell script).
|
||||||
|
|
||||||
|
Unfortunately, this technique does not work for `CONFIG_SHELL' due to
|
||||||
|
an Autoconf bug. Until the bug is fixed you can use this workaround:
|
||||||
|
|
||||||
|
CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash
|
||||||
|
|
||||||
|
`configure' Invocation
|
||||||
|
======================
|
||||||
|
|
||||||
|
`configure' recognizes the following options to control how it operates.
|
||||||
|
|
||||||
|
`--help'
|
||||||
|
`-h'
|
||||||
|
Print a summary of the options to `configure', and exit.
|
||||||
|
|
||||||
|
`--version'
|
||||||
|
`-V'
|
||||||
|
Print the version of Autoconf used to generate the `configure'
|
||||||
|
script, and exit.
|
||||||
|
|
||||||
|
`--cache-file=FILE'
|
||||||
|
Enable the cache: use and save the results of the tests in FILE,
|
||||||
|
traditionally `config.cache'. FILE defaults to `/dev/null' to
|
||||||
|
disable caching.
|
||||||
|
|
||||||
|
`--config-cache'
|
||||||
|
`-C'
|
||||||
|
Alias for `--cache-file=config.cache'.
|
||||||
|
|
||||||
|
`--quiet'
|
||||||
|
`--silent'
|
||||||
|
`-q'
|
||||||
|
Do not print messages saying which checks are being made. To
|
||||||
|
suppress all normal output, redirect it to `/dev/null' (any error
|
||||||
|
messages will still be shown).
|
||||||
|
|
||||||
|
`--srcdir=DIR'
|
||||||
|
Look for the package's source code in directory DIR. Usually
|
||||||
|
`configure' can determine that directory automatically.
|
||||||
|
|
||||||
|
`configure' also accepts some other, not widely useful, options. Run
|
||||||
|
`configure --help' for more details.
|
||||||
|
|
8
Makefile.am
Normal file
8
Makefile.am
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Makefile.am
|
||||||
|
|
||||||
|
SUBDIRS = src test etc
|
||||||
|
DIST_SUBDIRS = config src test etc
|
||||||
|
EXTRA_DIST = lxc.spec
|
||||||
|
|
||||||
|
rpm: dist
|
||||||
|
rpmbuild --clean -ta ${distdir}.tar.gz
|
275
README
Normal file
275
README
Normal file
@ -0,0 +1,275 @@
|
|||||||
|
|
||||||
|
Linux Container - LXC:
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
This document provides a quick help to use the linux container.
|
||||||
|
|
||||||
|
Change log:
|
||||||
|
-----------
|
||||||
|
|
||||||
|
version 0.1.0 : initial document, Daniel Lezcano <dlezcano@fr.ibm.com>, Aug 01, 2008
|
||||||
|
|
||||||
|
Contents:
|
||||||
|
---------
|
||||||
|
0) Quick start
|
||||||
|
1) Overview
|
||||||
|
2) Requirements
|
||||||
|
3) Functional Specification
|
||||||
|
4) Future work
|
||||||
|
|
||||||
|
|
||||||
|
0) Quick start
|
||||||
|
--------------
|
||||||
|
|
||||||
|
You are in a hurry, and you don't want to read this README. Ok,
|
||||||
|
without warranty, here are the commands to launch a shell inside a
|
||||||
|
container with a predefined configuration template, it may work.
|
||||||
|
|
||||||
|
lxc-create -n foo -f /etc/lxc/lxc-macvlan.conf
|
||||||
|
|
||||||
|
lxc-execute -n foo /bin/bash
|
||||||
|
|
||||||
|
When your bash exits, you don't have to create 'foo' again, just call
|
||||||
|
lxc-execute again.
|
||||||
|
|
||||||
|
1) Overview
|
||||||
|
-----------
|
||||||
|
|
||||||
|
The container technology is actively being pushed into the mainstream
|
||||||
|
linux kernel. It provides the resource management through the control
|
||||||
|
groups aka process containers and resource isolation through the
|
||||||
|
namespaces.
|
||||||
|
|
||||||
|
The LXC aims to use these new functionnalities to provide an userspace
|
||||||
|
container object which provides full resource isolation and resource
|
||||||
|
control for an applications or a system.
|
||||||
|
|
||||||
|
The first objective of this project is to make the life easier for the
|
||||||
|
kernel developpers involved in the containers project and especially
|
||||||
|
to continue working on the Checkpoint/Restart new features. The LXC is
|
||||||
|
small enough to easily manage a container with simple command lines
|
||||||
|
and complete enough to be used for other purposes.
|
||||||
|
|
||||||
|
2) Requirements
|
||||||
|
---------------
|
||||||
|
|
||||||
|
The LXC relies on a set of functionnalies provided by the kernel which
|
||||||
|
needs to be active. Depending of the missing functionnality the LXC
|
||||||
|
will work with a restricted number of functionnality or will simply
|
||||||
|
fails.
|
||||||
|
|
||||||
|
This is the list of the kernel features which needs to be compiled in:
|
||||||
|
|
||||||
|
* General
|
||||||
|
* Control Group support
|
||||||
|
-> namespace cgroup subsystem
|
||||||
|
-> cpuset support
|
||||||
|
-> Group CPU scheduler
|
||||||
|
-> control group freeze subsystem
|
||||||
|
-> Basis for grouping tasks (Control Groups)
|
||||||
|
-> Simple CPU accounting
|
||||||
|
-> Resource counters
|
||||||
|
-> Memory resource controllers for Control Groups
|
||||||
|
-> Namespace support
|
||||||
|
-> UTS namespace
|
||||||
|
-> IPC namespace
|
||||||
|
-> User namespace
|
||||||
|
-> Pid namespace
|
||||||
|
* Network support
|
||||||
|
-> Networking options
|
||||||
|
-> Network namespace support
|
||||||
|
|
||||||
|
For the moment the easiest way to have all the features in the kernel
|
||||||
|
is to use the git tree at:
|
||||||
|
|
||||||
|
git://git.kernel.org/pub/scm/linux/kernel/git/daveh/linux-2.6-lxc.git
|
||||||
|
|
||||||
|
Otherwise the latest version of 2.6.26 kernel is usable with LXC but
|
||||||
|
without sysfs if the network namespace is activated and without the
|
||||||
|
freezer subsystem.
|
||||||
|
|
||||||
|
Before using LXC, the system should be configured as followed:
|
||||||
|
|
||||||
|
* Control group file system must be mounted
|
||||||
|
|
||||||
|
mount -t cgroup cgroup /cgroup
|
||||||
|
|
||||||
|
* You must have root privileges
|
||||||
|
|
||||||
|
3) Functional Specification
|
||||||
|
---------------------------
|
||||||
|
|
||||||
|
A container is an object where the configuration is persistent. The
|
||||||
|
application will be launched inside this container and it will
|
||||||
|
use the configuration which was previously created.
|
||||||
|
|
||||||
|
3.1 Container life cycle
|
||||||
|
------------------------
|
||||||
|
|
||||||
|
When the container is created, it contains the configuration
|
||||||
|
information. When a process is launched, the container will be
|
||||||
|
starting and running. When the last process running inside the
|
||||||
|
container exits, the container is stopped.
|
||||||
|
|
||||||
|
In case of failure when the container is initialized, it will pass
|
||||||
|
through the aborting state.
|
||||||
|
|
||||||
|
---------
|
||||||
|
| STOPPED |<---------------
|
||||||
|
--------- |
|
||||||
|
| |
|
||||||
|
start |
|
||||||
|
| |
|
||||||
|
V |
|
||||||
|
---------- |
|
||||||
|
| STARTING |--error- |
|
||||||
|
---------- | |
|
||||||
|
| | |
|
||||||
|
V V |
|
||||||
|
--------- ---------- |
|
||||||
|
| RUNNING | | ABORTING | |
|
||||||
|
--------- ---------- |
|
||||||
|
| | |
|
||||||
|
no process | |
|
||||||
|
| | |
|
||||||
|
V | |
|
||||||
|
---------- | |
|
||||||
|
| STOPPING |<------- |
|
||||||
|
---------- |
|
||||||
|
| |
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
3.2 Configuration file
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
The configuration file has the following format:
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# the fstab mount file.
|
||||||
|
lxc.mount = ./fstab
|
||||||
|
|
||||||
|
# the hostname to be set into the container
|
||||||
|
lxc.utsname = virtnode
|
||||||
|
|
||||||
|
# the chroot if needed for the running application
|
||||||
|
lxc.chroot = /mnt/root
|
||||||
|
|
||||||
|
# The network has several of kind of configuration:
|
||||||
|
#
|
||||||
|
# * veth : the network will use the veth virtual device, the
|
||||||
|
# specified link must be a bridge
|
||||||
|
# * macvlan : the network will use the macvlan device, the specified
|
||||||
|
# link should be an existing interface, usually it is
|
||||||
|
# eth0
|
||||||
|
# * phys : the network will use a physical network device, the
|
||||||
|
# specified link should be an existing interface
|
||||||
|
lxc.network.type = macvlan
|
||||||
|
|
||||||
|
# specify the flags to be used for the network, actually only <up> is
|
||||||
|
# allowed which mean the network should be set up when created. If the
|
||||||
|
# network is set up, the loopback is automatically set up too.
|
||||||
|
lxc.network.flags = up
|
||||||
|
|
||||||
|
# specify the physical network device which will communicate with the
|
||||||
|
# outside world
|
||||||
|
lxc.network.link = eth0
|
||||||
|
|
||||||
|
# NIC ethernet mac address
|
||||||
|
lxc.network.hwaddr = 4a:49:43:49:79:bd
|
||||||
|
|
||||||
|
# specify the ipv4 address of the container. Several lines are allowed
|
||||||
|
# and will mean several addresses will be assigned to the interface
|
||||||
|
lxc.network.ipv4 = 1.2.3.5/24
|
||||||
|
|
||||||
|
# specify the ipv6 address of the container. Several lines are allowed
|
||||||
|
# and will mean several addresses will be assigned to the interface
|
||||||
|
lxc.network.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
* lxc.mount is optional
|
||||||
|
* lxc.utsname is optional
|
||||||
|
* lxc.network.xxx are optional, if not specified, the network
|
||||||
|
namespace will not be created
|
||||||
|
* lxc.chroot is optional
|
||||||
|
|
||||||
|
3.3 Container creation
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
The container is created via the 'lxc-create' command. The command
|
||||||
|
specifies the container name and the container configuration file.
|
||||||
|
|
||||||
|
lxc-create -n foo -f <config>
|
||||||
|
|
||||||
|
|
||||||
|
3.4 Starting a container
|
||||||
|
------------------------
|
||||||
|
|
||||||
|
As the container has been create with the lxc-create command, it is
|
||||||
|
possible now to start an application inside.
|
||||||
|
|
||||||
|
lxc-execute -n foo /bin/bash
|
||||||
|
|
||||||
|
When the application has exited, it is possible to continue using the
|
||||||
|
container configuration to launch another application.
|
||||||
|
|
||||||
|
3.5 Stopping a container
|
||||||
|
------------------------
|
||||||
|
|
||||||
|
Usually, a container stops when the last process exits but in some
|
||||||
|
cases, it is usefully to wipe out such application. The following
|
||||||
|
command will kill the processes.
|
||||||
|
|
||||||
|
lxc-stop -n foo
|
||||||
|
|
||||||
|
3.6 Freezing/Unfreezing a container
|
||||||
|
-----------------------------------
|
||||||
|
|
||||||
|
All the processes belonging to a container can be stopped and resumed.
|
||||||
|
|
||||||
|
lxc-freeze -n foo
|
||||||
|
|
||||||
|
lxc-unfreeze -n foo
|
||||||
|
|
||||||
|
3.7 Sending a signal to a container
|
||||||
|
-----------------------------------
|
||||||
|
|
||||||
|
A signal can be sent to all processes running inside the container.
|
||||||
|
|
||||||
|
lxc-kill -n foo -s <signal>
|
||||||
|
|
||||||
|
3.8 Monitoring container states
|
||||||
|
-------------------------------
|
||||||
|
|
||||||
|
A container has a life cycle and pass though different states as
|
||||||
|
defined in section 3.1. The following command allows to watch such
|
||||||
|
states for a specific container.
|
||||||
|
|
||||||
|
lxc-monitor -n foo
|
||||||
|
|
||||||
|
3.9 Getting the container state
|
||||||
|
-------------------------------
|
||||||
|
|
||||||
|
At any time, the following command will retrieve the state of the
|
||||||
|
container.
|
||||||
|
|
||||||
|
lxc-state -n foo
|
||||||
|
|
||||||
|
3.10 Showing processes list for a container
|
||||||
|
------------------------------------------
|
||||||
|
|
||||||
|
The following command will show all the processes for all the running
|
||||||
|
container.
|
||||||
|
|
||||||
|
lxc-ps
|
||||||
|
|
||||||
|
4) Future work
|
||||||
|
--------------
|
||||||
|
|
||||||
|
* change the lxc-start command to support system container
|
||||||
|
* change the lxc-execute to have the first process to exec
|
||||||
|
* take into account all the resource management
|
||||||
|
* man pages
|
||||||
|
* improve monitoring support
|
||||||
|
* and more :)
|
0
RELEASE-NOTES
Normal file
0
RELEASE-NOTES
Normal file
11
bootstrap
Executable file
11
bootstrap
Executable file
@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -x
|
||||||
|
|
||||||
|
test -d autom4te.cache && rm -rf autom4te.cache
|
||||||
|
|
||||||
|
ACLOCAL_AMFLAGS="-I config $ACLOCAL_AMFLAGS"
|
||||||
|
aclocal $ACLOCAL_AMFLAGS || exit 1
|
||||||
|
autoheader || exit 1
|
||||||
|
autoconf || exit 1
|
||||||
|
automake --add-missing --copy || exit 1
|
2
config/.cvsignore
Normal file
2
config/.cvsignore
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Makefile
|
||||||
|
Makefile.in
|
0
config/Makefile.am
Normal file
0
config/Makefile.am
Normal file
1500
config/config.guess
vendored
Executable file
1500
config/config.guess
vendored
Executable file
File diff suppressed because it is too large
Load Diff
1616
config/config.sub
vendored
Executable file
1616
config/config.sub
vendored
Executable file
File diff suppressed because it is too large
Load Diff
584
config/depcomp
Executable file
584
config/depcomp
Executable file
@ -0,0 +1,584 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
# depcomp - compile a program generating dependencies as side-effects
|
||||||
|
|
||||||
|
scriptversion=2006-10-15.18
|
||||||
|
|
||||||
|
# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006 Free Software
|
||||||
|
# Foundation, Inc.
|
||||||
|
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2, or (at your option)
|
||||||
|
# any later version.
|
||||||
|
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
# 02110-1301, USA.
|
||||||
|
|
||||||
|
# As a special exception to the GNU General Public License, if you
|
||||||
|
# distribute this file as part of a program that contains a
|
||||||
|
# configuration script generated by Autoconf, you may include it under
|
||||||
|
# the same distribution terms that you use for the rest of that program.
|
||||||
|
|
||||||
|
# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
'')
|
||||||
|
echo "$0: No command. Try \`$0 --help' for more information." 1>&2
|
||||||
|
exit 1;
|
||||||
|
;;
|
||||||
|
-h | --h*)
|
||||||
|
cat <<\EOF
|
||||||
|
Usage: depcomp [--help] [--version] PROGRAM [ARGS]
|
||||||
|
|
||||||
|
Run PROGRAMS ARGS to compile a file, generating dependencies
|
||||||
|
as side-effects.
|
||||||
|
|
||||||
|
Environment variables:
|
||||||
|
depmode Dependency tracking mode.
|
||||||
|
source Source file read by `PROGRAMS ARGS'.
|
||||||
|
object Object file output by `PROGRAMS ARGS'.
|
||||||
|
DEPDIR directory where to store dependencies.
|
||||||
|
depfile Dependency file to output.
|
||||||
|
tmpdepfile Temporary file to use when outputing dependencies.
|
||||||
|
libtool Whether libtool is used (yes/no).
|
||||||
|
|
||||||
|
Report bugs to <bug-automake@gnu.org>.
|
||||||
|
EOF
|
||||||
|
exit $?
|
||||||
|
;;
|
||||||
|
-v | --v*)
|
||||||
|
echo "depcomp $scriptversion"
|
||||||
|
exit $?
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if test -z "$depmode" || test -z "$source" || test -z "$object"; then
|
||||||
|
echo "depcomp: Variables source, object and depmode must be set" 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
|
||||||
|
depfile=${depfile-`echo "$object" |
|
||||||
|
sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
|
||||||
|
tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
|
||||||
|
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
|
||||||
|
# Some modes work just like other modes, but use different flags. We
|
||||||
|
# parameterize here, but still list the modes in the big case below,
|
||||||
|
# to make depend.m4 easier to write. Note that we *cannot* use a case
|
||||||
|
# here, because this file can only contain one case statement.
|
||||||
|
if test "$depmode" = hp; then
|
||||||
|
# HP compiler uses -M and no extra arg.
|
||||||
|
gccflag=-M
|
||||||
|
depmode=gcc
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test "$depmode" = dashXmstdout; then
|
||||||
|
# This is just like dashmstdout with a different argument.
|
||||||
|
dashmflag=-xM
|
||||||
|
depmode=dashmstdout
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$depmode" in
|
||||||
|
gcc3)
|
||||||
|
## gcc 3 implements dependency tracking that does exactly what
|
||||||
|
## we want. Yay! Note: for some reason libtool 1.4 doesn't like
|
||||||
|
## it if -MD -MP comes after the -MF stuff. Hmm.
|
||||||
|
## Unfortunately, FreeBSD c89 acceptance of flags depends upon
|
||||||
|
## the command line argument order; so add the flags where they
|
||||||
|
## appear in depend2.am. Note that the slowdown incurred here
|
||||||
|
## affects only configure: in makefiles, %FASTDEP% shortcuts this.
|
||||||
|
for arg
|
||||||
|
do
|
||||||
|
case $arg in
|
||||||
|
-c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
|
||||||
|
*) set fnord "$@" "$arg" ;;
|
||||||
|
esac
|
||||||
|
shift # fnord
|
||||||
|
shift # $arg
|
||||||
|
done
|
||||||
|
"$@"
|
||||||
|
stat=$?
|
||||||
|
if test $stat -eq 0; then :
|
||||||
|
else
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
exit $stat
|
||||||
|
fi
|
||||||
|
mv "$tmpdepfile" "$depfile"
|
||||||
|
;;
|
||||||
|
|
||||||
|
gcc)
|
||||||
|
## There are various ways to get dependency output from gcc. Here's
|
||||||
|
## why we pick this rather obscure method:
|
||||||
|
## - Don't want to use -MD because we'd like the dependencies to end
|
||||||
|
## up in a subdir. Having to rename by hand is ugly.
|
||||||
|
## (We might end up doing this anyway to support other compilers.)
|
||||||
|
## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
|
||||||
|
## -MM, not -M (despite what the docs say).
|
||||||
|
## - Using -M directly means running the compiler twice (even worse
|
||||||
|
## than renaming).
|
||||||
|
if test -z "$gccflag"; then
|
||||||
|
gccflag=-MD,
|
||||||
|
fi
|
||||||
|
"$@" -Wp,"$gccflag$tmpdepfile"
|
||||||
|
stat=$?
|
||||||
|
if test $stat -eq 0; then :
|
||||||
|
else
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
exit $stat
|
||||||
|
fi
|
||||||
|
rm -f "$depfile"
|
||||||
|
echo "$object : \\" > "$depfile"
|
||||||
|
alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
|
||||||
|
## The second -e expression handles DOS-style file names with drive letters.
|
||||||
|
sed -e 's/^[^:]*: / /' \
|
||||||
|
-e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
|
||||||
|
## This next piece of magic avoids the `deleted header file' problem.
|
||||||
|
## The problem is that when a header file which appears in a .P file
|
||||||
|
## is deleted, the dependency causes make to die (because there is
|
||||||
|
## typically no way to rebuild the header). We avoid this by adding
|
||||||
|
## dummy dependencies for each header file. Too bad gcc doesn't do
|
||||||
|
## this for us directly.
|
||||||
|
tr ' ' '
|
||||||
|
' < "$tmpdepfile" |
|
||||||
|
## Some versions of gcc put a space before the `:'. On the theory
|
||||||
|
## that the space means something, we add a space to the output as
|
||||||
|
## well.
|
||||||
|
## Some versions of the HPUX 10.20 sed can't process this invocation
|
||||||
|
## correctly. Breaking it into two sed invocations is a workaround.
|
||||||
|
sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
;;
|
||||||
|
|
||||||
|
hp)
|
||||||
|
# This case exists only to let depend.m4 do its work. It works by
|
||||||
|
# looking at the text of this script. This case will never be run,
|
||||||
|
# since it is checked for above.
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
|
||||||
|
sgi)
|
||||||
|
if test "$libtool" = yes; then
|
||||||
|
"$@" "-Wp,-MDupdate,$tmpdepfile"
|
||||||
|
else
|
||||||
|
"$@" -MDupdate "$tmpdepfile"
|
||||||
|
fi
|
||||||
|
stat=$?
|
||||||
|
if test $stat -eq 0; then :
|
||||||
|
else
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
exit $stat
|
||||||
|
fi
|
||||||
|
rm -f "$depfile"
|
||||||
|
|
||||||
|
if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
|
||||||
|
echo "$object : \\" > "$depfile"
|
||||||
|
|
||||||
|
# Clip off the initial element (the dependent). Don't try to be
|
||||||
|
# clever and replace this with sed code, as IRIX sed won't handle
|
||||||
|
# lines with more than a fixed number of characters (4096 in
|
||||||
|
# IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
|
||||||
|
# the IRIX cc adds comments like `#:fec' to the end of the
|
||||||
|
# dependency line.
|
||||||
|
tr ' ' '
|
||||||
|
' < "$tmpdepfile" \
|
||||||
|
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
|
||||||
|
tr '
|
||||||
|
' ' ' >> $depfile
|
||||||
|
echo >> $depfile
|
||||||
|
|
||||||
|
# The second pass generates a dummy entry for each header file.
|
||||||
|
tr ' ' '
|
||||||
|
' < "$tmpdepfile" \
|
||||||
|
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
|
||||||
|
>> $depfile
|
||||||
|
else
|
||||||
|
# The sourcefile does not contain any dependencies, so just
|
||||||
|
# store a dummy comment line, to avoid errors with the Makefile
|
||||||
|
# "include basename.Plo" scheme.
|
||||||
|
echo "#dummy" > "$depfile"
|
||||||
|
fi
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
;;
|
||||||
|
|
||||||
|
aix)
|
||||||
|
# The C for AIX Compiler uses -M and outputs the dependencies
|
||||||
|
# in a .u file. In older versions, this file always lives in the
|
||||||
|
# current directory. Also, the AIX compiler puts `$object:' at the
|
||||||
|
# start of each line; $object doesn't have directory information.
|
||||||
|
# Version 6 uses the directory in both cases.
|
||||||
|
stripped=`echo "$object" | sed 's/\(.*\)\..*$/\1/'`
|
||||||
|
tmpdepfile="$stripped.u"
|
||||||
|
if test "$libtool" = yes; then
|
||||||
|
"$@" -Wc,-M
|
||||||
|
else
|
||||||
|
"$@" -M
|
||||||
|
fi
|
||||||
|
stat=$?
|
||||||
|
|
||||||
|
if test -f "$tmpdepfile"; then :
|
||||||
|
else
|
||||||
|
stripped=`echo "$stripped" | sed 's,^.*/,,'`
|
||||||
|
tmpdepfile="$stripped.u"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test $stat -eq 0; then :
|
||||||
|
else
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
exit $stat
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test -f "$tmpdepfile"; then
|
||||||
|
outname="$stripped.o"
|
||||||
|
# Each line is of the form `foo.o: dependent.h'.
|
||||||
|
# Do two passes, one to just change these to
|
||||||
|
# `$object: dependent.h' and one to simply `dependent.h:'.
|
||||||
|
sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
|
||||||
|
sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
|
||||||
|
else
|
||||||
|
# The sourcefile does not contain any dependencies, so just
|
||||||
|
# store a dummy comment line, to avoid errors with the Makefile
|
||||||
|
# "include basename.Plo" scheme.
|
||||||
|
echo "#dummy" > "$depfile"
|
||||||
|
fi
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
;;
|
||||||
|
|
||||||
|
icc)
|
||||||
|
# Intel's C compiler understands `-MD -MF file'. However on
|
||||||
|
# icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
|
||||||
|
# ICC 7.0 will fill foo.d with something like
|
||||||
|
# foo.o: sub/foo.c
|
||||||
|
# foo.o: sub/foo.h
|
||||||
|
# which is wrong. We want:
|
||||||
|
# sub/foo.o: sub/foo.c
|
||||||
|
# sub/foo.o: sub/foo.h
|
||||||
|
# sub/foo.c:
|
||||||
|
# sub/foo.h:
|
||||||
|
# ICC 7.1 will output
|
||||||
|
# foo.o: sub/foo.c sub/foo.h
|
||||||
|
# and will wrap long lines using \ :
|
||||||
|
# foo.o: sub/foo.c ... \
|
||||||
|
# sub/foo.h ... \
|
||||||
|
# ...
|
||||||
|
|
||||||
|
"$@" -MD -MF "$tmpdepfile"
|
||||||
|
stat=$?
|
||||||
|
if test $stat -eq 0; then :
|
||||||
|
else
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
exit $stat
|
||||||
|
fi
|
||||||
|
rm -f "$depfile"
|
||||||
|
# Each line is of the form `foo.o: dependent.h',
|
||||||
|
# or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
|
||||||
|
# Do two passes, one to just change these to
|
||||||
|
# `$object: dependent.h' and one to simply `dependent.h:'.
|
||||||
|
sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
|
||||||
|
# Some versions of the HPUX 10.20 sed can't process this invocation
|
||||||
|
# correctly. Breaking it into two sed invocations is a workaround.
|
||||||
|
sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
|
||||||
|
sed -e 's/$/ :/' >> "$depfile"
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
;;
|
||||||
|
|
||||||
|
hp2)
|
||||||
|
# The "hp" stanza above does not work with aCC (C++) and HP's ia64
|
||||||
|
# compilers, which have integrated preprocessors. The correct option
|
||||||
|
# to use with these is +Maked; it writes dependencies to a file named
|
||||||
|
# 'foo.d', which lands next to the object file, wherever that
|
||||||
|
# happens to be.
|
||||||
|
# Much of this is similar to the tru64 case; see comments there.
|
||||||
|
dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
|
||||||
|
test "x$dir" = "x$object" && dir=
|
||||||
|
base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
|
||||||
|
if test "$libtool" = yes; then
|
||||||
|
tmpdepfile1=$dir$base.d
|
||||||
|
tmpdepfile2=$dir.libs/$base.d
|
||||||
|
"$@" -Wc,+Maked
|
||||||
|
else
|
||||||
|
tmpdepfile1=$dir$base.d
|
||||||
|
tmpdepfile2=$dir$base.d
|
||||||
|
"$@" +Maked
|
||||||
|
fi
|
||||||
|
stat=$?
|
||||||
|
if test $stat -eq 0; then :
|
||||||
|
else
|
||||||
|
rm -f "$tmpdepfile1" "$tmpdepfile2"
|
||||||
|
exit $stat
|
||||||
|
fi
|
||||||
|
|
||||||
|
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
|
||||||
|
do
|
||||||
|
test -f "$tmpdepfile" && break
|
||||||
|
done
|
||||||
|
if test -f "$tmpdepfile"; then
|
||||||
|
sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
|
||||||
|
# Add `dependent.h:' lines.
|
||||||
|
sed -ne '2,${; s/^ *//; s/ \\*$//; s/$/:/; p;}' "$tmpdepfile" >> "$depfile"
|
||||||
|
else
|
||||||
|
echo "#dummy" > "$depfile"
|
||||||
|
fi
|
||||||
|
rm -f "$tmpdepfile" "$tmpdepfile2"
|
||||||
|
;;
|
||||||
|
|
||||||
|
tru64)
|
||||||
|
# The Tru64 compiler uses -MD to generate dependencies as a side
|
||||||
|
# effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
|
||||||
|
# At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
|
||||||
|
# dependencies in `foo.d' instead, so we check for that too.
|
||||||
|
# Subdirectories are respected.
|
||||||
|
dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
|
||||||
|
test "x$dir" = "x$object" && dir=
|
||||||
|
base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
|
||||||
|
|
||||||
|
if test "$libtool" = yes; then
|
||||||
|
# With Tru64 cc, shared objects can also be used to make a
|
||||||
|
# static library. This mechanism is used in libtool 1.4 series to
|
||||||
|
# handle both shared and static libraries in a single compilation.
|
||||||
|
# With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
|
||||||
|
#
|
||||||
|
# With libtool 1.5 this exception was removed, and libtool now
|
||||||
|
# generates 2 separate objects for the 2 libraries. These two
|
||||||
|
# compilations output dependencies in $dir.libs/$base.o.d and
|
||||||
|
# in $dir$base.o.d. We have to check for both files, because
|
||||||
|
# one of the two compilations can be disabled. We should prefer
|
||||||
|
# $dir$base.o.d over $dir.libs/$base.o.d because the latter is
|
||||||
|
# automatically cleaned when .libs/ is deleted, while ignoring
|
||||||
|
# the former would cause a distcleancheck panic.
|
||||||
|
tmpdepfile1=$dir.libs/$base.lo.d # libtool 1.4
|
||||||
|
tmpdepfile2=$dir$base.o.d # libtool 1.5
|
||||||
|
tmpdepfile3=$dir.libs/$base.o.d # libtool 1.5
|
||||||
|
tmpdepfile4=$dir.libs/$base.d # Compaq CCC V6.2-504
|
||||||
|
"$@" -Wc,-MD
|
||||||
|
else
|
||||||
|
tmpdepfile1=$dir$base.o.d
|
||||||
|
tmpdepfile2=$dir$base.d
|
||||||
|
tmpdepfile3=$dir$base.d
|
||||||
|
tmpdepfile4=$dir$base.d
|
||||||
|
"$@" -MD
|
||||||
|
fi
|
||||||
|
|
||||||
|
stat=$?
|
||||||
|
if test $stat -eq 0; then :
|
||||||
|
else
|
||||||
|
rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
|
||||||
|
exit $stat
|
||||||
|
fi
|
||||||
|
|
||||||
|
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
|
||||||
|
do
|
||||||
|
test -f "$tmpdepfile" && break
|
||||||
|
done
|
||||||
|
if test -f "$tmpdepfile"; then
|
||||||
|
sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
|
||||||
|
# That's a tab and a space in the [].
|
||||||
|
sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
|
||||||
|
else
|
||||||
|
echo "#dummy" > "$depfile"
|
||||||
|
fi
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
;;
|
||||||
|
|
||||||
|
#nosideeffect)
|
||||||
|
# This comment above is used by automake to tell side-effect
|
||||||
|
# dependency tracking mechanisms from slower ones.
|
||||||
|
|
||||||
|
dashmstdout)
|
||||||
|
# Important note: in order to support this mode, a compiler *must*
|
||||||
|
# always write the preprocessed file to stdout, regardless of -o.
|
||||||
|
"$@" || exit $?
|
||||||
|
|
||||||
|
# Remove the call to Libtool.
|
||||||
|
if test "$libtool" = yes; then
|
||||||
|
while test $1 != '--mode=compile'; do
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove `-o $object'.
|
||||||
|
IFS=" "
|
||||||
|
for arg
|
||||||
|
do
|
||||||
|
case $arg in
|
||||||
|
-o)
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
$object)
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
set fnord "$@" "$arg"
|
||||||
|
shift # fnord
|
||||||
|
shift # $arg
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
test -z "$dashmflag" && dashmflag=-M
|
||||||
|
# Require at least two characters before searching for `:'
|
||||||
|
# in the target name. This is to cope with DOS-style filenames:
|
||||||
|
# a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
|
||||||
|
"$@" $dashmflag |
|
||||||
|
sed 's:^[ ]*[^: ][^:][^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
|
||||||
|
rm -f "$depfile"
|
||||||
|
cat < "$tmpdepfile" > "$depfile"
|
||||||
|
tr ' ' '
|
||||||
|
' < "$tmpdepfile" | \
|
||||||
|
## Some versions of the HPUX 10.20 sed can't process this invocation
|
||||||
|
## correctly. Breaking it into two sed invocations is a workaround.
|
||||||
|
sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
;;
|
||||||
|
|
||||||
|
dashXmstdout)
|
||||||
|
# This case only exists to satisfy depend.m4. It is never actually
|
||||||
|
# run, as this mode is specially recognized in the preamble.
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
|
||||||
|
makedepend)
|
||||||
|
"$@" || exit $?
|
||||||
|
# Remove any Libtool call
|
||||||
|
if test "$libtool" = yes; then
|
||||||
|
while test $1 != '--mode=compile'; do
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
# X makedepend
|
||||||
|
shift
|
||||||
|
cleared=no
|
||||||
|
for arg in "$@"; do
|
||||||
|
case $cleared in
|
||||||
|
no)
|
||||||
|
set ""; shift
|
||||||
|
cleared=yes ;;
|
||||||
|
esac
|
||||||
|
case "$arg" in
|
||||||
|
-D*|-I*)
|
||||||
|
set fnord "$@" "$arg"; shift ;;
|
||||||
|
# Strip any option that makedepend may not understand. Remove
|
||||||
|
# the object too, otherwise makedepend will parse it as a source file.
|
||||||
|
-*|$object)
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
set fnord "$@" "$arg"; shift ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
obj_suffix="`echo $object | sed 's/^.*\././'`"
|
||||||
|
touch "$tmpdepfile"
|
||||||
|
${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
|
||||||
|
rm -f "$depfile"
|
||||||
|
cat < "$tmpdepfile" > "$depfile"
|
||||||
|
sed '1,2d' "$tmpdepfile" | tr ' ' '
|
||||||
|
' | \
|
||||||
|
## Some versions of the HPUX 10.20 sed can't process this invocation
|
||||||
|
## correctly. Breaking it into two sed invocations is a workaround.
|
||||||
|
sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
|
||||||
|
rm -f "$tmpdepfile" "$tmpdepfile".bak
|
||||||
|
;;
|
||||||
|
|
||||||
|
cpp)
|
||||||
|
# Important note: in order to support this mode, a compiler *must*
|
||||||
|
# always write the preprocessed file to stdout.
|
||||||
|
"$@" || exit $?
|
||||||
|
|
||||||
|
# Remove the call to Libtool.
|
||||||
|
if test "$libtool" = yes; then
|
||||||
|
while test $1 != '--mode=compile'; do
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove `-o $object'.
|
||||||
|
IFS=" "
|
||||||
|
for arg
|
||||||
|
do
|
||||||
|
case $arg in
|
||||||
|
-o)
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
$object)
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
set fnord "$@" "$arg"
|
||||||
|
shift # fnord
|
||||||
|
shift # $arg
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
"$@" -E |
|
||||||
|
sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
|
||||||
|
-e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
|
||||||
|
sed '$ s: \\$::' > "$tmpdepfile"
|
||||||
|
rm -f "$depfile"
|
||||||
|
echo "$object : \\" > "$depfile"
|
||||||
|
cat < "$tmpdepfile" >> "$depfile"
|
||||||
|
sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
;;
|
||||||
|
|
||||||
|
msvisualcpp)
|
||||||
|
# Important note: in order to support this mode, a compiler *must*
|
||||||
|
# always write the preprocessed file to stdout, regardless of -o,
|
||||||
|
# because we must use -o when running libtool.
|
||||||
|
"$@" || exit $?
|
||||||
|
IFS=" "
|
||||||
|
for arg
|
||||||
|
do
|
||||||
|
case "$arg" in
|
||||||
|
"-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
|
||||||
|
set fnord "$@"
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
set fnord "$@" "$arg"
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
"$@" -E |
|
||||||
|
sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
|
||||||
|
rm -f "$depfile"
|
||||||
|
echo "$object : \\" > "$depfile"
|
||||||
|
. "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
|
||||||
|
echo " " >> "$depfile"
|
||||||
|
. "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
;;
|
||||||
|
|
||||||
|
none)
|
||||||
|
exec "$@"
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo "Unknown depmode $depmode" 1>&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
|
||||||
|
# Local Variables:
|
||||||
|
# mode: shell-script
|
||||||
|
# sh-indentation: 2
|
||||||
|
# eval: (add-hook 'write-file-hooks 'time-stamp)
|
||||||
|
# time-stamp-start: "scriptversion="
|
||||||
|
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||||
|
# time-stamp-end: "$"
|
||||||
|
# End:
|
507
config/install-sh
Executable file
507
config/install-sh
Executable file
@ -0,0 +1,507 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# install - install a program, script, or datafile
|
||||||
|
|
||||||
|
scriptversion=2006-10-14.15
|
||||||
|
|
||||||
|
# This originates from X11R5 (mit/util/scripts/install.sh), which was
|
||||||
|
# later released in X11R6 (xc/config/util/install.sh) with the
|
||||||
|
# following copyright and license.
|
||||||
|
#
|
||||||
|
# Copyright (C) 1994 X Consortium
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
# of this software and associated documentation files (the "Software"), to
|
||||||
|
# deal in the Software without restriction, including without limitation the
|
||||||
|
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
|
# sell copies of the Software, and to permit persons to whom the Software is
|
||||||
|
# furnished to do so, subject to the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be included in
|
||||||
|
# all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||||
|
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
|
||||||
|
# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
#
|
||||||
|
# Except as contained in this notice, the name of the X Consortium shall not
|
||||||
|
# be used in advertising or otherwise to promote the sale, use or other deal-
|
||||||
|
# ings in this Software without prior written authorization from the X Consor-
|
||||||
|
# tium.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# FSF changes to this file are in the public domain.
|
||||||
|
#
|
||||||
|
# Calling this script install-sh is preferred over install.sh, to prevent
|
||||||
|
# `make' implicit rules from creating a file called install from it
|
||||||
|
# when there is no Makefile.
|
||||||
|
#
|
||||||
|
# This script is compatible with the BSD install script, but was written
|
||||||
|
# from scratch.
|
||||||
|
|
||||||
|
nl='
|
||||||
|
'
|
||||||
|
IFS=" "" $nl"
|
||||||
|
|
||||||
|
# set DOITPROG to echo to test this script
|
||||||
|
|
||||||
|
# Don't use :- since 4.3BSD and earlier shells don't like it.
|
||||||
|
doit="${DOITPROG-}"
|
||||||
|
if test -z "$doit"; then
|
||||||
|
doit_exec=exec
|
||||||
|
else
|
||||||
|
doit_exec=$doit
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Put in absolute file names if you don't have them in your path;
|
||||||
|
# or use environment vars.
|
||||||
|
|
||||||
|
mvprog="${MVPROG-mv}"
|
||||||
|
cpprog="${CPPROG-cp}"
|
||||||
|
chmodprog="${CHMODPROG-chmod}"
|
||||||
|
chownprog="${CHOWNPROG-chown}"
|
||||||
|
chgrpprog="${CHGRPPROG-chgrp}"
|
||||||
|
stripprog="${STRIPPROG-strip}"
|
||||||
|
rmprog="${RMPROG-rm}"
|
||||||
|
mkdirprog="${MKDIRPROG-mkdir}"
|
||||||
|
|
||||||
|
posix_glob=
|
||||||
|
posix_mkdir=
|
||||||
|
|
||||||
|
# Desired mode of installed file.
|
||||||
|
mode=0755
|
||||||
|
|
||||||
|
chmodcmd=$chmodprog
|
||||||
|
chowncmd=
|
||||||
|
chgrpcmd=
|
||||||
|
stripcmd=
|
||||||
|
rmcmd="$rmprog -f"
|
||||||
|
mvcmd="$mvprog"
|
||||||
|
src=
|
||||||
|
dst=
|
||||||
|
dir_arg=
|
||||||
|
dstarg=
|
||||||
|
no_target_directory=
|
||||||
|
|
||||||
|
usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
|
||||||
|
or: $0 [OPTION]... SRCFILES... DIRECTORY
|
||||||
|
or: $0 [OPTION]... -t DIRECTORY SRCFILES...
|
||||||
|
or: $0 [OPTION]... -d DIRECTORIES...
|
||||||
|
|
||||||
|
In the 1st form, copy SRCFILE to DSTFILE.
|
||||||
|
In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
|
||||||
|
In the 4th, create DIRECTORIES.
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-c (ignored)
|
||||||
|
-d create directories instead of installing files.
|
||||||
|
-g GROUP $chgrpprog installed files to GROUP.
|
||||||
|
-m MODE $chmodprog installed files to MODE.
|
||||||
|
-o USER $chownprog installed files to USER.
|
||||||
|
-s $stripprog installed files.
|
||||||
|
-t DIRECTORY install into DIRECTORY.
|
||||||
|
-T report an error if DSTFILE is a directory.
|
||||||
|
--help display this help and exit.
|
||||||
|
--version display version info and exit.
|
||||||
|
|
||||||
|
Environment variables override the default commands:
|
||||||
|
CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG
|
||||||
|
"
|
||||||
|
|
||||||
|
while test $# -ne 0; do
|
||||||
|
case $1 in
|
||||||
|
-c) shift
|
||||||
|
continue;;
|
||||||
|
|
||||||
|
-d) dir_arg=true
|
||||||
|
shift
|
||||||
|
continue;;
|
||||||
|
|
||||||
|
-g) chgrpcmd="$chgrpprog $2"
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
continue;;
|
||||||
|
|
||||||
|
--help) echo "$usage"; exit $?;;
|
||||||
|
|
||||||
|
-m) mode=$2
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
case $mode in
|
||||||
|
*' '* | *' '* | *'
|
||||||
|
'* | *'*'* | *'?'* | *'['*)
|
||||||
|
echo "$0: invalid mode: $mode" >&2
|
||||||
|
exit 1;;
|
||||||
|
esac
|
||||||
|
continue;;
|
||||||
|
|
||||||
|
-o) chowncmd="$chownprog $2"
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
continue;;
|
||||||
|
|
||||||
|
-s) stripcmd=$stripprog
|
||||||
|
shift
|
||||||
|
continue;;
|
||||||
|
|
||||||
|
-t) dstarg=$2
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
continue;;
|
||||||
|
|
||||||
|
-T) no_target_directory=true
|
||||||
|
shift
|
||||||
|
continue;;
|
||||||
|
|
||||||
|
--version) echo "$0 $scriptversion"; exit $?;;
|
||||||
|
|
||||||
|
--) shift
|
||||||
|
break;;
|
||||||
|
|
||||||
|
-*) echo "$0: invalid option: $1" >&2
|
||||||
|
exit 1;;
|
||||||
|
|
||||||
|
*) break;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if test $# -ne 0 && test -z "$dir_arg$dstarg"; then
|
||||||
|
# When -d is used, all remaining arguments are directories to create.
|
||||||
|
# When -t is used, the destination is already specified.
|
||||||
|
# Otherwise, the last argument is the destination. Remove it from $@.
|
||||||
|
for arg
|
||||||
|
do
|
||||||
|
if test -n "$dstarg"; then
|
||||||
|
# $@ is not empty: it contains at least $arg.
|
||||||
|
set fnord "$@" "$dstarg"
|
||||||
|
shift # fnord
|
||||||
|
fi
|
||||||
|
shift # arg
|
||||||
|
dstarg=$arg
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test $# -eq 0; then
|
||||||
|
if test -z "$dir_arg"; then
|
||||||
|
echo "$0: no input file specified." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# It's OK to call `install-sh -d' without argument.
|
||||||
|
# This can happen when creating conditional directories.
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test -z "$dir_arg"; then
|
||||||
|
trap '(exit $?); exit' 1 2 13 15
|
||||||
|
|
||||||
|
# Set umask so as not to create temps with too-generous modes.
|
||||||
|
# However, 'strip' requires both read and write access to temps.
|
||||||
|
case $mode in
|
||||||
|
# Optimize common cases.
|
||||||
|
*644) cp_umask=133;;
|
||||||
|
*755) cp_umask=22;;
|
||||||
|
|
||||||
|
*[0-7])
|
||||||
|
if test -z "$stripcmd"; then
|
||||||
|
u_plus_rw=
|
||||||
|
else
|
||||||
|
u_plus_rw='% 200'
|
||||||
|
fi
|
||||||
|
cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
|
||||||
|
*)
|
||||||
|
if test -z "$stripcmd"; then
|
||||||
|
u_plus_rw=
|
||||||
|
else
|
||||||
|
u_plus_rw=,u+rw
|
||||||
|
fi
|
||||||
|
cp_umask=$mode$u_plus_rw;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
for src
|
||||||
|
do
|
||||||
|
# Protect names starting with `-'.
|
||||||
|
case $src in
|
||||||
|
-*) src=./$src ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if test -n "$dir_arg"; then
|
||||||
|
dst=$src
|
||||||
|
dstdir=$dst
|
||||||
|
test -d "$dstdir"
|
||||||
|
dstdir_status=$?
|
||||||
|
else
|
||||||
|
|
||||||
|
# Waiting for this to be detected by the "$cpprog $src $dsttmp" command
|
||||||
|
# might cause directories to be created, which would be especially bad
|
||||||
|
# if $src (and thus $dsttmp) contains '*'.
|
||||||
|
if test ! -f "$src" && test ! -d "$src"; then
|
||||||
|
echo "$0: $src does not exist." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test -z "$dstarg"; then
|
||||||
|
echo "$0: no destination specified." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
dst=$dstarg
|
||||||
|
# Protect names starting with `-'.
|
||||||
|
case $dst in
|
||||||
|
-*) dst=./$dst ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# If destination is a directory, append the input filename; won't work
|
||||||
|
# if double slashes aren't ignored.
|
||||||
|
if test -d "$dst"; then
|
||||||
|
if test -n "$no_target_directory"; then
|
||||||
|
echo "$0: $dstarg: Is a directory" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
dstdir=$dst
|
||||||
|
dst=$dstdir/`basename "$src"`
|
||||||
|
dstdir_status=0
|
||||||
|
else
|
||||||
|
# Prefer dirname, but fall back on a substitute if dirname fails.
|
||||||
|
dstdir=`
|
||||||
|
(dirname "$dst") 2>/dev/null ||
|
||||||
|
expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
|
||||||
|
X"$dst" : 'X\(//\)[^/]' \| \
|
||||||
|
X"$dst" : 'X\(//\)$' \| \
|
||||||
|
X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
|
||||||
|
echo X"$dst" |
|
||||||
|
sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
|
||||||
|
s//\1/
|
||||||
|
q
|
||||||
|
}
|
||||||
|
/^X\(\/\/\)[^/].*/{
|
||||||
|
s//\1/
|
||||||
|
q
|
||||||
|
}
|
||||||
|
/^X\(\/\/\)$/{
|
||||||
|
s//\1/
|
||||||
|
q
|
||||||
|
}
|
||||||
|
/^X\(\/\).*/{
|
||||||
|
s//\1/
|
||||||
|
q
|
||||||
|
}
|
||||||
|
s/.*/./; q'
|
||||||
|
`
|
||||||
|
|
||||||
|
test -d "$dstdir"
|
||||||
|
dstdir_status=$?
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
obsolete_mkdir_used=false
|
||||||
|
|
||||||
|
if test $dstdir_status != 0; then
|
||||||
|
case $posix_mkdir in
|
||||||
|
'')
|
||||||
|
# Create intermediate dirs using mode 755 as modified by the umask.
|
||||||
|
# This is like FreeBSD 'install' as of 1997-10-28.
|
||||||
|
umask=`umask`
|
||||||
|
case $stripcmd.$umask in
|
||||||
|
# Optimize common cases.
|
||||||
|
*[2367][2367]) mkdir_umask=$umask;;
|
||||||
|
.*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
|
||||||
|
|
||||||
|
*[0-7])
|
||||||
|
mkdir_umask=`expr $umask + 22 \
|
||||||
|
- $umask % 100 % 40 + $umask % 20 \
|
||||||
|
- $umask % 10 % 4 + $umask % 2
|
||||||
|
`;;
|
||||||
|
*) mkdir_umask=$umask,go-w;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# With -d, create the new directory with the user-specified mode.
|
||||||
|
# Otherwise, rely on $mkdir_umask.
|
||||||
|
if test -n "$dir_arg"; then
|
||||||
|
mkdir_mode=-m$mode
|
||||||
|
else
|
||||||
|
mkdir_mode=
|
||||||
|
fi
|
||||||
|
|
||||||
|
posix_mkdir=false
|
||||||
|
case $umask in
|
||||||
|
*[123567][0-7][0-7])
|
||||||
|
# POSIX mkdir -p sets u+wx bits regardless of umask, which
|
||||||
|
# is incompatible with FreeBSD 'install' when (umask & 300) != 0.
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
|
||||||
|
trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
|
||||||
|
|
||||||
|
if (umask $mkdir_umask &&
|
||||||
|
exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
if test -z "$dir_arg" || {
|
||||||
|
# Check for POSIX incompatibilities with -m.
|
||||||
|
# HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
|
||||||
|
# other-writeable bit of parent directory when it shouldn't.
|
||||||
|
# FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
|
||||||
|
ls_ld_tmpdir=`ls -ld "$tmpdir"`
|
||||||
|
case $ls_ld_tmpdir in
|
||||||
|
d????-?r-*) different_mode=700;;
|
||||||
|
d????-?--*) different_mode=755;;
|
||||||
|
*) false;;
|
||||||
|
esac &&
|
||||||
|
$mkdirprog -m$different_mode -p -- "$tmpdir" && {
|
||||||
|
ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
|
||||||
|
test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
then posix_mkdir=:
|
||||||
|
fi
|
||||||
|
rmdir "$tmpdir/d" "$tmpdir"
|
||||||
|
else
|
||||||
|
# Remove any dirs left behind by ancient mkdir implementations.
|
||||||
|
rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
|
||||||
|
fi
|
||||||
|
trap '' 0;;
|
||||||
|
esac;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if
|
||||||
|
$posix_mkdir && (
|
||||||
|
umask $mkdir_umask &&
|
||||||
|
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
|
||||||
|
)
|
||||||
|
then :
|
||||||
|
else
|
||||||
|
|
||||||
|
# The umask is ridiculous, or mkdir does not conform to POSIX,
|
||||||
|
# or it failed possibly due to a race condition. Create the
|
||||||
|
# directory the slow way, step by step, checking for races as we go.
|
||||||
|
|
||||||
|
case $dstdir in
|
||||||
|
/*) prefix=/ ;;
|
||||||
|
-*) prefix=./ ;;
|
||||||
|
*) prefix= ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
case $posix_glob in
|
||||||
|
'')
|
||||||
|
if (set -f) 2>/dev/null; then
|
||||||
|
posix_glob=true
|
||||||
|
else
|
||||||
|
posix_glob=false
|
||||||
|
fi ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
oIFS=$IFS
|
||||||
|
IFS=/
|
||||||
|
$posix_glob && set -f
|
||||||
|
set fnord $dstdir
|
||||||
|
shift
|
||||||
|
$posix_glob && set +f
|
||||||
|
IFS=$oIFS
|
||||||
|
|
||||||
|
prefixes=
|
||||||
|
|
||||||
|
for d
|
||||||
|
do
|
||||||
|
test -z "$d" && continue
|
||||||
|
|
||||||
|
prefix=$prefix$d
|
||||||
|
if test -d "$prefix"; then
|
||||||
|
prefixes=
|
||||||
|
else
|
||||||
|
if $posix_mkdir; then
|
||||||
|
(umask=$mkdir_umask &&
|
||||||
|
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
|
||||||
|
# Don't fail if two instances are running concurrently.
|
||||||
|
test -d "$prefix" || exit 1
|
||||||
|
else
|
||||||
|
case $prefix in
|
||||||
|
*\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
|
||||||
|
*) qprefix=$prefix;;
|
||||||
|
esac
|
||||||
|
prefixes="$prefixes '$qprefix'"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
prefix=$prefix/
|
||||||
|
done
|
||||||
|
|
||||||
|
if test -n "$prefixes"; then
|
||||||
|
# Don't fail if two instances are running concurrently.
|
||||||
|
(umask $mkdir_umask &&
|
||||||
|
eval "\$doit_exec \$mkdirprog $prefixes") ||
|
||||||
|
test -d "$dstdir" || exit 1
|
||||||
|
obsolete_mkdir_used=true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test -n "$dir_arg"; then
|
||||||
|
{ test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
|
||||||
|
{ test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
|
||||||
|
{ test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
|
||||||
|
test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
|
||||||
|
else
|
||||||
|
|
||||||
|
# Make a couple of temp file names in the proper directory.
|
||||||
|
dsttmp=$dstdir/_inst.$$_
|
||||||
|
rmtmp=$dstdir/_rm.$$_
|
||||||
|
|
||||||
|
# Trap to clean up those temp files at exit.
|
||||||
|
trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
|
||||||
|
|
||||||
|
# Copy the file name to the temp name.
|
||||||
|
(umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
|
||||||
|
|
||||||
|
# and set any options; do chmod last to preserve setuid bits.
|
||||||
|
#
|
||||||
|
# If any of these fail, we abort the whole thing. If we want to
|
||||||
|
# ignore errors from any of these, just make sure not to ignore
|
||||||
|
# errors from the above "$doit $cpprog $src $dsttmp" command.
|
||||||
|
#
|
||||||
|
{ test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
|
||||||
|
&& { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
|
||||||
|
&& { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
|
||||||
|
&& { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
|
||||||
|
|
||||||
|
# Now rename the file to the real destination.
|
||||||
|
{ $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null \
|
||||||
|
|| {
|
||||||
|
# The rename failed, perhaps because mv can't rename something else
|
||||||
|
# to itself, or perhaps because mv is so ancient that it does not
|
||||||
|
# support -f.
|
||||||
|
|
||||||
|
# Now remove or move aside any old file at destination location.
|
||||||
|
# We try this two ways since rm can't unlink itself on some
|
||||||
|
# systems and the destination file might be busy for other
|
||||||
|
# reasons. In this case, the final cleanup might fail but the new
|
||||||
|
# file should still install successfully.
|
||||||
|
{
|
||||||
|
if test -f "$dst"; then
|
||||||
|
$doit $rmcmd -f "$dst" 2>/dev/null \
|
||||||
|
|| { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null \
|
||||||
|
&& { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }; }\
|
||||||
|
|| {
|
||||||
|
echo "$0: cannot unlink or rename $dst" >&2
|
||||||
|
(exit 1); exit 1
|
||||||
|
}
|
||||||
|
else
|
||||||
|
:
|
||||||
|
fi
|
||||||
|
} &&
|
||||||
|
|
||||||
|
# Now rename the file to the real destination.
|
||||||
|
$doit $mvcmd "$dsttmp" "$dst"
|
||||||
|
}
|
||||||
|
} || exit 1
|
||||||
|
|
||||||
|
trap '' 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Local variables:
|
||||||
|
# eval: (add-hook 'write-file-hooks 'time-stamp)
|
||||||
|
# time-stamp-start: "scriptversion="
|
||||||
|
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||||
|
# time-stamp-end: "$"
|
||||||
|
# End:
|
6909
config/ltmain.sh
Normal file
6909
config/ltmain.sh
Normal file
File diff suppressed because it is too large
Load Diff
367
config/missing
Executable file
367
config/missing
Executable file
@ -0,0 +1,367 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
# Common stub for a few missing GNU programs while installing.
|
||||||
|
|
||||||
|
scriptversion=2006-05-10.23
|
||||||
|
|
||||||
|
# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006
|
||||||
|
# Free Software Foundation, Inc.
|
||||||
|
# Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
|
||||||
|
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2, or (at your option)
|
||||||
|
# any later version.
|
||||||
|
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
# 02110-1301, USA.
|
||||||
|
|
||||||
|
# As a special exception to the GNU General Public License, if you
|
||||||
|
# distribute this file as part of a program that contains a
|
||||||
|
# configuration script generated by Autoconf, you may include it under
|
||||||
|
# the same distribution terms that you use for the rest of that program.
|
||||||
|
|
||||||
|
if test $# -eq 0; then
|
||||||
|
echo 1>&2 "Try \`$0 --help' for more information"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
run=:
|
||||||
|
sed_output='s/.* --output[ =]\([^ ]*\).*/\1/p'
|
||||||
|
sed_minuso='s/.* -o \([^ ]*\).*/\1/p'
|
||||||
|
|
||||||
|
# In the cases where this matters, `missing' is being run in the
|
||||||
|
# srcdir already.
|
||||||
|
if test -f configure.ac; then
|
||||||
|
configure_ac=configure.ac
|
||||||
|
else
|
||||||
|
configure_ac=configure.in
|
||||||
|
fi
|
||||||
|
|
||||||
|
msg="missing on your system"
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
--run)
|
||||||
|
# Try to run requested program, and just exit if it succeeds.
|
||||||
|
run=
|
||||||
|
shift
|
||||||
|
"$@" && exit 0
|
||||||
|
# Exit code 63 means version mismatch. This often happens
|
||||||
|
# when the user try to use an ancient version of a tool on
|
||||||
|
# a file that requires a minimum version. In this case we
|
||||||
|
# we should proceed has if the program had been absent, or
|
||||||
|
# if --run hadn't been passed.
|
||||||
|
if test $? = 63; then
|
||||||
|
run=:
|
||||||
|
msg="probably too old"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
-h|--h|--he|--hel|--help)
|
||||||
|
echo "\
|
||||||
|
$0 [OPTION]... PROGRAM [ARGUMENT]...
|
||||||
|
|
||||||
|
Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
|
||||||
|
error status if there is no known handling for PROGRAM.
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h, --help display this help and exit
|
||||||
|
-v, --version output version information and exit
|
||||||
|
--run try to run the given command, and emulate it if it fails
|
||||||
|
|
||||||
|
Supported PROGRAM values:
|
||||||
|
aclocal touch file \`aclocal.m4'
|
||||||
|
autoconf touch file \`configure'
|
||||||
|
autoheader touch file \`config.h.in'
|
||||||
|
autom4te touch the output file, or create a stub one
|
||||||
|
automake touch all \`Makefile.in' files
|
||||||
|
bison create \`y.tab.[ch]', if possible, from existing .[ch]
|
||||||
|
flex create \`lex.yy.c', if possible, from existing .c
|
||||||
|
help2man touch the output file
|
||||||
|
lex create \`lex.yy.c', if possible, from existing .c
|
||||||
|
makeinfo touch the output file
|
||||||
|
tar try tar, gnutar, gtar, then tar without non-portable flags
|
||||||
|
yacc create \`y.tab.[ch]', if possible, from existing .[ch]
|
||||||
|
|
||||||
|
Send bug reports to <bug-automake@gnu.org>."
|
||||||
|
exit $?
|
||||||
|
;;
|
||||||
|
|
||||||
|
-v|--v|--ve|--ver|--vers|--versi|--versio|--version)
|
||||||
|
echo "missing $scriptversion (GNU Automake)"
|
||||||
|
exit $?
|
||||||
|
;;
|
||||||
|
|
||||||
|
-*)
|
||||||
|
echo 1>&2 "$0: Unknown \`$1' option"
|
||||||
|
echo 1>&2 "Try \`$0 --help' for more information"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Now exit if we have it, but it failed. Also exit now if we
|
||||||
|
# don't have it and --version was passed (most likely to detect
|
||||||
|
# the program).
|
||||||
|
case $1 in
|
||||||
|
lex|yacc)
|
||||||
|
# Not GNU programs, they don't have --version.
|
||||||
|
;;
|
||||||
|
|
||||||
|
tar)
|
||||||
|
if test -n "$run"; then
|
||||||
|
echo 1>&2 "ERROR: \`tar' requires --run"
|
||||||
|
exit 1
|
||||||
|
elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
|
||||||
|
# We have it, but it failed.
|
||||||
|
exit 1
|
||||||
|
elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
|
||||||
|
# Could not run --version or --help. This is probably someone
|
||||||
|
# running `$TOOL --version' or `$TOOL --help' to check whether
|
||||||
|
# $TOOL exists and not knowing $TOOL uses missing.
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# If it does not exist, or fails to run (possibly an outdated version),
|
||||||
|
# try to emulate it.
|
||||||
|
case $1 in
|
||||||
|
aclocal*)
|
||||||
|
echo 1>&2 "\
|
||||||
|
WARNING: \`$1' is $msg. You should only need it if
|
||||||
|
you modified \`acinclude.m4' or \`${configure_ac}'. You might want
|
||||||
|
to install the \`Automake' and \`Perl' packages. Grab them from
|
||||||
|
any GNU archive site."
|
||||||
|
touch aclocal.m4
|
||||||
|
;;
|
||||||
|
|
||||||
|
autoconf)
|
||||||
|
echo 1>&2 "\
|
||||||
|
WARNING: \`$1' is $msg. You should only need it if
|
||||||
|
you modified \`${configure_ac}'. You might want to install the
|
||||||
|
\`Autoconf' and \`GNU m4' packages. Grab them from any GNU
|
||||||
|
archive site."
|
||||||
|
touch configure
|
||||||
|
;;
|
||||||
|
|
||||||
|
autoheader)
|
||||||
|
echo 1>&2 "\
|
||||||
|
WARNING: \`$1' is $msg. You should only need it if
|
||||||
|
you modified \`acconfig.h' or \`${configure_ac}'. You might want
|
||||||
|
to install the \`Autoconf' and \`GNU m4' packages. Grab them
|
||||||
|
from any GNU archive site."
|
||||||
|
files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}`
|
||||||
|
test -z "$files" && files="config.h"
|
||||||
|
touch_files=
|
||||||
|
for f in $files; do
|
||||||
|
case $f in
|
||||||
|
*:*) touch_files="$touch_files "`echo "$f" |
|
||||||
|
sed -e 's/^[^:]*://' -e 's/:.*//'`;;
|
||||||
|
*) touch_files="$touch_files $f.in";;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
touch $touch_files
|
||||||
|
;;
|
||||||
|
|
||||||
|
automake*)
|
||||||
|
echo 1>&2 "\
|
||||||
|
WARNING: \`$1' is $msg. You should only need it if
|
||||||
|
you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
|
||||||
|
You might want to install the \`Automake' and \`Perl' packages.
|
||||||
|
Grab them from any GNU archive site."
|
||||||
|
find . -type f -name Makefile.am -print |
|
||||||
|
sed 's/\.am$/.in/' |
|
||||||
|
while read f; do touch "$f"; done
|
||||||
|
;;
|
||||||
|
|
||||||
|
autom4te)
|
||||||
|
echo 1>&2 "\
|
||||||
|
WARNING: \`$1' is needed, but is $msg.
|
||||||
|
You might have modified some files without having the
|
||||||
|
proper tools for further handling them.
|
||||||
|
You can get \`$1' as part of \`Autoconf' from any GNU
|
||||||
|
archive site."
|
||||||
|
|
||||||
|
file=`echo "$*" | sed -n "$sed_output"`
|
||||||
|
test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
|
||||||
|
if test -f "$file"; then
|
||||||
|
touch $file
|
||||||
|
else
|
||||||
|
test -z "$file" || exec >$file
|
||||||
|
echo "#! /bin/sh"
|
||||||
|
echo "# Created by GNU Automake missing as a replacement of"
|
||||||
|
echo "# $ $@"
|
||||||
|
echo "exit 0"
|
||||||
|
chmod +x $file
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
bison|yacc)
|
||||||
|
echo 1>&2 "\
|
||||||
|
WARNING: \`$1' $msg. You should only need it if
|
||||||
|
you modified a \`.y' file. You may need the \`Bison' package
|
||||||
|
in order for those modifications to take effect. You can get
|
||||||
|
\`Bison' from any GNU archive site."
|
||||||
|
rm -f y.tab.c y.tab.h
|
||||||
|
if test $# -ne 1; then
|
||||||
|
eval LASTARG="\${$#}"
|
||||||
|
case $LASTARG in
|
||||||
|
*.y)
|
||||||
|
SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
|
||||||
|
if test -f "$SRCFILE"; then
|
||||||
|
cp "$SRCFILE" y.tab.c
|
||||||
|
fi
|
||||||
|
SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
|
||||||
|
if test -f "$SRCFILE"; then
|
||||||
|
cp "$SRCFILE" y.tab.h
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
if test ! -f y.tab.h; then
|
||||||
|
echo >y.tab.h
|
||||||
|
fi
|
||||||
|
if test ! -f y.tab.c; then
|
||||||
|
echo 'main() { return 0; }' >y.tab.c
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
lex|flex)
|
||||||
|
echo 1>&2 "\
|
||||||
|
WARNING: \`$1' is $msg. You should only need it if
|
||||||
|
you modified a \`.l' file. You may need the \`Flex' package
|
||||||
|
in order for those modifications to take effect. You can get
|
||||||
|
\`Flex' from any GNU archive site."
|
||||||
|
rm -f lex.yy.c
|
||||||
|
if test $# -ne 1; then
|
||||||
|
eval LASTARG="\${$#}"
|
||||||
|
case $LASTARG in
|
||||||
|
*.l)
|
||||||
|
SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
|
||||||
|
if test -f "$SRCFILE"; then
|
||||||
|
cp "$SRCFILE" lex.yy.c
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
if test ! -f lex.yy.c; then
|
||||||
|
echo 'main() { return 0; }' >lex.yy.c
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
help2man)
|
||||||
|
echo 1>&2 "\
|
||||||
|
WARNING: \`$1' is $msg. You should only need it if
|
||||||
|
you modified a dependency of a manual page. You may need the
|
||||||
|
\`Help2man' package in order for those modifications to take
|
||||||
|
effect. You can get \`Help2man' from any GNU archive site."
|
||||||
|
|
||||||
|
file=`echo "$*" | sed -n "$sed_output"`
|
||||||
|
test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
|
||||||
|
if test -f "$file"; then
|
||||||
|
touch $file
|
||||||
|
else
|
||||||
|
test -z "$file" || exec >$file
|
||||||
|
echo ".ab help2man is required to generate this page"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
makeinfo)
|
||||||
|
echo 1>&2 "\
|
||||||
|
WARNING: \`$1' is $msg. You should only need it if
|
||||||
|
you modified a \`.texi' or \`.texinfo' file, or any other file
|
||||||
|
indirectly affecting the aspect of the manual. The spurious
|
||||||
|
call might also be the consequence of using a buggy \`make' (AIX,
|
||||||
|
DU, IRIX). You might want to install the \`Texinfo' package or
|
||||||
|
the \`GNU make' package. Grab either from any GNU archive site."
|
||||||
|
# The file to touch is that specified with -o ...
|
||||||
|
file=`echo "$*" | sed -n "$sed_output"`
|
||||||
|
test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
|
||||||
|
if test -z "$file"; then
|
||||||
|
# ... or it is the one specified with @setfilename ...
|
||||||
|
infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
|
||||||
|
file=`sed -n '
|
||||||
|
/^@setfilename/{
|
||||||
|
s/.* \([^ ]*\) *$/\1/
|
||||||
|
p
|
||||||
|
q
|
||||||
|
}' $infile`
|
||||||
|
# ... or it is derived from the source name (dir/f.texi becomes f.info)
|
||||||
|
test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info
|
||||||
|
fi
|
||||||
|
# If the file does not exist, the user really needs makeinfo;
|
||||||
|
# let's fail without touching anything.
|
||||||
|
test -f $file || exit 1
|
||||||
|
touch $file
|
||||||
|
;;
|
||||||
|
|
||||||
|
tar)
|
||||||
|
shift
|
||||||
|
|
||||||
|
# We have already tried tar in the generic part.
|
||||||
|
# Look for gnutar/gtar before invocation to avoid ugly error
|
||||||
|
# messages.
|
||||||
|
if (gnutar --version > /dev/null 2>&1); then
|
||||||
|
gnutar "$@" && exit 0
|
||||||
|
fi
|
||||||
|
if (gtar --version > /dev/null 2>&1); then
|
||||||
|
gtar "$@" && exit 0
|
||||||
|
fi
|
||||||
|
firstarg="$1"
|
||||||
|
if shift; then
|
||||||
|
case $firstarg in
|
||||||
|
*o*)
|
||||||
|
firstarg=`echo "$firstarg" | sed s/o//`
|
||||||
|
tar "$firstarg" "$@" && exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
case $firstarg in
|
||||||
|
*h*)
|
||||||
|
firstarg=`echo "$firstarg" | sed s/h//`
|
||||||
|
tar "$firstarg" "$@" && exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo 1>&2 "\
|
||||||
|
WARNING: I can't seem to be able to run \`tar' with the given arguments.
|
||||||
|
You may want to install GNU tar or Free paxutils, or check the
|
||||||
|
command line arguments."
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo 1>&2 "\
|
||||||
|
WARNING: \`$1' is needed, and is $msg.
|
||||||
|
You might have modified some files without having the
|
||||||
|
proper tools for further handling them. Check the \`README' file,
|
||||||
|
it often tells you about the needed prerequisites for installing
|
||||||
|
this package. You may also peek at any GNU archive site, in case
|
||||||
|
some other package would contain this missing \`$1' program."
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
|
||||||
|
# Local variables:
|
||||||
|
# eval: (add-hook 'write-file-hooks 'time-stamp)
|
||||||
|
# time-stamp-start: "scriptversion="
|
||||||
|
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||||
|
# time-stamp-end: "$"
|
||||||
|
# End:
|
38
configure.in
Normal file
38
configure.in
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
# -*- Autoconf -*-
|
||||||
|
# Process this file with autoconf to produce a configure script.
|
||||||
|
|
||||||
|
AC_INIT([lxc], [0.1.0])
|
||||||
|
|
||||||
|
AC_CONFIG_SRCDIR([configure.in])
|
||||||
|
AC_CONFIG_AUX_DIR([config])
|
||||||
|
AM_CONFIG_HEADER([src/config.h])
|
||||||
|
AM_INIT_AUTOMAKE([-Wno-portability])
|
||||||
|
AC_CANONICAL_HOST
|
||||||
|
AC_PROG_RANLIB
|
||||||
|
AM_PROG_CC_C_O
|
||||||
|
AC_GNU_SOURCE
|
||||||
|
AC_CHECK_HEADERS([linux/netlink.h linux/genetlink.h],, AC_MSG_ERROR([netlink headers not found]), [[]])
|
||||||
|
AC_PROG_GCC_TRADITIONAL
|
||||||
|
|
||||||
|
if test "x$GCC" = "xyes"; then
|
||||||
|
CFLAGS="$CFLAGS -Wall -Werror"
|
||||||
|
fi
|
||||||
|
|
||||||
|
AC_CONFIG_FILES([
|
||||||
|
Makefile
|
||||||
|
lxc.spec
|
||||||
|
config/Makefile
|
||||||
|
src/Makefile
|
||||||
|
src/liblxc/Makefile
|
||||||
|
src/lxc/Makefile
|
||||||
|
src/lxc/lxc-ps
|
||||||
|
etc/Makefile
|
||||||
|
etc/lxc-macvlan.conf
|
||||||
|
etc/lxc-no-netns.conf
|
||||||
|
etc/lxc-phys.conf
|
||||||
|
etc/lxc-veth.conf
|
||||||
|
etc/lxc-complex-config
|
||||||
|
test/Makefile
|
||||||
|
])
|
||||||
|
AC_CONFIG_COMMANDS([default],[[]],[[]])
|
||||||
|
AC_OUTPUT
|
2
doc/fstab
Normal file
2
doc/fstab
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
proc /proc proc defaults 0 0
|
||||||
|
sysfs /sys sysfs noauto 0 0
|
36
doc/lxc.conf
Normal file
36
doc/lxc.conf
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
# the fstab mount file
|
||||||
|
lxc.mount = ./fstab
|
||||||
|
|
||||||
|
# the hostname to be set into the container
|
||||||
|
lxc.utsname = virtnode
|
||||||
|
|
||||||
|
# The network has several of kind of configuration:
|
||||||
|
#
|
||||||
|
# * veth : the network will use the veth virtual device, the specified
|
||||||
|
# link must be a bridge
|
||||||
|
# * macvlan : the network will use the macvlan device, the specified link
|
||||||
|
# should be an existing interface, usually it is eth0
|
||||||
|
# * phys : the network will use a physical network device, the specified
|
||||||
|
# link should be an existing interface
|
||||||
|
lxc.network.type = macvlan
|
||||||
|
|
||||||
|
# specify the flags to be used for the network, actually only <up> is allowed
|
||||||
|
# which mean the network should be set up when created. If the network is set
|
||||||
|
# up, the loopback is automatically set up too.
|
||||||
|
lxc.network.flags = up
|
||||||
|
|
||||||
|
# specify the physical network device which will communicate with the
|
||||||
|
# outside world
|
||||||
|
lxc.network.link = eth0
|
||||||
|
|
||||||
|
# NIC ethernet mac address
|
||||||
|
lxc.network.hwaddr = 4a:49:43:49:79:bd
|
||||||
|
|
||||||
|
# specify the ipv4 address of the container. Several lines are allowed and
|
||||||
|
# will mean several addresses will be assigned to the interface
|
||||||
|
lxc.network.ipv4 = 1.2.3.5/24
|
||||||
|
|
||||||
|
# specify the ipv6 address of the container. Several lines are allowed and
|
||||||
|
# will mean several addresses will be assigned to the interface
|
||||||
|
lxc.network.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596
|
||||||
|
|
7
etc/.cvsignore
Normal file
7
etc/.cvsignore
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
Makefile
|
||||||
|
Makefile.in
|
||||||
|
lxc-macvlan.conf
|
||||||
|
lxc-no-netns.conf
|
||||||
|
lxc-phys.conf
|
||||||
|
lxc-veth.conf
|
||||||
|
|
13
etc/Makefile.am
Normal file
13
etc/Makefile.am
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
pkgsysconfdir = $(sysconfdir)/$(PACKAGE)
|
||||||
|
pkgsysconf_DATA = \
|
||||||
|
lxc-macvlan.conf \
|
||||||
|
lxc-no-netns.conf \
|
||||||
|
lxc-phys.conf \
|
||||||
|
lxc-veth.conf \
|
||||||
|
lxc-complex-config
|
||||||
|
noinst_DATA = \
|
||||||
|
lxc-macvlan.conf.in \
|
||||||
|
lxc-no-netns.conf.in \
|
||||||
|
lxc-phys.conf.in \
|
||||||
|
lxc-veth.conf.in \
|
||||||
|
lxc-complex-config.in
|
23
etc/lxc-complex-config.in
Normal file
23
etc/lxc-complex-config.in
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# Container with network a complex network mixing macvlan, veth and
|
||||||
|
# physical network devices
|
||||||
|
lxc.utsname = complex
|
||||||
|
lxc.network.type = veth
|
||||||
|
lxc.network.flags = up
|
||||||
|
lxc.network.link = br0
|
||||||
|
lxc.network.hwaddr = 4a:49:43:49:79:bf
|
||||||
|
lxc.network.ipv4 = 1.2.3.5/24
|
||||||
|
lxc.network.ipv6 = 2003:db8:1:0:214:1234:fe0b:3597
|
||||||
|
|
||||||
|
lxc.network.type = macvlan
|
||||||
|
lxc.network.flags = up
|
||||||
|
lxc.network.link = eth0
|
||||||
|
lxc.network.hwaddr = 4a:49:43:49:79:bd
|
||||||
|
lxc.network.ipv4 = 1.2.3.4/24
|
||||||
|
lxc.network.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596
|
||||||
|
|
||||||
|
lxc.network.type = phys
|
||||||
|
lxc.network.flags = up
|
||||||
|
lxc.network.link = dummy0
|
||||||
|
lxc.network.hwaddr = 4a:49:43:49:79:ff
|
||||||
|
lxc.network.ipv4 = 1.2.3.6/24
|
||||||
|
lxc.network.ipv6 = 2003:db8:1:0:214:1234:fe0b:3297
|
8
etc/lxc-macvlan.conf.in
Normal file
8
etc/lxc-macvlan.conf.in
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Container with network virtualized using the macvlan device driver
|
||||||
|
lxc.utsname = alpha
|
||||||
|
lxc.network.type = macvlan
|
||||||
|
lxc.network.flags = up
|
||||||
|
lxc.network.link = eth0
|
||||||
|
lxc.network.hwaddr = 4a:49:43:49:79:bd
|
||||||
|
lxc.network.ipv4 = 1.2.3.4/24
|
||||||
|
lxc.network.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596
|
2
etc/lxc-no-netns.conf.in
Normal file
2
etc/lxc-no-netns.conf.in
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Container with non-virtualized network
|
||||||
|
lxc.utsname = delta
|
9
etc/lxc-phys.conf.in
Normal file
9
etc/lxc-phys.conf.in
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# Container with network virtualized using a physical network device with name
|
||||||
|
# 'eth0'
|
||||||
|
lxc.utsname = gamma
|
||||||
|
lxc.network.type = phys
|
||||||
|
lxc.network.flags = up
|
||||||
|
lxc.network.link = eth0
|
||||||
|
lxc.network.hwaddr = 4a:49:43:49:79:ff
|
||||||
|
lxc.network.ipv4 = 1.2.3.6/24
|
||||||
|
lxc.network.ipv6 = 2003:db8:1:0:214:1234:fe0b:3297
|
9
etc/lxc-veth.conf.in
Normal file
9
etc/lxc-veth.conf.in
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# Container with network virtualized using a pre-configured bridge named br0 and
|
||||||
|
# veth pair virtual network devices
|
||||||
|
lxc.utsname = beta
|
||||||
|
lxc.network.type = veth
|
||||||
|
lxc.network.flags = up
|
||||||
|
lxc.network.link = br0
|
||||||
|
lxc.network.hwaddr = 4a:49:43:49:79:bf
|
||||||
|
lxc.network.ipv4 = 1.2.3.5/24
|
||||||
|
lxc.network.ipv6 = 2003:db8:1:0:214:1234:fe0b:3597
|
99
lxc.spec.in
Normal file
99
lxc.spec.in
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
#
|
||||||
|
# lxc: linux Container library
|
||||||
|
#
|
||||||
|
# (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
#
|
||||||
|
# Authors:
|
||||||
|
# Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
#
|
||||||
|
# This library is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
# License as published by the Free Software Foundation; either
|
||||||
|
# version 2.1 of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This library is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
# Lesser General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
|
# License along with this library; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
%define _unpackaged_files_terminate_build 0
|
||||||
|
|
||||||
|
%define RELEASE 1
|
||||||
|
%define rel %{?CUSTOM_RELEASE} %{!?CUSTOM_RELEASE: %RELEASE}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Arguments that can be passed to the rpm builder:
|
||||||
|
#
|
||||||
|
# --define 'confargs <extra args to configure args>' (def. '')
|
||||||
|
#
|
||||||
|
|
||||||
|
%{!?confargs: %{expand:%%define confargs ''}}
|
||||||
|
|
||||||
|
# What kernel are we building for?
|
||||||
|
%{!?kernel: %{expand:%%define kernel %(uname -r)}}
|
||||||
|
|
||||||
|
%define _prefix /usr
|
||||||
|
|
||||||
|
Name: @PACKAGE@
|
||||||
|
Version: @VERSION@
|
||||||
|
Release: %{rel}
|
||||||
|
Packager: <dlezcano@fr.ibm.com>
|
||||||
|
URL: http://lxc.sourceforge.net
|
||||||
|
Summary: %name
|
||||||
|
Group: Applications/System
|
||||||
|
License: LGPL
|
||||||
|
Source: %name/%name-%version.tar.gz
|
||||||
|
BuildRoot: %_tmppath/%name-%version-root
|
||||||
|
|
||||||
|
%description
|
||||||
|
%name is a set of command line to manage containers
|
||||||
|
|
||||||
|
%package devel
|
||||||
|
Release: %{rel}
|
||||||
|
Summary: development library for %{name}
|
||||||
|
Group: Application/System
|
||||||
|
|
||||||
|
%description devel
|
||||||
|
The %{name}-devel package contains header files and library needed for development
|
||||||
|
of containers
|
||||||
|
|
||||||
|
%prep
|
||||||
|
%setup -q
|
||||||
|
|
||||||
|
%build
|
||||||
|
%configure $args
|
||||||
|
|
||||||
|
ncpus=`egrep -c "^cpu[0-9]+" /proc/stat || :`
|
||||||
|
make -j$ncpus
|
||||||
|
|
||||||
|
%install
|
||||||
|
rm -rf %{buildroot}
|
||||||
|
%makeinstall
|
||||||
|
|
||||||
|
%clean
|
||||||
|
rm -rf %{buildroot}
|
||||||
|
|
||||||
|
%post
|
||||||
|
|
||||||
|
%files
|
||||||
|
%defattr(-,root,root)
|
||||||
|
%{_sysconfdir}/%{name}/*
|
||||||
|
%{_bindir}/*
|
||||||
|
|
||||||
|
%files devel
|
||||||
|
%defattr(-,root,root)
|
||||||
|
%{_includedir}/%{name}/*
|
||||||
|
%{_libdir}/*.a
|
||||||
|
|
||||||
|
%changelog
|
||||||
|
* Sun Aug 3 2008 Daniel Lezcano <dlezcano@fr.ibm.com>
|
||||||
|
- Initial RPM release.
|
||||||
|
|
||||||
|
# Local variables:
|
||||||
|
# mode: shell-script
|
||||||
|
# sh-shell: rpm
|
||||||
|
# end:
|
5
src/.cvsignore
Normal file
5
src/.cvsignore
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
Makefile
|
||||||
|
Makefile.in
|
||||||
|
config.h
|
||||||
|
config.h.in
|
||||||
|
stamp-h1
|
1
src/Makefile.am
Normal file
1
src/Makefile.am
Normal file
@ -0,0 +1 @@
|
|||||||
|
SUBDIRS = liblxc lxc
|
4
src/liblxc/.cvsignore
Normal file
4
src/liblxc/.cvsignore
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
Makefile
|
||||||
|
Makefile.in
|
||||||
|
liblxc.la
|
||||||
|
.deps
|
26
src/liblxc/Makefile.am
Normal file
26
src/liblxc/Makefile.am
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
lib_LIBRARIES = liblxc.a
|
||||||
|
pkginclude_HEADERS = lxc.h
|
||||||
|
liblxc_a_SOURCES = \
|
||||||
|
create.c \
|
||||||
|
destroy.c \
|
||||||
|
start.c \
|
||||||
|
stop.c \
|
||||||
|
execute.c \
|
||||||
|
monitor.c \
|
||||||
|
kill.c \
|
||||||
|
state.c \
|
||||||
|
freezer.c \
|
||||||
|
cgroup.c cgroup.h \
|
||||||
|
lxc.h \
|
||||||
|
utils.h \
|
||||||
|
lock.c lock.h \
|
||||||
|
namespace.h \
|
||||||
|
network.c network.h \
|
||||||
|
conf.c conf.h \
|
||||||
|
list.h \
|
||||||
|
state.c state.h \
|
||||||
|
log.c log.h \
|
||||||
|
\
|
||||||
|
nl.c nl.h \
|
||||||
|
rtnl.c rtnl.h \
|
||||||
|
genl.c genl.h
|
188
src/liblxc/cgroup.c
Normal file
188
src/liblxc/cgroup.c
Normal file
@ -0,0 +1,188 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <stdio.h>
|
||||||
|
#undef _GNU_SOURCE
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <mntent.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/inotify.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
#include <log.h>
|
||||||
|
|
||||||
|
#define MAXPRIOLEN 24
|
||||||
|
#define MTAB "/etc/mtab"
|
||||||
|
|
||||||
|
static int get_cgroup_mount(const char *mtab, char *mnt)
|
||||||
|
{
|
||||||
|
struct mntent *mntent;
|
||||||
|
FILE *file = NULL;
|
||||||
|
int err = -1;
|
||||||
|
|
||||||
|
file = setmntent(mtab, "r");
|
||||||
|
if (!file) {
|
||||||
|
lxc_log_syserror("failed to open %s", mtab);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((mntent = getmntent(file))) {
|
||||||
|
if (strcmp(mntent->mnt_fsname, "cgroup"))
|
||||||
|
continue;
|
||||||
|
strcpy(mnt, mntent->mnt_dir);
|
||||||
|
err = 0;
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
|
||||||
|
fclose(file);
|
||||||
|
out:
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lxc_link_nsgroup(const char *name, pid_t pid)
|
||||||
|
{
|
||||||
|
char *lxc, *nsgroup, cgroup[MAXPATHLEN];
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (get_cgroup_mount(MTAB, cgroup)) {
|
||||||
|
lxc_log_info("cgroup is not mounted");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
asprintf(&lxc, LXCPATH "/%s/nsgroup", name);
|
||||||
|
asprintf(&nsgroup, "%s/%d", cgroup, pid);
|
||||||
|
|
||||||
|
ret = symlink(nsgroup, lxc);
|
||||||
|
if (ret)
|
||||||
|
lxc_log_syserror("failed to create symlink %s->%s",
|
||||||
|
nsgroup, lxc);
|
||||||
|
free(lxc);
|
||||||
|
free(nsgroup);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lxc_unlink_nsgroup(const char *name)
|
||||||
|
{
|
||||||
|
char *nsgroup;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
asprintf(&nsgroup, LXCPATH "/%s/nsgroup", name);
|
||||||
|
ret = unlink(nsgroup);
|
||||||
|
free(nsgroup);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lxc_set_priority(const char *name, int priority)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
char *path = NULL, *prio = NULL;
|
||||||
|
|
||||||
|
asprintf(&path, LXCPATH "/%s/nsgroup/cpu.shares", name);
|
||||||
|
|
||||||
|
fd = open(path, O_WRONLY);
|
||||||
|
if (fd < 0) {
|
||||||
|
lxc_log_syserror("failed to open '%s'", path);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
asprintf(&prio, "%d", priority);
|
||||||
|
|
||||||
|
if (write(fd, prio, strlen(prio) + 1) < 0) {
|
||||||
|
lxc_log_syserror("failed to write to '%s'", path);
|
||||||
|
close(fd);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
out:
|
||||||
|
free(path);
|
||||||
|
free(prio);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lxc_get_priority(const char *name, int *priority)
|
||||||
|
{
|
||||||
|
int fd, ret = -1;
|
||||||
|
char *path, prio[MAXPRIOLEN];
|
||||||
|
|
||||||
|
asprintf(&path, LXCPATH "/%s/nsgroup/cpu.shares", name);
|
||||||
|
|
||||||
|
fd = open(path, O_RDONLY);
|
||||||
|
if (fd < 0) {
|
||||||
|
lxc_log_syserror("failed to open '%s'", path);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (read(fd, prio, MAXPRIOLEN) < 0) {
|
||||||
|
lxc_log_syserror("failed to read from '%s'", path);
|
||||||
|
close(fd);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
*priority = atoi(prio);
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
out:
|
||||||
|
free(path);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lxc_set_memory(const char *name, size_t memmax)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lxc_get_memory(const char *name, size_t *memmax)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lxc_get_memstat(const char *name, struct lxc_mem_stat *memstat)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lxc_set_cpuset(const char *name, long *cpumask, int len, int shared)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lxc_get_cpuset(const char *name, long *cpumask, int len, int *shared)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lxc_get_cpu_usage(const char *name, long long *usage)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
30
src/liblxc/cgroup.h
Normal file
30
src/liblxc/cgroup.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#ifndef _cgroup_h
|
||||||
|
#define _cgroup_h
|
||||||
|
|
||||||
|
int lxc_get_cgroup_mount(const char *mtab, char *mnt);
|
||||||
|
int lxc_link_nsgroup(const char *name, pid_t pid);
|
||||||
|
int lxc_unlink_nsgroup(const char *name);
|
||||||
|
|
||||||
|
#endif
|
1250
src/liblxc/conf.c
Normal file
1250
src/liblxc/conf.c
Normal file
File diff suppressed because it is too large
Load Diff
144
src/liblxc/conf.h
Normal file
144
src/liblxc/conf.h
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#ifndef _conf_h
|
||||||
|
#define _conf_h
|
||||||
|
|
||||||
|
enum {
|
||||||
|
VETH,
|
||||||
|
MACVLAN,
|
||||||
|
PHYS,
|
||||||
|
MAXCONFTYPE,
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Defines the structure to configure an ipv4 address
|
||||||
|
* @address : ipv4 address
|
||||||
|
* @broadcast : ipv4 broadcast address
|
||||||
|
* @mask : network mask
|
||||||
|
*/
|
||||||
|
struct inetdev {
|
||||||
|
struct in_addr addr;
|
||||||
|
struct in_addr bcast;
|
||||||
|
int prefix;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct route {
|
||||||
|
struct in_addr addr;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Defines the structure to configure an ipv6 address
|
||||||
|
* @flags : set the address up
|
||||||
|
* @address : ipv6 address
|
||||||
|
* @broadcast : ipv6 broadcast address
|
||||||
|
* @mask : network mask
|
||||||
|
*/
|
||||||
|
struct inet6dev {
|
||||||
|
struct in6_addr addr;
|
||||||
|
struct in6_addr bcast;
|
||||||
|
struct in6_addr acast;
|
||||||
|
int prefix;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct route6 {
|
||||||
|
struct in6_addr addr;
|
||||||
|
};
|
||||||
|
/*
|
||||||
|
* Defines a structure to configure a network device
|
||||||
|
* @ifname : network device name
|
||||||
|
* @flags : flag of the network device (IFF_UP, ... )
|
||||||
|
* @ipv4 : a list of ipv4 addresses to be set on the network device
|
||||||
|
* @ipv6 : a list of ipv6 addresses to be set on the network device
|
||||||
|
*/
|
||||||
|
struct netdev {
|
||||||
|
int flags;
|
||||||
|
char *ifname;
|
||||||
|
char *newname;
|
||||||
|
char *hwaddr;
|
||||||
|
struct list ipv4;
|
||||||
|
struct list ipv6;
|
||||||
|
struct list route4;
|
||||||
|
struct list route6;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Defines the kind of the network to use
|
||||||
|
* @type : the type of the network virtualization
|
||||||
|
* @phys : phys configuration type
|
||||||
|
* @veth : veth configuration type
|
||||||
|
* @macvlan : macvlan configuration type
|
||||||
|
*/
|
||||||
|
struct network {
|
||||||
|
int type;
|
||||||
|
struct list netdev;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Defines a structure to configure the control data and path
|
||||||
|
*/
|
||||||
|
struct cgroup {
|
||||||
|
;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Defines the global container configuration
|
||||||
|
* @chroot : the root directory to run the container
|
||||||
|
* @mount : the list of mount points
|
||||||
|
* @network : the network configuration
|
||||||
|
* @utsname : the container utsname
|
||||||
|
*/
|
||||||
|
struct lxc_conf {
|
||||||
|
char *chroot;
|
||||||
|
char *fstab;
|
||||||
|
struct utsname *utsname;
|
||||||
|
struct cgroup *cgroup;
|
||||||
|
struct list networks;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Configure the external resources for the container
|
||||||
|
*/
|
||||||
|
extern int lxc_configure(const char *name, struct lxc_conf *conf);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Remove the resources created by the configuration
|
||||||
|
*/
|
||||||
|
extern int lxc_unconfigure(const char *name);
|
||||||
|
|
||||||
|
extern int conf_create_network(const char *name, pid_t pid);
|
||||||
|
|
||||||
|
extern int conf_destroy_network(const char *name);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Configure the container from inside
|
||||||
|
*/
|
||||||
|
extern int lxc_setup(const char *name);
|
||||||
|
|
||||||
|
extern int conf_has(const char *name, const char *info);
|
||||||
|
|
||||||
|
#define conf_has_fstab(__name) conf_has(__name, "fstab")
|
||||||
|
#define conf_has_utsname(__name) conf_has(__name, "utsname")
|
||||||
|
#define conf_has_network(__name) conf_has(__name, "network")
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
153
src/liblxc/create.c
Normal file
153
src/liblxc/create.c
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/inotify.h>
|
||||||
|
#include <sys/file.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
#include <state.h>
|
||||||
|
#include <list.h>
|
||||||
|
#include <conf.h>
|
||||||
|
#include <lock.h>
|
||||||
|
#include <log.h>
|
||||||
|
|
||||||
|
static int dir_filter(const struct dirent *dirent)
|
||||||
|
{
|
||||||
|
if (!strcmp(dirent->d_name, ".") ||
|
||||||
|
!strcmp(dirent->d_name, ".."))
|
||||||
|
return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int is_empty_directory(const char *dirname)
|
||||||
|
{
|
||||||
|
struct dirent **namelist;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
n = scandir(dirname, &namelist, dir_filter, alphasort);
|
||||||
|
if (n < 0)
|
||||||
|
lxc_log_syserror("failed to scan %s directory", dirname);
|
||||||
|
return n == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int create_lxc_directory(const char *dirname)
|
||||||
|
{
|
||||||
|
char path[MAXPATHLEN];
|
||||||
|
|
||||||
|
if (mkdir(LXCPATH, 0755) && errno != EEXIST) {
|
||||||
|
lxc_log_syserror("failed to created %s directory", LXCPATH);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(path, LXCPATH "/%s", dirname);
|
||||||
|
|
||||||
|
if (mkdir(path, 0755)) {
|
||||||
|
lxc_log_syserror("failed to created %s directory", path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int remove_lxc_directory(const char *dirname)
|
||||||
|
{
|
||||||
|
char path[MAXPATHLEN];
|
||||||
|
|
||||||
|
sprintf(path, LXCPATH "/%s", dirname);
|
||||||
|
|
||||||
|
if (rmdir(path)) {
|
||||||
|
lxc_log_syserror("failed to remove %s directory", path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_empty_directory(LXCPATH)) {
|
||||||
|
if (rmdir(LXCPATH)) {
|
||||||
|
lxc_log_syserror("failed to remove %s directory", LXCPATH);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lxc_create(const char *name, struct lxc_conf *conf)
|
||||||
|
{
|
||||||
|
int lock, err = -1;
|
||||||
|
|
||||||
|
if (create_lxc_directory(name)) {
|
||||||
|
lxc_log_error("failed to create %s directory", name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
lock = lxc_get_lock(name);
|
||||||
|
if (!lock) {
|
||||||
|
lxc_log_error("'%s' is busy", name);
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lock < 0) {
|
||||||
|
lxc_log_error("failed to acquire lock on '%s':%s",
|
||||||
|
name, strerror(-lock));
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mkstate(name)) {
|
||||||
|
lxc_log_error("failed to create the state file for %s", name);
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lxc_setstate(name, STOPPED)) {
|
||||||
|
lxc_log_error("failed to set state for %s", name);
|
||||||
|
goto err_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lxc_configure(name, conf)) {
|
||||||
|
lxc_log_error("failed to set configuration for %s", name);
|
||||||
|
goto err_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = 0;
|
||||||
|
out:
|
||||||
|
lxc_put_lock(lock);
|
||||||
|
return err;
|
||||||
|
|
||||||
|
err_state:
|
||||||
|
lxc_unconfigure(name);
|
||||||
|
|
||||||
|
if (rmstate(name))
|
||||||
|
lxc_log_error("failed to remove state file for %s", name);
|
||||||
|
err:
|
||||||
|
if (remove_lxc_directory(name))
|
||||||
|
lxc_log_error("failed to cleanup lxc directory for %s", name);
|
||||||
|
goto out;
|
||||||
|
}
|
123
src/liblxc/destroy.c
Normal file
123
src/liblxc/destroy.c
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <stdio.h>
|
||||||
|
#undef _GNU_SOURCE
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/inotify.h>
|
||||||
|
#include <sys/file.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
#include <state.h>
|
||||||
|
#include <list.h>
|
||||||
|
#include <conf.h>
|
||||||
|
#include <log.h>
|
||||||
|
#include <lock.h>
|
||||||
|
|
||||||
|
static int dir_filter(const struct dirent *dirent)
|
||||||
|
{
|
||||||
|
if (!strcmp(dirent->d_name, ".") ||
|
||||||
|
!strcmp(dirent->d_name, ".."))
|
||||||
|
return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int is_empty_directory(const char *dirname)
|
||||||
|
{
|
||||||
|
struct dirent **namelist;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
n = scandir(dirname, &namelist, dir_filter, alphasort);
|
||||||
|
if (n < 0)
|
||||||
|
lxc_log_syserror("failed to scan %s directory", dirname);
|
||||||
|
return n == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int remove_lxc_directory(const char *dirname)
|
||||||
|
{
|
||||||
|
char path[MAXPATHLEN];
|
||||||
|
|
||||||
|
sprintf(path, LXCPATH "/%s", dirname);
|
||||||
|
|
||||||
|
if (rmdir(path)) {
|
||||||
|
lxc_log_syserror("failed to remove %s directory", path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_empty_directory(LXCPATH)) {
|
||||||
|
if (rmdir(LXCPATH)) {
|
||||||
|
lxc_log_syserror("failed to remove %s directory", LXCPATH);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lxc_destroy(const char *name)
|
||||||
|
{
|
||||||
|
int ret = -1, lock;
|
||||||
|
|
||||||
|
lock = lxc_get_lock(name);
|
||||||
|
if (!lock) {
|
||||||
|
lxc_log_error("'%s' is busy", name);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lock < 0) {
|
||||||
|
lxc_log_error("failed to acquire the lock for '%s':%s",
|
||||||
|
name, strerror(-lock));
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rmstate(name)) {
|
||||||
|
lxc_log_error("failed to remove state file for %s", name);
|
||||||
|
goto out_lock;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lxc_unconfigure(name)) {
|
||||||
|
lxc_log_error("failed to cleanup %s", name);
|
||||||
|
goto out_lock;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (remove_lxc_directory(name)) {
|
||||||
|
lxc_log_syserror("failed to remove '%s'", name);
|
||||||
|
goto out_lock;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
out_lock:
|
||||||
|
lxc_put_lock(lock);
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
278
src/liblxc/execute.c
Normal file
278
src/liblxc/execute.c
Normal file
@ -0,0 +1,278 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <stdio.h>
|
||||||
|
#undef _GNU_SOURCE
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/prctl.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <sys/file.h>
|
||||||
|
#include <sys/mount.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
|
||||||
|
#include <list.h>
|
||||||
|
#include <conf.h>
|
||||||
|
#include <log.h>
|
||||||
|
#include <lxc.h>
|
||||||
|
#include <lock.h>
|
||||||
|
#include <state.h>
|
||||||
|
#include <cgroup.h>
|
||||||
|
#include <namespace.h>
|
||||||
|
#include <utils.h>
|
||||||
|
|
||||||
|
LXC_TTY_HANDLER(SIGINT);
|
||||||
|
LXC_TTY_HANDLER(SIGQUIT);
|
||||||
|
|
||||||
|
int lxc_execute(const char *name, int argc, char *argv[],
|
||||||
|
lxc_callback_t preexec, void *data)
|
||||||
|
{
|
||||||
|
char *init = NULL, *val = NULL, *vinit = "[vinit]";
|
||||||
|
int fd, lock, sv[2], sync = 0, err = -1;
|
||||||
|
pid_t pid;
|
||||||
|
int clone_flags;
|
||||||
|
|
||||||
|
lock = lxc_get_lock(name);
|
||||||
|
if (!lock) {
|
||||||
|
lxc_log_error("'%s' is busy", name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lock < 0) {
|
||||||
|
lxc_log_error("failed to acquire lock on '%s':%s",
|
||||||
|
name, strerror(-lock));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fcntl(lock, F_SETFD, FD_CLOEXEC);
|
||||||
|
|
||||||
|
if (lxc_setstate(name, STARTING)) {
|
||||||
|
lxc_log_error("failed to set state %s", state2str(STARTING));
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sv)) {
|
||||||
|
lxc_log_syserror("failed to create communication socketpair");
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
LXC_TTY_ADD_HANDLER(SIGINT);
|
||||||
|
LXC_TTY_ADD_HANDLER(SIGQUIT);
|
||||||
|
|
||||||
|
clone_flags = CLONE_NEWPID|CLONE_NEWIPC|CLONE_NEWNS;
|
||||||
|
if (conf_has_utsname(name))
|
||||||
|
clone_flags |= CLONE_NEWUTS;
|
||||||
|
if (conf_has_network(name))
|
||||||
|
clone_flags |= CLONE_NEWNET;
|
||||||
|
|
||||||
|
pid = fork_ns(clone_flags);
|
||||||
|
if (pid < 0) {
|
||||||
|
lxc_log_syserror("failed to fork into a new namespace");
|
||||||
|
goto err_fork_ns;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pid) {
|
||||||
|
|
||||||
|
pid = fork();
|
||||||
|
if (pid < 0) {
|
||||||
|
lxc_log_syserror("failed to fork");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pid) {
|
||||||
|
close(sv[1]);
|
||||||
|
fcntl(sv[0], F_SETFD, FD_CLOEXEC);
|
||||||
|
|
||||||
|
if (write(sv[0], &sync, sizeof(sync)) < 0) {
|
||||||
|
lxc_log_syserror("failed to write socket");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (read(sv[0], &sync, sizeof(sync)) < 0) {
|
||||||
|
lxc_log_syserror("failed to read socket");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lxc_setup(name)) {
|
||||||
|
lxc_log_error("failed to setup the container");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
if (mount("proc", "/proc", "proc", 0, NULL)) {
|
||||||
|
lxc_log_error("failed to mount '/proc'");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
if (mount("sysfs", "/sys", "sysfs", 0, NULL)) {
|
||||||
|
lxc_log_syserror("failed to mount '/sys'");
|
||||||
|
/* continue: non fatal error until sysfs not per
|
||||||
|
namespace */
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preexec)
|
||||||
|
if (preexec(name, argc, argv, data)) {
|
||||||
|
lxc_log_error("preexec callback has failed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
execvp(argv[0], argv);
|
||||||
|
error:
|
||||||
|
lxc_log_syserror("failed to exec %s", argv[0]);
|
||||||
|
if (write(sv[0], &sync, sizeof(sync)) < 0)
|
||||||
|
lxc_log_syserror("failed to write the socket");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
setsid();
|
||||||
|
close(0);
|
||||||
|
close(1);
|
||||||
|
close(2);
|
||||||
|
|
||||||
|
if (prctl(PR_SET_NAME, vinit, 0, 0, 0))
|
||||||
|
lxc_log_syserror("failed to set process name");
|
||||||
|
|
||||||
|
close(sv[0]);
|
||||||
|
close(sv[1]);
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
int status;
|
||||||
|
if (wait(&status) < 0) {
|
||||||
|
if (errno == ECHILD)
|
||||||
|
return 0;
|
||||||
|
if (errno == EINTR)
|
||||||
|
continue;
|
||||||
|
lxc_log_syserror("failed to wait child");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
close(sv[0]);
|
||||||
|
|
||||||
|
if (read(sv[1], &sync, sizeof(sync)) < 0) {
|
||||||
|
lxc_log_syserror("failed to read the socket");
|
||||||
|
goto err_pipe_read;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clone_flags & CLONE_NEWNET && conf_create_network(name, pid)) {
|
||||||
|
lxc_log_error("failed to create the configured network");
|
||||||
|
goto err_create_network;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (write(sv[1], &sync, sizeof(sync)) < 0) {
|
||||||
|
lxc_log_syserror("failed to write the socket");
|
||||||
|
goto err_pipe_write;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = read(sv[1], &sync, sizeof(sync));
|
||||||
|
if (err < 0) {
|
||||||
|
lxc_log_error("failed to read the socket");
|
||||||
|
goto err_pipe_read2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err > 0) {
|
||||||
|
lxc_log_error("something went wrong with %d", pid);
|
||||||
|
/* TODO : check status etc ... */
|
||||||
|
waitpid(pid, NULL, 0);
|
||||||
|
goto err_child_failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
asprintf(&init, LXCPATH "/%s/init", name);
|
||||||
|
fd = open(init, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
|
||||||
|
if (fd < 0) {
|
||||||
|
lxc_log_syserror("failed to open %s", init);
|
||||||
|
goto err_open;
|
||||||
|
}
|
||||||
|
|
||||||
|
asprintf(&val, "%d", pid);
|
||||||
|
if (write(fd, val, strlen(val)) < 0) {
|
||||||
|
lxc_log_syserror("failed to write init pid");
|
||||||
|
goto err_write;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lxc_link_nsgroup(name, pid))
|
||||||
|
lxc_log_warning("cgroupfs not found: cgroup disabled");
|
||||||
|
|
||||||
|
if (lxc_setstate(name, RUNNING)) {
|
||||||
|
lxc_log_error("failed to set state to %s", state2str(RUNNING));
|
||||||
|
goto err_state_failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
wait_again:
|
||||||
|
if (waitpid(pid, NULL, 0) < 0) {
|
||||||
|
if (errno == EINTR)
|
||||||
|
goto wait_again;
|
||||||
|
lxc_log_syserror("failed to wait the pid %d", pid);
|
||||||
|
goto err_waitpid_failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lxc_setstate(name, STOPPING))
|
||||||
|
lxc_log_error("failed to set state %s", state2str(STOPPING));
|
||||||
|
|
||||||
|
if (clone_flags & CLONE_NEWNET && conf_destroy_network(name))
|
||||||
|
lxc_log_error("failed to destroy the network");
|
||||||
|
|
||||||
|
err = 0;
|
||||||
|
out:
|
||||||
|
if (lxc_setstate(name, STOPPED))
|
||||||
|
lxc_log_error("failed to set state %s", state2str(STOPPED));
|
||||||
|
|
||||||
|
lxc_unlink_nsgroup(name);
|
||||||
|
unlink(init);
|
||||||
|
free(init);
|
||||||
|
free(val);
|
||||||
|
lxc_put_lock(lock);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
|
||||||
|
err_write:
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
err_state_failed:
|
||||||
|
err_child_failed:
|
||||||
|
err_pipe_read2:
|
||||||
|
err_pipe_write:
|
||||||
|
conf_destroy_network(name);
|
||||||
|
err_create_network:
|
||||||
|
err_pipe_read:
|
||||||
|
err_open:
|
||||||
|
err_waitpid_failed:
|
||||||
|
if (lxc_setstate(name, ABORTING))
|
||||||
|
lxc_log_error("failed to set state %s", state2str(STOPPED));
|
||||||
|
|
||||||
|
kill(pid, SIGKILL);
|
||||||
|
err_fork_ns:
|
||||||
|
LXC_TTY_DEL_HANDLER(SIGQUIT);
|
||||||
|
LXC_TTY_DEL_HANDLER(SIGINT);
|
||||||
|
close(sv[0]);
|
||||||
|
close(sv[1]);
|
||||||
|
err:
|
||||||
|
goto out;
|
||||||
|
}
|
73
src/liblxc/freezer.c
Normal file
73
src/liblxc/freezer.c
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <stdio.h>
|
||||||
|
#undef _GNU_SOURCE
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/inotify.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
#include <state.h>
|
||||||
|
#include <log.h>
|
||||||
|
|
||||||
|
static int freeze_unfreeze(const char *name, int freeze)
|
||||||
|
{
|
||||||
|
char *freezer, *f = freeze?"FROZEN":"RUNNING";
|
||||||
|
int fd, ret = -1;
|
||||||
|
|
||||||
|
asprintf(&freezer, LXCPATH "/%s/nsgroup/freezer.state", name);
|
||||||
|
|
||||||
|
fd = open(freezer, O_WRONLY);
|
||||||
|
if (fd < 0) {
|
||||||
|
lxc_log_syserror("failed to open freezer for '%s'", name);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = write(fd, f, strlen(f) + 1) < 0;
|
||||||
|
close(fd);
|
||||||
|
if (ret)
|
||||||
|
lxc_log_syserror("failed to write to '%s'", freezer);
|
||||||
|
out:
|
||||||
|
free(freezer);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lxc_freeze(const char *name)
|
||||||
|
{
|
||||||
|
return freeze_unfreeze(name, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int lxc_unfreeze(const char *name)
|
||||||
|
{
|
||||||
|
return freeze_unfreeze(name, 0);
|
||||||
|
}
|
||||||
|
|
148
src/liblxc/genl.c
Normal file
148
src/liblxc/genl.c
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <linux/genetlink.h>
|
||||||
|
#include <linux/rtnetlink.h>
|
||||||
|
#include <nl.h>
|
||||||
|
#include <genl.h>
|
||||||
|
|
||||||
|
static int genetlink_resolve_family(const char *family)
|
||||||
|
{
|
||||||
|
struct nl_handler handler;
|
||||||
|
struct nlattr *attr;
|
||||||
|
struct genlmsg *request, *reply;
|
||||||
|
struct genlmsghdr *genlmsghdr;
|
||||||
|
|
||||||
|
int len, ret;
|
||||||
|
|
||||||
|
request = genlmsg_alloc(GENLMSG_GOOD_SIZE);
|
||||||
|
if (!request)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
reply = genlmsg_alloc(GENLMSG_GOOD_SIZE);
|
||||||
|
if (!reply) {
|
||||||
|
genlmsg_free(request);
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
request->nlmsghdr.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
|
||||||
|
request->nlmsghdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
|
||||||
|
request->nlmsghdr.nlmsg_type = GENL_ID_CTRL;
|
||||||
|
|
||||||
|
genlmsghdr = NLMSG_DATA(&request->nlmsghdr);
|
||||||
|
genlmsghdr->cmd = CTRL_CMD_GETFAMILY;
|
||||||
|
|
||||||
|
ret = netlink_open(&handler, NETLINK_GENERIC);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
ret = nla_put_string((struct nlmsg *)&request->nlmsghdr,
|
||||||
|
CTRL_ATTR_FAMILY_NAME, family);
|
||||||
|
if (ret)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
ret = netlink_transaction(&handler, (struct nlmsg *)&request->nlmsghdr,
|
||||||
|
(struct nlmsg *)&reply->nlmsghdr);
|
||||||
|
if (ret < 0)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
genlmsghdr = NLMSG_DATA(&reply->nlmsghdr);
|
||||||
|
len = reply->nlmsghdr.nlmsg_len;
|
||||||
|
|
||||||
|
ret = -ENOMSG;
|
||||||
|
if (reply->nlmsghdr.nlmsg_type != GENL_ID_CTRL)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (genlmsghdr->cmd != CTRL_CMD_NEWFAMILY)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
ret = -EMSGSIZE;
|
||||||
|
len -= NLMSG_LENGTH(GENL_HDRLEN);
|
||||||
|
if (len < 0)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
attr = (struct nlattr *)GENLMSG_DATA(reply);
|
||||||
|
attr = (struct nlattr *)((char *)attr + NLA_ALIGN(attr->nla_len));
|
||||||
|
|
||||||
|
ret = -ENOMSG;
|
||||||
|
if (attr->nla_type != CTRL_ATTR_FAMILY_ID)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
ret = *(__u16 *) NLA_DATA(attr);
|
||||||
|
out:
|
||||||
|
genlmsg_free(request);
|
||||||
|
genlmsg_free(reply);
|
||||||
|
netlink_close(&handler);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern int genetlink_open(struct genl_handler *handler, const char *family)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
handler->family = genetlink_resolve_family(family);
|
||||||
|
if (handler->family < 0)
|
||||||
|
return handler->family;
|
||||||
|
|
||||||
|
ret = netlink_open(&handler->nlh, NETLINK_GENERIC);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern int genetlink_close(struct genl_handler *handler)
|
||||||
|
{
|
||||||
|
return netlink_close(&handler->nlh);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern int genetlink_rcv(struct genl_handler *handler, struct genlmsg *genlmsg)
|
||||||
|
{
|
||||||
|
return netlink_rcv(&handler->nlh, (struct nlmsg *)&genlmsg->nlmsghdr);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern int genetlink_send(struct genl_handler *handler, struct genlmsg *genlmsg)
|
||||||
|
{
|
||||||
|
|
||||||
|
return netlink_send(&handler->nlh, (struct nlmsg *)&genlmsg->nlmsghdr);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern int genetlink_transaction(struct genl_handler *handler,
|
||||||
|
struct genlmsg *request, struct genlmsg *answer)
|
||||||
|
{
|
||||||
|
return netlink_transaction(&handler->nlh, (struct nlmsg *)&request->nlmsghdr,
|
||||||
|
(struct nlmsg *)&answer->nlmsghdr);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern struct genlmsg *genlmsg_alloc(size_t size)
|
||||||
|
{
|
||||||
|
size_t len = NLMSG_LENGTH(GENL_HDRLEN) + size;
|
||||||
|
return (struct genlmsg *)nlmsg_alloc(len);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern void genlmsg_free(struct genlmsg *genlmsg)
|
||||||
|
{
|
||||||
|
free(genlmsg);
|
||||||
|
}
|
121
src/liblxc/genl.h
Normal file
121
src/liblxc/genl.h
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#ifndef __genl_h
|
||||||
|
#define __genl_h
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Use this as a good size to allocate generic netlink messages
|
||||||
|
*/
|
||||||
|
#define GENLMSG_GOOD_SIZE NLMSG_GOOD_SIZE
|
||||||
|
#define GENLMSG_DATA(glh) ((void *)(NLMSG_DATA(glh) + GENL_HDRLEN))
|
||||||
|
|
||||||
|
/*
|
||||||
|
* struct genl_handler : the structure which store the netlink handler
|
||||||
|
* and the family number resulting of the auto-generating id family
|
||||||
|
* for the generic netlink protocol
|
||||||
|
*
|
||||||
|
* @nlh: the netlink socket handler
|
||||||
|
* @family: the generic netlink family assigned number
|
||||||
|
*/
|
||||||
|
struct genl_handler
|
||||||
|
{
|
||||||
|
struct nl_handler nlh;
|
||||||
|
int family;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* struct genlmsg : the struct containing the generic netlink message
|
||||||
|
* format
|
||||||
|
*
|
||||||
|
* @nlmsghdr: a netlink message header
|
||||||
|
* @genlmsghdr: a generic netlink message header pointer
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/* __attribute__ ((aligned(4))); */
|
||||||
|
struct genlmsg {
|
||||||
|
struct nlmsghdr nlmsghdr;
|
||||||
|
struct genlmsghdr genlmsghdr;
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline int genetlink_len(const struct genlmsg *genlmsg)
|
||||||
|
{
|
||||||
|
return ((genlmsg->nlmsghdr.nlmsg_len) - GENL_HDRLEN - NLMSG_HDRLEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* genetlink_open : resolve family number id and open a generic netlink socket
|
||||||
|
*
|
||||||
|
* @handler: a struct genl_handler pointer
|
||||||
|
* @family: the family name of the generic netlink protocol
|
||||||
|
*
|
||||||
|
* Returns 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
int genetlink_open(struct genl_handler *handler, const char *family);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* genetlink_close : close a generic netlink socket
|
||||||
|
*
|
||||||
|
* @handler: the handler of the socket to be closed
|
||||||
|
*
|
||||||
|
* Returns 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
int genetlink_close(struct genl_handler *handler);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* genetlink_rcv : receive a generic netlink socket, it is up
|
||||||
|
* to the caller to manage the allocation of the generic netlink message
|
||||||
|
*
|
||||||
|
* @handler: the handler of the generic netlink socket
|
||||||
|
* @genlmsg: the pointer to a generic netlink message pre-allocated
|
||||||
|
*
|
||||||
|
* Returns 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
int genetlink_rcv(struct genl_handler *handler, struct genlmsg *genlmsg);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* genetlink_send : send a generic netlink socket, it is up
|
||||||
|
* to the caller to manage the allocation of the generic netlink message
|
||||||
|
*
|
||||||
|
* @handler: the handler of the generic netlink socket
|
||||||
|
* @genlmsg: the pointer to a generic netlink message pre-allocated
|
||||||
|
*
|
||||||
|
* Returns 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
int genetlink_send(struct genl_handler *handler, struct genlmsg *genlmsg);
|
||||||
|
|
||||||
|
struct genlmsg *genlmsg_alloc(size_t size);
|
||||||
|
|
||||||
|
void genlmsg_free(struct genlmsg *genlmsg);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* genetlink_transaction : send and receive a generic netlink message in one shot
|
||||||
|
*
|
||||||
|
* @handler: the handler of the generic netlink socket
|
||||||
|
* @request: a generic netlink message containing the request to be sent
|
||||||
|
* @answer: a pre-allocated generic netlink message to receive the response
|
||||||
|
*
|
||||||
|
* Returns 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
int genetlink_transaction(struct genl_handler *handler,
|
||||||
|
struct genlmsg *request, struct genlmsg *answer);
|
||||||
|
#endif
|
74
src/liblxc/kill.c
Normal file
74
src/liblxc/kill.c
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <stdio.h>
|
||||||
|
#undef _GNU_SOURCE
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
#include <state.h>
|
||||||
|
#include <list.h>
|
||||||
|
#include <conf.h>
|
||||||
|
#include <log.h>
|
||||||
|
|
||||||
|
int lxc_kill(const char *name, int signum)
|
||||||
|
{
|
||||||
|
char *freezer = NULL, *signal = NULL;
|
||||||
|
int fd = -1, ret = -1;
|
||||||
|
|
||||||
|
if (signum < SIGHUP || signum > SIGRTMAX) {
|
||||||
|
lxc_log_error("bad signal value %d", signum);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
asprintf(&freezer, LXCPATH "/%s/nsgroup/freezer.kill", name);
|
||||||
|
asprintf(&signal, "%d", signum);
|
||||||
|
|
||||||
|
fd = open(freezer, O_WRONLY);
|
||||||
|
if (fd < 0) {
|
||||||
|
lxc_log_syserror("failed to open %s for %s", freezer, name);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (write(fd, &signal, strlen(signal)) < 0) {
|
||||||
|
lxc_log_syserror("failed to write to %s", freezer);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
out:
|
||||||
|
close(fd);
|
||||||
|
free(freezer);
|
||||||
|
free(signal);
|
||||||
|
return ret;
|
||||||
|
}
|
23
src/liblxc/list.c
Normal file
23
src/liblxc/list.c
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <list.h>
|
57
src/liblxc/list.h
Normal file
57
src/liblxc/list.h
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
#ifndef _list_h
|
||||||
|
#define _list_h
|
||||||
|
|
||||||
|
struct list {
|
||||||
|
void *elem;
|
||||||
|
struct list *next;
|
||||||
|
struct list *prev;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define init_list(l) { .next = l, .prev = l, }
|
||||||
|
|
||||||
|
#define list_for_each(__iterator, __list) \
|
||||||
|
for (__iterator = (__list)->next; \
|
||||||
|
__iterator != __list; \
|
||||||
|
__iterator = __iterator->next)
|
||||||
|
|
||||||
|
static inline void list_init(struct list *list)
|
||||||
|
{
|
||||||
|
list->elem = NULL;
|
||||||
|
list->next = list->prev = list;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void list_add_elem(struct list *list, void *elem)
|
||||||
|
{
|
||||||
|
list->elem = elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void *list_first_elem(struct list *list)
|
||||||
|
{
|
||||||
|
return list->next->elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int list_empty(struct list *list)
|
||||||
|
{
|
||||||
|
return list == list->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void list_add(struct list *list, struct list *new)
|
||||||
|
{
|
||||||
|
struct list *next = list->next;
|
||||||
|
next->prev = new;
|
||||||
|
new->next = next;
|
||||||
|
new->prev = list;
|
||||||
|
list->next = new;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void list_del(struct list *list)
|
||||||
|
{
|
||||||
|
struct list *next, *prev;
|
||||||
|
|
||||||
|
next = list->next;
|
||||||
|
prev = list->prev;
|
||||||
|
next->prev = prev;
|
||||||
|
prev->next = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
61
src/liblxc/lock.c
Normal file
61
src/liblxc/lock.c
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <stdio.h>
|
||||||
|
#undef _GNU_SOURCE
|
||||||
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/file.h>
|
||||||
|
#include <lxc.h>
|
||||||
|
|
||||||
|
int lxc_get_lock(const char *name)
|
||||||
|
{
|
||||||
|
char *lock;
|
||||||
|
int fd, ret;
|
||||||
|
|
||||||
|
asprintf(&lock, LXCPATH "/%s", name);
|
||||||
|
fd = open(lock, O_RDONLY|O_DIRECTORY, S_IRUSR|S_IWUSR);
|
||||||
|
if (fd < 0) {
|
||||||
|
ret = -errno;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flock(fd, LOCK_EX|LOCK_NB)) {
|
||||||
|
ret = errno == EWOULDBLOCK ? 0 : -errno;
|
||||||
|
close(fd);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = fd;
|
||||||
|
out:
|
||||||
|
free(lock);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void lxc_put_lock(int lock)
|
||||||
|
{
|
||||||
|
flock(lock, LOCK_UN);
|
||||||
|
close(lock);
|
||||||
|
}
|
30
src/liblxc/lock.h
Normal file
30
src/liblxc/lock.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#ifndef _lock_h
|
||||||
|
#define _lock_h
|
||||||
|
|
||||||
|
extern int lxc_get_lock(const char *name);
|
||||||
|
|
||||||
|
extern int lxc_put_lock(int lock);
|
||||||
|
|
||||||
|
#endif
|
9
src/liblxc/log.c
Normal file
9
src/liblxc/log.c
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#include <log.h>
|
||||||
|
|
||||||
|
#define MAXTIMELEN 47;
|
||||||
|
#define ERRNO_FORMAT "%d (%s)"
|
||||||
|
|
20
src/liblxc/log.h
Normal file
20
src/liblxc/log.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#ifndef _log_h
|
||||||
|
#define _log_h
|
||||||
|
|
||||||
|
#define lxc_log(format, level, ...) do { \
|
||||||
|
fprintf(stderr, "[%s] \t%s:%d - " format "\n", \
|
||||||
|
level, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define lxc_log_error(format, ...) lxc_log(format, "error", ##__VA_ARGS__);
|
||||||
|
#define lxc_log_warning(format, ...) lxc_log(format, "warning", ##__VA_ARGS__);
|
||||||
|
#define lxc_log_info(format, ...) lxc_log(format, "info", ##__VA_ARGS__);
|
||||||
|
#define lxc_log_debug(format, ...) lxc_log(format, "debug", ##__VA_ARGS__);
|
||||||
|
#define lxc_log_trace(format, ...) lxc_log(format, "trace", ##__VA_ARGS__);
|
||||||
|
#define lxc_log_syserror(format, ...) do { \
|
||||||
|
fprintf(stderr, "[SYSERROR][%s] \t%s:%d - " format "\n", \
|
||||||
|
strerror(errno),__FUNCTION__, __LINE__, \
|
||||||
|
##__VA_ARGS__); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#endif
|
220
src/liblxc/lxc.h
Normal file
220
src/liblxc/lxc.h
Normal file
@ -0,0 +1,220 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#ifndef __lxc_h
|
||||||
|
#define __lxc_h
|
||||||
|
|
||||||
|
/**
|
||||||
|
Following code is for liblxc.
|
||||||
|
|
||||||
|
liblxc/lxc.h will contain exports of liblxc
|
||||||
|
**/
|
||||||
|
|
||||||
|
#define LXCPATH "/var/lxc"
|
||||||
|
#define MAXPIDLEN 20
|
||||||
|
|
||||||
|
struct lxc_mem_stat;
|
||||||
|
struct lxc_conf;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
STOPPED, STARTING, RUNNING, STOPPING,
|
||||||
|
ABORTING, FREEZING, FROZEN, MAX_STATE,
|
||||||
|
} lxc_state_t;
|
||||||
|
|
||||||
|
typedef int (*lxc_callback_t)(const char *name, int argc,
|
||||||
|
char *argv[], void *data);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create the container object. Creates the /lxc/<name> directory
|
||||||
|
* and fills it with the files corresponding to the configuration
|
||||||
|
* structure passed as parameter.
|
||||||
|
* The first container will create the /lxc directory.
|
||||||
|
* @name : the name of the container
|
||||||
|
* @conf : the configuration data for the container
|
||||||
|
* Returns 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
extern int lxc_create(const char *name, struct lxc_conf *conf);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Destroy the container object. Removes the files into the /lxc/<name>
|
||||||
|
* directory and removes the <name> directory.
|
||||||
|
* The last container will remove the /lxc directory.
|
||||||
|
* @name : the name of the container to be detroyed
|
||||||
|
* Returns 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
extern int lxc_destroy(const char *name);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Start the container previously created with lxc_create.
|
||||||
|
* @name : the name of the container
|
||||||
|
* @argc : the number of arguments of the command line
|
||||||
|
* @argv : an array of char * corresponding to the commande line
|
||||||
|
* @prestart : hooks will be called just before the command execs
|
||||||
|
* Returns 0 on sucess, < 0 otherwise
|
||||||
|
*/
|
||||||
|
extern int lxc_start(const char *name, int argc, char *argv[],
|
||||||
|
lxc_callback_t prestart, void *data);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create the container and start it directly, using the argc, argv
|
||||||
|
* parameter. This command is for application container.
|
||||||
|
* At the end of the exec'ed command, the container will
|
||||||
|
* automatically autodestroy.
|
||||||
|
* @name : the name of the container
|
||||||
|
* @conf : the configuration data
|
||||||
|
* @argc : the number of arguments of the command line
|
||||||
|
* @argv : an array of char * corresponding to the commande line
|
||||||
|
* @preexec : hooks will be called just before the command execs
|
||||||
|
* Returns 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
extern int lxc_execute(const char *name, int argc, char *argv[],
|
||||||
|
lxc_callback_t preexec, void *data);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Stop the container previously started with lxc_start or lxc_exec
|
||||||
|
* @name : the name of the container
|
||||||
|
* Returns 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
extern int lxc_stop(const char *name);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Monitor the container, each time the state of the container
|
||||||
|
* is changed, a state data is send through a file descriptor passed to
|
||||||
|
* the function with output_fd.
|
||||||
|
* The function will block until the container is destroyed.
|
||||||
|
* @name : the name of the contaier
|
||||||
|
* @output_fd : the file descriptor where to send the states
|
||||||
|
* Returns 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
extern int lxc_monitor(const char *name, int output_fd);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Show the console of the container.
|
||||||
|
* @name : the name of container
|
||||||
|
* Returns 0 on sucess, < 0 otherwise
|
||||||
|
*/
|
||||||
|
extern int lxc_console(const char *name);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Freeze all the tasks running inside the container <name>
|
||||||
|
* @name : the container name
|
||||||
|
* Returns 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
extern int lxc_freeze(const char *name);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Unfreeze all previously frozen tasks.
|
||||||
|
* @name : the name of the container
|
||||||
|
* Return 0 on sucess, < 0 otherwise
|
||||||
|
*/
|
||||||
|
extern int lxc_unfreeze(const char *name);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Retrieve the container state
|
||||||
|
* @name : the name of the container
|
||||||
|
* Returns the state of the container on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
extern lxc_state_t lxc_state(const char *name);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Send a signal to all processes of the container. This is the same
|
||||||
|
* behavior of the well-known 'killpg' command except it is related
|
||||||
|
* to all tasks belonging to a container.
|
||||||
|
* @name : the name of the container
|
||||||
|
* @signum : the signal number to be sent
|
||||||
|
* Returns 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
extern int lxc_kill(const char *name, int signum);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Change the priority of the container
|
||||||
|
* @name : the name of the container
|
||||||
|
* @priority : an integer representing the desired priority
|
||||||
|
* Returns 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
extern int lxc_cgroup_set_priority(const char *name, int priority);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Retrieve the priority of the container
|
||||||
|
* @name : the name of the container
|
||||||
|
* @priority : a pointer to an int where the priority will be stored
|
||||||
|
* Returns 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
extern int lxc_cgroup_get_priority(const char *name, int *priority);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set the maximum memory usable by the container
|
||||||
|
* @name : the name of the container
|
||||||
|
* @memmax : the maximum usable memory in bytes
|
||||||
|
* Returns 0 on sucess, < 0 otherwise
|
||||||
|
*/
|
||||||
|
extern int lxc_cgroup_set_memory(const char *name, size_t memmax);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the maximum memory usable by the container
|
||||||
|
* @name : the name of the container
|
||||||
|
* @memmax : a pointer to a size_t where the value will be stored
|
||||||
|
* Returns 0 on sucess, < 0 otherwise
|
||||||
|
*/
|
||||||
|
extern int lxc_cgroup_get_memory(const char *name, size_t *memmax);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the memory statistics of the container
|
||||||
|
* @name : the name of the container
|
||||||
|
* @memstat : a pointer to a structure defining the memory statistic
|
||||||
|
* Returns 0 on sucess, < 0 otherwise
|
||||||
|
*/
|
||||||
|
extern int lxc_cgroup_get_memstat(const char *name,
|
||||||
|
struct lxc_mem_stat *memstat);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set the cpuset for the container
|
||||||
|
* @name : the name of the container
|
||||||
|
* @cpumask : a bitmask representing the cpu maps
|
||||||
|
* @len : the len of the bitmask
|
||||||
|
* @shared : a boolean specifying if the cpu could be shared with
|
||||||
|
* processes not belonging to the container
|
||||||
|
* Returns 0 on sucess, < 0 otherwise
|
||||||
|
*/
|
||||||
|
extern int lxc_cgroup_set_cpuset(const char *name, long *cpumask,
|
||||||
|
int len, int shared);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the actual cpuset for the container
|
||||||
|
* @cpumask : a bitmask representing the cpu maps
|
||||||
|
* @len : the len of the bitmask
|
||||||
|
* @shared : a boolean specifying if the cpu is shared with
|
||||||
|
* processes not belonging to the container
|
||||||
|
* Returns 0 on sucess, < 0 otherwise
|
||||||
|
*/
|
||||||
|
extern int lxc_cgroup_get_cpuset(const char *name, long *cpumask,
|
||||||
|
int len, int *shared);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the cpu usage of the container
|
||||||
|
* @name : the name of the container
|
||||||
|
* @usage : a value to be filled with the current container cpu usage
|
||||||
|
* Returns 0 on sucess, < 0 otherwise
|
||||||
|
*/
|
||||||
|
extern int lxc_cgroup_get_cpu_usage(const char *name, long long *usage);
|
||||||
|
|
||||||
|
#endif
|
97
src/liblxc/monitor.c
Normal file
97
src/liblxc/monitor.c
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/inotify.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
#include <state.h>
|
||||||
|
#include <log.h>
|
||||||
|
|
||||||
|
int lxc_monitor(const char *name, int output_fd)
|
||||||
|
{
|
||||||
|
char path[MAXPATHLEN];
|
||||||
|
int err = -1, nfd, wfd, state;
|
||||||
|
|
||||||
|
nfd = inotify_init();
|
||||||
|
if (nfd < 0) {
|
||||||
|
lxc_log_syserror("failed to initialize inotify");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(path, MAXPATHLEN, LXCPATH "/%s/state", name);
|
||||||
|
|
||||||
|
wfd = inotify_add_watch(nfd, path, IN_DELETE_SELF|IN_CLOSE_WRITE);
|
||||||
|
if (wfd < 0) {
|
||||||
|
lxc_log_syserror("failed to add a watch on %s", path);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(;;) {
|
||||||
|
struct inotify_event evt;
|
||||||
|
|
||||||
|
if (read(nfd, &evt, sizeof(evt)) < 0) {
|
||||||
|
lxc_log_syserror("failed to read inotify event");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (evt.mask & IN_CLOSE_WRITE) {
|
||||||
|
|
||||||
|
state = lxc_getstate(name);
|
||||||
|
if (state < 0) {
|
||||||
|
lxc_log_error("failed to get the state for %s",
|
||||||
|
name);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (write(output_fd, &state, sizeof(state)) < 0) {
|
||||||
|
lxc_log_syserror("failed to send state to %d",
|
||||||
|
output_fd);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (evt.mask & IN_DELETE_SELF) {
|
||||||
|
close(output_fd);
|
||||||
|
err = 0;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
lxc_log_error("unknown evt for inotity (%d)", evt.mask);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
inotify_rm_watch(nfd, wfd);
|
||||||
|
close(nfd);
|
||||||
|
return err;
|
||||||
|
}
|
71
src/liblxc/namespace.h
Normal file
71
src/liblxc/namespace.h
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#ifndef __namespace_h
|
||||||
|
#define __namespace_h
|
||||||
|
|
||||||
|
#include <syscall.h>
|
||||||
|
#ifndef CLONE_FS
|
||||||
|
# define CLONE_FS 0x00000200
|
||||||
|
#endif
|
||||||
|
#ifndef CLONE_NEWNS
|
||||||
|
# define CLONE_NEWNS 0x00020000
|
||||||
|
#endif
|
||||||
|
#ifndef CLONE_NEWUTS
|
||||||
|
# define CLONE_NEWUTS 0x04000000
|
||||||
|
#endif
|
||||||
|
#ifndef CLONE_NEWIPC
|
||||||
|
# define CLONE_NEWIPC 0x08000000
|
||||||
|
#endif
|
||||||
|
#ifndef CLONE_NEWUSER
|
||||||
|
# define CLONE_NEWUSER 0x10000000
|
||||||
|
#endif
|
||||||
|
#ifndef CLONE_NEWPID
|
||||||
|
# define CLONE_NEWPID 0x20000000
|
||||||
|
#endif
|
||||||
|
#ifndef CLONE_NEWNET
|
||||||
|
# define CLONE_NEWNET 0x40000000
|
||||||
|
#endif
|
||||||
|
#ifndef __NR_unshare
|
||||||
|
# ifdef __i386__
|
||||||
|
# define __NR_unshare 310
|
||||||
|
# elif __x86_64__
|
||||||
|
# define __NR_unshare 272
|
||||||
|
# elif __ia64__
|
||||||
|
# define __NR_unshare 1296
|
||||||
|
# elif __s390__
|
||||||
|
# define __NR_unshare 303
|
||||||
|
# elif __powerpc__
|
||||||
|
# define __NR_unshare 282
|
||||||
|
#else
|
||||||
|
# error "unsupported architecture"
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
#if __i386__ || __x86_64__ || __s390__ || __powerpc__
|
||||||
|
# define fork_ns(flags) syscall(SYS_clone, flags|SIGCHLD, NULL);
|
||||||
|
#elif __ia64__
|
||||||
|
# define fork_ns(flags) syscall(SYS_clone2, flags|SIGCHLD, NULL);
|
||||||
|
#else
|
||||||
|
# error "unsupported architecture"
|
||||||
|
#endif
|
||||||
|
#define unshare_ns(flags) syscall(__NR_unshare, flags, NULL);
|
||||||
|
#endif
|
727
src/liblxc/network.c
Normal file
727
src/liblxc/network.c
Normal file
@ -0,0 +1,727 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <stdio.h>
|
||||||
|
#undef _GNU_SOURCe
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
#include <net/if_arp.h>
|
||||||
|
#include <net/ethernet.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <linux/netlink.h>
|
||||||
|
#include <linux/rtnetlink.h>
|
||||||
|
#include <linux/sockios.h>
|
||||||
|
#include <linux/if_bridge.h>
|
||||||
|
#include <nl.h>
|
||||||
|
#include <network.h>
|
||||||
|
|
||||||
|
#ifndef IFLA_LINKMODE
|
||||||
|
# define IFLA_LINKMODE 17
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef IFLA_LINKINFO
|
||||||
|
# define IFLA_LINKINFO 18
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef IFLA_NET_NS_PID
|
||||||
|
# define IFLA_NET_NS_PID 19
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef IFLA_INFO_KIND
|
||||||
|
# define IFLA_INFO_KIND 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef IFLA_INFO_DATA
|
||||||
|
# define IFLA_INFO_DATA 2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef VETH_INFO_PEER
|
||||||
|
# define VETH_INFO_PEER 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct link_req {
|
||||||
|
struct nlmsg nlmsg;
|
||||||
|
struct ifinfomsg ifinfomsg;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ip_req {
|
||||||
|
struct nlmsg nlmsg;
|
||||||
|
struct ifaddrmsg ifa;
|
||||||
|
};
|
||||||
|
|
||||||
|
int device_move(const char *name, pid_t pid)
|
||||||
|
{
|
||||||
|
struct nl_handler nlh;
|
||||||
|
struct nlmsg *nlmsg = NULL;
|
||||||
|
struct link_req *link_req;
|
||||||
|
int index, len, err = -1;
|
||||||
|
|
||||||
|
if (netlink_open(&nlh, NETLINK_ROUTE))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
len = strlen(name);
|
||||||
|
if (len == 1 || len > IFNAMSIZ)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
|
||||||
|
if (!nlmsg)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
index = if_nametoindex(name);
|
||||||
|
if (!index)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
link_req = (struct link_req *)nlmsg;
|
||||||
|
link_req->ifinfomsg.ifi_family = AF_UNSPEC;
|
||||||
|
link_req->ifinfomsg.ifi_index = index;
|
||||||
|
nlmsg->nlmsghdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
|
||||||
|
nlmsg->nlmsghdr.nlmsg_flags = NLM_F_REQUEST|NLM_F_ACK;
|
||||||
|
nlmsg->nlmsghdr.nlmsg_type = RTM_NEWLINK;
|
||||||
|
|
||||||
|
if (nla_put_u32(nlmsg, IFLA_NET_NS_PID, pid))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (nla_put_string(nlmsg, IFLA_IFNAME, name))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (netlink_transaction(&nlh, nlmsg, nlmsg))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
err = 0;
|
||||||
|
out:
|
||||||
|
netlink_close(&nlh);
|
||||||
|
nlmsg_free(nlmsg);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern int device_delete(const char *name)
|
||||||
|
{
|
||||||
|
struct nl_handler nlh;
|
||||||
|
struct nlmsg *nlmsg = NULL, *answer = NULL;
|
||||||
|
struct link_req *link_req;
|
||||||
|
int index, len, err = -1;
|
||||||
|
|
||||||
|
if (netlink_open(&nlh, NETLINK_ROUTE))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
len = strlen(name);
|
||||||
|
if (len == 1 || len > IFNAMSIZ)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
|
||||||
|
if (!nlmsg)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
answer = nlmsg_alloc(NLMSG_GOOD_SIZE);
|
||||||
|
if (!answer)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
index = if_nametoindex(name);
|
||||||
|
if (!index)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
link_req = (struct link_req *)nlmsg;
|
||||||
|
link_req->ifinfomsg.ifi_family = AF_UNSPEC;
|
||||||
|
link_req->ifinfomsg.ifi_index = index;
|
||||||
|
nlmsg->nlmsghdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
|
||||||
|
nlmsg->nlmsghdr.nlmsg_flags = NLM_F_ACK|NLM_F_REQUEST;
|
||||||
|
nlmsg->nlmsghdr.nlmsg_type = RTM_DELLINK;
|
||||||
|
|
||||||
|
if (nla_put_string(nlmsg, IFLA_IFNAME, name))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (netlink_transaction(&nlh, nlmsg, answer))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
err = 0;
|
||||||
|
out:
|
||||||
|
netlink_close(&nlh);
|
||||||
|
nlmsg_free(answer);
|
||||||
|
nlmsg_free(nlmsg);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int device_set_flag(const char *name, int flag)
|
||||||
|
{
|
||||||
|
struct nl_handler nlh;
|
||||||
|
struct nlmsg *nlmsg = NULL, *answer = NULL;
|
||||||
|
struct link_req *link_req;
|
||||||
|
int index, len, err = -1;
|
||||||
|
|
||||||
|
if (netlink_open(&nlh, NETLINK_ROUTE))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
len = strlen(name);
|
||||||
|
if (len == 1 || len > IFNAMSIZ)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
|
||||||
|
if (!nlmsg)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
answer = nlmsg_alloc(NLMSG_GOOD_SIZE);
|
||||||
|
if (!answer)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
index = if_nametoindex(name);
|
||||||
|
if (!index)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
link_req = (struct link_req *)nlmsg;
|
||||||
|
link_req->ifinfomsg.ifi_family = AF_UNSPEC;
|
||||||
|
link_req->ifinfomsg.ifi_index = index;
|
||||||
|
link_req->ifinfomsg.ifi_change |= IFF_UP;
|
||||||
|
link_req->ifinfomsg.ifi_flags |= flag;
|
||||||
|
nlmsg->nlmsghdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
|
||||||
|
nlmsg->nlmsghdr.nlmsg_flags = NLM_F_REQUEST|NLM_F_ACK;
|
||||||
|
nlmsg->nlmsghdr.nlmsg_type = RTM_NEWLINK;
|
||||||
|
|
||||||
|
err = netlink_transaction(&nlh, nlmsg, answer);
|
||||||
|
if (err < 0)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
err = 0;
|
||||||
|
out:
|
||||||
|
netlink_close(&nlh);
|
||||||
|
nlmsg_free(nlmsg);
|
||||||
|
nlmsg_free(answer);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
int device_up(const char *name)
|
||||||
|
{
|
||||||
|
return device_set_flag(name, IFF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
int device_down(const char *name)
|
||||||
|
{
|
||||||
|
return device_set_flag(name, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int device_rename(const char *oldname, const char *newname)
|
||||||
|
{
|
||||||
|
struct nl_handler nlh;
|
||||||
|
struct nlmsg *nlmsg = NULL, *answer = NULL;
|
||||||
|
struct link_req *link_req;
|
||||||
|
int index, len, err = -1;
|
||||||
|
|
||||||
|
if (netlink_open(&nlh, NETLINK_ROUTE))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
len = strlen(oldname);
|
||||||
|
if (len == 1 || len > IFNAMSIZ)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
len = strlen(newname);
|
||||||
|
if (len == 1 || len > IFNAMSIZ)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
|
||||||
|
if (!nlmsg)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
answer = nlmsg_alloc(NLMSG_GOOD_SIZE);
|
||||||
|
if (!answer)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
index = if_nametoindex(oldname);
|
||||||
|
if (!index)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
link_req = (struct link_req *)nlmsg;
|
||||||
|
link_req->ifinfomsg.ifi_family = AF_UNSPEC;
|
||||||
|
link_req->ifinfomsg.ifi_index = index;
|
||||||
|
nlmsg->nlmsghdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
|
||||||
|
nlmsg->nlmsghdr.nlmsg_flags = NLM_F_ACK|NLM_F_REQUEST;
|
||||||
|
nlmsg->nlmsghdr.nlmsg_type = RTM_NEWLINK;
|
||||||
|
|
||||||
|
if (nla_put_string(nlmsg, IFLA_IFNAME, newname))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (netlink_transaction(&nlh, nlmsg, answer))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
err = 0;
|
||||||
|
out:
|
||||||
|
netlink_close(&nlh);
|
||||||
|
nlmsg_free(answer);
|
||||||
|
nlmsg_free(nlmsg);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
int veth_create(const char *name1, const char *name2)
|
||||||
|
{
|
||||||
|
struct nl_handler nlh;
|
||||||
|
struct nlmsg *nlmsg = NULL, *answer = NULL;
|
||||||
|
struct link_req *link_req;
|
||||||
|
struct rtattr *nest1, *nest2, *nest3;
|
||||||
|
int len, err = -1;
|
||||||
|
|
||||||
|
if (netlink_open(&nlh, NETLINK_ROUTE))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
len = strlen(name1);
|
||||||
|
if (len == 1 || len > IFNAMSIZ)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
len = strlen(name2);
|
||||||
|
if (len == 1 || len > IFNAMSIZ)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
|
||||||
|
if (!nlmsg)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
answer = nlmsg_alloc(NLMSG_GOOD_SIZE);
|
||||||
|
if (!answer)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
link_req = (struct link_req *)nlmsg;
|
||||||
|
link_req->ifinfomsg.ifi_family = AF_UNSPEC;
|
||||||
|
nlmsg->nlmsghdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
|
||||||
|
nlmsg->nlmsghdr.nlmsg_flags =
|
||||||
|
NLM_F_REQUEST|NLM_F_CREATE|NLM_F_EXCL|NLM_F_ACK;
|
||||||
|
nlmsg->nlmsghdr.nlmsg_type = RTM_NEWLINK;
|
||||||
|
|
||||||
|
nest1 = nla_begin_nested(nlmsg, IFLA_LINKINFO);
|
||||||
|
if (!nest1)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (nla_put_string(nlmsg, IFLA_INFO_KIND, "veth"))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
nest2 = nla_begin_nested(nlmsg, IFLA_INFO_DATA);
|
||||||
|
if (!nest2)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
nest3 = nla_begin_nested(nlmsg, VETH_INFO_PEER);
|
||||||
|
if (!nest3)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
nlmsg->nlmsghdr.nlmsg_len += sizeof(struct ifinfomsg);
|
||||||
|
|
||||||
|
if (nla_put_string(nlmsg, IFLA_IFNAME, name2))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
nla_end_nested(nlmsg, nest3);
|
||||||
|
|
||||||
|
nla_end_nested(nlmsg, nest2);
|
||||||
|
|
||||||
|
nla_end_nested(nlmsg, nest1);
|
||||||
|
|
||||||
|
if (nla_put_string(nlmsg, IFLA_IFNAME, name1))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (netlink_transaction(&nlh, nlmsg, answer))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
err = 0;
|
||||||
|
out:
|
||||||
|
netlink_close(&nlh);
|
||||||
|
nlmsg_free(answer);
|
||||||
|
nlmsg_free(nlmsg);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
int macvlan_create(const char *master, const char *name)
|
||||||
|
{
|
||||||
|
struct nl_handler nlh;
|
||||||
|
struct nlmsg *nlmsg = NULL, *answer = NULL;
|
||||||
|
struct link_req *link_req;
|
||||||
|
struct rtattr *nest;
|
||||||
|
int index, len, err = -1;
|
||||||
|
|
||||||
|
if (netlink_open(&nlh, NETLINK_ROUTE))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
len = strlen(master);
|
||||||
|
if (len == 1 || len > IFNAMSIZ)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
len = strlen(name);
|
||||||
|
if (len == 1 || len > IFNAMSIZ)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
|
||||||
|
if (!nlmsg)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
answer = nlmsg_alloc(NLMSG_GOOD_SIZE);
|
||||||
|
if (!answer)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
index = if_nametoindex(master);
|
||||||
|
if (!index)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
link_req = (struct link_req *)nlmsg;
|
||||||
|
link_req->ifinfomsg.ifi_family = AF_UNSPEC;
|
||||||
|
nlmsg->nlmsghdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
|
||||||
|
nlmsg->nlmsghdr.nlmsg_flags =
|
||||||
|
NLM_F_REQUEST|NLM_F_CREATE|NLM_F_EXCL|NLM_F_ACK;
|
||||||
|
nlmsg->nlmsghdr.nlmsg_type = RTM_NEWLINK;
|
||||||
|
|
||||||
|
nest = nla_begin_nested(nlmsg, IFLA_LINKINFO);
|
||||||
|
if (!nest)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (nla_put_string(nlmsg, IFLA_INFO_KIND, "macvlan"))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
nla_end_nested(nlmsg, nest);
|
||||||
|
|
||||||
|
if (nla_put_u32(nlmsg, IFLA_LINK, index))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (nla_put_string(nlmsg, IFLA_IFNAME, name))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (netlink_transaction(&nlh, nlmsg, answer))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
err = 0;
|
||||||
|
out:
|
||||||
|
netlink_close(&nlh);
|
||||||
|
nlmsg_free(answer);
|
||||||
|
nlmsg_free(nlmsg);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int proc_sys_net_write(const char *path, const char *value)
|
||||||
|
{
|
||||||
|
int fd, err = 0;
|
||||||
|
|
||||||
|
fd = open(path, O_WRONLY);
|
||||||
|
if (fd < 0)
|
||||||
|
return -errno;
|
||||||
|
|
||||||
|
if (write(fd, value, strlen(value)) < 0)
|
||||||
|
err = -errno;
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ip_forward_set(const char *ifname, int family, int flag)
|
||||||
|
{
|
||||||
|
char *path;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (family != AF_INET && family != AF_INET6)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
asprintf(&path, "/proc/sys/net/%s/conf/%s/forwarding",
|
||||||
|
family == AF_INET?"ipv4":"ipv6" , ifname);
|
||||||
|
|
||||||
|
ret = proc_sys_net_write(path, flag?"1":"0");
|
||||||
|
free(path);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ip_forward_on(const char *ifname, int family)
|
||||||
|
{
|
||||||
|
return ip_forward_set(ifname, family, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ip_forward_off(const char *ifname, int family)
|
||||||
|
{
|
||||||
|
return ip_forward_set(ifname, family, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int neigh_proxy_set(const char *ifname, int family, int flag)
|
||||||
|
{
|
||||||
|
char path[MAXPATHLEN];
|
||||||
|
|
||||||
|
if (family != AF_INET && family != AF_INET6)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
sprintf(path, "/proc/sys/net/%s/conf/%s/%s",
|
||||||
|
family == AF_INET?"ipv4":"ipv6" , ifname,
|
||||||
|
family == AF_INET?"proxy_arp":"proxy_ndp");
|
||||||
|
|
||||||
|
return proc_sys_net_write(path, flag?"1":"0");
|
||||||
|
}
|
||||||
|
|
||||||
|
int neigh_proxy_on(const char *name, int family)
|
||||||
|
{
|
||||||
|
return neigh_proxy_set(name, family, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int neigh_proxy_off(const char *name, int family)
|
||||||
|
{
|
||||||
|
return neigh_proxy_set(name, family, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int lxc_convert_mac(char *macaddr, struct sockaddr *sockaddr)
|
||||||
|
{
|
||||||
|
unsigned char *data;
|
||||||
|
char c;
|
||||||
|
int i = 0;
|
||||||
|
unsigned val;
|
||||||
|
|
||||||
|
sockaddr->sa_family = ARPHRD_ETHER;
|
||||||
|
data = (unsigned char *)sockaddr->sa_data;
|
||||||
|
|
||||||
|
while ((*macaddr != '\0') && (i < ETH_ALEN)) {
|
||||||
|
val = 0;
|
||||||
|
c = *macaddr++;
|
||||||
|
if (isdigit(c))
|
||||||
|
val = c - '0';
|
||||||
|
else if (c >= 'a' && c <= 'f')
|
||||||
|
val = c - 'a' + 10;
|
||||||
|
else if (c >= 'A' && c <= 'F')
|
||||||
|
val = c - 'A' + 10;
|
||||||
|
else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
val <<= 4;
|
||||||
|
c = *macaddr;
|
||||||
|
if (isdigit(c))
|
||||||
|
val |= c - '0';
|
||||||
|
else if (c >= 'a' && c <= 'f')
|
||||||
|
val |= c - 'a' + 10;
|
||||||
|
else if (c >= 'A' && c <= 'F')
|
||||||
|
val |= c - 'A' + 10;
|
||||||
|
else if (c == ':' || c == 0)
|
||||||
|
val >>= 4;
|
||||||
|
else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (c != 0)
|
||||||
|
macaddr++;
|
||||||
|
*data++ = (unsigned char) (val & 0377);
|
||||||
|
i++;
|
||||||
|
|
||||||
|
if (*macaddr == ':')
|
||||||
|
macaddr++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ip_addr_add(const char *ifname, const char *addr,
|
||||||
|
int prefix, const char *bcast)
|
||||||
|
{
|
||||||
|
struct nl_handler nlh;
|
||||||
|
struct in_addr in_addr;
|
||||||
|
/* struct in_addr in_bcast; */
|
||||||
|
struct nlmsg *nlmsg = NULL, *answer = NULL;
|
||||||
|
struct ip_req *ip_req;
|
||||||
|
int ifindex, err = -1;
|
||||||
|
|
||||||
|
if (netlink_open(&nlh, NETLINK_ROUTE))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (inet_pton(AF_INET, addr, (void *)&in_addr) < 0)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
/* if (inet_pton(AF_INET, bcast, (void *)&in_bcast) < 0) */
|
||||||
|
/* goto out; */
|
||||||
|
|
||||||
|
nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
|
||||||
|
if (!nlmsg)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
answer = nlmsg_alloc(NLMSG_GOOD_SIZE);
|
||||||
|
if (!answer)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
ifindex = if_nametoindex(ifname);
|
||||||
|
if (!ifindex)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
ip_req = (struct ip_req *)nlmsg;
|
||||||
|
ip_req->nlmsg.nlmsghdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
|
||||||
|
ip_req->nlmsg.nlmsghdr.nlmsg_flags =
|
||||||
|
NLM_F_ACK|NLM_F_REQUEST|NLM_F_CREATE|NLM_F_EXCL;
|
||||||
|
ip_req->nlmsg.nlmsghdr.nlmsg_type = RTM_NEWADDR;
|
||||||
|
ip_req->ifa.ifa_prefixlen = prefix;
|
||||||
|
ip_req->ifa.ifa_index = ifindex;
|
||||||
|
ip_req->ifa.ifa_family = AF_INET;
|
||||||
|
ip_req->ifa.ifa_scope = 0;
|
||||||
|
|
||||||
|
if (nla_put_buffer(nlmsg, IFA_LOCAL, &in_addr, sizeof(in_addr)))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (nla_put_buffer(nlmsg, IFA_ADDRESS, &in_addr, sizeof(in_addr)))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
/* if (in_bcast.s_addr != INADDR_ANY) */
|
||||||
|
/* if (nla_put_buffer(nlmsg, IFA_BROADCAST, &in_bcast, */
|
||||||
|
/* sizeof(in_bcast))) */
|
||||||
|
/* goto out; */
|
||||||
|
|
||||||
|
if (netlink_transaction(&nlh, nlmsg, answer))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
err = 0;
|
||||||
|
out:
|
||||||
|
netlink_close(&nlh);
|
||||||
|
nlmsg_free(answer);
|
||||||
|
nlmsg_free(nlmsg);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ip6_addr_add(const char *ifname, const char *addr,
|
||||||
|
int prefix, const char *bcast)
|
||||||
|
{
|
||||||
|
struct nl_handler nlh;
|
||||||
|
struct in6_addr in6_addr;
|
||||||
|
/* struct in6_addr in6_bcast; */
|
||||||
|
struct nlmsg *nlmsg = NULL, *answer = NULL;
|
||||||
|
struct ip_req *ip_req;
|
||||||
|
int ifindex, err = -1;
|
||||||
|
|
||||||
|
if (netlink_open(&nlh, NETLINK_ROUTE))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (inet_pton(AF_INET6, addr, (void *)&in6_addr) < 0)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
|
||||||
|
/* if (inet_pton(AF_INET6, bcast, (void *)&in6_bcast) < 0) */
|
||||||
|
/* goto out; */
|
||||||
|
|
||||||
|
nlmsg = nlmsg_alloc(NLMSG_GOOD_SIZE);
|
||||||
|
if (!nlmsg)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
answer = nlmsg_alloc(NLMSG_GOOD_SIZE);
|
||||||
|
if (!answer)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
ifindex = if_nametoindex(ifname);
|
||||||
|
if (!ifindex)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
ip_req = (struct ip_req *)nlmsg;
|
||||||
|
ip_req->nlmsg.nlmsghdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
|
||||||
|
ip_req->nlmsg.nlmsghdr.nlmsg_flags =
|
||||||
|
NLM_F_ACK|NLM_F_REQUEST|NLM_F_CREATE|NLM_F_EXCL;
|
||||||
|
ip_req->nlmsg.nlmsghdr.nlmsg_type = RTM_NEWADDR;
|
||||||
|
ip_req->ifa.ifa_prefixlen = prefix;
|
||||||
|
ip_req->ifa.ifa_index = ifindex;
|
||||||
|
ip_req->ifa.ifa_family = AF_INET6;
|
||||||
|
ip_req->ifa.ifa_scope = 0;
|
||||||
|
|
||||||
|
if (nla_put_buffer(nlmsg, IFA_LOCAL, &in6_addr, sizeof(in6_addr)))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (nla_put_buffer(nlmsg, IFA_ADDRESS, &in6_addr, sizeof(in6_addr)))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
/* if (in6_bcast.s6_addr != in6addr_any.s6_addr) */
|
||||||
|
/* if (nla_put_buffer(nlmsg, IFA_BROADCAST, &in6_bcast, */
|
||||||
|
/* sizeof(in6_bcast))) */
|
||||||
|
/* goto out; */
|
||||||
|
|
||||||
|
if (netlink_transaction(&nlh, nlmsg, answer))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
err = 0;
|
||||||
|
out:
|
||||||
|
netlink_close(&nlh);
|
||||||
|
nlmsg_free(answer);
|
||||||
|
nlmsg_free(nlmsg);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int bridge_add_del_interface(const char *bridge,
|
||||||
|
const char *ifname, int detach)
|
||||||
|
{
|
||||||
|
int fd, index, err;
|
||||||
|
struct ifreq ifr;
|
||||||
|
|
||||||
|
if (strlen(ifname) > IFNAMSIZ)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
index = if_nametoindex(ifname);
|
||||||
|
if (!index)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
if (fd < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
strncpy(ifr.ifr_name, bridge, IFNAMSIZ);
|
||||||
|
ifr.ifr_ifindex = index;
|
||||||
|
err = ioctl(fd, detach?SIOCBRDELIF:SIOCBRADDIF, &ifr);
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
int bridge_attach(const char *bridge, const char *ifname)
|
||||||
|
{
|
||||||
|
return bridge_add_del_interface(bridge, ifname, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int bridge_detach(const char *bridge, const char *ifname)
|
||||||
|
{
|
||||||
|
return bridge_add_del_interface(bridge, ifname, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int lxc_configure_veth(const char *veth1, const char *veth2, const char *bridge)
|
||||||
|
{
|
||||||
|
int err = -1;
|
||||||
|
if (veth_create(veth1, veth2)) {
|
||||||
|
fprintf(stderr, "failed to create veth interfaces %s/%s\n",
|
||||||
|
veth1, veth2);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bridge_attach(bridge, veth1)) {
|
||||||
|
fprintf(stderr, "failed to attach %s to %s\n",
|
||||||
|
veth1, bridge);
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = 0;
|
||||||
|
out:
|
||||||
|
return err;
|
||||||
|
err:
|
||||||
|
device_delete(veth1);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lxc_configure_macvlan(const char *link, const char *peer)
|
||||||
|
{
|
||||||
|
if (macvlan_create(link, peer)) {
|
||||||
|
fprintf(stderr, "failed to create %s", peer);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
126
src/liblxc/network.h
Normal file
126
src/liblxc/network.h
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#ifndef _network_h
|
||||||
|
#define _network_h
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create a macvlan network device
|
||||||
|
*/
|
||||||
|
extern int lxc_configure_macvlan(const char *link, const char *peer);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create a veth pair virtual device
|
||||||
|
*/
|
||||||
|
extern int lxc_configure_veth(const char *veth1, const char *veth2,
|
||||||
|
const char *bridge);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert a string mac address to a socket structure
|
||||||
|
*/
|
||||||
|
extern int lxc_convert_mac(char *macaddr, struct sockaddr *sockaddr);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Move a device between namespaces
|
||||||
|
*/
|
||||||
|
extern int device_move(const char *name, pid_t pid);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Delete a network device
|
||||||
|
*/
|
||||||
|
extern int device_delete(const char *name);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set the device network up
|
||||||
|
*/
|
||||||
|
extern int device_up(const char *name);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set the device network down
|
||||||
|
*/
|
||||||
|
extern int device_down(const char *name);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Change the device name
|
||||||
|
*/
|
||||||
|
extern int device_rename(const char *oldname, const char *newname);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create a veth network device
|
||||||
|
*/
|
||||||
|
extern int veth_create(const char *name1, const char *name2);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create a macvlan network device
|
||||||
|
*/
|
||||||
|
extern int macvlan_create(const char *master, const char *name);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Activate forwarding
|
||||||
|
*/
|
||||||
|
extern int ip_forward_on(const char *name, int family);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Disable forwarding
|
||||||
|
*/
|
||||||
|
extern int ip_forward_off(const char *name, int family);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set ip address
|
||||||
|
*/
|
||||||
|
extern int ip_addr_add(const char *ifname, const char *addr,
|
||||||
|
int prefix, const char *bcast);
|
||||||
|
|
||||||
|
extern int ip6_addr_add(const char *ifname, const char *addr,
|
||||||
|
int prefix, const char *bcast);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Attach an interface to the bridge
|
||||||
|
*/
|
||||||
|
extern int bridge_attach(const char *bridge, const char *ifname);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Detach an interface from the bridge
|
||||||
|
*/
|
||||||
|
extern int bridge_detach(const char *bridge, const char *ifname);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create default gateway
|
||||||
|
*/
|
||||||
|
extern int route_create_default(const char *addr, const char *ifname, int gateway);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Delete default gateway
|
||||||
|
*/
|
||||||
|
extern int route_delete_default(const char *addr, const char *ifname, int gateway);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Activate neighbor proxying
|
||||||
|
*/
|
||||||
|
extern int neigh_proxy_on(const char *name, int family);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Disable neighbor proxying
|
||||||
|
*/
|
||||||
|
extern int neigh_proxy_off(const char *name, int family);
|
||||||
|
|
||||||
|
#endif
|
260
src/liblxc/nl.c
Normal file
260
src/liblxc/nl.c
Normal file
@ -0,0 +1,260 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <linux/netlink.h>
|
||||||
|
#include <linux/rtnetlink.h>
|
||||||
|
#include <nl.h>
|
||||||
|
|
||||||
|
#define NLMSG_TAIL(nmsg) \
|
||||||
|
((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
|
||||||
|
|
||||||
|
extern size_t nlmsg_len(const struct nlmsg *nlmsg)
|
||||||
|
{
|
||||||
|
return nlmsg->nlmsghdr.nlmsg_len - NLMSG_HDRLEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern void *nlmsg_data(struct nlmsg *nlmsg)
|
||||||
|
{
|
||||||
|
char *data = ((char *)nlmsg) + NLMSG_ALIGN(sizeof(struct nlmsghdr));
|
||||||
|
if (!nlmsg_len(nlmsg))
|
||||||
|
return NULL;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int nla_put(struct nlmsg *nlmsg, int attr,
|
||||||
|
const void *data, size_t len)
|
||||||
|
{
|
||||||
|
struct rtattr *rta;
|
||||||
|
size_t rtalen = RTA_LENGTH(len);
|
||||||
|
|
||||||
|
rta = NLMSG_TAIL(&nlmsg->nlmsghdr);
|
||||||
|
rta->rta_type = attr;
|
||||||
|
rta->rta_len = rtalen;
|
||||||
|
memcpy(RTA_DATA(rta), data, len);
|
||||||
|
nlmsg->nlmsghdr.nlmsg_len =
|
||||||
|
NLMSG_ALIGN(nlmsg->nlmsghdr.nlmsg_len) + RTA_ALIGN(rtalen);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern int nla_put_buffer(struct nlmsg *nlmsg, int attr,
|
||||||
|
const void *data, size_t size)
|
||||||
|
{
|
||||||
|
return nla_put(nlmsg, attr, data, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern int nla_put_string(struct nlmsg *nlmsg, int attr, const char *string)
|
||||||
|
{
|
||||||
|
return nla_put(nlmsg, attr, string, strlen(string) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern int nla_put_u32(struct nlmsg *nlmsg, int attr, int value)
|
||||||
|
{
|
||||||
|
return nla_put(nlmsg, attr, &value, sizeof(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
extern int nla_put_attr(struct nlmsg *nlmsg, int attr)
|
||||||
|
{
|
||||||
|
return nla_put(nlmsg, attr, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct rtattr *nla_begin_nested(struct nlmsg *nlmsg, int attr)
|
||||||
|
{
|
||||||
|
struct rtattr *rtattr = NLMSG_TAIL(&nlmsg->nlmsghdr);
|
||||||
|
|
||||||
|
if (nla_put_attr(nlmsg, attr))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return rtattr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nla_end_nested(struct nlmsg *nlmsg, struct rtattr *attr)
|
||||||
|
{
|
||||||
|
attr->rta_len = (void *)NLMSG_TAIL(&nlmsg->nlmsghdr) - (void *)attr;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern struct nlmsg *nlmsg_alloc(size_t size)
|
||||||
|
{
|
||||||
|
struct nlmsg *nlmsg;
|
||||||
|
size_t len = NLMSG_ALIGN(size) + NLMSG_ALIGN(sizeof(struct nlmsghdr *));
|
||||||
|
|
||||||
|
nlmsg = (struct nlmsg *)malloc(len);
|
||||||
|
if (!nlmsg)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
memset(nlmsg, 0, len);
|
||||||
|
nlmsg->nlmsghdr.nlmsg_len = NLMSG_ALIGN(size);
|
||||||
|
|
||||||
|
return nlmsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern void nlmsg_free(struct nlmsg *nlmsg)
|
||||||
|
{
|
||||||
|
free(nlmsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern int netlink_rcv(struct nl_handler *handler, struct nlmsg *answer)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
struct sockaddr_nl nladdr;
|
||||||
|
struct iovec iov = {
|
||||||
|
.iov_base = answer,
|
||||||
|
.iov_len = answer->nlmsghdr.nlmsg_len,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct msghdr msg = {
|
||||||
|
.msg_name = &nladdr,
|
||||||
|
.msg_namelen = sizeof(nladdr),
|
||||||
|
.msg_iov = &iov,
|
||||||
|
.msg_iovlen = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
memset(&nladdr, 0, sizeof(nladdr));
|
||||||
|
nladdr.nl_family = AF_NETLINK;
|
||||||
|
nladdr.nl_pid = 0;
|
||||||
|
nladdr.nl_groups = 0;
|
||||||
|
|
||||||
|
again:
|
||||||
|
ret = recvmsg(handler->fd, &msg, 0);
|
||||||
|
if (ret < 0) {
|
||||||
|
if (errno == EINTR)
|
||||||
|
goto again;
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ret)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (msg.msg_flags & MSG_TRUNC)
|
||||||
|
return -EMSGSIZE;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern int netlink_send(struct nl_handler *handler, struct nlmsg *nlmsg)
|
||||||
|
{
|
||||||
|
struct sockaddr_nl nladdr;
|
||||||
|
struct iovec iov = {
|
||||||
|
.iov_base = (void*)nlmsg,
|
||||||
|
.iov_len = nlmsg->nlmsghdr.nlmsg_len,
|
||||||
|
};
|
||||||
|
struct msghdr msg = {
|
||||||
|
.msg_name = &nladdr,
|
||||||
|
.msg_namelen = sizeof(nladdr),
|
||||||
|
.msg_iov = &iov,
|
||||||
|
.msg_iovlen = 1,
|
||||||
|
};
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
memset(&nladdr, 0, sizeof(nladdr));
|
||||||
|
nladdr.nl_family = AF_NETLINK;
|
||||||
|
nladdr.nl_pid = 0;
|
||||||
|
nladdr.nl_groups = 0;
|
||||||
|
|
||||||
|
ret = sendmsg(handler->fd, &msg, 0);
|
||||||
|
if (ret < 0) {
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern int netlink_transaction(struct nl_handler *handler,
|
||||||
|
struct nlmsg *request, struct nlmsg *answer)
|
||||||
|
{
|
||||||
|
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = netlink_send(handler, request);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
ret = netlink_rcv(handler, answer);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
if (answer->nlmsghdr.nlmsg_type == NLMSG_ERROR) {
|
||||||
|
struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(answer);
|
||||||
|
errno = -err->error;
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern int netlink_open(struct nl_handler *handler, int protocol)
|
||||||
|
{
|
||||||
|
socklen_t socklen;
|
||||||
|
int sndbuf = 32768;
|
||||||
|
int rcvbuf = 32768;
|
||||||
|
|
||||||
|
memset(handler, 0, sizeof(*handler));
|
||||||
|
|
||||||
|
handler->fd = socket(AF_NETLINK, SOCK_RAW, protocol);
|
||||||
|
if (handler->fd < 0)
|
||||||
|
return -errno;
|
||||||
|
|
||||||
|
if (setsockopt(handler->fd, SOL_SOCKET, SO_SNDBUF,
|
||||||
|
&sndbuf, sizeof(sndbuf)) < 0)
|
||||||
|
return -errno;
|
||||||
|
|
||||||
|
if (setsockopt(handler->fd, SOL_SOCKET, SO_RCVBUF,
|
||||||
|
&rcvbuf,sizeof(rcvbuf)) < 0)
|
||||||
|
return -errno;
|
||||||
|
|
||||||
|
memset(&handler->local, 0, sizeof(handler->local));
|
||||||
|
handler->local.nl_family = AF_NETLINK;
|
||||||
|
handler->local.nl_groups = 0;
|
||||||
|
|
||||||
|
if (bind(handler->fd, (struct sockaddr*)&handler->local,
|
||||||
|
sizeof(handler->local)) < 0)
|
||||||
|
return -errno;
|
||||||
|
|
||||||
|
socklen = sizeof(handler->local);
|
||||||
|
if (getsockname(handler->fd, (struct sockaddr*)&handler->local,
|
||||||
|
&socklen) < 0)
|
||||||
|
return -errno;
|
||||||
|
|
||||||
|
if (socklen != sizeof(handler->local))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
if (handler->local.nl_family != AF_NETLINK)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
handler->seq = time(NULL);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern int netlink_close(struct nl_handler *handler)
|
||||||
|
{
|
||||||
|
close(handler->fd);
|
||||||
|
handler->fd = -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
228
src/liblxc/nl.h
Normal file
228
src/liblxc/nl.h
Normal file
@ -0,0 +1,228 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#ifndef __nl_h
|
||||||
|
#define __nl_h
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Use this as a good size to allocate generic netlink messages
|
||||||
|
*/
|
||||||
|
#ifndef PAGE_SIZE
|
||||||
|
#define PAGE_SIZE 4096
|
||||||
|
#endif
|
||||||
|
#define NLMSG_GOOD_SIZE (2*PAGE_SIZE)
|
||||||
|
#define NLMSG_TAIL(nmsg) \
|
||||||
|
((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
|
||||||
|
#define NLA_DATA(na) ((void *)((char*)(na) + NLA_HDRLEN))
|
||||||
|
#define NLA_NEXT_ATTR(attr) ((void *)((char *)attr) + NLA_ALIGN(attr->nla_len))
|
||||||
|
|
||||||
|
/*
|
||||||
|
* struct nl_handler : the handler for netlink sockets, this structure
|
||||||
|
* is used all along the netlink socket life cycle to specify the
|
||||||
|
* netlink socket to be used.
|
||||||
|
*
|
||||||
|
* @fd: the file descriptor of the netlink socket
|
||||||
|
* @seq: the sequence number of the netlink messages
|
||||||
|
* @local: the bind address
|
||||||
|
* @peer: the peer address
|
||||||
|
*/
|
||||||
|
struct nl_handler {
|
||||||
|
int fd;
|
||||||
|
int seq;
|
||||||
|
struct sockaddr_nl local;
|
||||||
|
struct sockaddr_nl peer;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* struct nlmsg : the netlink message structure, it consists just
|
||||||
|
* on a definition for a nlmsghdr. This message is to be used to
|
||||||
|
* be allocated with netlink_alloc.
|
||||||
|
* @nlmsghdr : a pointer to a netlink message header, this field
|
||||||
|
* _must_ be always the first field of this structure
|
||||||
|
*/
|
||||||
|
struct nlmsg {
|
||||||
|
struct nlmsghdr nlmsghdr;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* netlink_open : open a netlink socket, the function will
|
||||||
|
* fill the handler with the right value
|
||||||
|
*
|
||||||
|
* @handler: a netlink handler to be used all along the netlink
|
||||||
|
* socket life cycle
|
||||||
|
* @protocol: specify the protocol to be used when opening the
|
||||||
|
* netlink socket
|
||||||
|
*
|
||||||
|
* Return 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
int netlink_open(struct nl_handler *handler, int protocol);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* netlink_close : close a netlink socket, after this call,
|
||||||
|
* the handler is no longer valid
|
||||||
|
*
|
||||||
|
* @handler: a handler to the netlink socket
|
||||||
|
*
|
||||||
|
* Returns 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
int netlink_close(struct nl_handler *handler);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* netlink_rcv : receive a netlink message from the kernel.
|
||||||
|
* It is up to the caller to manage the allocation of the
|
||||||
|
* netlink message
|
||||||
|
*
|
||||||
|
* @handler: a handler to the netlink socket
|
||||||
|
* @nlmsg: a netlink message
|
||||||
|
*
|
||||||
|
* Returns 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
int netlink_rcv(struct nl_handler *handler, struct nlmsg *nlmsg);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* netlink_send: send a netlink message to the kernel. It is up
|
||||||
|
* to the caller to manage the allocate of the netlink message
|
||||||
|
*
|
||||||
|
* @handler: a handler to the netlink socket
|
||||||
|
* @nlmsg: a netlink message
|
||||||
|
*
|
||||||
|
* Returns 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
int netlink_send(struct nl_handler *handler, struct nlmsg *nlmsg);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* netlink_transaction: send a request to the kernel and read the response.
|
||||||
|
* This is useful for transactional protocol. It is up to the caller
|
||||||
|
* to manage the allocation of the netlink message.
|
||||||
|
*
|
||||||
|
* @handler: a handler to a opened netlink socket
|
||||||
|
* @request: a netlink message pointer containing the request
|
||||||
|
* @answer: a netlink message pointer to receive the result
|
||||||
|
*
|
||||||
|
* Returns 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
int netlink_transaction(struct nl_handler *handler,
|
||||||
|
struct nlmsg *request, struct nlmsg *anwser);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nla_put_string: copy a null terminated string to a netlink message
|
||||||
|
* attribute
|
||||||
|
*
|
||||||
|
* @nlmsg: the netlink message to be filled
|
||||||
|
* @attr: the attribute name of the string
|
||||||
|
* @string: a null terminated string to be copied to the netlink message
|
||||||
|
*
|
||||||
|
* Returns 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
int nla_put_string(struct nlmsg *nlmsg, int attr, const char *string);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nla_put_buffer: copy a buffer with a specified size to a netlink
|
||||||
|
* message attribute
|
||||||
|
*
|
||||||
|
* @nlmsg: the netlink message to be filled
|
||||||
|
* @attr: the attribute name of the string
|
||||||
|
* @data: a pointer to a buffer
|
||||||
|
* @size: the size of the buffer
|
||||||
|
*
|
||||||
|
* Returns 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
int nla_put_buffer(struct nlmsg *nlmsg, int attr,
|
||||||
|
const void *data, size_t size);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nla_put_u32: copy an integer to a netlink message attribute
|
||||||
|
*
|
||||||
|
* @nlmsg: the netlink message to be filled
|
||||||
|
* @attr: the attribute name of the integer
|
||||||
|
* @string: an integer to be copied to the netlink message
|
||||||
|
*
|
||||||
|
* Returns 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
int nla_put_u32(struct nlmsg *nlmsg, int attr, int value);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nla_put_attr: add an attribute name to a netlink
|
||||||
|
*
|
||||||
|
* @nlmsg: the netlink message to be filled
|
||||||
|
* @attr: the attribute name of the integer
|
||||||
|
*
|
||||||
|
* Returns 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
int nla_put_attr(struct nlmsg *nlmsg, int attr);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nla_begin_nested: begin the nesting attribute
|
||||||
|
*
|
||||||
|
* @nlmsg: the netlink message to be filled
|
||||||
|
* @attr: the netsted attribute name
|
||||||
|
*
|
||||||
|
* Returns current nested pointer to be reused
|
||||||
|
* to nla_end_nested.
|
||||||
|
*/
|
||||||
|
struct rtattr *nla_begin_nested(struct nlmsg *nlmsg, int attr);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nla_end_nested: end the nesting attribute
|
||||||
|
*
|
||||||
|
* @nlmsg: the netlink message
|
||||||
|
* @nested: the nested pointer
|
||||||
|
*
|
||||||
|
* Returns the current
|
||||||
|
*/
|
||||||
|
void nla_end_nested(struct nlmsg *nlmsg, struct rtattr *attr);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nlmsg_allocate : allocate a netlink message. The netlink format message
|
||||||
|
* is a header, a padding, a payload and a padding again.
|
||||||
|
* When a netlink message is allocated, the size specify the
|
||||||
|
* payload we want. So the real size of the allocated message
|
||||||
|
* is sizeof(header) + sizeof(padding) + payloadsize + sizeof(padding),
|
||||||
|
* in other words, the function will allocate more than specified. When
|
||||||
|
* the buffer is allocated, the content is zeroed.
|
||||||
|
* The function will also fill the field nlmsg_len with computed size.
|
||||||
|
* If the allocation must be for the specified size, just use malloc.
|
||||||
|
*
|
||||||
|
* @size: the size of the payload to be allocated
|
||||||
|
*
|
||||||
|
* Returns a pointer to the newly allocated netlink message, NULL otherwise
|
||||||
|
*/
|
||||||
|
struct nlmsg *nlmsg_alloc(size_t size);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nlmsg_free : free a previously allocate message
|
||||||
|
*
|
||||||
|
* @nlmsg: the netlink message to be freed
|
||||||
|
*/
|
||||||
|
void nlmsg_free(struct nlmsg *nlmsg);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nlmsg_data : returns a pointer to the data contained in the netlink message
|
||||||
|
*
|
||||||
|
* @nlmsg : the netlink message to get the data
|
||||||
|
*
|
||||||
|
* Returns a pointer to the netlink data or NULL if there is no data
|
||||||
|
*/
|
||||||
|
void *nlmsg_data(struct nlmsg *nlmsg);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
72
src/liblxc/rtnl.c
Normal file
72
src/liblxc/rtnl.c
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <linux/netlink.h>
|
||||||
|
#include <linux/rtnetlink.h>
|
||||||
|
#include <nl.h>
|
||||||
|
#include <rtnl.h>
|
||||||
|
|
||||||
|
extern int rtnetlink_open(struct rtnl_handler *handler)
|
||||||
|
{
|
||||||
|
return netlink_open(&handler->nlh, NETLINK_ROUTE);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern int rtnetlink_close(struct rtnl_handler *handler)
|
||||||
|
{
|
||||||
|
return netlink_close(&handler->nlh);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern int rtnetlink_rcv(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg)
|
||||||
|
{
|
||||||
|
return netlink_rcv(&handler->nlh, (struct nlmsg *)&rtnlmsg->nlmsghdr);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern int rtnetlink_send(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg)
|
||||||
|
{
|
||||||
|
|
||||||
|
return netlink_send(&handler->nlh, (struct nlmsg *)&rtnlmsg->nlmsghdr);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern int rtnetlink_transaction(struct rtnl_handler *handler,
|
||||||
|
struct rtnlmsg *request, struct rtnlmsg *answer)
|
||||||
|
{
|
||||||
|
return netlink_transaction(&handler->nlh, (struct nlmsg *)&request->nlmsghdr,
|
||||||
|
(struct nlmsg *)&answer->nlmsghdr);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern struct rtnlmsg *rtnlmsg_alloc(size_t size)
|
||||||
|
{
|
||||||
|
/* size_t len = NLMSG_LENGTH(NLMSG_ALIGN(sizeof(struct rtnlmsghdr))) + size; */
|
||||||
|
/* return (struct rtnlmsg *)nlmsg_alloc(len); */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern void rtnlmsg_free(struct rtnlmsg *rtnlmsg)
|
||||||
|
{
|
||||||
|
free(rtnlmsg);
|
||||||
|
}
|
110
src/liblxc/rtnl.h
Normal file
110
src/liblxc/rtnl.h
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#ifndef __genl_h
|
||||||
|
#define __genl_h
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Use this as a good size to allocate route netlink messages
|
||||||
|
*/
|
||||||
|
#define RTNLMSG_GOOD_SIZE NLMSG_GOOD_SIZE
|
||||||
|
#define RTNLMSG_DATA(glh) ((void *)(NLMSG_DATA(glh) + RTNL_HDRLEN))
|
||||||
|
|
||||||
|
/*
|
||||||
|
* struct genl_handler : the structure which store the netlink handler
|
||||||
|
* and the family number
|
||||||
|
*
|
||||||
|
* @nlh: the netlink socket handler
|
||||||
|
*/
|
||||||
|
struct rtnl_handler
|
||||||
|
{
|
||||||
|
struct nl_handler nlh;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* struct rtnlmsg : the struct containing the route netlink message
|
||||||
|
* format
|
||||||
|
*
|
||||||
|
* @nlmsghdr: a netlink message header
|
||||||
|
* @rtnlmsghdr: a route netlink message header pointer
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
struct rtnlmsg {
|
||||||
|
struct nlmsghdr nlmsghdr;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* rtnetlink_open : open a route netlink socket
|
||||||
|
*
|
||||||
|
* @handler: a struct rtnl_handler pointer
|
||||||
|
*
|
||||||
|
* Returns 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
int rtnetlink_open(struct rtnl_handler *handler);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* genetlink_close : close a route netlink socket
|
||||||
|
*
|
||||||
|
* @handler: the handler of the socket to be closed
|
||||||
|
*
|
||||||
|
* Returns 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
int rtnetlink_close(struct rtnl_handler *handler);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* rtnetlink_rcv : receive a route netlink socket, it is up
|
||||||
|
* to the caller to manage the allocation of the route netlink message
|
||||||
|
*
|
||||||
|
* @handler: the handler of the route netlink socket
|
||||||
|
* @rtnlmsg: the pointer to a route netlink message pre-allocated
|
||||||
|
*
|
||||||
|
* Returns 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
int rtnetlink_rcv(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* rtnetlink_send : send a route netlink socket, it is up
|
||||||
|
* to the caller to manage the allocation of the route netlink message
|
||||||
|
*
|
||||||
|
* @handler: the handler of the route netlink socket
|
||||||
|
* @rtnlmsg: the pointer to a netlink message pre-allocated
|
||||||
|
*
|
||||||
|
* Returns 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
int rtnetlink_send(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg);
|
||||||
|
|
||||||
|
struct genlmsg *genlmsg_alloc(size_t size);
|
||||||
|
|
||||||
|
void rtnlmsg_free(struct rtnlmsg *rtnlmsg);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* rtnetlink_transaction : send and receive a route netlink message in one shot
|
||||||
|
*
|
||||||
|
* @handler: the handler of the route netlink socket
|
||||||
|
* @request: a route netlink message containing the request to be sent
|
||||||
|
* @answer: a pre-allocated route netlink message to receive the response
|
||||||
|
*
|
||||||
|
* Returns 0 on success, < 0 otherwise
|
||||||
|
*/
|
||||||
|
int rtnetlink_transaction(struct rtnl_handler *handler,
|
||||||
|
struct rtnlmsg *request, struct rtnlmsg *answer);
|
||||||
|
#endif
|
261
src/liblxc/start.c
Normal file
261
src/liblxc/start.c
Normal file
@ -0,0 +1,261 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <stdio.h>
|
||||||
|
#undef _GNU_SOURCE
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <mntent.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/file.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/prctl.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
#include <namespace.h>
|
||||||
|
#include <network.h>
|
||||||
|
#include <state.h>
|
||||||
|
#include <cgroup.h>
|
||||||
|
#include <utils.h>
|
||||||
|
#include <list.h>
|
||||||
|
#include <conf.h>
|
||||||
|
#include <log.h>
|
||||||
|
#include <lock.h>
|
||||||
|
|
||||||
|
LXC_TTY_HANDLER(SIGINT);
|
||||||
|
LXC_TTY_HANDLER(SIGQUIT);
|
||||||
|
|
||||||
|
int lxc_start(const char *name, int argc, char *argv[],
|
||||||
|
lxc_callback_t prestart, void *data)
|
||||||
|
{
|
||||||
|
char *init = NULL, *val = NULL;
|
||||||
|
int fd, lock, sv[2], sync = 0, err = -1;
|
||||||
|
pid_t pid;
|
||||||
|
int clone_flags;
|
||||||
|
|
||||||
|
lock = lxc_get_lock(name);
|
||||||
|
if (!lock) {
|
||||||
|
lxc_log_error("'%s' is busy", name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lock < 0) {
|
||||||
|
lxc_log_error("failed to acquire lock on '%s':%s",
|
||||||
|
name, strerror(-lock));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fcntl(lock, F_SETFD, FD_CLOEXEC);
|
||||||
|
|
||||||
|
/* Begin the set the state to STARTING*/
|
||||||
|
if (lxc_setstate(name, STARTING)) {
|
||||||
|
lxc_log_error("failed to set state %s", state2str(STARTING));
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Synchro socketpair */
|
||||||
|
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sv)) {
|
||||||
|
lxc_log_syserror("failed to create communication socketpair");
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Avoid signals from terminal */
|
||||||
|
LXC_TTY_ADD_HANDLER(SIGINT);
|
||||||
|
LXC_TTY_ADD_HANDLER(SIGQUIT);
|
||||||
|
|
||||||
|
clone_flags = CLONE_NEWPID|CLONE_NEWIPC;
|
||||||
|
if (conf_has_fstab(name))
|
||||||
|
clone_flags |= CLONE_NEWNS;
|
||||||
|
if (conf_has_utsname(name))
|
||||||
|
clone_flags |= CLONE_NEWUTS;
|
||||||
|
if (conf_has_network(name))
|
||||||
|
clone_flags |= CLONE_NEWNET;
|
||||||
|
|
||||||
|
/* Create a process in a new set of namespaces */
|
||||||
|
pid = fork_ns(clone_flags);
|
||||||
|
if (pid < 0) {
|
||||||
|
lxc_log_syserror("failed to fork into a new namespace");
|
||||||
|
goto err_fork_ns;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pid) {
|
||||||
|
|
||||||
|
close(sv[1]);
|
||||||
|
|
||||||
|
/* Be sure we don't inherit this after the exec */
|
||||||
|
fcntl(sv[0], F_SETFD, FD_CLOEXEC);
|
||||||
|
|
||||||
|
/* Tell our father he can begin to configure the container */
|
||||||
|
if (write(sv[0], &sync, sizeof(sync)) < 0) {
|
||||||
|
lxc_log_syserror("failed to write socket");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Wait for the father to finish the configuration */
|
||||||
|
if (read(sv[0], &sync, sizeof(sync)) < 0) {
|
||||||
|
lxc_log_syserror("failed to read socket");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Setup the container, ip, names, utsname, ... */
|
||||||
|
if (lxc_setup(name)) {
|
||||||
|
lxc_log_error("failed to setup the container");
|
||||||
|
if (write(sv[0], &sync, sizeof(sync)) < 0)
|
||||||
|
lxc_log_syserror("failed to write the socket");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If a callback has been passed, call it before doing exec */
|
||||||
|
if (prestart)
|
||||||
|
if (prestart(name, argc, argv, data)) {
|
||||||
|
lxc_log_error("prestart callback has failed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
execvp(argv[0], argv);
|
||||||
|
lxc_log_syserror("failed to exec %s", argv[0]);
|
||||||
|
|
||||||
|
/* If the exec fails, tell that to our father */
|
||||||
|
if (write(sv[0], &sync, sizeof(sync)) < 0)
|
||||||
|
lxc_log_syserror("failed to write the socket");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
close(sv[0]);
|
||||||
|
|
||||||
|
/* Wait for the child to be ready */
|
||||||
|
if (read(sv[1], &sync, sizeof(sync)) < 0) {
|
||||||
|
lxc_log_syserror("failed to read the socket");
|
||||||
|
goto err_pipe_read;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create the network configuration */
|
||||||
|
if (clone_flags & CLONE_NEWNET && conf_create_network(name, pid)) {
|
||||||
|
lxc_log_error("failed to create the configured network");
|
||||||
|
goto err_create_network;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Tell the child to continue its initialization */
|
||||||
|
if (write(sv[1], &sync, sizeof(sync)) < 0) {
|
||||||
|
lxc_log_syserror("failed to write the socket");
|
||||||
|
goto err_pipe_write;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Wait for the child to exec or returning an error */
|
||||||
|
err = read(sv[1], &sync, sizeof(sync));
|
||||||
|
if (err < 0) {
|
||||||
|
lxc_log_error("failed to read the socket");
|
||||||
|
goto err_pipe_read2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err > 0) {
|
||||||
|
lxc_log_error("something went wrong with %d", pid);
|
||||||
|
/* TODO : check status etc ... */
|
||||||
|
waitpid(pid, NULL, 0);
|
||||||
|
goto err_child_failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
asprintf(&val, "%d\n", pid);
|
||||||
|
asprintf(&init, LXCPATH "/%s/init", name);
|
||||||
|
fd = open(init, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
|
||||||
|
if (fd < 0) {
|
||||||
|
lxc_log_syserror("failed to open '%s'", init);
|
||||||
|
goto err_write;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (write(fd, val, strlen(val)) < 0) {
|
||||||
|
lxc_log_syserror("failed to write the init pid");
|
||||||
|
goto err_write;
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
if (lxc_link_nsgroup(name, pid))
|
||||||
|
lxc_log_warning("cgroupfs not found: cgroup disabled");
|
||||||
|
|
||||||
|
if (lxc_setstate(name, RUNNING)) {
|
||||||
|
lxc_log_error("failed to set state to %s", state2str(RUNNING));
|
||||||
|
goto err_state_failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
wait_again:
|
||||||
|
if (waitpid(pid, NULL, 0) < 0) {
|
||||||
|
if (errno == EINTR)
|
||||||
|
goto wait_again;
|
||||||
|
lxc_log_syserror("failed to wait the pid %d", pid);
|
||||||
|
goto err_waitpid_failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lxc_setstate(name, STOPPING))
|
||||||
|
lxc_log_error("failed to set state %s", state2str(STOPPING));
|
||||||
|
|
||||||
|
if (clone_flags & CLONE_NEWNET && conf_destroy_network(name))
|
||||||
|
lxc_log_error("failed to destroy the network");
|
||||||
|
|
||||||
|
err = 0;
|
||||||
|
out:
|
||||||
|
if (lxc_setstate(name, STOPPED))
|
||||||
|
lxc_log_error("failed to set state %s", state2str(STOPPED));
|
||||||
|
|
||||||
|
lxc_unlink_nsgroup(name);
|
||||||
|
unlink(init);
|
||||||
|
free(init);
|
||||||
|
free(val);
|
||||||
|
lxc_put_lock(lock);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
|
||||||
|
err_write:
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
err_state_failed:
|
||||||
|
err_child_failed:
|
||||||
|
err_pipe_read2:
|
||||||
|
err_pipe_write:
|
||||||
|
if (clone_flags & CLONE_NEWNET)
|
||||||
|
conf_destroy_network(name);
|
||||||
|
err_create_network:
|
||||||
|
err_pipe_read:
|
||||||
|
err_waitpid_failed:
|
||||||
|
if (lxc_setstate(name, ABORTING))
|
||||||
|
lxc_log_error("failed to set state %s", state2str(STOPPED));
|
||||||
|
|
||||||
|
kill(pid, SIGKILL);
|
||||||
|
err_fork_ns:
|
||||||
|
LXC_TTY_DEL_HANDLER(SIGQUIT);
|
||||||
|
LXC_TTY_DEL_HANDLER(SIGINT);
|
||||||
|
close(sv[0]);
|
||||||
|
close(sv[1]);
|
||||||
|
err:
|
||||||
|
goto out;
|
||||||
|
}
|
193
src/liblxc/state.c
Normal file
193
src/liblxc/state.c
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/file.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
#include <state.h>
|
||||||
|
#include <log.h>
|
||||||
|
|
||||||
|
static char *strstate[] = {
|
||||||
|
"STOPPED", "STARTING", "RUNNING", "STOPPING",
|
||||||
|
"ABORTING", "FREEZING", "FROZEN",
|
||||||
|
};
|
||||||
|
|
||||||
|
const char *state2str(lxc_state_t state)
|
||||||
|
{
|
||||||
|
if (state < STOPPED || state > MAX_STATE - 1)
|
||||||
|
return NULL;
|
||||||
|
return strstate[state];
|
||||||
|
}
|
||||||
|
|
||||||
|
lxc_state_t str2state(const char *state)
|
||||||
|
{
|
||||||
|
int i, len;
|
||||||
|
len = sizeof(strstate)/sizeof(strstate[0]);
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
if (!strcmp(strstate[i], state))
|
||||||
|
return i;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lxc_setstate(const char *name, lxc_state_t state)
|
||||||
|
{
|
||||||
|
int fd, err;
|
||||||
|
char file[MAXPATHLEN];
|
||||||
|
const char *str = state2str(state);
|
||||||
|
|
||||||
|
if (!str)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
snprintf(file, MAXPATHLEN, LXCPATH "/%s/state", name);
|
||||||
|
|
||||||
|
fd = open(file, O_WRONLY);
|
||||||
|
if (fd < 0) {
|
||||||
|
lxc_log_syserror("failed to open %s file", file);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flock(fd, LOCK_EX)) {
|
||||||
|
lxc_log_syserror("failed to take the lock to %s", file);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ftruncate(fd, 0)) {
|
||||||
|
lxc_log_syserror("failed to truncate the file %s", file);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (write(fd, str, strlen(str)) < 0) {
|
||||||
|
lxc_log_syserror("failed to write state to %s", file);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = 0;
|
||||||
|
out:
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
/* let the event to be propagated, crappy but that works,
|
||||||
|
* otherwise the events will be folded into only one event,
|
||||||
|
* and I want to have them to be one by one in order
|
||||||
|
* to follow the different states of the container.
|
||||||
|
*/
|
||||||
|
usleep(200000);
|
||||||
|
|
||||||
|
return -err;
|
||||||
|
}
|
||||||
|
|
||||||
|
int mkstate(const char *name)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
char file[MAXPATHLEN];
|
||||||
|
|
||||||
|
snprintf(file, MAXPATHLEN, LXCPATH "/%s/state", name);
|
||||||
|
fd = creat(file, S_IRUSR|S_IWUSR);
|
||||||
|
if (fd < 0) {
|
||||||
|
lxc_log_syserror("failed to create file %s", file);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rmstate(const char *name)
|
||||||
|
{
|
||||||
|
char file[MAXPATHLEN];
|
||||||
|
snprintf(file, MAXPATHLEN, LXCPATH "/%s/state", name);
|
||||||
|
unlink(file);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
lxc_state_t lxc_getstate(const char *name)
|
||||||
|
{
|
||||||
|
int fd, err;
|
||||||
|
char file[MAXPATHLEN];
|
||||||
|
|
||||||
|
snprintf(file, MAXPATHLEN, LXCPATH "/%s/state", name);
|
||||||
|
|
||||||
|
fd = open(file, O_RDONLY);
|
||||||
|
if (fd < 0) {
|
||||||
|
lxc_log_syserror("failed to open %s", file);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flock(fd, LOCK_SH)) {
|
||||||
|
lxc_log_syserror("failed to take the lock to %s", file);
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = read(fd, file, strlen(file));
|
||||||
|
if (err < 0) {
|
||||||
|
lxc_log_syserror("failed to read file %s", file);
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
file[err] = '\0';
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
return str2state(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int freezer_state(const char *name)
|
||||||
|
{
|
||||||
|
char freezer[MAXPATHLEN];
|
||||||
|
char status[MAXPATHLEN];
|
||||||
|
FILE *file;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
snprintf(freezer, MAXPATHLEN,
|
||||||
|
LXCPATH "/%s/freezer.freeze", name);
|
||||||
|
|
||||||
|
file = fopen(freezer, "r");
|
||||||
|
if (file < 0) {
|
||||||
|
lxc_log_syserror("failed to open %s", freezer);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = fscanf(file, "%s", status);
|
||||||
|
fclose(file);
|
||||||
|
|
||||||
|
if (err == EOF) {
|
||||||
|
lxc_log_syserror("failed to read %s", freezer);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return str2state(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
lxc_state_t lxc_state(const char *name)
|
||||||
|
{
|
||||||
|
int state = freezer_state(name);
|
||||||
|
if (state != FROZEN && state != FREEZING)
|
||||||
|
state = lxc_getstate(name);
|
||||||
|
return state;
|
||||||
|
}
|
33
src/liblxc/state.h
Normal file
33
src/liblxc/state.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#ifndef _state_h
|
||||||
|
#define _state_h
|
||||||
|
|
||||||
|
extern const char *state2str(lxc_state_t state);
|
||||||
|
extern lxc_state_t str2state(const char *state);
|
||||||
|
extern int mkstate(const char *name);
|
||||||
|
extern int rmstate(const char *name);
|
||||||
|
extern int lxc_setstate(const char *name, lxc_state_t state);
|
||||||
|
extern lxc_state_t lxc_getstate(const char *name);
|
||||||
|
|
||||||
|
#endif
|
95
src/liblxc/stop.c
Normal file
95
src/liblxc/stop.c
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <stdio.h>
|
||||||
|
#undef _GNU_SOURCE
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/file.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
#include <state.h>
|
||||||
|
#include <log.h>
|
||||||
|
#include <lock.h>
|
||||||
|
|
||||||
|
int lxc_stop(const char *name)
|
||||||
|
{
|
||||||
|
char *init;
|
||||||
|
char val[MAXPIDLEN];
|
||||||
|
int fd, lock, ret = -1;
|
||||||
|
size_t pid;
|
||||||
|
|
||||||
|
lock = lxc_get_lock(name);
|
||||||
|
if (lock > 0) {
|
||||||
|
lxc_log_error("'%s' is not running", name);
|
||||||
|
lxc_put_lock(lock);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lock < 0) {
|
||||||
|
lxc_log_error("failed to acquire the lock on '%s':%s",
|
||||||
|
name, strerror(-lock));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
asprintf(&init, LXCPATH "/%s/init", name);
|
||||||
|
fd = open(init, O_RDONLY);
|
||||||
|
if (fd < 0) {
|
||||||
|
lxc_log_syserror("failed to open init file for %s", name);
|
||||||
|
goto out_free;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (read(fd, val, sizeof(val)) < 0) {
|
||||||
|
lxc_log_syserror("failed to read %s", init);
|
||||||
|
goto out_close;
|
||||||
|
}
|
||||||
|
|
||||||
|
pid = atoi(val);
|
||||||
|
|
||||||
|
if (kill(pid, SIGKILL)) {
|
||||||
|
lxc_log_syserror("failed to kill %zd", pid);
|
||||||
|
goto out_close;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unlink(init)) {
|
||||||
|
lxc_log_syserror("failed to unlink %s", init);
|
||||||
|
goto out_close;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
out_close:
|
||||||
|
close(fd);
|
||||||
|
out_free:
|
||||||
|
free(init);
|
||||||
|
return ret;
|
||||||
|
}
|
51
src/liblxc/utils.h
Normal file
51
src/liblxc/utils.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#ifndef _utils_h
|
||||||
|
#define _utils_h
|
||||||
|
|
||||||
|
#define LXC_TTY_HANDLER(s) \
|
||||||
|
static struct sigaction lxc_tty_sa_##s; \
|
||||||
|
static void tty_##s##_handler(int sig, siginfo_t *info, void *ctx) \
|
||||||
|
{ \
|
||||||
|
if (lxc_tty_sa_##s.sa_handler == SIG_DFL || \
|
||||||
|
lxc_tty_sa_##s.sa_handler == SIG_IGN) \
|
||||||
|
return; \
|
||||||
|
(*lxc_tty_sa_##s.sa_sigaction)(sig, info, ctx); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define LXC_TTY_ADD_HANDLER(s) \
|
||||||
|
do { \
|
||||||
|
struct sigaction sa; \
|
||||||
|
sa.sa_sigaction = tty_##s##_handler; \
|
||||||
|
sa.sa_flags = SA_SIGINFO; \
|
||||||
|
sigfillset(&sa.sa_mask); \
|
||||||
|
/* No error expected with sigaction. */ \
|
||||||
|
sigaction(s, &sa, &lxc_tty_sa_##s); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define LXC_TTY_DEL_HANDLER(s) \
|
||||||
|
do { \
|
||||||
|
sigaction(s, &lxc_tty_sa_##s, NULL); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#endif
|
15
src/lxc/.cvsignore
Normal file
15
src/lxc/.cvsignore
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
.deps
|
||||||
|
Makefile
|
||||||
|
Makefile.in
|
||||||
|
lxc-console
|
||||||
|
lxc-create
|
||||||
|
lxc-destroy
|
||||||
|
lxc-execute
|
||||||
|
lxc-freeze
|
||||||
|
lxc-kill
|
||||||
|
lxc-monitor
|
||||||
|
lxc-start
|
||||||
|
lxc-state
|
||||||
|
lxc-stop
|
||||||
|
lxc-unfreeze
|
||||||
|
lxc-ps
|
61
src/lxc/Makefile.am
Normal file
61
src/lxc/Makefile.am
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
INCLUDES= -I$(top_srcdir)/src/liblxc
|
||||||
|
|
||||||
|
bin_SCRIPTS = \
|
||||||
|
lxc-ps
|
||||||
|
|
||||||
|
bin_PROGRAMS = \
|
||||||
|
lxc-create \
|
||||||
|
lxc-destroy \
|
||||||
|
lxc-stop \
|
||||||
|
lxc-start \
|
||||||
|
lxc-execute \
|
||||||
|
lxc-monitor \
|
||||||
|
lxc-console \
|
||||||
|
lxc-state \
|
||||||
|
lxc-kill \
|
||||||
|
lxc-freeze \
|
||||||
|
lxc-unfreeze
|
||||||
|
|
||||||
|
lxc_create_SOURCES = lxc_create.c config.c config.h
|
||||||
|
lxc_create_LDADD = \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
||||||
|
|
||||||
|
lxc_destroy_SOURCES = lxc_destroy.c
|
||||||
|
lxc_destroy_LDADD = \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
||||||
|
|
||||||
|
lxc_start_SOURCES = lxc_start.c
|
||||||
|
lxc_start_LDADD = \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
||||||
|
|
||||||
|
lxc_stop_SOURCES = lxc_stop.c
|
||||||
|
lxc_stop_LDADD = \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
||||||
|
|
||||||
|
lxc_execute_SOURCES = lxc_execute.c config.c
|
||||||
|
lxc_execute_LDADD = \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
||||||
|
|
||||||
|
lxc_monitor_SOURCES = lxc_monitor.c
|
||||||
|
lxc_monitor_LDADD = \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
||||||
|
|
||||||
|
lxc_console_SOURCES = lxc_console.c
|
||||||
|
lxc_console_LDADD = \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
||||||
|
|
||||||
|
lxc_state_SOURCES = lxc_state.c
|
||||||
|
lxc_state_LDADD = \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
||||||
|
|
||||||
|
lxc_kill_SOURCES = lxc_kill.c
|
||||||
|
lxc_kill_LDADD = \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
||||||
|
|
||||||
|
lxc_freeze_SOURCES = lxc_freeze.c
|
||||||
|
lxc_freeze_LDADD = \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
||||||
|
|
||||||
|
lxc_unfreeze_SOURCES = lxc_unfreeze.c
|
||||||
|
lxc_unfreeze_LDADD = \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
550
src/lxc/config.c
Normal file
550
src/lxc/config.c
Normal file
@ -0,0 +1,550 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/utsname.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
#include <list.h>
|
||||||
|
#include <conf.h>
|
||||||
|
#include <log.h>
|
||||||
|
|
||||||
|
|
||||||
|
typedef int (*file_cb)(char* buffer, void *data);
|
||||||
|
typedef int (*config_cb)(char *value, struct lxc_conf *lxc_conf);
|
||||||
|
|
||||||
|
static int config_mount(char *, struct lxc_conf *);
|
||||||
|
static int config_chroot(char *, struct lxc_conf *);
|
||||||
|
static int config_utsname(char *, struct lxc_conf *);
|
||||||
|
static int config_network_type(char *, struct lxc_conf *);
|
||||||
|
static int config_network_flags(char *, struct lxc_conf *);
|
||||||
|
static int config_network_link(char *, struct lxc_conf *);
|
||||||
|
static int config_network_name(char *, struct lxc_conf *);
|
||||||
|
static int config_network_hwaddr(char *, struct lxc_conf *);
|
||||||
|
static int config_network_ipv4(char *, struct lxc_conf *);
|
||||||
|
static int config_network_ipv6(char *, struct lxc_conf *);
|
||||||
|
|
||||||
|
struct config {
|
||||||
|
char *name;
|
||||||
|
int type;
|
||||||
|
config_cb cb;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum { MOUNT, CHROOT, UTSNAME, NETTYPE, NETFLAGS, NETLINK,
|
||||||
|
NETNAME, NETHWADDR, NETIPV4, NETIPV6 };
|
||||||
|
|
||||||
|
struct config config[] = {
|
||||||
|
{ "lxc.mount", MOUNT, config_mount },
|
||||||
|
{ "lxc.chroot", CHROOT, config_chroot },
|
||||||
|
{ "lxc.utsname", UTSNAME, config_utsname },
|
||||||
|
{ "lxc.network.type", NETTYPE, config_network_type },
|
||||||
|
{ "lxc.network.flags", NETFLAGS, config_network_flags },
|
||||||
|
{ "lxc.network.link", NETLINK, config_network_link },
|
||||||
|
{ "lxc.network.name", NETNAME, config_network_name },
|
||||||
|
{ "lxc.network.hwaddr", NETHWADDR, config_network_hwaddr },
|
||||||
|
{ "lxc.network.ipv4", NETIPV4, config_network_ipv4 },
|
||||||
|
{ "lxc.network.ipv6", NETIPV6, config_network_ipv6 },
|
||||||
|
};
|
||||||
|
|
||||||
|
static const size_t config_size = sizeof(config)/sizeof(struct config);
|
||||||
|
|
||||||
|
static struct config *getconfig(const char *key)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < config_size; i++)
|
||||||
|
if (!strncmp(config[i].name, key,
|
||||||
|
strlen(config[i].name)))
|
||||||
|
return &config[i];
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int is_line_empty(char *line)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
size_t len = strlen(line);
|
||||||
|
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
if (line[i] != ' ' && line[i] != '\t' &&
|
||||||
|
line[i] != '\n' && line[i] != '\r' &&
|
||||||
|
line[i] != '\f' && line[i] != '\0')
|
||||||
|
return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int char_left_gc(char *buffer, size_t len)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
if (buffer[i] == ' ' ||
|
||||||
|
buffer[i] == '\t')
|
||||||
|
continue;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int char_right_gc(char *buffer, size_t len)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = len - 1; i >= 0; i--) {
|
||||||
|
if (buffer[i] == ' ' ||
|
||||||
|
buffer[i] == '\t' ||
|
||||||
|
buffer[i] == '\n' ||
|
||||||
|
buffer[i] == '\0')
|
||||||
|
continue;
|
||||||
|
return i + 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int config_network_type(char *value, struct lxc_conf *lxc_conf)
|
||||||
|
{
|
||||||
|
struct list *networks = &lxc_conf->networks;
|
||||||
|
struct network *network;
|
||||||
|
struct netdev *netdev;
|
||||||
|
struct list *list;
|
||||||
|
struct list *ndlist;
|
||||||
|
|
||||||
|
network = malloc(sizeof(*network));
|
||||||
|
if (!network) {
|
||||||
|
lxc_log_syserror("failed to allocate memory");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
list_init(&network->netdev);
|
||||||
|
|
||||||
|
netdev = malloc(sizeof(*netdev));
|
||||||
|
if (!netdev) {
|
||||||
|
lxc_log_syserror("failed to allocate memory");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
list_init(&netdev->ipv4);
|
||||||
|
list_init(&netdev->ipv6);
|
||||||
|
list_init(&netdev->route4);
|
||||||
|
list_init(&netdev->route6);
|
||||||
|
|
||||||
|
ndlist = malloc(sizeof(*ndlist));
|
||||||
|
if (!ndlist) {
|
||||||
|
lxc_log_syserror("failed to allocate memory");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ndlist->elem = netdev;
|
||||||
|
|
||||||
|
list_add(&network->netdev, ndlist);
|
||||||
|
|
||||||
|
list = malloc(sizeof(*list));
|
||||||
|
if (!list) {
|
||||||
|
lxc_log_syserror("failed to allocate memory");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
list_init(list);
|
||||||
|
list->elem = network;
|
||||||
|
|
||||||
|
list_add(networks, list);
|
||||||
|
|
||||||
|
if (!strcmp(value, "veth"))
|
||||||
|
network->type = VETH;
|
||||||
|
else if (!strcmp(value, "macvlan"))
|
||||||
|
network->type = MACVLAN;
|
||||||
|
else if (!strcmp(value, "phys"))
|
||||||
|
network->type = PHYS;
|
||||||
|
else {
|
||||||
|
lxc_log_error("invalid network type %s", value);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int config_network_flags(char *value, struct lxc_conf *lxc_conf)
|
||||||
|
{
|
||||||
|
struct list *networks = &lxc_conf->networks;
|
||||||
|
struct network *network;
|
||||||
|
struct netdev *netdev;
|
||||||
|
|
||||||
|
if (list_empty(networks)) {
|
||||||
|
lxc_log_error("network is not created for '%s' option", value);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
network = list_first_elem(networks);
|
||||||
|
if (!network) {
|
||||||
|
lxc_log_error("no network defined for '%s' option", value);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
netdev = list_first_elem(&network->netdev);
|
||||||
|
netdev->flags |= IFF_UP;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int config_network_link(char *value, struct lxc_conf *lxc_conf)
|
||||||
|
{
|
||||||
|
struct list *networks = &lxc_conf->networks;
|
||||||
|
struct network *network;
|
||||||
|
struct netdev *netdev;
|
||||||
|
|
||||||
|
if (list_empty(networks)) {
|
||||||
|
lxc_log_error("network is not created for %s", value);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
network = list_first_elem(networks);
|
||||||
|
if (!network) {
|
||||||
|
lxc_log_error("no network defined for %s", value);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strlen(value) > IFNAMSIZ) {
|
||||||
|
lxc_log_error("invalid interface name: %s", value);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
netdev = list_first_elem(&network->netdev);
|
||||||
|
netdev->ifname = strdup(value);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int config_network_name(char *value, struct lxc_conf *lxc_conf)
|
||||||
|
{
|
||||||
|
struct list *networks = &lxc_conf->networks;
|
||||||
|
struct network *network;
|
||||||
|
struct netdev *netdev;
|
||||||
|
|
||||||
|
if (list_empty(networks)) {
|
||||||
|
lxc_log_error("network is not created for %s", value);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
network = list_first_elem(networks);
|
||||||
|
if (!network) {
|
||||||
|
lxc_log_error("no network defined for %s", value);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strlen(value) > IFNAMSIZ) {
|
||||||
|
lxc_log_error("invalid interface name: %s", value);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
netdev = list_first_elem(&network->netdev);
|
||||||
|
netdev->newname = strdup(value);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int config_network_hwaddr(char *value, struct lxc_conf *lxc_conf)
|
||||||
|
{
|
||||||
|
struct list *networks = &lxc_conf->networks;
|
||||||
|
struct network *network;
|
||||||
|
struct netdev *netdev;
|
||||||
|
|
||||||
|
if (list_empty(networks)) {
|
||||||
|
lxc_log_error("network is not created for %s", value);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
network = list_first_elem(networks);
|
||||||
|
if (!network) {
|
||||||
|
lxc_log_error("no network defined for %s", value);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
netdev = list_first_elem(&network->netdev);
|
||||||
|
netdev->hwaddr = strdup(value);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int config_network_ipv4(char *value, struct lxc_conf *lxc_conf)
|
||||||
|
{
|
||||||
|
struct list *networks = &lxc_conf->networks;
|
||||||
|
struct network *network;
|
||||||
|
struct inetdev *inetdev;
|
||||||
|
struct netdev *netdev;
|
||||||
|
struct list *list;
|
||||||
|
char *cursor, *slash, *addr = NULL, *bcast = NULL, *prefix = NULL;
|
||||||
|
|
||||||
|
if (list_empty(networks)) {
|
||||||
|
lxc_log_error("network is not created for '%s'", value);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
network = list_first_elem(networks);
|
||||||
|
if (!network) {
|
||||||
|
lxc_log_error("no network defined for '%s'", value);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
netdev = list_first_elem(&network->netdev);
|
||||||
|
if (!netdev) {
|
||||||
|
lxc_log_error("no netdev defined for '%s'", value);
|
||||||
|
}
|
||||||
|
|
||||||
|
inetdev = malloc(sizeof(*inetdev));
|
||||||
|
if (!inetdev) {
|
||||||
|
lxc_log_syserror("failed to allocate ipv4 address");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
memset(inetdev, 0, sizeof(*inetdev));
|
||||||
|
|
||||||
|
list = malloc(sizeof(*list));
|
||||||
|
if (!list) {
|
||||||
|
lxc_log_syserror("failed to allocate memory");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
list_init(list);
|
||||||
|
list->elem = inetdev;
|
||||||
|
|
||||||
|
addr = value;
|
||||||
|
|
||||||
|
cursor = strstr(addr, " ");
|
||||||
|
if (cursor) {
|
||||||
|
*cursor = '\0';
|
||||||
|
bcast = cursor + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
slash = strstr(addr, "/");
|
||||||
|
if (slash) {
|
||||||
|
*slash = '\0';
|
||||||
|
prefix = slash + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!addr) {
|
||||||
|
lxc_log_error("no address specified");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!inet_pton(AF_INET, addr, &inetdev->addr)) {
|
||||||
|
lxc_log_syserror("invalid ipv4 address: %s", value);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bcast)
|
||||||
|
if (!inet_pton(AF_INET, bcast, &inetdev->bcast)) {
|
||||||
|
lxc_log_syserror("invalid ipv4 address: %s", value);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prefix)
|
||||||
|
inetdev->prefix = atoi(prefix);
|
||||||
|
|
||||||
|
list_add(&netdev->ipv4, list);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int config_network_ipv6(char *value, struct lxc_conf *lxc_conf)
|
||||||
|
{
|
||||||
|
struct list *networks = &lxc_conf->networks;
|
||||||
|
struct network *network;
|
||||||
|
struct netdev *netdev;
|
||||||
|
struct inet6dev *inet6dev;
|
||||||
|
struct list *list;
|
||||||
|
char *slash;
|
||||||
|
char *netmask;
|
||||||
|
|
||||||
|
if (list_empty(networks)) {
|
||||||
|
lxc_log_error("network is not created for %s", value);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
network = list_first_elem(networks);
|
||||||
|
if (!network) {
|
||||||
|
lxc_log_error("no network defined for %s", value);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
inet6dev = malloc(sizeof(*inet6dev));
|
||||||
|
if (!inet6dev) {
|
||||||
|
lxc_log_syserror("failed to allocate ipv6 address");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
memset(inet6dev, 0, sizeof(*inet6dev));
|
||||||
|
|
||||||
|
list = malloc(sizeof(*list));
|
||||||
|
if (!list) {
|
||||||
|
lxc_log_syserror("failed to allocate memory");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
list_init(list);
|
||||||
|
list->elem = inet6dev;
|
||||||
|
|
||||||
|
slash = strstr(value, "/");
|
||||||
|
if (slash) {
|
||||||
|
*slash = '\0';
|
||||||
|
netmask = slash + 1;
|
||||||
|
inet6dev->prefix = atoi(netmask);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!inet_pton(AF_INET6, value, &inet6dev->addr)) {
|
||||||
|
lxc_log_syserror("invalid ipv6 address: %s", value);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
netdev = list_first_elem(&network->netdev);
|
||||||
|
list_add(&netdev->ipv6, list);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int config_mount(char *value, struct lxc_conf *lxc_conf)
|
||||||
|
{
|
||||||
|
if (strlen(value) >= MAXPATHLEN) {
|
||||||
|
lxc_log_error("%s path is too long", value);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
lxc_conf->fstab = strdup(value);
|
||||||
|
if (!lxc_conf->fstab) {
|
||||||
|
lxc_log_syserror("failed to duplicate string %s", value);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int config_chroot(char *value, struct lxc_conf *lxc_conf)
|
||||||
|
{
|
||||||
|
if (strlen(value) >= MAXPATHLEN) {
|
||||||
|
lxc_log_error("%s path is too long", value);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
lxc_conf->chroot = strdup(value);
|
||||||
|
if (!lxc_conf->chroot) {
|
||||||
|
lxc_log_syserror("failed to duplicate string %s", value);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int config_utsname(char *value, struct lxc_conf *lxc_conf)
|
||||||
|
{
|
||||||
|
struct utsname *utsname;
|
||||||
|
|
||||||
|
utsname = malloc(sizeof(*utsname));
|
||||||
|
if (!utsname) {
|
||||||
|
lxc_log_syserror("failed to allocate memory");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strlen(value) >= sizeof(utsname->nodename)) {
|
||||||
|
lxc_log_error("node name '%s' is too long",
|
||||||
|
utsname->nodename);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
strcpy(utsname->nodename, value);
|
||||||
|
lxc_conf->utsname = utsname;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int parse_line(char *buffer, void *data)
|
||||||
|
{
|
||||||
|
struct config *config;
|
||||||
|
char *dot;
|
||||||
|
char *key;
|
||||||
|
char *value;
|
||||||
|
|
||||||
|
if (is_line_empty(buffer))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
buffer += char_left_gc(buffer, strlen(buffer));
|
||||||
|
if (buffer[0] == '#')
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
dot = strstr(buffer, "=");
|
||||||
|
if (!dot) {
|
||||||
|
lxc_log_error("invalid configuration line: %s", buffer);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
*dot = '\0';
|
||||||
|
value = dot + 1;
|
||||||
|
|
||||||
|
key = buffer;
|
||||||
|
key[char_right_gc(key, strlen(key))] = '\0';
|
||||||
|
|
||||||
|
value += char_left_gc(value, strlen(value));
|
||||||
|
value[char_right_gc(value, strlen(value))] = '\0';
|
||||||
|
|
||||||
|
config = getconfig(key);
|
||||||
|
if (!config) {
|
||||||
|
lxc_log_error("unknow key %s", key);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return config->cb(value, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int file_for_each_line(const char *file, file_cb callback, void *data)
|
||||||
|
{
|
||||||
|
char buffer[MAXPATHLEN];
|
||||||
|
size_t len = sizeof(buffer);
|
||||||
|
FILE *f;
|
||||||
|
int err = -1;
|
||||||
|
|
||||||
|
f = fopen(file, "r");
|
||||||
|
if (!f) {
|
||||||
|
lxc_log_syserror("failed to open %s", file);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (fgets(buffer, len, f))
|
||||||
|
if (callback(buffer, data))
|
||||||
|
goto out;
|
||||||
|
err = 0;
|
||||||
|
out:
|
||||||
|
fclose(f);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
int config_read(const char *file, struct lxc_conf *conf)
|
||||||
|
{
|
||||||
|
return file_for_each_line(file, parse_line, conf);
|
||||||
|
}
|
||||||
|
|
||||||
|
int config_init(struct lxc_conf *conf)
|
||||||
|
{
|
||||||
|
conf->chroot = NULL;
|
||||||
|
conf->fstab = NULL;
|
||||||
|
conf->utsname = NULL;
|
||||||
|
conf->cgroup = NULL;
|
||||||
|
list_init(&conf->networks);
|
||||||
|
return 0;
|
||||||
|
}
|
28
src/lxc/config.h
Normal file
28
src/lxc/config.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern int config_init(struct lxc_conf *conf);
|
||||||
|
extern int config_read(const char *file, struct lxc_conf *conf);
|
||||||
|
|
||||||
|
|
||||||
|
|
33
src/lxc/lxc-priority.c
Normal file
33
src/lxc/lxc-priority.c
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
17
src/lxc/lxc-ps.in
Executable file
17
src/lxc/lxc-ps.in
Executable file
@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
LXCPATH=/var/lxc
|
||||||
|
|
||||||
|
if [ ! -r $LXCPATH ]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
LXCS=$(ls $LXCPATH)
|
||||||
|
|
||||||
|
for i in $LXCS; do
|
||||||
|
if [ -d $LXCPATH/$i/nsgroup ]; then
|
||||||
|
echo "Container : $(basename $i)"
|
||||||
|
cat $LXCPATH/$i/nsgroup/tasks
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
33
src/lxc/lxc_console.c
Normal file
33
src/lxc/lxc_console.c
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
86
src/lxc/lxc_create.c
Normal file
86
src/lxc/lxc_create.c
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/utsname.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
#include <state.h>
|
||||||
|
#include <list.h>
|
||||||
|
#include <conf.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
void usage(char *cmd)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s <command>\n", basename(cmd));
|
||||||
|
fprintf(stderr, "\t -n <name> : name of the container\n");
|
||||||
|
fprintf(stderr, "\t -f <confile> : path of the configuration file\n");
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
const char *name = NULL, *file = NULL;
|
||||||
|
struct lxc_conf lxc_conf;
|
||||||
|
int opt;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "f:n:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'n':
|
||||||
|
name = optarg;
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
file = optarg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!name || !file)
|
||||||
|
usage(argv[0]);
|
||||||
|
|
||||||
|
if (config_init(&lxc_conf)) {
|
||||||
|
fprintf(stderr, "failed to initialize the configuration\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config_read(file, &lxc_conf)) {
|
||||||
|
fprintf(stderr, "invalid configuration file\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lxc_create(name, &lxc_conf)) {
|
||||||
|
fprintf(stderr, "failed to create the container %s\n", name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
63
src/lxc/lxc_destroy.c
Normal file
63
src/lxc/lxc_destroy.c
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
|
||||||
|
void usage(char *cmd)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s <command>\n", basename(cmd));
|
||||||
|
fprintf(stderr, "\t -n <name> : name of the container\n");
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char opt;
|
||||||
|
char *name = NULL;
|
||||||
|
int nbargs = 0;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "n:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'n':
|
||||||
|
name = optarg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
nbargs++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!name)
|
||||||
|
usage(argv[0]);
|
||||||
|
|
||||||
|
if (lxc_destroy(name)) {
|
||||||
|
fprintf(stderr, "failed to destroy %s\n", name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
68
src/lxc/lxc_execute.c
Normal file
68
src/lxc/lxc_execute.c
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
|
||||||
|
void usage(char *cmd)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s <command>\n", basename(cmd));
|
||||||
|
fprintf(stderr, "\t -n <name> : name of the container\n");
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char opt;
|
||||||
|
char *name = NULL;
|
||||||
|
char **args;
|
||||||
|
int nbargs = 0;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "n:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'n':
|
||||||
|
name = optarg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
nbargs++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!name || !argv[optind] || !strlen(argv[optind]))
|
||||||
|
usage(argv[0]);
|
||||||
|
|
||||||
|
args = &argv[optind];
|
||||||
|
argc -= nbargs;
|
||||||
|
|
||||||
|
if (lxc_execute(name, argc, args, NULL, NULL)) {
|
||||||
|
fprintf(stderr, "failed to start %s\n", name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
64
src/lxc/lxc_freeze.c
Normal file
64
src/lxc/lxc_freeze.c
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
|
||||||
|
void usage(char *cmd)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s <command>\n", basename(cmd));
|
||||||
|
fprintf(stderr, "\t -n <name> : name of the container\n");
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char opt;
|
||||||
|
char *name = NULL;
|
||||||
|
int nbargs = 0;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "n:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'n':
|
||||||
|
name = optarg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
nbargs++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!name)
|
||||||
|
usage(argv[0]);
|
||||||
|
|
||||||
|
if (lxc_freeze(name)) {
|
||||||
|
fprintf(stderr, "failed to freeze '%s'\n", name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
33
src/lxc/lxc_kill.c
Normal file
33
src/lxc/lxc_kill.c
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
98
src/lxc/lxc_monitor.c
Normal file
98
src/lxc/lxc_monitor.c
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
#include <state.h>
|
||||||
|
|
||||||
|
void usage(char *cmd)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s <command>\n", basename(cmd));
|
||||||
|
fprintf(stderr, "\t -n <name> : name of the container\n");
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char opt;
|
||||||
|
char *name = NULL;
|
||||||
|
int fds[2];
|
||||||
|
pid_t pid;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "n:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'n':
|
||||||
|
name = optarg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!name)
|
||||||
|
usage(argv[0]);
|
||||||
|
|
||||||
|
if (pipe(fds)) {
|
||||||
|
perror("pipe");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pid = fork();
|
||||||
|
if (pid < 0) {
|
||||||
|
perror("fork");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pid) {
|
||||||
|
close(fds[0]);
|
||||||
|
if (lxc_monitor(name, fds[1])) {
|
||||||
|
fprintf(stderr, "failed to monitor %s\n", name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fds[1]);
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
int err, state;
|
||||||
|
|
||||||
|
err = read(fds[0], &state, sizeof(state));
|
||||||
|
if (err < 0) {
|
||||||
|
perror("read");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!err) {
|
||||||
|
printf("container has been destroyed\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("container has changed the state to %d - %s\n",
|
||||||
|
state, state2str(state));
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
74
src/lxc/lxc_start.c
Normal file
74
src/lxc/lxc_start.c
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/utsname.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
|
||||||
|
void usage(char *cmd)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s <command>\n", basename(cmd));
|
||||||
|
fprintf(stderr, "\t -n <name> : name of the container\n");
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char opt;
|
||||||
|
char *name = NULL;
|
||||||
|
char **args;
|
||||||
|
int nbargs = 0;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "n:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'n':
|
||||||
|
name = optarg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
nbargs++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!name || !argv[optind] || !strlen(argv[optind]))
|
||||||
|
usage(argv[0]);
|
||||||
|
|
||||||
|
args = &argv[optind];
|
||||||
|
argc -= nbargs;
|
||||||
|
|
||||||
|
if (lxc_start(name, argc, args, NULL, NULL)) {
|
||||||
|
fprintf(stderr, "failed to start %s\n", name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
67
src/lxc/lxc_state.c
Normal file
67
src/lxc/lxc_state.c
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
#include <state.h>
|
||||||
|
|
||||||
|
void usage(char *cmd)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s <command>\n", basename(cmd));
|
||||||
|
fprintf(stderr, "\t -n <name> : name of the container\n");
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char opt;
|
||||||
|
char *name = NULL;
|
||||||
|
int state, nbargs = 0;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "n:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'n':
|
||||||
|
name = optarg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
nbargs++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!name)
|
||||||
|
usage(argv[0]);
|
||||||
|
|
||||||
|
state = lxc_getstate(name);
|
||||||
|
if (state < 0) {
|
||||||
|
fprintf(stderr, "failed to freeze '%s'\n", name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("'%s' is %s\n", name, state2str(state));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
62
src/lxc/lxc_stop.c
Normal file
62
src/lxc/lxc_stop.c
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
|
||||||
|
void usage(char *cmd)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s <command>\n", basename(cmd));
|
||||||
|
fprintf(stderr, "\t -n <name> : name of the container\n");
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char opt;
|
||||||
|
char *name = NULL;
|
||||||
|
int nbargs = 0;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "n:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'n':
|
||||||
|
name = optarg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
nbargs++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!name)
|
||||||
|
usage(argv[0]);
|
||||||
|
|
||||||
|
if (lxc_stop(name)) {
|
||||||
|
fprintf(stderr, "failed to stop %s\n", name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
63
src/lxc/lxc_unfreeze.c
Normal file
63
src/lxc/lxc_unfreeze.c
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
|
||||||
|
void usage(char *cmd)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s <command>\n", basename(cmd));
|
||||||
|
fprintf(stderr, "\t -n <name> : name of the container\n");
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char opt;
|
||||||
|
char *name = NULL;
|
||||||
|
int nbargs = 0;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "n:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'n':
|
||||||
|
name = optarg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
nbargs++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!name)
|
||||||
|
usage(argv[0]);
|
||||||
|
|
||||||
|
if (lxc_unfreeze(name)) {
|
||||||
|
fprintf(stderr, "failed to freeze '%s'\n", name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
19
test/.cvsignore
Normal file
19
test/.cvsignore
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
.deps
|
||||||
|
Makefile
|
||||||
|
Makefile.in
|
||||||
|
conf
|
||||||
|
dev
|
||||||
|
forward
|
||||||
|
ipv4_add
|
||||||
|
lxc_create
|
||||||
|
lxc_destroy
|
||||||
|
lxc_monitor
|
||||||
|
lxc_start
|
||||||
|
lxc_stop
|
||||||
|
lxc_state
|
||||||
|
macvlan
|
||||||
|
movedev
|
||||||
|
proxy
|
||||||
|
veth
|
||||||
|
confile
|
||||||
|
ipv6_add
|
91
test/Makefile.am
Normal file
91
test/Makefile.am
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
INCLUDES= -I$(top_srcdir)/src/liblxc
|
||||||
|
|
||||||
|
noinst_PROGRAMS = \
|
||||||
|
tst_list \
|
||||||
|
confile \
|
||||||
|
conf \
|
||||||
|
movedev \
|
||||||
|
dev \
|
||||||
|
forward \
|
||||||
|
proxy \
|
||||||
|
veth \
|
||||||
|
macvlan \
|
||||||
|
ipv4_add \
|
||||||
|
ipv6_add \
|
||||||
|
\
|
||||||
|
lxc_create \
|
||||||
|
lxc_destroy \
|
||||||
|
lxc_start \
|
||||||
|
lxc_stop \
|
||||||
|
lxc_monitor \
|
||||||
|
lxc_state
|
||||||
|
|
||||||
|
|
||||||
|
tst_list_SOURCES = tst_list.c
|
||||||
|
tst_list_LDADD = \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
||||||
|
|
||||||
|
confile_SOURCES = confile.c
|
||||||
|
confile_LDADD = \
|
||||||
|
$(top_builddir)/src/lxc/config.o \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
||||||
|
|
||||||
|
conf_SOURCES = conf.c
|
||||||
|
conf_LDADD = \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
||||||
|
|
||||||
|
movedev_SOURCES = movedev.c
|
||||||
|
movedev_LDADD = \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
||||||
|
|
||||||
|
dev_SOURCES = dev.c
|
||||||
|
dev_LDADD = \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
||||||
|
|
||||||
|
forward_SOURCES = forward.c
|
||||||
|
forward_LDADD = \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
||||||
|
|
||||||
|
proxy_SOURCES = proxy.c
|
||||||
|
proxy_LDADD = \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
||||||
|
|
||||||
|
veth_SOURCES = veth.c
|
||||||
|
veth_LDADD = \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
||||||
|
|
||||||
|
macvlan_SOURCES = macvlan.c
|
||||||
|
macvlan_LDADD = \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
||||||
|
|
||||||
|
ipv4_add_SOURCES = ipv4_add.c
|
||||||
|
ipv4_add_LDADD = \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
||||||
|
|
||||||
|
ipv6_add_SOURCES = ipv6_add.c
|
||||||
|
ipv6_add_LDADD = \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
||||||
|
|
||||||
|
lxc_create_SOURCES = lxc_create.c
|
||||||
|
lxc_create_LDADD = \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
||||||
|
|
||||||
|
lxc_destroy_SOURCES = lxc_destroy.c
|
||||||
|
lxc_destroy_LDADD = \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
||||||
|
|
||||||
|
lxc_start_SOURCES = lxc_start.c
|
||||||
|
lxc_start_LDADD = \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
||||||
|
|
||||||
|
lxc_stop_SOURCES = lxc_stop.c
|
||||||
|
lxc_stop_LDADD = \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
||||||
|
|
||||||
|
lxc_monitor_SOURCES = lxc_monitor.c
|
||||||
|
lxc_monitor_LDADD = \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
||||||
|
|
||||||
|
lxc_state_SOURCES = lxc_state.c
|
||||||
|
lxc_state_LDADD = \
|
||||||
|
$(top_builddir)/src/liblxc/liblxc.a
|
102
test/conf.c
Normal file
102
test/conf.c
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/utsname.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
|
||||||
|
#include <list.h>
|
||||||
|
#include <conf.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* I want to setup a container with a veth attached on a bridge,
|
||||||
|
* and have them up
|
||||||
|
*/
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
/* struct network network = { */
|
||||||
|
/* .net = init_list(&network.net), */
|
||||||
|
/* .netdev = init_list(&network.netdev), */
|
||||||
|
/* }; */
|
||||||
|
|
||||||
|
/* struct veth veth = { */
|
||||||
|
/* .link = "veth1", */
|
||||||
|
/* .peer = "veth2", */
|
||||||
|
/* .bridge = "br0", */
|
||||||
|
/* }; */
|
||||||
|
|
||||||
|
/* struct net net = { */
|
||||||
|
/* .type = VETH, */
|
||||||
|
/* }; */
|
||||||
|
|
||||||
|
/* net.veth = veth; */
|
||||||
|
|
||||||
|
/* struct netdev lo = { */
|
||||||
|
/* .ifname = "lo", */
|
||||||
|
/* .flags = IFF_UP, */
|
||||||
|
/* .ipv4 = init_list(&lo.ipv4), */
|
||||||
|
/* .ipv6 = init_list(&lo.ipv6), */
|
||||||
|
/* }; */
|
||||||
|
|
||||||
|
/* struct netdev veth1 = { */
|
||||||
|
/* .ifname = "veth1", */
|
||||||
|
/* .flags = IFF_UP, */
|
||||||
|
/* .ipv4 = init_list(&veth1.ipv4), */
|
||||||
|
/* .ipv6 = init_list(&veth1.ipv6), */
|
||||||
|
/* }; */
|
||||||
|
|
||||||
|
/* struct netdev veth2 = { */
|
||||||
|
/* .ifname = "veth2", */
|
||||||
|
/* .flags = IFF_UP, */
|
||||||
|
/* .netns = 1, */
|
||||||
|
/* .ipv4 = init_list(&veth2.ipv4), */
|
||||||
|
/* .ipv6 = init_list(&veth2.ipv6), */
|
||||||
|
/* }; */
|
||||||
|
|
||||||
|
/* struct netdev br0 = { */
|
||||||
|
/* .ifname = "br0", */
|
||||||
|
/* .ipv4 = init_list(&br0.ipv4), */
|
||||||
|
/* .ipv6 = init_list(&br0.ipv6), */
|
||||||
|
/* }; */
|
||||||
|
|
||||||
|
/* list_add(&network.netdev, &lo.list); */
|
||||||
|
/* list_add(&network.netdev, &veth1.list); */
|
||||||
|
/* list_add(&network.netdev, &veth2.list); */
|
||||||
|
/* list_add(&network.netdev, &br0.list); */
|
||||||
|
/* list_add(&network.net, &net.list); */
|
||||||
|
|
||||||
|
/* struct lxc_conf lxc_conf = { */
|
||||||
|
/* .network = &network, */
|
||||||
|
/* .mounts = init_list(&lxc_conf.mounts), */
|
||||||
|
/* }; */
|
||||||
|
|
||||||
|
/* if (lxc_configure("foo", &lxc_conf)) { */
|
||||||
|
/* fprintf(stderr, "failed to configure\n"); */
|
||||||
|
/* return 1; */
|
||||||
|
/* } */
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
82
test/confile.c
Normal file
82
test/confile.c
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/utsname.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
#include <state.h>
|
||||||
|
#include <list.h>
|
||||||
|
#include <conf.h>
|
||||||
|
|
||||||
|
#include "../src/lxc/config.h"
|
||||||
|
|
||||||
|
static void usage(const char *cmd)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s -n <name>\n", cmd);
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char *file = NULL, *name = NULL;
|
||||||
|
struct lxc_conf lxc_conf;
|
||||||
|
int opt;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "n:f:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'f':
|
||||||
|
file = optarg;
|
||||||
|
break;
|
||||||
|
case 'n':
|
||||||
|
name = optarg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file || !name)
|
||||||
|
usage(argv[0]);
|
||||||
|
|
||||||
|
if (config_init(&lxc_conf)) {
|
||||||
|
fprintf(stderr, "failed to initialize configuration structure\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config_read(file, &lxc_conf)) {
|
||||||
|
fprintf(stderr, "failed to read configuration\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lxc_create(name, &lxc_conf)) {
|
||||||
|
fprintf(stderr, "failed to create <%s>\n", name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
76
test/dev.c
Normal file
76
test/dev.c
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <network.h>
|
||||||
|
|
||||||
|
void usage(char *cmd)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s -i <ifname> -d -f <up|down>\n", cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char *ifname = NULL, *flag = NULL;
|
||||||
|
int opt, destroy = 0, ret = -EINVAL;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "i:f:d")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'i':
|
||||||
|
ifname = optarg;
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
flag = optarg;
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
destroy = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ifname || (!flag && !destroy)) {
|
||||||
|
usage(argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (destroy)
|
||||||
|
ret = device_delete(ifname);
|
||||||
|
else if (!strcmp(flag, "up"))
|
||||||
|
ret = device_up(ifname);
|
||||||
|
else if (!strcmp(flag, "down"))
|
||||||
|
ret = device_down(ifname);
|
||||||
|
|
||||||
|
if (ret) {
|
||||||
|
fprintf(stderr, "failed to set %s: %s\n",
|
||||||
|
ifname, strerror(-ret));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
77
test/forward.c
Normal file
77
test/forward.c
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#include <network.h>
|
||||||
|
|
||||||
|
void usage(const char *cmd)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s -i <ifname> -f <on|off>\n", cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char *ifname = NULL, *flag = NULL;
|
||||||
|
int opt, ret, family = AF_INET;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "6i:f:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'i':
|
||||||
|
ifname = optarg;
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
flag = optarg;
|
||||||
|
break;
|
||||||
|
case '6':
|
||||||
|
family = AF_INET6;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ifname || !flag) {
|
||||||
|
usage(argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strcmp(flag, "on"))
|
||||||
|
ret = ip_forward_on(ifname, family);
|
||||||
|
else if (!strcmp(flag, "off"))
|
||||||
|
ret = ip_forward_off(ifname, family);
|
||||||
|
else {
|
||||||
|
usage(argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret) {
|
||||||
|
fprintf(stderr, "failed for %s: %s\n",
|
||||||
|
ifname, strerror(-ret));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
66
test/ipv4_add.c
Normal file
66
test/ipv4_add.c
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#include <network.h>
|
||||||
|
|
||||||
|
void usage(char *cmd)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s -i <ifname> -a <ip>\n", cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char *ifname = NULL, *addr = NULL;
|
||||||
|
int opt, ret = -EINVAL;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "i:a:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'a':
|
||||||
|
addr = optarg;
|
||||||
|
break;
|
||||||
|
case 'i':
|
||||||
|
ifname = optarg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!addr || !ifname) {
|
||||||
|
usage(argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = ip_addr_add(ifname, addr, 24, NULL);
|
||||||
|
if (ret) {
|
||||||
|
fprintf(stderr, "failed to set %s: %s\n",
|
||||||
|
ifname, strerror(-ret));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
66
test/ipv6_add.c
Normal file
66
test/ipv6_add.c
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#include <network.h>
|
||||||
|
|
||||||
|
void usage(char *cmd)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s -i <ifname> -a <ip>\n", cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char *ifname = NULL, *addr = NULL;
|
||||||
|
int opt, ret = -EINVAL;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "i:a:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'a':
|
||||||
|
addr = optarg;
|
||||||
|
break;
|
||||||
|
case 'i':
|
||||||
|
ifname = optarg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!addr || !ifname) {
|
||||||
|
usage(argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = ip6_addr_add(ifname, addr, 64, NULL);
|
||||||
|
if (ret) {
|
||||||
|
fprintf(stderr, "failed to set %s: %s\n",
|
||||||
|
ifname, strerror(-ret));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
176
test/lxc_create.c
Normal file
176
test/lxc_create.c
Normal file
@ -0,0 +1,176 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/utsname.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
#include <state.h>
|
||||||
|
#include <list.h>
|
||||||
|
#include <conf.h>
|
||||||
|
|
||||||
|
static void usage(const char *cmd)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s -n <name>\n", cmd);
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
const char *name = NULL;
|
||||||
|
int opt;
|
||||||
|
|
||||||
|
/* struct list mclist; */
|
||||||
|
/* struct list mclist2; */
|
||||||
|
/* struct list vethlist; */
|
||||||
|
/* struct list vethlist2; */
|
||||||
|
struct list phylist;
|
||||||
|
|
||||||
|
/* struct inetdev idev; */
|
||||||
|
/* struct list l1 = init_list(&l1); */
|
||||||
|
/* l1.elem = &idev; */
|
||||||
|
|
||||||
|
/* struct inetdev idev_2; */
|
||||||
|
/* struct list l2 = init_list(&l2); */
|
||||||
|
/* l2.elem = &idev_2; */
|
||||||
|
|
||||||
|
/* struct inet6dev idev6; */
|
||||||
|
/* struct list l3 = init_list(&l3); */
|
||||||
|
/* l3.elem = &idev6; */
|
||||||
|
|
||||||
|
/* struct inet6dev idev6_2; */
|
||||||
|
/* struct list l4 = init_list(&l4); */
|
||||||
|
/* l4.elem = idev6_2; */
|
||||||
|
|
||||||
|
|
||||||
|
/* inet_pton(AF_INET, "1.2.3.4", &idev.addr); */
|
||||||
|
/* inet_pton(AF_INET, "1.2.3.255", &idev.bcast); */
|
||||||
|
/* idev.prefix = 24; */
|
||||||
|
|
||||||
|
/* inet_pton(AF_INET, "4.3.2.1", &idev_2.addr); */
|
||||||
|
/* inet_pton(AF_INET, "4.3.2.255", &idev_2.bcast); */
|
||||||
|
|
||||||
|
/* inet_pton(AF_INET6, "2003:db8:1:0:214:5eff:fe0b:3596", &idev6.addr); */
|
||||||
|
/* inet_pton(AF_INET6, "2003:db8:1:0:214:1234:fe0b:3596", &idev6_2.addr); */
|
||||||
|
|
||||||
|
/* struct network veth = { */
|
||||||
|
/* .type = VETH, */
|
||||||
|
/* .netdev = { */
|
||||||
|
/* .flags = IFF_UP, */
|
||||||
|
/* .ifname = "br0", */
|
||||||
|
/* .newname = "eth0", */
|
||||||
|
/* .ipv4 = init_list(&veth.netdev.ipv4), */
|
||||||
|
/* .ipv6 = init_list(&veth.netdev.ipv6), */
|
||||||
|
/* }, */
|
||||||
|
/* }; */
|
||||||
|
/* vethlist.elem = &veth; */
|
||||||
|
|
||||||
|
/* list_add(&veth.netdev.ipv4, &l1); */
|
||||||
|
/* list_add(&veth.netdev.ipv4, &l2); */
|
||||||
|
/* list_add(&veth.netdev.ipv6, &l4); */
|
||||||
|
|
||||||
|
/* struct network veth2 = { */
|
||||||
|
/* .type = VETH, */
|
||||||
|
/* .netdev = { */
|
||||||
|
/* .flags = IFF_UP, */
|
||||||
|
/* .ifname = "br0", */
|
||||||
|
/* .newname = "eth1", */
|
||||||
|
/* .ipv4 = init_list(&veth2.netdev.ipv4), */
|
||||||
|
/* .ipv6 = init_list(&veth2.netdev.ipv6), */
|
||||||
|
/* }, */
|
||||||
|
/* }; */
|
||||||
|
/* list_add(&veth2.netdev.ipv6, &l3); */
|
||||||
|
/* vethlist2.elem = &veth2; */
|
||||||
|
|
||||||
|
/* struct network macvlan = { */
|
||||||
|
/* .type = MACVLAN, */
|
||||||
|
/* .netdev = { */
|
||||||
|
/* .flags = IFF_UP, */
|
||||||
|
/* .ifname = "eth0", */
|
||||||
|
/* .ipv4 = init_list(&macvlan.netdev.ipv4), */
|
||||||
|
/* .ipv6 = init_list(&macvlan.netdev.ipv6), */
|
||||||
|
/* }, */
|
||||||
|
/* }; */
|
||||||
|
/* mclist.elem = &macvlan; */
|
||||||
|
|
||||||
|
/* struct network macvlan2 = { */
|
||||||
|
/* .type = MACVLAN, */
|
||||||
|
/* .netdev = { */
|
||||||
|
/* .ifname = "eth0", */
|
||||||
|
/* .ipv4 = init_list(&macvlan2.netdev.ipv4), */
|
||||||
|
/* .ipv6 = init_list(&macvlan2.netdev.ipv6), */
|
||||||
|
/* }, */
|
||||||
|
/* }; */
|
||||||
|
/* mclist2.elem = &macvlan2; */
|
||||||
|
|
||||||
|
struct netdev nd = {
|
||||||
|
.ifname = "dummy0",
|
||||||
|
.ipv4 = init_list(&nd.ipv4),
|
||||||
|
.ipv6 = init_list(&nd.ipv6),
|
||||||
|
};
|
||||||
|
struct list ndlist = init_list(&ndlist);
|
||||||
|
ndlist.elem = &nd;
|
||||||
|
|
||||||
|
struct network phys = {
|
||||||
|
.type = PHYS,
|
||||||
|
.netdev = init_list(&phys.netdev),
|
||||||
|
};
|
||||||
|
phylist.elem = &phys;
|
||||||
|
|
||||||
|
struct lxc_conf lxc_conf = {
|
||||||
|
.networks = init_list(&lxc_conf.networks),
|
||||||
|
.chroot = "/mnt/iso",
|
||||||
|
};
|
||||||
|
|
||||||
|
list_add(&phys.netdev, &ndlist);
|
||||||
|
|
||||||
|
/* list_add(&lxc_conf.networks, &vethlist); */
|
||||||
|
/* list_add(&lxc_conf.networks, &mclist); */
|
||||||
|
list_add(&lxc_conf.networks, &phylist);
|
||||||
|
/* list_add(&lxc_conf.networks, &mclist); */
|
||||||
|
/* list_add(&lxc_conf.networks, &vethlist2); */
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "n:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'n':
|
||||||
|
name = optarg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!name)
|
||||||
|
usage(argv[0]);
|
||||||
|
|
||||||
|
if (lxc_create(name, &lxc_conf)) {
|
||||||
|
fprintf(stderr, "failed to create the container %s\n", name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
55
test/lxc_destroy.c
Normal file
55
test/lxc_destroy.c
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <lxc.h>
|
||||||
|
|
||||||
|
static void usage(const char *cmd)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s -n <name>\n", cmd);
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
const char *name = NULL;
|
||||||
|
int opt;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "n:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'n':
|
||||||
|
name = optarg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!name)
|
||||||
|
usage(argv[0]);
|
||||||
|
|
||||||
|
if (lxc_destroy(name)) {
|
||||||
|
fprintf(stderr, "failed to destroy %s\n", name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
100
test/lxc_monitor.c
Normal file
100
test/lxc_monitor.c
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
#include <state.h>
|
||||||
|
|
||||||
|
void usage(char *cmd)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s <command>\n", basename(cmd));
|
||||||
|
fprintf(stderr, "\t -n <name> : name of the container\n");
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char opt;
|
||||||
|
char *name = NULL;
|
||||||
|
int fds[2];
|
||||||
|
pid_t pid;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "n:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'n':
|
||||||
|
name = optarg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!name)
|
||||||
|
usage(argv[0]);
|
||||||
|
|
||||||
|
if (pipe(fds)) {
|
||||||
|
perror("pipe");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
pid = fork();
|
||||||
|
if (pid < 0) {
|
||||||
|
perror("fork");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pid) {
|
||||||
|
close(fds[0]);
|
||||||
|
if (lxc_monitor(name, fds[1])) {
|
||||||
|
fprintf(stderr, "failed to monitor %s\n", name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fds[1]);
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
int err, state;
|
||||||
|
|
||||||
|
err = read(fds[0], &state, sizeof(state));
|
||||||
|
if (err < 0) {
|
||||||
|
perror("read");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!err) {
|
||||||
|
printf("container has been destroyed\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("container has changed the state to %d - %s\n",
|
||||||
|
state, state2str(state));
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
84
test/lxc_start.c
Normal file
84
test/lxc_start.c
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/utsname.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
#include <state.h>
|
||||||
|
#include <list.h>
|
||||||
|
#include <conf.h>
|
||||||
|
|
||||||
|
void usage(char *cmd)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s <command>\n", basename(cmd));
|
||||||
|
fprintf(stderr, "\t -n <name> : name of the container\n");
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int prestart(const char *name, int argc, char *argv[], void *data)
|
||||||
|
{
|
||||||
|
printf("%s hook has been called with data %s\n",
|
||||||
|
__FUNCTION__, (char *)data);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char opt;
|
||||||
|
char *name = NULL;
|
||||||
|
char **args;
|
||||||
|
int nbargs = 0;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "n:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'n':
|
||||||
|
name = optarg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
nbargs++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!name || !argv[optind] || !strlen(argv[optind]))
|
||||||
|
usage(argv[0]);
|
||||||
|
|
||||||
|
args = &argv[optind];
|
||||||
|
argc -= nbargs;
|
||||||
|
|
||||||
|
if (lxc_start(name, argc, args, prestart, "hello world")) {
|
||||||
|
fprintf(stderr, "failed to start %s\n", name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
66
test/lxc_state.c
Normal file
66
test/lxc_state.c
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
#include <state.h>
|
||||||
|
|
||||||
|
void usage(char *cmd)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s <command>\n", basename(cmd));
|
||||||
|
fprintf(stderr, "\t -n <name> : name of the container\n");
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char opt;
|
||||||
|
char *name = NULL;
|
||||||
|
int state;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "n:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'n':
|
||||||
|
name = optarg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!name)
|
||||||
|
usage(argv[0]);
|
||||||
|
|
||||||
|
state = lxc_state(name);
|
||||||
|
if (state < 0) {
|
||||||
|
fprintf(stderr, "failed to retrieve the state of %s\n", name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("container has the state to %d - %s\n",
|
||||||
|
state, state2str(state));
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
59
test/lxc_stop.c
Normal file
59
test/lxc_stop.c
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
|
||||||
|
#include <lxc.h>
|
||||||
|
|
||||||
|
void usage(char *cmd)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s <command>\n", basename(cmd));
|
||||||
|
fprintf(stderr, "\t -n <name> : name of the container\n");
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char opt;
|
||||||
|
char *name = NULL;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "n:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'n':
|
||||||
|
name = optarg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!name)
|
||||||
|
usage(argv[0]);
|
||||||
|
|
||||||
|
if (lxc_stop(name)) {
|
||||||
|
fprintf(stderr, "failed to stop %s\n", name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
66
test/macvlan.c
Normal file
66
test/macvlan.c
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#include <network.h>
|
||||||
|
|
||||||
|
void usage(const char *cmd)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s -i <ifname> -p <ifname>\n", cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char *ifname = NULL, *peer = NULL;
|
||||||
|
int opt, ret = -EINVAL;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "i:p:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'i':
|
||||||
|
ifname = optarg;
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
peer = optarg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ifname || !peer) {
|
||||||
|
usage(argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = macvlan_create(ifname, peer);
|
||||||
|
if (ret) {
|
||||||
|
fprintf(stderr, "failed to set %s/%s: %s\n",
|
||||||
|
ifname, peer, strerror(-ret));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
64
test/movedev.c
Normal file
64
test/movedev.c
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <network.h>
|
||||||
|
|
||||||
|
void usage(const char *cmd)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s -i <ifname> -p <pid>\n", cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char *ifname = NULL;
|
||||||
|
pid_t pid = -1;
|
||||||
|
int opt;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "p:i:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'p':
|
||||||
|
pid = atoi(optarg);
|
||||||
|
break;
|
||||||
|
case 'i':
|
||||||
|
ifname = optarg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ifname || pid == -1) {
|
||||||
|
usage(argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (device_move(ifname, pid)) {
|
||||||
|
fprintf(stderr, "failed to move %s\n", ifname);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
77
test/proxy.c
Normal file
77
test/proxy.c
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#include <network.h>
|
||||||
|
|
||||||
|
void usage(const char *cmd)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s -i <ifname> -f <on|off>\n", cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char *ifname = NULL, *flag = NULL;
|
||||||
|
int opt, ret, family = AF_INET;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "6i:f:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'i':
|
||||||
|
ifname = optarg;
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
flag = optarg;
|
||||||
|
break;
|
||||||
|
case '6':
|
||||||
|
family = AF_INET6;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ifname || !flag) {
|
||||||
|
usage(argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strcmp(flag, "on"))
|
||||||
|
ret = neigh_proxy_on(ifname, family);
|
||||||
|
else if (!strcmp(flag, "off"))
|
||||||
|
ret = neigh_proxy_off(ifname, family);
|
||||||
|
else {
|
||||||
|
usage(argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret) {
|
||||||
|
fprintf(stderr, "failed for %s: %s\n",
|
||||||
|
ifname, strerror(-ret));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
66
test/tst_list.c
Normal file
66
test/tst_list.c
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <list.h>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
struct list *iterator;
|
||||||
|
struct list head = init_list(&head);
|
||||||
|
struct list l1 = init_list(&l1);
|
||||||
|
struct list l2 = init_list(&l2);
|
||||||
|
struct list l3 = init_list(&l3);
|
||||||
|
struct list l4 = init_list(&l4);
|
||||||
|
|
||||||
|
struct dummy {
|
||||||
|
int a;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct dummy *elem;
|
||||||
|
struct dummy d1 = { .a = 1 };
|
||||||
|
struct dummy d2 = { .a = 2 };
|
||||||
|
struct dummy d3 = { .a = 3 };
|
||||||
|
struct dummy d4 = { .a = 4 };
|
||||||
|
|
||||||
|
if (!list_empty(&head)) {
|
||||||
|
fprintf(stderr, "expected empty list\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
l1.elem = &d1;
|
||||||
|
l2.elem = &d2;
|
||||||
|
l3.elem = &d3;
|
||||||
|
l4.elem = &d4;
|
||||||
|
|
||||||
|
list_add(&head, &l1);
|
||||||
|
list_add(&head, &l2);
|
||||||
|
list_add(&head, &l3);
|
||||||
|
list_add(&head, &l4);
|
||||||
|
|
||||||
|
list_for_each(iterator, &head) {
|
||||||
|
elem = iterator->elem;
|
||||||
|
printf("elem has %d\n", elem->a);
|
||||||
|
}
|
||||||
|
|
||||||
|
list_del(&l3);
|
||||||
|
|
||||||
|
list_for_each(iterator, &head) {
|
||||||
|
elem = iterator->elem;
|
||||||
|
printf("elem has %d\n", elem->a);
|
||||||
|
}
|
||||||
|
|
||||||
|
list_del(&l1);
|
||||||
|
list_del(&l2);
|
||||||
|
list_del(&l4);
|
||||||
|
|
||||||
|
if (!list_empty(&head)) {
|
||||||
|
fprintf(stderr, "expected empty list\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
list_for_each(iterator, &head) {
|
||||||
|
fprintf(stderr, "should not loop\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
66
test/veth.c
Normal file
66
test/veth.c
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* lxc: linux Container library
|
||||||
|
*
|
||||||
|
* (C) Copyright IBM Corp. 2007, 2008
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Daniel Lezcano <dlezcano at fr.ibm.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#include <network.h>
|
||||||
|
|
||||||
|
void usage(const char *cmd)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s -i <ifname> -p <ifname>\n", cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char *ifname = NULL, *peer = NULL;
|
||||||
|
int opt, ret = -EINVAL;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "i:p:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'i':
|
||||||
|
ifname = optarg;
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
peer = optarg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ifname || !peer) {
|
||||||
|
usage(argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = veth_create(ifname, peer);
|
||||||
|
if (ret) {
|
||||||
|
fprintf(stderr, "failed to set %s/%s: %s\n",
|
||||||
|
ifname, peer, strerror(-ret));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user