Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 629338 - media-sound/mpd: init script improvements
Summary: media-sound/mpd: init script improvements
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Mikle Kolyada (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-29 23:55 UTC by Michael Orlitzky
Modified: 2019-01-22 17:31 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Orlitzky gentoo-dev 2017-08-29 23:55:36 UTC
The init script for mpd comes with a get_config() function:

  get_config() {
	x=$1
	test -e ${CFGFILE} || return 1
	sed -n \
	  -e '/^[ \t]*'${x}'/{s:^[ \t]*'${x}'[ \t]\+... \
	  ${CFGFILE}
  }

That's needed, essentially, because mpd doesn't let you override the PID file location on the command-line. However, it does let you run the daemon in the foreground via a command-line parameter. If you do that, OpenRC can background the process and manage the PID file for you, eliminating the need to dig through the config file. The resulting init script is a little simpler; get_config can be deleted, and you wind up with this chunk of variables:

  extra_started_commands='reload'
  command=/usr/bin/mpd
  command_args="--no-daemon ${CFGFILE}"
  command_background=true
  required_files=${CFGFILE}
  pidfile=/run/${RC_SVCNAME}.pid
  description="Music Player Daemon"

You can then eliminate a portion of your custom mpd-0.18.conf.patch -- the part that messes with the pid_file setting.

Finally, for the sake of portability, it's nice to use start-stop-daemon in the reload function:

  reload() {
      ebegin "Reloading ${RC_SVCNAME}"
      start-stop-daemon --pidfile $pidfile --signal HUP
      eend $?
  }

(otherwise you require sys-process/procps at runtime for "kill")
Comment 1 Andreas Sturmlechner gentoo-dev 2017-11-11 19:28:46 UTC
Michael, I think you can commit this change if it works for you - maybe together with a 0.20.11 version bump?
Comment 2 Michael Orlitzky gentoo-dev 2017-11-11 21:11:58 UTC
(In reply to Andreas Sturmlechner from comment #1)
> Michael, I think you can commit this change if it works for you - maybe
> together with a 0.20.11 version bump?

I don't use mpd myself, so I'm not confident saying that it works for me. I've been auditing init scripts: a lot of get_config() functions are exploitable -- and even though this one isn't -- I figured I'd offer some drive-by suggestions that I noticed in the process.
Comment 3 BT 2018-02-20 08:13:55 UTC
(In reply to Michael Orlitzky from comment #0)

It would be great to have your improvements committed. I believe it will also solve bug #645664.
Comment 4 Mikle Kolyada (RETIRED) archtester Gentoo Infrastructure gentoo-dev Security 2018-08-29 05:57:20 UTC
(In reply to Michael Orlitzky from comment #0)
> The init script for mpd comes with a get_config() function:
> 
>   get_config() {
> 	x=$1
> 	test -e ${CFGFILE} || return 1
> 	sed -n \
> 	  -e '/^[ \t]*'${x}'/{s:^[ \t]*'${x}'[ \t]\+... \
> 	  ${CFGFILE}
>   }
> 
> That's needed, essentially, because mpd doesn't let you override the PID
> file location on the command-line. However, it does let you run the daemon
> in the foreground via a command-line parameter. If you do that, OpenRC can
> background the process and manage the PID file for you, eliminating the need
> to dig through the config file. The resulting init script is a little
> simpler; get_config can be deleted, and you wind up with this chunk of
> variables:
> 
>   extra_started_commands='reload'
>   command=/usr/bin/mpd
>   command_args="--no-daemon ${CFGFILE}"
>   command_background=true
>   required_files=${CFGFILE}
>   pidfile=/run/${RC_SVCNAME}.pid
>   description="Music Player Daemon"
> 
> You can then eliminate a portion of your custom mpd-0.18.conf.patch -- the
> part that messes with the pid_file setting.
> 
> Finally, for the sake of portability, it's nice to use start-stop-daemon in
> the reload function:
> 
>   reload() {
>       ebegin "Reloading ${RC_SVCNAME}"
>       start-stop-daemon --pidfile $pidfile --signal HUP
>       eend $?
>   }
> 
> (otherwise you require sys-process/procps at runtime for "kill")

feel free to submit a pull request though :)
Comment 5 Mikle Kolyada (RETIRED) archtester Gentoo Infrastructure gentoo-dev Security 2019-01-22 17:31:22 UTC
I actually ammended the reload() function as I agree that s-s-d is better than the direct kill, as for pidfile path, I think this is better to leave everything as is.