aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/env-update.c6
-rw-r--r--src/librc-depend.c2
-rw-r--r--src/librc-misc.c24
-rw-r--r--src/librc.h6
-rw-r--r--src/rc.h275
5 files changed, 157 insertions, 156 deletions
diff --git a/src/env-update.c b/src/env-update.c
index c9739a78..aef50bc4 100644
--- a/src/env-update.c
+++ b/src/env-update.c
@@ -143,7 +143,7 @@ int env_update (int argc, char **argv)
*(file + j - 1) != '~' &&
(j < 4 || strcmp (file + j - 4, ".bak") != 0) &&
(j < 5 || strcmp (file + j - 5, ".core") != 0))
- entries = rc_get_config (path);
+ entries = rc_config_load (path);
free (path);
STRLIST_FOREACH (entries, entry, j) {
@@ -278,7 +278,7 @@ int env_update (int argc, char **argv)
}
fclose (fp);
- ldent = rc_get_config_entry (envs, "LDPATH");
+ ldent = rc_config_value (envs, "LDPATH");
if (! ldent ||
(argc > 1 && argv[1] && strcmp (argv[1], "--no-ldconfig") == 0))
@@ -298,7 +298,7 @@ int env_update (int argc, char **argv)
if (ldconfig) {
/* Update ld.so.conf only if different */
if (rc_exists (LDSOCONF)) {
- char **lines = rc_get_list (LDSOCONF);
+ char **lines = rc_config_list (LDSOCONF);
char *line;
ld = false;
diff --git a/src/librc-depend.c b/src/librc-depend.c
index d8bad32c..37f5d9ea 100644
--- a/src/librc-depend.c
+++ b/src/librc-depend.c
@@ -629,7 +629,7 @@ bool rc_deptree_update_needed (void)
/* Some init scripts dependencies change depending on config files
* outside of baselayout, like syslog-ng, so we check those too. */
- config = rc_get_list (RC_DEPCONFIG);
+ config = rc_config_list (RC_DEPCONFIG);
STRLIST_FOREACH (config, service, i) {
if (! is_newer_than (RC_DEPTREE, service)) {
newer = true;
diff --git a/src/librc-misc.c b/src/librc-misc.c
index 87e8faef..0d272d56 100644
--- a/src/librc-misc.c
+++ b/src/librc-misc.c
@@ -285,7 +285,7 @@ bool rc_rm_dir (const char *pathname, bool top)
}
librc_hidden_def(rc_rm_dir)
-char **rc_get_config (const char *file)
+char **rc_config_load (const char *file)
{
char **list = NULL;
FILE *fp;
@@ -367,9 +367,9 @@ char **rc_get_config (const char *file)
return (list);
}
-librc_hidden_def(rc_get_config)
+librc_hidden_def(rc_config_load)
-char *rc_get_config_entry (char **list, const char *entry)
+char *rc_config_value (char **list, const char *entry)
{
char *line;
int i;
@@ -383,9 +383,9 @@ char *rc_get_config_entry (char **list, const char *entry)
return (NULL);
}
-librc_hidden_def(rc_get_config_entry)
+librc_hidden_def(rc_config_value)
-char **rc_get_list (const char *file)
+char **rc_config_list (const char *file)
{
FILE *fp;
char buffer[RC_LINEBUFFER];
@@ -417,7 +417,7 @@ char **rc_get_list (const char *file)
return (list);
}
-librc_hidden_def(rc_get_list)
+librc_hidden_def(rc_config_list)
char **rc_filter_env (void)
{
@@ -435,11 +435,11 @@ char **rc_filter_env (void)
char *e;
int pplen = strlen (PATH_PREFIX);
- whitelist = rc_get_list (SYS_WHITELIST);
+ whitelist = rc_config_list (SYS_WHITELIST);
if (! whitelist)
fprintf (stderr, "system environment whitelist (" SYS_WHITELIST ") missing\n");
- env = rc_get_list (USR_WHITELIST);
+ env = rc_config_list (USR_WHITELIST);
rc_strlist_join (&whitelist, env);
rc_strlist_free (env);
env = NULL;
@@ -448,7 +448,7 @@ char **rc_filter_env (void)
return (NULL);
if (rc_is_file (PROFILE_ENV))
- profile = rc_get_config (PROFILE_ENV);
+ profile = rc_config_load (PROFILE_ENV);
STRLIST_FOREACH (whitelist, env_name, count) {
char *space = strchr (env_name, ' ');
@@ -461,7 +461,7 @@ char **rc_filter_env (void)
env_len = strlen (env_name) + strlen ("export ") + 1;
p = rc_xmalloc (sizeof (char *) * env_len);
snprintf (p, env_len, "export %s", env_name);
- env_var = rc_get_config_entry (profile, p);
+ env_var = rc_config_value (profile, p);
free (p);
}
@@ -573,9 +573,9 @@ char **rc_make_env (void)
/* Don't trust environ for softlevel yet */
snprintf (buffer, PATH_MAX, "%s.%s", RC_CONFIG, runlevel);
if (rc_exists (buffer))
- config = rc_get_config (buffer);
+ config = rc_config_load (buffer);
else
- config = rc_get_config (RC_CONFIG);
+ config = rc_config_load (RC_CONFIG);
STRLIST_FOREACH (config, line, i) {
p = strchr (line, '=');
diff --git a/src/librc.h b/src/librc.h
index e71392a1..b99693b5 100644
--- a/src/librc.h
+++ b/src/librc.h
@@ -51,6 +51,9 @@
#define librc_hidden_proto(x) hidden_proto(x)
#define librc_hidden_def(x) hidden_def(x)
+librc_hidden_proto(rc_config_list)
+librc_hidden_proto(rc_config_load)
+librc_hidden_proto(rc_config_value)
librc_hidden_proto(rc_deptree_depends)
librc_hidden_proto(rc_deptree_depinfo)
librc_hidden_proto(rc_deptree_deptype)
@@ -63,9 +66,6 @@ librc_hidden_proto(rc_env_bool)
librc_hidden_proto(rc_exists)
librc_hidden_proto(rc_filter_env)
librc_hidden_proto(rc_find_pids)
-librc_hidden_proto(rc_get_config)
-librc_hidden_proto(rc_get_config_entry)
-librc_hidden_proto(rc_get_list)
librc_hidden_proto(rc_is_dir)
librc_hidden_proto(rc_is_exec)
librc_hidden_proto(rc_is_file)
diff --git a/src/rc.h b/src/rc.h
index 24bd4746..00e6504a 100644
--- a/src/rc.h
+++ b/src/rc.h
@@ -30,9 +30,31 @@
#define RC_LEVEL_SHUTDOWN "shutdown"
#define RC_LEVEL_REBOOT "reboot"
-/*! @name rc_ls_dir options */
-/*! Ensure that an init.d service exists for each file returned */
-#define RC_LS_INITD 0x01
+/*! Return the current runlevel.
+ * @return the current runlevel */
+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);
+
+/*! Return a NULL terminated list of runlevels
+ * @return a NULL terminated list of runlevels */
+char **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);
+
+/*! Is the runlevel starting?
+ * @return true if yes, otherwise false */
+bool rc_runlevel_starting (void);
+
+/*! Is the runlevel stopping?
+ * @return true if yes, otherwise false */
+bool rc_runlevel_stopping (void);
/*! @name RC
* A service can be given as a full path or just its name.
@@ -59,6 +81,18 @@ typedef enum
RC_SERVICE_WASINACTIVE = 0x0800,
} rc_service_state_t;
+/*! 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);
+
+/*! 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);
+
/*! Save the arguments to find a running daemon
* @param service to save arguments for
* @param exec that we started
@@ -97,19 +131,10 @@ bool rc_service_mark (const char *service, rc_service_state_t state);
* @return NULL terminated string list of options */
char **rc_service_options (const char *service);
-/*! Return a saved value for a service
+/*! Check if the service is allowed to be hot/cold plugged
* @param service to check
- * @param option to load
- * @return saved value */
-char *rc_service_value_get (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
- * @return true if saved, otherwise false */
-bool rc_service_value_set (const char *service, const char *option,
- const char *value);
+ * @return true if allowed, otherwise false */
+bool rc_service_plugable (char *service);
/*! Resolves a service name to its full path.
* @param service to check
@@ -146,11 +171,6 @@ pid_t rc_service_start (const char *service);
* @return pid of service stopping process */
pid_t rc_service_stop (const char *service);
-/*! Wait for a service to finish
- * @param service to wait for
- * @return true if service finished before timeout, otherwise false */
-bool rc_service_wait (const char *service);
-
/*! Check if the service started the daemon
* @param service to check
* @param exec to check
@@ -159,47 +179,24 @@ bool rc_service_wait (const char *service);
bool rc_service_started_daemon (const char *service, const char *exec,
int indx);
-/*! Check if the service is allowed to be hot/cold plugged
+/*! Return a saved value for a service
* @param service to check
- * @return true if allowed, otherwise false */
-bool rc_service_plugable (char *service);
-
-/*! Return the current runlevel.
- * @return the current runlevel */
-char *rc_runlevel_get (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);
-
-/*! 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);
-
-/*! Return a NULL terminated list of runlevels
- * @return a NULL terminated list of runlevels */
-char **rc_runlevel_list (void);
-
-/*! Is the runlevel starting?
- * @return true if yes, otherwise false */
-bool rc_runlevel_starting (void);
-/*! Is the runlevel stopping?
- * @return true if yes, otherwise false */
-bool rc_runlevel_stopping (void);
+ * @param option to load
+ * @return saved value */
+char *rc_service_value_get (const char *service, const char *option);
-/*! 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);
+/*! 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);
-/*! 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);
+/*! Wait for a service to finish
+ * @param service to wait for
+ * @return true if service finished before timeout, otherwise false */
+bool rc_service_wait (const char *service);
/*! List the services in a runlevel
* @param runlevel to list
@@ -348,91 +345,15 @@ int rc_plugin_hook (rc_hook_t hook, const char *name);
* variables they wish. Variables should be separated by NULLs. */
extern FILE *rc_environ_fd;
-/*! @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 */
-void *rc_xmalloc (size_t size);
-
-/*! 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 */
-void *rc_xrealloc (void *ptr, size_t size);
-
-/*! Duplicate a NULL terminated string
- * @param str to duplicate
- * @return pointer to the new string */
-char *rc_xstrdup (const char *str);
-/*@}*/
-
-/*! @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 */
-char *rc_strcatpaths (const char *path1, const char *paths, ...) SENTINEL;
-
-/*! 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.
- * @param variable to check
- * @return true if it matches true, yes or 1, false if otherwise. */
-bool rc_env_bool (const char *variable);
-
-/*! Check if the file exists or not
- * @param pathname to check
- * @return true if it exists, otherwise false */
-bool rc_exists (const char *pathname);
-
-/*! Check if the file is a real file
- * @param pathname to check
- * @return true if it's a real file, otherwise false */
-bool rc_is_file (const char *pathname);
-
-/*! Check if the file is a symbolic link or not
- * @param pathname to check
- * @return true if it's a symbolic link, otherwise false */
-bool rc_is_link (const char *pathname);
-
-/*! Check if the file is a directory or not
- * @param pathname to check
- * @return true if it's a directory, otherwise false */
-bool rc_is_dir (const char *pathname);
-
-/*! Check if the file is marked executable or not
- * @param pathname to check
- * @return true if it's marked executable, otherwise false */
-bool rc_is_exec (const char *pathname);
-
-/*! 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 */
-char **rc_ls_dir (const char *dir, int options);
-
-/*! Remove a directory
- * @param pathname to remove
- * @param top remove the top level directory too
- * @return true if successful, otherwise false */
-bool rc_rm_dir (const char *pathname, bool top);
-
/*! @name Configuration */
/*! Return a NULL terminated list of non comment lines from a file. */
-char **rc_get_list (const char *file);
+char **rc_config_list (const char *file);
/*! Return a NULL terminated list of key=value lines from a file. */
-char **rc_get_config (const char *file);
+char **rc_config_load (const char *file);
/*! Return the value of the entry from a key=value list. */
-char *rc_get_config_entry (char **list, const char *entry);
+char *rc_config_value (char **list, const char *entry);
/*! Return a NULL terminated string list of variables allowed through
* from the current environemnt. */
@@ -503,4 +424,84 @@ void rc_strlist_reverse (char **list);
* @param list to free */
void rc_strlist_free (char **list);
+/*! @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 */
+void *rc_xmalloc (size_t size);
+
+/*! 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 */
+void *rc_xrealloc (void *ptr, size_t size);
+
+/*! Duplicate a NULL terminated string
+ * @param str to duplicate
+ * @return pointer to the new string */
+char *rc_xstrdup (const char *str);
+/*@}*/
+
+/*! @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 */
+char *rc_strcatpaths (const char *path1, const char *paths, ...) SENTINEL;
+
+/*! 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.
+ * @param variable to check
+ * @return true if it matches true, yes or 1, false if otherwise. */
+bool rc_env_bool (const char *variable);
+
+/*! Check if the file exists or not
+ * @param pathname to check
+ * @return true if it exists, otherwise false */
+bool rc_exists (const char *pathname);
+
+/*! Check if the file is a real file
+ * @param pathname to check
+ * @return true if it's a real file, otherwise false */
+bool rc_is_file (const char *pathname);
+
+/*! Check if the file is a symbolic link or not
+ * @param pathname to check
+ * @return true if it's a symbolic link, otherwise false */
+bool rc_is_link (const char *pathname);
+
+/*! Check if the file is a directory or not
+ * @param pathname to check
+ * @return true if it's a directory, otherwise false */
+bool rc_is_dir (const char *pathname);
+
+/*! Check if the file is marked executable or not
+ * @param pathname to check
+ * @return true if it's marked executable, otherwise false */
+bool rc_is_exec (const char *pathname);
+
+/*! @name rc_ls_dir options */
+/*! Ensure that an init.d service exists for each file returned */
+#define RC_LS_INITD 0x01
+
+/*! 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 */
+char **rc_ls_dir (const char *dir, int options);
+
+/*! Remove a directory
+ * @param pathname to remove
+ * @param top remove the top level directory too
+ * @return true if successful, otherwise false */
+bool rc_rm_dir (const char *pathname, bool top);
+
#endif