emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs-24 r116952: * keyboard.c (Fopen_dribble_file): Avoid


From: Paul Eggert
Subject: [Emacs-diffs] emacs-24 r116952: * keyboard.c (Fopen_dribble_file): Avoid some races.
Date: Sat, 12 Apr 2014 21:54:30 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 116952
revision-id: address@hidden
parent: address@hidden
fixes bug: http://debbugs.gnu.org/17187
committer: Paul Eggert <address@hidden>
branch nick: emacs-24
timestamp: Sat 2014-04-12 14:54:27 -0700
message:
  * keyboard.c (Fopen_dribble_file): Avoid some races.
modified:
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/keyboard.c                 keyboard.c-20091113204419-o5vbwnq5f7feedwu-449
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2014-04-12 11:21:47 +0000
+++ b/src/ChangeLog     2014-04-12 21:54:27 +0000
@@ -1,3 +1,7 @@
+2014-04-12  Paul Eggert  <address@hidden>
+
+       * keyboard.c (Fopen_dribble_file): Avoid some races.  (Bug#17187)
+
 2014-04-12  Eli Zaretskii  <address@hidden>
 
        * xdisp.c (move_it_by_lines): If a large portion of buffer text is

=== modified file 'src/keyboard.c'
--- a/src/keyboard.c    2014-04-11 05:47:32 +0000
+++ b/src/keyboard.c    2014-04-12 21:54:27 +0000
@@ -10088,15 +10088,9 @@
     {
       int fd;
       file = Fexpand_file_name (file, Qnil);
-      /* This isn't robust, since eg file could be created after we
-         check whether it exists but before emacs_open.
-         Feel free to improve it, but this is not critical.  (Bug#17187)  */
-      if (! NILP (Ffile_exists_p (file)))
-        {
-          if (chmod (SSDATA (file), 0600) < 0)
-            report_file_error ("Doing chmod", file);
-        }
-      fd = emacs_open (SSDATA (file), O_WRONLY | O_CREAT | O_TRUNC, 0600);
+      fd = emacs_open (SSDATA (file), O_WRONLY | O_CREAT | O_EXCL, 0600);
+      if (fd < 0 && errno == EEXIST && unlink (SSDATA (file)) == 0)
+       fd = emacs_open (SSDATA (file), O_WRONLY | O_CREAT | O_EXCL, 0600);
       dribble = fd < 0 ? 0 : fdopen (fd, "w");
       if (dribble == 0)
        report_file_error ("Opening dribble", file);


reply via email to

[Prev in Thread] Current Thread [Next in Thread]