Bug 229806 - usr.sbin/sysrc: Warning message "unknown variable" should be on stderr
Summary: usr.sbin/sysrc: Warning message "unknown variable" should be on stderr
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 11.1-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: Devin Teske
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2018-07-16 14:49 UTC by Andreas Sommer
Modified: 2018-08-10 20:57 UTC (History)
1 user (show)

See Also:


Attachments
Write warning to stderr (432 bytes, patch)
2018-07-16 14:49 UTC, Andreas Sommer
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Sommer 2018-07-16 14:49:11 UTC
Created attachment 195172 [details]
Write warning to stderr

Patch speaks for itself. This hit me when I did a scripted `sysrc -n -f /usr/local/etc/my-config-file my-var` and ended up having an error message in stdout instead of an empty value.
Comment 1 Devin Teske freebsd_committer freebsd_triage 2018-07-16 18:28:17 UTC
Thanks.

Will apply with minor modification -- \\n should be \n (doesn't matter if the shell expands it before passing it to printf or not; either way you get the desired result).
Comment 2 commit-hook freebsd_committer freebsd_triage 2018-07-16 18:53:53 UTC
A commit references this bug:

Author: dteske
Date: Mon Jul 16 18:53:18 UTC 2018
New revision: 336350
URL: https://svnweb.freebsd.org/changeset/base/336350

Log:
  sysrc(8): Send error message to stderr (not stdout)

  PR:		bin/229806
  Reported by:	Andreas Sommer <andreas.sommer87@googlemail.com>
  MFC after:	3 days
  X-MFC-to:	stable/11 stable/10 stable/9
  Sponsored by:	Smule, Inc.

Changes:
  head/usr.sbin/sysrc/sysrc
Comment 3 Andreas Sommer 2018-07-17 05:23:54 UTC
(In reply to Devin Teske from comment #1)
Sure, I don't mind staying consistent in "\n" vs. "\\n" as it does not matter here. Linters like shellcheck, however, explicitly spit out a note at such lines (which is why I usually write it using escaping):

  Backslash is literal in "\n". Prefer explicit escaping: "\\n". [SC1117]
Comment 4 commit-hook freebsd_committer freebsd_triage 2018-08-10 20:08:45 UTC
A commit references this bug:

Author: dteske
Date: Fri Aug 10 20:08:00 UTC 2018
New revision: 337588
URL: https://svnweb.freebsd.org/changeset/base/337588

Log:
  MFC SVN r336350: Send sysrc(8) error message to stderr (not stdout)

  PR:		bin/229806
  Reported by:	Andreas Sommer <andreas.sommer87@googlemail.com>
  Sponsored by:	Smule, Inc.

Changes:
_U  stable/10/
  stable/10/usr.sbin/sysrc/sysrc
_U  stable/11/
  stable/11/usr.sbin/sysrc/sysrc
_U  stable/9/
_U  stable/9/usr.sbin/
_U  stable/9/usr.sbin/sysrc/
  stable/9/usr.sbin/sysrc/sysrc