1

From manpage pm-action(8):

/etc/pm/sleep.d, /usr/lib/pm-utils/sleep.d

Programs in these directories (called hooks) are combined and executed in C sort order before suspend and hibernate with as argument ´suspend´ or ´hibernate´.

Afterwards they are called in reverse order with argument ´resume´ and ´thaw´ respectively.

If both directories contain a similar named file, the one in /etc/pm/sleep.d will get preference. It is possible to disable a hook in the distribution directory by putting a non-executable file in /etc/pm/sleep.d, or by adding it to the HOOK_BLACKLIST configuration variable.

What is "C sort order"?

Does "a similar named file" mean two files with the same filename?

I have two files /usr/lib/pm-utils/sleep.d/94cpufreq and /etc/pm/sleep.d/20_cpu_freq. When resume and thaw, which one is run first and which second?

Thanks.

3

The C lexical sort order is very simple: characters with a lower numeric value sort before characters with a higher one. As almost all UNIX-derived systems nowadays use extended ASCII-derived character sets, the ordering would therefore be 8-bit as follows:

  • Control characters: NUL-US (^@-^_: 0-26)
  • Printable characters: (space)-/, 0-9, :-@, A-Z, [-` , a-z, {-~
  • Extended characters: stuff afterwards (depends on the codepage)

Because of this, here are some filenames, in order:

!afile
0Afile
0_file
0afile
0~file
20-cpu_freq
20_cpu_freq
94Cpufreq
94cpufreq

By "similar named file", the two directory lists are combined, and if two file have the same name, the one in /etc/pm/sleep.d wins: if you had /usr/lib/pm-utils/sleep.d/94cpufreq and /etc/pm/sleep.d/94cpufreq, the latter would be read.

The order which these will be run is dictated by the operation that pm-utils is doing (from HOWTO.hooks):

SLEEP.D SPECIFIC NOTES

For any given sleep/wakeup cycle, the hooks in sleep.d are run twice:

  • Once in C lexical sort order before the system goes to sleep, and
  • Once in reverse C lexical sort order when the system wakes up.

TL;DR: 20_cpu_freq will be run first and 94cpufreq second when preparing to sleep, and the other way around when waking up.

Not the answer you're looking for? Browse other questions tagged or ask your own question.