mirror of
https://github.com/pygos/init.git
synced 2024-05-19 04:06:13 +02:00
Compare commits
64 commits
Author | SHA1 | Date | |
---|---|---|---|
David Oberhollenzer | 5307b95b93 | ||
David Oberhollenzer | 70ea16b0b4 | ||
David Oberhollenzer | 5f28289731 | ||
David Oberhollenzer | 0975ed0fb7 | ||
David Oberhollenzer | 9b43890591 | ||
David Oberhollenzer | 87a524d931 | ||
David Oberhollenzer | 9f9807d4d3 | ||
David Oberhollenzer | 0d985a7430 | ||
David Oberhollenzer | 60efd9dc33 | ||
David Oberhollenzer | 1c72dd2c2f | ||
David Oberhollenzer | 2e89d32a75 | ||
David Oberhollenzer | c1cb8491f9 | ||
David Oberhollenzer | c8c0f10ce1 | ||
David Oberhollenzer | be06641904 | ||
David Oberhollenzer | c3d14cbfa8 | ||
David Oberhollenzer | 7cfe6e8458 | ||
David Oberhollenzer | f844c4e2c2 | ||
David Oberhollenzer | 028394b8a5 | ||
David Oberhollenzer | 6fa0393be4 | ||
David Oberhollenzer | ba12700080 | ||
David Oberhollenzer | 9e7478397a | ||
David Oberhollenzer | c16735414b | ||
David Oberhollenzer | d16d260181 | ||
David Oberhollenzer | affe9e4b88 | ||
David Oberhollenzer | 72c02308cd | ||
David Oberhollenzer | 9fece2eb88 | ||
David Oberhollenzer | ec04681c4d | ||
David Oberhollenzer | a6c059203b | ||
David Oberhollenzer | e21840cfce | ||
David Oberhollenzer | 390175c406 | ||
David Oberhollenzer | 4f1b393cee | ||
David Oberhollenzer | 1850f31d6d | ||
David Oberhollenzer | 065d3b678d | ||
David Oberhollenzer | 11053ebe6a | ||
David Oberhollenzer | a9602ad6e0 | ||
David Oberhollenzer | 3f40c4d3ed | ||
David Oberhollenzer | 40ad83dc6a | ||
David Oberhollenzer | 23b713c3b5 | ||
David Oberhollenzer | 08f72865b2 | ||
David Oberhollenzer | c78bbd2f73 | ||
David Oberhollenzer | c544fcc7a3 | ||
David Oberhollenzer | 5b106abaed | ||
4ee949c1ca | |||
d9a5736bdf | |||
c14c3c0173 | |||
d983a282ed | |||
bf878d08dd | |||
dc6358b0e1 | |||
7ee95668ca | |||
4bcfd98764 | |||
a8f3360e93 | |||
5923ad488a | |||
b864c727c8 | |||
c0e8c7e245 | |||
074fe20a47 | |||
34f542b7cc | |||
1ffc240b3f | |||
acd09007a1 | |||
d4ce928fc0 | |||
b3773d09ea | |||
24e98f1e5b | |||
ef51a8e06f | |||
53bc182e09 | |||
24c90b7700 |
26
.gitignore
vendored
26
.gitignore
vendored
|
@ -20,31 +20,7 @@ reboot
|
|||
shutdown
|
||||
killall5
|
||||
runsvc
|
||||
syslog
|
||||
usyslogd
|
||||
klogd
|
||||
gcrond
|
||||
|
||||
services/sigkill
|
||||
services/sigterm
|
||||
services/devfs
|
||||
services/procfs
|
||||
services/sysfs
|
||||
services/ifrename
|
||||
services/ifcfg
|
||||
services/ifdown
|
||||
services/modules
|
||||
services/hostapd
|
||||
services/swclock
|
||||
services/swclocksave
|
||||
services/nft
|
||||
services/sshd
|
||||
services/sshd_keygen
|
||||
services/swclocksave.gcron
|
||||
|
||||
scripts/devfs.sh
|
||||
scripts/ifrename.sh
|
||||
scripts/ifcfg.sh
|
||||
scripts/modules_load.sh
|
||||
waitfile
|
||||
|
||||
etc/initd.env
|
||||
|
|
687
LICENSE
687
LICENSE
|
@ -1,674 +1,13 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, 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
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If 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 convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU 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
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "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 PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state 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 program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
Copyright (c) 2018 David Oberhollenzer <goliath@infraroot.at>
|
||||
|
||||
Permission to use, copy, modify, and distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
|
40
Makefile.am
40
Makefile.am
|
@ -6,24 +6,21 @@ AM_CFLAGS = $(WARN_CFLAGS)
|
|||
bin_PROGRAMS =
|
||||
sbin_PROGRAMS =
|
||||
noinst_LIBRARIES =
|
||||
nobase_sysconf_DATA = netcfg/ifrename
|
||||
nobase_sysconf_DATA =
|
||||
sysconf_DATA = etc/initd.env
|
||||
EXTRA_DIST = README.md LICENSE docs netcfg
|
||||
|
||||
helperdir = @SCRIPTDIR@
|
||||
helper_PROGRAMS =
|
||||
helper_SCRIPTS =
|
||||
|
||||
EXTRA_DIST = README.md LICENSE docs
|
||||
|
||||
dist_man1_MANS =
|
||||
dist_man8_MANS =
|
||||
|
||||
include lib/Makemodule.am
|
||||
include cmd/Makemodule.am
|
||||
include initd/Makemodule.am
|
||||
include crond/Makemodule.am
|
||||
include scripts/Makemodule.am
|
||||
include services/Makemodule.am
|
||||
include syslogd/Makemodule.am
|
||||
|
||||
install-exec-hook:
|
||||
(cd $(DESTDIR)$(sbindir); $(LN_S) shutdown reboot)
|
||||
|
@ -32,33 +29,4 @@ install-data-local:
|
|||
$(MKDIR_P) $(DESTDIR)$(man8dir)
|
||||
(cd $(DESTDIR)$(man8dir); $(LN_S) shutdown.8 reboot.8)
|
||||
$(MKDIR_P) $(DESTDIR)$(SVCDIR)
|
||||
$(LN_S) $(TEMPLATEDIR)/loopback $(DESTDIR)$(SVCDIR)/loopback
|
||||
$(LN_S) $(TEMPLATEDIR)/hostname $(DESTDIR)$(SVCDIR)/hostname
|
||||
$(LN_S) $(TEMPLATEDIR)/sysctl $(DESTDIR)$(SVCDIR)/sysctl
|
||||
$(LN_S) $(TEMPLATEDIR)/sysinit $(DESTDIR)$(SVCDIR)/sysinit
|
||||
$(LN_S) $(TEMPLATEDIR)/procfs $(DESTDIR)$(SVCDIR)/procfs
|
||||
$(LN_S) $(TEMPLATEDIR)/sysfs $(DESTDIR)$(SVCDIR)/sysfs
|
||||
$(LN_S) $(TEMPLATEDIR)/devfs $(DESTDIR)$(SVCDIR)/devfs
|
||||
$(LN_S) $(TEMPLATEDIR)/tmpfs $(DESTDIR)$(SVCDIR)/tmpfs
|
||||
$(LN_S) $(TEMPLATEDIR)/vfs $(DESTDIR)$(SVCDIR)/vfs
|
||||
$(LN_S) $(TEMPLATEDIR)/ifdown $(DESTDIR)$(SVCDIR)/ifdown@shutdown
|
||||
$(LN_S) $(TEMPLATEDIR)/sync $(DESTDIR)$(SVCDIR)/sync@shutdown
|
||||
$(LN_S) $(TEMPLATEDIR)/sigkill $(DESTDIR)$(SVCDIR)/sigkill@shutdown
|
||||
$(LN_S) $(TEMPLATEDIR)/sigterm $(DESTDIR)$(SVCDIR)/sigterm@shutdown
|
||||
$(LN_S) $(TEMPLATEDIR)/sync $(DESTDIR)$(SVCDIR)/sync@reboot
|
||||
$(LN_S) $(TEMPLATEDIR)/sigkill $(DESTDIR)$(SVCDIR)/sigkill@reboot
|
||||
$(LN_S) $(TEMPLATEDIR)/sigterm $(DESTDIR)$(SVCDIR)/sigterm@reboot
|
||||
$(LN_S) $(TEMPLATEDIR)/ifdown $(DESTDIR)$(SVCDIR)/ifdown@reboot
|
||||
$(LN_S) $(TEMPLATEDIR)/ifcfg $(DESTDIR)$(SVCDIR)/ifcfg
|
||||
$(LN_S) $(TEMPLATEDIR)/modules $(DESTDIR)$(SVCDIR)/modules
|
||||
$(LN_S) $(TEMPLATEDIR)/network $(DESTDIR)$(SVCDIR)/network
|
||||
if GCROND
|
||||
$(MKDIR_P) $(DESTDIR)$(GCRONDIR)
|
||||
$(LN_S) $(TEMPLATEDIR)/gcrond $(DESTDIR)$(SVCDIR)/gcrond
|
||||
endif
|
||||
if USYSLOGD
|
||||
$(LN_S) $(TEMPLATEDIR)/usyslogd $(DESTDIR)$(SVCDIR)/usyslogd
|
||||
endif
|
||||
if KLOGD
|
||||
$(LN_S) $(TEMPLATEDIR)/klogd $(DESTDIR)$(SVCDIR)/klogd
|
||||
endif
|
||||
$(MKDIR_P) $(DESTDIR)$(TEMPLATEDIR)
|
||||
|
|
36
README.md
36
README.md
|
@ -1,16 +1,8 @@
|
|||
# About
|
||||
|
||||
This directory contains the source code for a tiny service supervision
|
||||
framework devised for the Pygos system, consisting of an init daemon,
|
||||
a small syslog daemon, a _definitely_ non standards compliant cron
|
||||
implementation and various command line utilities.
|
||||
|
||||
The individual parts of the framework are designed to be independent of
|
||||
each other (for instance, the tiny syslogd is intended to work with *any*
|
||||
init system and other components of the framework don't depend on the presence
|
||||
of this *specific* syslog implementation) and everything that is not strictly
|
||||
part of the init system (such as the syslog daemon) can be disabled through
|
||||
the configure script.
|
||||
framework devised for the Pygos system, consisting of an init daemon and
|
||||
accompanying command line utilities.
|
||||
|
||||
|
||||
The programs of this package are developed first and foremost for GNU/Linux
|
||||
|
@ -30,19 +22,18 @@ in `/etc/init.d`. This can be done more conveniently using the `service`
|
|||
command line tool.
|
||||
|
||||
|
||||
A default setup is provided, as needed for the Pygos system, including helper
|
||||
scripts for setting up mount points and for network configuration. If you want
|
||||
to use the init daemon for another system, you may have to toss out or adapt
|
||||
some of the default configuration and make your own.
|
||||
A default setup for the Pygos system, including helper scripts for setting up
|
||||
mount points and for network configuration, is provided in a seperate package.
|
||||
This package only contains the bare init framework without any default
|
||||
configuration.
|
||||
|
||||
|
||||
Right now, the system is in a "basically works" proof of concept stage and
|
||||
needs some more work to become usable.
|
||||
|
||||
There are plans for *maybe* *eventually* adding more fancy features like
|
||||
support for Linux name spaces, seccomp filters and cgroups or network
|
||||
back ends for the syslog daemon, but right now, features are added only
|
||||
when the need arises.
|
||||
support for Linux name spaces, seccomp filters and cgroups, but right now,
|
||||
features are added only when the need arises.
|
||||
|
||||
|
||||
See [docs/init.md](docs/init.md) for more information on the design,
|
||||
|
@ -54,17 +45,6 @@ command line tools.
|
|||
See [docs/services.md](docs/services.md) for more information on service
|
||||
description files.
|
||||
|
||||
See [docs/network.md](docs/network.md) for information on how the network
|
||||
configuration works.
|
||||
|
||||
See [docs/defconfig.md](docs/defconfig.md) for an explanation on the default
|
||||
services and configuration provided with this package.
|
||||
|
||||
See [docs/usyslogd.md](docs/usyslogd.md) for details on the tiny syslog
|
||||
implementation.
|
||||
|
||||
See [docs/gcron.md](docs/gcron.md) for details on the cron implementation.
|
||||
|
||||
|
||||
## Why
|
||||
|
||||
|
|
|
@ -2,49 +2,33 @@ shutdown_SOURCES = cmd/shutdown.c
|
|||
shutdown_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
shutdown_CFLAGS = $(AM_CFLAGS)
|
||||
shutdown_LDFLAGS = $(AM_LDFLAGS)
|
||||
shutdown_LDADD = libinit.a
|
||||
|
||||
runsvc_SOURCES = cmd/runsvc/runsvc.c cmd/runsvc/env.c cmd/runsvc/runsvc.h
|
||||
runsvc_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
runsvc_CFLAGS = $(AM_CFLAGS)
|
||||
runsvc_LDFLAGS = $(AM_LDFLAGS)
|
||||
runsvc_LDADD = libinit.a libcfg.a
|
||||
|
||||
killall5_SOURCES = cmd/killall5.c
|
||||
killall5_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
killall5_CFLAGS = $(AM_CFLAGS)
|
||||
killall5_LDFLAGS = $(AM_LDFLAGS)
|
||||
|
||||
waitfile_SOURCES = cmd/waitfile.c
|
||||
waitfile_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
waitfile_CFLAGS = $(AM_CFLAGS)
|
||||
waitfile_LDFLAGS = $(AM_LDFLAGS)
|
||||
|
||||
SRVHEADERS = cmd/service/servicecmd.h
|
||||
|
||||
service_SOURCES = cmd/service/servicecmd.c cmd/service/help.c
|
||||
service_SOURCES += cmd/service/enable.c cmd/service/disable.c
|
||||
service_SOURCES += cmd/service/dumpscript.c cmd/service/list.c
|
||||
service_SOURCES += cmd/service/status.c cmd/service/loadsvc.c
|
||||
service_SOURCES += cmd/service/startstop.c
|
||||
service_SOURCES += $(SRVHEADERS)
|
||||
service_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
service_CFLAGS = $(AM_CFLAGS)
|
||||
service_LDFLAGS = $(AM_LDFLAGS)
|
||||
service_LDADD = libinit.a libcfg.a
|
||||
|
||||
if GCROND
|
||||
service_SOURCES += cmd/service/schedule.c
|
||||
service_SOURCES += cmd/service/unschedule.c
|
||||
endif
|
||||
|
||||
if USYSLOGD
|
||||
syslog_SOURCES = cmd/syslog.c
|
||||
syslog_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
syslog_CFLAGS = $(AM_CFLAGS)
|
||||
syslog_LDFLAGS = $(AM_LDFLAGS)
|
||||
syslog_LDADD = libinit.a
|
||||
|
||||
bin_PROGRAMS += syslog
|
||||
dist_man1_MANS += cmd/syslog.1
|
||||
endif
|
||||
|
||||
dist_man8_MANS += cmd/shutdown.8 cmd/service/service.8
|
||||
|
||||
EXTRA_DIST += $(SRVHEADERS)
|
||||
|
||||
sbin_PROGRAMS += service shutdown
|
||||
helper_PROGRAMS += killall5 runsvc
|
||||
helper_PROGRAMS += killall5 waitfile
|
||||
|
|
|
@ -1,20 +1,4 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* SPDX-License-Identifier: ISC */
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <signal.h>
|
||||
|
@ -25,9 +9,7 @@
|
|||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
static NORETURN void usage_and_exit(void)
|
||||
static __attribute__((noreturn)) void usage_and_exit(void)
|
||||
{
|
||||
fputs("Usage: killall5 SIGNAL\n", stderr);
|
||||
exit(EXIT_FAILURE);
|
||||
|
|
130
cmd/runsvc/env.c
130
cmd/runsvc/env.c
|
@ -1,130 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "runsvc.h"
|
||||
|
||||
struct entry {
|
||||
struct entry *next;
|
||||
char data[];
|
||||
};
|
||||
|
||||
extern char **environ;
|
||||
|
||||
static void free_list(struct entry *list)
|
||||
{
|
||||
struct entry *e;
|
||||
|
||||
while (list != NULL) {
|
||||
e = list;
|
||||
list = list->next;
|
||||
free(e);
|
||||
}
|
||||
}
|
||||
|
||||
static struct entry *parse_list(rdline_t *rd)
|
||||
{
|
||||
struct entry *e, *list = NULL;
|
||||
char *ptr;
|
||||
|
||||
while (rdline(rd) == 0) {
|
||||
ptr = rd->buffer;
|
||||
|
||||
while (*ptr != '\0' && *ptr != ' ' && *ptr != '=')
|
||||
++ptr;
|
||||
|
||||
if (*ptr == ' ')
|
||||
memmove(ptr, ptr + 1, strlen(ptr + 1) + 1);
|
||||
|
||||
if (*(ptr++) != '=') {
|
||||
fprintf(stderr, "%s: %zu: line is not of the shape "
|
||||
"'key = value', skipping\n",
|
||||
rd->filename, rd->lineno);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (*ptr == ' ')
|
||||
memmove(ptr, ptr + 1, strlen(ptr + 1) + 1);
|
||||
|
||||
if (unescape(ptr)) {
|
||||
fprintf(stderr, "%s: %zu: malformed string constant, "
|
||||
"skipping\n",
|
||||
rd->filename, rd->lineno);
|
||||
continue;
|
||||
}
|
||||
|
||||
e = calloc(1, sizeof(*e) + strlen(rd->buffer) + 1);
|
||||
if (e == NULL)
|
||||
goto fail_oom;
|
||||
|
||||
strcpy(e->data, rd->buffer);
|
||||
e->next = list;
|
||||
list = e;
|
||||
}
|
||||
|
||||
return list;
|
||||
fail_oom:
|
||||
fputs("out of memory\n", stderr);
|
||||
free_list(list);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct entry *list_from_file(void)
|
||||
{
|
||||
struct entry *list;
|
||||
rdline_t rd;
|
||||
int fd;
|
||||
|
||||
fd = open(ENVFILE, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
perror(ENVFILE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rdline_init(&rd, fd, ENVFILE, 0, NULL);
|
||||
list = parse_list(&rd);
|
||||
close(fd);
|
||||
return list;
|
||||
}
|
||||
|
||||
int initenv(void)
|
||||
{
|
||||
struct entry *list, *e;
|
||||
int i, count;
|
||||
char **envp;
|
||||
|
||||
list = list_from_file();
|
||||
if (list == NULL)
|
||||
return -1;
|
||||
|
||||
for (count = 0, e = list; e != NULL; e = e->next)
|
||||
++count;
|
||||
|
||||
envp = malloc((count + 1) * sizeof(char *));
|
||||
if (envp == NULL) {
|
||||
fputs("out of memory\n", stderr);
|
||||
free_list(list);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0, e = list; e != NULL; e = e->next)
|
||||
envp[i] = e->data;
|
||||
|
||||
envp[i] = NULL;
|
||||
|
||||
environ = envp;
|
||||
return 0;
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "runsvc.h"
|
||||
|
||||
static int runlst_wait(exec_t *list)
|
||||
{
|
||||
pid_t ret, pid;
|
||||
int status;
|
||||
|
||||
for (; list != NULL; list = list->next) {
|
||||
pid = fork();
|
||||
|
||||
if (pid == 0)
|
||||
argv_exec(list);
|
||||
|
||||
if (pid == -1) {
|
||||
perror("fork");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
do {
|
||||
ret = waitpid(pid, &status, 0);
|
||||
} while (ret != pid);
|
||||
|
||||
if (!WIFEXITED(status))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if (WEXITSTATUS(status) != EXIT_SUCCESS)
|
||||
return WEXITSTATUS(status);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int dirfd, ret = EXIT_FAILURE;
|
||||
service_t *svc = NULL;
|
||||
|
||||
if (argc != 3) {
|
||||
fputs("usage: runsvc <directory> <filename>\n", stderr);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (getppid() != 1) {
|
||||
fputs("must be run by init!\n", stderr);
|
||||
goto out;
|
||||
}
|
||||
|
||||
dirfd = open(argv[1], O_RDONLY | O_DIRECTORY);
|
||||
if (dirfd < 0) {
|
||||
perror(argv[1]);
|
||||
goto out;
|
||||
}
|
||||
|
||||
svc = rdsvc(dirfd, argv[2], RDSVC_NO_FNAME | RDSVC_NO_DEPS);
|
||||
close(dirfd);
|
||||
if (svc == NULL)
|
||||
goto out;
|
||||
|
||||
if (svc->exec == NULL) {
|
||||
ret = EXIT_SUCCESS;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (initenv())
|
||||
goto out;
|
||||
|
||||
if (setup_tty(svc->ctty, (svc->flags & SVC_FLAG_TRUNCATE_OUT) != 0))
|
||||
goto out;
|
||||
|
||||
if (svc->exec->next == NULL)
|
||||
argv_exec(svc->exec);
|
||||
|
||||
ret = runlst_wait(svc->exec);
|
||||
out:
|
||||
delsvc(svc);
|
||||
return ret;
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef RUNSVC_H
|
||||
#define RUNSVC_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "service.h"
|
||||
#include "libcfg.h"
|
||||
#include "util.h"
|
||||
|
||||
#define ENVFILE ETCPATH "/initd.env"
|
||||
|
||||
int initenv(void);
|
||||
|
||||
#endif /* RUNSVC_H */
|
|
@ -1,25 +1,10 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* SPDX-License-Identifier: ISC */
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
@ -71,6 +56,8 @@ static int cmd_disable(int argc, char **argv)
|
|||
goto out;
|
||||
}
|
||||
|
||||
kill(1, SIGHUP);
|
||||
|
||||
ret = EXIT_SUCCESS;
|
||||
out:
|
||||
free(linkname);
|
||||
|
|
|
@ -1,20 +1,4 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* SPDX-License-Identifier: ISC */
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
@ -22,37 +6,6 @@
|
|||
#include <errno.h>
|
||||
|
||||
#include "servicecmd.h"
|
||||
#include "service.h"
|
||||
|
||||
static service_t *try_load(const char *directory, const char *filename)
|
||||
{
|
||||
int dirfd, type;
|
||||
struct stat sb;
|
||||
service_t *svc;
|
||||
|
||||
dirfd = open(directory, O_RDONLY | O_DIRECTORY);
|
||||
|
||||
if (dirfd < 0) {
|
||||
perror(directory);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (fstatat(dirfd, filename, &sb, AT_SYMLINK_NOFOLLOW)) {
|
||||
fprintf(stderr, "stat %s/%s: %s\n",
|
||||
directory, filename, strerror(errno));
|
||||
close(dirfd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
type = (sb.st_mode & S_IFMT);
|
||||
|
||||
if (type != S_IFREG && type != S_IFLNK)
|
||||
return NULL;
|
||||
|
||||
svc = rdsvc(dirfd, filename, 0);
|
||||
close(dirfd);
|
||||
return svc;
|
||||
}
|
||||
|
||||
enum {
|
||||
NEED_QUOTES = 0x01,
|
||||
|
@ -140,7 +93,7 @@ static int cmd_dumpscript(int argc, char **argv)
|
|||
strcat(filename, argv[i]);
|
||||
}
|
||||
|
||||
svc = try_load(SVCDIR, filename);
|
||||
svc = loadsvc(SVCDIR, filename);
|
||||
|
||||
if (svc == NULL) {
|
||||
fprintf(stderr, "Could not load service '%s'\n", filename);
|
||||
|
@ -160,7 +113,7 @@ static int cmd_dumpscript(int argc, char **argv)
|
|||
print_str(ptr);
|
||||
ptr += strlen(ptr) + 1;
|
||||
}
|
||||
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
|
|
|
@ -1,25 +1,10 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* SPDX-License-Identifier: ISC */
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
@ -76,6 +61,8 @@ static int cmd_enable(int argc, char **argv)
|
|||
goto out;
|
||||
}
|
||||
|
||||
kill(1, SIGHUP);
|
||||
|
||||
ret = EXIT_SUCCESS;
|
||||
out:
|
||||
free(linkname);
|
||||
|
|
|
@ -1,20 +1,4 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* SPDX-License-Identifier: ISC */
|
||||
#include "servicecmd.h"
|
||||
|
||||
extern char *__progname;
|
||||
|
|
|
@ -1,20 +1,4 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* SPDX-License-Identifier: ISC */
|
||||
#include "servicecmd.h"
|
||||
#include "service.h"
|
||||
#include "config.h"
|
||||
|
@ -40,7 +24,7 @@ static int cmd_list(int argc, char **argv)
|
|||
if (check_arguments(argv[0], argc, 1, 2))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if (svcscan(SVCDIR, &list, 0)) {
|
||||
if (svcscan(SVCDIR, &list)) {
|
||||
fprintf(stderr, "Error while reading services from %s\n",
|
||||
SVCDIR);
|
||||
ret = EXIT_FAILURE;
|
||||
|
|
23
cmd/service/loadsvc.c
Normal file
23
cmd/service/loadsvc.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
/* SPDX-License-Identifier: ISC */
|
||||
#include "servicecmd.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
|
||||
service_t *loadsvc(const char *directory, const char *filename)
|
||||
{
|
||||
service_t *svc;
|
||||
int dirfd;
|
||||
|
||||
dirfd = open(directory, O_RDONLY | O_DIRECTORY);
|
||||
|
||||
if (dirfd < 0) {
|
||||
perror(directory);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
svc = rdsvc(dirfd, filename);
|
||||
close(dirfd);
|
||||
return svc;
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "servicecmd.h"
|
||||
|
||||
static int cmd_schedule(int argc, char **argv)
|
||||
{
|
||||
char *target, *linkname, *ptr;
|
||||
int ret = EXIT_FAILURE;
|
||||
struct stat sb;
|
||||
|
||||
if (check_arguments(argv[0], argc, 2, 2))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
for (ptr = argv[1]; isalnum(*ptr) || *ptr == '_'; ++ptr)
|
||||
;
|
||||
|
||||
if (*ptr != '\0') {
|
||||
fprintf(stderr, "Invalid service name '%s'\n", argv[1]);
|
||||
tell_read_help(argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (asprintf(&target, "%s/%s.gcron", TEMPLATEDIR, argv[1]) < 0) {
|
||||
perror("asprintf");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (stat(target, &sb)) {
|
||||
fprintf(stderr, "%s: %s\n", target, strerror(errno));
|
||||
goto out_tgt;
|
||||
}
|
||||
|
||||
if ((sb.st_mode & S_IFMT) != S_IFREG) {
|
||||
fprintf(stderr, "%s: must be a regular file\n", target);
|
||||
goto out_tgt;
|
||||
}
|
||||
|
||||
if (asprintf(&linkname, "%s/%s", GCRONDIR, argv[1]) < 0) {
|
||||
perror("asprintf");
|
||||
goto out_tgt;
|
||||
}
|
||||
|
||||
if (symlink(target, linkname)) {
|
||||
fprintf(stderr, "creating symlink '%s' -> '%s: %s\n",
|
||||
linkname, target, strerror(errno));
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = EXIT_SUCCESS;
|
||||
out:
|
||||
free(linkname);
|
||||
out_tgt:
|
||||
free(target);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static command_t schedule = {
|
||||
.cmd = "schedule",
|
||||
.usage = "<name>",
|
||||
.s_desc = "enable a gcrond service",
|
||||
.l_desc = "This marks a gcrond service as enabled by creating a "
|
||||
"symlink in " GCRONDIR " pointing to a template file in "
|
||||
TEMPLATEDIR " with a .gcron extension.",
|
||||
.run_cmd = cmd_schedule,
|
||||
};
|
||||
|
||||
REGISTER_COMMAND(schedule)
|
|
@ -28,12 +28,6 @@ configuration directory, pointing to the service template file.
|
|||
|
||||
An optional argument can be supplied to parameterize the template.
|
||||
.TP
|
||||
.BR schedule " " \fI<service>\fP
|
||||
If built with support for gcrond, enable a gcron service by creating a symlink
|
||||
in the gcrond configuration directory, pointing to the service file.
|
||||
|
||||
The extension \fB.gcron\fP is automatically appended to the service name.
|
||||
.TP
|
||||
.BR disable " " \fI<service>\fP " " \fI[arguments]\fP
|
||||
Disable (but do not stop) a system service by removing the corresponding
|
||||
symlink in the configuration directory.
|
||||
|
@ -41,19 +35,26 @@ symlink in the configuration directory.
|
|||
If the service is parameterized, arguments have to be specified to disable
|
||||
the desired service instance.
|
||||
.TP
|
||||
.BR unschedule " " \fI<service>\fP
|
||||
If built with support for gcrond, disable a gcron service by removing the
|
||||
corresponding symlink in the gcron configuration directory.
|
||||
.TP
|
||||
.BR dumpscript " " \fI<service>\fP " " \fI[arguments]\fP
|
||||
Parse a service file from and produce a pseudo shell script containing the
|
||||
exact commands executed when starting the service.
|
||||
.TP
|
||||
.BR status " " \fI[--detail|-d]\fP " " \fI[services...]\fP
|
||||
Print a status report of all supervised services, i.e. if they are currently
|
||||
running, have exited or waiting to be scheduled. A specific list of services
|
||||
can be specified. Shell globbing patterns can be used.
|
||||
.TP
|
||||
.BR start " " \fIservices...\fP
|
||||
Start one or more currently not running services. Shell globbing patterns can be used.
|
||||
.TP
|
||||
.BR stop " " \fIservices...\fP
|
||||
Stop one or more currently running services. Shell globbing patterns can be used.
|
||||
.SH AVAILABILITY
|
||||
This program is part of the Pygos init system.
|
||||
.SH COPYRIGHT
|
||||
Copyright \(co 2018 David Oberhollenzer
|
||||
.br
|
||||
License: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
|
||||
License: ISC <https://www.gnu.org/licenses/license-list.html#ISC>.
|
||||
.br
|
||||
This is free software: you are free to change and redistribute it.
|
||||
There is NO WARRANTY, to the extent permitted by law.
|
||||
|
|
|
@ -1,27 +1,10 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* SPDX-License-Identifier: ISC */
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "servicecmd.h"
|
||||
#include "service.h"
|
||||
#include "config.h"
|
||||
#include "util.h"
|
||||
|
||||
|
||||
command_t *commands;
|
||||
|
|
|
@ -1,29 +1,15 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* SPDX-License-Identifier: ISC */
|
||||
#ifndef SERVICECMD_H
|
||||
#define SERVICECMD_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "service.h"
|
||||
#include "config.h"
|
||||
|
||||
/*
|
||||
Describes a command that can be launched by passing its name as
|
||||
|
@ -54,11 +40,13 @@ typedef struct command_t {
|
|||
/* Global list of available commands */
|
||||
extern command_t *commands;
|
||||
|
||||
service_t *loadsvc(const char *directory, const char *filename);
|
||||
|
||||
/*
|
||||
Implemented in servicecmd.c. Prints program usage message and
|
||||
terminates with the given exit status.
|
||||
*/
|
||||
void usage(int status) NORETURN;
|
||||
void usage(int status) __attribute__((noreturn));
|
||||
|
||||
/*
|
||||
Write a message to stderr that advises the user how to consult the
|
||||
|
@ -90,4 +78,3 @@ int check_arguments(const char *cmd, int argc, int minc, int maxc);
|
|||
}
|
||||
|
||||
#endif /* SERVICECMD_H */
|
||||
|
||||
|
|
104
cmd/service/startstop.c
Normal file
104
cmd/service/startstop.c
Normal file
|
@ -0,0 +1,104 @@
|
|||
/* SPDX-License-Identifier: ISC */
|
||||
#include "servicecmd.h"
|
||||
#include "initsock.h"
|
||||
#include "service.h"
|
||||
#include "config.h"
|
||||
|
||||
#include <fnmatch.h>
|
||||
#include <getopt.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static int cmd_startstop(int argc, char **argv,
|
||||
E_SERVICE_STATE filter, E_INIT_REQUEST action)
|
||||
{
|
||||
int i, fd, ret = EXIT_FAILURE;
|
||||
init_status_t resp;
|
||||
char tmppath[256];
|
||||
bool found;
|
||||
|
||||
if (check_arguments(argv[0], argc, 2, 2))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
sprintf(tmppath, "/tmp/svcstatus.%d.sock", (int)getpid());
|
||||
fd = init_socket_open(tmppath);
|
||||
|
||||
if (fd < 0) {
|
||||
unlink(tmppath);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (init_socket_send_request(fd, EIR_STATUS, filter))
|
||||
goto out;
|
||||
|
||||
for (;;) {
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
|
||||
if (init_socket_recv_status(fd, &resp)) {
|
||||
perror("reading from initd socket");
|
||||
free_init_status(&resp);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (resp.state == ESS_NONE) {
|
||||
free_init_status(&resp);
|
||||
break;
|
||||
}
|
||||
|
||||
found = false;
|
||||
|
||||
for (i = optind; i < argc; ++i) {
|
||||
if (fnmatch(argv[i], resp.service_name, 0) == 0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
if (fnmatch(argv[i], resp.filename, 0) == 0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
if (init_socket_send_request(fd, action, resp.id))
|
||||
goto out;
|
||||
}
|
||||
|
||||
free_init_status(&resp);
|
||||
}
|
||||
|
||||
ret = EXIT_SUCCESS;
|
||||
out:
|
||||
close(fd);
|
||||
unlink(tmppath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int cmd_start(int argc, char **argv)
|
||||
{
|
||||
return cmd_startstop(argc, argv, ESS_NONE, EIR_START);
|
||||
}
|
||||
|
||||
static int cmd_stop(int argc, char **argv)
|
||||
{
|
||||
return cmd_startstop(argc, argv, ESS_NONE, EIR_STOP);
|
||||
}
|
||||
|
||||
static command_t start = {
|
||||
.cmd = "start",
|
||||
.usage = "services...",
|
||||
.s_desc = "start a currently not running service",
|
||||
.l_desc = "Start one or more service that are currently not running. "
|
||||
"Shell style globbing patterns can used for service names.",
|
||||
.run_cmd = cmd_start,
|
||||
};
|
||||
|
||||
static command_t stop = {
|
||||
.cmd = "stop",
|
||||
.usage = "services...",
|
||||
.s_desc = "stop a currently running service",
|
||||
.l_desc = "Stop one or more service that are currently running. "
|
||||
"Shell style globbing patterns can used for service names.",
|
||||
.run_cmd = cmd_stop,
|
||||
};
|
||||
|
||||
REGISTER_COMMAND(start)
|
||||
REGISTER_COMMAND(stop)
|
170
cmd/service/status.c
Normal file
170
cmd/service/status.c
Normal file
|
@ -0,0 +1,170 @@
|
|||
/* SPDX-License-Identifier: ISC */
|
||||
#include "servicecmd.h"
|
||||
#include "initsock.h"
|
||||
#include "service.h"
|
||||
#include "config.h"
|
||||
|
||||
#include <fnmatch.h>
|
||||
#include <getopt.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static const struct option long_opts[] = {
|
||||
{ "detail", no_argument, NULL, 'd' },
|
||||
{ NULL, 0, NULL, 0 },
|
||||
};
|
||||
|
||||
static const char *short_opts = "d";
|
||||
|
||||
static int cmd_status(int argc, char **argv)
|
||||
{
|
||||
bool is_tty, found, show_details = false;
|
||||
int i, fd, ret = EXIT_FAILURE;
|
||||
init_status_t resp;
|
||||
char tmppath[256];
|
||||
const char *state;
|
||||
service_t *svc;
|
||||
|
||||
for (;;) {
|
||||
i = getopt_long(argc, argv, short_opts, long_opts, NULL);
|
||||
if (i == -1)
|
||||
break;
|
||||
|
||||
switch (i) {
|
||||
case 'd':
|
||||
show_details = true;
|
||||
break;
|
||||
default:
|
||||
tell_read_help(argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
sprintf(tmppath, "/tmp/svcstatus.%d.sock", (int)getpid());
|
||||
fd = init_socket_open(tmppath);
|
||||
|
||||
if (fd < 0) {
|
||||
unlink(tmppath);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (init_socket_send_request(fd, EIR_STATUS, ESS_NONE))
|
||||
goto out;
|
||||
|
||||
is_tty = (isatty(STDOUT_FILENO) == 1);
|
||||
|
||||
for (;;) {
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
|
||||
if (init_socket_recv_status(fd, &resp)) {
|
||||
perror("reading from initd socket");
|
||||
free_init_status(&resp);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (resp.state == ESS_NONE) {
|
||||
free_init_status(&resp);
|
||||
break;
|
||||
}
|
||||
|
||||
if (optind < argc) {
|
||||
found = false;
|
||||
|
||||
for (i = optind; i < argc; ++i) {
|
||||
if (fnmatch(argv[i],
|
||||
resp.service_name, 0) == 0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
if (fnmatch(argv[i], resp.filename, 0) == 0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
free_init_status(&resp);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
switch (resp.state) {
|
||||
case ESS_RUNNING:
|
||||
if (!is_tty) {
|
||||
state = "UP";
|
||||
break;
|
||||
}
|
||||
state = "\033[22;32m UP \033[0m";
|
||||
break;
|
||||
case ESS_ENQUEUED:
|
||||
state = "SCHED";
|
||||
break;
|
||||
case ESS_FAILED:
|
||||
if (!is_tty) {
|
||||
state = "FAIL";
|
||||
break;
|
||||
}
|
||||
state = "\033[22;31mFAIL\033[0m";
|
||||
break;
|
||||
case ESS_DONE:
|
||||
if (!is_tty) {
|
||||
state = "DONE";
|
||||
break;
|
||||
}
|
||||
|
||||
state = "\033[22;33mDONE\033[0m";
|
||||
break;
|
||||
default:
|
||||
if (!is_tty) {
|
||||
state = "UNKNOWN";
|
||||
break;
|
||||
}
|
||||
state = "\033[22;31mUNKNOWN\033[0m";
|
||||
break;
|
||||
}
|
||||
|
||||
if (show_details) {
|
||||
printf("Service: %s\n", resp.filename);
|
||||
printf("\tStatus: %s\n", state);
|
||||
printf("\tTemplate name: %s\n", resp.service_name);
|
||||
printf("\tExit status: %d\n", resp.exit_status);
|
||||
|
||||
svc = loadsvc(SVCDIR, resp.filename);
|
||||
|
||||
if (svc == NULL) {
|
||||
fputs("\tError loading service file\n", stdout);
|
||||
} else {
|
||||
printf("\tDescription: %s\n", svc->desc);
|
||||
printf("\tType: %s\n",
|
||||
svc_type_to_string(svc->type));
|
||||
printf("\tTarget: %s\n",
|
||||
svc_target_to_string(svc->target));
|
||||
delsvc(svc);
|
||||
}
|
||||
} else {
|
||||
printf("[%s] %s\n", state, resp.filename);
|
||||
}
|
||||
|
||||
free_init_status(&resp);
|
||||
}
|
||||
|
||||
ret = EXIT_SUCCESS;
|
||||
out:
|
||||
close(fd);
|
||||
unlink(tmppath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static command_t status = {
|
||||
.cmd = "status",
|
||||
.usage = "[-d|--detail] [services...]",
|
||||
.s_desc = "report the status of the currently enabled services",
|
||||
.l_desc = "Gathers a list of all currently running services and the "
|
||||
"state that they are in (currently running, done, failed, "
|
||||
"wating to get scheduled). A list of services with wildcard "
|
||||
"globbing patterns can be specified. If ommitted, produces "
|
||||
"a general overview of all services. If the --detail "
|
||||
"is given, more details are shown about a service.",
|
||||
.run_cmd = cmd_status,
|
||||
};
|
||||
|
||||
REGISTER_COMMAND(status)
|
|
@ -1,82 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "servicecmd.h"
|
||||
|
||||
static int cmd_unschedule(int argc, char **argv)
|
||||
{
|
||||
int ret = EXIT_FAILURE;
|
||||
char *linkname, *ptr;
|
||||
struct stat sb;
|
||||
|
||||
if (check_arguments(argv[0], argc, 2, 2))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
for (ptr = argv[1]; isalnum(*ptr) || *ptr == '_'; ++ptr)
|
||||
;
|
||||
|
||||
if (*ptr != '\0') {
|
||||
fprintf(stderr, "Invalid service name '%s'\n", argv[1]);
|
||||
tell_read_help(argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (asprintf(&linkname, "%s/%s.gcron", GCRONDIR, argv[1]) < 0) {
|
||||
perror("asprintf");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (lstat(linkname, &sb)) {
|
||||
fprintf(stderr, "lstat %s: %s\n", linkname, strerror(errno));
|
||||
goto out;
|
||||
}
|
||||
|
||||
if ((sb.st_mode & S_IFMT) != S_IFLNK) {
|
||||
fprintf(stderr, "error: '%s' is not a symlink!", linkname);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (unlink(linkname)) {
|
||||
fprintf(stderr, "removing %s: %s\n",
|
||||
linkname, strerror(errno));
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = EXIT_SUCCESS;
|
||||
out:
|
||||
free(linkname);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static command_t unschedule = {
|
||||
.cmd = "unschedule",
|
||||
.usage = "<name>",
|
||||
.s_desc = "disable a gcrond service",
|
||||
.l_desc = "This disables a gcrond service by removing the coresponding "
|
||||
"symlink in " GCRONDIR ".",
|
||||
.run_cmd = cmd_unschedule,
|
||||
};
|
||||
|
||||
REGISTER_COMMAND(unschedule)
|
|
@ -39,7 +39,7 @@ This program is part of the Pygos init system.
|
|||
.SH COPYRIGHT
|
||||
Copyright \(co 2018 David Oberhollenzer
|
||||
.br
|
||||
License: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
|
||||
License: ISC <https://www.gnu.org/licenses/license-list.html#ISC>.
|
||||
.br
|
||||
This is free software: you are free to change and redistribute it.
|
||||
There is NO WARRANTY, to the extent permitted by law.
|
||||
|
|
|
@ -1,20 +1,4 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* SPDX-License-Identifier: ISC */
|
||||
#include <getopt.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -26,14 +10,11 @@
|
|||
#include <sys/reboot.h>
|
||||
#include <linux/reboot.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#define FL_FORCE 0x01
|
||||
#define FL_NOSYNC 0x02
|
||||
|
||||
static const struct option options[] = {
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ "version", no_argument, NULL, 'V' },
|
||||
{ "poweroff", no_argument, NULL, 'p' },
|
||||
{ "reboot", no_argument, NULL, 'r' },
|
||||
{ "force", no_argument, NULL, 'f' },
|
||||
|
@ -41,12 +22,12 @@ static const struct option options[] = {
|
|||
{ NULL, 0, NULL, 0 },
|
||||
};
|
||||
|
||||
static const char *shortopt = "hVprfn";
|
||||
static const char *shortopt = "hprfn";
|
||||
|
||||
static const char *defact_str = "power-off";
|
||||
static int defact = RB_POWER_OFF;
|
||||
|
||||
static NORETURN void usage(const char *progname, int status)
|
||||
static __attribute__((noreturn)) void usage(const char *progname, int status)
|
||||
{
|
||||
fprintf(status == EXIT_SUCCESS ? stdout : stderr,
|
||||
"%s [OPTIONS...]\n\n"
|
||||
|
@ -94,8 +75,6 @@ int main(int argc, char **argv)
|
|||
case 'r':
|
||||
defact = RB_AUTOBOOT;
|
||||
break;
|
||||
case 'V':
|
||||
print_version(ptr);
|
||||
case 'h':
|
||||
usage(ptr, EXIT_SUCCESS);
|
||||
default:
|
||||
|
|
47
cmd/syslog.1
47
cmd/syslog.1
|
@ -1,47 +0,0 @@
|
|||
.TH syslog 1 "August 2018" "Pygos Init"
|
||||
.SH NAME
|
||||
syslog \- send a log message to the syslog daemon
|
||||
.SH SYNOPSIS
|
||||
.B syslog
|
||||
[options] message..
|
||||
.SH DESCRIPTION
|
||||
The syslog command concatenates all non option arguments to a single message
|
||||
that it sends to the syslog daemon.
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.BR \-h , " \-\-help"
|
||||
Display a brief help text, a list of available facilities, log levels, all the
|
||||
default setting and exit.
|
||||
.TP
|
||||
.BR \-V , " \-\-version"
|
||||
Print version information and exit.
|
||||
.TP
|
||||
.BR \-f , " \-\-facility " \fIfacility\fP
|
||||
Logging facility name or numeric identifier. Use
|
||||
.B \-\-help
|
||||
to get a list of all available facility names.
|
||||
.TP
|
||||
.BR \-l , " \-\-level " \fIlevel\fP
|
||||
A log level number from 0 to 8 with 8 being most severe, or a name from
|
||||
.I debug
|
||||
to
|
||||
.I emergency.
|
||||
Use
|
||||
.B \-\-help
|
||||
to get a list of all available log level names.
|
||||
.TP
|
||||
.BR \-i , " \-\-ident " \fIname\fP
|
||||
Program name to specify to syslog. If not set, "(shell)" is used as sensible
|
||||
default to indicate that the message came from the command line.
|
||||
.TP
|
||||
.BR \-c , " \-\-console"
|
||||
Try to write directly to the console if opening the syslog socket fails.
|
||||
.SH AVAILABILITY
|
||||
This program is part of the Pygos init system.
|
||||
.SH COPYRIGHT
|
||||
Copyright \(co 2018 David Oberhollenzer
|
||||
.br
|
||||
License: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
|
||||
.br
|
||||
This is free software: you are free to change and redistribute it.
|
||||
There is NO WARRANTY, to the extent permitted by law.
|
223
cmd/syslog.c
223
cmd/syslog.c
|
@ -1,223 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <getopt.h>
|
||||
#include <syslog.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include "util.h"
|
||||
|
||||
static int facility = LOG_USER;
|
||||
static int level = LOG_INFO;
|
||||
static int flags = LOG_NDELAY | LOG_NOWAIT;
|
||||
static const char *ident = "(shell)";
|
||||
|
||||
static const enum_map_t facility_map[] = {
|
||||
{ "auth", LOG_AUTH },
|
||||
{ "cron", LOG_CRON },
|
||||
{ "daemon", LOG_DAEMON },
|
||||
{ "ftp", LOG_FTP },
|
||||
{ "local0", LOG_LOCAL0 },
|
||||
{ "local1", LOG_LOCAL1 },
|
||||
{ "local2", LOG_LOCAL2 },
|
||||
{ "local3", LOG_LOCAL3 },
|
||||
{ "local4", LOG_LOCAL4 },
|
||||
{ "local5", LOG_LOCAL5 },
|
||||
{ "local6", LOG_LOCAL6 },
|
||||
{ "local7", LOG_LOCAL7 },
|
||||
{ "lpr", LOG_LPR },
|
||||
{ "news", LOG_NEWS },
|
||||
{ "user", LOG_USER },
|
||||
{ "uucp", LOG_UUCP },
|
||||
{ NULL, 0 },
|
||||
};
|
||||
|
||||
static const enum_map_t level_map[] = {
|
||||
{ "emergency", LOG_EMERG },
|
||||
{ "alert", LOG_ALERT },
|
||||
{ "critical", LOG_CRIT },
|
||||
{ "error", LOG_ERR },
|
||||
{ "warning", LOG_WARNING },
|
||||
{ "notice", LOG_NOTICE },
|
||||
{ "info", LOG_INFO },
|
||||
{ "debug", LOG_DEBUG },
|
||||
{ NULL, 0 },
|
||||
};
|
||||
|
||||
static const struct option options[] = {
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ "version", no_argument, NULL, 'V' },
|
||||
{ "console", required_argument, NULL, 'c' },
|
||||
{ "facility", required_argument, NULL, 'f' },
|
||||
{ "level", required_argument, NULL, 'l' },
|
||||
{ "ident", required_argument, NULL, 'i' },
|
||||
{ NULL, 0, NULL, 0 },
|
||||
};
|
||||
|
||||
static const char *shortopt = "hVcf:l:i:";
|
||||
|
||||
static const char *helptext =
|
||||
"Usage: syslog [OPTION]... [STRING]...\n\n"
|
||||
"Concatenate the given STRINGs and send a log message to the syslog daemon.\n"
|
||||
"\n"
|
||||
"The following OPTIONSs can be used:\n"
|
||||
" -f, --facility <facility> Logging facilty name or numeric identifier.\n"
|
||||
" -l, --level <level> Log level name or numeric identifier.\n"
|
||||
" -i, --ident <name> Program name for log syslog message.\n"
|
||||
" Default is %s.\n\n"
|
||||
" -c, --console Write to the console if opening the syslog\n"
|
||||
" socket fails.\n\n"
|
||||
" -h, --help Print this help text and exit\n"
|
||||
" -V, --version Print version information and exit\n\n";
|
||||
|
||||
static void print_map(const enum_map_t *map, int defaultval,
|
||||
const char *option)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
printf("The following values can be used for %s:\n", option);
|
||||
|
||||
for (i = 0; map[i].name != NULL; ++i) {
|
||||
if (map[i].value == defaultval) {
|
||||
printf(" %s (=%d), set as default\n",
|
||||
map[i].name, map[i].value);
|
||||
} else {
|
||||
printf(" %s (=%d)\n", map[i].name, map[i].value);
|
||||
}
|
||||
}
|
||||
|
||||
fputc('\n', stdout);
|
||||
}
|
||||
|
||||
static NORETURN void usage(int status)
|
||||
{
|
||||
if (status != EXIT_SUCCESS) {
|
||||
fputs("Try `syslog --help' for more information\n", stderr);
|
||||
} else {
|
||||
printf(helptext, ident);
|
||||
print_map(level_map, level, "--level");
|
||||
print_map(facility_map, facility, "--facility");
|
||||
}
|
||||
|
||||
exit(status);
|
||||
}
|
||||
|
||||
static int readint(const char *str)
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
if (!isdigit(*str))
|
||||
return -1;
|
||||
|
||||
while (isdigit(*str))
|
||||
x = x * 10 + (*(str++)) - '0';
|
||||
|
||||
return (*str == '\0') ? x : -1;
|
||||
}
|
||||
|
||||
static void process_options(int argc, char **argv)
|
||||
{
|
||||
const enum_map_t *e;
|
||||
int c;
|
||||
|
||||
for (;;) {
|
||||
c = getopt_long(argc, argv, shortopt, options, NULL);
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
switch (c) {
|
||||
case 'f':
|
||||
facility = readint(optarg);
|
||||
if (facility >= 0)
|
||||
break;
|
||||
e = enum_by_name(facility_map, optarg);
|
||||
if (e == NULL) {
|
||||
fprintf(stderr, "Unknown facility name '%s'\n",
|
||||
optarg);
|
||||
usage(EXIT_FAILURE);
|
||||
}
|
||||
facility = e->value;
|
||||
break;
|
||||
case 'l':
|
||||
level = readint(optarg);
|
||||
if (level >= 0)
|
||||
break;
|
||||
e = enum_by_name(level_map, optarg);
|
||||
if (e == NULL) {
|
||||
fprintf(stderr, "Unknown log level '%s'\n",
|
||||
optarg);
|
||||
usage(EXIT_FAILURE);
|
||||
}
|
||||
level = e->value;
|
||||
break;
|
||||
case 'i':
|
||||
ident = optarg;
|
||||
break;
|
||||
case 'c':
|
||||
flags |= LOG_CONS;
|
||||
break;
|
||||
case 'h':
|
||||
usage(EXIT_SUCCESS);
|
||||
case 'V':
|
||||
print_version("syslog");
|
||||
default:
|
||||
usage(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
size_t len = 0;
|
||||
char *str;
|
||||
int i;
|
||||
|
||||
process_options(argc, argv);
|
||||
|
||||
if (optind >= argc) {
|
||||
fputs("Error: no log string provided.\n", stderr);
|
||||
usage(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (i = optind; i < argc; ++i)
|
||||
len += strlen(argv[i]);
|
||||
|
||||
len += argc - optind - 1;
|
||||
|
||||
str = calloc(1, len + 1);
|
||||
if (str == NULL) {
|
||||
fputs("syslog: out of memory\n", stderr);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
for (i = optind; i < argc; ++i) {
|
||||
if (i > optind)
|
||||
strcat(str, " ");
|
||||
strcat(str, argv[i]);
|
||||
}
|
||||
|
||||
openlog(ident, flags, facility);
|
||||
syslog(level, "%s", str);
|
||||
closelog();
|
||||
|
||||
free(str);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
82
cmd/waitfile.c
Normal file
82
cmd/waitfile.c
Normal file
|
@ -0,0 +1,82 @@
|
|||
/* SPDX-License-Identifier: ISC */
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <poll.h>
|
||||
|
||||
static int strtoui(const char *str)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
if (!isdigit(*str))
|
||||
return -1;
|
||||
|
||||
while (isdigit(*str)) {
|
||||
if (i > (INT_MAX / 10))
|
||||
return -1;
|
||||
|
||||
i = i * 10 + (*(str++)) - '0';
|
||||
}
|
||||
|
||||
if (*str != '\0')
|
||||
return -1;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
static void sigproc(int signo)
|
||||
{
|
||||
if (signo == SIGALRM) {
|
||||
fputs("waitfile timeout\n", stderr);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i, found, timeout, probetime;
|
||||
struct stat sb;
|
||||
|
||||
if (argc < 4)
|
||||
goto fail_usage;
|
||||
|
||||
timeout = strtoui(argv[1]);
|
||||
probetime = strtoui(argv[2]);
|
||||
if (timeout < 0 || probetime < 0)
|
||||
goto fail_timeout;
|
||||
|
||||
signal(SIGALRM, sigproc);
|
||||
alarm(timeout);
|
||||
|
||||
for (;;) {
|
||||
found = 1;
|
||||
|
||||
for (i = 3; i < argc; ++i) {
|
||||
if (stat(argv[i], &sb) != 0) {
|
||||
found = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
alarm(0);
|
||||
break;
|
||||
}
|
||||
|
||||
poll(NULL, 0, probetime);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
fail_timeout:
|
||||
fputs("Timeout values must be integers!\n", stderr);
|
||||
goto fail_usage;
|
||||
fail_usage:
|
||||
fputs("Usage: waitfile <timeout secs> <probe time ms> FILES...\n",
|
||||
stderr);
|
||||
return EXIT_FAILURE;
|
||||
}
|
54
configure.ac
54
configure.ac
|
@ -1,8 +1,8 @@
|
|||
AC_PREREQ([2.60])
|
||||
|
||||
m4_define([RELEASE], 0.7)
|
||||
m4_define([RELEASE], 0.10)
|
||||
|
||||
AC_INIT([init], [RELEASE], [david.oberhollenzer@tele2.at], init)
|
||||
AC_INIT([init], [RELEASE], [goliath@infraroot.at], init)
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
AM_INIT_AUTOMAKE([foreign subdir-objects dist-xz])
|
||||
AM_SILENT_RULES([yes])
|
||||
|
@ -36,38 +36,8 @@ UL_WARN_ADD([-pedantic])
|
|||
|
||||
AC_SUBST([WARN_CFLAGS])
|
||||
|
||||
|
||||
AC_ARG_WITH([usyslogd],
|
||||
[AS_HELP_STRING([--without-usyslogd], [Build without syslog daemon])],
|
||||
[case "${withval}" in
|
||||
yes) AM_CONDITIONAL([USYSLOGD], [true]) ;;
|
||||
no) AM_CONDITIONAL([USYSLOGD], [false]) ;;
|
||||
*) AC_MSG_ERROR([bad value ${withval} for --without-usyslogd]) ;;
|
||||
esac],
|
||||
[AM_CONDITIONAL([USYSLOGD], [true])])
|
||||
|
||||
AC_ARG_WITH([klogd],
|
||||
[AS_HELP_STRING([--without-klogd], [Build without kernel log daemon])],
|
||||
[case "${withval}" in
|
||||
yes) AM_CONDITIONAL([KLOGD], [true]) ;;
|
||||
no) AM_CONDITIONAL([KLOGD], [false]) ;;
|
||||
*) AC_MSG_ERROR([bad value ${withval} for --without-klogd]) ;;
|
||||
esac],
|
||||
[AM_CONDITIONAL([KLOGD], [true])])
|
||||
|
||||
AC_ARG_WITH([gcrond],
|
||||
[AS_HELP_STRING([--without-gcrond], [Build without gcron daemon])],
|
||||
[case "${withval}" in
|
||||
yes) AM_CONDITIONAL([GCROND], [true]) ;;
|
||||
no) AM_CONDITIONAL([GCROND], [false]) ;;
|
||||
*) AC_MSG_ERROR([bad value ${withval} for --without-gcron]) ;;
|
||||
esac],
|
||||
[AM_CONDITIONAL([GCROND], [true])])
|
||||
|
||||
|
||||
AC_CONFIG_HEADERS([lib/include/config.h])
|
||||
AC_DEFINE_DIR(SVCDIR, sysconfdir/init.d, [Startup service directory])
|
||||
AC_DEFINE_DIR(GCRONDIR, sysconfdir/gcron.d, [Cron service directory])
|
||||
AC_DEFINE_DIR(TEMPLATEDIR, datadir/init, [Service template directory])
|
||||
AC_DEFINE_DIR(SCRIPTDIR, libexecdir/init, [Helper script directory])
|
||||
AC_DEFINE_DIR(SOCKDIR, localstatedir/run, [Directory for initd socket])
|
||||
|
@ -79,26 +49,6 @@ AC_DEFINE_DIR(STATEFILESPATH, prefix/var/lib, [Path for persistent state files])
|
|||
|
||||
AC_DEFINE_DIR(PREFIXPATH, prefix, [Fully expaneded installation prefix])
|
||||
|
||||
AC_CONFIG_FILES([services/sigkill])
|
||||
AC_CONFIG_FILES([services/sigterm])
|
||||
AC_CONFIG_FILES([services/sysfs])
|
||||
AC_CONFIG_FILES([services/devfs])
|
||||
AC_CONFIG_FILES([services/procfs])
|
||||
AC_CONFIG_FILES([services/ifrename])
|
||||
AC_CONFIG_FILES([services/ifcfg])
|
||||
AC_CONFIG_FILES([services/ifdown])
|
||||
AC_CONFIG_FILES([services/modules])
|
||||
AC_CONFIG_FILES([services/hostapd])
|
||||
AC_CONFIG_FILES([services/swclock])
|
||||
AC_CONFIG_FILES([services/swclocksave])
|
||||
AC_CONFIG_FILES([services/swclocksave.gcron])
|
||||
AC_CONFIG_FILES([services/nft])
|
||||
AC_CONFIG_FILES([services/sshd])
|
||||
AC_CONFIG_FILES([services/sshd_keygen])
|
||||
AC_CONFIG_FILES([scripts/devfs.sh])
|
||||
AC_CONFIG_FILES([scripts/ifrename.sh])
|
||||
AC_CONFIG_FILES([scripts/ifcfg.sh])
|
||||
AC_CONFIG_FILES([scripts/modules_load.sh])
|
||||
AC_CONFIG_FILES([etc/initd.env])
|
||||
|
||||
AC_OUTPUT([Makefile])
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
if GCROND
|
||||
gcrond_SOURCES = crond/main.c crond/gcrond.h crond/runjob.c
|
||||
gcrond_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
gcrond_CFLAGS = $(AM_CFLAGS)
|
||||
gcrond_LDFLAGS = $(AM_LDFLAGS)
|
||||
gcrond_LDADD = libcron.a libinit.a libcfg.a
|
||||
|
||||
sbin_PROGRAMS += gcrond
|
||||
endif
|
|
@ -1,37 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef GCROND_H
|
||||
#define GCROND_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "crontab.h"
|
||||
#include "config.h"
|
||||
#include "util.h"
|
||||
|
||||
int runjob(crontab_t *tab);
|
||||
|
||||
#endif /* GCROND_H */
|
||||
|
135
crond/main.c
135
crond/main.c
|
@ -1,135 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "gcrond.h"
|
||||
|
||||
static crontab_t *jobs;
|
||||
static sig_atomic_t run = 1;
|
||||
static sig_atomic_t rescan = 1;
|
||||
|
||||
static void read_config(void)
|
||||
{
|
||||
if (cronscan(GCRONDIR, &jobs)) {
|
||||
fputs("Error reading configuration. Continuing anyway.\n",
|
||||
stderr);
|
||||
}
|
||||
}
|
||||
|
||||
static void cleanup_config(void)
|
||||
{
|
||||
crontab_t *t;
|
||||
|
||||
while (jobs != NULL) {
|
||||
t = jobs;
|
||||
jobs = jobs->next;
|
||||
delcron(t);
|
||||
}
|
||||
}
|
||||
|
||||
static int calc_timeout(void)
|
||||
{
|
||||
time_t now = time(NULL), future;
|
||||
struct tm tmstruct;
|
||||
crontab_t mask, *t;
|
||||
int minutes;
|
||||
|
||||
for (minutes = 0; minutes < 120; ++minutes) {
|
||||
future = now + minutes * 60;
|
||||
|
||||
localtime_r(&future, &tmstruct);
|
||||
cron_tm_to_mask(&mask, &tmstruct);
|
||||
|
||||
for (t = jobs; t != NULL; t = t->next) {
|
||||
if (cron_should_run(t, &mask))
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
out:
|
||||
return minutes ? minutes * 60 : 60;
|
||||
}
|
||||
|
||||
static void runjobs(void)
|
||||
{
|
||||
time_t now = time(NULL);
|
||||
struct tm tmstruct;
|
||||
crontab_t mask, *t;
|
||||
|
||||
localtime_r(&now, &tmstruct);
|
||||
cron_tm_to_mask(&mask, &tmstruct);
|
||||
|
||||
for (t = jobs; t != NULL; t = t->next) {
|
||||
if (cron_should_run(t, &mask))
|
||||
runjob(t);
|
||||
}
|
||||
}
|
||||
|
||||
static void sighandler(int signo)
|
||||
{
|
||||
pid_t pid;
|
||||
|
||||
switch (signo) {
|
||||
case SIGINT:
|
||||
case SIGTERM:
|
||||
run = 0;
|
||||
break;
|
||||
case SIGHUP:
|
||||
rescan = 1;
|
||||
break;
|
||||
case SIGCHLD:
|
||||
while ((pid = waitpid(-1, NULL, WNOHANG)) != -1)
|
||||
;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct timespec stime;
|
||||
struct sigaction act;
|
||||
int timeout;
|
||||
|
||||
memset(&act, 0, sizeof(act));
|
||||
act.sa_handler = sighandler;
|
||||
sigaction(SIGINT, &act, NULL);
|
||||
sigaction(SIGTERM, &act, NULL);
|
||||
sigaction(SIGHUP, &act, NULL);
|
||||
sigaction(SIGCHLD, &act, NULL);
|
||||
|
||||
while (run) {
|
||||
if (rescan == 1) {
|
||||
cleanup_config();
|
||||
read_config();
|
||||
timeout = 60;
|
||||
rescan = 0;
|
||||
} else {
|
||||
runjobs();
|
||||
timeout = calc_timeout();
|
||||
}
|
||||
|
||||
stime.tv_sec = timeout;
|
||||
stime.tv_nsec = 0;
|
||||
|
||||
while (nanosleep(&stime, &stime) != 0 && run && !rescan) {
|
||||
if (errno != EINTR) {
|
||||
perror("nanosleep");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "gcrond.h"
|
||||
|
||||
int runjob(crontab_t *tab)
|
||||
{
|
||||
struct sigaction act;
|
||||
pid_t pid;
|
||||
exec_t *e;
|
||||
int ret;
|
||||
|
||||
if (tab->exec == NULL)
|
||||
return 0;
|
||||
|
||||
pid = fork();
|
||||
if (pid == -1) {
|
||||
perror("fork");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pid != 0)
|
||||
return 0;
|
||||
|
||||
/* XXX: inside the child process */
|
||||
memset(&act, 0, sizeof(act));
|
||||
act.sa_handler = SIG_DFL;
|
||||
sigaction(SIGINT, &act, NULL);
|
||||
sigaction(SIGTERM, &act, NULL);
|
||||
sigaction(SIGHUP, &act, NULL);
|
||||
sigaction(SIGCHLD, &act, NULL);
|
||||
|
||||
if (setup_tty(tab->ctty, tab->tty_truncate))
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
if (tab->gid != 0) {
|
||||
if (setresgid(tab->gid, tab->gid, tab->gid)) {
|
||||
perror("setgid");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (tab->uid != 0) {
|
||||
if (setresuid(tab->uid, tab->uid, tab->uid)) {
|
||||
perror("setuid");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (tab->exec->next == NULL)
|
||||
argv_exec(tab->exec);
|
||||
|
||||
for (e = tab->exec; e != NULL; e = e->next) {
|
||||
pid = fork();
|
||||
if (pid == -1) {
|
||||
perror("fork");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (pid == 0)
|
||||
argv_exec(e);
|
||||
|
||||
while (waitpid(pid, &ret, 0) != pid)
|
||||
;
|
||||
|
||||
ret = WIFEXITED(ret) ? WEXITSTATUS(ret) : EXIT_FAILURE;
|
||||
if (ret != EXIT_SUCCESS)
|
||||
break;
|
||||
}
|
||||
|
||||
exit(ret);
|
||||
}
|
|
@ -13,15 +13,15 @@ Currently available service commands are:
|
|||
* disable - disable a service. If the service is parameterized, requires the
|
||||
same arguments used for enabling, to disable the specific instance of the
|
||||
service.
|
||||
* schedule - enable a gcrond service. Only available if this package is built
|
||||
with gcrond.
|
||||
* unschedule - disnable a gcrond service. Only available if this package is
|
||||
built with gcrond.
|
||||
* dumpscript - generate an equivalent shell script from the `exec` lines of
|
||||
a service after applying all parameter substitutions.
|
||||
* list - list all enabled service. A target can be specified to only list
|
||||
services for the specified target.
|
||||
* help - display a short help text and a list of available commands.
|
||||
* start - start one or more services listed on the command line.
|
||||
* stop - stop one or more services listed on the command line.
|
||||
* status - display status of all services or the ones specified
|
||||
on the command line.
|
||||
|
||||
|
||||
## shutdown and reboot
|
||||
|
@ -33,15 +33,3 @@ The option `-f` or `--force` can be used to by pass the init system entirely
|
|||
and force a hard reset or power off by directly signalling the kernel.
|
||||
|
||||
Running any one of those programs requires superuser privileges.
|
||||
|
||||
|
||||
## syslog
|
||||
|
||||
If the `usyslogd` service is built as part of this package, a program called
|
||||
`syslog` is built that can be used from the command line to send syslog
|
||||
messages.
|
||||
|
||||
This can for instance be used to produce log messages from shell scripts.
|
||||
|
||||
The log level, facility and identity string can be specified.
|
||||
See `syslog --help` for more information.
|
||||
|
|
|
@ -1,120 +0,0 @@
|
|||
# Default Service Configuration
|
||||
|
||||
## Pseudo Services
|
||||
|
||||
The default configuration contains a number of "pseudo services" in the boot
|
||||
target that don't actually do anything but are merely used as anchors in
|
||||
service dependencies, i.e. they indicate that some sort of milestone in the
|
||||
boot sequence has been reached. Everything that is part of that milestone
|
||||
specifies that it should be run *before* that pseudo service and everything
|
||||
that requires that this milestone has been reached, specifies that it wants
|
||||
to run afterwards.
|
||||
|
||||
The pseudo targets are (in the order that they are executed):
|
||||
|
||||
* vfs
|
||||
|
||||
All services that do mount point setup go before this, all service that
|
||||
depend on the fully mounted rootfs go after this.
|
||||
|
||||
* sysinit
|
||||
|
||||
The system has reached a sane state, i.e. the hostname is set, the system
|
||||
clock has a sane value, modules and kernel parameters are loaded, some
|
||||
very basic, fundamental services are running (e.g. syslog).
|
||||
Everything that is part of that setup process goes between `vfs` and
|
||||
`sysinit`, everything that requires a sane setup goes *after* `sysinit`.
|
||||
|
||||
* network
|
||||
|
||||
Network configuration is done. All services that do network configuration
|
||||
should position themselves between `sysinit` and `network`. Everything that
|
||||
requires a fully configured networking setup should go *after* `network`.
|
||||
|
||||
## Default Bootup Services
|
||||
|
||||
This section outlines the services for the boot target that are enabled by
|
||||
default.
|
||||
|
||||
|
||||
The following services are enabled by default and run *before* the `vfs` target
|
||||
for filesystem setup:
|
||||
|
||||
* procfs - mount `procfs` to `/proc` and try to mount additional pseudo
|
||||
filesystems in `/proc` such as `binfmt_misc`
|
||||
* tmpfs - mount a `tmpfs` to `/tmp`
|
||||
* sysfs - mount `sysfs` to `/sys` and try to mount additional pseudo
|
||||
filesystems in `/sys` (e.g. `securityfs`, `configfs`, ...)
|
||||
* devfs - mount `devtmpfs` to `/dev`, try to mount additional pseudo
|
||||
filesystems in `/dev` (e.g. `devpts`, `mqueue`, ...) and try to create
|
||||
some additional device nodes and symlinks.
|
||||
|
||||
|
||||
The following services are enabled by default and configured to run *after*
|
||||
the `vfs` target and *before* the `sysinit` target:
|
||||
|
||||
* hostname - reload hostname `/etc/hostname`
|
||||
* loopback - bring the loopback device up
|
||||
* usyslogd - if the `usyslogd` service is compiled with this package, this
|
||||
service is enabled by default and starts `usyslogd`.
|
||||
* klogd - if the `klogd` daemon is compiled with this package, this service
|
||||
is enabled by default and starts after `usyslogd`.
|
||||
* modules - iterate over the file `/etc/modules` and try to load each module
|
||||
using modprobe.
|
||||
* sysctl - restore kernel parameters using `sysctl --system`. See `sysctl(8)`
|
||||
for a list of possible locations that the parameters are read from.
|
||||
|
||||
|
||||
The following services are enabled by default and configured to run *after*
|
||||
the `sysinit` target and *before* the `network` target:
|
||||
|
||||
* ifcfg - static network configuration
|
||||
Does the static network configuration outlined in [network.md](network.md)
|
||||
|
||||
The following services are enabled by default and configured to run *after*
|
||||
the `network` target:
|
||||
|
||||
* gcrond - if the `gcrond` daemon is compiled with this package, this service
|
||||
is enabled by default.
|
||||
|
||||
|
||||
## Default Shutdown and Reboot Services
|
||||
|
||||
For the shutdown and reboot targets, the following services are executed:
|
||||
|
||||
* sigterm - send the SIGTERM signal to all processes and wait for 5 seconds
|
||||
* sigkill - send the SIGKILL signal to all remaining processes
|
||||
* ifdown - bring all network interfaces down
|
||||
* sync - run the sync command
|
||||
|
||||
|
||||
## Additional Services not Enabled by Default
|
||||
|
||||
* agetty - A parameterizeable, respawn type `agetty` service. The first
|
||||
parameter is the terminal device that the getty should run on.
|
||||
* consolefont - If enabled, run once before sysinit. Sets the console font
|
||||
to the first parameter.
|
||||
* dhcpcdmaster - If one or more network interfaces should be configured using
|
||||
dhcpcd, this service starts a central `dhcpcd` master instance.
|
||||
* dhcpcd - A parameterizeable single shot service that signals the `dhcpcd`
|
||||
master that it should configure a specific interface. The first parameter
|
||||
is the interface that should be configured by `dhcpcd`.
|
||||
* dnsmasq - A respawn type service for the `dnsmasq` DNS and DHCP server.
|
||||
* hostapd - If the system should operate a WIFI access point, this respawn
|
||||
type service can be enabled to manage an instace of the `hostapd` program.
|
||||
* unbound - A respawn type service that manages an instance of the `unbound`
|
||||
name resolver.
|
||||
* hwclock - If the system has a hardware clock, this service can restore the
|
||||
kernels clock from the hardware at bootup, between the `vfs` and `sysinit`
|
||||
targets.
|
||||
* nft - If enabled, restores net filter table rules during boot.
|
||||
* swclock - For systems that don't have a hardware clock, this service
|
||||
restores a somewhat usable time from a file during boot.
|
||||
* swclocksave - For systems that don't have a hardware clock, this service
|
||||
saves the current time to a file during shutdown or reboot.
|
||||
* sshd_keygen - A wait type service that generates host keys for the OpenSSH
|
||||
server and then disables itself.
|
||||
* sshd - Starts an OpenSSH server after the network pseudo service and after
|
||||
the sshd_keygen service.
|
||||
* nginx - Starts the Nginx server after the network pseudo serivce.
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
# Gcron
|
||||
|
||||
Gcron is a small daemon that executes batch commands once a certain
|
||||
condition is met.
|
||||
|
||||
In a typical installation, it reads configuration files from `/etc/gcron.d`.
|
||||
If used together with the init system in this package, the `service` command
|
||||
can be used to administer symlinks in that directory, pointing
|
||||
to `/usr/share/init/<name>.gcron`.
|
||||
|
||||
Each file in the configuration directory represents a single scheduled batch
|
||||
job. The syntax and most of the keywords are similar to `initd` service files
|
||||
(See [services.md](services.md)).
|
||||
|
||||
## Cron Style Patterns
|
||||
|
||||
The following keywords can be used to specify classic cron style patterns for
|
||||
when a job should be run:
|
||||
|
||||
* `hour`
|
||||
* `minute`
|
||||
* `dayofmonth`
|
||||
* `dayofweek`
|
||||
* `month`
|
||||
|
||||
For each of those keywords, a comma separated sequence of times can be
|
||||
specified. Time ranges can be specified using the syntax `<start>-<end>`,
|
||||
or using `*` for every possible value. A sequence (either range or star)
|
||||
can be suffixed with `/<step>` to specify an increment.
|
||||
For instance, `minute */5` means every five minutes and `minute 15-30/2`
|
||||
means every two minutes between quarter past and half past.
|
||||
|
||||
In addition to numeric values, the keywords `dayofweek` and `month` allow
|
||||
specifying 3 letter, uppercase week day and moth names such as `MON`, `TUE`,
|
||||
etc and `JAN`, `FEB`, ...
|
||||
|
||||
The job is only run when all specified conditions are met. Omitting a field
|
||||
is the same as specifying `*`.
|
||||
|
||||
## Named Intervals
|
||||
|
||||
Alternatively to the above, the keyword `interval` can be used. The following
|
||||
intervals can be specified:
|
||||
|
||||
* `yearly` or `annually` means on every January the first at midnight.
|
||||
* `monthly` means on every first of the month at midnight.
|
||||
* `weekly` means every Sunday at midnight.
|
||||
* `daily` means every day at midnight.
|
||||
* `hourly` means every first minute of the hour.
|
||||
|
||||
## Command Specification
|
||||
|
||||
To specify *what* should be done once the condition is met, the following
|
||||
keywords can be used:
|
||||
|
||||
* `exec` - the command to run. Multiple commands can be grouped
|
||||
using curly braces.
|
||||
* `user` - a user name or ID to set before running the commands.
|
||||
* `group` - a group name or ID to set before running the commands.
|
||||
* `tty` - similar to init service files, the controlling tty or output file
|
||||
for the batch commands. Like init service files, the `truncate` keyword
|
||||
can be used.
|
|
@ -1,83 +0,0 @@
|
|||
# Static Network Configuration
|
||||
|
||||
The default configuration provides multiple services that perform network
|
||||
initialization and static configuration using helper scripts that require
|
||||
programs from the `iproute2` package.
|
||||
|
||||
Configuration files are typically stored in `/etc/netcfg/` (depending on
|
||||
configure options).
|
||||
|
||||
Please note that the loopback device is treated specially and not included in
|
||||
any of the network configuration outlined below. The loopback device is brought
|
||||
up and configured by a dedicated service long before the network configuration
|
||||
is done.
|
||||
|
||||
|
||||
## Interface Renaming
|
||||
|
||||
If the `ifrename` service is enabled (it is disabled by default), network
|
||||
interfaces are renamed based on a rule set stored in the file `ifrename`.
|
||||
The file contains comma separated shell globing patterns for the current
|
||||
interface name, MAC address and a prefix for the new interface name.
|
||||
|
||||
For each network interface, rules are processed top to bottom. If the first two
|
||||
globing patterns apply, the interface is renamed. Interfaces with the same
|
||||
prefix are sorted by mac address and a running index is appended to the prefix.
|
||||
|
||||
If none of the rules apply, the interface name is left unchanged.
|
||||
|
||||
|
||||
The intent is, to provide a way to configure persistent, deterministic names for
|
||||
at least all network interfaces that are permanently installed on a board.
|
||||
|
||||
Extension cards or external network adapters should be given a different prefix
|
||||
to avoid changes in the order as they come and go.
|
||||
|
||||
|
||||
## Interface Configuration
|
||||
|
||||
After interface renaming, for each network interface, the configuration path is
|
||||
scanned for files with the same name as the interface.
|
||||
|
||||
Each successfully found configuration file is processed line by line, top to
|
||||
bottom. Each line may contain a keyword, followed by multiple arguments.
|
||||
|
||||
The following keywords can be used to add IPv4 or IPv6 network addresses to
|
||||
an interface:
|
||||
|
||||
* address
|
||||
* addr
|
||||
* ip
|
||||
* ip6
|
||||
* ipv6
|
||||
|
||||
Those commands are expected to be followed by an IPv4 or IPv6 address and
|
||||
network mask.
|
||||
|
||||
|
||||
Furthermore, the following commands can be used for configuring interface
|
||||
parameters:
|
||||
|
||||
* `arp {on|off}`
|
||||
* `multicast {on|off}`
|
||||
* `mtu <value>`
|
||||
* `offload [rx {on|off}] [tx {on|off}] [sg {on|off}] [tso {on|off}]`
|
||||
* `offload [gso {on|off}] [gro {on|off}] [lro {on|off}] [rxvlan {on|off}]`
|
||||
* `offload [txvlan {on|off}] [ntuple {on|off}] [rxhash {on|off}]`
|
||||
* `offload [ufo {on|off}]`
|
||||
|
||||
|
||||
## Route Configuration
|
||||
|
||||
After interface configuration is done, routes and rules are restored from a
|
||||
file named `routes` in the same configuration path.
|
||||
|
||||
The file may contain lines starting with `route` or `rule`. Everything that
|
||||
follows is passed on to `ip route add` or `ip rule add` respectively.
|
||||
|
||||
|
||||
## Net Filter Tables
|
||||
|
||||
|
||||
An additional service is provided that restores the nft rule set from
|
||||
`/etc/nftables.rules`.
|
103
docs/usyslogd.md
103
docs/usyslogd.md
|
@ -1,103 +0,0 @@
|
|||
# Syslogd Implementation
|
||||
|
||||
A tiny syslogd implementation `usyslogd` is provided as part of this package.
|
||||
|
||||
It opens a socket in `/dev/log`, processes syslog messages and forwards the
|
||||
parsed message to a modular backend interface.
|
||||
|
||||
Currently, there is only one implementation of the backend interface that dumps
|
||||
the log messages into files in the processes working directory (by default
|
||||
`/var/log`).
|
||||
|
||||
A simple log rotation scheme has been implemented.
|
||||
|
||||
|
||||
## Kernel Message Logging
|
||||
|
||||
An additional small `klogd` daemon is provided that redirects kernel messages
|
||||
to the syslog daemon.
|
||||
|
||||
It can be enabled or disabled independently of the `usyslogd` daemon and is
|
||||
designed to work with any other syslogd implementation.
|
||||
|
||||
|
||||
## Security Considerations
|
||||
|
||||
By default, the daemon switches its working directory to `/var/log`. The
|
||||
directory is created if it doesn't exist and the daemon always tries to
|
||||
change its mode to one that doesn't allow other users (except group members)
|
||||
to access the directory.
|
||||
|
||||
If told to so on the command line, the daemon chroots to the log directory.
|
||||
|
||||
By default, the daemon then tries to drop privileges by switching to user and
|
||||
group named `syslogd` if they exist (any other user or group can be specified
|
||||
on the command line; doing so causes syslogd to fail if they don't exist).
|
||||
|
||||
|
||||
On a system that hosts accounts for multiple users that may be more or less
|
||||
trusted, one may consider only giving system services access to the syslog
|
||||
socket and not allowing regular users. Otherwise, a user may flood the syslog
|
||||
daemon with messages, possibly leading to resource starvation, or (in the case
|
||||
of size limited log rotation outlined below) to the loss of otherwise critical
|
||||
log messages. Since this is not the primary target of the Pygos system, such
|
||||
a mechanism is not yet implemented.
|
||||
|
||||
In case of a system where only daemons are running, the above mentioned
|
||||
security measure is useless. If a remote attacker manages to get regular user
|
||||
privileges, you already have a different, much greater problem. Also, a remote
|
||||
attacker would have to compromise a local daemon that already has special
|
||||
access to the syslog socket, which is again your least concern in this
|
||||
scenario.
|
||||
|
||||
|
||||
## Logrotation
|
||||
|
||||
The backend can be configured to do log rotation in a continuous fashion (i.e.
|
||||
in a way that log messages aren't lost), or in a way where it drops old
|
||||
messages. Furthermore, the backend can be configured to automatically do a log
|
||||
rotation if a certain size threshold is hit.
|
||||
|
||||
If the `usyslogd` receives a `SIGHUP`, it tells the backend to do log rotation.
|
||||
|
||||
In the case of the size threshold, the backend is expected to do the rotation
|
||||
on its own if the predetermined limit is hit.
|
||||
|
||||
|
||||
## File Based Backend
|
||||
|
||||
The file based backend writes log messages to files in the current working
|
||||
directory (by default `/var/log`), named either after the ident string (if
|
||||
specified) or the facility name.
|
||||
|
||||
Log messages are prefixed with an ISO 8601 time stamp, optionally the facility
|
||||
name (unless part of the file name), the log level and the senders PID. Each
|
||||
of those fields is enclosed in brackets.
|
||||
|
||||
Log rotation in a continuous fashion means renaming the existing log file to
|
||||
one suffixed with the current time stamp. Overwriting old messages renaming
|
||||
the log file by appending a constant `.1` suffix.
|
||||
|
||||
|
||||
## Default Configuration
|
||||
|
||||
The default service configuration limits the log file size to 8 KiB and
|
||||
configures the daemon to overwrite old messages when rotating log files,
|
||||
effectively limiting the amount of log data to 16 KiB per source or facility.
|
||||
|
||||
The intended use case in the Pygos system is logging to a ramdisk without
|
||||
exhausting available memory.
|
||||
|
||||
|
||||
## Possible Future Directions
|
||||
|
||||
In the near term future, the daemon probably requires more fine grained control
|
||||
over logging such as setting a minimum log level or a way to configure limits
|
||||
per facility or service.
|
||||
|
||||
In the medium term future, extended resource control using c-groups might be
|
||||
a possibility.
|
||||
|
||||
Future directions may include adding other backends, such as forwarding the
|
||||
log messages to a central server, for instance using syslog over UDP/TCP or
|
||||
using the front end of some time series database.
|
|
@ -1,5 +1,5 @@
|
|||
init_SOURCES = initd/main.c initd/init.h initd/signal_linux.c initd/runsvc.c
|
||||
init_SOURCES += initd/status.c initd/supervisor.c
|
||||
init_SOURCES = initd/main.c initd/init.h initd/runsvc.c
|
||||
init_SOURCES += initd/status.c initd/supervisor.c initd/initsock.c
|
||||
init_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
init_CFLAGS = $(AM_CFLAGS)
|
||||
init_LDFLAGS = $(AM_LDFLAGS)
|
||||
|
|
56
initd/init.h
56
initd/init.h
|
@ -1,29 +1,15 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* SPDX-License-Identifier: ISC */
|
||||
#ifndef INIT_H
|
||||
#define INIT_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <endian.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <poll.h>
|
||||
|
@ -31,13 +17,15 @@
|
|||
#include <linux/reboot.h>
|
||||
#include <sys/signalfd.h>
|
||||
#include <sys/reboot.h>
|
||||
#include <stdbool.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "initsock.h"
|
||||
#include "service.h"
|
||||
#include "telinit.h"
|
||||
#include "util.h"
|
||||
#include "config.h"
|
||||
|
||||
#define RUNSVCBIN SCRIPTDIR "/runsvc"
|
||||
#define ENVFILE ETCPATH "/initd.env"
|
||||
#define PROCFDDIR "/proc/self/fd"
|
||||
|
||||
enum {
|
||||
STATUS_OK = 0,
|
||||
|
@ -82,28 +70,20 @@ void supervisor_init(void);
|
|||
|
||||
bool supervisor_process_queues(void);
|
||||
|
||||
/********** signal_<platform>.c **********/
|
||||
void supervisor_reload_config(void);
|
||||
|
||||
/*
|
||||
Setup signal handling. Returns -1 on error, a file descriptor on
|
||||
success.
|
||||
void supervisor_answer_status_request(int fd, const void *dest_addr,
|
||||
size_t addrlen, E_SERVICE_STATE filter);
|
||||
|
||||
The returned file descriptor can be polled and becomes readable
|
||||
when a signal arrives. Reading from it returns a signalfd_siginfo
|
||||
structure.
|
||||
void supervisor_start(int id);
|
||||
|
||||
The returned file descriptor has the close on exec flag set.
|
||||
void supervisor_stop(int id);
|
||||
|
||||
The kernel is also told to send us SIGINT signals if a user presses
|
||||
the local equivalent of CTRL+ALT+DEL.
|
||||
*/
|
||||
int sigsetup(void);
|
||||
/********** initsock.c **********/
|
||||
|
||||
/*
|
||||
Undo everything that sigsetup() changed about signal handling and
|
||||
restore the default.
|
||||
*/
|
||||
void sigreset(void);
|
||||
int init_socket_create(void);
|
||||
|
||||
int init_socket_send_status(int fd, const void *dest_addr, size_t addrlen,
|
||||
E_SERVICE_STATE state, service_t *svc);
|
||||
|
||||
#endif /* INIT_H */
|
||||
|
||||
|
|
88
initd/initsock.c
Normal file
88
initd/initsock.c
Normal file
|
@ -0,0 +1,88 @@
|
|||
/* SPDX-License-Identifier: ISC */
|
||||
#include "init.h"
|
||||
|
||||
static int send_retry(int fd, const void *dst, size_t addrlen,
|
||||
const void *buffer, size_t size)
|
||||
{
|
||||
ssize_t ret;
|
||||
retry:
|
||||
ret = sendto(fd, buffer, size, MSG_NOSIGNAL, dst, addrlen);
|
||||
if (ret < 0 && errno == EINTR)
|
||||
goto retry;
|
||||
|
||||
if (ret < 0 || (size_t)ret < size)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int send_string(int fd, const void *dst, size_t addrlen,
|
||||
const char *str)
|
||||
{
|
||||
size_t len = strlen(str);
|
||||
uint16_t raw;
|
||||
|
||||
if (len > 0xFFFF)
|
||||
return -1;
|
||||
|
||||
raw = htobe16(len);
|
||||
if (send_retry(fd, dst, addrlen, &raw, 2))
|
||||
return -1;
|
||||
|
||||
return len > 0 ? send_retry(fd, dst, addrlen, str, len) : 0;
|
||||
}
|
||||
|
||||
int init_socket_create(void)
|
||||
{
|
||||
struct sockaddr_un un;
|
||||
int fd;
|
||||
|
||||
fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
|
||||
if (fd < 0) {
|
||||
perror("socket");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&un, 0, sizeof(un));
|
||||
un.sun_family = AF_UNIX;
|
||||
|
||||
strcpy(un.sun_path, INIT_SOCK_PATH);
|
||||
unlink(INIT_SOCK_PATH);
|
||||
|
||||
if (bind(fd, (struct sockaddr *)&un, sizeof(un))) {
|
||||
perror("bind: " INIT_SOCK_PATH);
|
||||
close(fd);
|
||||
unlink(INIT_SOCK_PATH);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
int init_socket_send_status(int fd, const void *dest_addr, size_t addrlen,
|
||||
E_SERVICE_STATE state, service_t *svc)
|
||||
{
|
||||
init_response_status_t info;
|
||||
|
||||
memset(&info, 0, sizeof(info));
|
||||
|
||||
if (svc == NULL || state == ESS_NONE) {
|
||||
info.state = ESS_NONE;
|
||||
info.id = -1;
|
||||
} else {
|
||||
info.state = state;
|
||||
info.exit_status = svc->status & 0xFF;
|
||||
info.id = htobe32(svc->id);
|
||||
}
|
||||
|
||||
if (send_retry(fd, dest_addr, addrlen, &info, sizeof(info)))
|
||||
return -1;
|
||||
|
||||
if (svc != NULL && state != ESS_NONE) {
|
||||
if (send_string(fd, dest_addr, addrlen, svc->fname))
|
||||
return -1;
|
||||
if (send_string(fd, dest_addr, addrlen, svc->name))
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
148
initd/main.c
148
initd/main.c
|
@ -1,24 +1,8 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* SPDX-License-Identifier: ISC */
|
||||
#include "init.h"
|
||||
|
||||
static int ti_sock = -1;
|
||||
static int sigfd = -1;
|
||||
static int sockfd = -1;
|
||||
|
||||
static void handle_signal(void)
|
||||
{
|
||||
|
@ -46,62 +30,60 @@ static void handle_signal(void)
|
|||
case SIGINT:
|
||||
supervisor_set_target(TGT_REBOOT);
|
||||
break;
|
||||
case SIGHUP:
|
||||
supervisor_reload_config();
|
||||
break;
|
||||
case SIGUSR1:
|
||||
if (sockfd >= 0) {
|
||||
close(sockfd);
|
||||
unlink(INIT_SOCK_PATH);
|
||||
sockfd = -1;
|
||||
}
|
||||
sockfd = init_socket_create();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int read_msg(int fd, ti_msg_t *msg)
|
||||
static void handle_request(void)
|
||||
{
|
||||
struct sockaddr_un addr;
|
||||
init_request_t rq;
|
||||
socklen_t addrlen;
|
||||
ssize_t ret;
|
||||
retry:
|
||||
ret = read(fd, msg, sizeof(*msg));
|
||||
memset(&rq, 0, sizeof(rq));
|
||||
addrlen = sizeof(addr);
|
||||
ret = recvfrom(sockfd, &rq, sizeof(rq), MSG_DONTWAIT | MSG_TRUNC,
|
||||
(struct sockaddr *)&addr, &addrlen);
|
||||
|
||||
if (ret < 0) {
|
||||
if (errno == EINTR)
|
||||
goto retry;
|
||||
perror("read on telinit socket");
|
||||
return -1;
|
||||
}
|
||||
if (ret < 0 && errno == EINTR)
|
||||
goto retry;
|
||||
|
||||
if ((size_t)ret < sizeof(*msg)) {
|
||||
fputs("short read on telinit socket", stderr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void handle_tellinit(void)
|
||||
{
|
||||
ti_msg_t msg;
|
||||
int fd;
|
||||
|
||||
fd = accept(ti_sock, NULL, NULL);
|
||||
if (fd == -1)
|
||||
if ((size_t)ret < sizeof(rq))
|
||||
return;
|
||||
|
||||
if (read_msg(fd, &msg)) {
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg.type) {
|
||||
case TI_SHUTDOWN:
|
||||
supervisor_set_target(TGT_SHUTDOWN);
|
||||
switch (rq.rq) {
|
||||
case EIR_STATUS:
|
||||
supervisor_answer_status_request(sockfd, &addr, addrlen,
|
||||
rq.arg.status.filter);
|
||||
break;
|
||||
case TI_REBOOT:
|
||||
supervisor_set_target(TGT_REBOOT);
|
||||
case EIR_START:
|
||||
rq.arg.startstop.id = be32toh(rq.arg.startstop.id);
|
||||
supervisor_start(rq.arg.startstop.id);
|
||||
break;
|
||||
case EIR_STOP:
|
||||
rq.arg.startstop.id = be32toh(rq.arg.startstop.id);
|
||||
supervisor_stop(rq.arg.startstop.id);
|
||||
break;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
}
|
||||
|
||||
void target_completed(int target)
|
||||
{
|
||||
switch (target) {
|
||||
case TGT_BOOT:
|
||||
if (ti_sock == -1)
|
||||
ti_sock = mksock(INITSOCK, SOCK_FLAG_ROOT_ONLY);
|
||||
if (sockfd < 0)
|
||||
sockfd = init_socket_create();
|
||||
break;
|
||||
case TGT_SHUTDOWN:
|
||||
for (;;)
|
||||
|
@ -114,9 +96,32 @@ void target_completed(int target)
|
|||
}
|
||||
}
|
||||
|
||||
static int sigsetup(void)
|
||||
{
|
||||
sigset_t mask;
|
||||
int sfd;
|
||||
|
||||
sigfillset(&mask);
|
||||
if (sigprocmask(SIG_SETMASK, &mask, NULL) == -1) {
|
||||
perror("sigprocmask");
|
||||
return -1;
|
||||
}
|
||||
|
||||
sfd = signalfd(-1, &mask, SFD_CLOEXEC);
|
||||
if (sfd == -1) {
|
||||
perror("signalfd");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (reboot(LINUX_REBOOT_CMD_CAD_OFF))
|
||||
perror("cannot disable CTRL+ALT+DEL");
|
||||
|
||||
return sfd;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int ret, count;
|
||||
int i, ret, count;
|
||||
struct pollfd pfd[2];
|
||||
|
||||
if (getpid() != 1) {
|
||||
|
@ -135,24 +140,29 @@ int main(void)
|
|||
;
|
||||
|
||||
memset(pfd, 0, sizeof(pfd));
|
||||
pfd[0].fd = sigfd;
|
||||
pfd[0].events = POLLIN;
|
||||
count = 1;
|
||||
count = 0;
|
||||
|
||||
if (ti_sock != -1) {
|
||||
pfd[1].fd = ti_sock;
|
||||
pfd[1].events = POLLIN;
|
||||
count = 2;
|
||||
pfd[count].fd = sigfd;
|
||||
pfd[count].events = POLLIN;
|
||||
++count;
|
||||
|
||||
if (sockfd >= 0) {
|
||||
pfd[count].fd = sockfd;
|
||||
pfd[count].events = POLLIN;
|
||||
++count;
|
||||
}
|
||||
|
||||
ret = poll(pfd, count, -1);
|
||||
if (ret <= 0)
|
||||
continue;
|
||||
|
||||
if (ret > 0) {
|
||||
if (pfd[0].revents & POLLIN)
|
||||
handle_signal();
|
||||
|
||||
if (ti_sock != -1 && pfd[1].revents & POLLIN)
|
||||
handle_tellinit();
|
||||
for (i = 0; i < count; ++i) {
|
||||
if (pfd[i].revents & POLLIN) {
|
||||
if (pfd[i].fd == sigfd)
|
||||
handle_signal();
|
||||
if (pfd[i].fd == sockfd)
|
||||
handle_request();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
185
initd/runsvc.c
185
initd/runsvc.c
|
@ -1,50 +1,177 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* SPDX-License-Identifier: ISC */
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "init.h"
|
||||
|
||||
static int setup_env(void)
|
||||
{
|
||||
int status = -1;
|
||||
ssize_t ret;
|
||||
FILE *fp;
|
||||
|
||||
clearenv();
|
||||
|
||||
fp = fopen(ENVFILE, "r");
|
||||
if (fp == NULL) {
|
||||
perror(ENVFILE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
do {
|
||||
char *line = NULL;
|
||||
size_t n = 0;
|
||||
|
||||
errno = 0;
|
||||
ret = getline(&line, &n, fp);
|
||||
|
||||
if (ret < 0) {
|
||||
if (errno == 0) {
|
||||
status = 0;
|
||||
} else {
|
||||
perror(ENVFILE);
|
||||
}
|
||||
} else if (ret > 0 && putenv(line) != 0) {
|
||||
perror("putenv");
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
free(line);
|
||||
} while (ret >= 0);
|
||||
|
||||
fclose(fp);
|
||||
return status;
|
||||
}
|
||||
|
||||
static int close_all_files(void)
|
||||
{
|
||||
struct dirent *ent;
|
||||
DIR *dir;
|
||||
int fd;
|
||||
|
||||
dir = opendir(PROCFDDIR);
|
||||
if (dir == NULL) {
|
||||
perror(PROCFDDIR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
while ((ent = readdir(dir)) != NULL) {
|
||||
if (!isdigit(ent->d_name[0]))
|
||||
continue;
|
||||
|
||||
fd = atoi(ent->d_name);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int setup_tty(const char *tty, bool truncate)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (tty == NULL)
|
||||
return 0;
|
||||
|
||||
fd = open(tty, O_RDWR);
|
||||
if (fd < 0) {
|
||||
perror(tty);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (truncate)
|
||||
ftruncate(fd, 0);
|
||||
|
||||
setsid();
|
||||
|
||||
dup2(fd, STDIN_FILENO);
|
||||
dup2(fd, STDOUT_FILENO);
|
||||
dup2(fd, STDERR_FILENO);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static __attribute__((noreturn)) void argv_exec(exec_t *e)
|
||||
{
|
||||
char **argv = alloca(sizeof(char *) * (e->argc + 1)), *ptr;
|
||||
int i;
|
||||
|
||||
for (ptr = e->args, i = 0; i < e->argc; ++i, ptr += strlen(ptr) + 1)
|
||||
argv[i] = ptr;
|
||||
|
||||
argv[i] = NULL;
|
||||
execvp(argv[0], argv);
|
||||
perror(argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static int run_sequentially(exec_t *list)
|
||||
{
|
||||
pid_t ret, pid;
|
||||
int status;
|
||||
|
||||
for (; list != NULL; list = list->next) {
|
||||
if (list->next == NULL)
|
||||
argv_exec(list);
|
||||
|
||||
pid = fork();
|
||||
|
||||
if (pid == 0)
|
||||
argv_exec(list);
|
||||
|
||||
if (pid == -1) {
|
||||
perror("fork");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
do {
|
||||
ret = waitpid(pid, &status, 0);
|
||||
} while (ret != pid);
|
||||
|
||||
if (!WIFEXITED(status))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if (WEXITSTATUS(status) != EXIT_SUCCESS)
|
||||
return WEXITSTATUS(status);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
pid_t runsvc(service_t *svc)
|
||||
{
|
||||
char *argv[4], *envp[1];
|
||||
sigset_t mask;
|
||||
pid_t pid;
|
||||
|
||||
argv[0] = (char *)RUNSVCBIN;
|
||||
argv[1] = (char *)SVCDIR;
|
||||
argv[2] = svc->fname;
|
||||
argv[3] = NULL;
|
||||
|
||||
envp[0] = NULL;
|
||||
|
||||
pid = fork();
|
||||
|
||||
if (pid == -1)
|
||||
perror("fork");
|
||||
|
||||
if (pid == 0) {
|
||||
sigreset();
|
||||
execve(argv[0], argv, envp);
|
||||
perror(argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
sigemptyset(&mask);
|
||||
sigprocmask(SIG_SETMASK, &mask, NULL);
|
||||
|
||||
if (setup_env())
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
if (close_all_files())
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
if (setup_tty(svc->ctty,
|
||||
(svc->flags & SVC_FLAG_TRUNCATE_OUT) != 0)) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
exit(run_sequentially(svc->exec));
|
||||
}
|
||||
|
||||
return pid;
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
||||
#include "init.h"
|
||||
|
||||
int sigsetup(void)
|
||||
{
|
||||
sigset_t mask;
|
||||
int sfd;
|
||||
|
||||
sigfillset(&mask);
|
||||
if (sigprocmask(SIG_SETMASK, &mask, NULL) == -1) {
|
||||
perror("sigprocmask");
|
||||
return -1;
|
||||
}
|
||||
|
||||
sigemptyset(&mask);
|
||||
sigaddset(&mask, SIGCHLD);
|
||||
sigaddset(&mask, SIGINT);
|
||||
sigaddset(&mask, SIGTERM);
|
||||
|
||||
sfd = signalfd(-1, &mask, SFD_CLOEXEC);
|
||||
if (sfd == -1) {
|
||||
perror("signalfd");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (reboot(LINUX_REBOOT_CMD_CAD_OFF))
|
||||
perror("cannot disable CTRL+ALT+DEL");
|
||||
|
||||
return sfd;
|
||||
}
|
||||
|
||||
void sigreset(void)
|
||||
{
|
||||
sigset_t mask;
|
||||
|
||||
sigemptyset(&mask);
|
||||
sigprocmask(SIG_SETMASK, &mask, NULL);
|
||||
}
|
|
@ -1,20 +1,4 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* SPDX-License-Identifier: ISC */
|
||||
#include <stdio.h>
|
||||
|
||||
#include "init.h"
|
||||
|
|
|
@ -1,37 +1,68 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* SPDX-License-Identifier: ISC */
|
||||
#include "init.h"
|
||||
|
||||
static service_list_t cfg;
|
||||
|
||||
static int service_id = 1;
|
||||
static int target = -1;
|
||||
static service_t *running = NULL;
|
||||
static service_t *terminated = NULL;
|
||||
static service_t *queue = NULL;
|
||||
static service_t *completed = NULL;
|
||||
static service_t *failed = NULL;
|
||||
static int singleshot = 0;
|
||||
static bool waiting = false;
|
||||
|
||||
static bool find_service(service_t *list, service_t *svc)
|
||||
{
|
||||
while (list != NULL) {
|
||||
if (strcmp(list->fname, svc->fname) == 0)
|
||||
return true;
|
||||
|
||||
list = list->next;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void remove_not_in_list(service_t **current, service_t *list, int tgt)
|
||||
{
|
||||
service_t *it = *current, *prev = NULL;
|
||||
|
||||
while (it != NULL) {
|
||||
if (it->target == tgt && !find_service(list, it)) {
|
||||
if (prev == NULL) {
|
||||
delsvc(it);
|
||||
*current = (*current)->next;
|
||||
it = *current;
|
||||
} else {
|
||||
prev->next = it->next;
|
||||
delsvc(it);
|
||||
it = prev->next;
|
||||
}
|
||||
} else {
|
||||
prev = it;
|
||||
it = it->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool have_service(service_t *svc)
|
||||
{
|
||||
return find_service(running, svc) || find_service(terminated, svc) ||
|
||||
find_service(queue, svc) || find_service(completed, svc) ||
|
||||
find_service(failed, svc);
|
||||
}
|
||||
|
||||
static int start_service(service_t *svc)
|
||||
{
|
||||
if (svc->id < 1)
|
||||
svc->id = service_id++;
|
||||
|
||||
svc->pid = runsvc(svc);
|
||||
if (svc->pid == -1) {
|
||||
print_status(svc->desc, STATUS_FAIL, false);
|
||||
delsvc(svc);
|
||||
svc->next = completed;
|
||||
completed = svc;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -47,12 +78,15 @@ static void handle_terminated_service(service_t *svc)
|
|||
if (target == TGT_REBOOT || target == TGT_SHUTDOWN)
|
||||
break;
|
||||
|
||||
if (svc->rspwn_limit > 0) {
|
||||
svc->rspwn_limit -= 1;
|
||||
if (svc->flags & SVC_FLAG_ADMIN_STOPPED)
|
||||
break;
|
||||
|
||||
if (svc->rspwn_limit == 0) {
|
||||
if (svc->rspwn_limit > 0) {
|
||||
svc->rspwn_count += 1;
|
||||
|
||||
if (svc->rspwn_count >= svc->rspwn_limit) {
|
||||
print_status(svc->desc, STATUS_FAIL, false);
|
||||
break;
|
||||
goto out_failure;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,6 +99,8 @@ static void handle_terminated_service(service_t *svc)
|
|||
STATUS_OK : STATUS_FAIL, true);
|
||||
if (singleshot == 0 && queue == NULL)
|
||||
target_completed(target);
|
||||
if (svc->status != EXIT_SUCCESS)
|
||||
goto out_failure;
|
||||
break;
|
||||
case SVC_ONCE:
|
||||
singleshot -= 1;
|
||||
|
@ -73,9 +109,16 @@ static void handle_terminated_service(service_t *svc)
|
|||
STATUS_OK : STATUS_FAIL, false);
|
||||
if (singleshot == 0 && queue == NULL && !waiting)
|
||||
target_completed(target);
|
||||
if (svc->status != EXIT_SUCCESS)
|
||||
goto out_failure;
|
||||
break;
|
||||
}
|
||||
delsvc(svc);
|
||||
svc->next = completed;
|
||||
completed = svc;
|
||||
return;
|
||||
out_failure:
|
||||
svc->next = failed;
|
||||
failed = svc;
|
||||
}
|
||||
|
||||
void supervisor_handle_exited(pid_t pid, int status)
|
||||
|
@ -132,7 +175,7 @@ void supervisor_init(void)
|
|||
{
|
||||
int status = STATUS_OK;
|
||||
|
||||
if (svcscan(SVCDIR, &cfg, RDSVC_NO_EXEC | RDSVC_NO_CTTY))
|
||||
if (svcscan(SVCDIR, &cfg))
|
||||
status = STATUS_FAIL;
|
||||
|
||||
target = TGT_BOOT;
|
||||
|
@ -142,6 +185,45 @@ void supervisor_init(void)
|
|||
print_status("reading configuration from " SVCDIR, status, false);
|
||||
}
|
||||
|
||||
void supervisor_reload_config(void)
|
||||
{
|
||||
service_list_t newcfg;
|
||||
service_t *svc;
|
||||
int i;
|
||||
|
||||
if (svcscan(SVCDIR, &newcfg))
|
||||
return;
|
||||
|
||||
for (i = 0; i < TGT_MAX; ++i) {
|
||||
if (cfg.targets[i] == NULL) {
|
||||
remove_not_in_list(&queue, newcfg.targets[i], i);
|
||||
remove_not_in_list(&terminated, newcfg.targets[i], i);
|
||||
remove_not_in_list(&completed, newcfg.targets[i], i);
|
||||
remove_not_in_list(&failed, newcfg.targets[i], i);
|
||||
|
||||
while (newcfg.targets[i] != NULL) {
|
||||
svc = newcfg.targets[i];
|
||||
newcfg.targets[i] = svc->next;
|
||||
|
||||
if (have_service(svc)) {
|
||||
delsvc(svc);
|
||||
} else {
|
||||
svc->id = service_id++;
|
||||
svc->status = EXIT_SUCCESS;
|
||||
svc->next = completed;
|
||||
completed = svc;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
svc = cfg.targets[i];
|
||||
cfg.targets[i] = newcfg.targets[i];
|
||||
newcfg.targets[i] = svc;
|
||||
}
|
||||
}
|
||||
|
||||
del_svc_list(&newcfg);
|
||||
}
|
||||
|
||||
bool supervisor_process_queues(void)
|
||||
{
|
||||
service_t *svc;
|
||||
|
@ -160,6 +242,14 @@ bool supervisor_process_queues(void)
|
|||
svc = queue;
|
||||
queue = queue->next;
|
||||
|
||||
if (!(svc->flags & SVC_FLAG_HAS_EXEC)) {
|
||||
print_status(svc->desc, STATUS_OK, false);
|
||||
svc->status = EXIT_SUCCESS;
|
||||
svc->next = completed;
|
||||
completed = svc;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (start_service(svc) != 0)
|
||||
return true;
|
||||
|
||||
|
@ -175,8 +265,97 @@ bool supervisor_process_queues(void)
|
|||
singleshot += 1;
|
||||
break;
|
||||
}
|
||||
|
||||
out:
|
||||
if (singleshot == 0 && queue == NULL && !waiting)
|
||||
target_completed(target);
|
||||
return true;
|
||||
}
|
||||
|
||||
static int send_svc_list(int fd, const void *dst, size_t addrlen,
|
||||
E_SERVICE_STATE filter, E_SERVICE_STATE state,
|
||||
service_t *list)
|
||||
{
|
||||
if (filter != ESS_NONE && filter != state)
|
||||
return 0;
|
||||
|
||||
while (list != NULL) {
|
||||
if (init_socket_send_status(fd, dst, addrlen, state, list))
|
||||
return -1;
|
||||
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void supervisor_answer_status_request(int fd, const void *dst, size_t addrlen,
|
||||
E_SERVICE_STATE filter)
|
||||
{
|
||||
if (send_svc_list(fd, dst, addrlen, filter, ESS_RUNNING, running))
|
||||
return;
|
||||
if (send_svc_list(fd, dst, addrlen, filter, ESS_DONE, completed))
|
||||
return;
|
||||
if (send_svc_list(fd, dst, addrlen, filter, ESS_FAILED, failed))
|
||||
return;
|
||||
if (send_svc_list(fd, dst, addrlen, filter, ESS_ENQUEUED, queue))
|
||||
return;
|
||||
if (send_svc_list(fd, dst, addrlen, filter, ESS_ENQUEUED, terminated))
|
||||
return;
|
||||
init_socket_send_status(fd, dst, addrlen, ESS_NONE, NULL);
|
||||
}
|
||||
|
||||
static service_t *remove_by_id(service_t **list, int id)
|
||||
{
|
||||
service_t *svc = *list, *prev = NULL;
|
||||
|
||||
while (svc != NULL && svc->id != id) {
|
||||
prev = svc;
|
||||
svc = svc->next;
|
||||
}
|
||||
|
||||
if (svc != NULL) {
|
||||
if (prev == NULL) {
|
||||
*list = svc->next;
|
||||
} else {
|
||||
prev->next = svc->next;
|
||||
}
|
||||
}
|
||||
|
||||
return svc;
|
||||
}
|
||||
|
||||
void supervisor_start(int id)
|
||||
{
|
||||
service_t *svc;
|
||||
|
||||
svc = remove_by_id(&completed, id);
|
||||
if (svc != NULL)
|
||||
goto found;
|
||||
|
||||
svc = remove_by_id(&failed, id);
|
||||
if (svc != NULL)
|
||||
goto found;
|
||||
|
||||
return;
|
||||
found:
|
||||
svc->rspwn_count = 0;
|
||||
svc->flags &= ~SVC_FLAG_ADMIN_STOPPED;
|
||||
svc->next = queue;
|
||||
queue = svc;
|
||||
}
|
||||
|
||||
void supervisor_stop(int id)
|
||||
{
|
||||
service_t *svc;
|
||||
|
||||
for (svc = running; svc != NULL; svc = svc->next) {
|
||||
if (svc->id == id)
|
||||
break;
|
||||
}
|
||||
|
||||
if (svc != NULL) {
|
||||
/* TODO: something more sophisticated? */
|
||||
svc->flags |= SVC_FLAG_ADMIN_STOPPED;
|
||||
kill(svc->pid, SIGTERM);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,15 @@
|
|||
HEADRS = lib/include/util.h lib/include/service.h lib/include/telinit.h
|
||||
|
||||
libinit_a_SOURCES = lib/util/delsvc.c lib/util/svcmap.c lib/util/enum_by_name.c
|
||||
libinit_a_SOURCES += lib/util/rdsvc.c lib/util/svcscan.c lib/util/mksock.c
|
||||
libinit_a_SOURCES += lib/util/del_svc_list.c lib/util/svc_tsort.c
|
||||
libinit_a_SOURCES += lib/util/opensock.c lib/util/enum_to_name.c
|
||||
libinit_a_SOURCES += lib/util/print_version.c lib/util/argv_exec.c $(HEADRS)
|
||||
libinit_a_SOURCES = lib/init/delsvc.c lib/init/svcmap.c lib/init/rdsvc.c
|
||||
libinit_a_SOURCES += lib/init/svcscan.c lib/init/del_svc_list.c
|
||||
libinit_a_SOURCES += lib/init/svc_tsort.c lib/include/service.h
|
||||
libinit_a_SOURCES += lib/init/init_socket_open.c lib/init/free_init_status.c
|
||||
libinit_a_SOURCES += lib/include/initsock.h lib/init/init_socket_send_request.c
|
||||
libinit_a_SOURCES += lib/init/init_socket_recv_status.c
|
||||
libinit_a_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
libinit_a_CFLAGS = $(AM_CFLAGS)
|
||||
|
||||
libcfg_a_SOURCES = lib/libcfg/rdline.c lib/libcfg/unescape.c
|
||||
libcfg_a_SOURCES += lib/libcfg/splitkv.c lib/libcfg/rdcfg.c
|
||||
libcfg_a_SOURCES = lib/libcfg/rdline.c lib/libcfg/unescape.c lib/libcfg/rdcfg.c
|
||||
libcfg_a_SOURCES += lib/libcfg/pack_argv.c lib/include/libcfg.h
|
||||
libcfg_a_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
libcfg_a_CFLAGS = $(AM_CFLAGS)
|
||||
|
||||
libcron_a_SOURCES = lib/cron/rdcron.c lib/cron/delcron.c lib/cron/crontab.c
|
||||
libcron_a_SOURCES += lib/cron/cronscan.c lib/include/crontab.h
|
||||
libcron_a_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
libcron_a_CFLAGS = $(AM_CFLAGS)
|
||||
|
||||
EXTRA_DIST += $(HEADRS) lib/include/libcfg.h lib/include/crontab.h
|
||||
|
||||
noinst_LIBRARIES += libinit.a libcfg.a libcron.a
|
||||
noinst_LIBRARIES += libinit.a libcfg.a
|
||||
|
|
|
@ -1,77 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stddef.h>
|
||||
#include <dirent.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "crontab.h"
|
||||
|
||||
int cronscan(const char *directory, crontab_t **list)
|
||||
{
|
||||
struct dirent *ent;
|
||||
int dfd, ret = 0;
|
||||
crontab_t *cron;
|
||||
DIR *dir;
|
||||
|
||||
dir = opendir(directory);
|
||||
if (dir == NULL) {
|
||||
perror(directory);
|
||||
return -1;
|
||||
}
|
||||
|
||||
dfd = dirfd(dir);
|
||||
if (dfd < 0) {
|
||||
perror(directory);
|
||||
closedir(dir);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
errno = 0;
|
||||
ent = readdir(dir);
|
||||
|
||||
if (ent == NULL) {
|
||||
if (errno != 0) {
|
||||
perror(directory);
|
||||
ret = -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
|
||||
continue;
|
||||
|
||||
cron = rdcron(dfd, ent->d_name);
|
||||
if (cron == NULL) {
|
||||
ret = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
cron->next = *list;
|
||||
*list = cron;
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
return ret;
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <string.h>
|
||||
|
||||
#include "crontab.h"
|
||||
|
||||
void cron_tm_to_mask(crontab_t *out, struct tm *t)
|
||||
{
|
||||
memset(out, 0, sizeof(*out));
|
||||
out->minute = 1UL << ((unsigned long)t->tm_min);
|
||||
out->hour = 1 << t->tm_hour;
|
||||
out->dayofmonth = 1 << (t->tm_mday - 1);
|
||||
out->month = 1 << t->tm_mon;
|
||||
out->dayofweek = 1 << t->tm_wday;
|
||||
}
|
||||
|
||||
bool cron_should_run(const crontab_t *t, const crontab_t *mask)
|
||||
{
|
||||
if ((t->minute & mask->minute) == 0)
|
||||
return false;
|
||||
|
||||
if ((t->hour & mask->hour) == 0)
|
||||
return false;
|
||||
|
||||
if ((t->dayofmonth & mask->dayofmonth) == 0)
|
||||
return false;
|
||||
|
||||
if ((t->month & mask->month) == 0)
|
||||
return false;
|
||||
|
||||
if ((t->dayofweek & mask->dayofweek) == 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "crontab.h"
|
||||
|
||||
void delcron(crontab_t *cron)
|
||||
{
|
||||
exec_t *e;
|
||||
|
||||
if (cron == NULL)
|
||||
return;
|
||||
|
||||
while (cron->exec != NULL) {
|
||||
e = cron->exec;
|
||||
cron->exec = e->next;
|
||||
|
||||
free(e);
|
||||
}
|
||||
|
||||
free(cron->ctty);
|
||||
free(cron);
|
||||
}
|
|
@ -1,507 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
|
||||
#include "crontab.h"
|
||||
#include "libcfg.h"
|
||||
#include "util.h"
|
||||
|
||||
|
||||
static const enum_map_t weekday[] = {
|
||||
{ "MON", 1 },
|
||||
{ "TUE", 2 },
|
||||
{ "WED", 3 },
|
||||
{ "THU", 4 },
|
||||
{ "FRI", 5 },
|
||||
{ "SAT", 6 },
|
||||
{ "SUN", 0 },
|
||||
};
|
||||
|
||||
static const enum_map_t month[] = {
|
||||
{ "JAN", 1 },
|
||||
{ "FEB", 2 },
|
||||
{ "MAR", 3 },
|
||||
{ "APR", 4 },
|
||||
{ "MAY", 5 },
|
||||
{ "JUN", 6 },
|
||||
{ "JUL", 7 },
|
||||
{ "AUG", 8 },
|
||||
{ "SEP", 9 },
|
||||
{ "OCT", 10 },
|
||||
{ "NOV", 11 },
|
||||
{ "DEC", 12 },
|
||||
};
|
||||
|
||||
static const struct {
|
||||
const char *macro;
|
||||
crontab_t tab;
|
||||
} intervals[] = {
|
||||
{
|
||||
.macro = "yearly",
|
||||
.tab = {
|
||||
.minute = 0x01,
|
||||
.hour = 0x01,
|
||||
.dayofmonth = 0x01,
|
||||
.month = 0x01,
|
||||
.dayofweek = 0xFF
|
||||
},
|
||||
}, {
|
||||
.macro = "annually",
|
||||
.tab = {
|
||||
.minute = 0x01,
|
||||
.hour = 0x01,
|
||||
.dayofmonth = 0x01,
|
||||
.month = 0x01,
|
||||
.dayofweek = 0xFF
|
||||
},
|
||||
}, {
|
||||
.macro = "monthly",
|
||||
.tab = {
|
||||
.minute = 0x01,
|
||||
.hour = 0x01,
|
||||
.dayofmonth = 0x01,
|
||||
.month = 0xFFFF,
|
||||
.dayofweek = 0xFF
|
||||
},
|
||||
}, {
|
||||
.macro = "weekly",
|
||||
.tab = {
|
||||
.minute = 0x01,
|
||||
.hour = 0x01,
|
||||
.dayofmonth = 0xFFFFFFFF,
|
||||
.month = 0xFFFF,
|
||||
.dayofweek = 0x01
|
||||
},
|
||||
}, {
|
||||
.macro = "daily",
|
||||
.tab = {
|
||||
.minute = 0x01,
|
||||
.hour = 0x01,
|
||||
.dayofmonth = 0xFFFFFFFF,
|
||||
.month = 0xFFFF,
|
||||
.dayofweek = 0xFF
|
||||
},
|
||||
}, {
|
||||
.macro = "hourly",
|
||||
.tab = {
|
||||
.minute = 0x01,
|
||||
.hour = 0xFFFFFFFF,
|
||||
.dayofmonth = 0xFFFFFFFF,
|
||||
.month = 0xFFFF,
|
||||
.dayofweek = 0xFF
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static int try_unescape(char *arg, rdline_t *rd)
|
||||
{
|
||||
if (unescape(arg)) {
|
||||
fprintf(stderr, "%s: %zu: malformed string constant\n",
|
||||
rd->filename, rd->lineno);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char *try_strdup(const char *str, rdline_t *rd)
|
||||
{
|
||||
char *out = strdup(str);
|
||||
|
||||
if (out == NULL) {
|
||||
fprintf(stderr, "%s: %zu: out of memory\n",
|
||||
rd->filename, rd->lineno);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
static char *readnum(char *line, int *out, int minval, int maxval,
|
||||
const enum_map_t *mnemonic, rdline_t *rd)
|
||||
{
|
||||
int i, temp, value = 0;
|
||||
const enum_map_t *ev;
|
||||
|
||||
if (!isdigit(*line)) {
|
||||
if (!mnemonic)
|
||||
goto fail_mn;
|
||||
|
||||
for (i = 0; isalnum(line[i]); ++i)
|
||||
;
|
||||
if (i == 0)
|
||||
goto fail_mn;
|
||||
|
||||
temp = line[i];
|
||||
line[i] = '\0';
|
||||
ev = enum_by_name(mnemonic, line);
|
||||
if (!ev) {
|
||||
fprintf(stderr, "%s: %zu: unexpected '%s'",
|
||||
rd->filename, rd->lineno, line);
|
||||
}
|
||||
line[i] = temp;
|
||||
if (!ev)
|
||||
return NULL;
|
||||
*out = ev->value;
|
||||
return line + i;
|
||||
}
|
||||
|
||||
while (isdigit(*line)) {
|
||||
i = ((*(line++)) - '0');
|
||||
if (value > (maxval - i) / 10)
|
||||
goto fail_of;
|
||||
value = value * 10 + i;
|
||||
}
|
||||
|
||||
if (value < minval)
|
||||
goto fail_uf;
|
||||
|
||||
*out = value;
|
||||
return line;
|
||||
fail_of:
|
||||
fprintf(stderr, "%s: %zu: value exceeds maximum (%d > %d)\n",
|
||||
rd->filename, rd->lineno, value, maxval);
|
||||
return NULL;
|
||||
fail_uf:
|
||||
fprintf(stderr, "%s: %zu: value too small (%d < %d)\n",
|
||||
rd->filename, rd->lineno, value, minval);
|
||||
return NULL;
|
||||
fail_mn:
|
||||
fprintf(stderr, "%s: %zu: expected numeric value",
|
||||
rd->filename, rd->lineno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char *readfield(char *line, uint64_t *out, int minval, int maxval,
|
||||
const enum_map_t *mnemonic, rdline_t *rd)
|
||||
{
|
||||
int value, endvalue, step;
|
||||
uint64_t v = 0;
|
||||
next:
|
||||
if (*line == '*') {
|
||||
++line;
|
||||
value = minval;
|
||||
endvalue = maxval;
|
||||
} else {
|
||||
line = readnum(line, &value, minval, maxval, mnemonic, rd);
|
||||
if (!line)
|
||||
goto fail;
|
||||
|
||||
if (*line == '-') {
|
||||
line = readnum(line + 1, &endvalue, minval, maxval,
|
||||
mnemonic, rd);
|
||||
if (!line)
|
||||
goto fail;
|
||||
} else {
|
||||
endvalue = value;
|
||||
}
|
||||
}
|
||||
|
||||
if (endvalue < value)
|
||||
goto fail;
|
||||
|
||||
if (*line == '/') {
|
||||
line = readnum(line + 1, &step, 1, maxval + 1, NULL, rd);
|
||||
if (!line)
|
||||
goto fail;
|
||||
} else {
|
||||
step = 1;
|
||||
}
|
||||
|
||||
while (value <= endvalue) {
|
||||
v |= 1UL << (unsigned long)(value - minval);
|
||||
value += step;
|
||||
}
|
||||
|
||||
if (*line == ',' || *line == ' ') {
|
||||
++line;
|
||||
goto next;
|
||||
}
|
||||
|
||||
if (*line != '\0')
|
||||
goto fail;
|
||||
|
||||
*out = v;
|
||||
return line;
|
||||
fail:
|
||||
fprintf(stderr, "%s: %zu: invalid time range expression\n",
|
||||
rd->filename, rd->lineno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static int cron_exec(void *user, char *arg, rdline_t *rd, int flags)
|
||||
{
|
||||
crontab_t *cron = user;
|
||||
exec_t *e, *end;
|
||||
(void)flags;
|
||||
|
||||
e = calloc(1, sizeof(*e) + strlen(arg) + 1);
|
||||
if (e == NULL) {
|
||||
fprintf(stderr, "%s: %zu: out of memory\n",
|
||||
rd->filename, rd->lineno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
strcpy(e->args, arg);
|
||||
|
||||
e->argc = pack_argv(e->args);
|
||||
if (e->argc < 0) {
|
||||
fprintf(stderr, "%s: %zu: malformed string constant\n",
|
||||
rd->filename, rd->lineno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cron->exec == NULL) {
|
||||
cron->exec = e;
|
||||
} else {
|
||||
for (end = cron->exec; end->next != NULL; end = end->next)
|
||||
;
|
||||
end->next = e;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cron_hour(void *user, char *arg, rdline_t *rd, int flags)
|
||||
{
|
||||
crontab_t *cron = user;
|
||||
uint64_t value;
|
||||
(void)flags;
|
||||
|
||||
if (!readfield(arg, &value, 0, 23, NULL, rd))
|
||||
return -1;
|
||||
|
||||
cron->hour = value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cron_minute(void *user, char *arg, rdline_t *rd, int flags)
|
||||
{
|
||||
crontab_t *cron = user;
|
||||
uint64_t value;
|
||||
(void)flags;
|
||||
|
||||
if (!readfield(arg, &value, 0, 59, NULL, rd))
|
||||
return -1;
|
||||
|
||||
cron->minute = value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cron_dayofmonth(void *user, char *arg, rdline_t *rd, int flags)
|
||||
{
|
||||
crontab_t *cron = user;
|
||||
uint64_t value;
|
||||
(void)flags;
|
||||
|
||||
if (!readfield(arg, &value, 1, 31, NULL, rd))
|
||||
return -1;
|
||||
|
||||
cron->dayofmonth = value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cron_dayofweek(void *user, char *arg, rdline_t *rd, int flags)
|
||||
{
|
||||
crontab_t *cron = user;
|
||||
uint64_t value;
|
||||
(void)flags;
|
||||
|
||||
if (!readfield(arg, &value, 0, 6, weekday, rd))
|
||||
return -1;
|
||||
|
||||
cron->dayofweek = value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cron_month(void *user, char *arg, rdline_t *rd, int flags)
|
||||
{
|
||||
crontab_t *cron = user;
|
||||
uint64_t value;
|
||||
(void)flags;
|
||||
|
||||
if (!readfield(arg, &value, 1, 12, month, rd))
|
||||
return -1;
|
||||
|
||||
cron->month = value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cron_interval(void *user, char *arg, rdline_t *rd, int flags)
|
||||
{
|
||||
crontab_t *cron = user;
|
||||
size_t i;
|
||||
(void)flags;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(intervals); ++i) {
|
||||
if (!strcmp(intervals[i].macro, arg)) {
|
||||
cron->minute = intervals[i].tab.minute;
|
||||
cron->hour = intervals[i].tab.hour;
|
||||
cron->dayofmonth = intervals[i].tab.dayofmonth;
|
||||
cron->month = intervals[i].tab.month;
|
||||
cron->dayofweek = intervals[i].tab.dayofweek;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "%s: %zu: unknown interval '%s'\n",
|
||||
rd->filename, rd->lineno, arg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int cron_user(void *user, char *arg, rdline_t *rd, int flags)
|
||||
{
|
||||
crontab_t *cron = user;
|
||||
struct passwd *pwd;
|
||||
bool isnumeric;
|
||||
char *ptr;
|
||||
int value;
|
||||
(void)flags;
|
||||
|
||||
for (ptr = arg; isdigit(*ptr); ++ptr)
|
||||
;
|
||||
|
||||
isnumeric = (*ptr == '\0');
|
||||
pwd = getpwnam(arg);
|
||||
|
||||
if (pwd == NULL && !isnumeric) {
|
||||
fprintf(stderr, "%s: %zu: unknown user '%s'\n",
|
||||
rd->filename, rd->lineno, arg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pwd != NULL) {
|
||||
cron->uid = pwd->pw_uid;
|
||||
} else {
|
||||
if (readnum(arg, &value, 0, INT_MAX, NULL, rd))
|
||||
return -1;
|
||||
cron->uid = value;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cron_group(void *user, char *arg, rdline_t *rd, int flags)
|
||||
{
|
||||
crontab_t *cron = user;
|
||||
struct group *group;
|
||||
bool isnumeric;
|
||||
char *ptr;
|
||||
int value;
|
||||
(void)flags;
|
||||
|
||||
for (ptr = arg; isdigit(*ptr); ++ptr)
|
||||
;
|
||||
|
||||
isnumeric = (*ptr == '\0');
|
||||
group = getgrnam(arg);
|
||||
|
||||
if (group == NULL && !isnumeric) {
|
||||
fprintf(stderr, "%s: %zu: unknown group '%s'\n",
|
||||
rd->filename, rd->lineno, arg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (group != NULL) {
|
||||
cron->gid = group->gr_gid;
|
||||
} else {
|
||||
if (readnum(arg, &value, 0, INT_MAX, NULL, rd))
|
||||
return -1;
|
||||
cron->gid = value;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cron_tty(void *user, char *arg, rdline_t *rd, int flags)
|
||||
{
|
||||
crontab_t *cron = user;
|
||||
(void)flags;
|
||||
|
||||
if (strncmp(arg, "truncate", 8) == 0 && isspace(arg[8])) {
|
||||
cron->tty_truncate = 1;
|
||||
arg += 8;
|
||||
while (isspace(*arg))
|
||||
++arg;
|
||||
}
|
||||
|
||||
if (try_unescape(arg, rd))
|
||||
return -1;
|
||||
|
||||
cron->ctty = try_strdup(arg, rd);
|
||||
return cron->ctty == NULL ? -1 : 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static const cfg_param_t cron_params[] = {
|
||||
{ "hour", 0, cron_hour },
|
||||
{ "minute", 0, cron_minute },
|
||||
{ "dayofmonth", 0, cron_dayofmonth },
|
||||
{ "dayofweek", 0, cron_dayofweek },
|
||||
{ "month", 0, cron_month },
|
||||
{ "interval", 0, cron_interval },
|
||||
{ "user", 0, cron_user },
|
||||
{ "group", 0, cron_group },
|
||||
{ "tty", 0, cron_tty },
|
||||
{ "exec", 1, cron_exec },
|
||||
};
|
||||
|
||||
crontab_t *rdcron(int dirfd, const char *filename)
|
||||
{
|
||||
crontab_t *cron;
|
||||
rdline_t rd;
|
||||
int fd, ret;
|
||||
|
||||
fd = openat(dirfd, filename, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
perror(filename);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cron = calloc(1, sizeof(*cron));
|
||||
if (cron == NULL) {
|
||||
fputs("out of memory\n", stderr);
|
||||
goto out;
|
||||
}
|
||||
|
||||
cron->minute = 0xFFFFFFFFFFFFFFFFUL;
|
||||
cron->hour = 0xFFFFFFFF;
|
||||
cron->dayofmonth = 0xFFFFFFFF;
|
||||
cron->month = 0xFFFF;
|
||||
cron->dayofweek = 0xFF;
|
||||
|
||||
rdline_init(&rd, fd, filename, 0, NULL);
|
||||
ret = rdcfg(cron, &rd, cron_params, ARRAY_SIZE(cron_params), 0);
|
||||
if (ret) {
|
||||
delcron(cron);
|
||||
cron = NULL;
|
||||
}
|
||||
out:
|
||||
close(fd);
|
||||
return cron;
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef CRONTAB_H
|
||||
#define CRONTAB_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "service.h"
|
||||
|
||||
typedef struct crontab_t {
|
||||
struct crontab_t *next;
|
||||
exec_t *exec;
|
||||
char *ctty;
|
||||
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
|
||||
uint64_t minute;
|
||||
uint32_t hour;
|
||||
uint32_t dayofmonth;
|
||||
uint16_t month;
|
||||
uint8_t dayofweek;
|
||||
|
||||
unsigned int tty_truncate : 1;
|
||||
} crontab_t;
|
||||
|
||||
crontab_t *rdcron(int dirfd, const char *filename);
|
||||
|
||||
void delcron(crontab_t *cron);
|
||||
|
||||
int cronscan(const char *directory, crontab_t **list);
|
||||
|
||||
void cron_tm_to_mask(crontab_t *out, struct tm *t);
|
||||
|
||||
bool cron_should_run(const crontab_t *t, const crontab_t *mask);
|
||||
|
||||
#endif /* CRONTAB_H */
|
65
lib/include/initsock.h
Normal file
65
lib/include/initsock.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
/* SPDX-License-Identifier: ISC */
|
||||
#ifndef INITSOCK_H
|
||||
#define INITSOCK_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "service.h"
|
||||
|
||||
#define INIT_SOCK_PATH SOCKDIR "/init.sock"
|
||||
|
||||
typedef enum {
|
||||
EIR_STATUS = 0x00,
|
||||
EIR_START = 0x01,
|
||||
EIR_STOP = 0x02,
|
||||
} E_INIT_REQUEST;
|
||||
|
||||
typedef enum {
|
||||
ESS_NONE = 0x00,
|
||||
ESS_RUNNING = 0x01,
|
||||
ESS_ENQUEUED = 0x02,
|
||||
ESS_DONE = 0x03,
|
||||
ESS_FAILED = 0x04
|
||||
} E_SERVICE_STATE;
|
||||
|
||||
typedef struct {
|
||||
uint8_t rq;
|
||||
uint8_t padd[3];
|
||||
|
||||
union {
|
||||
struct {
|
||||
uint8_t filter;
|
||||
uint8_t padd[3];
|
||||
} status;
|
||||
|
||||
struct {
|
||||
uint32_t id;
|
||||
} startstop;
|
||||
} arg;
|
||||
} init_request_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t state;
|
||||
uint8_t exit_status;
|
||||
uint8_t padd[2];
|
||||
int32_t id;
|
||||
} init_response_status_t;
|
||||
|
||||
typedef struct {
|
||||
E_SERVICE_STATE state;
|
||||
int exit_status;
|
||||
int id;
|
||||
char *filename;
|
||||
char *service_name;
|
||||
} init_status_t;
|
||||
|
||||
int init_socket_open(const char *tmppath);
|
||||
|
||||
int init_socket_send_request(int fd, E_INIT_REQUEST rq, ...);
|
||||
|
||||
int init_socket_recv_status(int fd, init_status_t *resp);
|
||||
|
||||
void free_init_status(init_status_t *resp);
|
||||
|
||||
#endif /* INITSOCK_H */
|
|
@ -1,42 +1,19 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* SPDX-License-Identifier: ISC */
|
||||
#ifndef LIBCONFIG_H
|
||||
#define LIBCONFIG_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
typedef struct {
|
||||
int fd; /* input file descriptor */
|
||||
const char *argstr; /* if not NULL, read from this instead */
|
||||
|
||||
const char *filename; /* input file name */
|
||||
size_t lineno; /* current line number */
|
||||
|
||||
size_t i; /* buffer offset */
|
||||
char buffer[256]; /* current line, null-terminated */
|
||||
FILE *fp;
|
||||
char *line;
|
||||
|
||||
int argc;
|
||||
const char *const *argv;
|
||||
|
||||
bool string; /* inside a string? */
|
||||
bool escape; /* reading an escape sequence? */
|
||||
bool comment; /* inside a comment */
|
||||
} rdline_t;
|
||||
|
||||
typedef struct {
|
||||
|
@ -50,18 +27,22 @@ typedef struct {
|
|||
*/
|
||||
unsigned int allow_block : 1;
|
||||
|
||||
int (*handle)(void *obj, char *arg, rdline_t *rd, int flags);
|
||||
int (*handle)(void *obj, char *arg, rdline_t *rd);
|
||||
} cfg_param_t;
|
||||
|
||||
/*
|
||||
Initialize the config line scanner.
|
||||
|
||||
The scanner reads from the provided fd. The filename is used for
|
||||
error reporting. An argument count and vector can be set for argument
|
||||
substitution in rdline.
|
||||
The scanner opens the filename relative to the passed dirfd. An
|
||||
argument count and vector can be set for argument substitution
|
||||
in rdline.
|
||||
|
||||
Returns 0 on success.
|
||||
*/
|
||||
void rdline_init(rdline_t *t, int fd, const char *filename,
|
||||
int argc, const char *const *argv);
|
||||
int rdline_init(rdline_t *t, int dirfd, const char *filename,
|
||||
int argc, const char *const *argv);
|
||||
|
||||
void rdline_cleanup(rdline_t *t);
|
||||
|
||||
/*
|
||||
Read from file until end-of-file or a line feed is encountered.
|
||||
|
@ -84,9 +65,8 @@ void rdline_init(rdline_t *t, int fd, const char *filename,
|
|||
outside the bounds set by argc, processing fails. On success,
|
||||
the argv value is inserted and processed as described above.
|
||||
- A '%' character can be escaped by writing '%%' or, if inside
|
||||
a double quite string, by writing \%.
|
||||
- An attempt to use such an indexed argument inside an argument
|
||||
expansion, results in failure.
|
||||
a double quoted string, by writing \%.
|
||||
- Arguments are pasted as is. Substitution is not recursive.
|
||||
- If the resulting line is empty, processing is restarted.
|
||||
*/
|
||||
int rdline(rdline_t *t);
|
||||
|
@ -110,22 +90,12 @@ int unescape(char *src);
|
|||
*/
|
||||
int pack_argv(char *str);
|
||||
|
||||
/*
|
||||
Split the current input line into a space seperted keyword
|
||||
(alphabetical characters only) and a value (the rest of the line).
|
||||
|
||||
If errors are encounted, prints a diagnostic message to stderr and
|
||||
returns -1. On success, zero is returned.
|
||||
*/
|
||||
int splitkv(rdline_t *rd, char **k, char **v);
|
||||
|
||||
/*
|
||||
Parse a configuration file containing '<keyword> [arguments...]' lines.
|
||||
The cfgobj and flags are passed to the callback in the params array.
|
||||
The cfgobj is passed to the callback in the params array.
|
||||
|
||||
Returns zero on success.
|
||||
*/
|
||||
int rdcfg(void *cfgobj, rdline_t *rd, const cfg_param_t *params, size_t count,
|
||||
int flags);
|
||||
int rdcfg(void *cfgobj, rdline_t *rd, const cfg_param_t *params, size_t count);
|
||||
|
||||
#endif /* LIBCONFIG_H */
|
||||
|
|
|
@ -1,26 +1,14 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* SPDX-License-Identifier: ISC */
|
||||
#ifndef SERVICE_H
|
||||
#define SERVICE_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "util.h"
|
||||
typedef struct exec_t {
|
||||
struct exec_t *next;
|
||||
int argc; /* number of elements in argument vector */
|
||||
char args[]; /* argument vectot string blob */
|
||||
} exec_t;
|
||||
|
||||
enum {
|
||||
/*
|
||||
|
@ -35,6 +23,8 @@ enum {
|
|||
it terminates.
|
||||
*/
|
||||
SVC_RESPAWN,
|
||||
|
||||
SVC_MAX
|
||||
};
|
||||
|
||||
enum {
|
||||
|
@ -45,23 +35,13 @@ enum {
|
|||
TGT_MAX
|
||||
};
|
||||
|
||||
enum {
|
||||
RDSVC_NO_FNAME = 0x01, /* do not store a copy of the filename */
|
||||
RDSVC_NO_EXEC = 0x02, /* do not store executable script */
|
||||
RDSVC_NO_CTTY = 0x04, /* do not store the controlling tty */
|
||||
RDSVC_NO_DEPS = 0x08, /* do not store dependencies */
|
||||
};
|
||||
|
||||
enum {
|
||||
/* truncate stdout */
|
||||
SVC_FLAG_TRUNCATE_OUT = 0x01,
|
||||
};
|
||||
|
||||
typedef struct exec_t {
|
||||
struct exec_t *next;
|
||||
int argc; /* number of elements in argument vector */
|
||||
char args[]; /* argument vectot string blob */
|
||||
} exec_t;
|
||||
SVC_FLAG_HAS_EXEC = 0x10,
|
||||
SVC_FLAG_ADMIN_STOPPED = 0x20,
|
||||
};
|
||||
|
||||
typedef struct service_t {
|
||||
struct service_t *next;
|
||||
|
@ -73,6 +53,7 @@ typedef struct service_t {
|
|||
char *desc; /* description string */
|
||||
char *ctty; /* controlling tty or log file */
|
||||
int rspwn_limit; /* maximum respawn count */
|
||||
int rspwn_count; /* services respawn counter */
|
||||
unsigned int flags; /* SVC_FLAG_* bit field */
|
||||
|
||||
/* linked list of command lines to execute */
|
||||
|
@ -86,6 +67,7 @@ typedef struct service_t {
|
|||
|
||||
pid_t pid;
|
||||
int status; /* process exit status */
|
||||
int id; /* service ID used by initd */
|
||||
|
||||
char name[]; /* canonical service name */
|
||||
} service_t;
|
||||
|
@ -97,7 +79,7 @@ typedef struct {
|
|||
/*
|
||||
Read a service from a file.
|
||||
*/
|
||||
service_t *rdsvc(int dirfd, const char *filename, int flags);
|
||||
service_t *rdsvc(int dirfd, const char *filename);
|
||||
|
||||
void delsvc(service_t *svc);
|
||||
|
||||
|
@ -108,7 +90,7 @@ void delsvc(service_t *svc);
|
|||
Returns 0 on success, -1 on failure. The function takes care of
|
||||
printing error messages on failure.
|
||||
*/
|
||||
int svcscan(const char *directory, service_list_t *list, int flags);
|
||||
int svcscan(const char *directory, service_list_t *list);
|
||||
|
||||
void del_svc_list(service_list_t *list);
|
||||
|
||||
|
@ -125,9 +107,4 @@ const char *svc_target_to_string(int target);
|
|||
|
||||
int svc_target_from_string(const char *target);
|
||||
|
||||
int setup_tty(const char *tty, bool truncate);
|
||||
|
||||
NORETURN void argv_exec(exec_t *e);
|
||||
|
||||
#endif /* SERVICE_H */
|
||||
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef TELINIT_H
|
||||
#define TELINIT_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#define INITSOCK SOCKDIR "/" "initd.socket"
|
||||
|
||||
enum {
|
||||
TI_SHUTDOWN = 1,
|
||||
TI_REBOOT = 2,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int type; /* TI_* message type identifier */
|
||||
} ti_msg_t;
|
||||
|
||||
/* Try to connect to the init socket. */
|
||||
int opensock(void);
|
||||
|
||||
#endif /* TELINIT_H */
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef UTIL_H
|
||||
#define UTIL_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define NORETURN __attribute__((noreturn))
|
||||
#endif
|
||||
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
int value;
|
||||
} enum_map_t;
|
||||
|
||||
enum {
|
||||
/* only allow root to connect */
|
||||
SOCK_FLAG_ROOT_ONLY = 0x01,
|
||||
|
||||
/* allow everyone to connect */
|
||||
SOCK_FLAG_EVERYONE = 0x02,
|
||||
|
||||
/* create a datagram socket, otherwise use a stream socket */
|
||||
SOCK_FLAG_DGRAM = 0x04,
|
||||
};
|
||||
|
||||
/*
|
||||
Search through an array of enum_map_t entries to resolve a string to
|
||||
a numeric value. The end of the map is indicated by a sentinel entry
|
||||
with the name set to NULL.
|
||||
*/
|
||||
const enum_map_t *enum_by_name(const enum_map_t *map, const char *name);
|
||||
|
||||
/*
|
||||
Search through an array of enum_map_t entries to resolve a numeric
|
||||
value to a string name. The end of the map is indicated by a sentinel
|
||||
entry with the name set to NULL.
|
||||
*/
|
||||
const char *enum_to_name(const enum_map_t *map, int value);
|
||||
|
||||
/*
|
||||
Create a UNIX stream socket at the given path.
|
||||
|
||||
Returns the socket fd, -1 on failure. The function takes care of
|
||||
printing error messages on failure.
|
||||
|
||||
The socket has the CLOEXEC flag set.
|
||||
*/
|
||||
int mksock(const char *path, int flags);
|
||||
|
||||
/* print a default version info and license string */
|
||||
NORETURN void print_version(const char *program);
|
||||
|
||||
#endif /* UTIL_H */
|
||||
|
19
lib/init/del_svc_list.c
Normal file
19
lib/init/del_svc_list.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
/* SPDX-License-Identifier: ISC */
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "service.h"
|
||||
|
||||
void del_svc_list(service_list_t *list)
|
||||
{
|
||||
service_t *svc;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < TGT_MAX; ++i) {
|
||||
while (list->targets[i] != NULL) {
|
||||
svc = list->targets[i];
|
||||
list->targets[i] = svc->next;
|
||||
|
||||
delsvc(svc);
|
||||
}
|
||||
}
|
||||
}
|
27
lib/init/delsvc.c
Normal file
27
lib/init/delsvc.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
/* SPDX-License-Identifier: ISC */
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "service.h"
|
||||
|
||||
void delsvc(service_t *svc)
|
||||
{
|
||||
exec_t *e;
|
||||
|
||||
if (svc == NULL)
|
||||
return;
|
||||
|
||||
while (svc->exec != NULL) {
|
||||
e = svc->exec;
|
||||
svc->exec = e->next;
|
||||
|
||||
free(e);
|
||||
}
|
||||
|
||||
free(svc->before);
|
||||
free(svc->after);
|
||||
free(svc->fname);
|
||||
free(svc->desc);
|
||||
free(svc->exec);
|
||||
free(svc->ctty);
|
||||
free(svc);
|
||||
}
|
10
lib/init/free_init_status.c
Normal file
10
lib/init/free_init_status.c
Normal file
|
@ -0,0 +1,10 @@
|
|||
/* SPDX-License-Identifier: ISC */
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "initsock.h"
|
||||
|
||||
void free_init_status(init_status_t *resp)
|
||||
{
|
||||
free(resp->filename);
|
||||
free(resp->service_name);
|
||||
}
|
46
lib/init/init_socket_open.c
Normal file
46
lib/init/init_socket_open.c
Normal file
|
@ -0,0 +1,46 @@
|
|||
/* SPDX-License-Identifier: ISC */
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "initsock.h"
|
||||
|
||||
int init_socket_open(const char *tmppath)
|
||||
{
|
||||
struct sockaddr_un un;
|
||||
int fd;
|
||||
|
||||
fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
|
||||
if (fd < 0) {
|
||||
perror("socket");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&un, 0, sizeof(un));
|
||||
un.sun_family = AF_UNIX;
|
||||
|
||||
strcpy(un.sun_path, tmppath);
|
||||
|
||||
if (bind(fd, (struct sockaddr *)&un, sizeof(un))) {
|
||||
fprintf(stderr, "bind: %s: %s", tmppath, strerror(errno));
|
||||
close(fd);
|
||||
unlink(tmppath);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&un, 0, sizeof(un));
|
||||
un.sun_family = AF_UNIX;
|
||||
|
||||
strcpy(un.sun_path, INIT_SOCK_PATH);
|
||||
|
||||
if (connect(fd, (struct sockaddr *)&un, sizeof(un))) {
|
||||
perror("connect: " INIT_SOCK_PATH);
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
87
lib/init/init_socket_recv_status.c
Normal file
87
lib/init/init_socket_recv_status.c
Normal file
|
@ -0,0 +1,87 @@
|
|||
/* SPDX-License-Identifier: ISC */
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "initsock.h"
|
||||
|
||||
static int read_retry(int fd, void *buffer, size_t size)
|
||||
{
|
||||
ssize_t ret;
|
||||
retry:
|
||||
ret = read(fd, buffer, size);
|
||||
|
||||
if (ret < 0) {
|
||||
if (errno == EINTR)
|
||||
goto retry;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((size_t)ret < size) {
|
||||
errno = EPROTO;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static char *read_string(int fd)
|
||||
{
|
||||
uint16_t len;
|
||||
char *buffer;
|
||||
int ret;
|
||||
|
||||
ret = read_retry(fd, &len, sizeof(len));
|
||||
if (ret <= 0)
|
||||
return NULL;
|
||||
|
||||
len = be16toh(len);
|
||||
|
||||
buffer = calloc(1, len + 1);
|
||||
if (buffer == NULL)
|
||||
return NULL;
|
||||
|
||||
if (len > 0) {
|
||||
ret = read_retry(fd, buffer, len);
|
||||
|
||||
if (ret <= 0) {
|
||||
ret = errno;
|
||||
free(buffer);
|
||||
errno = ret;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
int init_socket_recv_status(int fd, init_status_t *resp)
|
||||
{
|
||||
init_response_status_t info;
|
||||
|
||||
memset(resp, 0, sizeof(*resp));
|
||||
|
||||
if (read_retry(fd, &info, sizeof(info)) <= 0)
|
||||
return -1;
|
||||
|
||||
resp->state = info.state;
|
||||
resp->exit_status = info.exit_status;
|
||||
resp->id = be32toh(info.id);
|
||||
|
||||
if (resp->state == ESS_NONE)
|
||||
return 0;
|
||||
|
||||
resp->filename = read_string(fd);
|
||||
if (resp->filename == NULL)
|
||||
return -1;
|
||||
|
||||
resp->service_name = read_string(fd);
|
||||
if (resp->service_name == NULL)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
45
lib/init/init_socket_send_request.c
Normal file
45
lib/init/init_socket_send_request.c
Normal file
|
@ -0,0 +1,45 @@
|
|||
/* SPDX-License-Identifier: ISC */
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <endian.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "initsock.h"
|
||||
|
||||
int init_socket_send_request(int fd, E_INIT_REQUEST rq, ...)
|
||||
{
|
||||
init_request_t request;
|
||||
ssize_t ret;
|
||||
va_list ap;
|
||||
|
||||
memset(&request, 0, sizeof(request));
|
||||
request.rq = rq;
|
||||
|
||||
va_start(ap, rq);
|
||||
switch (rq) {
|
||||
case EIR_STATUS:
|
||||
request.arg.status.filter = va_arg(ap, E_SERVICE_STATE);
|
||||
break;
|
||||
case EIR_START:
|
||||
case EIR_STOP:
|
||||
request.arg.startstop.id = htobe32(va_arg(ap, int));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
retry:
|
||||
ret = write(fd, &request, sizeof(request));
|
||||
|
||||
if (ret < 0) {
|
||||
if (errno == EINTR)
|
||||
goto retry;
|
||||
perror(INIT_SOCK_PATH);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,20 +1,4 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* SPDX-License-Identifier: ISC */
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
@ -27,7 +11,6 @@
|
|||
|
||||
#include "service.h"
|
||||
#include "libcfg.h"
|
||||
#include "util.h"
|
||||
|
||||
static int try_unescape(char *arg, rdline_t *rd)
|
||||
{
|
||||
|
@ -60,10 +43,9 @@ static int try_pack_argv(char *str, rdline_t *rd)
|
|||
return count;
|
||||
}
|
||||
|
||||
static int svc_desc(void *user, char *arg, rdline_t *rd, int flags)
|
||||
static int svc_desc(void *user, char *arg, rdline_t *rd)
|
||||
{
|
||||
service_t *svc = user;
|
||||
(void)flags;
|
||||
|
||||
if (try_unescape(arg, rd))
|
||||
return -1;
|
||||
|
@ -71,13 +53,10 @@ static int svc_desc(void *user, char *arg, rdline_t *rd, int flags)
|
|||
return svc->desc == NULL ? -1 : 0;
|
||||
}
|
||||
|
||||
static int svc_tty(void *user, char *arg, rdline_t *rd, int flags)
|
||||
static int svc_tty(void *user, char *arg, rdline_t *rd)
|
||||
{
|
||||
service_t *svc = user;
|
||||
|
||||
if (flags & RDSVC_NO_CTTY)
|
||||
return 0;
|
||||
|
||||
if (strncmp(arg, "truncate", 8) == 0 && isspace(arg[8])) {
|
||||
svc->flags |= SVC_FLAG_TRUNCATE_OUT;
|
||||
arg += 8;
|
||||
|
@ -92,13 +71,12 @@ static int svc_tty(void *user, char *arg, rdline_t *rd, int flags)
|
|||
return svc->ctty == NULL ? -1 : 0;
|
||||
}
|
||||
|
||||
static int svc_exec(void *user, char *arg, rdline_t *rd, int flags)
|
||||
static int svc_exec(void *user, char *arg, rdline_t *rd)
|
||||
{
|
||||
service_t *svc = user;
|
||||
exec_t *e, *end;
|
||||
|
||||
if (flags & RDSVC_NO_EXEC)
|
||||
return 0;
|
||||
svc->flags |= SVC_FLAG_HAS_EXEC;
|
||||
|
||||
e = calloc(1, sizeof(*e) + strlen(arg) + 1);
|
||||
if (e == NULL) {
|
||||
|
@ -123,13 +101,10 @@ static int svc_exec(void *user, char *arg, rdline_t *rd, int flags)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int svc_before(void *user, char *arg, rdline_t *rd, int flags)
|
||||
static int svc_before(void *user, char *arg, rdline_t *rd)
|
||||
{
|
||||
service_t *svc = user;
|
||||
|
||||
if (flags & RDSVC_NO_DEPS)
|
||||
return 0;
|
||||
|
||||
if (svc->before != NULL) {
|
||||
fprintf(stderr, "%s: %zu: 'before' dependencies respecified\n",
|
||||
rd->filename, rd->lineno);
|
||||
|
@ -144,13 +119,10 @@ static int svc_before(void *user, char *arg, rdline_t *rd, int flags)
|
|||
return (svc->num_before < 0) ? -1 : 0;
|
||||
}
|
||||
|
||||
static int svc_after(void *user, char *arg, rdline_t *rd, int flags)
|
||||
static int svc_after(void *user, char *arg, rdline_t *rd)
|
||||
{
|
||||
service_t *svc = user;
|
||||
|
||||
if (flags & RDSVC_NO_DEPS)
|
||||
return 0;
|
||||
|
||||
if (svc->after != NULL) {
|
||||
fprintf(stderr, "%s: %zu: 'after' dependencies respecified\n",
|
||||
rd->filename, rd->lineno);
|
||||
|
@ -165,11 +137,10 @@ static int svc_after(void *user, char *arg, rdline_t *rd, int flags)
|
|||
return (svc->num_after < 0) ? -1 : 0;
|
||||
}
|
||||
|
||||
static int svc_type(void *user, char *arg, rdline_t *rd, int flags)
|
||||
static int svc_type(void *user, char *arg, rdline_t *rd)
|
||||
{
|
||||
service_t *svc = user;
|
||||
int count = try_pack_argv(arg, rd);
|
||||
(void)flags;
|
||||
|
||||
if (count < 1)
|
||||
return -1;
|
||||
|
@ -213,11 +184,10 @@ fail_limit:
|
|||
return -1;
|
||||
}
|
||||
|
||||
static int svc_target(void *user, char *arg, rdline_t *rd, int flags)
|
||||
static int svc_target(void *user, char *arg, rdline_t *rd)
|
||||
{
|
||||
service_t *svc = user;
|
||||
int target;
|
||||
(void)flags;
|
||||
|
||||
if (try_unescape(arg, rd))
|
||||
return -1;
|
||||
|
@ -244,19 +214,12 @@ static const cfg_param_t svc_params[] = {
|
|||
{ "after", 0, svc_after },
|
||||
};
|
||||
|
||||
service_t *rdsvc(int dirfd, const char *filename, int flags)
|
||||
service_t *rdsvc(int dirfd, const char *filename)
|
||||
{
|
||||
const char *arg, *args[1];
|
||||
service_t *svc = NULL;
|
||||
size_t argc, nlen;
|
||||
rdline_t rd;
|
||||
int fd;
|
||||
|
||||
fd = openat(dirfd, filename, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
perror(filename);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
arg = strchr(filename, '@');
|
||||
if (arg != NULL) {
|
||||
|
@ -266,7 +229,8 @@ service_t *rdsvc(int dirfd, const char *filename, int flags)
|
|||
argc = 0;
|
||||
}
|
||||
|
||||
rdline_init(&rd, fd, filename, argc, args);
|
||||
if (rdline_init(&rd, dirfd, filename, argc, args))
|
||||
return NULL;
|
||||
|
||||
nlen = (arg != NULL) ? (size_t)(arg - filename) : strlen(filename);
|
||||
|
||||
|
@ -274,23 +238,25 @@ service_t *rdsvc(int dirfd, const char *filename, int flags)
|
|||
if (svc == NULL)
|
||||
goto fail_oom;
|
||||
|
||||
if (!(flags & RDSVC_NO_FNAME)) {
|
||||
svc->fname = strdup(filename);
|
||||
if (svc->fname == NULL)
|
||||
goto fail_oom;
|
||||
}
|
||||
svc->fname = strdup(filename);
|
||||
if (svc->fname == NULL)
|
||||
goto fail_oom;
|
||||
|
||||
memcpy(svc->name, filename, nlen);
|
||||
svc->id = -1;
|
||||
|
||||
if (rdcfg(svc, &rd, svc_params, ARRAY_SIZE(svc_params), flags))
|
||||
if (rdcfg(svc, &rd, svc_params,
|
||||
sizeof(svc_params) / sizeof(svc_params[0]))) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
out:
|
||||
rdline_cleanup(&rd);
|
||||
return svc;
|
||||
fail_oom:
|
||||
fputs("out of memory\n", stderr);
|
||||
fail:
|
||||
delsvc(svc);
|
||||
close(fd);
|
||||
return NULL;
|
||||
svc = NULL;
|
||||
goto out;
|
||||
}
|
|
@ -1,20 +1,4 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* SPDX-License-Identifier: ISC */
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
49
lib/init/svcmap.c
Normal file
49
lib/init/svcmap.c
Normal file
|
@ -0,0 +1,49 @@
|
|||
/* SPDX-License-Identifier: ISC */
|
||||
#include <string.h>
|
||||
#include "service.h"
|
||||
|
||||
static const char *type_map[] = {
|
||||
"once",
|
||||
"wait",
|
||||
"respawn",
|
||||
};
|
||||
|
||||
static const char *target_map[] = {
|
||||
"boot",
|
||||
"shutdown",
|
||||
"reboot",
|
||||
};
|
||||
|
||||
const char *svc_type_to_string(int type)
|
||||
{
|
||||
return type >= 0 && type < SVC_MAX ? type_map[type] : NULL;
|
||||
}
|
||||
|
||||
int svc_type_from_string(const char *type)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < sizeof(type_map) / sizeof(type_map[0]); ++i) {
|
||||
if (strcmp(type_map[i], type) == 0)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *svc_target_to_string(int target)
|
||||
{
|
||||
return target >= 0 && target < TGT_MAX ? target_map[target] : NULL;
|
||||
}
|
||||
|
||||
int svc_target_from_string(const char *target)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < sizeof(target_map) / sizeof(target_map[0]); ++i) {
|
||||
if (strcmp(target_map[i], target) == 0)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
|
@ -1,20 +1,4 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* SPDX-License-Identifier: ISC */
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stddef.h>
|
||||
|
@ -27,7 +11,7 @@
|
|||
|
||||
#include "service.h"
|
||||
|
||||
int svcscan(const char *directory, service_list_t *list, int flags)
|
||||
int svcscan(const char *directory, service_list_t *list)
|
||||
{
|
||||
int i, dfd, type, ret = 0;
|
||||
struct dirent *ent;
|
||||
|
@ -82,7 +66,7 @@ int svcscan(const char *directory, service_list_t *list, int flags)
|
|||
if (type != S_IFREG && type != S_IFLNK)
|
||||
continue;
|
||||
|
||||
svc = rdsvc(dfd, ent->d_name, flags);
|
||||
svc = rdsvc(dfd, ent->d_name);
|
||||
if (svc == NULL) {
|
||||
ret = -1;
|
||||
continue;
|
|
@ -1,20 +1,4 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* SPDX-License-Identifier: ISC */
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
|
|
@ -1,24 +1,9 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* SPDX-License-Identifier: ISC */
|
||||
#include "libcfg.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
static const cfg_param_t *find_param(rdline_t *rd, const char *name,
|
||||
const cfg_param_t *params, size_t count)
|
||||
|
@ -35,8 +20,34 @@ static const cfg_param_t *find_param(rdline_t *rd, const char *name,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int rdcfg(void *cfgobj, rdline_t *rd, const cfg_param_t *params, size_t count,
|
||||
int flags)
|
||||
static int splitkv(rdline_t *rd, char **k, char **v)
|
||||
{
|
||||
char *key = rd->line, *value = rd->line;
|
||||
|
||||
while (*value != ' ' && *value != '\0') {
|
||||
if (!isalpha(*value)) {
|
||||
fprintf(stderr,
|
||||
"%s: %zu: unexpected '%c' in keyword\n",
|
||||
rd->filename, rd->lineno, *value);
|
||||
return -1;
|
||||
}
|
||||
++value;
|
||||
}
|
||||
|
||||
if (*value != ' ') {
|
||||
fprintf(stderr, "%s: %zu: expected argument after '%s'\n",
|
||||
rd->filename, rd->lineno, key);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*(value++) = '\0';
|
||||
|
||||
*k = key;
|
||||
*v = value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rdcfg(void *cfgobj, rdline_t *rd, const cfg_param_t *params, size_t count)
|
||||
{
|
||||
const cfg_param_t *p;
|
||||
char *key, *value;
|
||||
|
@ -55,15 +66,15 @@ int rdcfg(void *cfgobj, rdline_t *rd, const cfg_param_t *params, size_t count,
|
|||
;
|
||||
|
||||
if (*value != '\0') {
|
||||
ret = p->handle(cfgobj, value, rd, flags);
|
||||
ret = p->handle(cfgobj, value, rd);
|
||||
if (ret)
|
||||
return -1;
|
||||
}
|
||||
|
||||
while ((ret = rdline(rd)) == 0) {
|
||||
if (strcmp(rd->buffer, "}") == 0)
|
||||
if (strcmp(rd->line, "}") == 0)
|
||||
break;
|
||||
if (p->handle(cfgobj, rd->buffer, rd, flags))
|
||||
if (p->handle(cfgobj, rd->line, rd))
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -71,7 +82,7 @@ int rdcfg(void *cfgobj, rdline_t *rd, const cfg_param_t *params, size_t count,
|
|||
return -1;
|
||||
if (ret > 0)
|
||||
goto fail_bra;
|
||||
} else if (p->handle(cfgobj, value, rd, flags)) {
|
||||
} else if (p->handle(cfgobj, value, rd)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,174 +1,172 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* SPDX-License-Identifier: ISC */
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "libcfg.h"
|
||||
|
||||
static int rdline_getc(rdline_t *t)
|
||||
int rdline_init(rdline_t *t, int dirfd, const char *filename,
|
||||
int argc, const char *const *argv)
|
||||
{
|
||||
int ret;
|
||||
char c;
|
||||
int fd = openat(dirfd, filename, O_RDONLY);
|
||||
|
||||
if (t->argstr != NULL) {
|
||||
c = *(t->argstr++);
|
||||
if (c != '\0')
|
||||
goto out;
|
||||
if (fd == -1)
|
||||
goto fail_open;
|
||||
|
||||
t->argstr = NULL;
|
||||
}
|
||||
|
||||
do {
|
||||
ret = read(t->fd, &c, 1);
|
||||
} while (ret < 0 && errno == EINTR);
|
||||
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
|
||||
if (ret == 0) {
|
||||
if (t->i == 0) {
|
||||
errno = 0;
|
||||
return -1;
|
||||
}
|
||||
c = '\0';
|
||||
}
|
||||
out:
|
||||
return (c == '\n') ? '\0' : c;
|
||||
}
|
||||
|
||||
static int rdline_append(rdline_t *t, int c)
|
||||
{
|
||||
if (t->comment) {
|
||||
if (c != '\0')
|
||||
return 0;
|
||||
} else if (t->string) {
|
||||
if (t->escape) {
|
||||
t->escape = false;
|
||||
} else {
|
||||
if (c == '\\')
|
||||
t->escape = true;
|
||||
if (c == '"')
|
||||
t->string = false;
|
||||
}
|
||||
} else {
|
||||
if (isspace(c))
|
||||
c = ' ';
|
||||
if (c == ' ' && (t->i == 0 || t->buffer[t->i - 1] == ' '))
|
||||
return 0;
|
||||
if (c == '#') {
|
||||
t->comment = true;
|
||||
return 0;
|
||||
}
|
||||
if (c == '"')
|
||||
t->string = true;
|
||||
}
|
||||
|
||||
if (c == '\0') {
|
||||
while (t->i > 0 && t->buffer[t->i - 1] == ' ')
|
||||
t->i -= 1;
|
||||
}
|
||||
|
||||
if (t->i == sizeof(t->buffer))
|
||||
return -1;
|
||||
|
||||
t->buffer[t->i++] = c;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void rdline_init(rdline_t *t, int fd, const char *filename,
|
||||
int argc, const char *const *argv)
|
||||
{
|
||||
memset(t, 0, sizeof(*t));
|
||||
t->fd = fd;
|
||||
|
||||
t->fp = fdopen(fd, "r");
|
||||
if (t->fp == NULL) {
|
||||
close(fd);
|
||||
goto fail_open;
|
||||
}
|
||||
|
||||
t->filename = filename;
|
||||
t->argc = argc;
|
||||
t->argv = argv;
|
||||
return 0;
|
||||
fail_open:
|
||||
perror(filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int rdline(rdline_t *t)
|
||||
void rdline_cleanup(rdline_t *t)
|
||||
{
|
||||
const char *errstr;
|
||||
int c;
|
||||
retry:
|
||||
t->i = 0;
|
||||
t->argstr = NULL;
|
||||
t->string = t->escape = t->comment = false;
|
||||
free(t->line);
|
||||
fclose(t->fp);
|
||||
}
|
||||
|
||||
static int read_raw_line(rdline_t *t)
|
||||
{
|
||||
size_t len = 0;
|
||||
|
||||
free(t->line);
|
||||
t->line = NULL;
|
||||
|
||||
errno = 0;
|
||||
|
||||
if (getline(&t->line, &len, t->fp) < 0) {
|
||||
if (errno) {
|
||||
fprintf(stderr, "%s: %zu: %s\n", t->filename,
|
||||
t->lineno, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
t->lineno += 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int normalize_line(rdline_t *t)
|
||||
{
|
||||
char *dst = t->line, *src = t->line;
|
||||
bool string = false;
|
||||
const char *errstr;
|
||||
int c, ret = 0;
|
||||
|
||||
while (isspace(*src))
|
||||
++src;
|
||||
|
||||
do {
|
||||
errno = 0;
|
||||
c = rdline_getc(t);
|
||||
if (c < 0) {
|
||||
if (errno == 0)
|
||||
return 1;
|
||||
errstr = strerror(errno);
|
||||
goto fail;
|
||||
}
|
||||
if (c == 0 && t->string) {
|
||||
errstr = "missing \"";
|
||||
goto fail;
|
||||
}
|
||||
c = *(src++);
|
||||
|
||||
if (c == '%') {
|
||||
c = rdline_getc(t);
|
||||
if (c == 0) {
|
||||
errstr = "unexpected end of line after '%%'";
|
||||
goto fail;
|
||||
}
|
||||
if (c < 0) {
|
||||
errstr = strerror(errno);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (c != '%') {
|
||||
if (!isdigit(c)) {
|
||||
errstr = "exptected digit after '%%'";
|
||||
goto fail;
|
||||
}
|
||||
if (c == '"') {
|
||||
string = !string;
|
||||
} else if (!string && c == '#') {
|
||||
c = '\0';
|
||||
} else if (!string && isspace(c)) {
|
||||
if (*src == '#' || *src == '\0' || isspace(*src))
|
||||
continue;
|
||||
c = ' ';
|
||||
} else if (c == '%') {
|
||||
*(dst++) = c;
|
||||
c = *(src++);
|
||||
if (isdigit(c)) {
|
||||
if ((c - '0') >= t->argc) {
|
||||
errstr = "argument out of range";
|
||||
goto fail;
|
||||
}
|
||||
if (t->argstr != NULL) {
|
||||
errstr = "recursive argument "
|
||||
"expansion";
|
||||
goto fail;
|
||||
}
|
||||
t->argstr = t->argv[c - '0'];
|
||||
continue;
|
||||
ret += strlen(t->argv[c - '0']);
|
||||
} else if (c != '%') {
|
||||
errstr = "expected digit after '%%'";
|
||||
goto fail;
|
||||
}
|
||||
} else if (string && c == '\\' && *src != '\0') {
|
||||
*(dst++) = c;
|
||||
c = *(src++);
|
||||
}
|
||||
|
||||
if (rdline_append(t, c)) {
|
||||
errstr = "line too long";
|
||||
goto fail;
|
||||
}
|
||||
*(dst++) = c;
|
||||
} while (c != '\0');
|
||||
|
||||
if (t->buffer[0] == '\0')
|
||||
goto retry;
|
||||
|
||||
return 0;
|
||||
if (string) {
|
||||
errstr = "missing \"";
|
||||
goto fail;
|
||||
}
|
||||
return ret;
|
||||
fail:
|
||||
fprintf(stderr, "%s: %zu: %s\n", t->filename, t->lineno, errstr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void substitute(rdline_t *t, char *dst, char *src)
|
||||
{
|
||||
bool string = false;
|
||||
|
||||
while (*src != '\0') {
|
||||
if (src[0] == '%' && isdigit(src[1])) {
|
||||
strcpy(dst, t->argv[src[1] - '0']);
|
||||
dst += strlen(dst);
|
||||
src += 2;
|
||||
} else if (src[0] == '%' && src[1] == '%') {
|
||||
*(dst++) = '%';
|
||||
src += 2;
|
||||
} else {
|
||||
if (*src == '"')
|
||||
string = !string;
|
||||
if (string && *src == '\\')
|
||||
*(dst++) = *(src++);
|
||||
*(dst++) = *(src++);
|
||||
}
|
||||
}
|
||||
|
||||
*(dst++) = '\0';
|
||||
}
|
||||
|
||||
int rdline(rdline_t *t)
|
||||
{
|
||||
char *buffer = NULL;
|
||||
int ret;
|
||||
|
||||
do {
|
||||
if ((ret = read_raw_line(t)))
|
||||
goto out;
|
||||
if ((ret = normalize_line(t)) < 0)
|
||||
goto out;
|
||||
} while (t->line[0] == '\0');
|
||||
|
||||
if (ret == 0) {
|
||||
substitute(t, t->line, t->line);
|
||||
return 0;
|
||||
}
|
||||
|
||||
buffer = calloc(1, strlen(t->line) + ret + 1);
|
||||
if (buffer == NULL) {
|
||||
fprintf(stderr, "%s: %zu: out of memory\n",
|
||||
t->filename, t->lineno);
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
substitute(t, buffer, t->line);
|
||||
ret = 0;
|
||||
out:
|
||||
free(t->line);
|
||||
t->line = buffer;
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "libcfg.h"
|
||||
|
||||
int splitkv(rdline_t *rd, char **k, char **v)
|
||||
{
|
||||
char *key = rd->buffer, *value = rd->buffer;
|
||||
|
||||
while (*value != ' ' && *value != '\0') {
|
||||
if (!isalpha(*value)) {
|
||||
fprintf(stderr,
|
||||
"%s: %zu: unexpected '%c' in keyword\n",
|
||||
rd->filename, rd->lineno, *value);
|
||||
return -1;
|
||||
}
|
||||
++value;
|
||||
}
|
||||
|
||||
if (*value != ' ') {
|
||||
fprintf(stderr, "%s: %zu: expected argument after '%s'\n",
|
||||
rd->filename, rd->lineno, key);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*(value++) = '\0';
|
||||
|
||||
*k = key;
|
||||
*v = value;
|
||||
return 0;
|
||||
}
|
|
@ -1,20 +1,4 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* SPDX-License-Identifier: ISC */
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "service.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int setup_tty(const char *tty, bool truncate)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (tty == NULL)
|
||||
return 0;
|
||||
|
||||
fd = open(tty, O_RDWR);
|
||||
if (fd < 0) {
|
||||
perror(tty);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (truncate)
|
||||
ftruncate(fd, 0);
|
||||
|
||||
close(STDIN_FILENO);
|
||||
close(STDOUT_FILENO);
|
||||
close(STDERR_FILENO);
|
||||
|
||||
setsid();
|
||||
|
||||
dup2(fd, STDIN_FILENO);
|
||||
dup2(fd, STDOUT_FILENO);
|
||||
dup2(fd, STDERR_FILENO);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void argv_exec(exec_t *e)
|
||||
{
|
||||
char **argv = alloca(e->argc + 1), *ptr;
|
||||
int i;
|
||||
|
||||
for (ptr = e->args, i = 0; i < e->argc; ++i, ptr += strlen(ptr) + 1)
|
||||
argv[i] = ptr;
|
||||
|
||||
argv[i] = NULL;
|
||||
execvp(argv[0], argv);
|
||||
perror(argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "service.h"
|
||||
|
||||
void del_svc_list(service_list_t *list)
|
||||
{
|
||||
service_t *svc;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < TGT_MAX; ++i) {
|
||||
while (list->targets[i] != NULL) {
|
||||
svc = list->targets[i];
|
||||
list->targets[i] = svc->next;
|
||||
|
||||
delsvc(svc);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "service.h"
|
||||
|
||||
void delsvc(service_t *svc)
|
||||
{
|
||||
exec_t *e;
|
||||
|
||||
if (svc == NULL)
|
||||
return;
|
||||
|
||||
while (svc->exec != NULL) {
|
||||
e = svc->exec;
|
||||
svc->exec = e->next;
|
||||
|
||||
free(e);
|
||||
}
|
||||
|
||||
free(svc->before);
|
||||
free(svc->after);
|
||||
free(svc->fname);
|
||||
free(svc->desc);
|
||||
free(svc->exec);
|
||||
free(svc->ctty);
|
||||
free(svc);
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <string.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
const enum_map_t *enum_by_name(const enum_map_t *map, const char *name)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; map[i].name != NULL; ++i) {
|
||||
if (!strcmp(map[i].name, name))
|
||||
return map + i;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <string.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
const char *enum_to_name(const enum_map_t *map, int value)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; map[i].name != NULL; ++i) {
|
||||
if (map[i].value == value)
|
||||
return map[i].name;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
int mksock(const char *path, int flags)
|
||||
{
|
||||
struct sockaddr_un un;
|
||||
const char *errmsg;
|
||||
int fd, type;
|
||||
|
||||
type = (flags & SOCK_FLAG_DGRAM) ? SOCK_DGRAM : SOCK_STREAM;
|
||||
|
||||
fd = socket(AF_UNIX, type | SOCK_CLOEXEC, 0);
|
||||
if (fd < 0) {
|
||||
perror("socket");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&un, 0, sizeof(un));
|
||||
un.sun_family = AF_UNIX;
|
||||
|
||||
strcpy(un.sun_path, path);
|
||||
|
||||
if (bind(fd, (struct sockaddr *)&un, sizeof(un))) {
|
||||
errmsg ="bind";
|
||||
goto fail_errno;
|
||||
}
|
||||
|
||||
if (flags & SOCK_FLAG_ROOT_ONLY) {
|
||||
if (chown(path, 0, 0)) {
|
||||
errmsg = "chown";
|
||||
goto fail_errno;
|
||||
}
|
||||
|
||||
if (chmod(path, 0770)) {
|
||||
errmsg = "chmod";
|
||||
goto fail_errno;
|
||||
}
|
||||
} else if (flags & SOCK_FLAG_EVERYONE) {
|
||||
if (chmod(path, 0777)) {
|
||||
errmsg = "chmod";
|
||||
goto fail_errno;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(flags & SOCK_FLAG_DGRAM)) {
|
||||
if (listen(fd, 10)) {
|
||||
errmsg = "listen";
|
||||
goto fail_errno;
|
||||
}
|
||||
}
|
||||
|
||||
return fd;
|
||||
fail_errno:
|
||||
fprintf(stderr, "%s: %s: %s\n", path, errmsg, strerror(errno));
|
||||
close(fd);
|
||||
unlink(path);
|
||||
return -1;
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "telinit.h"
|
||||
|
||||
int opensock(void)
|
||||
{
|
||||
struct sockaddr_un un;
|
||||
int fd;
|
||||
|
||||
fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (fd < 0) {
|
||||
perror("socket");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&un, 0, sizeof(un));
|
||||
un.sun_family = AF_UNIX;
|
||||
|
||||
strcpy(un.sun_path, INITSOCK);
|
||||
|
||||
if (connect(fd, (struct sockaddr *)&un, sizeof(un))) {
|
||||
perror("connect: " INITSOCK);
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "util.h"
|
||||
|
||||
#define GPL_URL "https://gnu.org/licenses/gpl.html"
|
||||
|
||||
static const char *version_string =
|
||||
"%s (pygos init) " PACKAGE_VERSION "\n"
|
||||
"Copyright (C) 2018 David Oberhollenzer\n\n"
|
||||
"License GPLv3+: GNU GPL version 3 or later <" GPL_URL ">.\n"
|
||||
"This is free software: you are free to change and redistribute it.\n"
|
||||
"There is NO WARRANTY, to the extent permitted by law.\n";
|
||||
|
||||
void print_version(const char *program)
|
||||
{
|
||||
fprintf(stdout, version_string, program);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "service.h"
|
||||
#include "util.h"
|
||||
|
||||
static const enum_map_t type_map[] = {
|
||||
{ "once", SVC_ONCE },
|
||||
{ "wait", SVC_WAIT },
|
||||
{ "respawn", SVC_RESPAWN },
|
||||
{ NULL, 0 },
|
||||
};
|
||||
|
||||
static const enum_map_t target_map[] = {
|
||||
{ "boot", TGT_BOOT },
|
||||
{ "shutdown", TGT_SHUTDOWN },
|
||||
{ "reboot", TGT_REBOOT },
|
||||
{ NULL, 0 },
|
||||
};
|
||||
|
||||
const char *svc_type_to_string(int type)
|
||||
{
|
||||
return enum_to_name(type_map, type);
|
||||
}
|
||||
|
||||
int svc_type_from_string(const char *type)
|
||||
{
|
||||
const enum_map_t *ent = enum_by_name(type_map, type);
|
||||
|
||||
return ent == NULL ? -1 : ent->value;
|
||||
}
|
||||
|
||||
const char *svc_target_to_string(int target)
|
||||
{
|
||||
return enum_to_name(target_map, target);
|
||||
}
|
||||
|
||||
int svc_target_from_string(const char *target)
|
||||
{
|
||||
const enum_map_t *ent = enum_by_name(target_map, target);
|
||||
|
||||
return ent == NULL ? -1 : ent->value;
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
#!/bin/sh -uef
|
||||
|
||||
# A small helper script taken from mtd-utils to generate a release tar ball.
|
||||
|
||||
fatal() {
|
||||
printf "Error: %s\n" "$1" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: ${0##*/} <new_ver> <outdir>
|
||||
|
||||
<new_ver> - mtd utils version to create in X.Y[.Z[-rcX]] format
|
||||
<outdir> - the output directory where to store the tarball
|
||||
EOF
|
||||
exit 0
|
||||
}
|
||||
|
||||
[ $# -eq 0 ] && usage
|
||||
[ $# -eq 2 ] || fatal "Insufficient or too many argumetns"
|
||||
|
||||
new_ver="$1"
|
||||
outdir="$2"
|
||||
|
||||
release_name="init-$new_ver"
|
||||
tag_name="v$new_ver"
|
||||
|
||||
# Make sure the input is sane and the makefile contains sensible version
|
||||
VER_REGEX="[0-9]\+.[0-9]\+\(.[0-9]\+\)\?\(-rc[0-9]\+\)\?"
|
||||
|
||||
echo "$new_ver" | grep -q -x "$VER_REGEX" ||
|
||||
fatal "please, provide new version in X.Y[.Z][-rcX] format"
|
||||
|
||||
grep -q -x "m4_define(\[RELEASE\], $VER_REGEX)" configure.ac ||
|
||||
fatal "configure.ac does not contain a valid version string"
|
||||
|
||||
# Make sure the git index is up-to-date
|
||||
[ -z "$(git status --porcelain)" ] || fatal "Git index is not up-to-date"
|
||||
|
||||
# Make sure the tag does not exist
|
||||
[ -z "$(git tag -l "$tag_name")" ] || fatal "Tag $tag_name already exists"
|
||||
|
||||
# Change the version in the configure.ac
|
||||
sed -i -e "s/^m4_define(\[RELEASE\], $VER_REGEX)/m4_define([RELEASE], $new_ver)/" configure.ac
|
||||
|
||||
# And commit the change
|
||||
git commit -m "Release $release_name" configure.ac
|
||||
|
||||
# Create new tag
|
||||
echo "Signing tag $tag_name"
|
||||
git tag -m "$release_name" "$tag_name"
|
||||
|
||||
# Prepare tarball
|
||||
./autogen.sh
|
||||
./configure
|
||||
make distcheck
|
||||
mkdir -p "$outdir"
|
||||
mv "$release_name.tar.xz" "$outdir"
|
|
@ -1,13 +0,0 @@
|
|||
#
|
||||
# Interface renaming rules
|
||||
#
|
||||
# Format: NAME,MAC,NEWNAME
|
||||
#
|
||||
# NAME and MAC are shell glob patterns. Both must match for a rule to apply.
|
||||
# The first matching rule is chosen (top to bottom).
|
||||
#
|
||||
# Interfaces with the same NEWNAME are sorted by MAC and have a running
|
||||
# index appended to their new name.
|
||||
#
|
||||
# Example: rename all ethernet interfaces to "port<X>"
|
||||
# eth*,*,port
|
|
@ -1,5 +0,0 @@
|
|||
helper_SCRIPTS += scripts/devfs.sh scripts/trymount.sh scripts/ifrename.sh
|
||||
helper_SCRIPTS += scripts/ifcfg.sh scripts/ifdown.sh scripts/modules_load.sh
|
||||
helper_SCRIPTS += scripts/setntpdate.sh
|
||||
|
||||
EXTRA_DIST += scripts/trymount.sh scripts/ifdown.sh scripts/setntpdate.sh
|
|
@ -1,21 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
mount -t devtmpfs none /dev
|
||||
|
||||
[ -c /dev/console ] || mknod -m 600 /dev/console c 5 1
|
||||
[ -c /dev/tty ] || mknod -m 666 /dev/tty c 5 0
|
||||
[ -c /dev/null ] || mknod -m 666 /dev/null c 1 3
|
||||
[ -c /dev/kmsg ] || mknod -m 660 /dev/kmsg c 1 11
|
||||
[ -e /dev/fd ] || ln -snf /proc/self/fd /dev/fd
|
||||
[ -e /dev/stdin ] || ln -snf /proc/self/fd/0 /dev/stdin
|
||||
[ -e /dev/stdout ] || ln -snf /proc/self/fd/1 /dev/stdout
|
||||
[ -e /dev/stderr ] || ln -snf /proc/self/fd/2 /dev/stderr
|
||||
[ -e /proc/kcore ] && ln -snf /proc/kcore /dev/core
|
||||
|
||||
mkdir -p /dev/mqueue -m 1777
|
||||
mkdir -p /dev/pts -m 0755
|
||||
mkdir -p /dev/shm -m 1777
|
||||
|
||||
@SCRIPTDIR@/trymount.sh "/dev/mqueue" "mqueue" "noexec,nosuid,nodev"
|
||||
@SCRIPTDIR@/trymount.sh "/dev/pts" "devpts" "noexec,nosuid,gid=5,mode=0620"
|
||||
@SCRIPTDIR@/trymount.sh "/dev/shm" "tmpfs" "noexec,nosuid,nodev,mode=1777"
|
|
@ -1,89 +0,0 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#
|
||||
# Copyright (C) 2018 - David Oberhollenzer
|
||||
#
|
||||
# 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
CFGPATH="@ETCPATH@/netcfg"
|
||||
|
||||
[ -d "$CFGPATH" ] || exit 0
|
||||
|
||||
# configure interfaces
|
||||
for IFPATH in /sys/class/net/*; do
|
||||
[ "$IFPATH" == "/sys/class/net/lo" ] && continue
|
||||
|
||||
IF=`basename $IFPATH`
|
||||
CFGFILE="$CFGPATH/$IF"
|
||||
|
||||
[ -f "$CFGFILE" ] || continue
|
||||
|
||||
ip link set dev "$IF" down
|
||||
|
||||
while read LINE;
|
||||
do
|
||||
trimmed=`echo -- $LINE`
|
||||
[ ! -z "$trimmed" ] || continue
|
||||
set $trimmed
|
||||
|
||||
case "$1" in
|
||||
address|addr|ip|ip6|ipv6)
|
||||
shift
|
||||
ip address add $@ dev "$IF"
|
||||
;;
|
||||
arp|multicast|mtu)
|
||||
ip link set dev "$IF" $@
|
||||
;;
|
||||
offload)
|
||||
shift
|
||||
ethtool -K "$IF" $@
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
done < "$CFGFILE"
|
||||
done
|
||||
|
||||
# configure static routs
|
||||
if [ -f "$CFGPATH/routes" ]; then
|
||||
while read LINE;
|
||||
do
|
||||
trimmed=`echo -- $LINE`
|
||||
[ ! -z "$trimmed" ] || continue
|
||||
set $trimmed
|
||||
|
||||
case "$1" in
|
||||
route)
|
||||
shift
|
||||
ip route add $@
|
||||
;;
|
||||
rule)
|
||||
shift
|
||||
ip rule add $@
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
done < "$CFGFILE"
|
||||
fi
|
||||
|
||||
# activate interfaces
|
||||
for IFPATH in /sys/class/net/*; do
|
||||
[ "$IFPATH" == "/sys/class/net/lo" ] && continue
|
||||
|
||||
IF=`basename $IFPATH`
|
||||
|
||||
[ ! -f "$CFGPATH/$IF" ] || ip link set dev "$IF" up
|
||||
done
|
|
@ -1,26 +0,0 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#
|
||||
# Copyright (C) 2018 - David Oberhollenzer
|
||||
#
|
||||
# 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
for IFPATH in /sys/class/net/*; do
|
||||
[ "$IFPATH" == "/sys/class/net/lo" ] && continue
|
||||
|
||||
IF=`basename $IFPATH`
|
||||
|
||||
ip link set dev "$IF" down
|
||||
done
|
|
@ -1,65 +0,0 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#
|
||||
# Copyright (C) 2018 - David Oberhollenzer
|
||||
#
|
||||
# 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
NAMERULES="@ETCPATH@/netcfg/ifrename"
|
||||
TMPPATH="/tmp/ifrename"
|
||||
|
||||
[ -f "$NAMERULES" ] || exit 0
|
||||
|
||||
mkdir -p "$TMPPATH"
|
||||
|
||||
for IFPATH in /sys/class/net/*; do
|
||||
[ "$IFPATH" == "/sys/class/net/lo" ] && continue
|
||||
|
||||
IF=`basename $IFPATH`
|
||||
MAC=`cat $IFPATH/address`
|
||||
|
||||
grep "^[^,]\+,[^,]\+,[a-zA-Z0-9]\+$" $NAMERULES | while read LINE;
|
||||
do
|
||||
NAMECMP=$(echo $LINE | cut -d',' -f1)
|
||||
ADDRCMP=$(echo $LINE | cut -d',' -f2)
|
||||
RULE=$(echo $LINE | cut -d',' -f3)
|
||||
|
||||
case $IF in ($NAMECMP) ;; *) continue;; esac
|
||||
case $MAC in ($ADDRCMP) ;; *) continue;; esac
|
||||
|
||||
echo "$MAC,$IF" >> "$TMPPATH/$RULE"
|
||||
break
|
||||
done
|
||||
done
|
||||
|
||||
for FNAME in $TMPPATH/*; do
|
||||
[ ! -f "$FNAME" ] && break
|
||||
|
||||
IDX=0
|
||||
PREFIX=$(basename $FNAME)
|
||||
|
||||
sort -t',' -k1 -u $FNAME | while read LINE;
|
||||
do
|
||||
OLDNAME=$(echo $LINE | cut -d',' -f2)
|
||||
NEWNAME="$PREFIX$IDX"
|
||||
IDX=`expr $IDX + 1`
|
||||
|
||||
ip link set "$OLDNAME" name "$NEWNAME"
|
||||
done
|
||||
|
||||
rm "$FNAME"
|
||||
done
|
||||
|
||||
rmdir "$TMPPATH"
|
|
@ -1,39 +0,0 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#
|
||||
# Copyright (C) 2018 - David Oberhollenzer
|
||||
#
|
||||
# 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
MODLIST="@ETCPATH@/modules"
|
||||
|
||||
if [ ! -f "$MODLIST" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
while read LINE;
|
||||
do
|
||||
trimmed=`echo -- $LINE`
|
||||
[ ! -z "$trimmed" ] || continue
|
||||
set $trimmed
|
||||
|
||||
case "$1" in
|
||||
\#*)
|
||||
;;
|
||||
*)
|
||||
modprobe "$1"
|
||||
;;
|
||||
esac
|
||||
done < "$MODLIST"
|
|
@ -1,67 +0,0 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#
|
||||
# Copyright (C) 2018 - David Oberhollenzer
|
||||
#
|
||||
# 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 3 of the License, 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, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
resolve() {
|
||||
local domain="$1"
|
||||
local server="$2"
|
||||
|
||||
if [ -x "$(command -v dig)" ]; then
|
||||
if [ -z "$server" ]; then
|
||||
dig +short "$domain"
|
||||
else
|
||||
dig +short "@$server" "$domain"
|
||||
fi
|
||||
return $?
|
||||
fi
|
||||
|
||||
if [ -x "$(command -v drill)" ]; then
|
||||
if [ -z "$server" ]; then
|
||||
drill "$domain" | grep "^${domain}." | cut -d$'\t' -f5
|
||||
else
|
||||
drill "@$server" "$domain" | grep "^${domain}." |\
|
||||
cut -d$'\t' -f5
|
||||
fi
|
||||
return $?
|
||||
fi
|
||||
exit 1
|
||||
}
|
||||
|
||||
try_update() {
|
||||
while read ip; do
|
||||
if ntpdate -bu "$ip"; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
pool="pool.ntp.org"
|
||||
dns="1.1.1.1"
|
||||
|
||||
# try default DNS server first
|
||||
resolve "$pool" "" | try_update
|
||||
[ $? -eq 0 ] && exit 0
|
||||
|
||||
# try fallback public dns server
|
||||
ping -q -c 1 "$dns" || exit 1
|
||||
|
||||
resolve "$pool" "$dns" | try_update
|
||||
exit $?
|
|
@ -1,7 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
if [ -d "$1" ]; then
|
||||
if grep -qsE "[[:space:]]+$2$" "/proc/filesystems"; then
|
||||
mount -n -t "$2" -o "$3" "$2" "$1"
|
||||
fi
|
||||
fi
|
|
@ -1,35 +0,0 @@
|
|||
initdir = @TEMPLATEDIR@
|
||||
init_DATA = services/agetty services/hostname services/loopback
|
||||
init_DATA += services/sysctl services/hwclock services/sysinit
|
||||
init_DATA += services/sigterm services/sync services/devfs
|
||||
init_DATA += services/sysfs services/procfs services/tmpfs
|
||||
init_DATA += services/vfs services/ifrename services/ifcfg
|
||||
init_DATA += services/dhcpcd services/dhcpcdmaster services/unbound
|
||||
init_DATA += services/dnsmasq services/ifdown services/modules
|
||||
init_DATA += services/network services/hostapd services/swclock
|
||||
init_DATA += services/swclocksave services/nft services/sigkill
|
||||
init_DATA += services/sshd services/sshd_keygen services/consolefont
|
||||
init_DATA += services/nginx
|
||||
|
||||
if GCROND
|
||||
init_DATA += services/swclocksave.gcron
|
||||
endif
|
||||
|
||||
if USYSLOGD
|
||||
init_DATA += services/usyslogd
|
||||
endif
|
||||
|
||||
if USYSLOGD
|
||||
init_DATA += services/klogd
|
||||
endif
|
||||
|
||||
if GCROND
|
||||
init_DATA += services/gcrond
|
||||
endif
|
||||
|
||||
EXTRA_DIST += services/sysinit services/vfs services/agetty services/hostname
|
||||
EXTRA_DIST += services/hwclock services/loopback services/klogd
|
||||
EXTRA_DIST += services/sync services/sysctl services/tmpfs
|
||||
EXTRA_DIST += services/dhcpcd services/dhcpcdmaster services/unbound
|
||||
EXTRA_DIST += services/usyslogd services/dnsmasq services/network
|
||||
EXTRA_DIST += services/consolefont services/gcrond services/nginx
|
|
@ -1,6 +0,0 @@
|
|||
description agetty on %0
|
||||
exec agetty %0 linux
|
||||
type respawn
|
||||
target boot
|
||||
after network
|
||||
tty "/dev/%0"
|
|
@ -1,6 +0,0 @@
|
|||
description set console font
|
||||
type once
|
||||
target boot
|
||||
before sysinit
|
||||
after vfs
|
||||
exec setfont %0
|
|
@ -1,6 +0,0 @@
|
|||
description "mount /dev"
|
||||
type wait
|
||||
target boot
|
||||
after procfs sysfs
|
||||
before vfs
|
||||
exec "@SCRIPTDIR@/devfs.sh"
|
|
@ -1,7 +0,0 @@
|
|||
description "DHCP client on %0"
|
||||
type once
|
||||
target boot
|
||||
after dhcpcdmaster network
|
||||
|
||||
tty /dev/null
|
||||
exec dhcpcd -n %0
|
|
@ -1,10 +0,0 @@
|
|||
description "DHCP client - master service"
|
||||
type wait
|
||||
target boot
|
||||
after network
|
||||
tty /dev/null
|
||||
|
||||
exec {
|
||||
mkdir -p /var/db/dhcpcd
|
||||
dhcpcd --inactive
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
description "dnsmasq DNS & DHCP server"
|
||||
type respawn limit 5
|
||||
target boot
|
||||
after network unbound
|
||||
|
||||
exec dnsmasq -k
|
|
@ -1,5 +0,0 @@
|
|||
description start gcron daemon
|
||||
exec gcrond
|
||||
type respawn
|
||||
target boot
|
||||
after network
|
|
@ -1,7 +0,0 @@
|
|||
description "WIFI access point daemon"
|
||||
type respawn limit 10
|
||||
target boot
|
||||
after sysinit ifrename
|
||||
before network ifcfg
|
||||
|
||||
exec hostapd "@ETCPATH@/hostapd.conf"
|
|
@ -1,6 +0,0 @@
|
|||
description reload hostname
|
||||
exec hostname --file /etc/hostname
|
||||
type wait
|
||||
target boot
|
||||
before sysinit
|
||||
after hwclock vfs
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue