Bug 1348671

Summary: [PATCH] install-info: Use create-tmp-then-rename pattern
Product: [Fedora] Fedora Reporter: Colin Walters <walters>
Component: texinfoAssignee: Vitezslav Crhonek <vcrhonek>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 23CC: pertusus, vcrhonek
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: texinfo-6.1-3.fc24 texinfo-6.0-3.fc23 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-06-23 17:53:17 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: 1352154    
Attachments:
Description Flags
0001-install-info-Use-create-tmp-then-rename-pattern.patch none

Description Colin Walters 2016-06-21 17:39:45 UTC
Created attachment 1170337 [details]
0001-install-info-Use-create-tmp-then-rename-pattern.patch

From 23c3374a73a438029c17bcf385e7486754bead7a Mon Sep 17 00:00:00 2001
From: Colin Walters <walters>
Date: Tue, 21 Jun 2016 13:02:04 -0400
Subject: [PATCH] install-info: Use create-tmp-then-rename pattern

rpm-ostree uses
https://github.com/ostreedev/ostree/blob/master/man/rofiles-fuse.xml
when running `%post` scripts, to avoid corruption of the underlying
hardlink store.

Switch to that pattern to be compatible.
---
 install-info/install-info.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/install-info/install-info.c b/install-info/install-info.c
index 4e39122..ef29eaf 100644
--- a/install-info/install-info.c
+++ b/install-info/install-info.c
@@ -954,18 +954,23 @@ output_dirfile (char *dirfile, int dir_nlines, struct line_data *dir_lines,
   int n_entries_added = 0;
   int i;
   FILE *output;
+  char *dirfile_tmp = NULL;
+
+  asprintf (&dirfile_tmp, "%s.tmp", dirfile);
+  if (!dirfile_tmp)
+    xalloc_die ();
 
   if (compression_program)
     {
-      char *command = concat (compression_program, ">", dirfile);
+      char *command = concat (compression_program, ">", dirfile_tmp);
       output = popen (command, "w");
     }
   else
-    output = fopen (dirfile, "w");
+    output = fopen (dirfile_tmp, "w");
 
   if (!output)
     {
-      perror (dirfile);
+      perror (dirfile_tmp);
       exit (EXIT_FAILURE);
     }
 
@@ -1076,6 +1081,12 @@ output_dirfile (char *dirfile, int dir_nlines, struct line_data *dir_lines,
     pclose (output);
   else
     fclose (output);
+
+  if (rename (dirfile_tmp, dirfile) < 0)
+    {
+      perror (dirfile_tmp);
+      exit (EXIT_FAILURE);
+    }
 }
 ^L
 /* Parse the input to find the section names and the entry names it
-- 
2.5.5

Comment 1 Vitezslav Crhonek 2016-06-22 07:58:42 UTC
I would add free (dirfile_tmp) at the end, otherwise the patch looks fine, I'll apply it. Thanks.

Comment 2 Colin Walters 2016-06-22 12:56:30 UTC
Yep, sorry - I had the free() in a version of this patch, but I lost it when juggling multiple branches.  Thanks for the review!

Comment 3 Fedora Update System 2016-06-22 13:35:30 UTC
texinfo-6.1-3.fc24 has been submitted as an update to Fedora 24. https://bodhi.fedoraproject.org/updates/FEDORA-2016-81e90d2724

Comment 4 Fedora Update System 2016-06-22 13:40:59 UTC
texinfo-6.0-3.fc23 has been submitted as an update to Fedora 23. https://bodhi.fedoraproject.org/updates/FEDORA-2016-e9bc854cca

Comment 5 Fedora Update System 2016-06-22 22:59:17 UTC
texinfo-6.0-3.fc23 has been pushed to the Fedora 23 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2016-e9bc854cca

Comment 6 Fedora Update System 2016-06-22 23:02:25 UTC
texinfo-6.1-3.fc24 has been pushed to the Fedora 24 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2016-81e90d2724

Comment 7 Fedora Update System 2016-06-23 17:53:15 UTC
texinfo-6.1-3.fc24 has been pushed to the Fedora 24 stable repository. If problems still persist, please make note of it in this bug report.

Comment 8 Fedora Update System 2016-07-02 19:32:07 UTC
texinfo-6.0-3.fc23 has been pushed to the Fedora 23 stable repository. If problems still persist, please make note of it in this bug report.