Commit Graph

1311 Commits

Author SHA1 Message Date
William Hubbs
382efdbfcb add quiet parameter to run_stop_schedule 2017-09-06 17:22:35 -05:00
William Hubbs
17b5cc78d3 add retry option to supervise-daemon
The --retry option for supervise-daemon defines how the supervisor will
attempt to stop the child process it is monitoring. It is defined when
the supervisor is started since stopping the supervisor just sends a
signal to the active supervisor.

This fixes #160.
2017-09-06 17:22:21 -05:00
William Hubbs
36a0ab9054 make run_stop_schedule accept a pid instead of a pid file 2017-08-25 11:36:45 -05:00
William Hubbs
d7938f54f2 start-stop-daemon: move --retry processing code to a shared module
This was part of start-stop-daemon; however, it needs to be shared in
order to be used by supervise-daemon.
2017-08-24 11:34:18 -05:00
William Hubbs
cfbe9c2ede move get_pid function to a shared file 2017-08-23 14:36:50 -05:00
Jason Graham
6d4e843397 fix ENT macro usage
X-Gentoo-Bug: 624796
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=624796
2017-07-24 18:24:18 -05:00
Jory A. Pratt
11243f85b6 kill_all: include limits.h for PATH_MAX 2017-06-08 10:04:19 -05:00
William Hubbs
560d874d2f fix compile issue for musl 2017-06-08 08:43:42 -05:00
William Hubbs
ee886c4482 openrc-shutdown: add --single option and clean up option processing 2017-06-05 15:49:22 -05:00
William Hubbs
7689106aa1 add support for writing reboot and shutdown records to wtmp 2017-06-04 20:56:03 -05:00
Sergei Trofimovich
0ddee9b7d2 openrc-init: fix buffer overflow in init.ctl
How to reproduce 1-byte overflow:

```
$ FEATURES=-test CFLAGS="-fsanitize=address -O0 -ggdb3" emerge -1 openrc

=================================================================
==1==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fff0efd8710
    at pc 0x000000402076 bp 0x7fff0efd7d50 sp 0x7fff0efd7d40
WRITE of size 1 at 0x7fff0efd8710 thread T0
    #0 0x402075  (/sbin/openrc-init+0x402075)
    #1 0x3cf6e2070f in __libc_start_main (/lib64/libc.so.6+0x3cf6e2070f)
    #2 0x4013b8  (/sbin/openrc-init+0x4013b8)

Address 0x7fff0efd8710 is located in stack of thread T0 at offset 2432 in frame
    #0 0x401cfb  (/sbin/openrc-init+0x401cfb)

  This frame has 3 object(s):
    [32, 160) 'signals'
    [192, 344) 'sa'
    [384, 2432) 'buf' <== Memory access at offset 2432 overflows this variable
HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow ??:0 ??
```

The problem here is in the code handling reads from 'init.ctl':

```
int main(int argc, char **argv) {
...
    char buf[2048];
    for (;;) {
        /* This will block until a command is sent down the pipe... */
        fifo = fopen(RC_INIT_FIFO, "r");
        count = fread(buf, 1, 2048, fifo);
        buf[count] = 0;
        ...
    }
```

`buf[count] = 0;` writes outside the buffer when `fread()` returns non-truncated read.

This fixes #138.
2017-05-30 16:21:23 -05:00
Sergei Trofimovich
7185e242ff rc-logger.c: fix crash on fclose(NULL) (#137)
Only close the log if we successfully opened it.

Reported-by: Brian Evans <grknight@gentoo.org>
Tested-by: Brian Evans <grknight@gentoo.org>
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
2017-05-30 03:47:55 -04:00
William Hubbs
1ece16bfcd openrc-shutdown: add dry-run option 2017-05-22 12:42:37 -05:00
William Hubbs
0cfd0dd9ef openrc-shutdown: move to single user mode by default
To be more compatible with sysvinit, move to single user mode if no
options are specified on the command line.
2017-05-22 12:15:15 -05:00
William Hubbs
a77ee2e941 init: add ability to switch to single user mode 2017-05-22 11:29:23 -05:00
William Hubbs
49b8a573a1 add kill_all helper
This is similar to the sysvinit killall5 utility.  It should only be used
in service scripts, so it will not be installed in the path.

This closes #129.
2017-05-19 18:13:39 -05:00
William Hubbs
a2055af900 rc_status: calculate time differences in time_t and display seconds in uptime 2017-05-15 18:55:47 -05:00
William Hubbs
cbf96967f1 supervise-daemon: save start time and respawn count before dropping privs 2017-05-12 17:15:55 -05:00
William Hubbs
82e12e3092 rc-status: show uptimes and respawn counts for supervised daemons 2017-05-11 21:39:03 -05:00
William Hubbs
1ebef0d7a3 fix to_time_t to honor dst 2017-05-11 18:13:13 -05:00
William Hubbs
6b4050ab9c fix from_time_t function 2017-05-11 16:22:12 -05:00
William Hubbs
cf5e9aa2bb Move time_t conversions to rc-misc.c so they can be shared 2017-05-11 16:06:12 -05:00
William Hubbs
a3250e77d4 supervise-daemon: save start time and respawn count
This will allow rc-status to display an uptime and restart count for
supervised processes.
2017-05-11 13:54:20 -05:00
William Hubbs
df027ca472 supervise-daemon: fix our status when we give up on the child process 2017-05-11 11:36:42 -05:00
William Hubbs
4c89e3f5fa supervise-daemon:create multiple options from --respawn-limit
This creates --respawn-delay, --respawn-max and --respawn-period. It was
suggested that it would be easier to follow if the options were
separated.

This is for #126.
2017-05-10 18:13:23 -05:00
William Hubbs
3673040722 supervise-daemon: add a --respawn-limit option
Allow limiting the number of times supervise-daemon will attempt to respawn a
daemon once it has died to prevent infinite respawning. Also, set a
reasonable default limit (10 times in a 5 second period).

This is for issue #126.
2017-05-09 18:30:08 -05:00
William Hubbs
96c8ba2fb5 supervise-daemon: mark all open file descriptors FD_CLOEXEC 2017-04-29 13:48:45 -05:00
William Hubbs
47cf1d0c70 supervise-daemon:remove the controlling tty in the supervisor 2017-04-29 12:04:15 -05:00
William Hubbs
06a6a27e44 supervise-daemon: fix access to tty_fd and devnull_fd
Both the child and supervisor need access to these file descriptors.
2017-04-29 10:12:16 -05:00
William Hubbs
5de3798afc supervise-daemon: mark the service started when the supervisor is active 2017-04-29 09:41:07 -05:00
William Hubbs
0e3f872098 init: send term/kill signals as final step of shutdown 2017-04-17 12:23:45 -05:00
William Hubbs
4694900190 init: fix signal handling
The only signals we handle are SIGINT and SIGCHLD, so block all others
and unblock them in the child process before we start a rurnlevel.
2017-04-13 12:54:30 -05:00
William Hubbs
05738bfce1 init: add re-exec capability
This will allow the re-execution of the init process after upgrading
OpenRC.
2017-04-12 17:56:36 -05:00
William Hubbs
cc51bdca3b Add attribution to openrc-init.c and openrc-shutdown.c 2017-04-07 07:39:12 -05:00
William Hubbs
13ca79856e add init process
openrc-init.c and openrc-shutdown.c are based on code which was written by
James Hammons <jlhamm@acm.org>, so I would like to publically
thank him for his work.
2017-04-06 17:13:59 -05:00
Austin English
9eb669591e start-stop-daemon: warn if calling --start with --retry or --stop with --wait
This fixes #122
2017-04-03 10:43:40 -05:00
William Hubbs
6f614cd3f3 Move deptree2dot to the support folder
Since deptree2dot and the perl requirement are completely optional, we
can move this tool to the support folder. This gives the user the option
of using it if they have perl installed, and means we do not have an
optional runtime dependency on perl.

Documentation for this tool has also been added to the support folder.

X-Gentoo-Bug: 600742
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=600742
2017-02-17 12:06:03 -06:00
Doug Freed
6dcb692986 start-stop-daemon: allow all standard signals
Also we define the signalpair_item macro.
This fixes #113.

X-Gentoo-Bug: 604986
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=604986
2017-01-25 17:48:52 -06:00
William Hubbs
b73941f0c3 mountinfo: make the path to /proc/mounts a constant
This path should not be hard coded in the open call.
Linux prior to 2.4.19 did not have /proc/self/mounts, so for now I'm
making this value /proc/mounts everywhere, but that may change to
/proc/self/mounts on linux; I'm not sure we should care about <2.4.19.

X-Gentoo-Bug: 604646
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=604646
2017-01-04 18:18:37 -06:00
Benda Xu
c304522131 Clean up warnings that can use the _unused macro
X-Gentoo-Bug: 604666
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=604666
2017-01-04 17:18:35 -06:00
Benda Xu
92325b44ba Indentation fixes
X-Gentoo-Bug: 604666
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=604666
2017-01-04 16:59:38 -06:00
Doug Freed
45aa36cc62 librc: detect loops in stacked runlevels and abort
This fixes #109.
X-Gentoo-Bug: 558700
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=558700
2016-12-19 18:24:31 -06:00
Jason Zaman
6414c3bc39 selinux: fix SIGSEGV with invalid contexts
Fixes: https://github.com/openrc/openrc/issues/104
2016-11-17 12:03:12 -06:00
William Hubbs
be06cd250e src/rc/rc: do not try to start services if fork fails 2016-11-01 17:31:57 -05:00
William Hubbs
4fd144c0a6 src/rc/rc-misc.c: report error if call to flock() fails
X-Gentoo-Bug: 597390
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=597390
2016-10-24 12:47:49 -05:00
Sven Wegener
78146b0e14 do_service: Initialize idx to 0
If index is not explicitly specified for service_started_daemon, it will
look for daemons by random index.

This fixes #100.
2016-10-11 10:30:02 -05:00
Doug Freed
6710316a18 openrc-run: fix double free 2016-09-30 17:29:56 -04:00
William Hubbs
83bb827edf Revert "Disable parallel startup in interactive mode"
This reverts commit 8b4fc05ff2.
The original commit did not explain why this feature was disabled, and I
now have a request to enable it.

This fixes #24.
2016-09-19 12:09:05 -05:00
Doug Freed
6cabaf274d rc-misc: allow EINFO_VERBOSE through too 2016-09-16 09:51:03 -04:00
Doug Freed
1edb5f6fd9 rc-misc: Allow EINFO_COLOR through env_filter()
This allows rc-service -C <service> <action> to properly not print color
messages.

Fixes #93
2016-09-14 22:48:56 -04:00
William Hubbs
69ac78d76a openrc-run: make runscript warning respect quiet option
X-Gentoo-Bug: 591414
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=591414
2016-08-25 11:04:48 -05:00
William Hubbs
ca8c29ee60 librc: fix Docker auto detection
The original auto detection of Docker containers assumed the presence of
a container environment variable. However, Docker-1.12 does not
implement this, and I'm not sure which versions of docker implemented
it.

The new test is for the presence of a file named .dockerenv in the
root directory.
2016-07-31 12:24:56 -05:00
Kenneth Lakin
94b98430cb start-stop-daemon: Add SSD_IONICELEVEL
This is the disk IO counterpart to SSD_NICELEVEL.
Modified by William Hubbs to add the variable to the start-stop-daemon
man page.

This fixes #69.
2016-07-26 12:30:39 -05:00
Doug Freed
3adb8fb389 rc-logger: refuse to cat TMPLOG into itself
This prevents an infinite loop in case somebody decides to set
rc_log_path to match TMPLOG.
2016-07-24 02:27:53 +00:00
William Hubbs
695be59083 rc-status: add -m/--manual option to show manually started services
X-Gentoo-Bug: 585906
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=585906
2016-07-18 13:20:56 -05:00
Doug Freed
c962678dd6 rc: Rename some static variables to kill warnings 2016-07-16 20:10:37 +00:00
William Hubbs
3a1262703f Remove the DEBUG_MEMORY macro
This fixes #43.
2016-07-14 16:52:57 -05:00
William Hubbs
20035210bd make variable aflag a boolean show_all 2016-07-14 12:13:17 -05:00
Jaromil
7f84b5d741 libeinfo: document the x suffix on function names
This fixes #88.
2016-07-13 17:04:28 -05:00
William Hubbs
b2c92b88cc fstabinfo/mountinfo: ensure /etc/fstab exists before calling setmntent
This is based on a patch by A. Wilcox <awilfox.gentoo@foxkit.us>.

X-Gentoo-Bug: 478226
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=478226

X-Gentoo-Bug: 478226
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=478226
2016-06-10 17:16:37 -05:00
William Hubbs
87884db667 Make deprecation warnings for rc and runscript more visible
These warnings were inserted in verbose only mode in OpenRC-0.13.A
Now, we are making them more visible in preparation for removing these
compatibility binaries in the future.
2016-05-24 11:24:10 -05:00
William Hubbs
94077d264e supervise-daemon: log the exit code or signal when a child process dies 2016-05-23 11:10:51 -05:00
Jason Zaman
3fa9015b8e rc-selinux: access check was backwards 2016-05-13 12:52:21 -05:00
William Hubbs
3b5a8b331e supervise-daemon: add pam service file 2016-05-13 12:05:23 -05:00
William Hubbs
ad23d5b8db openrc-run: clean up runscript deprecation message 2016-05-04 18:17:58 -05:00
William Hubbs
62410eaf4b add daemon supervisor
The supervise-daemon process is meant to be a lightweight supervisor
which can monitor and restart a daemon if it crashes.
2016-04-27 11:13:50 -05:00
Mike Gilbert
171e856ec8 start-stop-daemon: Allow group read/write when creating output files
This allows for better interaction with inherited ACL entries.
This fixes #84.

X-Gentoo-Bug: 577362
X-Gentoo-Bug-URL: https://bugs.gentoo.org/577362
2016-04-11 11:11:59 -05:00
William Hubbs
7eaf71176b Fix rc_env_allow wildcard usage
Before this commit, using * in rc_env_allow did not work.

This fixes #60.
2016-02-12 12:44:52 -06:00
William Hubbs
8a7e4d38a7 rc-service: add --ifinactive and --ifnotstarted flags
X-Gentoo-Bug: 523174
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=523174
2016-01-28 12:57:11 -06:00
William Hubbs
47dd5e37cb add back deprecation warnings lost during refactoring 2016-01-22 12:46:29 -06:00
William Hubbs
e277ae57ef fix tests
X-Gentoo-Bug: 572602
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=572602
2016-01-22 12:07:13 -06:00
William Hubbs
69f052b611 librc: Complain when a real and virtual service have the same name 2016-01-21 15:58:03 -06:00
William Hubbs
e4eacf02ca openrc-run: in verbose mode, log execution of the shell script
This is to show when openrc-run runs the openrc-run.sh script; it is
used for debugging.
2016-01-20 11:20:40 -06:00
Doug Freed
62b49b2a3a rc: remove use of magic constant and allow OpenVZ to drop to shell
OpenVZ has had console support for a long time now; allow them to use it
to drop to a shell during interactive boot.
2016-01-19 00:09:20 -06:00
Doug Freed
4c814a0a28 librc: handle rc_sys="prefix" even if we weren't built with a prefix
This probably isn't needed, but it mimics old behavior.
2016-01-19 00:09:20 -06:00
Doug Freed
36dde4e7f2 librc: fix handling the nothing special case for rc_sys 2016-01-19 00:09:20 -06:00
Doug Freed
649f63d882 librc: move system detection code into rc_sys and use it
This fixes an issue where librc code was calling code that only existed
in the rc binary.

This reverts commits 8addd79 and 9f6e056

This fixes #75.
2016-01-19 00:09:20 -06:00
William Hubbs
55a28f5d25 Revert "rc: make get_systype similar to the old rc_sys function"
This reverts commit f79a7a7be1.
2016-01-18 23:40:20 -06:00
William Hubbs
6c09421375 Revert "librc: fix librc-depend functions to call rc_sys"
This reverts commit 73482cf13a.
2016-01-18 23:40:03 -06:00
William Hubbs
79359f77cc fix bsd build
X-Gentoo-Bug: 572068
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=572068
2016-01-18 16:06:39 -06:00
William Hubbs
f79a7a7be1 rc: make get_systype similar to the old rc_sys function 2016-01-18 15:50:59 -06:00
William Hubbs
73482cf13a librc: fix librc-depend functions to call rc_sys 2016-01-18 15:09:31 -06:00
William Hubbs
0910c455d3 src/rc/Makefile: fix make depend target 2016-01-14 13:33:05 -06:00
William Hubbs
f5e06bc55a include rc.h properly in source files
We were attempting to include rc.h in rc-misc.h instead of the source
files where it should be included.
2016-01-14 12:52:32 -06:00
William Hubbs
6da0abc085 fix selinux build
X-Gentoo-Bug: 571798
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=571798
2016-01-14 11:29:24 -06:00
William Hubbs
b34df9dd81 fix selinux build 2016-01-13 20:11:06 -06:00
William Hubbs
6f02069746 Add LANG, LC_MESSAGES and TERM to the environment whitelist 2016-01-13 19:34:22 -06:00
William Hubbs
d4c7207ef3 fix seg fault 2016-01-13 19:30:19 -06:00
William Hubbs
bf2f40828e Remove multicall binary structure from OpenRC
This eliminates the need for the selinux-specific wrapper scrript we
were installing in /lib*/rc/{bin,sbin}.
2016-01-12 10:42:14 -06:00
William Hubbs
fe485f4433 rc: fix compiler warnings cleanup
This reverts commit 981d2b3308 and fixes
the warnings that generated.
2016-01-05 01:05:00 -06:00
William Hubbs
53bc986ce5 Clean default env_whitelist
The whitelist of environment variables we pass to service scripts
included several unnecessary variables.

The default whitelist now includes EERROR_QUIET, EINFO_QUIET,
IN_BACKGROUND and IN_HOTPLUG.

X-Gentoo-Bug: 569542
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=569542
2016-01-04 15:14:15 -06:00
William Hubbs
981d2b3308 rc: clean up compiler warnings
The get_systype(), detect_container(), detect_prefix() and detect_vm()
functions need to return "char *" instead of "const char *".
2016-01-01 13:13:28 -06:00
William Hubbs
000503fad7 Convert OpenRC to a centralized copyright/license structure
In the past, OpenRC was a hybrid of a centralized and file-scope
license/copyright structure.

I followed the instructions from the Software Freedom Law Center [1] to
convert to a Centralized structure where possible, for easier future
maintenance.

[1] https://softwarefreedom.org/resources/2012/ManagingCopyrightInformation.html
2015-12-21 12:16:06 -06:00
William Hubbs
065f034059 format fix 2015-12-14 11:37:39 -06:00
William Hubbs
f9bdb072e8 rc.map: remove references to rc_sys_v{1,2} 2015-12-08 12:50:47 -06:00
William Hubbs
9f6e05671d Convert rc_sys() calls to detect_container() and detect_vm() 2015-12-08 12:09:33 -06:00
William Hubbs
8addd7913a Create detect_container() and detect_vm() functions
These functions replace rc_sys so that we can detect containers and vms
separately.

Also, we copy file_regex() to rc-misc.c and open it to all operating
systems.
2015-12-08 12:05:59 -06:00
William Hubbs
83cd7145e3 Rename bootlevel variable in _usage.c
In src/rc/_usage.c, we were using bootlevel as the variable to hold the
return value of rc_sys.
This changes the variable name to systype because this function returns
a system type, not a runlevel.
2015-12-05 17:47:47 -06:00
William Hubbs
f5cf1136e7 Use systype variable for rc_sys call 2015-12-02 15:44:35 -06:00
William Hubbs
a0cf8f9124 Add detection for rkt containers 2015-12-02 10:20:39 -06:00
William Hubbs
9fedb3b40b Add detection for docker containers 2015-12-02 10:20:15 -06:00
William Hubbs
635e33cdc8 librc: comsolidate rc_sys_v1 and rc_sys_v2 into rc_sys
These functions were never meant to be used outside of OpenRC, and they
were added when we thought we were going to do away with the automatic
detection of subsystems. Since the autodetection is not going away, we
can combine these functions into rc_sys.
2015-12-01 17:39:04 -06:00
Ian Stakenvicius
33d3f33b3c Implement "want" dependency
The want dependency is similar to the use dependency. If a service
script, for example called service1, adds "want service2" to its depend
function, OpenRC will attempt to start service2, if it exists on the
system,  when service1 is started.

However, service1 will start regardless of the status of
service2.

X-Gentoo-Bug: 406021
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=406021
2015-11-12 12:32:45 -06:00
Benda Xu
085d77f17e Standardize macro tests for gnu hurd
This also fixes breakage of GNU/hurd builds introduced by commit 3f82edbeb9.
2015-11-11 13:37:41 -06:00
William Hubbs
c831f1f994 librc: rework overriding rc.conf options from the kcl
Rename the rc_conf_override function to describe its purpose better,
drop one conditional compile by making it available everywhere, and move
the call to it after the optional rc.conf.d directory is processed.
2015-11-05 11:20:57 -06:00
William Hubbs
591aea2821 librc: Remove redundant code from rc_config_load 2015-11-05 11:20:57 -06:00
William Hubbs
c09eeca491 Add rc.conf.d support
This makes it possible to override settings in rc.conf by adding a
directory @SYSCONFDIR@/rc.conf.d and putting files in this directory.
The files will be processed in lexical order, and the last setting in
these files will be used.
2015-11-05 10:40:24 -06:00
William Hubbs
b81317bdf8 mountinfo: make sure the netdev variable is initialized on Linux
This fixes the following regression:

X-Gentoo-Bug: 562668
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=562668
2015-10-13 08:27:43 -05:00
William Hubbs
5f4f242036 mountinfo: fix --netdev and --nonetdev on Linux
On Linux, the --netdev and --nonetdev switches were not working. They
were both returning false. After this change, they operate based on the
presence or abscence of the _netdev option in mount options.
2015-10-05 10:18:00 -05:00
William Hubbs
b3f7ff901f mountinfo: read /proc/self/mounts instead of /proc/mounts on Linux 2015-10-04 15:35:33 -05:00
William Hubbs
3b6a6df4b5 openrc-run: rename some dependency variables and a function for clarity
All of the dependency type lists had the types_ prefix in their names;
this has been changed to deptypes_ to make them more self documenting.

Along the same lines, the setup_types function was renamed
setup_deptypes.
2015-09-17 15:02:30 -05:00
William Hubbs
f69833a1e1 mountinfo: fix -e and -E options
Add the -e and -E options to getoptstring so they are recognized.
2015-08-02 07:39:58 -05:00
William Hubbs
eeadca0b8a Add EERROR_QUIET and EINFO_QUIET to environment whitelist 2015-07-23 12:44:10 -05:00
Jakob Drexel
0b435ddd83 librc: Fix crash if the service name is the same as the including runlevel
If a service has the same name as the runlevel it is in, openrc will
crash on changing to such runlevel. It goes in a recursive madness and
eventually gets a SEGV while in snprintf (don't know why).

This fixes two errors:
1. ls_dir stats files not with full path -> stat always returns != 0
2. ls_dir adds files to list if stat failed

This fixes #53.

X-Gentoo-Bug: 537304
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=537304
2015-05-04 09:54:51 -05:00
William Hubbs
c709e6077c Add support for systemd-nspawn containers
This adds support for running OpenRC in a container created by
the systemd-nspawn utility.

This fixes #52.

X-Gentoo-Bug: 548058
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=548058
2015-05-01 09:04:07 -05:00
William Hubbs
8b93492086 convert all references from runscript to openrc-run 2015-04-27 11:21:29 -05:00
William Hubbs
03803ae8e9 start-stop-daemon: redirect stdin if --background option is used
X-Gentoo-Bug: 498684
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=498684
2015-04-24 12:24:09 -05:00
William Hubbs
b8ab99b5d3 checkpath: Remove the last HAVE_SELINUX test 2015-03-25 08:33:42 -05:00
William Hubbs
a4cf61e8bf selinux: unconditionally include the header and provide stub methods
If selinux is disabled, then stub methods will be provided instead of
calling the real methods. This removes some warnings about unused
parameters which used to be covered up with #ifdef HAVE_SELINUX.

Signed-off-by: Jason Zaman <jason@perfinion.com>
2015-03-25 01:01:38 -05:00
William Hubbs
d38cc8f221 checkpath: fix warning about selinux_on being unused 2015-03-24 23:18:15 -05:00
Doug Freed
f085ae400c Fix some compiler warnings
librc: Fix C90 warning (mixed declaration and code)
rc: Fix warning about discarding const qualifier

Fixes #45.
2015-03-24 19:08:29 -05:00
Will Miles
c1faafcad8 start-stop-daemon: Fix regression for --test
The previous fix to --test (PR #34) prevented reading one too many
arguments when --exec -or --name was not specified, but created a
regression where the last argument would not print if either of those
arguments was specified. This corrects the issue.

Fixes #41.
2015-03-24 15:52:19 -05:00
William Hubbs
a0378f3871 checkpath: do not chown or chmod symbolic links
This is another security fix. If you use chown() or chmod() on a
symbolic link, it affects the referenced file, not the symbolic link
itself.

X-Gentoo-Bug: 540006
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=540006
2015-02-19 14:39:04 -06:00
William Hubbs
6781667641 typo fix 2015-02-15 16:15:18 -06:00
William Hubbs
b17af3c85f checkpath: security fix for -m and -o options
Do not change permissions on the target if it is a file and has multiple
hard links. This is necessary because a hard link can be an attack
vector to gain privilege escalation.

X-Gentoo-Bug: 540006
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=540006
2015-02-15 16:04:43 -06:00
Will Miles
3f80f22e22 Prioritize local includes and libraries
This fixes #35.
2015-01-24 13:48:53 -06:00
Will Miles
cddb4aad08 Fix off-by-one error in --test argument printout in start-stop-daemon.
Fixes #34.
2015-01-22 12:53:41 -06:00
Doug Freed
74478830a8 fix double free of pidfile
This fixes a double free of the pidfile variable. For discussion of this
issue, see the bug.

X-Gentoo-Bug: 531600
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=531600
2015-01-12 10:30:36 -06:00
William Hubbs
7a92eb8887 rename git.mk to gitver.mk
This is a more descriptive name since this file only sets the gitver
variable.
2014-12-05 11:55:45 -06:00
Jason Zaman
1932360adc Integrate the functionality from runscript_selinux.so
runscript used to dlopen() runscript_selinux.so. This adds equivalent
functionality directly in to runscript instead. It authenticates with
either PAM or shadow and optionally has a dep on audit.

X-Gentoo-Bug: 517450
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=517450
2014-11-03 09:31:25 -06:00
Alexander Vershilov
be952bebb3 Fix incorrect handling of chroot option.
Fixes #28.

X-Gentoo-Bug: #527370
X-Gentoo-Bug-Url: https://bugs.gentoo.org/show_bug.cgi?id=527370
2014-11-01 16:44:30 -05:00
William Hubbs
7700e6fe79 Fix compile errors created by bundling queue.h 2014-10-24 10:44:14 -05:00
Anthony G. Basile
6ca79042b9 helpers.h, start-stop-daemon.c: remove uneeded macros
TAILQ_CONCAT, TAILQ_FOREACH_SAFE and LIST_FOREACH_SAFE are defined
in our bundled queue.h and are no longer required.
2014-10-23 19:14:06 -05:00
Anthony G. Basile
1e0a4bebde Bundle <sys/queue.h> from NetBSD
We are bundling this to allow building on musl-based systems since musl
does not include <sys/queue.h>.
2014-10-23 19:14:06 -05:00
William Hubbs
ca6b86be44 Fix all tests for GNU/kFreeBSD
It is necessary to check for both the kernel and c library because
__FreeBSD_kernel is also defined on native FreeBSD [1].

[1] http://sourceforge.net/p/predef/wiki/OperatingSystems/
2014-10-23 18:47:24 -05:00
Gabriele Giacone
4ac289b539 Fix rc_svcdir for GNU/Hurd 2014-10-23 13:05:08 -05:00
Svante Signell
875f03e27c fix defines for GNU/Hurd 2014-10-23 13:00:24 -05:00
Gabriele Giacone
89c8a62a10 Fix rc_svcdir for GNU/kFreeBSD 2014-10-22 13:27:37 -05:00
Svante Signell
3f82edbeb9 Fix GNU/kFreeBSD port
Check for __FreeBSD_kernel instead of __GLIBC__ in source files.

note from William Hubbs:
I was told this is a better check for GNU/kFreeBSD than checking the
C  library the source is being compiled against.
GNU/kFreeBSD than checking which library we are using.
2014-10-22 11:05:07 -05:00
Anthony G. Basile
86e9aa0d36 einfo.h, rc.h.in: simplify __BEGIN_DECLS logic
There is no need to redefine __BEGIN_DECLS and __END_DECLS.
We simplify the logic here and avoid undefining these macros.
2014-10-22 07:46:49 -04:00
Anthony G. Basile
4a08517cac einfo.h, rc.h.in: ensure __BEGIN_DECLS is defined
Some Standard C Libraries, like musl, don't define __BEGIN_DECLS
or __END_DECLS.  We add some ifdef magic to ensure these are
available.
2014-10-21 09:39:34 -04:00
Alexander Vershilov
f9acd65497 librc:look for the pid file in a chroot if defined
X-Gentoo-Bug: 524388
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=524388
2014-10-20 15:44:19 -05:00
William Hubbs
866501be1c typo fix 2014-09-20 16:51:30 -05:00
William Hubbs
d1e71b07af Show rc and runscript deprecation warnings in verbose mode
These messages are being changed for this release to show in verbose
mode because of the number of times they display.
2014-08-11 12:32:44 -05:00
William Hubbs
2624a8c8a7 checkpath: apply ownership to all paths given on command line
The stat structure was not being initialized correctly in do_check. This
was causing the owner adjustment to be skipped if the first path had the
correct owner.

Also, the "correcting owner" message should always be printed when the
owner is being changed.

X-Gentoo-Bug: 518042
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=518042
2014-07-28 10:41:24 -05:00
William Hubbs
275714bdc7 checkpath: style fix 2014-07-25 11:04:57 -05:00
William Hubbs
1f7582c78b src/librc/librc-daemon.c: style fix 2014-07-19 13:03:00 -05:00
William Hubbs
cc1bc6a4ce src/rc/Makefile: typo fix 2014-07-19 12:59:35 -05:00
William Hubbs
40f42ced21 rc-status: fix infinite loop when using stacked runlevels
Remove the recursive call in print_stacked_services which was causing an
infinite loop when using stacked runlevels.
I would like to thank Doug Freed and Jason Zaman for assisting with
tracking this down.

X-Gentoo-Bug: 514972
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=514972
2014-07-17 23:10:28 -05:00
Jason Zaman
89907b60ba move the selinux_setup function into rc-selinux
X-Gentoo-Bug: 516956
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=516956
2014-07-16 17:59:25 -05:00
William Hubbs
a94a9740d5 checkpath: style fixes 2014-07-16 15:03:11 -05:00
William Hubbs
8b8edc2970 style fixes 2014-07-16 14:48:03 -05:00
William Hubbs
010c2ab18b Rename SELinux source files
The name rc-selinux-util.* is a bit long, so I renamed the source files
to rc-selinux.*

X-Gentoo-Bug: 516956
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=516956
2014-07-16 14:14:37 -05:00
Jason Zaman
9c689542c3 checkpath: restore the SELinux context
X-Gentoo-Bug: 516956
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=516956
2014-07-16 13:09:38 -05:00
William Hubbs
71d6d61b28 checkpath: fix logic for the writable option
The -W option does not need an argument of its own; it can take the
first path after all other options are processed on the command line.

Also, move the processing for the -W option out of the switch so it will
be in the same loop as the other processing.
2014-07-13 14:12:36 -05:00
William Hubbs
d80482c2f4 checkpath: fix error message in previous commit 2014-07-11 15:23:38 -05:00
William Hubbs
d0040aff0a checkpath: report an error if required options were not specified
Before this commit, not specifying -d, -f, -p or -W in a checkpath
command meant the command exited successfully but actually did nothing.

This is an error condition, so report it as such.
2014-07-11 15:04:06 -05:00
William Hubbs
9eb9b28d3e librc: filter out container processes on OpenVZ host
Thanks to info and testing done by Daniel Robbins <drobbins@funtoo.org>,
there is now a fix for this. Below is his description of the steps
OpenRC needed to use.

1) See if /proc/<pid>/status exists
2) If it does, see if it has a "envID:" field
3) If it does, see if "envID:" is set to "0"
4) If so, then it's one of the host's processes and should be a
candidate for the list. Otherwise, it is one of the container's
processes and should be ignored.

This should fix the bug and allow start-stop-daemon to work properly on
OpenVZ hosts.

X-Gentoo-Bug: 376817
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=376817
2014-06-20 16:01:47 -05:00
William Hubbs
de186401e5 fstabinfo: fix mount and remount
The mount and remount options should always be processed. They were only
being processed if -q was not on the command line.

X-Gentoo-Bug: 498206
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=498206
2014-01-18 13:50:05 -06:00
Benda Xu
abadaa04ab rc-update: add option to remove a service from all runlevels
The -a option,which only applies to the del command, is used to remove a
service from all runlevels.

X-Gentoo-Bug: 497740
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=497740
2014-01-13 10:41:38 -06:00
William Hubbs
3470eda3f5 Rename runscript to openrc-run
This was requested by Debian, because the minicom software, which is
available on Debian and other distros, has a binary named runscript. We
are keeping a backward compatibility symlink for now, but this allows
Debian or any other distro to safely remove the symlink.

X-Gentoo-Bug: 494220
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=494220
2013-12-29 22:57:31 -06:00
William Hubbs
c096ad63ca add openrc binary to ignore patterns 2013-12-13 12:19:27 -06:00
William Hubbs
7a35daeab7 runscript: clarify the message wrt scheduling
The message about a service being scheduled to start was confusing to
some of our users; I was told this wording is more clear.

X-Gentoo-Bug: 493070
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=493070
2013-12-13 01:09:55 -06:00
William Hubbs
7b5fa011ac Rename the rc binary to openrc
Debian requested this rename due to the "rc" binary conflicting with the
"rc" binary from the plan 9 shell.

We also add a deprecation warning to the binary when it is run as rc to
encourage users to switch to openrc instead.

X-Gentoo-Bug: 493958
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=493958
2013-12-12 18:31:29 -06:00
William Hubbs
1fccf91df1 rc-update: make "service already installed" message informational
This message was being sent to stderr, and it should be sent to
stdout since it is informational. This change was requested by
zero_chaos.
2013-12-01 11:20:29 -06:00
Steven Chamberlain
766d71c2d3 Begin port to GNU/kFreeBSD
This is just a minimal port to get Debian up and running; the rest will
be done later.
2013-10-30 01:40:03 -05:00
William Hubbs
aeb670f4e8 librc: do not allow "." and ".." as runlevel names
The rc_runlevel_exists function was attempting to treat "." and ".." as
valid runlevels; however, this should not be allowed.

X-Gentoo-Bug: 488710
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=488710
2013-10-21 14:21:22 -05:00
William Hubbs
48981be8a8 Revert "Make einfo routines private"
This reverts commit de88aff0a8.
I was advised that splashutils links to libeinfo, so we do have a
consumer for this library.
2013-10-21 13:49:41 -05:00
William Hubbs
f751e14416 convert flock() messages to verbose warnings
Convert these messages to warnings that are only displayed if
EINFO_VERBOSE is set to yes in the environment.

This is based on a suggestion from Patrick Lauer <patrick@gentoo.org>.

X-Gentoo-Bug: 487588
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=487588
2013-10-12 09:38:09 -05:00
William Hubbs
82378bd92d start-stop-daemon: fix do_stop calls
Several calls to do_stop were forcing the test parameter to be true,
which was causing extra output to the terminal, such as:

* Would send signal 0 to pid xxxxx

This should only happen if the --test command line option was used.
2013-10-06 12:00:37 -05:00
Natanael Copa
03c67bcc27 librc: fix a read off-by-one bug
We should first check if we are within bounds and then read rather than
the opposite.

This makes valgrind happy.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
2013-10-04 14:02:02 -05:00
Natanael Copa
681a37e7bd librc: fix off-by-one bug
We need allocate space for both the added leading '-' and the trailing
'\0'.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
2013-10-04 14:01:46 -05:00
William Hubbs
56d592866c start-stop-daemon: fix eerorr calls in get_pid
The eerror calls in this function make it too verbose, so change them to
ewarnv() calls instead. This means that they will only print if the
--verbose option is used or EINFO_VERBOSE=yes is set in the environment.
2013-09-30 16:55:25 -05:00
William Hubbs
de88aff0a8 Make einfo routines private
The libeinfo library has no consumers other than OpenRC, so there is no
reason for it to be maintained as a library. The einfo routines are now
an object that links with the rc binary.
2013-09-26 22:18:21 -05:00
William Hubbs
9e989227ab start-stop-daemon: remove the verbose variable
Along the same lines as the quiet variable, this is controlled by an
environment variable for the einfo code, so we do not need a separate
boolean flag.
2013-09-24 01:47:17 -05:00
William Hubbs
d6436bed09 start-stop-daemon: remove the quiet variable
The suppression of output is controlled in the e* functions themselves,
so there is no need for a variable to test in start-stop-daemon.

X-Gentoo-Bug: 482396
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=482396
2013-09-23 17:28:39 -05:00
William Hubbs
4480f1f395 rc: add service to ignore patterns 2013-09-23 13:37:21 -05:00
William Hubbs
0ba14ae720 style fixes 2013-09-23 12:40:26 -05:00
Alexander V Vershilov
7716bf31de Fix stacked runlevel support
Patch was provided by  Max Hacking <max.gentoo.bugzilla@hacking.co.uk>
and slightly fixed by Alexander Vershilov <qnikst@gentoo.org> and
William Hubbs <williamh@gentoo.org>.

Fixes:
1). Rebase to newest OpenRC version.
2). Remove code style fixes. Port to currect code style.
3). Fix rc_runlevel_stack instead of introducing new function.
4). Make get_runlevel_chain a private function.

X-Gentoo-Bug: 467368
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=467368
2013-09-20 14:27:31 -05:00
William Hubbs
445b297360 rc: add support for suppressing error messages
Add support for suppressing error messages with --quiet specified twice
on the command line.

X-Gentoo-Bug: 482396
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=482396
2013-09-03 19:05:13 -05:00
William Hubbs
2590bf7a2b libeinfo: add separate variable to suppress eerror messages
Add an EERROR_QUIET environment variable which works like EINFO_QUIET
but for the eerror functions. This will allow library consumers to
choose whether to suppress eerror messages separately from einfo and
ewarn messages.

X-Gentoo-Bug: 482396
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=482396
2013-09-03 13:03:55 -05:00
William Hubbs
a78b18e291 libeinfo: suppress output for eerror* functions
This makes the eerror* functions honor the EINFO_QUIET environment
variable like the einfo* and ewarn* functions.

X-Gentoo-Bug: 482396
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=482396
2013-08-28 14:23:46 -05:00
William Hubbs
72b58b9e6b Revert "Libeinfo: do not suppress ewarn() messages"
This reverts commit 4ee62c7903.

The previously referenced commit broke consistency because ewarnx() was
respecting the EINFO_QUIET environment setting, but after this commit,
ewarn() was not.
Also, due to discussion on the below referenced bugs, I think we do
want to suppress warnings when EINFO_QUIET=yes.

X-Gentoo-Bug: 482396
X-Gentoo-Bug: 439174
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=482396
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=439174
2013-08-27 10:26:48 -05:00
William Hubbs
5c3e5d801b start-stop-daemon: remove redundant test of the quiet value
The einfo() function tests for the EINFO_QUIET environment variable
directly, and this is the variable that is set by the --quiet flag, so
there was no reason for this test to exist.
2013-08-26 17:09:18 -05:00
William Hubbs
bb8a9c087d start-stop-daemon: fix --quiet switch
The --quiet switch wasn't really quiet, because we changed it to report
errors. I am changing it back due to discussions on the listed bugs.

X-Gentoo-Bug: 482396
X-Gentoo-Bug: 439174
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=482396
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=439174
2013-08-26 15:51:11 -05:00
Gary
9ebd5a6aff Add support for DragonFly BSD 2013-07-25 22:33:24 -05:00
Alexander V Vershilov
c18d623dc0 rc-status: fix typo
X-Gentoo-Bug: 477318
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=477318
2013-07-19 15:30:28 -05:00
Alexander V Vershilov
0f70cd067f rc-status: fix -a to show all services
We need to unset rc_svcname so that all of the services are added to the
list to display.

X-Gentoo-Bug: 409787
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=409787
2013-07-16 12:53:03 -05:00
William Hubbs
a09a60c4cf Add service applet
The service applet is equivalent to rc-service. This was added so that
we will be more compatible with Debian and Fedora.

Reported-by: cardoe@gentoo.org
X-Gentoo-Bug: 468168
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=468168
2013-05-02 13:52:27 -05:00
William Hubbs
70628a875b fix the build for non-selinux systems
The symlinks should be created only if MKSELINUX=yes, not if it just has
a value.
2013-05-01 18:20:01 -05:00
William Hubbs
10a4385e40 rc: allow switching runlevels without stopping services
OpenRC, by default, stops all services that are not listed in a runlevel
when rc is used to switch runlevels. This adds a -n/--no-stop command
line option to rc which tells it to skip stopping the services which are
not in the runlevel.

Reported-by: gentoo@thoth.purplefrog.com
X-Gentoo-Bug: 372585
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=372585
2013-04-28 12:51:12 -05:00
Natanael Copa
e4668a5061 Fix autodetection of lxc
The /proc/1/environ contains various \0 terminated strings. The current
code will only work when the search string is in the first of those.

To fix this we look for strings in entire buffer.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
2013-04-09 02:25:26 -05:00
Andrew Gregory
fb10b97172 rc-service: add usage message
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2013-02-25 14:45:39 -06:00
Andrew Gregory
927207c1b7 rc-status: improve usage message accuracy and consistency
This makes it more clear that many of the options are used as an
alternative to a runlevel.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2013-02-25 14:44:04 -06:00
Andrew Gregory
5872bf1333 rc-update: improve usage message accuracy and consistency
The old message did not indicate that the runlevel argument was optional
for add and del or that it could be used with show.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2013-02-25 14:41:30 -06:00
Andrew Gregory
67377cc09f rc: add usage message
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2013-02-25 14:39:50 -06:00
Andrew Gregory
8c90042dee make BINDIR and SBINDIR available to input files
BINDIR and SBINDIR can be set independently of PREFIX and may not be set
to PREFIX/bin as scripts currently assume.

Note from William Hubbs:

This adds @BINDIR@ and @SBINDIR@ macros to the sed commands run to
convert *.in files to the executable form.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2013-02-23 20:30:39 -06:00
Alexander Mezin
970893adf3 runscript: retry prefix flock if it is interrupted by a signal
Reported-by: Pacho Ramos <pacho2@gentoo.org>
X-Gentoo-Bug: 434800
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=434800
2013-02-15 13:28:35 -06:00
Andrew Gregory
3896b9d55c libeinfo: check for "color" in the terminal name
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2013-01-04 08:48:08 -06:00
William Hubbs
630d23283a Add tools directory
This directory will contain tools which are not necessary for OpenRC to
run, but which some users have found useful.

The first of these is deptree2dot, which converts /run/openrc/deptree to
a .dot file for use with graphviz. This can assist in finding circular
dependencies.
2013-01-02 18:00:04 -06:00