Hi all,

I thought of adding another flag to apmd (or modify -A) to make it
run with hw.setperf=100 when the power is connected and automatically
adjust it when running on battery.  While reading the code and manual,
I figured the /etc/apm/* actions was a much better solution and added
a script which runs "apm -A" for powerdown and one with "apm -H" for
powerup.

I unplugged the power but nothing happened, ran "apm" manually and it
got stuck apmd was unresponsive.  It took me a few rounds to figure
it's the wait4() call suspending apmd while waiting for the child to
finish.  I assume this is to guarantee the child is finishes before the
machine begin suspending or hibernating, etc.

This could be avoided by adding a trailing '&' in the script, but I
can't decide which is more correct.  It feels ugly to add an exception
when running power{up,down} but it also feels like a bug if apmd becomes
unresponsive if one doesn't make apm execute in the background.

The patch below adds the exception.


Regards,
Jesper Wallin


Index: apmd.c
===================================================================
RCS file: /cvs/src/usr.sbin/apmd/apmd.c,v
retrieving revision 1.81
diff -u -p -r1.81 apmd.c
--- apmd.c      15 Oct 2017 15:14:49 -0000      1.81
+++ apmd.c      5 Apr 2018 20:50:10 -0000
@@ -664,6 +664,9 @@ do_etc_file(const char *file)
                /* NOTREACHED */
        default:
                /* We are the parent. */
+               if (strcmp(file, _PATH_APM_ETC_POWERUP) == 0 ||
+                   strcmp(file, _PATH_APM_ETC_POWERDOWN) == 0)
+                       return;
                wait4(pid, &status, 0, 0);
                if (WIFEXITED(status))
                        syslog(LOG_DEBUG, "%s exited with status %d", file,

Reply via email to