Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 482830 - sys-block/tgt-1.0.24-r1 - init.d script always claims tgtd isn't running
Summary: sys-block/tgt-1.0.24-r1 - init.d script always claims tgtd isn't running
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Matthew Thode ( prometheanfire )
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-28 17:54 UTC by Jernej Simončič
Modified: 2015-08-06 02:14 UTC (History)
5 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
tgtd init patch (tgtd.init.patch,527 bytes, patch)
2014-07-20 22:54 UTC, Erik Mackdanz
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jernej Simončič 2013-08-28 17:54:34 UTC
# /etc/init.d/tgtd status; ps -C tgtd
tgtd is NOT running.
  PID TTY          TIME CMD
 3056 ?        00:00:00 tgtd
 3057 ?        00:00:00 tgtd

The reason for this seems the way /etc/init.d/tgtd checks for number of running tgtd processes:

status() {
        # Don't name this script "tgtd"...
        TGTD_PROC=$(ps -C tgtd | grep -c tgtd)
        if [ "$TGTD_PROC" -eq 2 ] ; then
            echo "tgtd is running. Run 'tgt-admin -s' to see detailed target info."
        else
            echo "tgtd is NOT running."
        fi
}

Note the comment.
Comment 1 Erik Mackdanz gentoo-dev 2014-07-18 03:45:28 UTC
I ran into this tonight, so it's still an issue.  As the submitter pointed out, the status checks for two running processes that match 'tgtd', which fails when the third (grep) process runs.

Since tgtd doesn't create a pid file, a slightly better test might be "Are two processes running whose names start with tgtd, one of which is the other's parent?"  

We could even start the process as "tgtd --debug 0" to make the text match better.  The "--debug 0" would be a no-op, and would have to be omitted if the user specified an actual --debug in /etc/conf.d/tgtd.

Unrelatedly, the stop command fails to stop the daemon, and I question the assumption in the comments "tgtd will exit if all targets were removed".  The whole script could probably use review.
Comment 2 Erik Mackdanz gentoo-dev 2014-07-20 22:54:21 UTC
Created attachment 381178 [details, diff]
tgtd init patch

Proposed fix.  Uses pidof (from procps, a base package).

Test case:
1. /etc/init.d/tgtd start
2. /etc/init.d/tgtd status
Expect: Messaging that tgtd is running
Actual: Messaging "tgtd is NOT running", ps shows tgtd processes
Comment 3 Thomas Capricelli 2015-04-25 16:41:52 UTC
I've kept on having problems such as this one with tgtd init scripts (for 1.5 years).
Comment 4 Matthew Thode ( prometheanfire ) archtester Gentoo Infrastructure gentoo-dev Security 2015-08-05 01:45:13 UTC
I'm gonna work on it sometime this week(end).
Comment 5 Matthew Thode ( prometheanfire ) archtester Gentoo Infrastructure gentoo-dev Security 2015-08-06 02:14:40 UTC
Fixed in 1.0.60