Skip to content

[BUG] -t | -w suppress warning message, but help text is still shown (#312) - #374

Open
hugojosealmeida wants to merge 5 commits into
lsof-org:masterfrom
hugojosealmeida:sdlc/issue-312-bug-t-w-suppress-warning-message-but-hel
Open

hugojosealmeida wants to merge 5 commits into
lsof-org:masterfrom
hugojosealmeida:sdlc/issue-312-bug-t-w-suppress-warning-message-but-hel

Conversation

@hugojosealmeida

@hugojosealmeida hugojosealmeida commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

When +D/+d (or other warning-guarded soft errors) targets a missing or invalid directory, enter_dir() returns failure and sets err, which unconditionally drives usage() and prints the version/usage/help block. The -w/-t flags only set Fwarn, suppressing the warning text but not the error-driven help text. A SoftErr flag now marks these warning-level failures; when warnings are suppressed (Fwarn set), main() exits silently with an error status instead of calling usage(), while normal (warnings-enabled) runs retain the existing warning + help output. Hard errors are unaffected and still show help text.

Changes

  • src/arg.c: declare extern int SoftErr; and set SoftErr = 1 on warning-guarded soft failures (enter_dir, enter_efsys, enter_fd_lst), with braces fixed on the Readlink branches.
  • src/main.c: define int SoftErr = 0; and, before calling usage(), call Error(ctx) when err && Fwarn && SoftErr so suppressed soft errors exit silently.

Verification

  • make -> build succeeds
  • ./lsof -w +D /test -> no output, exit 1
  • ./lsof -t +D /test -> no output, exit 1
  • ./lsof +D /test -> warning + help text preserved, exit 1
  • ./lsof -w -z -> hard error still shows help text, exit 1
  • bash tests/case-20-exit-status.bash ... -> pass
  • bash tests/case-20-handle-missing-files.bash ... -> pass

Risks / Follow-ups

See CI failure description at #374 (comment)


This PR is AI Assisted.

Closes #312

@hugojosealmeida

hugojosealmeida commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor Author

The following CI steps are failing at Build and test using auto toolset on ci/circleci: linux-archlinux, ci/circleci: linux-fedora38 and ci/circleci: linux-opensuse15

FAIL: tests/LTlock

I am not able to see details of ./test-suite.log at https://app.circleci.com/pipelines/github/lsof-org/lsof/884/details?workflowId=8c9fec36-da21-4ac9-9914-68b5ef27c635.

Nevertheless it passes in my local environment (opensuse/leap:15):

NAME="openSUSE Leap"
VERSION="15.6"
(...)
SKIP: lib/dialects/linux/tests/case-20-ux-socket-endpoint.bash
PASS: lib/dialects/linux/tests/case-20-ux-socket-endpoint-unaccepted.bash
PASS: lib/dialects/linux/tests/case-20-unbal-parens.bash
PASS: tests/LTbasic
PASS: tests/LTbigf
PASS: tests/LTdnlc
PASS: tests/LTlock
SKIP: tests/LTnfs
PASS: tests/LTnlink
PASS: tests/LTsock
PASS: tests/LTszoff
PASS: tests/LTunix
PASS: tests/LTbasic2
============================================================================
Testsuite summary for lsof 4.99.7
============================================================================
# TOTAL: 42
# PASS:  31
# SKIP:  11
# XFAIL: 0
# FAIL:  0
# XPASS: 0
# ERROR: 0
============================================================================
make[2]: Leaving directory '/src'
make[1]: Leaving directory '/src'
4cf32bdea806:/src # cat ./test
test-driver     test-suite.log  tests/          
4cf32bdea806:/src # cat ./test
test-driver     test-suite.log  tests/          
4cf32bdea806:/src # cat ./test-suite.log 
===================================
   lsof 4.99.7: ./test-suite.log
===================================

# TOTAL: 42
# PASS:  31
# SKIP:  11
# XFAIL: 0
# FAIL:  0
# XPASS: 0
# ERROR: 0

Maybe someone could support me to understand what is really failing at circleci (x86_64 vs. my aarch64 container??).

Comment thread arg-20f1a0cd.o.tmp Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not commit temp files

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accidentally committed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems the repo's .gitignore ignores *.o, *.lo, etc., but not *.o.tmp, so libtool temp files can slip through. Maybe this also could be added to .gitignore?!

Comment thread src/arg.c Outdated
"%s: -e not followed by a file system path: \"%s\"\n",
Pn, e);
return (1);
SoftErr = 1; return (1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to change the return value, instead of using another global variable to express this difference, e.g. return (2).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, nevertheless, 0 and 1 are the conventional success/failure returns that are used throughout lsof codebase, like read it as boolean. A bare 2  has no such convention, it is kind we need to guess what it means. I will take a look at this to make the solution more elegant, maybe using a 2  with a comment in the function header...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe an enum for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case a full three-value enum ( OK ,  ERR ,  SOFT_ERR) would be cleaner, but the impact is huge. But 0 and 1 shall remain untouched and so I do agree that having the anonymous enum (e.g. SOFT_ERR = 2) is the compromise.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have replaced global SoftErr with enum { SOFT_ERR = 2 }, preserving existing 0/1 returns. Soft errors propagate through helpers without masking hard errors. Added regression tests.

Resolve the enter_efsys() conflict by keeping master's Readlink() cleanup (free(ec) and Readlink_op reset) and the PR's SoftErr marking.
Preserve hard-error precedence through argument helpers and keep warning-level failures local to argument processing. Add regression coverage for suppressed warnings, explicit help, option ordering, and mixed FD-list errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] -t | -w suppress warning message, but help text is still shown

2 participants