[Pm-utils] RFC - PATCH to functions.in to support Slackware init

Victor Lowther victor.lowther at gmail.com
Thu Oct 30 05:09:55 PDT 2008


On Wed, 2008-10-29 at 23:15 -0500, Robby Workman wrote:
> On Wed, 29 Oct 2008 16:44:39 -0500
> Victor Lowther <victor.lowther at gmail.com> wrote:
> 
> > On Oct 29, 2008, at 4:02 PM, Robby Workman <rw at rlworkman.net> wrote:
> > > I like the idea, I think.  I almost prefer to have those named in a
> > > format of "$distro.functions" and "$distro.pm-functions" though.
> > > This, of course, would require testing if the directory is not empty
> > > and then sourcing all of its contents if not, or perhaps this, to
> > > add (probably needless) complexity:  a --with-distro=$distro
> > > configure flag, and then configure could write that value into the
> > > stock functions files so that it knows what to source.  Did that
> > > make any sense? :-)
> > 
> > Well, Part of the idea is that upstream pm-utils would not do
> > anything in the distro.d directory - it would be there for the
> > distros to use or ignore as they choose. I don't want to be in the
> > business of maintaining every distro-specific method for doing
> > something out there  
> > - I just want to provide sane defaults and make it easy for distro  
> > maintainers to customize things. Giving y'all a designated place and
> > a method to do so is part of that goal.
> 
> 
> I don't think I was very clear in explaining what I meant.  Maybe you
> still won't like it, and if not, fine :) but I'll try again...
> 
> The idea was that, for example in our case, it would be even more clear
> that the directory is Slackware-specific, as the directory would be
> named /usr/lib/pm-utils/distro.d/ and contain files named
> "slackware.functions" and "slackware.pm-functions"
> 
> There wouldn't be a need for the pm-utils package itself to create
> anything but the "distro.d" directory.  The packager would decide the
> naming scheme of the files inside via the --with-distro flag to
> configure.  If the package sets --with-distro=slackware, then the files
> are named as I stated above.  If --with-distro=redhat, then the files
> are named redhat.functions and redhat.pm-functions, and if nothing is
> specified there, it could default to distro.functions and
> distro.pm-functions.  In the process, configure would also substitute
> in that value to the stock "functions" and "pm-functions" files from
> the .in files so that it would be seamless.
> 
> Now, with all that said, I'm second-guessing myself and thinking that
> it's just needless complexity, so at this point, unless you're
> agreeing, let's nix that idea. :-)  

Well, it sounds needlessly complicated to me -- if you were in the habit
of creating single packages customized for multiple distributions at
once it would come in handy, but that sounds like a rather unusual way
of doing things too me.

> However, perhaps "vendor.d" is a bit better sounding than "distro.d" as
> are "vendor.functions" and "vendor.pm-functions"  :-)

Essentially, my proposed directory structure is this:

/etc/pm/config.d/..
	sleep.d/...
	power.d/...
/usr/lib/pm-utils
	 functions
	 pm-functions
	 defaults
	 sleep.d/...
	 power.d/...
	 modules.d/...
	 distro.d/functions
		  pm-functions
		  sleep.d/...
		  power.d/...
		  modules.d/...
		  config.d/...

A patch against fd.o master that implements these ideas is here (with a
couple of other bugfixes):

diff --git a/Makefile.am b/Makefile.am
index 958b3b9..d3d8d0c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,8 @@
 SUBDIRS = pm man src
 
 pkgconfigdir = $(libdir)/pkgconfig
+pm_libdir=$(libdir)/pm-utils
+pm_distrodir=$(pm_libdir)/distro.d
 pkgconfig_DATA = pm-utils.pc
 
 dist_doc_DATA = README			\
@@ -22,6 +24,13 @@ ChangeLog:
 
 dist-hook: ChangeLog
 
+install-exec-local:
+	-mkdir -p $(DESTDIR)$(sysconfdir)/pm/config.d
+	-mkdir -p $(DESTDIR)$(pm_distrodir)/sleep.d
+	-mkdir -p $(DESTDIR)$(pm_distrodir)/power.d
+	-mkdir -p $(DESTDIR)$(pm_distrodir)/modules.d
+	-mkdir -p $(DESTDIR)$(pm_distrodir)/config.d
+
 MAINTAINERCLEANFILES = ChangeLog
 
 clean-local :
diff --git a/README.distributions b/README.distributions
index 38c1b07..f51ed0d 100644
--- a/README.distributions
+++ b/README.distributions
@@ -10,4 +10,34 @@ fix would be to have the anacron package install a hook in
 This will also help package maintenance by allowing package maintainers to 
 keep track of what the best way to handle any suspend/resume functionality their
 package requires insteas of leaving it up to the pm-utils maintainers to guess
-at what functionality is needed.
\ No newline at end of file
+at what functionality is needed.
+
+To make this easier, pm-utils supports pkg-config, which makes it easy for
+packages that use automake to detect the presence of pm-utils and the locations
+that hooks should be installed in.  The pm-utils pkgconfig file exports the 
+following variables:
+
+pm_libdir: This is the directory that the pm-utils infrastructure is installed
+	   in.  /usr/lib/pm-utils is the default value
+
+pm_sysconfdir: This is the directory that any package-specific pm-utils related
+	       config files should be installed in.  
+	       Defaults to /etc/pm/config.d
+
+pm_distrodir: Distribution-specific customization should go here.  If you need
+	      to override functionality in pm-utils and to add distro-maintained
+	      hooks. ${pm_libdir}/(functions|pm-functions) will look for files
+	      of the same name and source them after loading themselves -- you
+	      can override pm-utils supplied core functionality that way.
+
+pm_sleephooks: This is the directory that sleep hooks are installed in.  
+	       Defaults to ${pm_distrodir}/sleep.d
+
+pm_powerhooks: This is the directory that power management hooks are installed
+	       in.  Defaults to ${pm_distrodir}/power.d
+
+pm_sleepmodules: This is the directory that sleep modules are installed in.  
+		 Defaults to ${pm_distrodir}/module.d
+
+pm_distconfdir: This is the directory where package-supplied configuration
+		snippets should go.  Defaults to ${pm_distrodir}/config.d
diff --git a/pm-utils.pc.in b/pm-utils.pc.in
index 668ef29..5b23bb4 100644
--- a/pm-utils.pc.in
+++ b/pm-utils.pc.in
@@ -4,7 +4,12 @@ libdir=@libdir@
 sysconfdir=@sysconfdir@
 
 pm_libdir=${libdir}/pm-utils
+pm_distrodir=${pm_libdir}/distro.d
 pm_sysconfdir=${sysconfdir}/pm
+pm_sleephooks=${pm_distrodir}/sleep.d
+pm_powerhooks=${pm_distrodir)/power.d
+pm_sleepmodules=${pm_distrodir}/module.d
+pm_distconfdir=${pm_distrodir}/config.d
 
 Name: pm-utils
 Description: Power management scripts for suspend and hibernate
diff --git a/pm/Makefile.am b/pm/Makefile.am
index 08a9054..63408af 100644
--- a/pm/Makefile.am
+++ b/pm/Makefile.am
@@ -19,9 +19,6 @@ CLEANFILES =  $(script_in_files:.in=)
 
 EXTRA_DIST =  $(script_in_files)
 
-install-exec-local:
-	-mkdir $(DESTDIR)$(sysconfdir)/pm/config.d
-
 do_subst = sed -e 's,[@]PM-UTILS-LIBDIR[@],$(pm_libdir),g' \
 	   -e 's,[@]PM-UTILS-SYSCONFDIR[@],$(pm_sysconfdir),g'
 
diff --git a/pm/functions.in b/pm/functions.in
index 110282e..c3d55fc 100644
--- a/pm/functions.in
+++ b/pm/functions.in
@@ -240,3 +240,12 @@ has_parameter()
 	done
 	return 1
 }
+
+[ -f "$PM_UTILS_DISTRODIR/functions" ] && \
+    . "$PM_UTILS_DISTRODIR/functions"
+
+# Like regular dbus-send, but returns $NA if the command fails for any reason.
+dbus_send ()
+{
+	command dbus-send "$@" 2>/dev/null || return $NA
+}
diff --git a/pm/pm-functions.in b/pm/pm-functions.in
index f5cc400..67eea5c 100644
--- a/pm/pm-functions.in
+++ b/pm/pm-functions.in
@@ -17,6 +17,7 @@ set -a
 PM_UTILS_LIBDIR="@PM-UTILS-LIBDIR@"
 PM_UTILS_ETCDIR="@PM-UTILS-SYSCONFDIR@"
 PM_UTILS_RUNDIR="/var/run/pm-utils"
+PM_UTILS_DISTRODIR="${PM_UTILS_LIBDIR}/distro.d"
 
 PATH=/sbin:/usr/sbin:/bin:/usr/bin:"${PM_UTILS_LIBDIR}"/bin
 PM_LOGFILE="/var/log/${STASHNAME}.log"
@@ -57,7 +58,11 @@ SUSPEND_HYBRID_MODULE=""
     . "${PM_UTILS_LIBDIR}/${STASHNAME}.defaults"
 set +a
 
-for cfg in "${PM_UTILS_ETCDIR}"/config.d/*[!~] \
+# we want user config settings to override distro-configured settings,
+# so load distro specific config settings first.
+for cfg in "${PM_UTILS_DISTRODIR}"/config.d/*[!~] \
+           "${PM_UTILS_DISTRODIR}/${STASHNAME}.config.d"/*[!~] \
+           "${PM_UTILS_ETCDIR}"/config.d/*[!~] \
            "${PM_UTILS_ETCDIR}/${STASHNAME}.config.d"/*[!~]; do
 	[ -f "$cfg" ] || continue
 	# Ugly, I know. The goal here is to allow multiple files in
@@ -179,6 +184,7 @@ run_hooks() {
 	# $3 = if present and equal to "reverse", run hooks backwards.
 	# Currently only power and sleep are meaningful.
 	local syshooks="${PM_UTILS_ETCDIR}/$1.d"
+	local disthooks="${PM_UTILS_DISTRODIR}/$1.d"
 	local phooks="${PM_UTILS_LIBDIR}/$1.d"
 	command_exists before_hooks && before_hooks
 	local sort="sort"
@@ -190,8 +196,10 @@ run_hooks() {
 "
 	IFS="${nifs}" # tolerate spaces in filenames.
 	[ "$3" = "reverse" ] && sort="sort -r"
-	for base in $(IFS="${oifs}"; for f in "$syshooks/"*[!~] "$phooks/"*[!~];
-		do [ -O "$f" ] && echo ${f##*/} ; done | $sort | uniq) ;
+	for base in $(IFS="${oifs}"; 
+	    for f in "$syshooks/"*[!~] "$phooks/"*[!~] "$disthooks/"*[!~];
+	        do [ -O "$f" ] && echo ${f##*/} ; 
+	    done | $sort | uniq) ;
 	do
 		IFS="${oifs}"
 		# if we are running backwards, skip hooks that we did not 
@@ -202,11 +210,12 @@ run_hooks() {
 		# don't run any more hooks.
 		[ ! "$3" ] && inhibited && break
 		update_parameters
-		if [ -f "$syshooks/$base" ]; then
-			hook="$syshooks/$base"
-		elif [ -f "$phooks/$base" ]; then
-			hook="$phooks/$base"
-		fi
+		for basedir in "$syshooks" "$disthooks" "$phooks"; do
+		    [ -f "$basedir/$base" ] || continue
+		    hook="$basedir/$base"
+		    break
+		done
+		[ "$hook" ] || continue
 		log -n "${hook} $2: "
 		hook_ok "$hook" && "${hook}" $2 
 		# if the hook exited with an unknown exit code inhibit,
@@ -246,9 +255,13 @@ if [ "$SLEEP_MODULE" = "auto" ]; then
 fi
 
 for mod in $SLEEP_MODULE; do
-    mod="${PM_UTILS_LIBDIR}/module.d/${mod}"
-    [ -f "$mod" ] || continue
-    . "$mod"
+    for basedir in "${PM_UTILS_LIBDIR}" "${PM_UTILS_DISTRODIR}"
+    do
+	mod="${basedir}/module.d/${mod}"
+	[ -f "$mod" ] || continue
+	. "$mod"
+	break
+    done
 done
 
 # always fall back to kernel methods if nothing else was declared
@@ -275,3 +288,6 @@ if [ -z "$HIBERNATE_MODULE" ] && \
 		echo -n "disk" > /sys/power/state
 	}
 fi
+
+[ -f "$PM_UTILS_DISTRODIR/pm-functions" ] && \
+	. "$PM_UTILS_DISTRODIR/pm-functions"

		  

> -RW
-- 
Victor Lowther
RHCE# 805008539634727
LPIC-2# LPI000140019



More information about the Pm-utils mailing list