Re: add getrun for rcctl(8)

2019-02-19 Thread YASUOKA Masahiko
Hi,

On Mon, 18 Feb 2019 10:24:51 +
Stuart Henderson  wrote:
> There's a safer way, you can obtain reliable current information about
> the rtable for a process from ps.

Yes.

But what I wanted to do is applying rtable changes by rc.conf to the
daemon if needed.  Running daemon's rtable may be configured by it's
configuration file as well.  For example, if ntpd.conf has "Listen on
* rtable 1" and rc.conf.local doesn't have "ntpd_rtable",

   curr=$(rcctl get ntpd rtable)
   running=$(get rtable from ps)
   if [[ $curr != $running ]]; then
  /etc/rc.d/ntpd restart
   fi

will restart ntpd always.

On this use case, the script needs to know not the actual running
daemon's configuration but the last configuration applied by rcctl(or
rc.d).  I thought that kind of information should be provided through
rcctl(8).

Anyway, I admit the use case is minor and the diff looks too much.
Let me withdraw the diff unless another user appears.

> On 18 February 2019 09:55:55 Antoine Jacoutot 
> wrote:
> 
>> On Mon, Feb 18, 2019 at 11:21:38AM +0900, YASUOKA Masahiko wrote:
>>> Hi,
>>>
>>> On Sun, 17 Feb 2019 10:55:11 +0100
>>> Antoine Jacoutot  wrote:
>>> > On Fri, Feb 15, 2019 at 02:50:22PM +0900, YASUOKA Masahiko wrote:
>>> >> On Fri, 15 Feb 2019 14:45:14 +0900 (JST)
>>> >> YASUOKA Masahiko  wrote:
>>> >> > The diff adds "getrun" command for rcctl(8) which shows the daemon
>>> >> > variables from the running daemon.
>>> >> >
>>> >> > ok? comment?
>>> >>
>>> >> Sorry, previous diff is broken.  It could not get any value other than
>>> >> daemon_pexp.  Let me update the diff.
>>> >
>>> > That's a lot of chunk of code for an enhanced 'cat /var/run/rc.d/foo'.
>>> > What is your usage for this?
>>>
>>> My actual usage is to know whether current "rtable" or "user" is
>>> changed from the values of the running daemon.  If either is changed,
>>> we need to restart the daemon apply that change.
>>>
>>> For example,
>>>
>>>   curr=$(rcctl get ntpd rtable)
>>>   running=$(rcctl getrun ntpd rtable)
>>>   if [[ $curr != $running ]]; then
>>>  /etc/rc.d/ntpd restart
>>>   fi
>>
>> You better of using this I think:
>> running=$(sed -n 's/^daemon_rtable=*//p' /var/run/rc.d/ntpd)
>>
>> What's under /var/run/rc.d/ is only a "hint".
>> If ntpd is manually killed (outside of the rc.d system), the
>> information is not
>> removed from there.
>> That's why I'd like to avoid relying on it too much in rcctl.
>>
>>
>>> >> Index: usr.sbin/rcctl/rcctl.8
>>> >> ===
>>> >> RCS file: /cvs/src/usr.sbin/rcctl/rcctl.8,v
>>> >> retrieving revision 1.35
>>> >> diff -u -p -r1.35 rcctl.8
>>> >> --- usr.sbin/rcctl/rcctl.8   20 Sep 2018 12:24:14 -  1.35
>>> >> +++ usr.sbin/rcctl/rcctl.8   15 Feb 2019 05:48:16 -
>>> >> @@ -22,7 +22,7 @@
>>> >>  .Nd configure and control daemons and services
>>> >>  .Sh SYNOPSIS
>>> >>  .Nm rcctl
>>> >> -.Cm get Ns | Ns Cm getdef Ns | Ns Cm set
>>> >> +.Cm get Ns | Ns Cm getdef Ns | Ns Cm getrun Ns | Ns Cm set
>>> >>  .Ar service | daemon Op Ar variable Op Ar arguments
>>> >>  .Nm rcctl
>>> >>  .Op Fl df
>>> >> @@ -103,6 +103,10 @@ will display all services and daemons va
>>> >>  Like
>>> >>  .Cm get
>>> >>  but returns the default values.
>>> >> +.It Cm getrun Ar service | daemon Op Ar variable
>>> >> +Like
>>> >> +.Cm get
>>> >> +but returns the values of the running daemon.
>>> >>  .It Cm ls Ar lsarg
>>> >>  Display a list of services and daemons matching
>>> >>  .Ar lsarg ,
>>> >> @@ -180,6 +184,9 @@ exits with 0 if the daemon or service is
>>> >>  .Nm Cm getdef Ar daemon | service Op Cm status
>>> >>  exits with 0 if the daemon or service is enabled by default
>>> >>  and 1 if it is not.
>>> >> +.Nm Cm getrun Ar daemon | service
>>> >> +exits with 0 if the values of the running daemon exists
>>> >> +and 1 if it doesn't.
>>> >>  .Nm Cm ls failed
>>> >>  exits with 1 if an enabled daemon is not running.
>>> >>  Otherwise, the
>>> >> Index: usr.sbin/rcctl/rcctl.sh
>>> >> ===
>>> >> RCS file: /cvs/src/usr.sbin/rcctl/rcctl.sh,v
>>> >> retrieving revision 1.107
>>> >> diff -u -p -r1.107 rcctl.sh
>>> >> --- usr.sbin/rcctl/rcctl.sh  21 Oct 2018 21:20:40 -  1.107
>>> >> +++ usr.sbin/rcctl/rcctl.sh  15 Feb 2019 05:48:16 -
>>> >> @@ -21,6 +21,7 @@ _special_svcs="accounting check_quotas i
>>> >> spamd_black"
>>> >>  readonly _special_svcs
>>> >>
>>> >> +_RC_RUNDIR=/var/run/rc.d
>>> >>  # get local functions from rc.subr(8)
>>> >>  FUNCS_ONLY=1
>>> >>  . /etc/rc.d/rc.subr
>>> >> @@ -32,7 +33,7 @@ usage()
>>> >>  for _i in ${_rc_actions}; do _a="$(echo -n 
>>> >> ${_i}${_a:+|${_a}})"; done
>>> >>
>>> >>  _rc_err \
>>> >> -"usage: rcctl get|getdef|set service | daemon [variable 
>>> >> [arguments]]
>>> >> + "usage: rcctl get|getdef|getrun|set service | daemon [variable
>>> >> [arguments]]
>>> >>  rcctl [-df] ${_a

Re: add getrun for rcctl(8)

2019-02-18 Thread Stuart Henderson
There's a safer way, you can obtain reliable current information about the 
rtable for a process from ps.


--
Sent from a phone, apologies for poor formatting.

On 18 February 2019 09:55:55 Antoine Jacoutot  wrote:


On Mon, Feb 18, 2019 at 11:21:38AM +0900, YASUOKA Masahiko wrote:

Hi,

On Sun, 17 Feb 2019 10:55:11 +0100
Antoine Jacoutot  wrote:
> On Fri, Feb 15, 2019 at 02:50:22PM +0900, YASUOKA Masahiko wrote:
>> On Fri, 15 Feb 2019 14:45:14 +0900 (JST)
>> YASUOKA Masahiko  wrote:
>> > The diff adds "getrun" command for rcctl(8) which shows the daemon
>> > variables from the running daemon.
>> >
>> > ok? comment?
>>
>> Sorry, previous diff is broken.  It could not get any value other than
>> daemon_pexp.  Let me update the diff.
>
> That's a lot of chunk of code for an enhanced 'cat /var/run/rc.d/foo'.
> What is your usage for this?

My actual usage is to know whether current "rtable" or "user" is
changed from the values of the running daemon.  If either is changed,
we need to restart the daemon apply that change.

For example,

  curr=$(rcctl get ntpd rtable)
  running=$(rcctl getrun ntpd rtable)
  if [[ $curr != $running ]]; then
 /etc/rc.d/ntpd restart
  fi


You better of using this I think:
running=$(sed -n 's/^daemon_rtable=*//p' /var/run/rc.d/ntpd)

What's under /var/run/rc.d/ is only a "hint".
If ntpd is manually killed (outside of the rc.d system), the information is not
removed from there.
That's why I'd like to avoid relying on it too much in rcctl.



>> Index: usr.sbin/rcctl/rcctl.8
>> ===
>> RCS file: /cvs/src/usr.sbin/rcctl/rcctl.8,v
>> retrieving revision 1.35
>> diff -u -p -r1.35 rcctl.8
>> --- usr.sbin/rcctl/rcctl.8 20 Sep 2018 12:24:14 -  1.35
>> +++ usr.sbin/rcctl/rcctl.8 15 Feb 2019 05:48:16 -
>> @@ -22,7 +22,7 @@
>>  .Nd configure and control daemons and services
>>  .Sh SYNOPSIS
>>  .Nm rcctl
>> -.Cm get Ns | Ns Cm getdef Ns | Ns Cm set
>> +.Cm get Ns | Ns Cm getdef Ns | Ns Cm getrun Ns | Ns Cm set
>>  .Ar service | daemon Op Ar variable Op Ar arguments
>>  .Nm rcctl
>>  .Op Fl df
>> @@ -103,6 +103,10 @@ will display all services and daemons va
>>  Like
>>  .Cm get
>>  but returns the default values.
>> +.It Cm getrun Ar service | daemon Op Ar variable
>> +Like
>> +.Cm get
>> +but returns the values of the running daemon.
>>  .It Cm ls Ar lsarg
>>  Display a list of services and daemons matching
>>  .Ar lsarg ,
>> @@ -180,6 +184,9 @@ exits with 0 if the daemon or service is
>>  .Nm Cm getdef Ar daemon | service Op Cm status
>>  exits with 0 if the daemon or service is enabled by default
>>  and 1 if it is not.
>> +.Nm Cm getrun Ar daemon | service
>> +exits with 0 if the values of the running daemon exists
>> +and 1 if it doesn't.
>>  .Nm Cm ls failed
>>  exits with 1 if an enabled daemon is not running.
>>  Otherwise, the
>> Index: usr.sbin/rcctl/rcctl.sh
>> ===
>> RCS file: /cvs/src/usr.sbin/rcctl/rcctl.sh,v
>> retrieving revision 1.107
>> diff -u -p -r1.107 rcctl.sh
>> --- usr.sbin/rcctl/rcctl.sh21 Oct 2018 21:20:40 -  1.107
>> +++ usr.sbin/rcctl/rcctl.sh15 Feb 2019 05:48:16 -
>> @@ -21,6 +21,7 @@ _special_svcs="accounting check_quotas i
>> spamd_black"
>>  readonly _special_svcs
>>
>> +_RC_RUNDIR=/var/run/rc.d
>>  # get local functions from rc.subr(8)
>>  FUNCS_ONLY=1
>>  . /etc/rc.d/rc.subr
>> @@ -32,7 +33,7 @@ usage()
>>for _i in ${_rc_actions}; do _a="$(echo -n ${_i}${_a:+|${_a}})"; done
>>
>>_rc_err \
>> -  "usage:rcctl get|getdef|set service | daemon [variable 
[arguments]]
>> +	"usage:	rcctl get|getdef|getrun|set service | daemon [variable 
[arguments]]

>>rcctl [-df] ${_a} daemon ...
>>rcctl disable|enable|order [daemon ...]
>>rcctl ls all|failed|off|on|started|stopped"
>> @@ -374,6 +375,35 @@ svc_getdef()
>>fi
>>  }
>>
>> +svc_getrun()
>> +{
>> +  local _svc=$1
>> +
>> +  ( svc_is_special ${_svc} || svc_is_meta ${_svc} ) && return 1
>> +
>> +  local _val _var=$2
>> +  local daemon_class daemon_flags daemon_rtable daemon_timeout 
daemon_user
>> +  local daemon_pexp
>> +
>> +  [ ! -f $_RC_RUNDIR/$_svc ] && return 1
>> +  _rc_parse_conf -readonly $_RC_RUNDIR/$_svc
>> +
>> +  [ -z "${daemon_pexp}" ] && eval daemon_pexp=\${pexp}
>> +
>> +  if [ -n "${_var}" ]; then
>> +  eval _val=\${daemon_${_var}}
>> +  [ -z "${_val}" ] || print -r -- "${_val}"
>> +  else
>> +  echo "${_svc}_class=${daemon_class}"
>> +  echo "${_svc}_flags=${daemon_flags}"
>> +  echo "${_svc}_rtable=${daemon_rtable}"
>> +  echo "${_svc}_timeout=${daemon_timeout}"
>> +  echo "${_svc}_user=${daemon_user}"
>> +  echo "${_svc}_pexp=${daemon_pexp}"
>> +  fi
>> +  return 0
>> +}
>> +
>>  svc_rm()
>>  {
>>local _svc=$1
>> 

Re: add getrun for rcctl(8)

2019-02-18 Thread Antoine Jacoutot
On Mon, Feb 18, 2019 at 11:21:38AM +0900, YASUOKA Masahiko wrote:
> Hi,
> 
> On Sun, 17 Feb 2019 10:55:11 +0100
> Antoine Jacoutot  wrote:
> > On Fri, Feb 15, 2019 at 02:50:22PM +0900, YASUOKA Masahiko wrote:
> >> On Fri, 15 Feb 2019 14:45:14 +0900 (JST)
> >> YASUOKA Masahiko  wrote:
> >> > The diff adds "getrun" command for rcctl(8) which shows the daemon
> >> > variables from the running daemon.
> >> > 
> >> > ok? comment?
> >> 
> >> Sorry, previous diff is broken.  It could not get any value other than
> >> daemon_pexp.  Let me update the diff.
> > 
> > That's a lot of chunk of code for an enhanced 'cat /var/run/rc.d/foo'.
> > What is your usage for this?
> 
> My actual usage is to know whether current "rtable" or "user" is
> changed from the values of the running daemon.  If either is changed,
> we need to restart the daemon apply that change.
> 
> For example,
> 
>   curr=$(rcctl get ntpd rtable)
>   running=$(rcctl getrun ntpd rtable)
>   if [[ $curr != $running ]]; then
>  /etc/rc.d/ntpd restart
>   fi

You better of using this I think:
running=$(sed -n 's/^daemon_rtable=*//p' /var/run/rc.d/ntpd)

What's under /var/run/rc.d/ is only a "hint".
If ntpd is manually killed (outside of the rc.d system), the information is not
removed from there.
That's why I'd like to avoid relying on it too much in rcctl.


> >> Index: usr.sbin/rcctl/rcctl.8
> >> ===
> >> RCS file: /cvs/src/usr.sbin/rcctl/rcctl.8,v
> >> retrieving revision 1.35
> >> diff -u -p -r1.35 rcctl.8
> >> --- usr.sbin/rcctl/rcctl.8 20 Sep 2018 12:24:14 -  1.35
> >> +++ usr.sbin/rcctl/rcctl.8 15 Feb 2019 05:48:16 -
> >> @@ -22,7 +22,7 @@
> >>  .Nd configure and control daemons and services
> >>  .Sh SYNOPSIS
> >>  .Nm rcctl
> >> -.Cm get Ns | Ns Cm getdef Ns | Ns Cm set
> >> +.Cm get Ns | Ns Cm getdef Ns | Ns Cm getrun Ns | Ns Cm set
> >>  .Ar service | daemon Op Ar variable Op Ar arguments
> >>  .Nm rcctl
> >>  .Op Fl df
> >> @@ -103,6 +103,10 @@ will display all services and daemons va
> >>  Like
> >>  .Cm get
> >>  but returns the default values.
> >> +.It Cm getrun Ar service | daemon Op Ar variable
> >> +Like
> >> +.Cm get
> >> +but returns the values of the running daemon.
> >>  .It Cm ls Ar lsarg
> >>  Display a list of services and daemons matching
> >>  .Ar lsarg ,
> >> @@ -180,6 +184,9 @@ exits with 0 if the daemon or service is
> >>  .Nm Cm getdef Ar daemon | service Op Cm status
> >>  exits with 0 if the daemon or service is enabled by default
> >>  and 1 if it is not.
> >> +.Nm Cm getrun Ar daemon | service
> >> +exits with 0 if the values of the running daemon exists
> >> +and 1 if it doesn't.
> >>  .Nm Cm ls failed
> >>  exits with 1 if an enabled daemon is not running.
> >>  Otherwise, the
> >> Index: usr.sbin/rcctl/rcctl.sh
> >> ===
> >> RCS file: /cvs/src/usr.sbin/rcctl/rcctl.sh,v
> >> retrieving revision 1.107
> >> diff -u -p -r1.107 rcctl.sh
> >> --- usr.sbin/rcctl/rcctl.sh21 Oct 2018 21:20:40 -  1.107
> >> +++ usr.sbin/rcctl/rcctl.sh15 Feb 2019 05:48:16 -
> >> @@ -21,6 +21,7 @@ _special_svcs="accounting check_quotas i
> >> spamd_black"
> >>  readonly _special_svcs
> >>  
> >> +_RC_RUNDIR=/var/run/rc.d
> >>  # get local functions from rc.subr(8)
> >>  FUNCS_ONLY=1
> >>  . /etc/rc.d/rc.subr
> >> @@ -32,7 +33,7 @@ usage()
> >>for _i in ${_rc_actions}; do _a="$(echo -n ${_i}${_a:+|${_a}})"; done
> >>  
> >>_rc_err \
> >> -  "usage: rcctl get|getdef|set service | daemon [variable [arguments]]
> >> +  "usage: rcctl get|getdef|getrun|set service | daemon [variable 
> >> [arguments]]
> >>rcctl [-df] ${_a} daemon ...
> >>rcctl disable|enable|order [daemon ...]
> >>rcctl ls all|failed|off|on|started|stopped"
> >> @@ -374,6 +375,35 @@ svc_getdef()
> >>fi
> >>  }
> >>  
> >> +svc_getrun()
> >> +{
> >> +  local _svc=$1
> >> +
> >> +  ( svc_is_special ${_svc} || svc_is_meta ${_svc} ) && return 1
> >> +
> >> +  local _val _var=$2
> >> +  local daemon_class daemon_flags daemon_rtable daemon_timeout daemon_user
> >> +  local daemon_pexp
> >> +
> >> +  [ ! -f $_RC_RUNDIR/$_svc ] && return 1
> >> +  _rc_parse_conf -readonly $_RC_RUNDIR/$_svc
> >> +
> >> +  [ -z "${daemon_pexp}" ] && eval daemon_pexp=\${pexp}
> >> +
> >> +  if [ -n "${_var}" ]; then
> >> +  eval _val=\${daemon_${_var}}
> >> +  [ -z "${_val}" ] || print -r -- "${_val}"
> >> +  else
> >> +  echo "${_svc}_class=${daemon_class}"
> >> +  echo "${_svc}_flags=${daemon_flags}"
> >> +  echo "${_svc}_rtable=${daemon_rtable}"
> >> +  echo "${_svc}_timeout=${daemon_timeout}"
> >> +  echo "${_svc}_user=${daemon_user}"
> >> +  echo "${_svc}_pexp=${daemon_pexp}"
> >> +  fi
> >> +  return 0
> >> +}
> >> +
> >>  svc_rm()
> >>  {
> >>local _svc=$1
> >> @@ -509,7 +539,7 @@ case ${action} in
> >>done
> >

Re: add getrun for rcctl(8)

2019-02-17 Thread YASUOKA Masahiko
Hi,

On Sun, 17 Feb 2019 10:55:11 +0100
Antoine Jacoutot  wrote:
> On Fri, Feb 15, 2019 at 02:50:22PM +0900, YASUOKA Masahiko wrote:
>> On Fri, 15 Feb 2019 14:45:14 +0900 (JST)
>> YASUOKA Masahiko  wrote:
>> > The diff adds "getrun" command for rcctl(8) which shows the daemon
>> > variables from the running daemon.
>> > 
>> > ok? comment?
>> 
>> Sorry, previous diff is broken.  It could not get any value other than
>> daemon_pexp.  Let me update the diff.
> 
> That's a lot of chunk of code for an enhanced 'cat /var/run/rc.d/foo'.
> What is your usage for this?

My actual usage is to know whether current "rtable" or "user" is
changed from the values of the running daemon.  If either is changed,
we need to restart the daemon apply that change.

For example,

  curr=$(rcctl get ntpd rtable)
  running=$(rcctl getrun ntpd rtable)
  if [[ $curr != $running ]]; then
 /etc/rc.d/ntpd restart
  fi

>> Index: usr.sbin/rcctl/rcctl.8
>> ===
>> RCS file: /cvs/src/usr.sbin/rcctl/rcctl.8,v
>> retrieving revision 1.35
>> diff -u -p -r1.35 rcctl.8
>> --- usr.sbin/rcctl/rcctl.8   20 Sep 2018 12:24:14 -  1.35
>> +++ usr.sbin/rcctl/rcctl.8   15 Feb 2019 05:48:16 -
>> @@ -22,7 +22,7 @@
>>  .Nd configure and control daemons and services
>>  .Sh SYNOPSIS
>>  .Nm rcctl
>> -.Cm get Ns | Ns Cm getdef Ns | Ns Cm set
>> +.Cm get Ns | Ns Cm getdef Ns | Ns Cm getrun Ns | Ns Cm set
>>  .Ar service | daemon Op Ar variable Op Ar arguments
>>  .Nm rcctl
>>  .Op Fl df
>> @@ -103,6 +103,10 @@ will display all services and daemons va
>>  Like
>>  .Cm get
>>  but returns the default values.
>> +.It Cm getrun Ar service | daemon Op Ar variable
>> +Like
>> +.Cm get
>> +but returns the values of the running daemon.
>>  .It Cm ls Ar lsarg
>>  Display a list of services and daemons matching
>>  .Ar lsarg ,
>> @@ -180,6 +184,9 @@ exits with 0 if the daemon or service is
>>  .Nm Cm getdef Ar daemon | service Op Cm status
>>  exits with 0 if the daemon or service is enabled by default
>>  and 1 if it is not.
>> +.Nm Cm getrun Ar daemon | service
>> +exits with 0 if the values of the running daemon exists
>> +and 1 if it doesn't.
>>  .Nm Cm ls failed
>>  exits with 1 if an enabled daemon is not running.
>>  Otherwise, the
>> Index: usr.sbin/rcctl/rcctl.sh
>> ===
>> RCS file: /cvs/src/usr.sbin/rcctl/rcctl.sh,v
>> retrieving revision 1.107
>> diff -u -p -r1.107 rcctl.sh
>> --- usr.sbin/rcctl/rcctl.sh  21 Oct 2018 21:20:40 -  1.107
>> +++ usr.sbin/rcctl/rcctl.sh  15 Feb 2019 05:48:16 -
>> @@ -21,6 +21,7 @@ _special_svcs="accounting check_quotas i
>> spamd_black"
>>  readonly _special_svcs
>>  
>> +_RC_RUNDIR=/var/run/rc.d
>>  # get local functions from rc.subr(8)
>>  FUNCS_ONLY=1
>>  . /etc/rc.d/rc.subr
>> @@ -32,7 +33,7 @@ usage()
>>  for _i in ${_rc_actions}; do _a="$(echo -n ${_i}${_a:+|${_a}})"; done
>>  
>>  _rc_err \
>> -"usage: rcctl get|getdef|set service | daemon [variable [arguments]]
>> +"usage: rcctl get|getdef|getrun|set service | daemon [variable 
>> [arguments]]
>>  rcctl [-df] ${_a} daemon ...
>>  rcctl disable|enable|order [daemon ...]
>>  rcctl ls all|failed|off|on|started|stopped"
>> @@ -374,6 +375,35 @@ svc_getdef()
>>  fi
>>  }
>>  
>> +svc_getrun()
>> +{
>> +local _svc=$1
>> +
>> +( svc_is_special ${_svc} || svc_is_meta ${_svc} ) && return 1
>> +
>> +local _val _var=$2
>> +local daemon_class daemon_flags daemon_rtable daemon_timeout daemon_user
>> +local daemon_pexp
>> +
>> +[ ! -f $_RC_RUNDIR/$_svc ] && return 1
>> +_rc_parse_conf -readonly $_RC_RUNDIR/$_svc
>> +
>> +[ -z "${daemon_pexp}" ] && eval daemon_pexp=\${pexp}
>> +
>> +if [ -n "${_var}" ]; then
>> +eval _val=\${daemon_${_var}}
>> +[ -z "${_val}" ] || print -r -- "${_val}"
>> +else
>> +echo "${_svc}_class=${daemon_class}"
>> +echo "${_svc}_flags=${daemon_flags}"
>> +echo "${_svc}_rtable=${daemon_rtable}"
>> +echo "${_svc}_timeout=${daemon_timeout}"
>> +echo "${_svc}_user=${daemon_user}"
>> +echo "${_svc}_pexp=${daemon_pexp}"
>> +fi
>> +return 0
>> +}
>> +
>>  svc_rm()
>>  {
>>  local _svc=$1
>> @@ -509,7 +539,7 @@ case ${action} in
>>  done
>>  fi
>>  ;;
>> -get|getdef)
>> +get|getdef|getrun)
>>  svc=$2
>>  var=$3
>>  [ -z "${svc}" ] && usage
>> @@ -571,7 +601,7 @@ case ${action} in
>>  done
>>  exit ${ret}
>>  ;;
>> -get|getdef)
>> +get|getdef|getrun)
>>  if [ "${svc}" = "all" ]; then
>>  for svc in $(svc_ls all); do
>>  ( svc_${action} ${svc} "${var}" )
>> Index: etc/rc.d/rc.subr
>> ==

Re: add getrun for rcctl(8)

2019-02-17 Thread Antoine Jacoutot
On Fri, Feb 15, 2019 at 02:50:22PM +0900, YASUOKA Masahiko wrote:
> On Fri, 15 Feb 2019 14:45:14 +0900 (JST)
> YASUOKA Masahiko  wrote:
> > The diff adds "getrun" command for rcctl(8) which shows the daemon
> > variables from the running daemon.
> > 
> > ok? comment?
> 
> Sorry, previous diff is broken.  It could not get any value other than
> daemon_pexp.  Let me update the diff.

Hi.

That's a lot of chunk of code for an enhanced 'cat /var/run/rc.d/foo'.
What is your usage for this?


> Index: usr.sbin/rcctl/rcctl.8
> ===
> RCS file: /cvs/src/usr.sbin/rcctl/rcctl.8,v
> retrieving revision 1.35
> diff -u -p -r1.35 rcctl.8
> --- usr.sbin/rcctl/rcctl.820 Sep 2018 12:24:14 -  1.35
> +++ usr.sbin/rcctl/rcctl.815 Feb 2019 05:48:16 -
> @@ -22,7 +22,7 @@
>  .Nd configure and control daemons and services
>  .Sh SYNOPSIS
>  .Nm rcctl
> -.Cm get Ns | Ns Cm getdef Ns | Ns Cm set
> +.Cm get Ns | Ns Cm getdef Ns | Ns Cm getrun Ns | Ns Cm set
>  .Ar service | daemon Op Ar variable Op Ar arguments
>  .Nm rcctl
>  .Op Fl df
> @@ -103,6 +103,10 @@ will display all services and daemons va
>  Like
>  .Cm get
>  but returns the default values.
> +.It Cm getrun Ar service | daemon Op Ar variable
> +Like
> +.Cm get
> +but returns the values of the running daemon.
>  .It Cm ls Ar lsarg
>  Display a list of services and daemons matching
>  .Ar lsarg ,
> @@ -180,6 +184,9 @@ exits with 0 if the daemon or service is
>  .Nm Cm getdef Ar daemon | service Op Cm status
>  exits with 0 if the daemon or service is enabled by default
>  and 1 if it is not.
> +.Nm Cm getrun Ar daemon | service
> +exits with 0 if the values of the running daemon exists
> +and 1 if it doesn't.
>  .Nm Cm ls failed
>  exits with 1 if an enabled daemon is not running.
>  Otherwise, the
> Index: usr.sbin/rcctl/rcctl.sh
> ===
> RCS file: /cvs/src/usr.sbin/rcctl/rcctl.sh,v
> retrieving revision 1.107
> diff -u -p -r1.107 rcctl.sh
> --- usr.sbin/rcctl/rcctl.sh   21 Oct 2018 21:20:40 -  1.107
> +++ usr.sbin/rcctl/rcctl.sh   15 Feb 2019 05:48:16 -
> @@ -21,6 +21,7 @@ _special_svcs="accounting check_quotas i
> spamd_black"
>  readonly _special_svcs
>  
> +_RC_RUNDIR=/var/run/rc.d
>  # get local functions from rc.subr(8)
>  FUNCS_ONLY=1
>  . /etc/rc.d/rc.subr
> @@ -32,7 +33,7 @@ usage()
>   for _i in ${_rc_actions}; do _a="$(echo -n ${_i}${_a:+|${_a}})"; done
>  
>   _rc_err \
> - "usage: rcctl get|getdef|set service | daemon [variable [arguments]]
> + "usage: rcctl get|getdef|getrun|set service | daemon [variable 
> [arguments]]
>   rcctl [-df] ${_a} daemon ...
>   rcctl disable|enable|order [daemon ...]
>   rcctl ls all|failed|off|on|started|stopped"
> @@ -374,6 +375,35 @@ svc_getdef()
>   fi
>  }
>  
> +svc_getrun()
> +{
> + local _svc=$1
> +
> + ( svc_is_special ${_svc} || svc_is_meta ${_svc} ) && return 1
> +
> + local _val _var=$2
> + local daemon_class daemon_flags daemon_rtable daemon_timeout daemon_user
> + local daemon_pexp
> +
> + [ ! -f $_RC_RUNDIR/$_svc ] && return 1
> + _rc_parse_conf -readonly $_RC_RUNDIR/$_svc
> +
> + [ -z "${daemon_pexp}" ] && eval daemon_pexp=\${pexp}
> +
> + if [ -n "${_var}" ]; then
> + eval _val=\${daemon_${_var}}
> + [ -z "${_val}" ] || print -r -- "${_val}"
> + else
> + echo "${_svc}_class=${daemon_class}"
> + echo "${_svc}_flags=${daemon_flags}"
> + echo "${_svc}_rtable=${daemon_rtable}"
> + echo "${_svc}_timeout=${daemon_timeout}"
> + echo "${_svc}_user=${daemon_user}"
> + echo "${_svc}_pexp=${daemon_pexp}"
> + fi
> + return 0
> +}
> +
>  svc_rm()
>  {
>   local _svc=$1
> @@ -509,7 +539,7 @@ case ${action} in
>   done
>   fi
>   ;;
> - get|getdef)
> + get|getdef|getrun)
>   svc=$2
>   var=$3
>   [ -z "${svc}" ] && usage
> @@ -571,7 +601,7 @@ case ${action} in
>   done
>   exit ${ret}
>   ;;
> - get|getdef)
> + get|getdef|getrun)
>   if [ "${svc}" = "all" ]; then
>   for svc in $(svc_ls all); do
>   ( svc_${action} ${svc} "${var}" )
> Index: etc/rc.d/rc.subr
> ===
> RCS file: /cvs/src/etc/rc.d/rc.subr,v
> retrieving revision 1.130
> diff -u -p -r1.130 rc.subr
> --- etc/rc.d/rc.subr  20 Jan 2019 04:52:07 -  1.130
> +++ etc/rc.d/rc.subr  15 Feb 2019 05:48:16 -
> @@ -138,18 +138,24 @@ _rc_quirks() {
>  
>  _rc_parse_conf() {
>   typeset -l _key
> - local _l _rcfile _val
> + local _l _rcfile _val _readonly=
>   set -A _allowed_keys -- \
>   accounting amd_master check_quotas ipsec library_aslr

Re: add getrun for rcctl(8)

2019-02-14 Thread YASUOKA Masahiko
On Fri, 15 Feb 2019 14:45:14 +0900 (JST)
YASUOKA Masahiko  wrote:
> The diff adds "getrun" command for rcctl(8) which shows the daemon
> variables from the running daemon.
> 
> ok? comment?

Sorry, previous diff is broken.  It could not get any value other than
daemon_pexp.  Let me update the diff.

Index: usr.sbin/rcctl/rcctl.8
===
RCS file: /cvs/src/usr.sbin/rcctl/rcctl.8,v
retrieving revision 1.35
diff -u -p -r1.35 rcctl.8
--- usr.sbin/rcctl/rcctl.8  20 Sep 2018 12:24:14 -  1.35
+++ usr.sbin/rcctl/rcctl.8  15 Feb 2019 05:48:16 -
@@ -22,7 +22,7 @@
 .Nd configure and control daemons and services
 .Sh SYNOPSIS
 .Nm rcctl
-.Cm get Ns | Ns Cm getdef Ns | Ns Cm set
+.Cm get Ns | Ns Cm getdef Ns | Ns Cm getrun Ns | Ns Cm set
 .Ar service | daemon Op Ar variable Op Ar arguments
 .Nm rcctl
 .Op Fl df
@@ -103,6 +103,10 @@ will display all services and daemons va
 Like
 .Cm get
 but returns the default values.
+.It Cm getrun Ar service | daemon Op Ar variable
+Like
+.Cm get
+but returns the values of the running daemon.
 .It Cm ls Ar lsarg
 Display a list of services and daemons matching
 .Ar lsarg ,
@@ -180,6 +184,9 @@ exits with 0 if the daemon or service is
 .Nm Cm getdef Ar daemon | service Op Cm status
 exits with 0 if the daemon or service is enabled by default
 and 1 if it is not.
+.Nm Cm getrun Ar daemon | service
+exits with 0 if the values of the running daemon exists
+and 1 if it doesn't.
 .Nm Cm ls failed
 exits with 1 if an enabled daemon is not running.
 Otherwise, the
Index: usr.sbin/rcctl/rcctl.sh
===
RCS file: /cvs/src/usr.sbin/rcctl/rcctl.sh,v
retrieving revision 1.107
diff -u -p -r1.107 rcctl.sh
--- usr.sbin/rcctl/rcctl.sh 21 Oct 2018 21:20:40 -  1.107
+++ usr.sbin/rcctl/rcctl.sh 15 Feb 2019 05:48:16 -
@@ -21,6 +21,7 @@ _special_svcs="accounting check_quotas i
spamd_black"
 readonly _special_svcs
 
+_RC_RUNDIR=/var/run/rc.d
 # get local functions from rc.subr(8)
 FUNCS_ONLY=1
 . /etc/rc.d/rc.subr
@@ -32,7 +33,7 @@ usage()
for _i in ${_rc_actions}; do _a="$(echo -n ${_i}${_a:+|${_a}})"; done
 
_rc_err \
-   "usage: rcctl get|getdef|set service | daemon [variable [arguments]]
+   "usage: rcctl get|getdef|getrun|set service | daemon [variable 
[arguments]]
rcctl [-df] ${_a} daemon ...
rcctl disable|enable|order [daemon ...]
rcctl ls all|failed|off|on|started|stopped"
@@ -374,6 +375,35 @@ svc_getdef()
fi
 }
 
+svc_getrun()
+{
+   local _svc=$1
+
+   ( svc_is_special ${_svc} || svc_is_meta ${_svc} ) && return 1
+
+   local _val _var=$2
+   local daemon_class daemon_flags daemon_rtable daemon_timeout daemon_user
+   local daemon_pexp
+
+   [ ! -f $_RC_RUNDIR/$_svc ] && return 1
+   _rc_parse_conf -readonly $_RC_RUNDIR/$_svc
+
+   [ -z "${daemon_pexp}" ] && eval daemon_pexp=\${pexp}
+
+   if [ -n "${_var}" ]; then
+   eval _val=\${daemon_${_var}}
+   [ -z "${_val}" ] || print -r -- "${_val}"
+   else
+   echo "${_svc}_class=${daemon_class}"
+   echo "${_svc}_flags=${daemon_flags}"
+   echo "${_svc}_rtable=${daemon_rtable}"
+   echo "${_svc}_timeout=${daemon_timeout}"
+   echo "${_svc}_user=${daemon_user}"
+   echo "${_svc}_pexp=${daemon_pexp}"
+   fi
+   return 0
+}
+
 svc_rm()
 {
local _svc=$1
@@ -509,7 +539,7 @@ case ${action} in
done
fi
;;
-   get|getdef)
+   get|getdef|getrun)
svc=$2
var=$3
[ -z "${svc}" ] && usage
@@ -571,7 +601,7 @@ case ${action} in
done
exit ${ret}
;;
-   get|getdef)
+   get|getdef|getrun)
if [ "${svc}" = "all" ]; then
for svc in $(svc_ls all); do
( svc_${action} ${svc} "${var}" )
Index: etc/rc.d/rc.subr
===
RCS file: /cvs/src/etc/rc.d/rc.subr,v
retrieving revision 1.130
diff -u -p -r1.130 rc.subr
--- etc/rc.d/rc.subr20 Jan 2019 04:52:07 -  1.130
+++ etc/rc.d/rc.subr15 Feb 2019 05:48:16 -
@@ -138,18 +138,24 @@ _rc_quirks() {
 
 _rc_parse_conf() {
typeset -l _key
-   local _l _rcfile _val
+   local _l _rcfile _val _readonly=
set -A _allowed_keys -- \
accounting amd_master check_quotas ipsec library_aslr \
multicast nfs_server pexp pf pkg_scripts shlib_dirs spamd_black
 
+   if [ "$1" = "-readonly" ]; then
+   _readonly=y
+   shift
+   fi
+
[ $# -gt 0 ] || set -- /etc/rc.conf /etc/rc.conf.local
for _rcfile; do
[[ -f $_rcfile ]] || continue
whil

add getrun for rcctl(8)

2019-02-14 Thread YASUOKA Masahiko
Hi,

The diff adds "getrun" command for rcctl(8) which shows the daemon
variables from the running daemon.

ok? comment?

Index: usr.sbin/rcctl/rcctl.8
===
RCS file: /cvs/src/usr.sbin/rcctl/rcctl.8,v
retrieving revision 1.35
diff -u -p -r1.35 rcctl.8
--- usr.sbin/rcctl/rcctl.8  20 Sep 2018 12:24:14 -  1.35
+++ usr.sbin/rcctl/rcctl.8  15 Feb 2019 05:41:38 -
@@ -22,7 +22,7 @@
 .Nd configure and control daemons and services
 .Sh SYNOPSIS
 .Nm rcctl
-.Cm get Ns | Ns Cm getdef Ns | Ns Cm set
+.Cm get Ns | Ns Cm getdef Ns | Ns Cm getrun Ns | Ns Cm set
 .Ar service | daemon Op Ar variable Op Ar arguments
 .Nm rcctl
 .Op Fl df
@@ -103,6 +103,10 @@ will display all services and daemons va
 Like
 .Cm get
 but returns the default values.
+.It Cm getrun Ar service | daemon Op Ar variable
+Like
+.Cm get
+but returns the values of the running daemon.
 .It Cm ls Ar lsarg
 Display a list of services and daemons matching
 .Ar lsarg ,
@@ -180,6 +184,9 @@ exits with 0 if the daemon or service is
 .Nm Cm getdef Ar daemon | service Op Cm status
 exits with 0 if the daemon or service is enabled by default
 and 1 if it is not.
+.Nm Cm getrun Ar daemon | service
+exits with 0 if the values of the running daemon exists
+and 1 if it doesn't.
 .Nm Cm ls failed
 exits with 1 if an enabled daemon is not running.
 Otherwise, the
Index: usr.sbin/rcctl/rcctl.sh
===
RCS file: /cvs/src/usr.sbin/rcctl/rcctl.sh,v
retrieving revision 1.107
diff -u -p -r1.107 rcctl.sh
--- usr.sbin/rcctl/rcctl.sh 21 Oct 2018 21:20:40 -  1.107
+++ usr.sbin/rcctl/rcctl.sh 15 Feb 2019 05:41:38 -
@@ -21,6 +21,7 @@ _special_svcs="accounting check_quotas i
spamd_black"
 readonly _special_svcs
 
+_RC_RUNDIR=/var/run/rc.d
 # get local functions from rc.subr(8)
 FUNCS_ONLY=1
 . /etc/rc.d/rc.subr
@@ -32,7 +33,7 @@ usage()
for _i in ${_rc_actions}; do _a="$(echo -n ${_i}${_a:+|${_a}})"; done
 
_rc_err \
-   "usage: rcctl get|getdef|set service | daemon [variable [arguments]]
+   "usage: rcctl get|getdef|getrun|set service | daemon [variable 
[arguments]]
rcctl [-df] ${_a} daemon ...
rcctl disable|enable|order [daemon ...]
rcctl ls all|failed|off|on|started|stopped"
@@ -374,6 +375,34 @@ svc_getdef()
fi
 }
 
+svc_getrun()
+{
+   local _svc=$1
+
+   ( svc_is_special ${_svc} || svc_is_meta ${_svc} ) && return 1
+   [ ! -f $_RC_RUNDIR/$_svc ] && return 1
+   _rc_parse_conf -readonly $_RC_RUNDIR/$_svc
+
+   local _val _var=$2
+   local daemon_class daemon_flags daemon_rtable daemon_timeout daemon_user
+   local daemon_pexp
+
+   [ -z "${daemon_pexp}" ] && eval daemon_pexp=\${pexp}
+
+   if [ -n "${_var}" ]; then
+   eval _val=\${daemon_${_var}}
+   [ -z "${_val}" ] || print -r -- "${_val}"
+   else
+   echo "${_svc}_class=${daemon_class}"
+   echo "${_svc}_flags=${daemon_flags}"
+   echo "${_svc}_rtable=${daemon_rtable}"
+   echo "${_svc}_timeout=${daemon_timeout}"
+   echo "${_svc}_user=${daemon_user}"
+   echo "${_svc}_pexp=${daemon_pexp}"
+   fi
+   return 0
+}
+
 svc_rm()
 {
local _svc=$1
@@ -509,7 +538,7 @@ case ${action} in
done
fi
;;
-   get|getdef)
+   get|getdef|getrun)
svc=$2
var=$3
[ -z "${svc}" ] && usage
@@ -571,7 +600,7 @@ case ${action} in
done
exit ${ret}
;;
-   get|getdef)
+   get|getdef|getrun)
if [ "${svc}" = "all" ]; then
for svc in $(svc_ls all); do
( svc_${action} ${svc} "${var}" )
Index: etc/rc.d/rc.subr
===
RCS file: /cvs/src/etc/rc.d/rc.subr,v
retrieving revision 1.130
diff -u -p -r1.130 rc.subr
--- etc/rc.d/rc.subr20 Jan 2019 04:52:07 -  1.130
+++ etc/rc.d/rc.subr15 Feb 2019 05:41:38 -
@@ -138,18 +138,24 @@ _rc_quirks() {
 
 _rc_parse_conf() {
typeset -l _key
-   local _l _rcfile _val
+   local _l _rcfile _val _readonly=
set -A _allowed_keys -- \
accounting amd_master check_quotas ipsec library_aslr \
multicast nfs_server pexp pf pkg_scripts shlib_dirs spamd_black
 
+   if [ "$1" = "-readonly" ]; then
+   _readonly=y
+   shift
+   fi
+
[ $# -gt 0 ] || set -- /etc/rc.conf /etc/rc.conf.local
for _rcfile; do
[[ -f $_rcfile ]] || continue
while IFS=' ' read -r _l; do
[[ $_l == [!#=]*=* ]] || continue
_key=${_l%%*([[:blank:]])=*}
-   [[ $_key == *_@(f