Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 312583

Summary: make sys-apps/slocate battery aware
Product: Gentoo Linux Reporter: Daniel Troeder <daniel>
Component: [OLD] Core systemAssignee: Gentoo's Team for Core System packages <base-system>
Status: RESOLVED FIXED    
Severity: enhancement CC: gef.kornflakes
Priority: High    
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---

Description Daniel Troeder 2010-04-01 10:42:00 UTC
I think it is very anoing if updatedb runs when I'm on battery. I don't want to remove cron globally from a battery-runlevel (and I can't expect all users to do so). So I think the cronjob could be a bit sensitive about it.

What do you think of the following modification to the slocate-cronjob?

/usr/bin/on_ac_power is from sys-power/pm-utils, what (I think) most
people have installed. If prefered we could check if sys-power/pm-utils is installed, and only then apply this patch.

--- /etc/cron.daily/slocate	2010-03-30 19:41:24.954135902 +0200
+++ /etc/cron.daily/slocate.old	2010-03-30 19:37:06.721255754 +0200
@@ -1,11 +1,5 @@
 #! /bin/sh

-if [ -x /usr/bin/on_ac_power ]; then
-    if ! /usr/bin/on_ac_power ; then
-        exit 0;
-    fi;
-fi
-
 if [ -x /usr/bin/updatedb ]
 then
 	if [ -f /etc/updatedb.conf ]

Reproducible: Always

Steps to Reproduce:
1. remove power from notebook
2. start cronjob (/etc/cron.daily/slocate)
Comment 1 Gef 2010-04-01 12:48:49 UTC
Nice idea. About its implementation, on baselayout-2.0 systems, there is also /lib/rc/bin/on_ac_power from sys-apps/openrc (which doesn't require sys-power/pm-utils) ; baselayout-1.12* doesn't looks like it has such a function.
Comment 2 SpanKY gentoo-dev 2010-04-02 09:03:42 UTC
your patch is reversed.  but anyways, as Gef points out, ive pushed Roy to export a helper function specifically for cronjobs to leverage.  that's the only thing i would use in cronjobs -- we're not going to start copying & pasting duplicate code all over the place.

the way to do things though is:
. /etc/init.d/functions.sh
on_ac_power 2>/dev/null
[ $? -eq 1 ] && exit 0
Comment 3 Daniel Troeder 2010-04-05 11:44:41 UTC
> your patch is reversed.
oops :D

Duplicate code is bad of course. Is it possible to check in an ebuild if we're on baselayout-2, and only then patch the cronjob with the three lines spanky suggests?