Sleep hook in a subdirectory ignored but causes double execution of previous hook
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
pm-utils |
Won't Fix
|
Medium
|
|||
pm-utils (Ubuntu) |
Confirmed
|
Medium
|
Unassigned |
Bug Description
The set of sleep hooks provided in /usr/lib/
1 the hook is not run;
2 the previous hook, currently /usr/lib/
Presumably #1 is wrong, and results from an installation fault in packagekit, separately reported as bug 1548480.
#2 occurs because the function run_hooks() in /usr/lib/
At lines 243 on, there is a code path with no else clause through which the $hook from the previous iteration can be accidentally reused:
if [ -f "$syshooks/$base" ]; then
hook=
elif [ -f "$phooks/$base" ]; then
hook=
fi
An easy fix is to insert the missing else clause before the fi line so that the script skips the subdirectory or other non-regular file and carries on with the next correctly specified hook:
if [ -f "$syshooks/$base" ]; then
hook=
elif [ -f "$phooks/$base" ]; then
hook=
else
continue
fi
Observed in Lubuntu 14.04.3,4 with pm-utils 1.4.1-13ubuntu0
ProblemType: Bug
DistroRelease: Ubuntu 14.04
Package: pm-utils 1.4.1-13ubuntu0.2 [modified: usr/lib/
ProcVersionSign
Uname: Linux 4.2.0-29-generic i686
ApportVersion: 2.14.1-0ubuntu3.19
Architecture: i386
Date: Mon Feb 22 17:10:53 2016
InstallationDate: Installed on 2016-02-21 (0 days ago)
InstallationMedia: Lubuntu 14.04.4 LTS "Trusty Tahr" - Release i386 (20160217.1)
PackageArchitec
SourcePackage: pm-utils
UpgradeStatus: No upgrade log present (probably fresh install)
Changed in pm-utils: | |
importance: | Unknown → Medium |
status: | Unknown → Won't Fix |
tags: | added: bitesize |
tags: |
added: server-triage-discuss removed: server-todo |
tags: | removed: server-triage-discuss |
Created attachment 122012
patch taken from running pm-functions; also fixes comment typo
The function run_hooks() in pm-functions proposes to-be-executed hooks that includes subdirectories in the hook directories but neither fully validates each such hook as a regular file nor handles a set of to-be-executed hooks in a subdirectory. This can cause a hook to be executed more than once.
At lines 241 on, there is a code path with no else clause:
if [ -f "$syshooks/$base" ]; then "$syshooks/ $base" "$phooks/ $base"
hook=
elif [ -f "$phooks/$base" ]; then
hook=
fi
If the $base proposed by the for statement at line 229 doesn't match either of the -f tests (which will happen eg if a hook is configured in a subdirectory of the hook directory), the $hook from the previous iteration can be accidentally reused.
An easy fix is to insert the missing else clause before the fi line so that the script skips the subdirectory or other non-regular file and carries on with the next correctly specified hook, as in the attached patch.