2007-09-25 21:08:21 +05:30
|
|
|
/*!
|
|
|
|
* @file rc.h
|
|
|
|
* @brief Describes how to interface with the RC library
|
|
|
|
* @internal
|
|
|
|
*
|
|
|
|
* Copyright 2007 Gentoo Foundation
|
|
|
|
* Released under the GPLv2
|
|
|
|
*/
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
#ifndef __RC_H__
|
|
|
|
#define __RC_H__
|
|
|
|
|
2007-04-05 20:31:09 +05:30
|
|
|
#ifdef __GNUC__
|
2007-09-25 21:08:21 +05:30
|
|
|
# define GCC_VERSION (__GNUC__ * 1000 + __GNUC__MINOR)
|
2007-07-10 17:12:56 +05:30
|
|
|
# if (GCC_VERSION >= 3005)
|
|
|
|
# define SENTINEL __attribute__ ((__sentinel__))
|
|
|
|
# endif
|
2007-04-05 20:31:09 +05:30
|
|
|
#endif
|
2007-09-25 21:08:21 +05:30
|
|
|
#ifndef SENTINEL
|
|
|
|
# define SENTINEL
|
|
|
|
#endif
|
2007-04-05 20:31:09 +05:30
|
|
|
|
2007-04-05 16:48:42 +05:30
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdbool.h>
|
2007-08-09 20:03:20 +05:30
|
|
|
#include <stdio.h>
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! @name Reserved runlevel names */
|
2007-04-12 18:48:52 +05:30
|
|
|
#define RC_LEVEL_SYSINIT "sysinit"
|
|
|
|
#define RC_LEVEL_SINGLE "single"
|
|
|
|
#define RC_LEVEL_SHUTDOWN "shutdown"
|
|
|
|
#define RC_LEVEL_REBOOT "reboot"
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! @name rc_ls_dir options */
|
|
|
|
/*! Ensure that an init.d service exists for each file returned */
|
|
|
|
#define RC_LS_INITD 0x01
|
|
|
|
|
|
|
|
/*! @name RC
|
|
|
|
* A service can be given as a full path or just its name.
|
|
|
|
* If its just a name then we try to resolve the service to a full path.
|
|
|
|
* This should allow the use if local init.d directories in the future. */
|
|
|
|
|
|
|
|
/*! @brief States a service can be in */
|
2007-04-05 16:48:42 +05:30
|
|
|
typedef enum
|
|
|
|
{
|
2007-09-28 17:59:23 +05:30
|
|
|
/* These are actual states
|
|
|
|
* The service has to be in one only at all times */
|
2007-09-28 20:23:38 +05:30
|
|
|
RC_SERVICE_STOPPED = 0x0001,
|
|
|
|
RC_SERVICE_STARTED = 0x0002,
|
2007-09-28 17:59:23 +05:30
|
|
|
RC_SERVICE_STOPPING = 0x0004,
|
2007-09-28 20:23:38 +05:30
|
|
|
RC_SERVICE_STARTING = 0x0008,
|
|
|
|
RC_SERVICE_INACTIVE = 0x0010,
|
2007-09-28 17:59:23 +05:30
|
|
|
|
|
|
|
/* Service may or may not have been coldplugged */
|
2007-09-28 20:23:38 +05:30
|
|
|
RC_SERVICE_COLDPLUGGED = 0x0100,
|
2007-09-28 17:59:23 +05:30
|
|
|
|
|
|
|
/* Optional states service could also be in */
|
2007-09-28 20:23:38 +05:30
|
|
|
RC_SERVICE_FAILED = 0x0200,
|
|
|
|
RC_SERVICE_SCHEDULED = 0x0400,
|
|
|
|
RC_SERVICE_WASINACTIVE = 0x0800,
|
2007-04-05 16:48:42 +05:30
|
|
|
} rc_service_state_t;
|
|
|
|
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Resolves a service name to its full path.
|
|
|
|
* @param service to check
|
|
|
|
* @return pointer to full path of service */
|
2007-04-05 16:48:42 +05:30
|
|
|
char *rc_resolve_service (const char *service);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Checks if a service exists or not.
|
|
|
|
* @param service to check
|
2007-09-25 23:00:07 +05:30
|
|
|
* @return true if service exists, otherwise false */
|
|
|
|
bool rc_service_exists (const char *service);
|
2007-09-25 21:08:21 +05:30
|
|
|
|
|
|
|
/*! Lists the extra options a service has
|
|
|
|
* @param service to load the options from
|
|
|
|
* @return NULL terminated string list of options */
|
2007-07-11 00:39:41 +05:30
|
|
|
char **rc_service_options (const char *service);
|
2007-09-25 21:08:21 +05:30
|
|
|
|
|
|
|
/*! 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 */
|
2007-07-11 00:44:37 +05:30
|
|
|
char *rc_service_description (const char *service, const char *option);
|
2007-09-25 21:08:21 +05:30
|
|
|
|
|
|
|
/*! Checks if a service is in a runlevel
|
|
|
|
* @param service to check
|
|
|
|
* @param runlevel it should be in
|
2007-09-25 23:00:07 +05:30
|
|
|
* @return true if service is in the runlevel, otherwise false */
|
|
|
|
bool rc_service_in_runlevel (const char *service, const char *runlevel);
|
2007-09-25 21:08:21 +05:30
|
|
|
|
|
|
|
/*! Checks if a service in in a state
|
|
|
|
* @param service to check
|
2007-09-28 20:23:38 +05:30
|
|
|
* @return state of the service */
|
|
|
|
rc_service_state_t rc_service_state (const char *service);
|
2007-09-25 21:08:21 +05:30
|
|
|
|
|
|
|
/*! Marks the service state
|
|
|
|
* @param service to mark
|
|
|
|
* @param state service should be in
|
2007-09-25 23:00:07 +05:30
|
|
|
* @return true if service state change was successful, otherwise false */
|
|
|
|
bool rc_mark_service (const char *service, rc_service_state_t state);
|
2007-09-25 21:08:21 +05:30
|
|
|
|
|
|
|
/*! Stop a service
|
|
|
|
* @param service to stop
|
|
|
|
* @return pid of service stopping process */
|
2007-04-05 16:48:42 +05:30
|
|
|
pid_t rc_stop_service (const char *service);
|
2007-09-25 21:08:21 +05:30
|
|
|
|
|
|
|
/*! Start a service
|
|
|
|
* @param service to start
|
|
|
|
* @return pid of the service starting process */
|
2007-04-05 16:48:42 +05:30
|
|
|
pid_t rc_start_service (const char *service);
|
2007-09-25 21:08:21 +05:30
|
|
|
|
|
|
|
/*! Wait for a process to finish
|
|
|
|
* @param pid to wait for
|
|
|
|
* @return exit status of the process */
|
2007-04-21 00:28:42 +05:30
|
|
|
int rc_waitpid (pid_t pid);
|
2007-09-25 21:08:21 +05:30
|
|
|
|
|
|
|
/*! 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 */
|
2007-04-05 16:48:42 +05:30
|
|
|
void rc_schedule_start_service (const char *service,
|
2007-04-11 18:14:47 +05:30
|
|
|
const char *service_to_start);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! 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 */
|
2007-04-05 16:48:42 +05:30
|
|
|
char **rc_services_scheduled_by (const char *service);
|
2007-09-25 21:08:21 +05:30
|
|
|
|
|
|
|
/*! Clear the list of services scheduled to be started by this service
|
|
|
|
* @param service to clear */
|
2007-04-05 16:48:42 +05:30
|
|
|
void rc_schedule_clear (const char *service);
|
2007-09-25 21:08:21 +05:30
|
|
|
|
|
|
|
/*! Wait for a service to finish
|
|
|
|
* @param service to wait for
|
2007-09-25 23:00:07 +05:30
|
|
|
* @return true if service finished before timeout, otherwise false */
|
|
|
|
bool rc_wait_service (const char *service);
|
2007-09-25 21:08:21 +05:30
|
|
|
|
|
|
|
/*! Return a saved value for a service
|
|
|
|
* @param service to check
|
|
|
|
* @param option to load
|
|
|
|
* @return saved value */
|
|
|
|
char *rc_get_service_option (const char *service, const char *option);
|
|
|
|
/*! Save a persistent value for a service
|
|
|
|
* @param service to save for
|
|
|
|
* @param option to save
|
|
|
|
* @param value of the option
|
2007-09-25 23:00:07 +05:30
|
|
|
* @return true if saved, otherwise false */
|
|
|
|
bool rc_set_service_option (const char *service, const char *option,
|
|
|
|
const char *value);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Save the arguments to find a running daemon
|
|
|
|
* @param service to save arguments for
|
|
|
|
* @param exec that we started
|
|
|
|
* @param name of the process (optional)
|
|
|
|
* @param pidfile of the process (optional)
|
2007-09-25 23:00:07 +05:30
|
|
|
* @param started if true, add the arguments otherwise remove existing matching arguments */
|
|
|
|
void rc_set_service_daemon (const char *service, const char *exec,
|
|
|
|
const char *name, const char *pidfile,
|
|
|
|
bool started);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! 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)
|
2007-09-25 23:00:07 +05:30
|
|
|
* @return true if started by this service, otherwise false */
|
|
|
|
bool rc_service_started_daemon (const char *service, const char *exec,
|
|
|
|
int indx);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Check if the service is allowed to be hot/cold plugged
|
|
|
|
* @param service to check
|
2007-09-25 23:00:07 +05:30
|
|
|
* @return true if allowed, otherwise false */
|
|
|
|
bool rc_allow_plug (char *service);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Return the current runlevel.
|
|
|
|
* @return the current runlevel */
|
2007-04-05 16:48:42 +05:30
|
|
|
char *rc_get_runlevel (void);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Set the runlevel.
|
|
|
|
* This just changes the stored runlevel and does not start or stop any services.
|
|
|
|
* @param runlevel to store */
|
2007-04-05 16:48:42 +05:30
|
|
|
void rc_set_runlevel (const char *runlevel);
|
2007-09-25 21:08:21 +05:30
|
|
|
|
|
|
|
/*! Checks if the runlevel exists or not
|
|
|
|
* @param runlevel to check
|
2007-09-25 23:00:07 +05:30
|
|
|
* @return true if the runlevel exists, otherwise false */
|
|
|
|
bool rc_runlevel_exists (const char *runlevel);
|
2007-09-25 21:08:21 +05:30
|
|
|
|
|
|
|
/*! Return a NULL terminated list of runlevels
|
|
|
|
* @return a NULL terminated list of runlevels */
|
2007-04-05 16:48:42 +05:30
|
|
|
char **rc_get_runlevels (void);
|
2007-09-25 21:08:21 +05:30
|
|
|
|
|
|
|
/*! Is the runlevel starting?
|
2007-09-25 23:00:07 +05:30
|
|
|
* @return true if yes, otherwise false */
|
|
|
|
bool rc_runlevel_starting (void);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Is the runlevel stopping?
|
2007-09-25 23:00:07 +05:30
|
|
|
* @return true if yes, otherwise false */
|
|
|
|
bool rc_runlevel_stopping (void);
|
2007-09-25 21:08:21 +05:30
|
|
|
|
|
|
|
/*! Add the service to the runlevel
|
|
|
|
* @param runlevel to add to
|
|
|
|
* @param service to add
|
2007-09-25 23:00:07 +05:30
|
|
|
* @return true if successful, otherwise false */
|
|
|
|
bool rc_service_add (const char *runlevel, const char *service);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Remove the service from the runlevel
|
|
|
|
* @param runlevel to remove from
|
|
|
|
* @param service to remove
|
2007-09-25 23:00:07 +05:30
|
|
|
* @return true if sucessful, otherwise false */
|
|
|
|
bool rc_service_delete (const char *runlevel, const char *service);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! List the services in a runlevel
|
|
|
|
* @param runlevel to list
|
|
|
|
* @return NULL terminated list of services */
|
2007-04-05 16:48:42 +05:30
|
|
|
char **rc_services_in_runlevel (const char *runlevel);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! List the services in a state
|
|
|
|
* @param state to list
|
|
|
|
* @return NULL terminated list of services */
|
2007-04-05 16:48:42 +05:30
|
|
|
char **rc_services_in_state (rc_service_state_t state);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! List the services shceduled to start when this one does
|
|
|
|
* @param service to check
|
|
|
|
* @return NULL terminated list of services */
|
2007-04-05 16:48:42 +05:30
|
|
|
char **rc_services_scheduled (const char *service);
|
|
|
|
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Find processes based on criteria.
|
|
|
|
* All of these are optional.
|
|
|
|
* pid overrides anything else.
|
|
|
|
* If both exec and cmd are given then we ignore exec.
|
|
|
|
* @param exec to check for
|
|
|
|
* @param cmd to check for
|
|
|
|
* @param uid to check for
|
|
|
|
* @param pid to check for
|
|
|
|
* @return NULL terminated list of pids */
|
2007-04-05 16:48:42 +05:30
|
|
|
pid_t *rc_find_pids (const char *exec, const char *cmd,
|
2007-04-11 18:14:47 +05:30
|
|
|
uid_t uid, pid_t pid);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Checks that all daemons started with start-stop-daemon by the service
|
|
|
|
* are still running.
|
|
|
|
* @param service to check
|
2007-09-25 23:00:07 +05:30
|
|
|
* @return true if all daemons started are still running, otherwise false */
|
|
|
|
bool rc_service_daemons_crashed (const char *service);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! @name Dependency options
|
|
|
|
* These options can change the services found by the rc_get_depinfo and
|
|
|
|
* rc_get_depends functions. */
|
|
|
|
/*! Trace provided services */
|
|
|
|
#define RC_DEP_TRACE 0x01
|
|
|
|
/*! Only use services added to runlevels */
|
|
|
|
#define RC_DEP_STRICT 0x02
|
|
|
|
/*! Runlevel is starting */
|
|
|
|
#define RC_DEP_START 0x04
|
|
|
|
/*! Runlevel is stopping */
|
|
|
|
#define RC_DEP_STOP 0x08
|
|
|
|
|
|
|
|
/*! @name Dependencies
|
|
|
|
* We analyse each init script and cache the resultant dependency tree.
|
2007-09-28 04:46:40 +05:30
|
|
|
* This tree can be accessed using the below functions. */
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-09-28 04:46:40 +05:30
|
|
|
#ifndef _IN_LIBRC
|
|
|
|
/* Handles to internal structures */
|
|
|
|
typedef void *rc_deptype_t;
|
|
|
|
typedef void *rc_depinfo_t;
|
|
|
|
#endif
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! 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.
|
|
|
|
* @param force an update
|
|
|
|
* @return 0 if successful, otherwise -1 */
|
2007-04-05 16:48:42 +05:30
|
|
|
int rc_update_deptree (bool force);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Load the cached dependency tree and return a pointer to it.
|
|
|
|
* This pointer should be freed with rc_free_deptree when done.
|
|
|
|
* @return pointer to the dependency tree */
|
2007-04-05 16:48:42 +05:30
|
|
|
rc_depinfo_t *rc_load_deptree (void);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Get a services depedency information from a loaded tree
|
|
|
|
* @param deptree to search
|
|
|
|
* @param service to find
|
|
|
|
* @return service dependency information */
|
2007-04-05 16:48:42 +05:30
|
|
|
rc_depinfo_t *rc_get_depinfo (rc_depinfo_t *deptree, const char *service);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Get a depenency type from the service dependency information
|
|
|
|
* @param depinfo service dependency to search
|
|
|
|
* @param type to find
|
|
|
|
* @return service dependency type information */
|
2007-04-05 16:48:42 +05:30
|
|
|
rc_deptype_t *rc_get_deptype (rc_depinfo_t *depinfo, const char *type);
|
|
|
|
char **rc_get_depends (rc_depinfo_t *deptree, char **types,
|
2007-04-11 18:14:47 +05:30
|
|
|
char **services, const char *runlevel, int options);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! List all the services that should be stoppned and then started, in order,
|
|
|
|
* for the given runlevel, including sysinit and boot services where
|
|
|
|
* approriate.
|
|
|
|
* @param deptree to search
|
|
|
|
* @param runlevel to change into
|
|
|
|
* @param options to pass
|
|
|
|
* @return NULL terminated list of services in order */
|
2007-04-05 16:48:42 +05:30
|
|
|
char **rc_order_services (rc_depinfo_t *deptree, const char *runlevel,
|
2007-04-11 18:14:47 +05:30
|
|
|
int options);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Free a deptree and its information
|
|
|
|
* @param deptree to free */
|
2007-04-05 16:48:42 +05:30
|
|
|
void rc_free_deptree (rc_depinfo_t *deptree);
|
|
|
|
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! @name Plugins
|
|
|
|
* For each plugin loaded we will call rc_plugin_hook with the below
|
|
|
|
* enum and either the runlevel name or service name.
|
|
|
|
*
|
|
|
|
* Plugins are called when rc does something. This does not indicate an
|
|
|
|
* end result and the plugin should use the above functions to query things
|
|
|
|
* like service status.
|
|
|
|
*
|
|
|
|
* The service hooks have extra ones - now and done. This is because after
|
|
|
|
* start_in we may start other services before we start the service in
|
|
|
|
* question. now shows we really will start the service now and done shows
|
|
|
|
* when we have done it as may start scheduled services at this point. */
|
|
|
|
/*! Points at which a plugin can hook into RC */
|
2007-04-05 16:48:42 +05:30
|
|
|
typedef enum
|
|
|
|
{
|
2007-09-28 17:59:23 +05:30
|
|
|
RC_HOOK_RUNLEVEL_STOP_IN = 1,
|
|
|
|
RC_HOOK_RUNLEVEL_STOP_OUT = 4,
|
|
|
|
RC_HOOK_RUNLEVEL_START_IN = 5,
|
|
|
|
RC_HOOK_RUNLEVEL_START_OUT = 8,
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! We send the abort if an init script requests we abort and drop
|
2007-04-20 20:32:13 +05:30
|
|
|
* into single user mode if system not fully booted */
|
2007-09-28 17:59:23 +05:30
|
|
|
RC_HOOK_ABORT = 99,
|
|
|
|
RC_HOOK_SERVICE_STOP_IN = 101,
|
|
|
|
RC_HOOK_SERVICE_STOP_NOW = 102,
|
|
|
|
RC_HOOK_SERVICE_STOP_DONE = 103,
|
|
|
|
RC_HOOK_SERVICE_STOP_OUT = 104,
|
|
|
|
RC_HOOK_SERVICE_START_IN = 105,
|
|
|
|
RC_HOOK_SERVICE_START_NOW = 106,
|
|
|
|
RC_HOOK_SERVICE_START_DONE = 107,
|
|
|
|
RC_HOOK_SERVICE_START_OUT = 108
|
2007-04-05 16:48:42 +05:30
|
|
|
} rc_hook_t;
|
|
|
|
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! 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);
|
|
|
|
|
|
|
|
/*! Plugins should write FOO=BAR to this fd to set any environment
|
|
|
|
* variables they wish. Variables should be separated by NULLs. */
|
2007-04-20 15:09:47 +05:30
|
|
|
extern FILE *rc_environ_fd;
|
|
|
|
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! @name Memory Allocation
|
|
|
|
* Ensure that if we cannot allocate the memory then we exit */
|
|
|
|
/*@{*/
|
|
|
|
/*! Allocate a block of memory
|
|
|
|
* @param size of memory to allocate
|
|
|
|
* @return pointer to memory */
|
2007-08-03 15:44:38 +05:30
|
|
|
void *rc_xmalloc (size_t size);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Re-size a block of memory
|
|
|
|
* @param ptr to the block of memory to re-size
|
|
|
|
* @param size memory should be
|
|
|
|
* @return pointer to memory block */
|
2007-08-03 15:44:38 +05:30
|
|
|
void *rc_xrealloc (void *ptr, size_t size);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Duplicate a NULL terminated string
|
|
|
|
* @param str to duplicate
|
|
|
|
* @return pointer to the new string */
|
2007-08-03 15:44:38 +05:30
|
|
|
char *rc_xstrdup (const char *str);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*@}*/
|
2007-08-03 15:44:38 +05:30
|
|
|
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! @name Utility
|
|
|
|
* Although not RC specific functions, they are used by the supporting
|
|
|
|
* applications */
|
|
|
|
/*! 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 */
|
2007-08-03 15:44:38 +05:30
|
|
|
char *rc_strcatpaths (const char *path1, const char *paths, ...) SENTINEL;
|
2007-09-26 12:35:33 +05:30
|
|
|
/*! Check if an environment 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.
|
2007-09-25 21:08:21 +05:30
|
|
|
* @param variable to check
|
2007-09-26 12:35:33 +05:30
|
|
|
* @return true if it matches true, yes or 1, false if otherwise. */
|
|
|
|
bool rc_env_bool (const char *variable);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Check if the file exists or not
|
|
|
|
* @param pathname to check
|
2007-09-25 23:00:07 +05:30
|
|
|
* @return true if it exists, otherwise false */
|
|
|
|
bool rc_exists (const char *pathname);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Check if the file is a real file
|
|
|
|
* @param pathname to check
|
2007-09-25 23:00:07 +05:30
|
|
|
* @return true if it's a real file, otherwise false */
|
|
|
|
bool rc_is_file (const char *pathname);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Check if the file is a symbolic link or not
|
|
|
|
* @param pathname to check
|
2007-09-25 23:00:07 +05:30
|
|
|
* @return true if it's a symbolic link, otherwise false */
|
|
|
|
bool rc_is_link (const char *pathname);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Check if the file is a directory or not
|
|
|
|
* @param pathname to check
|
2007-09-25 23:00:07 +05:30
|
|
|
* @return true if it's a directory, otherwise false */
|
|
|
|
bool rc_is_dir (const char *pathname);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Check if the file is marked executable or not
|
|
|
|
* @param pathname to check
|
2007-09-25 23:00:07 +05:30
|
|
|
* @return true if it's marked executable, otherwise false */
|
|
|
|
bool rc_is_exec (const char *pathname);
|
2007-08-03 15:44:38 +05:30
|
|
|
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Return a NULL terminted sorted list of the contents of the directory
|
|
|
|
* @param dir to list
|
|
|
|
* @param options any options to apply
|
|
|
|
* @return NULL terminated list */
|
2007-09-18 17:34:51 +05:30
|
|
|
char **rc_ls_dir (const char *dir, int options);
|
2007-08-03 15:44:38 +05:30
|
|
|
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Remove a directory
|
|
|
|
* @param pathname to remove
|
|
|
|
* @param top remove the top level directory too
|
2007-09-25 23:00:07 +05:30
|
|
|
* @return true if successful, otherwise false */
|
|
|
|
bool rc_rm_dir (const char *pathname, bool top);
|
2007-08-03 15:44:38 +05:30
|
|
|
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! @name Configuration */
|
|
|
|
/*! Return a NULL terminated list of non comment lines from a file. */
|
2007-09-18 17:34:51 +05:30
|
|
|
char **rc_get_list (const char *file);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Return a NULL terminated list of key=value lines from a file. */
|
2007-09-18 17:34:51 +05:30
|
|
|
char **rc_get_config (const char *file);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Return the value of the entry from a key=value list. */
|
2007-08-03 15:44:38 +05:30
|
|
|
char *rc_get_config_entry (char **list, const char *entry);
|
|
|
|
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Return a NULL terminated string list of variables allowed through
|
|
|
|
* from the current environemnt. */
|
2007-08-03 15:44:38 +05:30
|
|
|
char **rc_filter_env (void);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Return a NULL terminated string list of enviroment variables made from
|
|
|
|
* our configuration files. */
|
2007-09-18 17:50:55 +05:30
|
|
|
char **rc_make_env (void);
|
2007-08-03 15:44:38 +05:30
|
|
|
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! @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.*/
|
|
|
|
/*! 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 */
|
2007-09-18 17:06:55 +05:30
|
|
|
char *rc_strlist_add (char ***list, const char *item);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! 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 */
|
2007-09-18 17:06:55 +05:30
|
|
|
char *rc_strlist_addu (char ***list, const char *item);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! 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 */
|
2007-09-18 17:06:55 +05:30
|
|
|
char *rc_strlist_addsort (char ***list, const char *item);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! 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 */
|
2007-09-18 17:06:55 +05:30
|
|
|
char *rc_strlist_addsortc (char ***list, const char *item);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! 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 */
|
2007-09-18 17:06:55 +05:30
|
|
|
char *rc_strlist_addsortu (char ***list, const char *item);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! 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.
|
2007-09-25 23:02:12 +05:30
|
|
|
* @return true on success, otherwise false */
|
|
|
|
bool rc_strlist_delete (char ***list, const char *item);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! 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);
|
|
|
|
/*! Reverses the contents of the list.
|
|
|
|
* @param list to reverse */
|
2007-08-03 15:44:38 +05:30
|
|
|
void rc_strlist_reverse (char **list);
|
2007-09-25 21:08:21 +05:30
|
|
|
/*! Frees each item on the list and the list itself.
|
|
|
|
* @param list to free */
|
2007-08-03 15:44:38 +05:30
|
|
|
void rc_strlist_free (char **list);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
#endif
|