aboutsummaryrefslogtreecommitdiff
path: root/src/librc/rc.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/librc/rc.h')
-rw-r--r--src/librc/rc.h200
1 files changed, 101 insertions, 99 deletions
diff --git a/src/librc/rc.h b/src/librc/rc.h
index 0b811f46..061959e7 100644
--- a/src/librc/rc.h
+++ b/src/librc/rc.h
@@ -32,15 +32,24 @@
# if (GCC_VERSION >= 3005)
# define SENTINEL __attribute__ ((__sentinel__))
# endif
+# define DEPRECATED __attribute__ ((deprecated))
#endif
#ifndef SENTINEL
# define SENTINEL
#endif
#include <sys/types.h>
+#include <sys/queue.h>
#include <stdbool.h>
#include <stdio.h>
+/* A doubly linked list using queue(3) for ease of use */
+typedef struct rc_string {
+ char *value;
+ TAILQ_ENTRY(rc_string) entries;
+} RC_STRING;
+typedef TAILQ_HEAD(rc_stringlist, rc_string) RC_STRINGLIST;
+
/*! @name Reserved runlevel names */
#define RC_LEVEL_SYSINIT "sysinit"
#define RC_LEVEL_SINGLE "single"
@@ -49,30 +58,30 @@
/*! Return the current runlevel.
* @return the current runlevel */
-char *rc_runlevel_get (void);
+char *rc_runlevel_get(void);
/*! Checks if the runlevel exists or not
* @param runlevel to check
* @return true if the runlevel exists, otherwise false */
-bool rc_runlevel_exists (const char *runlevel);
+bool rc_runlevel_exists(const char *);
/*! Return a NULL terminated list of runlevels
* @return a NULL terminated list of runlevels */
-char **rc_runlevel_list (void);
+RC_STRINGLIST *rc_runlevel_list(void);
/*! Set the runlevel.
* This just changes the stored runlevel and does not start or stop any
* services.
* @param runlevel to store */
-bool rc_runlevel_set (const char *runlevel);
+bool rc_runlevel_set(const char *);
/*! Is the runlevel starting?
* @return true if yes, otherwise false */
-bool rc_runlevel_starting (void);
+bool rc_runlevel_starting(void);
/*! Is the runlevel stopping?
* @return true if yes, otherwise false */
-bool rc_runlevel_stopping (void);
+bool rc_runlevel_stopping(void);
/*! @name RC
* A service can be given as a full path or just its name.
@@ -97,19 +106,19 @@ typedef enum
RC_SERVICE_FAILED = 0x0200,
RC_SERVICE_SCHEDULED = 0x0400,
RC_SERVICE_WASINACTIVE = 0x0800
-} rc_service_state_t;
+} RC_SERVICE;
/*! Add the service to the runlevel
* @param runlevel to add to
* @param service to add
* @return true if successful, otherwise false */
-bool rc_service_add (const char *runlevel, const char *service);
+bool rc_service_add(const char *, const char *);
/*! Remove the service from the runlevel
* @param runlevel to remove from
* @param service to remove
* @return true if sucessful, otherwise false */
-bool rc_service_delete (const char *runlevel, const char *service);
+bool rc_service_delete(const char *, const char *);
/*! Save the arguments to find a running daemon
* @param service to save arguments for
@@ -117,116 +126,113 @@ bool rc_service_delete (const char *runlevel, const char *service);
* @param name of the process (optional)
* @param pidfile of the process (optional)
* @param started if true, add the arguments otherwise remove existing matching arguments */
-bool rc_service_daemon_set (const char *service, const char *const *argv,
- const char *name, const char *pidfile,
- bool started);
+bool rc_service_daemon_set(const char *, const char *const *, const char *, const char *,
+ bool);
/*! Returns a description of what the service and/or option does.
* @param service to check
* @param option to check (if NULL, service description)
* @return a newly allocated pointer to the description */
-char *rc_service_description (const char *service, const char *option);
+char *rc_service_description(const char *, const char *);
/*! Checks if a service exists or not.
* @param service to check
* @return true if service exists, otherwise false */
-bool rc_service_exists (const char *service);
+bool rc_service_exists(const char *);
/*! Checks if a service is in a runlevel
* @param service to check
* @param runlevel it should be in
* @return true if service is in the runlevel, otherwise false */
-bool rc_service_in_runlevel (const char *service, const char *runlevel);
+bool rc_service_in_runlevel(const char *, const char *);
/*! Marks the service state
* @param service to mark
* @param state service should be in
* @return true if service state change was successful, otherwise false */
-bool rc_service_mark (const char *service, rc_service_state_t state);
+bool rc_service_mark(const char *, RC_SERVICE);
/*! Lists the extra commands a service has
* @param service to load the commands from
* @return NULL terminated string list of commands */
-char **rc_service_extra_commands (const char *service);
+RC_STRINGLIST *rc_service_extra_commands(const char *);
/*! Resolves a service name to its full path.
* @param service to check
* @return pointer to full path of service */
-char *rc_service_resolve (const char *service);
+char *rc_service_resolve(const char *);
/*! Schedule a service to be started when another service starts
* @param service that starts the scheduled service when started
* @param service_to_start service that will be started */
-bool rc_service_schedule_start (const char *service,
- const char *service_to_start);
+bool rc_service_schedule_start(const char *, const char *);
+
/*! Return a NULL terminated list of services that are scheduled to start
* when the given service has started
* @param service to check
* @return NULL terminated list of services scheduled to start */
-char **rc_services_scheduled_by (const char *service);
+RC_STRINGLIST *rc_services_scheduled_by(const char *);
/*! Clear the list of services scheduled to be started by this service
* @param service to clear
* @return true if no errors, otherwise false */
-bool rc_service_schedule_clear (const char *service);
+bool rc_service_schedule_clear(const char *);
/*! Checks if a service in in a state
* @param service to check
* @return state of the service */
-rc_service_state_t rc_service_state (const char *service);
+RC_SERVICE rc_service_state(const char *);
/*! Start a service
* @param service to start
* @return pid of the service starting process */
-pid_t rc_service_start (const char *service);
+pid_t rc_service_start(const char *);
/*! Stop a service
* @param service to stop
* @return pid of service stopping process */
-pid_t rc_service_stop (const char *service);
+pid_t rc_service_stop(const char *);
/*! Check if the service started the daemon
* @param service to check
* @param exec to check
* @param indx of the daemon (optional - 1st daemon, 2nd daemon, etc)
* @return true if started by this service, otherwise false */
-bool rc_service_started_daemon (const char *service, const char *const *argv,
- int indx);
+bool rc_service_started_daemon(const char *, const char *const *, int);
/*! Return a saved value for a service
* @param service to check
* @param option to load
* @return saved value */
-char *rc_service_value_get (const char *service, const char *option);
+char *rc_service_value_get(const char *, const char *);
/*! Save a persistent value for a service
* @param service to save for
* @param option to save
* @param value of the option
* @return true if saved, otherwise false */
-bool rc_service_value_set (const char *service, const char *option,
- const char *value);
+bool rc_service_value_set(const char *, const char *, const char *);
/*! List the services in a runlevel
* @param runlevel to list
* @return NULL terminated list of services */
-char **rc_services_in_runlevel (const char *runlevel);
+RC_STRINGLIST *rc_services_in_runlevel(const char *);
/*! List the services in a state
* @param state to list
* @return NULL terminated list of services */
-char **rc_services_in_state (rc_service_state_t state);
+RC_STRINGLIST *rc_services_in_state(RC_SERVICE);
/*! List the services shceduled to start when this one does
* @param service to check
* @return NULL terminated list of services */
-char **rc_services_scheduled (const char *service);
+RC_STRINGLIST *rc_services_scheduled(const char *);
/*! Checks that all daemons started with start-stop-daemon by the service
* are still running.
* @param service to check
* @return true if all daemons started are still running, otherwise false */
-bool rc_service_daemons_crashed (const char *service);
+bool rc_service_daemons_crashed(const char *);
/*! @name System types
* OpenRC can support some special sub system types, normally virtualization.
@@ -238,7 +244,7 @@ bool rc_service_daemons_crashed (const char *service);
#define RC_SYS_VSERVER "VSERVER"
#define RC_SYS_XEN0 "XEN0"
#define RC_SYS_XENU "XENU"
-const char *rc_sys (void);
+const char *rc_sys(void);
/*! @name Dependency options
* These options can change the services found by the rc_get_depinfo and
@@ -256,40 +262,67 @@ const char *rc_sys (void);
* We analyse each init script and cache the resultant dependency tree.
* This tree can be accessed using the below functions. */
-#ifndef _IN_LIBRC
+#ifdef _IN_LIBRC
+/*! @name Dependency structures
+ * private to librc */
+
+/*! Singly linked list of dependency types that list the services the
+ * type is for */
+typedef struct rc_deptype
+{
+ /*! ineed, iuse, iafter, etc */
+ char *type;
+ /*! list of services */
+ RC_STRINGLIST *services;
+ /*! list of types */
+ STAILQ_ENTRY(rc_deptype) entries;
+} RC_DEPTYPE;
+
+/*! Singly linked list of services and their dependencies */
+typedef struct rc_depinfo
+{
+ /*! Name of service */
+ char *service;
+ /*! Dependencies */
+ STAILQ_HEAD(, rc_deptype) depends;
+ /*! List of entries */
+ STAILQ_ENTRY(rc_depinfo) entries;
+} RC_DEPINFO;
+
+typedef STAILQ_HEAD(,rc_depinfo) RC_DEPTREE;
+#else
/* Handles to internal structures */
-typedef void *rc_depinfo_t;
+typedef void *RC_DEPTREE;
#endif
/*! Check to see if source is newer than target.
* If target is a directory then we traverse it and it's children.
* @return true if source is newer than target, otherwise false */
-bool rc_newer_than (const char *source, const char *target);
+bool rc_newer_than(const char *, const char *);
/*! Update the cached dependency tree if it's older than any init script,
* its configuration file or an external configuration file the init script
* has specified.
* @return true if successful, otherwise false */
-bool rc_deptree_update (void);
+bool rc_deptree_update(void);
/*! Check if the cached dependency tree is older than any init script,
* its configuration file or an external configuration file the init script
* has specified.
* @return true if it needs updating, otherwise false */
-bool rc_deptree_update_needed (void);
+bool rc_deptree_update_needed(void);
/*! Load the cached dependency tree and return a pointer to it.
* This pointer should be freed with rc_deptree_free when done.
* @return pointer to the dependency tree */
-rc_depinfo_t *rc_deptree_load (void);
+RC_DEPTREE *rc_deptree_load(void);
/*! List the depend for the type of service
* @param deptree to search
* @param type to use (keywords, etc)
* @param service to check
* @return NULL terminated list of services in order */
-char **rc_deptree_depend (const rc_depinfo_t *deptree,
- const char *type, const char *service);
+RC_STRINGLIST *rc_deptree_depend(const RC_DEPTREE *, const char *, const char *);
/*! List all the services in order that the given services have
* for the given types and options.
@@ -298,10 +331,8 @@ char **rc_deptree_depend (const rc_depinfo_t *deptree,
* @param services to check
* @param options to pass
* @return NULL terminated list of services in order */
-char **rc_deptree_depends (const rc_depinfo_t *deptree,
- const char *const *types,
- const char *const *services, const char *runlevel,
- int options);
+RC_STRINGLIST *rc_deptree_depends(const RC_DEPTREE *, const RC_STRINGLIST *,
+ const RC_STRINGLIST *, const char *, int);
/*! List all the services that should be stoppned and then started, in order,
* for the given runlevel, including sysinit and boot services where
@@ -310,12 +341,11 @@ char **rc_deptree_depends (const rc_depinfo_t *deptree,
* @param runlevel to change into
* @param options to pass
* @return NULL terminated list of services in order */
-char **rc_deptree_order (const rc_depinfo_t *deptree, const char *runlevel,
- int options);
+RC_STRINGLIST *rc_deptree_order(const RC_DEPTREE *, const char *, int);
/*! Free a deptree and its information
* @param deptree to free */
-void rc_deptree_free (rc_depinfo_t *deptree);
+void rc_deptree_free(RC_DEPTREE *);
/*! @name Plugins
* For each plugin loaded we will call rc_plugin_hook with the below
@@ -347,13 +377,13 @@ typedef enum
RC_HOOK_SERVICE_START_NOW = 106,
RC_HOOK_SERVICE_START_DONE = 107,
RC_HOOK_SERVICE_START_OUT = 108
-} rc_hook_t;
+} RC_HOOK;
/*! Plugin entry point
* @param hook point
* @param name of runlevel or service
* @return 0 for success otherwise -1 */
-int rc_plugin_hook (rc_hook_t hook, const char *name);
+int rc_plugin_hook(RC_HOOK, const char *);
/*! Plugins should write FOO=BAR to this fd to set any environment
* variables they wish. Variables should be separated by NULLs. */
@@ -362,91 +392,64 @@ extern FILE *rc_environ_fd;
/*! @name Configuration
* These functions help to deal with shell based configuration files */
/*! Return a line from a file, stripping the trailing newline. */
-char *rc_getline (FILE *fp);
+char *rc_getline(FILE *);
/*! Return a NULL terminated list of non comment lines from a file. */
-char **rc_config_list (const char *file);
+RC_STRINGLIST *rc_config_list(const char *);
/*! Return a NULL terminated list of key=value lines from a file. */
-char **rc_config_load (const char *file);
+RC_STRINGLIST *rc_config_load(const char *);
/*! Return the value of the entry from a key=value list. */
-char *rc_config_value (const char *const *list, const char *entry);
+char *rc_config_value(RC_STRINGLIST *, const char *);
/*! Check if a variable is a boolean and return it's value.
* If variable is not a boolean then we set errno to be ENOENT when it does
* not exist or EINVAL if it's not a boolean.
* @param variable to check
* @return true if it matches true, yes or 1, false if otherwise. */
-bool rc_yesno (const char *variable);
+bool rc_yesno(const char *);
/*! @name String List functions
- * Handy functions for dealing with string arrays of char **.
- * It's safe to assume that any function here that uses char ** is a string
- * list that can be manipulated with the below functions. Every string list
- * should be released with a call to rc_strlist_free. */
+ * Every string list should be released with a call to rc_stringlist_free. */
+
+/*! Create a new stringlinst
+ * @return pointer to new list */
+RC_STRINGLIST *rc_stringlist_new(void);
/*! Duplicate the item, add it to end of the list and return a pointer to it.
* @param list to add the item too
* @param item to add.
* @return pointer to newly added item */
-char *rc_strlist_add (char ***list, const char *item);
+RC_STRING *rc_stringlist_add(RC_STRINGLIST *, const char *);
/*! If the item does not exist in the list, duplicate it, add it to the
* list and then return a pointer to it.
* @param list to add the item too
* @param item to add.
* @return pointer to newly added item */
-char *rc_strlist_addu (char ***list, const char *item);
-
-/*! Duplicate the item, add it to the list at the point based on locale and
- * then return a pointer to it.
- * @param list to add the item too
- * @param item to add.
- * @return pointer to newly added item */
-char *rc_strlist_addsort (char ***list, const char *item);
-
-/*! Duplicate the item, add it to the list at the point based on C locale and
- * then return a pointer to it.
- * @param list to add the item too
- * @param item to add.
- * @return pointer to newly added item */
-char *rc_strlist_addsortc (char ***list, const char *item);
-
-/*! If the item does not exist in the list, duplicate it, add it to the
- * list based on locale and then return a pointer to it.
- * @param list to add the item too
- * @param item to add.
- * @return pointer to newly added item */
-char *rc_strlist_addsortu (char ***list, const char *item);
+RC_STRING *rc_stringlist_addu(RC_STRINGLIST *, const char *);
/*! Free the item and remove it from the list. Return 0 on success otherwise -1.
* @param list to add the item too
* @param item to add.
* @return true on success, otherwise false */
-bool rc_strlist_delete (char ***list, const char *item);
-
-/*! Moves the contents of list2 onto list1, so list2 is effectively emptied.
- * Returns a pointer to the last item on the new list.
- * @param list1 to append to
- * @param list2 to move from
- * @return pointer to the last item on the list */
-char *rc_strlist_join (char ***list1, char **list2);
+bool rc_stringlist_delete(RC_STRINGLIST *, const char *);
-/*! Reverses the contents of the list.
- * @param list to reverse */
-void rc_strlist_reverse (char **list);
+/*! Sort the list according to C locale
+ * @param list to sort */
+void rc_stringlist_sort(RC_STRINGLIST **);
/*! Frees each item on the list and the list itself.
* @param list to free */
-void rc_strlist_free (char **list);
+void rc_stringlist_free(RC_STRINGLIST *);
/*! Concatenate paths adding '/' if needed. The resultant pointer should be
* freed when finished with.
* @param path1 starting path
* @param paths NULL terminated list of paths to add
* @return pointer to the new path */
-char *rc_strcatpaths (const char *path1, const char *paths, ...) SENTINEL;
+char *rc_strcatpaths(const char *, const char *, ...) SENTINEL;
/*! Find processes based on criteria.
* All of these are optional.
@@ -457,7 +460,6 @@ char *rc_strcatpaths (const char *path1, const char *paths, ...) SENTINEL;
* @param uid to check for
* @param pid to check for
* @return NULL terminated list of pids */
-pid_t *rc_find_pids (const char *const *argv, const char *cmd,
- uid_t uid, pid_t pid);
+pid_t *rc_find_pids(const char *const *, const char *, uid_t, pid_t);
#endif