emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 9b14d8b: Simplify unexec file mode setting


From: Paul Eggert
Subject: [Emacs-diffs] master 9b14d8b: Simplify unexec file mode setting
Date: Sat, 20 Dec 2014 21:12:24 +0000

branch: master
commit 9b14d8b6f259a4d602f0c61689d6641e7ab20b49
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    Simplify unexec file mode setting
    
    * unexaix.c, unexcoff.c, unexelf.c, unexmacosx.c:
    Don't include <sys/stat.h> when no longer needed.
    (unexec): Create file with correct mode in the first place,
    rather than overwriting the mode later and fiddling with the
    global umask in the mean time.  Avoid bogus usage like
    'umask (777)', which should have been 'umask (0777)'.
    (mark_x): Remove. All callers removed.
---
 src/ChangeLog    |   11 +++++++++++
 src/unexaix.c    |   27 +--------------------------
 src/unexcoff.c   |   27 +--------------------------
 src/unexelf.c    |   12 +-----------
 src/unexmacosx.c |    2 +-
 5 files changed, 15 insertions(+), 64 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 819c88b..e21d9ee 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,14 @@
+2014-12-20  Paul Eggert  <address@hidden>
+
+       Simplify unexec file mode setting
+       * unexaix.c, unexcoff.c, unexelf.c, unexmacosx.c:
+       Don't include <sys/stat.h> when no longer needed.
+       (unexec): Create file with correct mode in the first place,
+       rather than overwriting the mode later and fiddling with the
+       global umask in the mean time.  Avoid bogus usage like
+       'umask (777)', which should have been 'umask (0777)'.
+       (mark_x): Remove. All callers removed.
+
 2014-12-19  Paul Eggert  <address@hidden>
 
        Minor cleanups for Lisp objects and symbols
diff --git a/src/unexaix.c b/src/unexaix.c
index c97d5ca..fd36e4a 100644
--- a/src/unexaix.c
+++ b/src/unexaix.c
@@ -55,7 +55,6 @@ what you give them.   Help stamp out software-hoarding!  */
 #include <inttypes.h>
 #include <stdarg.h>
 #include <stdio.h>
-#include <sys/stat.h>
 #include <errno.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -134,7 +133,7 @@ unexec (const char *new_name, const char *a_name)
     {
       PERROR (a_name);
     }
-  if ((new = emacs_open (new_name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0)
+  if ((new = emacs_open (new_name, O_WRONLY | O_CREAT | O_TRUNC, 0777)) < 0)
     {
       PERROR (new_name);
     }
@@ -152,7 +151,6 @@ unexec (const char *new_name, const char *a_name)
   emacs_close (new);
   if (a_out >= 0)
     emacs_close (a_out);
-  mark_x (new_name);
 }
 
 /* ****************************************************************
@@ -466,29 +464,6 @@ copy_sym (int new, int a_out, const char *a_name, const 
char *new_name)
   return 0;
 }
 
-/* ****************************************************************
- * mark_x
- *
- * After successfully building the new a.out, mark it executable
- */
-static void
-mark_x (const char *name)
-{
-  struct stat sbuf;
-  int um;
-  int new = 0;  /* for PERROR */
-
-  um = umask (777);
-  umask (um);
-  if (stat (name, &sbuf) == -1)
-    {
-      PERROR (name);
-    }
-  sbuf.st_mode |= 0111 & ~um;
-  if (chmod (name, sbuf.st_mode) == -1)
-    PERROR (name);
-}
-
 static int
 adjust_lnnoptrs (int writedesc, int readdesc, const char *new_name)
 {
diff --git a/src/unexcoff.c b/src/unexcoff.c
index 0e47bdd..292c38f 100644
--- a/src/unexcoff.c
+++ b/src/unexcoff.c
@@ -97,7 +97,6 @@ struct aouthdr
 #include <sys/types.h>
 #endif /* makedev */
 #include <stdio.h>
-#include <sys/stat.h>
 #include <errno.h>
 
 #include <sys/file.h>
@@ -439,29 +438,6 @@ copy_sym (int new, int a_out, const char *a_name, const 
char *new_name)
   return 0;
 }
 
-/* ****************************************************************
- * mark_x
- *
- * After successfully building the new a.out, mark it executable
- */
-static void
-mark_x (const char *name)
-{
-  struct stat sbuf;
-  int um;
-  int new = 0;  /* for PERROR */
-
-  um = umask (777);
-  umask (um);
-  if (stat (name, &sbuf) == -1)
-    {
-      PERROR (name);
-    }
-  sbuf.st_mode |= 0111 & ~um;
-  if (chmod (name, sbuf.st_mode) == -1)
-    PERROR (name);
-}
-
 
 /*
  *     If the COFF file contains a symbol table and a line number section,
@@ -542,7 +518,7 @@ unexec (const char *new_name, const char *a_name)
     {
       PERROR (a_name);
     }
-  if ((new = emacs_open (new_name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0)
+  if ((new = emacs_open (new_name, O_WRONLY | O_CREAT | O_TRUNC, 0777)) < 0)
     {
       PERROR (new_name);
     }
@@ -560,7 +536,6 @@ unexec (const char *new_name, const char *a_name)
   emacs_close (new);
   if (a_out >= 0)
     emacs_close (a_out);
-  mark_x (new_name);
 }
 
 #endif /* not CANNOT_DUMP */
diff --git a/src/unexelf.c b/src/unexelf.c
index 0983f8f..34478e0 100644
--- a/src/unexelf.c
+++ b/src/unexelf.c
@@ -665,7 +665,6 @@ unexec (const char *new_name, const char *old_name)
 #endif
   struct stat stat_buf;
   off_t old_file_size;
-  int mask;
 
   /* Open the old file, allocate a buffer of the right size, and read
      in the file contents.  */
@@ -799,7 +798,7 @@ unexec (const char *new_name, const char *old_name)
      the image of the new file.  Set pointers to various interesting
      objects.  */
 
-  new_file = emacs_open (new_name, O_RDWR | O_CREAT, 0666);
+  new_file = emacs_open (new_name, O_RDWR | O_CREAT, 0777);
   if (new_file < 0)
     fatal ("Can't creat (%s): %s", new_name, strerror (errno));
 
@@ -1319,13 +1318,4 @@ temacs:
 
   if (emacs_close (new_file) != 0)
     fatal ("Can't close (%s): %s", new_name, strerror (errno));
-
-  if (stat (new_name, &stat_buf) != 0)
-    fatal ("Can't stat (%s): %s", new_name, strerror (errno));
-
-  mask = umask (777);
-  umask (mask);
-  stat_buf.st_mode |= 0111 & ~mask;
-  if (chmod (new_name, stat_buf.st_mode) != 0)
-    fatal ("Can't chmod (%s): %s", new_name, strerror (errno));
 }
diff --git a/src/unexmacosx.c b/src/unexmacosx.c
index 2e1ac88..89971bb 100644
--- a/src/unexmacosx.c
+++ b/src/unexmacosx.c
@@ -1267,7 +1267,7 @@ unexec (const char *outfile, const char *infile)
       unexec_error ("cannot open input file `%s'", infile);
     }
 
-  outfd = emacs_open (outfile, O_WRONLY | O_TRUNC | O_CREAT, 0755);
+  outfd = emacs_open (outfile, O_WRONLY | O_TRUNC | O_CREAT, 0777);
   if (outfd < 0)
     {
       emacs_close (infd);



reply via email to

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