---
name: "rc_service"
section: "3"
platform: "linux"
package: "librc-dev"
version: "0.56-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/rc_service"
---

# rc\_service(3)

functions to query OpenRC services

## NAME

**rc\_service\_add**, **rc\_service\_delete**, **rc\_service\_daemon\_set**, **rc\_service\_description**, **rc\_service\_exists**, **rc\_service\_in\_runlevel**, **rc\_service\_mark**, **rc\_service\_extra\_commands**, **rc\_service\_plugable**, **rc\_service\_resolve**, **rc\_service\_schedule\_start**, **rc\_services\_scheduled\_by**, **rc\_service\_schedule\_clear**, **rc\_service\_state**, **rc\_service\_started\_daemon**, **rc\_service\_value\_get**, **rc\_service\_value\_set**, **rc\_services\_in\_runlevel**, **rc\_services\_in\_state**, **rc\_services\_scheduled**, **rc\_service\_daemons\_crashed** – functions to query OpenRC services

## LIBRARY

Run Command library (librc, -lrc)

## SYNOPSIS

**#include \<rc.h\>**

*bool* *Fn* *rc\_service\_add* *const char \*runlevel* *const char \*service*\

*bool* *Fn* *rc\_service\_delete* *const char \*runlevel* *const char \*service*\

*bool* *Fo* *rc\_service\_daemon\_set*\
 *const char \*service* *const char \*exec* *const char \*name* *const char \*pidfile* *bool started*);

*char \** *Fo* *rc\_service\_description*\
 *const char \*service* *const char \*option*);

*bool* *Fn* *rc\_service\_exists* *const char \*service*\

*bool* *Fn* *rc\_service\_in\_runlevel* *const char \*service* *const char \*runlevel*\

*bool* *Fn* *rc\_service\_mark* *const char \*service* *RC\_SERVICE state*\

*RC\_STRINGLIST \** *Fn* *rc\_service\_extra\_commands* *const char \*service*\

*bool* *Fn* *rc\_service\_plugable* *const char \*service*\

*char \** *rc\_service\_resolve* *const char \*service*\

*bool* *Fo* *rc\_service\_schedule\_start*\
 *const char \*service* *const char \*service\_to\_start*);

*RC\_STRINGLIST \** *Fn* *rc\_services\_scheduled\_by* *const char \*service*\

*bool* *Fn* *rc\_service\_schedule\_clear* *const char \*service*\

*RC\_SERVICE* *Fn* *rc\_service\_state* *const char \*service*\

*bool* *Fo* *rc\_service\_started\_daemon*\
 *const char \*service* *const char \*exec* *int indx*);

*char \** *Fn* *rc\_service\_value\_get* *const char \*service* *const char \*option*\

*bool* *Fo* *rc\_service\_value\_set*\
 *const char \*service* *const char \*option* *const char \*value*);

*RC\_STRINGLIST \** *Fn* *rc\_services\_in\_runlevel* *const char \*runlevel*\

*RC\_STRINGLIST \** *Fn* *rc\_services\_in\_state* *RC\_SERVICE state*\

*RC\_STRINGLIST \** *Fn* *rc\_services\_scheduled* *const char \*service*\

*bool* *Fn* *rc\_service\_daemons\_crashed* *const char \*service*\

## DESCRIPTION

These functions provide a means of querying OpenRC services to find out the state of each one, to start and stop it, and any other functions related to it.

Most functions should be self descriptive as to what they do and what they return based on names and arguments.

**rc\_service\_add**() adds the *service* to the *runlevel*.

**rc\_service\_delete**() deletes the *service* from the *runlevel*.

**rc\_service\_daemon\_set**() saves the arguments in the *service* state data so that **rc\_service\_daemons\_crashed**() can check to see if they are still running or not.

**rc\_service\_description**() returns the *description* variable of the *service*. If *option* is not null then we return the *description\_$option* variable instead.

**rc\_service\_exists**() returns true if the *service* exists, otherwise false.

**rc\_service\_in\_runlevel**() returns true if the *service* is in the *runlevel*, otherwise false.

**rc\_service\_mark**() puts the *service* into the given *state*. If the state is RC\_SERVICE\_STOPPED then all data associated with the *service* is lost. **rc\_service\_extra\_commands**() returns a list of extra commands the *service* supports beyond the default ones. See **openrc-run** for default commands.

**rc\_service\_plugable**() returns true if the service is allowed to be plugged by *rc.conf*. Default is true.

**rc\_service\_resolve**() resolves *service* to the full path of service that was started, or would be started.

When *service* starts, it starts *service\_to\_start* afterwards as directed by **rc\_service\_schedule\_start**(). **rc\_services\_scheduled**() returns a list of services that will be started when *service* starts. **rc\_service\_schedule\_clear**() clears these scheduled services for *service*.

**rc\_service\_state**(*returns*, *the*, *state*, *of*) *service*. The return value is a bitmask, where more than one state can apply.

**rc\_service\_started\_daemon**() checks to see if *service* started *exec* using **start-stop-daemon**. If *indx* is greater than zero, then it must also be the nth daemon started by *service*. **rc\_service\_value\_set**() saves the *value* under the name *option*. **rc\_service\_value\_get**() returns the value of the saved *option*.

**rc\_services\_in\_runlevel**() returns a list of services in *runlevel*. If *runlevel* is not specified, then it returns a list of all available services.

**rc\_services\_in\_state**() returns a list of all the services in *state*.

## IMPLEMENTATION NOTES

Each function that returns char \* returns a malloced NULL terminated string that should be freed when done.

Each function that returns RC\_STRINGLIST \* should be freed using **rc\_stringlist\_free**() when done.

When a function fails it should either return false or NULL and set *errno* unless specified otherwise as above.

## FILES

*/run/openrc* normally holds the volatile state data for services on a RAM backed disk.

## SEE ALSO

[errno(3)](/errno/3.md), [malloc(3)](/malloc/3.md), [free(3)](/free/3.md) [rc\_stringlist\_free(3)](/rc_stringlist_free/3.md), [start-stop-daemon(8)](/start-stop-daemon/8.md)

## AUTHORS

Roy Marples \<roy@marples.name\>
