Remove null terminated char ** lists in favour of RC_STRINGLIST, using TAILQ from queue(3). Refactor code style around the BSD KNF.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
MAN3= einfo.3 \
|
||||
rc_config.3 rc_deptree.3 rc_find_pids.3 rc_plugin_hook.3 \
|
||||
rc_runlevel.3 rc_service.3 rc_strcatpaths.3 rc_strlist.3
|
||||
rc_runlevel.3 rc_service.3 rc_strcatpaths.3 rc_stringlist.3
|
||||
MAN8= rc-status.8 rc-update.8 rc.8 runscript.8 start-stop-daemon.8
|
||||
|
||||
# Handy macro to create symlinks
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd Feb 22, 2008
|
||||
.Dd Mar 16, 2008
|
||||
.Dt EINFO 3 SMM
|
||||
.Os OpenRC
|
||||
.Sh NAME
|
||||
@@ -62,7 +62,7 @@ Enhanced Informatation output library (libeinfo, -leinfo)
|
||||
.Ft int Fn ewend "int retval" "const char * restrict format" ...
|
||||
.Ft int Fn eendv "int retval" "const char * restrict format" ...
|
||||
.Ft int Fn ewendv "int retval" "const char * restrict format" ...
|
||||
.Ft void Fn ebracket "int col" "einfo_color_t color" "const char * restrict msg"
|
||||
.Ft void Fn ebracket "int col" "ECOLOR color" "const char * restrict msg"
|
||||
.Ft void Fn eindent void
|
||||
.Ft void Fn eoutdent void
|
||||
.Ft void Fn eindentv void
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd Jan 08, 2008
|
||||
.Dd Mar 16, 2008
|
||||
.Dt RC_CONFIG 3 SMM
|
||||
.Os OpenRC
|
||||
.Sh NAME
|
||||
@@ -33,8 +33,8 @@ Run Command library (librc, -lrc)
|
||||
.Sh SYNOPSIS
|
||||
.In rc.h
|
||||
.Ft "char *" Fn rc_getline "FILE *fp"
|
||||
.Ft "char **" Fn rc_config_list "const char *file"
|
||||
.Ft "char **" Fn rc_config_load "const char *file"
|
||||
.Ft "RC_STRINGLIST *" Fn rc_config_list "const char *file"
|
||||
.Ft "RC_STRINGLIST *" Fn rc_config_load "const char *file"
|
||||
.Ft "char *" Fn rc_config_value "const char *const *list" "const char *entry"
|
||||
.Ft bool Fn rc_yesno "const char *value"
|
||||
.Sh DESCRIPTION
|
||||
@@ -61,7 +61,7 @@ found in
|
||||
.Fa list .
|
||||
.Pp
|
||||
Each list should be freed using
|
||||
.Fn rc_strlist_free
|
||||
.Fn rc_stringlist_free
|
||||
when done.
|
||||
.Pp
|
||||
.Fn rc_yesno
|
||||
@@ -76,7 +76,7 @@ is set to
|
||||
.Va EINVAL .
|
||||
.Sh SEE ALSO
|
||||
.Xr malloc 3 ,
|
||||
.Xr rc_strlist_free 3 ,
|
||||
.Xr rc_stringlist_free 3 ,
|
||||
.Xr sh 1
|
||||
.Sh AUTHORS
|
||||
.An "Roy Marples" Aq roy@marples.name
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd Feb 22, 2008
|
||||
.Dd Mar 16, 2008
|
||||
.Dt RC_DEPTREE 3 SMM
|
||||
.Os OpenRC
|
||||
.Sh NAME
|
||||
@@ -36,25 +36,25 @@ Run Command library (librc, -lrc)
|
||||
.In rc.h
|
||||
.Ft bool Fn rc_deptree_update void
|
||||
.Ft bool Fn rc_deptree_update_needed void
|
||||
.Ft rc_depinfo_t Fn rc_deptree_load void
|
||||
.Ft "char **" Fo rc_deptree_depend
|
||||
.Fa "const rc_depinfo_t *deptree"
|
||||
.Ft RC_DEPTREE Fn rc_deptree_load void
|
||||
.Ft "RC_STRINGLIST *" Fo rc_deptree_depend
|
||||
.Fa "const RC_DEPTREE *deptree"
|
||||
.Fa "const char *type"
|
||||
.Fa "const char *service"
|
||||
.Fc
|
||||
.Ft bool Fo rc_deptree_depends
|
||||
.Fa "const rc_depinfo_t *deptree"
|
||||
.Fa "const RC_DEPTREE *deptree"
|
||||
.Fa "const char *const *types"
|
||||
.Fa "const char *const *services"
|
||||
.Fa "const char *runlevel"
|
||||
.Fa "int options"
|
||||
.Fc
|
||||
.Ft "char **" Fo rc_deptree_order
|
||||
.Fa "const rc_depinfo_t *deptree"
|
||||
.Ft "RC_STRINGLIST *" Fo rc_deptree_order
|
||||
.Fa "const RC_DEPTREE *deptree"
|
||||
.Fa "const char *runlevel"
|
||||
.Fa "int options"
|
||||
.Fc
|
||||
.Ft void Fn rc_deptree_free "rc_depinfo_t *deptree"
|
||||
.Ft void Fn rc_deptree_free "RC_DEPTREE *deptree"
|
||||
.Sh DESCRIPTION
|
||||
These functions provide a means of querying the dependencies of OpenRC
|
||||
services.
|
||||
@@ -100,15 +100,14 @@ only lists services actually needed or in the
|
||||
.Va runlevel .
|
||||
.Sh IMPLEMENTATION NOTES
|
||||
Each function that returns
|
||||
.Fr "char **"
|
||||
returns a malloced NULL terminated array of malloced NULL terminated strings,
|
||||
all of which need to be freed using
|
||||
.Fn rc_strlist_free
|
||||
.Fr "RC_STRINGLIST *"
|
||||
should be freed by calling
|
||||
.Fn rc_stringlist_free
|
||||
when done.
|
||||
.Sh SEE ALSO
|
||||
.Xr malloc 3 ,
|
||||
.Xr free 3 ,
|
||||
.Xr rc_strlist_free 3 ,
|
||||
.Xr rc_stringlist_free 3 ,
|
||||
.Xr runscript 8
|
||||
.Sh AUTHORS
|
||||
.An "Roy Marples" Aq roy@marples.name
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd Feb 22, 2008
|
||||
.Dd Mar 16, 2008
|
||||
.Dt RC_PLUGIN_HOOK 3 SMM
|
||||
.Os OpenRC
|
||||
.Sh NAME
|
||||
@@ -32,7 +32,7 @@
|
||||
Run Command library (librc, -lrc)
|
||||
.Sh SYNOPSIS
|
||||
.In rc.h
|
||||
.Ft int Fn rc_plugin_hook "rc_hook_t hook" "const char *name"
|
||||
.Ft int Fn rc_plugin_hook "RC_HOOK hook" "const char *name"
|
||||
.Sh DESCRIPTION
|
||||
.Fn rc_plugin_hook
|
||||
is called for each shareable object found in
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd Feb 22, 2008
|
||||
.Dd Mar 16, 2008
|
||||
.Dt RC_RUNLEVEL 3 SMM
|
||||
.Os OpenRC
|
||||
.Sh NAME
|
||||
@@ -35,7 +35,7 @@ Run Command library (librc, -lrc)
|
||||
.In rc.h
|
||||
.Ft "char *" Fn rc_runlevel_get void
|
||||
.Ft bool Fn rc_runlevel_exists
|
||||
.Ft "char **" Fn rc_runlevel_list void
|
||||
.Ft "RC_STRINGLIST *" Fn rc_runlevel_list void
|
||||
.Ft bool Fn rc_runlevel_set "const char *runlevel"
|
||||
.Ft bool Fn rc_runlevel_starting void
|
||||
.Ft bool Fn rc_runlevel_stopping void
|
||||
@@ -48,10 +48,9 @@ Each function that returns
|
||||
returns a malloced NULL terminated string that should be freed when done.
|
||||
.Pp
|
||||
Each function that returns
|
||||
.Fr "char **"
|
||||
returns a malloced NULL terminated array of malloced NULL terminated strings,
|
||||
all of which need to be freed using
|
||||
.Fn rc_strlist_free
|
||||
.Fr "RC_STRINGLIST *"
|
||||
should by freed by calling
|
||||
.Fn rc_stringlist_free
|
||||
when done.
|
||||
.Sh FILES
|
||||
.Pa /etc/init.d/functions.sh
|
||||
@@ -62,6 +61,6 @@ Rinse and repeat for the other verbose functions.
|
||||
.Sh SEE ALSO
|
||||
.Xr malloc 3 ,
|
||||
.Xr free 3
|
||||
.Xr rc_strlist_free 3
|
||||
.Xr rc_stringlist_free 3
|
||||
.Sh AUTHORS
|
||||
.An "Roy Marples" Aq roy@marples.name
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd Feb 22, 2008
|
||||
.Dd Mar 16, 2008
|
||||
.Dt RC_SERVICE 3 SMM
|
||||
.Os OpenRC
|
||||
.Sh NAME
|
||||
@@ -55,17 +55,17 @@ Run Command library (librc, -lrc)
|
||||
.Fc
|
||||
.Ft bool Fn rc_service_exists "const char *service"
|
||||
.Ft bool Fn rc_service_in_runlevel "const char *service" "const char *runlevel"
|
||||
.Ft bool Fn rc_service_mark "const char *service" "rc_service_state_t state"
|
||||
.Ft "char **" Fn rc_service_extra_commands "const char *service"
|
||||
.Ft bool Fn rc_service_mark "const char *service" "RC_SERVICE state"
|
||||
.Ft "RC_STRINGLIST *" Fn rc_service_extra_commands "const char *service"
|
||||
.Ft bool Fn rc_service_plugable "const char *service"
|
||||
.Ft "char *" rc_service_resolve "const char *service"
|
||||
.Ft bool Fo rc_service_schedule_start
|
||||
.Fa "const char *service"
|
||||
.Fa "const char *service_to_start"
|
||||
.Fc
|
||||
.Ft "char **" Fn rc_services_scheduled_by "const char *service"
|
||||
.Ft "RC_STRINGLIST *" Fn rc_services_scheduled_by "const char *service"
|
||||
.Ft bool Fn rc_service_schedule_clear "const char *service"
|
||||
.Ft rc_service_state_t Fn rc_service_state "const char *service"
|
||||
.Ft RC_SERVICE Fn rc_service_state "const char *service"
|
||||
.Ft pid_t Fn rc_service_start "const char *service"
|
||||
.Ft pid_t Fn rc_service_stop "const char *service"
|
||||
.Ft bool Fo rc_service_started_daemon
|
||||
@@ -79,9 +79,9 @@ Run Command library (librc, -lrc)
|
||||
.Fa "const char *option"
|
||||
.Fa "const char *value"
|
||||
.Fc
|
||||
.Ft "char **" Fn rc_services_in_runlevel "const char *runlevel"
|
||||
.Ft "char **" Fn rc_services_in_state "rc_service_state_t state"
|
||||
.Ft "char **" Fn rc_services_scheduled "const char *service"
|
||||
.Ft "RC_STRINGLIST *" Fn rc_services_in_runlevel "const char *runlevel"
|
||||
.Ft "RC_STRINGLIST *" Fn rc_services_in_state "RC_SERVICE state"
|
||||
.Ft "RC_STRINGLIST *" Fn rc_services_scheduled "const char *service"
|
||||
.Ft bool Fn rc_service_daemons_crashed "const char *service"
|
||||
.Sh DESCRIPTION
|
||||
These functions provide a means of querying OpenRC services to find out the
|
||||
@@ -222,10 +222,9 @@ Each function that returns
|
||||
returns a malloced NULL terminated string that should be freed when done.
|
||||
.Pp
|
||||
Each function that returns
|
||||
.Fr "char **"
|
||||
returns a malloced NULL terminated array of malloced NULL terminated strings,
|
||||
all of which need to be freed using
|
||||
.Fn rc_strlist_free
|
||||
.Fr "RC_STRINGLIST *"
|
||||
should be freed using
|
||||
.Fn rc_stringlist_free
|
||||
when done.
|
||||
.Pp
|
||||
When a function fails it should either return false or NULL and set
|
||||
@@ -238,7 +237,7 @@ normally holds the volatile state data for services on a RAM backed disk.
|
||||
.Xr errno 3 ,
|
||||
.Xr malloc 3 ,
|
||||
.Xr free 3
|
||||
.Xr rc_strlist_free 3 ,
|
||||
.Xr rc_stringlist_free 3 ,
|
||||
.Xr start-stop-daemon 8
|
||||
.Sh AUTHORS
|
||||
.An "Roy Marples" Aq roy@marples.name
|
||||
|
||||
104
man/rc_strlist.3
104
man/rc_strlist.3
@@ -1,104 +0,0 @@
|
||||
.\" Copyright 2007-2008 Roy Marples
|
||||
.\" All rights reserved
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd Feb 22, 2008
|
||||
.Dt RC_STRLIST 3 SMM
|
||||
.Os OpenRC
|
||||
.Sh NAME
|
||||
.Nm rc_strlist_add , rc_strlist_addu , rc_strlist_addsort ,
|
||||
.Nm rc_strlist_addsortc , rc_strlist_addsortu , rc_strlist_delete ,
|
||||
.Nm rc_strlist_join , rc_strlist_reverse , rc_strlist_free
|
||||
.Nd RC string list functions
|
||||
.Sh LIBRARY
|
||||
Run Command library (librc, -lrc)
|
||||
.Sh SYNOPSIS
|
||||
.In rc.h
|
||||
.Ft "char *" Fn rc_strlist_add "char ***list" "const char *item"
|
||||
.Ft "char *" Fn rc_strlist_addu "char ***list" "const char *item"
|
||||
.Ft "char *" Fn rc_strlist_addsort "char ***list" "const char *item"
|
||||
.Ft "char *" Fn rc_strlist_addsortc "char ***list" "const char *item"
|
||||
.Ft "char *" Fn rc_strlist_addsortu "char ***list" "const char *item"
|
||||
.Ft bool Fn rc_strlist_delete "char ***list" "const char *item"
|
||||
.Ft "char *" Fn rc_strlist_join "char ***list1" "const char **list2"
|
||||
.Ft void Fn rc_strlist_reverse "char **list"
|
||||
.Ft void Fn rc_strlist_free "char **list"
|
||||
.Sh DESCRIPTION
|
||||
These functions provide an easy means of manipulating string lists without
|
||||
the need for custom structures or non standard macros.
|
||||
.Pp
|
||||
.Fn rc_strlist_add
|
||||
adds a malloced copy of
|
||||
.Fa item
|
||||
to
|
||||
.Fa list ,
|
||||
realloced to accomodate the new item. It returns a pointer to the new item on
|
||||
success, or NULL on failure and sets
|
||||
.Va errno
|
||||
accordingly.
|
||||
.Fn rc_strlist_addu
|
||||
and
|
||||
.Fn rc_strlist_addsortu
|
||||
only work if
|
||||
.Fa list
|
||||
does not already contain
|
||||
.Fa item .
|
||||
.Fn rc_strlist_addsort
|
||||
adds the item to the list in a lexically sorted position, using
|
||||
.Nm strcoll ,
|
||||
whereas
|
||||
.Fn rc_strlist_addsortc
|
||||
uses
|
||||
.Nm strcmp .
|
||||
.Pp
|
||||
.Fn rc_strlist_delete
|
||||
removes and frees
|
||||
.Fa item
|
||||
from
|
||||
.Fa list ,
|
||||
retuning true on success, otherwise false.
|
||||
.Pp
|
||||
.Fn rc_strlist_join
|
||||
appends
|
||||
.Fa list2
|
||||
to the end of
|
||||
.Fa list1
|
||||
and returns a pointer to the last item on the new list.
|
||||
.Pp
|
||||
.Fn rc_strlist_reverse
|
||||
reverses the items on
|
||||
.Fa list .
|
||||
.Pp
|
||||
.Fn rc_strlist_free
|
||||
frees each item on
|
||||
.Fa list
|
||||
and the
|
||||
.Fa list
|
||||
itself.
|
||||
.Sh SEE ALSO
|
||||
.Xr malloc 3 ,
|
||||
.Xr free 3 ,
|
||||
.Xr strcmp 3 ,
|
||||
.Xr strcoll 3
|
||||
.Sh AUTHORS
|
||||
.An "Roy Marples" Aq roy@marples.name
|
||||
Reference in New Issue
Block a user