Bug 240875 - usr.sbin/sysrc: If the file to be modified does not exist, an error message is displayed
Summary: usr.sbin/sysrc: If the file to be modified does not exist, an error message i...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Mateusz Piotrowski
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2019-09-27 15:02 UTC by Jose Luis Duran
Modified: 2023-07-06 15:43 UTC (History)
3 users (show)

See Also:


Attachments
sysrc.subr patch obtained from https://github.com/freebsd/poudriere/pull/708#issuecomment-526753174 (441 bytes, patch)
2019-09-27 15:02 UTC, Jose Luis Duran
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jose Luis Duran 2019-09-27 15:02:24 UTC
Created attachment 207890 [details]
sysrc.subr patch obtained from https://github.com/freebsd/poudriere/pull/708#issuecomment-526753174

Currently, with sysrc, if the file to be modified does not exist, an error message is displayed.

In this case, there is no /etc/rc.conf:

    root@test:~ # sysrc hostname="test.example.com"
    awk: can't open file /etc/rc.conf
     source line number 1
    hostname:  -> test.example.com

The patch fixes this situation.

This patch was created by @dteske, obtained from https://github.com/freebsd/poudriere/pull/708#issuecomment-526753174
Comment 1 commit-hook freebsd_committer freebsd_triage 2019-12-02 05:24:30 UTC
A commit references this bug:

Author: dteske
Date: Mon Dec  2 05:24:17 UTC 2019
New revision: 355280
URL: https://svnweb.freebsd.org/changeset/base/355280

Log:
  Fix spurious error from sysrc

  When using sysrc to modify a file, the file should be created silently.
  However, with the introduction of SVN r335280, an error of "No such file
  or directory" would appear despite everything else working as-expected.

  The nature of this spurious error is that SVN r335280 did not check if
  the file exists first, before trying to fixup the line-endings in the
  file just prior to modification.

  PR:		bin/240875
  Reported by:	Jose Luis Duran
  MFC after:	3 days

Changes:
  head/usr.sbin/bsdconfig/share/sysrc.subr
Comment 2 Jose Luis Duran 2023-02-01 14:08:21 UTC
Thank you!
Comment 3 Michael Osipov 2023-02-01 14:10:39 UTC
It never made it into FreeBSD 12 :-(
Comment 4 Mateusz Piotrowski freebsd_committer freebsd_triage 2023-07-06 15:40:14 UTC
(In reply to Michael Osipov from comment #3)
I've just MFCd that into 12.
Comment 5 commit-hook freebsd_committer freebsd_triage 2023-07-06 15:40:28 UTC
A commit in branch stable/12 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=98358de5754cc85b50309323ff72a66193502107

commit 98358de5754cc85b50309323ff72a66193502107
Author:     Devin Teske <dteske@FreeBSD.org>
AuthorDate: 2019-12-02 05:24:16 +0000
Commit:     Mateusz Piotrowski <0mp@FreeBSD.org>
CommitDate: 2023-07-06 15:39:23 +0000

    Fix spurious error from sysrc

    When using sysrc to modify a file, the file should be created silently.
    However, with the introduction of SVN r335280, an error of "No such file
    or directory" would appear despite everything else working as-expected.

    The nature of this spurious error is that SVN r335280 did not check if
    the file exists first, before trying to fixup the line-endings in the
    file just prior to modification.

    PR:             bin/240875
    Reported by:    Jose Luis Duran
    MFC after:      3 days

    (cherry picked from commit e19a2226fe3bbeeb6e922987475300868374d09a)

 usr.sbin/bsdconfig/share/sysrc.subr | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Comment 6 Michael Osipov 2023-07-06 15:42:49 UTC
(In reply to Mateusz Piotrowski from comment #4)

Magic, thank you!
Comment 7 Mateusz Piotrowski freebsd_committer freebsd_triage 2023-07-06 15:43:44 UTC
(In reply to Michael Osipov from comment #6)
Thank you for pointing out the issue!