Bug 980134 - 'service httpd status' as non root, returns incorrect status
'service httpd status' as non root, returns incorrect status
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: initscripts (Show other bugs)
Unspecified Unspecified
unspecified Severity unspecified
: pre-dev-freeze
: 6.6
Assigned To: Lukáš Nykrýn
Jan Ščotka
Depends On: 971606
  Show dependency treegraph
Reported: 2013-07-01 09:44 EDT by Pádraig Brady
Modified: 2016-11-25 08:03 EST (History)
4 users (show)

See Also:
Fixed In Version: initscripts-9.03.44-1.el6
Doc Type: Bug Fix
Doc Text:
Previously when checking for running service only permission for pidfile were checked. When the parent directory for that pidfile was not accessible initscript returned wrong return code. Now we are also checking for permission for the parent directory.
Story Points: ---
Clone Of: 971606
Last Closed: 2014-10-14 02:27:04 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Pádraig Brady 2013-07-01 09:44:33 EDT
+++ This bug was initially created as a clone of Bug #971606 +++

When checking service status as a non root user...

  $ service httpd status
  httpd dead but subsys locked

Aside from the fact that this really shouldn't need root access,
the bug here is that the init script return code is incorrect:

  $ echo $?

states that "2" means the service is dead.
In this case "4" should be returned so that status
for this service can be presented correctly.

--- Additional comment from Jan Kaluža on 2013-06-07 00:50:23 EDT ---

I have checked httpd initscript and it uses "status" function from /etc/rc.d/init.d/functions (from package "initscripts") and returns its return code.

This function checks if the /var/run/httpd/httpd.pid exists, but /var/run/httpd directory has mode 0710, so as a user, you are not allowed to read its content. status function in /etc/init.d/functions should probably check for this case and return 4. I think this should be filed as a bug against initscripts package.
Comment 2 Lukáš Nykrýn 2013-07-10 07:41:42 EDT
In ideal case we should check whole path, but I think that parent dir of pid file should be enough.

untested patch:
diff --git a/rc.d/init.d/functions b/rc.d/init.d/functions
index fc5914c..e7725dd 100644
--- a/rc.d/init.d/functions
+++ b/rc.d/init.d/functions
@@ -148,6 +148,9 @@ __umount_loopback_loop() {
 __pids_var_run() {
        local base=${1##*/}
        local pid_file=${2:-/var/run/$base.pid}
+        local pid_dir=$(/usr/bin/dirname $pid_file)
+        [ -d "$pid_dir" -a ! -r "$pid_dir" ] && return 4
        if [ -f "$pid_file" ] ; then
Comment 6 Pádraig Brady 2014-06-05 10:14:35 EDT
The patch above looks incorrect. There is a redirect to >/dev/null ?
I.E. I'd change:

  /usr/bin/dirname $pid_file > /dev/null


  dirname "$pid_file"
Comment 10 errata-xmlrpc 2014-10-14 02:27:04 EDT
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.


Note You need to log in before you can comment on or make changes to this bug.