Compare commits

..

34 Commits
0.39 ... 0.40.1

Author SHA1 Message Date
William Hubbs
cefae65392 Update ChangeLog 2018-12-04 17:27:46 -06:00
Alexander Zubkov
69fbd12993 supervise-daemon: redirect std{in,out,err} to /dev/null after demonizing
This fixes #239.
2018-12-04 17:23:27 -06:00
William Hubbs
4aa5686d90 version 0.40.1 2018-12-04 17:21:55 -06:00
William Hubbs
ab6c8d56f1 Update ChangeLog 2018-12-03 15:56:19 -06:00
Austin English
fb4dd351c7 misc: make checks always fatal
This fixes #263.
2018-12-03 15:26:42 -06:00
Austin English
10dc65cc46 src/rc/supervise-daemon.c: fix style issue
This is for #263.
2018-12-03 15:26:20 -06:00
William Hubbs
9a2115f762 rc-status: show status for supervised services instead of a list 2018-12-03 15:16:17 -06:00
William Hubbs
eeba6df476 Update supervise-daemon man page 2018-12-03 13:08:25 -06:00
William Hubbs
ac42e81a64 supervise-daemon.sh: drop the unused stopsig variable 2018-12-03 12:43:12 -06:00
William Hubbs
af70862a7a supervise-daemon: use a default pid file if one is not specified
Since the pid file is internal to us, start moving toward deprecating it
by not requiring the user to specify it.
In the next release, I plan on working on code to start phasing out the
use of a pid file if this is possible.
2018-12-03 12:41:29 -06:00
William Hubbs
fa6611b5af rc-status: add --supervised option to show supervised services 2018-12-02 18:33:25 -06:00
William Hubbs
db01442580 rc-status: show failed services as failed 2018-12-02 18:33:25 -06:00
William Hubbs
ebf79db79e supervise-daemon: mark a service failed if it respawns too many times 2018-12-02 18:33:25 -06:00
William Hubbs
1b5a3b4ef4 supervise-daemon: make respawn-max and respawn-period independent settings 2018-12-02 18:33:25 -06:00
William Hubbs
77262c359c supervise-daemon: add support for a fifo
This will allow us to signal the daemon we are supervising as well as
send other commands to the supervisor in the future.

This fixes #227.
2018-12-02 18:33:25 -06:00
William Hubbs
7f23e0461d supervise-daemon: rework signal handling and main loop
This is needed in preparation for adding support for a fifo to allow us
to communicate with the supervisor to ask it to signal the child it is
supervising.
2018-12-02 18:33:25 -06:00
William Hubbs
ff4af908a5 Revert "checkpath: use O_PATH when available"
This reverts commit 2af0cedd59.

After speaking with Luis Ressel on the Gentoo selinux team, I am reverting
this commit for the following reasons:

- Luis told me that he feels this is not the solution we need to address
  the concern with checkpath; I will be working with him on another
  solution.

- There are concerns about the way the path variable was handled
  and the assert() call.
  The path variable should be dynamically allocated using xasprintf
  instead of defining a length at compile time. This would eliminate the
  need for the assert() call.

- It introduces the definition of _GNU_SOURCE which makes it
  easier to introduce portability concerns in the future (see #262).
2018-12-02 16:08:42 -06:00
Mike Gilbert
2af0cedd59 checkpath: use O_PATH when available
This avoids opening directories/files with read permission, which is
sometimes rejected by selinux policy.

Bug: https://bugs.gentoo.org/667122
2018-12-01 21:43:18 -08:00
William Hubbs
ee41e444ad rc.conf: typo fix
X-Gentoo-Bug: 670874
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=670874
2018-11-29 08:19:56 -06:00
William Hubbs
b7828651ba supervise-daemon: fix type of exiting flag 2018-11-28 16:06:07 -06:00
Austin English
e96f7d5658 src/tests/runtests.sh: add a FATAL_CHECKS variable to make whitespace/etc. fatal 2018-11-27 21:22:29 -05:00
Austin English
28b73fc524 src/rc/openrc-shutdown.c: fix style 2018-11-27 21:22:29 -05:00
Austin English
7a00c63420 fix misc whitespace issues 2018-11-27 21:22:29 -05:00
Austin English
f4597c546a give TravisCI a try 2018-11-27 21:22:29 -05:00
Austin English
e10afc8e75 sh/functions.sh.in: return a different value for invalid input in yesno() 2018-11-18 13:22:59 -05:00
William Hubbs
0f704402a2 supervise-daemon: make the pidfile an implementation detail
The pidfile of the supervisor doesn't need to be adjustable by the
service script. It is only used so the supervisor can stop itself when
the --stop option is used.
2018-11-15 14:15:15 -06:00
William Hubbs
2504a2c25b Do not complain if interrupted by a signal
In start-stop-daemon and rc-schedules, we were printing out a warning if
the nanosleep call was interrupted by a signal, but we did not treat
this as an error situation other than displaying the message, so there
is no need for the message.
2018-11-15 14:03:06 -06:00
William Hubbs
7eb3975543 Create save-keymaps and save-ktermencoding services
These services represent the parts of the keymaps and termencoding
services which saved the settings back to the root file system so they
can be loaded very early in the boot process.
These are needed to allow keymaps and termencoding to run earlier in the
boot sequence.

X-Gentoo-Bug: 446018
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=446018
2018-11-07 08:55:44 -06:00
William Hubbs
60e60dc9bb supervise-daemon.sh: drop invalid --signal switch
This fixes #230.
2018-11-06 10:54:02 -06:00
William Hubbs
008c9d0036 supervise-daemon: reap zombies
We need to make sure to reap zombies so that we can shut down
successfully.

Fixes #252.
Possibly related to #250.
2018-11-05 21:35:00 -06:00
William Hubbs
025c9693cc rc-service: fix help output 2018-11-05 11:39:39 -06:00
William Hubbs
ee3c4afdb7 openrc-init: add SELinux support
This is for #173.
2018-11-02 18:22:11 -05:00
William Hubbs
e2416d0893 openrc-shutdown: do not require a time for -w switch
X-Gentoo-Bug: 669500
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=669500
2018-10-24 15:24:40 -05:00
William Hubbs
a2bcfeb428 version 0.40 2018-10-24 15:18:10 -05:00
28 changed files with 689 additions and 501 deletions

14
.travis.yml Normal file
View File

@@ -0,0 +1,14 @@
# Travis build integration.
# https://docs.travis-ci.com/
language: c
os:
- linux
compiler:
- gcc
- clang
script:
- ./test/travis.sh

580
ChangeLog
View File

@@ -1,3 +1,284 @@
commit 69fbd129938522cdd9b82fea2b83c857796a32af
Author: Alexander Zubkov <green@msu.ru>
Commit: William Hubbs <w.d.hubbs@gmail.com>
supervise-daemon: redirect std{in,out,err} to /dev/null after demonizing
This fixes #239.
commit 4aa5686d9037132b27d7554436738fa98e8e9057
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
version 0.40.1
commit ab6c8d56f155564f56d61553c4b1af9e7f63a9d2
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
Update ChangeLog
commit fb4dd351c7ef2614076309d630e163ff963ac8bf
Author: Austin English <austinenglish@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
misc: make checks always fatal
This fixes #263.
commit 10dc65cc46e4f16f1b1f9822f3b687f2e58e4b40
Author: Austin English <austinenglish@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
src/rc/supervise-daemon.c: fix style issue
This is for #263.
commit 9a2115f7620b33e03592fb1eabe5a613984a9894
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
rc-status: show status for supervised services instead of a list
commit eeba6df4761777be5af7f9a2876223155921ee37
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
Update supervise-daemon man page
commit ac42e81a6419b281ed3f62900e29a5a802106dce
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
supervise-daemon.sh: drop the unused stopsig variable
commit af70862a7a115d6269affca663423e9340d6e929
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
supervise-daemon: use a default pid file if one is not specified
Since the pid file is internal to us, start moving toward deprecating it
by not requiring the user to specify it.
In the next release, I plan on working on code to start phasing out the
use of a pid file if this is possible.
commit fa6611b5af94548e901e587fcd36f4fb59124975
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
rc-status: add --supervised option to show supervised services
commit db01442580847d36f232527200e50091431c32b5
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
rc-status: show failed services as failed
commit ebf79db79eaa2df0ceb62b4edbef94e68a28b612
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
supervise-daemon: mark a service failed if it respawns too many times
commit 1b5a3b4ef4b2c3e20cfe4a71cf38c63279ed42d2
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
supervise-daemon: make respawn-max and respawn-period independent settings
commit 77262c359c4aaf15ba00b07cd51f3987ce514769
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
supervise-daemon: add support for a fifo
This will allow us to signal the daemon we are supervising as well as
send other commands to the supervisor in the future.
This fixes #227.
commit 7f23e0461d6c6d24f5cfa39b9e404a7ec9cfd9c1
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
supervise-daemon: rework signal handling and main loop
This is needed in preparation for adding support for a fifo to allow us
to communicate with the supervisor to ask it to signal the child it is
supervising.
commit ff4af908a58eedf9a165946f109f06add23fff9c
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
Revert "checkpath: use O_PATH when available"
This reverts commit 2af0cedd5952d7da71681b7a636dff3540e4295d.
After speaking with Luis Ressel on the Gentoo selinux team, I am reverting
this commit for the following reasons:
- Luis told me that he feels this is not the solution we need to address
the concern with checkpath; I will be working with him on another
solution.
- There are concerns about the way the path variable was handled
and the assert() call.
The path variable should be dynamically allocated using xasprintf
instead of defining a length at compile time. This would eliminate the
need for the assert() call.
- It introduces the definition of _GNU_SOURCE which makes it
easier to introduce portability concerns in the future (see #262).
commit 2af0cedd5952d7da71681b7a636dff3540e4295d
Author: Mike Gilbert <floppym@gentoo.org>
Commit: Mike Frysinger <vapier@gmail.com>
checkpath: use O_PATH when available
This avoids opening directories/files with read permission, which is
sometimes rejected by selinux policy.
Bug: https://bugs.gentoo.org/667122
commit ee41e444ad18192fa34f598464e3ac52f323e27e
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
rc.conf: typo fix
X-Gentoo-Bug: 670874
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=670874
commit b7828651babd20fb6cc11aed91721e103ccbb3e1
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
supervise-daemon: fix type of exiting flag
commit e96f7d5658950ddee68e54fba4b6321b9a6a2ed8
Author: Austin English <austinenglish@gmail.com>
Commit: Mike Frysinger <vapier@gmail.com>
src/tests/runtests.sh: add a FATAL_CHECKS variable to make whitespace/etc. fatal
commit 28b73fc524096d5b2205fea25943410725d6227f
Author: Austin English <austinenglish@gmail.com>
Commit: Mike Frysinger <vapier@gmail.com>
src/rc/openrc-shutdown.c: fix style
commit 7a00c63420f81797b3e0cc402f756b63fe06f7d4
Author: Austin English <austinenglish@gmail.com>
Commit: Mike Frysinger <vapier@gmail.com>
fix misc whitespace issues
commit f4597c546a998085e09880aa6663d1d6ee05fac4
Author: Austin English <austinenglish@gmail.com>
Commit: Mike Frysinger <vapier@gmail.com>
give TravisCI a try
commit e10afc8e757fb914e632e9c40fc6e589e6d47580
Author: Austin English <austinenglish@gmail.com>
Commit: Mike Frysinger <vapier@gmail.com>
sh/functions.sh.in: return a different value for invalid input in yesno()
commit 0f704402a236d385e8b30083ccf9aca327c0a57e
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
supervise-daemon: make the pidfile an implementation detail
The pidfile of the supervisor doesn't need to be adjustable by the
service script. It is only used so the supervisor can stop itself when
the --stop option is used.
commit 2504a2c25bc0587b36d81a2d85c203b20e2d40cf
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
Do not complain if interrupted by a signal
In start-stop-daemon and rc-schedules, we were printing out a warning if
the nanosleep call was interrupted by a signal, but we did not treat
this as an error situation other than displaying the message, so there
is no need for the message.
commit 7eb3975543eafd44c6946ca5a76812aa0d7a7303
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
Create save-keymaps and save-ktermencoding services
These services represent the parts of the keymaps and termencoding
services which saved the settings back to the root file system so they
can be loaded very early in the boot process.
These are needed to allow keymaps and termencoding to run earlier in the
boot sequence.
X-Gentoo-Bug: 446018
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=446018
commit 60e60dc9bbf0e3a18d897861367d9289ae8006d6
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
supervise-daemon.sh: drop invalid --signal switch
This fixes #230.
commit 008c9d0036e348242e323c0b5a66f3724b4a839d
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
supervise-daemon: reap zombies
We need to make sure to reap zombies so that we can shut down
successfully.
Fixes #252.
Possibly related to #250.
commit 025c9693ccab9c6220520ace47aa81553e7ea600
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
rc-service: fix help output
commit ee3c4afdb75b98cd472b7ffbb46adc9d8a1e1b15
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
openrc-init: add SELinux support
This is for #173.
commit e2416d089396e2b9a72cc56ef9f57886ffb0f1c8
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
openrc-shutdown: do not require a time for -w switch
X-Gentoo-Bug: 669500
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=669500
commit a2bcfeb42882b40ca23ddfefca2a17a7988f8082
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
version 0.40
commit 53f7afd3b3daf659d58d6545dc79cd45c4c54277
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
Update ChangeLog
commit 75e9b66f6ff36d06bf1f8bd4824000f9f26106e0
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
@@ -1136,302 +1417,3 @@ Commit: William Hubbs <w.d.hubbs@gmail.com>
add bash completion support
This fixes #188.
commit a2447dfb420cbd97a65cc085404c031d42cb3dfb
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
rc-service: add --ifcrashed option
This works like the other --if options. If the service is crashed, run
the command.
This fixes #154.
commit cee3919908c2d715fd75a796873e3308209a4c2e
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
Clean up the calls to group_add_service
This function should only be called once and it does not take any
arguments.
X-Gentoo-Bug: 639166
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=639166
commit 0feadd2922484ec181c2ab86a5f7f8d6d37c5c77
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
man/openrc-run.8: update documentation for command_user
commit a7c99506d9de81b9a2a7547bd11715073de1ce95
Author: Will Miles <wmiles@sgl.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
Fix repeated dependency cache rebuild if clock skewed
rc_deptree_update_needed would return early as soon as it found
any file newer than the existing dependency cache. Unfortunately,
the first file found may not be the newest one there; so the
clock skew workaround in rc-misc:_rc_deptree_load would be given
a timestamp that was still too old.
This fix forces a full scan of all relevant files, so as to
ensure that we return a timestamp that will allow the clock skew
fix to operate. The runtime cost is no worse than the case where
the cache is up to date (ie. we must check every possible file).
This fixes #161.
commit f0129307759f1a5eb34b72589e8d48790c92b2db
Author: Julien Reichardt <mi@jrei.ch>
Commit: William Hubbs <w.d.hubbs@gmail.com>
man/openrc-run.8: remove white space
This is for #184.
commit ddbdb696582e9fd61995f15d6a3a53055a151e41
Author: Julien Reichardt <mi@jrei.ch>
Commit: William Hubbs <w.d.hubbs@gmail.com>
add more variables for start-stop-daemon and supervise-daemon options
Add the following variables to expose more arguments that can be passed
to start-stop-daemon or supervise-daemon:
- directory will be passed to --chdir
- error_log will be passed to --stderr
- output_log will be passed to --stdout
- umask will be passed to umask
This is for #184.
commit c84ebb94d19ca856fe064e15d2068d5671e360c9
Author: Doug Freed <dwfreed@mtu.edu>
Commit: GitHub <noreply@github.com>
start-stop-daemon: properly handle missing pidfile
X-Gentoo-Bug: 639218
X-Gentoo-Bug-URL: https://bugs.gentoo.org/639218
commit 3de6395ae3b8780ab501f3cf8688e1cb2a9f0243
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
split cgroups mounting out of sysfs
This is neceessary to allow cgroups to be mounted in an lxc/lxd
container.
Fixes https://github.com/openrc/openrc/issues/187
commit 6bb7ebec483a96e258c64ea3fea18358d7893fee
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
fix FreeBSD build
This is for #186.
commit a192caf88f527e09508e32baa623ef85549612ae
Author: Doug Freed <dwfreed@mtu.edu>
Commit: Doug Freed <dwfreed@mtu.edu>
rc-schedules: if given nothing to look for, stop
This avoids trying to kill everything.
X-Gentoo-Bug: 631958
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=631958
commit e805c74d31113c75058d860588e83bca120decf6
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
s6 supervisor fixes
Add the ability to force-kill a service if it does not go down
successfully. Also, adjust the default wait time for an s6 service to go
down to 60 seconds.
commit 318e87348168e37d78f433d3ff06288ad8ccf15c
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
strongly encourage Linux users to not make /etc/mtab a flat file
The OpenRC team does not currently know of any modern linux tools that
require /etc/mtab to be a flat file, so this puts users on notice that
the mtab service will be removed in the future.
commit 0d15898f58cc254d79777c791d4798a9b2542cf2
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
adjust mtab and localmount dependencies
localmount had mtab in its "use" dependencies; however, it makes more
sense to add "before localmount" to the mtab service and remove
"use mtab" from the localmount service.
commit 971e82784cd1ad8f9a286ee792e6417359972976
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
rc_find_pids: namespace fix
Ignore namespaces if there are errors reading either the pid namespace
for the current process or the process we aare testing.
This fixes https://github.com/openrc/openrc/issues/180.
commit 90d9ea656ff7c6b5d618df4e4261ebfa4033f1a8
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
start-stop-daemon: do not use do_stop to verify whether a daemon is running
X-Gentoo-Bug: 636574
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=636574
commit a3d1c8a0e7d5586be13e2cd9b5029fd729bc1594
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
fix issue with --reexec call
commit 913b2ca53771742385d5c69164aefcaab634f012
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
supervise-daemon: use RC_SVCNAME as the first argument to the daemon
This makes ps show which service the supervisor is monitoring.
commit 3fe99c8b8264269dd935d52a1a52581cc0f14e8e
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
supervise-daemon: fix logging for reexec and the child command line
commit 27b8183de2f2bfd7411c14c1ec28543ca8a36602
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
log as supervise-daemon not the service
commit f32d8e1bfe16caf233d1180921f4aeed77d7476d
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
supervise-daemon: clarify a log message
commit d019f34a83b0ad5e890f685b1263b281ab54ce54
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
supervise-daemon: log the command line we run to spawn the child process
commit bb9c481f02cb1843e00bf32e98caf18b6b56bb4d
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
supervise-daemon: log with the service name instead of "supervise-daemon"
commit 82da844b42ff83b2ebf944198e56ac2d81851897
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
implement "unsupervised" status
The unsupervised status is to be used when a supervisor of a supervised
service dies but leaves the service daemon itself running.
commit 667a09983ca5311824aa88c42d39a495c540fc4c
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
supervise-daemon: remove child_pid from saved options during shutdown
This allows us to detect when the supervisor dies unexpectedly because
in that case child_pid will still exist.
commit cf429ee359356d736c818e8b35db8fca887e7332
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
rc_service_value_set: remove the option if NULL is the value
This allows the equivalent of "unsetting" a value for a service.
commit 6f3e2e2d7de61ab28cf03937ccf2e5f80b62190a
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
supervise-daemon.sh: fix status function with no namespaces
commit 35b88fb42bb8e0a56cdc1947342f1b89c98658bc
Author: Patrick McLean <chutzpah@gentoo.org>
Commit: William Hubbs <w.d.hubbs@gmail.com>
cgroups_cleanup: clean up shutdown signaling
- do not sleep for the full 90 seconds if processes are dead
- re-arrange the order of signals we attempt to send to the processes
commit a428c325a902bba55a849a07a59c0c1567404db2
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
add "unsupervised" status and return code 64 to supervise-daemon status function
This is to be used if the service is being supervised and the
supervisor is somehow killed.
Currently, this is very linux specific, but I will expand to other
platforms, patches are welcome.
commit 3219ecd6085231d7cc1268323a5be6a69f8c9143
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
supervise-daemon: fix build issue for >=glibc-2.26
X-Gentoo-Bug: 635334
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=635334
commit 0d8dc4f798cc0d707fc64e8bffcba4fbceb32935
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
version 0.35
commit f3c70bf5b5aa18e8dc94d4949f05568e0741c5cb
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
Update ChangeLog
commit f5acc66db7d1a0bfad6a40eefc0240b80f52df94
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
rc_find_pids: ignore pids that are not in our pid namespace
X-Gentoo-Bug: 634634
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=634634
commit fdce4769f2e0f4175163ffa181c7b3b2192f7b22
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
supervise-daemon: multiple fixes
- Harden against dying by handling all signals that would terminate the
program and adding --reexec support
- factor the supervisor into its own function
- fix test for whether we are already running

View File

@@ -1,3 +1,3 @@
NAME= openrc
VERSION= 0.39
VERSION= 0.40.1
PKG= ${NAME}-${VERSION}

13
NEWS.md
View File

@@ -4,6 +4,19 @@ OpenRC NEWS
This file will contain a list of notable changes for each release. Note
the information in this file is in reverse order.
## OpenRC 0.40
In this version, the keymaps and termencoding services on Linux needed
to be modified so they do not write to the root file system. This was
done so they can run earlier in the boot sequence. AS a result, you will
need to add save-termencoding and save-keymaps to your boot runlevel.
This can be done as follows:
```
# rc-update add save-keymaps boot
# rc-update add save-termencoding boot
```
## OpenRC 0.39
This version removes the support for addons.

View File

@@ -230,7 +230,7 @@ rc_tty_number=12
# The following setting turns on the memory.use_hierarchy setting in the
# root memory cgroup for cgroups v1.
# It must be set to yes in this file if you want this functionality.
#rc_cggroup_memory_use_hierarchy="NO"
#rc_cgroup_memory_use_hierarchy="NO"
# The following settings allow you to set up values for the cgroups version 1
# controllers for your services.

2
init.d/.gitignore vendored
View File

@@ -41,6 +41,8 @@ rc-enabled
rpcbind
runsvdir
savecore
save-keymaps
save-termencoding
swap-blk
swclock
syslogd

View File

@@ -23,8 +23,8 @@ SRCS-FreeBSD+= adjkerntz.in devd.in dumpon.in encswap.in ipfw.in \
SRCS-Linux= agetty.in binfmt.in devfs.in cgroups.in dmesg.in hwclock.in \
consolefont.in keymaps.in killprocs.in modules.in \
mount-ro.in mtab.in numlock.in procfs.in net-online.in sysfs.in \
termencoding.in
mount-ro.in mtab.in numlock.in procfs.in net-online.in save-keymaps.in \
save-termencoding.in sysfs.in termencoding.in
# Generic BSD scripts
SRCS-NetBSD= hostid.in moused.in newsyslog.in pf.in rarpd.in rc-enabled.in \

View File

@@ -14,7 +14,7 @@ description="Applies a keymap for the consoles."
depend()
{
need termencoding
after bootmisc clock
after devfs
keyword -docker -lxc -openvz -prefix -systemd-nspawn -uml -vserver -xenu
}
@@ -68,10 +68,5 @@ start()
echo "altgr keycode 18 = U+20AC" | loadkeys -q -
eend $?
fi
# Save the keymapping for use immediately at boot
if checkpath -W "$RC_LIBEXECDIR"; then
mkdir -p "$RC_LIBEXECDIR"/console
dumpkeys >"$RC_LIBEXECDIR"/console/keymap
fi
return 0
}

28
init.d/save-keymaps.in Normal file
View File

@@ -0,0 +1,28 @@
#!@SBINDIR@/openrc-run
# Copyright (c) 2018 Sony Interactive Entertainment, Inc.
#
# This file is part of OpenRC. It is subject to the license terms in
# the LICENSE file found in the top-level directory of this
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
# This file may not be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
description="Save the keymap for use as early as possible"
depend()
{
need termencoding
after bootmisc clock keymaps
keyword -docker -lxc -openvz -prefix -systemd-nspawn -uml -vserver -xenu
}
start()
{
# Save the keymapping for use immediately at boot
ebegin "Saving key mapping"
if checkpath -W "$RC_LIBEXECDIR"; then
mkdir -p "$RC_LIBEXECDIR"/console
dumpkeys >"$RC_LIBEXECDIR"/console/keymap
fi
eend $? "Unable to save keymapping"
}

View File

@@ -0,0 +1,35 @@
#!@SBINDIR@/openrc-run
# Copyright (c) 2018 Sony Interactive Entertainment, Inc.
#
# This file is part of OpenRC. It is subject to the license terms in
# the LICENSE file found in the top-level directory of this
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
# This file may not be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
description="Configures terminal encoding."
ttyn=${rc_tty_number:-${RC_TTY_NUMBER:-12}}
: ${unicode:=${UNICODE}}
depend()
{
keyword -docker -lxc -openvz -prefix -systemd-nspawn -uml -vserver -xenu
use root
after bootmisc clock termencoding
}
start()
{
ebegin "Saving terminal encoding"
# Save the encoding for use immediately at boot
if checkpath -W "$RC_LIBEXECDIR"; then
mkdir -p "$RC_LIBEXECDIR"/console
if yesno ${unicode:-${UNICODE}}; then
echo "" > "$RC_LIBEXECDIR"/console/unicode
else
rm -f "$RC_LIBEXECDIR"/console/unicode
fi
fi
eend 0
}

View File

@@ -17,8 +17,7 @@ ttyn=${rc_tty_number:-${RC_TTY_NUMBER:-12}}
depend()
{
keyword -docker -lxc -openvz -prefix -systemd-nspawn -uml -vserver -xenu
use root
after bootmisc clock
after devfs
}
start()

View File

@@ -43,6 +43,8 @@ List all defined runlevels.
Show all manually started services.
.It Fl r , -runlevel
Print the current runlevel name.
.It Fl S , -supervised
Show all supervised services.
.It Fl s , -servicelist
Show all services.
.It Fl u , -unused

View File

@@ -16,6 +16,7 @@
.Nd starts a daemon and restarts it if it crashes
.Sh SYNOPSIS
.Nm
servicename
.Fl a , -healthcheck-timer
.Ar seconds
.Fl A , -healthcheck-delay
@@ -36,8 +37,6 @@
.Ar count
.Fl N , -nicelevel
.Ar level
.Fl p , -pidfile
.Ar pidfile
.Fl P , -respawn-period
.Ar seconds
.Fl R , -retry
@@ -55,10 +54,15 @@
.Op Fl -
.Op Ar arguments
.Nm
servicename
.Fl K , -stop
.Ar daemon
.Fl p , -pidfile
.Ar pidfile
.Fl r , -chroot
.Ar chrootpath
.Nm
servicename
.Fl s , -signal
.Ar signal
.Fl r , -chroot
.Ar chrootpath
.Sh DESCRIPTION
@@ -66,22 +70,15 @@
provides a consistent method of starting, stopping and restarting
daemons. If
.Fl K , -stop
or
.Fl s , -signal
is not provided, then we assume we are starting the daemon.
.Nm
only works with daemons which do not fork. Also, it uses its own pid
file, so the daemon should not write a pid file, or the pid file passed
to
.Nm
should not be the one the daemon writes.
only works with daemons which do not fork. If your daemon has options to
tell it not to fork, it should be configured to not fork.
.Pp
Here are the options to specify the daemon and how it should start or stop:
.Bl -tag -width indent
.It Fl p , -pidfile Ar pidfile
When starting, we write a
.Ar pidfile
so we know which supervisor to stop. When stopping we only stop the pid(s)
listed in the
.Ar pidfile .
.It Fl u , -user Ar user Ns Op : Ns Ar group
Start the daemon as the
.Ar user
@@ -115,16 +112,19 @@ Data can be from 0 to 7 inclusive.
.It Fl k , -umask Ar mode
Set the umask of the daemon.
.It Fl m , -respawn-max Ar count
Sets the maximum number of times a daemon will be respawned during a
respawn period. If a daemon dies more than this number of times during a
respawn period,
Sets the maximum number of times a daemon will be respawned. If a daemon
crashes more than this number of times,
.Nm
will give up trying to respawn it and exit. The default is 10, and 0
means unlimited.
will give up and exit. The default is 10 and 0 means unlimited.
.Pp
If respawn-period is also set, more than respawn-max crashes must occur
during respawn-period seconds to cause
.Nm
to give up and exit.
.It Fl N , -nicelevel Ar level
Modifies the scheduling priority of the daemon.
.It Fl P , -respawn-period Ar seconds
Sets the length of a respawn period. The default is 10 seconds. See the
Sets the length of a respawn period. See the
description of --respawn-max for more information.
.It Fl R , -retry Ar timeout | Ar signal Ns / Ns Ar timeout
The retry specification can be either a timeout in seconds or multiple
@@ -132,7 +132,11 @@ signal/timeout pairs (like SIGTERM/5).
If this option is not given, the default is SIGTERM/5.
.It Fl r , -chroot Ar path
chroot to this directory before starting the daemon. All other paths, such
as the path to the daemon, chdir and pidfile, should be relative to the chroot.
as the path to the daemon and chdir should be relative to the chroot.
.It Fl , -signal Ar signal
Instruct a supervisor to signal the process it is supervising. The
process to communicate with is determined by the name of the service
taken from the RC_SVCNAME environment variable.
.It Fl u , -user Ar user
Start the daemon as the specified user.
.It Fl 1 , -stdout Ar logfile
@@ -145,7 +149,6 @@ The same thing as
.Fl 1 , -stdout
but with the standard error output.
.El
.El
.Sh ENVIRONMENT
.Va SSD_NICELEVEL
can also set the scheduling priority of the daemon, but the command line
@@ -167,15 +170,16 @@ make sure the settings mmake sense. For example, a respawn period of 5
seconds with a respawn max of 10 and a respawn delay of 1 second leads
to infinite respawning since there can never be 10 respawns within 5
seconds.
.Sh NOTE
Invoking supervise-daemon requires both the RC_SVCNAME environment
variable to be set and the name of the service as the first argument on
the command line, so it is best to invoke it inside a service script
rather than manually.
.Sh SEE ALSO
.Xr chdir 2 ,
.Xr chroot 2 ,
.Xr getopt 3 ,
.Xr nice 2 ,
.Xr rc_find_pids 3
.Sh BUGS
.Nm
cannot stop an interpreted daemon that no longer exists without a pidfile.
.Sh HISTORY
.Nm
first appeared in Debian.

View File

@@ -36,7 +36,8 @@ BOOT-FreeBSD+= hostid modules newsyslog savecore syslogd
# FreeBSD specific stuff
BOOT-FreeBSD+= adjkerntz dumpon syscons
BOOT-Linux+= binfmt hwclock keymaps modules mtab procfs termencoding
BOOT-Linux+= binfmt hwclock keymaps modules mtab procfs save-keymaps \
save-termencoding termencoding
SHUTDOWN-Linux= killprocs mount-ro
SYSINIT-Linux= devfs cgroups dmesg sysfs

View File

@@ -46,7 +46,7 @@ yesno()
case "$value" in
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;;
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;;
*) vewarn "\$$1 is not set properly"; return 1;;
*) vewarn "\$$1 is not set properly"; return 2;;
esac
}

View File

@@ -55,11 +55,9 @@ supervise_stop()
local startpidfile="$(service_get_value "pidfile")"
chroot="${startchroot:-$chroot}"
pidfile="${startpidfile:-$pidfile}"
[ -n "$pidfile" ] || return 0
ebegin "Stopping ${name:-$RC_SVCNAME}"
supervise-daemon "${RC_SVCNAME}" --stop \
${pidfile:+--pidfile} $chroot$pidfile \
${stopsig:+--signal} $stopsig
${pidfile:+--pidfile} $chroot$pidfile
eend $? "Failed to stop ${name:-$RC_SVCNAME}"
}

View File

@@ -4,7 +4,7 @@
*/
/*
* Copyright 2018 Sony Interactive Entertainment Inc.
* Copyright 2018 Sony Interactive Entertainment Inc.
*
* This file is part of OpenRC. It is subject to the license terms in
* the LICENSE file found in the top-level directory of this
@@ -153,7 +153,7 @@ void broadcast(char *text)
p = strchr(date, '\n');
if (p)
*p = 0;
xasprintf(&line, "\007\r\nBroadcast message from %s@%s %s(%s):\r\n\r\n",
user, name.nodename, tty, date);
@@ -162,7 +162,7 @@ void broadcast(char *text)
*/
if (fork() != 0)
return;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = handler;
sigemptyset(&sa.sa_mask);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018 Sony Interactive Entertainment Inc.
* Copyright 2018 Sony Interactive Entertainment Inc.
*
* This file is part of OpenRC. It is subject to the license terms in
* the LICENSE file found in the top-level directory of this

View File

@@ -31,6 +31,10 @@
#include <sys/reboot.h>
#include <sys/wait.h>
#ifdef HAVE_SELINUX
# include <selinux/selinux.h>
#endif
#include "helpers.h"
#include "rc.h"
#include "rc-wtmp.h"
@@ -161,10 +165,36 @@ int main(int argc, char **argv)
bool reexec = false;
sigset_t signals;
struct sigaction sa;
#ifdef HAVE_SELINUX
int enforce = 0;
#endif
if (getpid() != 1)
return 1;
#ifdef HAVE_SELINUX
if (getenv("SELINUX_INIT") == NULL) {
if (is_selinux_enabled() != 1) {
if (selinux_init_load_policy(&enforce) == 0) {
putenv("SELINUX_INIT=YES");
execv(argv[0], argv);
} else {
if (enforce > 0) {
/*
* SELinux in enforcing mode but load_policy failed
* At this point, we probably can't open /dev/console,
* so log() won't work
*/
fprintf(stderr,"Unable to load SELinux Policy.\n");
fprintf(stderr,"Machine is in enforcing mode.\n");
fprintf(stderr,"Halting now.\n");
exit(1);
}
}
}
}
#endif
printf("OpenRC init version %s starting\n", VERSION);
if (argc > 1)

View File

@@ -154,7 +154,7 @@ static void sleep_no_interrupt(int seconds)
duration.tv_sec = seconds;
duration.tv_nsec = 0;
while(nanosleep(&duration, &remaining) < 0 && errno == EINTR)
while (nanosleep(&duration, &remaining) < 0 && errno == EINTR)
duration = remaining;
}
@@ -250,6 +250,9 @@ int main(int argc, char **argv)
} else if (do_reexec) {
send_cmd("reexec");
exit(EXIT_SUCCESS);
} else if (do_wtmp_only) {
log_wtmp("shutdown", "~~", 0, RUN_LVL, "~~");
exit(EXIT_SUCCESS);
}
if (optind >= argc) {
@@ -329,7 +332,5 @@ int main(int argc, char **argv)
send_cmd("reboot");
else if (do_single)
send_cmd("single");
else if (do_wtmp_only)
log_wtmp("shutdown", "~~", 0, RUN_LVL, "~~");
return 0;
}

View File

@@ -376,10 +376,7 @@ int run_stop_schedule(const char *applet,
printf("\n");
progressed = false;
}
if (errno == EINTR)
eerror("%s: caught an"
" interrupt", applet);
else {
if (errno != EINTR) {
eerror("%s: nanosleep: %s",
applet, strerror(errno));
return 0;

View File

@@ -49,10 +49,12 @@ const char * const longopts_help[] = {
"set xtrace when running the command",
"ignore dependencies",
"tests if the service exists or not",
"if the service is crashed then run the command",
"if the service exists then run the command",
"if the service is inactive then run the command",
"if the service is not started then run the command",
"if the service is crashed run the command",
"if the service exists run the command",
"if the service is inactive run the command",
"if the service is not started run the command",
"if the service is started run the command",
"if the service is stopped run the command",
"list all available services",
"resolve the service name to an init script",
"dry run (show what would happen)",

View File

@@ -29,7 +29,7 @@
const char *applet = NULL;
const char *extraopts = NULL;
const char *getoptstring = "aclmrsu" getoptstring_COMMON;
const char *getoptstring = "aclmrsSu" getoptstring_COMMON;
const struct option longopts[] = {
{"all", 0, NULL, 'a'},
{"crashed", 0, NULL, 'c'},
@@ -37,6 +37,7 @@ const struct option longopts[] = {
{"manual", 0, NULL, 'm'},
{"runlevel", 0, NULL, 'r'},
{"servicelist", 0, NULL, 's'},
{"supervised", 0, NULL, 'S'},
{"unused", 0, NULL, 'u'},
longopts_COMMON
};
@@ -47,6 +48,7 @@ const char * const longopts_help[] = {
"Show manually started services",
"Show the name of the current runlevel",
"Show service list",
"show supervised services",
"Show services not assigned to any runlevel",
longopts_help_COMMON
};
@@ -167,6 +169,9 @@ print_service(const char *service)
} else if (state & RC_SERVICE_SCHEDULED) {
xasprintf(&status, "scheduled");
color = ECOLOR_WARN;
} else if (state & RC_SERVICE_FAILED) {
xasprintf(&status, "failed");
color = ECOLOR_WARN;
} else
xasprintf(&status, " stopped ");
@@ -238,6 +243,7 @@ print_stacked_services(const char *runlevel)
int main(int argc, char **argv)
{
RC_SERVICE state;
RC_STRING *s, *l, *t, *level;
bool show_all = false;
char *p, *runlevel = NULL;
@@ -292,6 +298,14 @@ int main(int argc, char **argv)
printf("%s\n", runlevel);
goto exit;
/* NOTREACHED */
case 'S':
services = rc_services_in_state(RC_SERVICE_STARTED);
TAILQ_FOREACH_SAFE(s, services, entries, t)
if (!rc_service_value_get(s->value, "child_pid"))
TAILQ_REMOVE(services, s, entries);
print_services(NULL, services);
goto exit;
/* NOTREACHED */
case 's':
services = rc_services_in_runlevel(NULL);
print_services(NULL, services);
@@ -373,11 +387,14 @@ int main(int argc, char **argv)
free(nservices);
}
TAILQ_FOREACH_SAFE(s, services, entries, t) {
state = rc_service_state(s->value);
if ((rc_stringlist_find(sservices, s->value) ||
(rc_service_state(s->value) & ( RC_SERVICE_STOPPED | RC_SERVICE_HOTPLUGGED)))) {
TAILQ_REMOVE(services, s, entries);
free(s->value);
free(s);
(state & ( RC_SERVICE_STOPPED | RC_SERVICE_HOTPLUGGED)))) {
if (! (state & RC_SERVICE_FAILED)) {
TAILQ_REMOVE(services, s, entries);
free(s->value);
free(s);
}
}
}
needsme = rc_stringlist_new();

View File

@@ -996,9 +996,7 @@ int main(int argc, char **argv)
ts.tv_sec = start_wait / 1000;
ts.tv_nsec = (start_wait % 1000) * ONE_MS;
if (nanosleep(&ts, NULL) == -1) {
if (errno == EINTR)
eerror("%s: caught an interrupt", applet);
else {
if (errno != EINTR) {
eerror("%s: nanosleep: %s",
applet, strerror(errno));
return 0;

View File

@@ -68,7 +68,7 @@ static struct pam_conv conv = { NULL, NULL};
const char *applet = NULL;
const char *extraopts = NULL;
const char *getoptstring = "A:a:D:d:e:g:H:I:Kk:m:N:p:R:r:Su:1:2:3" \
const char *getoptstring = "A:a:D:d:e:g:H:I:Kk:m:N:p:R:r:s:Su:1:2:3" \
getoptstring_COMMON;
const struct option longopts[] = {
{ "healthcheck-timer", 1, NULL, 'a'},
@@ -86,6 +86,7 @@ const struct option longopts[] = {
{ "respawn-period", 1, NULL, 'P'},
{ "retry", 1, NULL, 'R'},
{ "chroot", 1, NULL, 'r'},
{ "signal", 1, NULL, 's'},
{ "start", 0, NULL, 'S'},
{ "user", 1, NULL, 'u'},
{ "stdout", 1, NULL, '1'},
@@ -109,6 +110,7 @@ const char * const longopts_help[] = {
"Set respawn time period",
"Retry schedule to use when stopping",
"Chroot to this directory",
"Send a signal to the daemon",
"Start daemon",
"Change the process user",
"Redirect stdout to file",
@@ -121,6 +123,7 @@ const char *usagestring = NULL;
static int healthcheckdelay = 0;
static int healthchecktimer = 0;
static volatile sig_atomic_t do_healthcheck = 0;
static volatile sig_atomic_t exiting = 0;
static int nicelevel = 0;
static int ionicec = -1;
static int ioniced = 0;
@@ -133,7 +136,6 @@ static int stdout_fd;
static int stderr_fd;
static char *redirect_stderr = NULL;
static char *redirect_stdout = NULL;
static bool exiting = false;
#ifdef TIOCNOTTY
static int tty_fd = -1;
#endif
@@ -141,7 +143,9 @@ static pid_t child_pid;
static int respawn_count = 0;
static int respawn_delay = 0;
static int respawn_max = 10;
static int respawn_period = 5;
static int respawn_period = 0;
static char *fifopath = NULL;
static int fifo_fd = 0;
static char *pidfile = NULL;
static char *svcname = NULL;
@@ -181,20 +185,22 @@ static void handle_signal(int sig)
{
int serrno = errno;
syslog(LOG_WARNING, "caught signal %d", sig);
if (sig == SIGTERM)
exiting = true;
switch (sig) {
case SIGALRM:
do_healthcheck = 1;
break;
case SIGCHLD:
while (waitpid((pid_t)(-1), NULL, WNOHANG) > 0) {}
break;
case SIGTERM:
exiting = 1;
break;
default:
syslog(LOG_WARNING, "caught signal %d", sig);
re_exec_supervisor();
}
/* Restore errno */
errno = serrno;
if (! exiting)
re_exec_supervisor();
}
static void healthcheck(int sig)
{
if (sig == SIGALRM)
do_healthcheck = 1;
}
static char * expand_home(const char *home, const char *path)
@@ -437,53 +443,37 @@ static void child_process(char *exec, char **argv)
static void supervisor(char *exec, char **argv)
{
FILE *fp;
pid_t wait_pid;
char buf[2048];
char cmd[2048];
int count;
int failing;
int health_status;
int healthcheck_respawn;
int i;
int nkilled;
int sig_send;
pid_t health_pid;
pid_t wait_pid;
sigset_t old_signals;
sigset_t signals;
struct sigaction sa;
struct timespec ts;
time_t respawn_now= 0;
time_t first_spawn= 0;
pid_t health_pid;
int health_status;
#ifndef RC_DEBUG
signal_setup_restart(SIGHUP, handle_signal);
signal_setup_restart(SIGINT, handle_signal);
signal_setup_restart(SIGQUIT, handle_signal);
signal_setup_restart(SIGILL, handle_signal);
signal_setup_restart(SIGABRT, handle_signal);
signal_setup_restart(SIGFPE, handle_signal);
signal_setup_restart(SIGSEGV, handle_signal);
signal_setup_restart(SIGPIPE, handle_signal);
signal_setup_restart(SIGALRM, handle_signal);
signal_setup(SIGTERM, handle_signal);
signal_setup_restart(SIGUSR1, handle_signal);
signal_setup_restart(SIGUSR2, handle_signal);
signal_setup_restart(SIGBUS, handle_signal);
#ifdef SIGPOLL
signal_setup_restart(SIGPOLL, handle_signal);
#endif
signal_setup_restart(SIGPROF, handle_signal);
signal_setup_restart(SIGSYS, handle_signal);
signal_setup_restart(SIGTRAP, handle_signal);
signal_setup_restart(SIGVTALRM, handle_signal);
signal_setup_restart(SIGXCPU, handle_signal);
signal_setup_restart(SIGXFSZ, handle_signal);
#ifdef SIGEMT
signal_setup_restart(SIGEMT, handle_signal);
#endif
signal_setup_restart(SIGIO, handle_signal);
#ifdef SIGPWR
signal_setup_restart(SIGPWR, handle_signal);
#endif
#ifdef SIGUNUSED
signal_setup_restart(SIGUNUSED, handle_signal);
#endif
#ifdef SIGRTMIN
for (i = SIGRTMIN; i <= SIGRTMAX; i++)
signal_setup_restart(i, handle_signal);
#endif
#endif
/* block all signals we do not handle */
sigfillset(&signals);
sigdelset(&signals, SIGALRM);
sigdelset(&signals, SIGCHLD);
sigdelset(&signals, SIGTERM);
sigprocmask(SIG_SETMASK, &signals, &old_signals);
/* install signal handler */
memset(&sa, 0, sizeof(sa));
sa.sa_handler = handle_signal;
sigaction(SIGALRM, &sa, NULL);
sigaction(SIGCHLD, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
fp = fopen(pidfile, "w");
if (! fp)
@@ -504,100 +494,129 @@ static void supervisor(char *exec, char **argv)
/*
* Supervisor main loop
*/
i = 0;
if (healthcheckdelay) {
signal_setup(SIGALRM, healthcheck);
if (healthcheckdelay)
alarm(healthcheckdelay);
} else if (healthchecktimer) {
signal_setup(SIGALRM, healthcheck);
else if (healthchecktimer)
alarm(healthchecktimer);
}
fifo_fd = open(fifopath, O_RDONLY |O_NONBLOCK);
failing = 0;
while (!exiting) {
wait_pid = wait(&i);
if (wait_pid == -1) {
if (do_healthcheck) {
do_healthcheck = 0;
alarm(0);
syslog(LOG_DEBUG, "running health check for %s", svcname);
health_pid = exec_service(svcname, "healthcheck");
health_status = rc_waitpid(health_pid);
if (WIFEXITED(health_status) && !WEXITSTATUS(health_status)) {
alarm(healthchecktimer);
continue;
} else {
syslog(LOG_WARNING, "health check for %s failed", svcname);
health_pid = exec_service(svcname, "unhealthy");
rc_waitpid(health_pid);
syslog(LOG_INFO, "stopping %s, pid %d", exec, child_pid);
nkilled = run_stop_schedule(applet, NULL, NULL, child_pid, 0,
false, false, true);
if (nkilled > 0)
syslog(LOG_INFO, "killed %d processes", nkilled);
else if (errno != 0)
syslog(LOG_INFO, "Unable to kill %d: %s",
child_pid, strerror(errno));
healthcheck_respawn = 0;
wait_pid = waitpid(child_pid, &i, WNOHANG);
memset(buf, 0, sizeof(buf));
if (fifo_fd >= 0) {
count = read(fifo_fd, buf, sizeof(buf) - 1);
if (count != -1)
buf[count] = 0;
}
if (strlen(buf) > 0) {
syslog(LOG_DEBUG, "Received %s from fifo", buf);
if (strncasecmp(buf, "sig", 3) == 0) {
if ((sscanf(buf, "%s %d", cmd, &sig_send) == 2)
&& (sig_send >= 0 && sig_send < NSIG)) {
syslog(LOG_INFO, "Sending signal %d to %d", sig_send,
child_pid);
if (kill(child_pid, sig_send) == -1)
syslog(LOG_ERR, "Unable to send signal %d to %d",
sig_send, child_pid);
}
} else if (exiting ) {
alarm(0);
syslog(LOG_INFO, "stopping %s, pid %d", exec, child_pid);
nkilled = run_stop_schedule(applet, exec, NULL, child_pid, 0,
false, false, true);
if (nkilled > 0)
syslog(LOG_INFO, "killed %d processes", nkilled);
continue;
}
} else if (wait_pid == child_pid) {
}
if (do_healthcheck) {
do_healthcheck = 0;
alarm(0);
syslog(LOG_DEBUG, "running health check for %s", svcname);
health_pid = exec_service(svcname, "healthcheck");
health_status = rc_waitpid(health_pid);
if (WIFEXITED(health_status) && WEXITSTATUS(health_status) == 0)
alarm(healthchecktimer);
else {
syslog(LOG_WARNING, "health check for %s failed", svcname);
health_pid = exec_service(svcname, "unhealthy");
rc_waitpid(health_pid);
syslog(LOG_INFO, "stopping %s, pid %d", exec, child_pid);
nkilled = run_stop_schedule(applet, NULL, NULL, child_pid, 0,
false, false, true);
if (nkilled < 0)
syslog(LOG_INFO, "Unable to kill %d: %s",
child_pid, strerror(errno));
else
healthcheck_respawn = 1;
}
}
if (exiting ) {
alarm(0);
syslog(LOG_INFO, "stopping %s, pid %d", exec, child_pid);
nkilled = run_stop_schedule(applet, NULL, NULL, child_pid, 0,
false, false, true);
if (nkilled > 0)
syslog(LOG_INFO, "killed %d processes", nkilled);
continue;
}
if (wait_pid == child_pid) {
if (WIFEXITED(i))
syslog(LOG_WARNING, "%s, pid %d, exited with return code %d",
exec, child_pid, WEXITSTATUS(i));
else if (WIFSIGNALED(i))
syslog(LOG_WARNING, "%s, pid %d, terminated by signal %d",
exec, child_pid, WTERMSIG(i));
} else
continue;
ts.tv_sec = respawn_delay;
ts.tv_nsec = 0;
nanosleep(&ts, NULL);
if (respawn_max > 0 && respawn_period > 0) {
}
if (wait_pid == child_pid || healthcheck_respawn) {
do_healthcheck = 0;
healthcheck_respawn = 0;
alarm(0);
respawn_now = time(NULL);
if (first_spawn == 0)
first_spawn = respawn_now;
if (respawn_now - first_spawn > respawn_period) {
if ((respawn_period > 0)
&& (respawn_now - first_spawn > respawn_period)) {
respawn_count = 0;
first_spawn = 0;
} else
respawn_count++;
if (respawn_count > respawn_max) {
syslog(LOG_WARNING,
"respawned \"%s\" too many times, exiting", exec);
exiting = true;
if (respawn_max > 0 && respawn_count > respawn_max) {
syslog(LOG_WARNING, "respawned \"%s\" too many times, exiting",
exec);
exiting = 1;
failing = 1;
continue;
}
}
alarm(0);
child_pid = fork();
if (child_pid == -1)
eerrorx("%s: fork: %s", applet, strerror(errno));
if (child_pid == 0)
child_process(exec, argv);
if (healthcheckdelay) {
signal_setup(SIGALRM, healthcheck);
alarm(healthcheckdelay);
} else if (healthchecktimer) {
signal_setup(SIGALRM, healthcheck);
alarm(healthchecktimer);
ts.tv_sec = respawn_delay;
ts.tv_nsec = 0;
nanosleep(&ts, NULL);
child_pid = fork();
if (child_pid == -1) {
syslog(LOG_ERR, "%s: fork: %s", applet, strerror(errno));
exit(EXIT_FAILURE);
}
if (child_pid == 0) {
sigprocmask(SIG_SETMASK, &old_signals, NULL);
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_DFL;
sigaction(SIGALRM, &sa, NULL);
sigaction(SIGCHLD, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
child_process(exec, argv);
}
if (healthcheckdelay)
alarm(healthcheckdelay);
else if (healthchecktimer)
alarm(healthchecktimer);
}
}
if (pidfile && exists(pidfile))
unlink(pidfile);
if (svcname) {
rc_service_daemon_set(svcname, exec, (const char *const *)argv,
pidfile, false);
rc_service_mark(svcname, RC_SERVICE_STOPPED);
rc_service_value_set(svcname, "child_pid", NULL);
rc_service_mark(svcname, RC_SERVICE_STOPPED);
if (failing)
rc_service_mark(svcname, RC_SERVICE_FAILED);
}
if (pidfile && exists(pidfile))
unlink(pidfile);
if (fifopath && exists(fifopath))
unlink(fifopath);
exit(EXIT_SUCCESS);
}
@@ -609,6 +628,7 @@ int main(int argc, char **argv)
bool start = false;
bool stop = false;
bool reexec = false;
bool sendsig = false;
char *exec = NULL;
char *retry = NULL;
int sig = SIGTERM;
@@ -714,6 +734,10 @@ int main(int argc, char **argv)
eerrorx("Invalid respawn-period value '%s'", optarg);
break;
case 's': /* --signal */
sig = parse_signal(applet, optarg);
sendsig = true;
break;
case 'S': /* --start */
start = true;
break;
@@ -819,8 +843,6 @@ int main(int argc, char **argv)
case_RC_COMMON_GETOPT
}
if (!pidfile && !reexec)
eerrorx("%s: --pidfile must be specified", applet);
endpwent();
argc -= optind;
argv += optind;
@@ -833,6 +855,12 @@ int main(int argc, char **argv)
ch_root = expand_home(home, ch_root);
umask(numask);
if (!pidfile)
xasprintf(&pidfile, "/var/run/supervise-%s.pid", svcname);
xasprintf(&fifopath, "%s/supervise-%s.ctl", RC_SVCDIR, svcname);
if (mkfifo(fifopath, 0600) == -1 && errno != EEXIST)
eerrorx("%s: unable to create control fifo: %s",
applet, strerror(errno));
if (reexec) {
str = rc_service_value_get(svcname, "argc");
@@ -907,7 +935,7 @@ int main(int argc, char **argv)
0, false, true) > 0)
eerrorx("%s: %s is already running", applet, exec);
if (respawn_delay * respawn_max > respawn_period)
if (respawn_period > 0 && respawn_delay * respawn_max > respawn_period)
ewarn("%s: Please increase the value of --respawn-period to more "
"than %d to avoid infinite respawning", applet,
respawn_delay * respawn_max);
@@ -954,6 +982,9 @@ int main(int argc, char **argv)
tty_fd = open("/dev/tty", O_RDWR);
#endif
devnull_fd = open("/dev/null", O_RDWR);
dup2(devnull_fd, STDIN_FILENO);
dup2(devnull_fd, STDOUT_FILENO);
dup2(devnull_fd, STDERR_FILENO);
child_pid = fork();
if (child_pid == -1)
eerrorx("%s: fork: %s", applet, strerror(errno));
@@ -1006,5 +1037,18 @@ int main(int argc, char **argv)
rc_service_mark(svcname, RC_SERVICE_STOPPED);
}
exit(EXIT_SUCCESS);
} else if (sendsig) {
fifo_fd = open(fifopath, O_WRONLY |O_NONBLOCK);
if (fifo_fd < 0)
eerrorx("%s: unable to open control fifo %s", applet, strerror(errno));
xasprintf(&str, "sig %d", sig);
x = write(fifo_fd, str, strlen(str));
if (x == -1) {
free(tmp);
eerrorx("%s: error writing to control fifo: %s", applet,
strerror(errno));
}
free(tmp);
exit(EXIT_SUCCESS);
}
}

View File

@@ -20,6 +20,13 @@ checkit() {
ret=0
fail_on_out() {
if [ -n "${out}" ]; then
eerror "Last command failed; failing"
exit 1
fi
}
ebegin "Checking exported symbols in libeinfo.so (data)"
checkit einfo.data $(
readelf -Ws ${libeinfo_builddir}/libeinfo.so \
@@ -74,6 +81,7 @@ out=$(cd ${top_srcdir}; find */ \
-exec grep -n -E '[[:space:]]+$' {} +)
[ -z "${out}" ]
eend $? "Trailing whitespace needs to be deleted:"$'\n'"${out}"
fail_on_out
ebegin "Checking trailing newlines in code"
out=$(cd ${top_srcdir};
@@ -82,6 +90,7 @@ out=$(cd ${top_srcdir};
done)
[ -z "${out}" ]
eend $? "Trailing newlines need to be deleted:"$'\n'"${out}"
fail_on_out
ebegin "Checking for obsolete functions"
out=$(cd ${top_srcdir}; find src -name '*.[ch]' \
@@ -89,6 +98,7 @@ out=$(cd ${top_srcdir}; find src -name '*.[ch]' \
-exec grep -n -E '\<(malloc|memory|sys/(errno|fcntl|signal|stropts|termios|unistd))\.h\>' {} +)
[ -z "${out}" ]
eend $? "Avoid these obsolete functions:"$'\n'"${out}"
fail_on_out
ebegin "Checking for x* func usage"
out=$(cd ${top_srcdir}; find src -name '*.[ch]' \
@@ -99,6 +109,7 @@ out=$(cd ${top_srcdir}; find src -name '*.[ch]' \
-e src/libeinfo/libeinfo.c)
[ -z "${out}" ]
eend $? "These need to be using the x* variant:"$'\n'"${out}"
fail_on_out
ebegin "Checking spacing style"
out=$(cd ${top_srcdir}; find src -name '*.[ch]' \
@@ -113,6 +124,7 @@ out=$(cd ${top_srcdir}; find src -name '*.[ch]' \
{} +)
[ -z "${out}" ]
eend $? "These lines violate style rules:"$'\n'"${out}"
fail_on_out
einfo "Running unit tests"
eindent

View File

@@ -57,15 +57,6 @@ Several other variables affect the way services behave under
supervise-daemon. They are documented on the openrc-run man page, but I
will list them here for convenience:
``` sh
pidfile=/pid/of/supervisor.pid
```
If you are using start-stop-daemon to monitor your scripts, the pidfile
is the path to the pidfile the daemon creates. If, on the other hand,
you are using supervise-daemon, this is the path to the pidfile the
supervisor creates.
``` sh
command_args_foreground="arguments"
```

23
test/travis.sh Executable file
View File

@@ -0,0 +1,23 @@
#!/bin/bash
# Copyright (c) 2007-2018 The OpenRC Authors.
# See the Authors file at the top-level directory of this distribution and
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
#
# This file is part of OpenRC. It is subject to the license terms in
# the LICENSE file found in the top-level directory of this
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
# This file may not be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
set -e
set -u
set -x
# These are steps to run on TravisCI under a containerized Ubuntu system.
# See $TOP/.travis.yml for more info about the TravisCI setup.
cpus=$(getconf _NPROCESSORS_CONF || echo 1)
# make on TravisCI doesn't support -O yet
make -j"${cpus}"
make test