Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 820149

Summary: sed -i will change symbolic link to file.
Product: Red Hat Enterprise Linux 6 Reporter: Freax <holmes86>
Component: sedAssignee: Petr Stodulka <pstodulk>
Status: CLOSED WONTFIX QA Contact: qe-baseos-tools-bugs
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.2CC: cww, dsulliva, hhorak, hripps, ovasik
Target Milestone: rcKeywords: Reopened
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 1289645 (view as bug list) Environment:
Last Closed: 2016-08-17 19:06:48 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1269194, 1289645    

Description Freax 2012-05-09 09:34:32 UTC
Description of problem:

if use "sed -i " edit a symbolic link, will change this link to a regular file and no longer a symbolic link. sed version is 4.2.1.


Version-Release number of selected component (if applicable):


How reproducible:

On RHEL 6.2:
# touch a
# ln -s a b
# ll b
lrwxrwxrwx 1 root root 1 May  9 01:06 b -> a
# sed -i '/test/d' b
# ll b
-rw-r--r-- 1 root root 0 May  9 01:06 b
# sed --version
GNU sed version 4.2.1

On RHEL 5.4:
# touch a
# ln -s a b
# ll b
lrwxrwxrwx 1 root root 1 May  9 17:09 b -> a
# sed -i '/test/d' b
sed: ck_follow_symlink: couldn't lstat b/a: Not a directory
# sed -i '/test/d' $PWD/b
# ll b
lrwxrwxrwx 1 root root 1 May  9 17:09 b -> a
# sed --version
GNU sed version 4.1.5

Steps to Reproduce:
1.
2.
3.
  
Actual results:

sed -i should edit target file of symbolic link.


Expected results:


Additional info:

Comment 2 Freax 2012-05-09 10:54:56 UTC
I found sed has --follow-symlinks parameter, so this should be not a bug.

Comment 3 Dave Sullivan 2015-12-08 14:43:28 UTC
I'm reopening this bug as this is bad.

e.g. someone could unknowingly do a sed -i edit on /etc/grub.conf

And the link is removed and file replaced.

Now when kernel is updated form a patch.

It does a readlink

grubConfig=$(readlink -f /etc/grub.conf 2>/dev/null)

But seems to work fine on regular file.

And hence /boot/grub/grub.conf is not updated.

So on reboot you don't boot to the patched kernel.

Fixing the link and reboot resolves the issue but this seems bad in my view.

I think the default handling of sed -i on links should error out mentioning to run the sed -i on the target and or use the --follow-symlinks

Comment 4 Ondrej Vasik 2016-08-05 09:17:22 UTC
TBH, I don't think this should be changed in RHEL 6 - given the fact we are now in production phase 2. It is change in behaviour and can potentially break something. In addition, behaviour is still the same in RHEL 7.

Comment 5 Petr Stodulka 2016-08-05 10:11:07 UTC
I agree with Ondrej. I understand Dave's opinion but it is somthing what could be fixed in rawhide after discussion with upstream. For me it's similar to gzip, which by default removes original file when --keep option isn't used.

I know, it's not same, but point says that you should read manual at first. And really, if this is sou expected behaviour, shouldn't be this fixed rather by some alias for root like e.g. "rm" uses "-i"? Yes, this is ugly solution too. But to be honest, not uglier than above.

We should'n just change behaviour because we expect user will not read manual, otherwise we can "redesign" half of system.

Comment 6 Chris Williams 2016-08-17 19:06:48 UTC
When Red Hat shipped 6.8 on May 10, 2016 RHEL 6 entered Production Phase 2. 
https://access.redhat.com/support/policy/updates/errata#Production_2_Phase
That means only "Critical and Important Security errata advisories (RHSAs) and Urgent Priority Bug Fix errata advisories (RHBAs) may be released"
This BZ is now going to be closed as it does not appear to meet Phase 2 criteria. 
If this BZ is deemed critical please open a support case in the Red Hat Customer Portal and as that this BZ be re-opened so it can be re-evaluated for 6.9.