cant use -d switch

Bug #1547060 reported by stsp on 2016-02-18
This bug affects 2 people
Affects Status Importance Assigned to Milestone
tgt (Debian)
Fix Released
tgt (Ubuntu)
Ryan Harper

Bug Description


 * Users of tgt who wish to make use of the server command line options:
   -d,--debug , -t,--nr_iothreads, -C,--control-port will fail due to
   an option parsing error. This prevents users from exercising
   additional control of the tgtd, regressing the capabilities of tgtd.

   This affects the 1.0.63 release of tgt and is not yet fixed upstream.
   Patches have been sumitted.

 * Backporting fixes from upstream release is required to ensure
   users of tgtd can exercise all capabilities, including enabling
   debugging and other features previously available to tgt users.

 * The patch fixes a misuderstanding of the use of errno after calling
   the strtoull libc call. Errno is not set in all cases for strtoull
   so extra checks must be used to determine if the current value of
   errno is related to the strtoull call.

[Test Case]

 * On a Xenial 16.04 system
    1. lxd init
    2. lxc launch ubuntu-daily:xenial x1
    3. lxc exec x1 -- /bin/bash -c 'apt-get update && apt-get -y install tgt && tgtd -d1; echo $?'

    # On FAILURE: return code will be non-zero with the following output

    -d argument value '1' invalid
    Try `tgtd --help' for more information.

    # After installing the newer tgt package, return code will be 0

[Regression Potential]

 * Unlikely any new regressions will take place as the current package
   prevents users from using portions of tgtd due to not being able to
   pass numeric values to tgtd options.

[Other Info]
 * Debian Bug filed:
 * Upstream request to accept patch

[Original Description]

# ./tgtd -d 1
-d argument value '1' invalid
Try `tgtd --help' for more information.

The following change should fix the problem:

--- util.h.old 2015-12-02 03:27:15.000000000 +0300
+++ util.h 2016-02-18 18:04:08.749932076 +0300
@@ -148,7 +148,7 @@
        unsigned long long ull_val; \
        ull_val = strtoull(str, &ptr, 0); \
        val = (typeof(val)) ull_val; \
- if (errno || ptr == str) \
+ if (ull_val == ULONG_MAX || ptr == str) \
                ret = EINVAL; \
        else if (val != ull_val) \
                ret = ERANGE; \

Here, the errno is checked incorrectly: you can't check
errno unless the returned value allows you to. In case
of strtoull(), errno should be checked only if ULONG_MAX is
I however can't test the fix properly because when compiled
from source, the bug doesn't happen. The value of errno is
unspecified, and it just happens to be 0 when I compile from

Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in tgt (Ubuntu):
status: New → Confirmed
Dimiter Naydenov (dimitern) wrote :

I'm seeing quite a lot of oom kills with multiple boot images imported in MAAS 2.0.0 (beta3), which depends on tgt via maas-rack-controller package.

FWIW this issue causes the workaround suggested in bug 1389811 impossible (passing -t 1 to limit the number of threads to 1, rather than causing oom killer).

Jon Grimm (jgrimm) on 2016-04-21
Changed in tgt (Ubuntu):
importance: Undecided → High
assignee: nobody → ChristianEhrhardt (paelzer)

reassigning, since Ryan took over even faster

Changed in tgt (Ubuntu):
assignee: ChristianEhrhardt (paelzer) → Ryan Harper (raharper)
Ryan Harper (raharper) wrote :

Applied patch as-is.

This issue exists in upstream (and Debian) as well.

A pull request has been sent to upstream, I'll forward this bug and link to the pull request to the stgt mailing list.

The attachment "fix-errno-parsing.debdiff" seems to be a debdiff. The ubuntu-sponsors team has been subscribed to the bug report so that they can review and hopefully sponsor the debdiff. If the attachment isn't a patch, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are member of the ~ubuntu-sponsors, unsubscribe the team.

[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issue please contact him.]

tags: added: patch
Ryan Harper (raharper) on 2016-04-21
description: updated
Changed in tgt (Debian):
status: Unknown → New
tags: added: xenial
Changed in tgt (Ubuntu):
status: Confirmed → Triaged
tags: added: regression-release
Daniel Holbach (dholbach) wrote :

Fixes for xenial/yakkety uploaded, sitting in the review queue now.

Changed in tgt (Ubuntu Xenial):
status: New → Fix Committed
Changed in tgt (Ubuntu):
status: Triaged → Fix Committed
Changed in tgt (Ubuntu Xenial):
importance: Undecided → High

Hello stsp, or anyone else affected,

Accepted tgt into xenial-proposed. The package will build now and be available at in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See for documentation how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, and change the tag from verification-needed to verification-done. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed. In either case, details of your testing will help us make a better decision.

Further information regarding the verification process can be found at . Thank you in advance!

tags: added: verification-needed
stsp (stsp-0) wrote :

Please consider integrating also the fix for
bug #1389811 to make the testing easier and
more sensible.

Launchpad Janitor (janitor) wrote :

This bug was fixed in the package tgt - 1:1.0.63-1ubuntu2

tgt (1:1.0.63-1ubuntu2) yakkety; urgency=medium

  * debian/patches/util_strtoull_errno.patch by Stas Sergeev
    - Fix errno handling for number * parsing (LP: #1547060)

 -- Ryan Harper <email address hidden> Thu, 21 Apr 2016 09:13:09 -0500

Changed in tgt (Ubuntu):
status: Fix Committed → Fix Released
Roy Zuo (roylez) on 2016-05-16
Changed in tgt (Ubuntu):
status: Fix Released → Confirmed
status: Confirmed → Fix Released
Jason Hobbs (jason-hobbs) wrote :

I tested tgt 1:1.0.63-1ubuntu1.1 on xenial and it fixed this bug for me.

tags: added: verification-done
removed: verification-needed
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package tgt - 1:1.0.63-1ubuntu1.1

tgt (1:1.0.63-1ubuntu1.1) xenial; urgency=medium

  * debian/patches/util_strtoull_errno.patch by Stas Sergeev
    - Fix errno handling for number * parsing (LP: #1547060)

 -- Ryan Harper <email address hidden> Thu, 21 Apr 2016 09:13:09 -0500

Changed in tgt (Ubuntu Xenial):
status: Fix Committed → Fix Released

The verification of the Stable Release Update for tgt has completed successfully and the package has now been released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regressions.

Christian Reis (kiko) wrote :

I just confirmed this was indeed a Xenial regression, as in Trusty this works fine.

Changed in tgt (Debian):
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.