]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Switch from numerical to defined constants for permissions.
authorÉrico Rolim <erico.erc@gmail.com>
Mon, 2 Nov 2020 01:49:46 +0000 (22:49 -0300)
committerMark Wielaard <mark@klomp.org>
Tue, 3 Nov 2020 14:54:14 +0000 (15:54 +0100)
Use defined constants for permission values. Also add fallback
definitions for them in system.h, to allow for compatibility with
systems that don't provide these macros.

Include system.h in all tests/ files that required it.

Signed-off-by: Érico Rolim <erico.erc@gmail.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
19 files changed:
debuginfod/ChangeLog
debuginfod/debuginfod-client.c
lib/ChangeLog
lib/system.h
src/ChangeLog
src/unstrip.c
tests/ChangeLog
tests/alldts.c
tests/arextract.c
tests/ecp.c
tests/elfstrtab.c
tests/emptyfile.c
tests/fillfile.c
tests/newdata.c
tests/update1.c
tests/update2.c
tests/update3.c
tests/update4.c
tests/vendorelf.c

index 5b743d761c84caa6ee8c6cdf661c91f863c7ddd3..a02643e17b7d856510045bd54a22d434db68795a 100644 (file)
@@ -1,3 +1,8 @@
+2020-11-01  Érico N. Rolim  <erico.erc@gmail.com>
+
+       * debuginfod-client.c (debuginfod_init_cache): Use ACCESSPERMS for
+       mkdir, DEFFILEMODE for open with O_CREAT.
+
 2020-11-01  Érico N. Rolim  <erico.erc@gmail.com>
 
        * debuginfod.cxx: include libintl.h.
index 0e5177bc688415f236fed5550290488fb9de4852..ce1d819b97e68d03ef2cb89239bbd0437855c6b5 100644 (file)
@@ -212,13 +212,13 @@ debuginfod_init_cache (char *cache_path, char *interval_path, char *maxage_path)
     return 0;
 
   /* Create the cache and config files as necessary.  */
-  if (stat(cache_path, &st) != 0 && mkdir(cache_path, 0777) < 0)
+  if (stat(cache_path, &st) != 0 && mkdir(cache_path, ACCESSPERMS) < 0)
     return -errno;
 
   int fd = -1;
 
   /* init cleaning interval config file.  */
-  fd = open(interval_path, O_CREAT | O_RDWR, 0666);
+  fd = open(interval_path, O_CREAT | O_RDWR, DEFFILEMODE);
   if (fd < 0)
     return -errno;
 
@@ -227,7 +227,7 @@ debuginfod_init_cache (char *cache_path, char *interval_path, char *maxage_path)
 
   /* init max age config file.  */
   if (stat(maxage_path, &st) != 0
-      && (fd = open(maxage_path, O_CREAT | O_RDWR, 0666)) < 0)
+      && (fd = open(maxage_path, O_CREAT | O_RDWR, DEFFILEMODE)) < 0)
     return -errno;
 
   if (dprintf(fd, "%ld", cache_default_max_unused_age_s) < 0)
index f4ab6d48b77e7a032e2d0cea0f5209e36faf0568..663a7aa584b02112082d182f3e9dc20ac88beaa1 100644 (file)
@@ -1,3 +1,9 @@
+2020-11-01  Érico N. Rolim  <erico.erc@gmail.com>
+
+       * system.h (ACCESSPERMS): Define macro if it doesn't exist.
+       (ALLPERMS): Likewise.
+       (DEFFILEMODE): Likewise.
+
 2020-06-11  Mark Wielaaard  <mark@klomp.org>
 
        * printversion.c (print_version): Update copyright year.
index 292082bdbd245d12741fb4eac4da3458c968f249..7b650f11f5d6f28443f0343f890904aa22452211 100644 (file)
      __res; })
 #endif
 
+#ifndef ACCESSPERMS
+#define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */
+#endif
+
+#ifndef ALLPERMS
+#define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO) /* 07777 */
+#endif
+
+#ifndef DEFFILEMODE
+#define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)/* 0666 */
+#endif
+
 static inline ssize_t __attribute__ ((unused))
 pwrite_retry (int fd, const void *buf, size_t len, off_t off)
 {
index ab7ae3f6146bfd1f2502c9c2da38f95fa5cb8e4c..668b18b0f350594494f5408717281e6adf17d9c9 100644 (file)
@@ -1,3 +1,9 @@
+2020-11-01  Érico N. Rolim  <erico.erc@gmail.com>
+
+       * unstrip.c (make_directories): Use ACCESSPERMS for mkdir.
+       (handle_file): Use DEFFILEMODE for open with O_CREAT for ET_REL
+       files, ACCESSPERMS otherwise.
+
 2020-11-01  Érico N. Rolim  <erico.erc@gmail.com>
 
        * Makefile.am (nm_LDADD): Add obstack_LIBS.
index 0257d9cc374034b8fbadd30151c8eb2af7f916ec..231b941d22faa9249059d87402a21c07eee8572c 100644 (file)
@@ -315,7 +315,7 @@ make_directories (const char *path)
   if (dir == NULL)
     error(EXIT_FAILURE, errno, _("memory exhausted"));
 
-  while (mkdir (dir, 0777) < 0 && errno != EEXIST)
+  while (mkdir (dir, ACCESSPERMS) < 0 && errno != EEXIST)
     {
       if (errno == ENOENT)
         make_directories (dir);
@@ -2192,7 +2192,8 @@ DWARF data in '%s' not adjusted for prelinking bias; consider prelink -u"),
 
       /* Copy the unstripped file and then modify it.  */
       int outfd = open (output_file, O_RDWR | O_CREAT,
-                         stripped_ehdr->e_type == ET_REL ? 0666 : 0777);
+                       (stripped_ehdr->e_type == ET_REL
+                        ? DEFFILEMODE : ACCESSPERMS));
       if (outfd < 0)
        error (EXIT_FAILURE, errno, _("cannot open '%s'"), output_file);
       Elf *outelf = elf_begin (outfd, ELF_C_WRITE, NULL);
index 57fc4c8e14554cb5e5034cbd639b74e436cd8485..f7b78c83fb7986c8d312755ebeb92e793c73dffe 100644 (file)
@@ -1,3 +1,18 @@
+2020-11-01  Érico N. Rolim  <erico.erc@gmail.com>
+           Mark Wielaard  <mark@klomp.org>
+
+       * alldts.c (main): Use DEFFILEMODE for open with O_CREAT.
+       * arextract.c (main): Likewise.
+       * ecp.c (main): Likewise for creat.
+       * elfstrtab.c (check_elf): Use DEFFILEMODE for open with O_CREAT,
+       remove mode from open calls without O_CREAT.
+       * emptyfile.c (check_elf): Likewise.
+       * fillfile.c (check_elf): Likewise.
+       * vendorelf.c (check_elf): Likewise.
+       * newdata.c (checkelf): Use DEFFILEMODE for open with O_CREAT.
+       * update{1,2,3,4}.c (main): Likewise.
+       *
+
 2020-10-31  Mark Wielaard  <mark@klomp.org>
 
        * dwfl-proc-attach.c (dlopen): New external function override.
index 28b3063c957eb23fce62ecfae5b6943460e77f93..3e9f9fe69a3d4c6638f40fe49fd10fa4647b2511 100644 (file)
@@ -32,6 +32,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include "system.h"
 
 
 int
@@ -68,7 +69,7 @@ main (void)
   (void) __fsetlocking (stdout, FSETLOCKING_BYCALLER);
 
   /* Open the file.  */
-  int fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, 0666);
+  int fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE);
   if (fd == -1)
     {
       printf ("cannot open `%s': %m\n", fname);
index 2c4dc758359ae0163088bf3caadcadbe11e11e78..936d7f55cf5663969fc7551fdfc646a86acc8153 100644 (file)
@@ -95,7 +95,7 @@ Failed to get base address for the archive element: %s\n",
            }
 
          /* Open the output file.  */
-         outfd = open (argv[3], O_CREAT | O_TRUNC | O_RDWR, 0666);
+         outfd = open (argv[3], O_CREAT | O_TRUNC | O_RDWR, DEFFILEMODE);
          if (outfd == -1)
            {
              printf ("cannot open output file: %m");
index 1df40a326141ad3572487e4870e95b2143af19c8..44a7bda25061cf71b4a01ae1497be246ceb019ba 100644 (file)
@@ -43,7 +43,7 @@ main (int argc, char *argv[])
     error (EXIT_FAILURE, 0, "problems opening '%s' as ELF file: %s",
           argv[1], elf_errmsg (-1));
 
-  int outfd = creat (argv[2], 0666);
+  int outfd = creat (argv[2], DEFFILEMODE);
   if (outfd == -1)
     error (EXIT_FAILURE, errno, "cannot open output file '%s'", argv[2]);
 
index c27d6cfb4164d049ede3185fb199d054bf2b2686..5fae37e03cfabba37463a08b29e881b399b1fedf 100644 (file)
@@ -26,6 +26,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include "system.h"
 
 #include ELFUTILS_HEADER(elf)
 #include <gelf.h>
@@ -134,7 +135,7 @@ check_elf (const char *fname, int class, int use_mmap)
   printf ("\nfname: %s\n", fname);
   stridx = 0;
 
-  int fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, 0666);
+  int fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE);
   if (fd == -1)
     {
       printf ("cannot open `%s': %s\n", fname, strerror (errno));
@@ -280,7 +281,7 @@ check_elf (const char *fname, int class, int use_mmap)
   close (fd);
 
   /* Read the ELF from disk now.  */
-  fd = open (fname, O_RDWR, 0666);
+  fd = open (fname, O_RDWR);
   if (fd == -1)
     {
       printf ("cannot open `%s' read-only: %s\n", fname, strerror (errno));
@@ -349,7 +350,7 @@ check_elf (const char *fname, int class, int use_mmap)
   close (fd);
 
   // And read it in one last time.
-  fd = open (fname, O_RDONLY, 0666);
+  fd = open (fname, O_RDONLY);
   if (fd == -1)
     {
       printf ("cannot open `%s' read-only: %s\n", fname, strerror (errno));
index 6d086246efb3cca8711d47a2245f027c465fa802..9124c39753841d4bb1c3894f3f9fe7896ff26c0f 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include "system.h"
 
 #include ELFUTILS_HEADER(elf)
 #include <gelf.h>
@@ -67,7 +68,7 @@ check_elf (const char *fname, int class, int use_mmap)
   printf ("\nfname: %s\n", fname);
   stridx = 0; // Reset strtab strings index
 
-  int fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, 0666);
+  int fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE);
   if (fd == -1)
     {
       printf ("cannot open `%s': %s\n", fname, strerror (errno));
@@ -125,7 +126,7 @@ check_elf (const char *fname, int class, int use_mmap)
   close (fd);
 
   /* Reread the ELF from disk now.  */
-  fd = open (fname, O_RDWR, 0666);
+  fd = open (fname, O_RDWR);
   if (fd == -1)
     {
       printf ("cannot (re)open `%s': %s\n", fname, strerror (errno));
@@ -208,7 +209,7 @@ check_elf (const char *fname, int class, int use_mmap)
   close (fd);
 
   // And read it in one last time.
-  fd = open (fname, O_RDONLY, 0666);
+  fd = open (fname, O_RDONLY);
   if (fd == -1)
     {
       printf ("cannot open `%s' read-only: %s\n", fname, strerror (errno));
index 915e249d1858b2c3c8a8b26d50b9ecf9f451cd45..7f6225360ada1f5e9d81330abc4da7dc9c7b74e9 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include "system.h"
 
 #include ELFUTILS_HEADER(elf)
 #include <gelf.h>
@@ -201,7 +202,7 @@ check_elf (const char *fname, int class, int use_mmap)
   printf ("\nfname: %s\n", fname);
   stridx = 0; // Reset strtab strings index
 
-  int fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, 0666);
+  int fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE);
   if (fd == -1)
     {
       printf ("cannot open `%s': %s\n", fname, strerror (errno));
@@ -266,7 +267,7 @@ check_elf (const char *fname, int class, int use_mmap)
 
   /* Reread the ELF from disk now.  */
   printf ("Rereading %s\n", fname);
-  fd = open (fname, O_RDWR, 0666);
+  fd = open (fname, O_RDWR);
   if (fd == -1)
     {
       printf ("cannot (re)open `%s': %s\n", fname, strerror (errno));
@@ -347,7 +348,7 @@ check_elf (const char *fname, int class, int use_mmap)
 
   // And read it in one last time.
   printf ("Rereading %s again\n", fname);
-  fd = open (fname, O_RDONLY, 0666);
+  fd = open (fname, O_RDONLY);
   if (fd == -1)
     {
       printf ("cannot open `%s' read-only: %s\n", fname, strerror (errno));
index 9af99564ee181157206daeb2f54b7740c6035f29..fcf26acf8cb916467fd488fe17cd64b5327b561c 100644 (file)
@@ -26,6 +26,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include "system.h"
 
 #include ELFUTILS_HEADER(elf)
 #include <gelf.h>
@@ -243,7 +244,7 @@ check_elf (int class, int use_mmap)
 
   printf ("\ncheck_elf: %s\n", fname);
 
-  int fd = open (fname, O_RDWR|O_CREAT|O_TRUNC, 00666);
+  int fd = open (fname, O_RDWR|O_CREAT|O_TRUNC, DEFFILEMODE);
   if (fd == -1)
     {
       printf ("cannot create `%s': %s\n", fname, strerror (errno));
index f4c1475372123c05109f0dd243360ec538807fd0..b7be4e5f8d96ac25f3021e34a0967b700aed15ef 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include "system.h"
 
 
 int
@@ -38,7 +39,7 @@ main (int argc, char *argv[] __attribute__ ((unused)))
   Elf32_Ehdr *ehdr;
   int i;
 
-  fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, 0666);
+  fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE);
   if (fd == -1)
     {
       printf ("cannot open `%s': %s\n", fname, strerror (errno));
index 5805163d8607f76f223e9a4a62f0209cdbd1de48..714556337c5fa948a8cc1cbfd41baacca3e4ef91 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include "system.h"
 
 
 int
@@ -39,7 +40,7 @@ main (int argc, char *argv[] __attribute__ ((unused)))
   Elf32_Phdr *phdr;
   int i;
 
-  fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, 0666);
+  fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE);
   if (fd == -1)
     {
       printf ("cannot open `%s': %s\n", fname, strerror (errno));
index 7a4224ddd147b29072c15bd37dda785d5421b229..62f67f74f4d9736c32c98d4dbcf53007460f2b5f 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include "system.h"
 
 #include ELFUTILS_HEADER(dwelf)
 
@@ -46,7 +47,7 @@ main (int argc, char *argv[] __attribute__ ((unused)))
   Dwelf_Strent *shstrtabse;
   int i;
 
-  fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, 0666);
+  fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE);
   if (fd == -1)
     {
       printf ("cannot open `%s': %s\n", fname, strerror (errno));
index a9bd4bf96ba35a3746c024fd70613ce6a61cae2e..a703b592b55b36baa6669ed17174c0813107e028 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include "system.h"
 
 #include ELFUTILS_HEADER(dwelf)
 
@@ -50,7 +51,7 @@ main (int argc, char *argv[] __attribute__ ((unused)))
   Dwelf_Strent *shstrtabse;
   int i;
 
-  fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, 0666);
+  fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE);
   if (fd == -1)
     {
       printf ("cannot open `%s': %s\n", fname, strerror (errno));
index bc13cce312f5bbc97ea5ffb8398a74a51044ae67..8ce1e5ece99f5e4d435936fae5036ff24ffca83b 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include "system.h"
 
 #include ELFUTILS_HEADER(elf)
 #include <gelf.h>
@@ -36,7 +37,7 @@ check_elf (const char *fname, int class, int use_mmap)
 {
   printf ("\nfname: %s\n", fname);
 
-  int fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, 0666);
+  int fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE);
   if (fd == -1)
     {
       printf ("cannot open `%s': %s\n", fname, strerror (errno));
@@ -124,7 +125,7 @@ check_elf (const char *fname, int class, int use_mmap)
   close (fd);
 
   /* Reread the ELF from disk now.  */
-  fd = open (fname, O_RDONLY, 0666);
+  fd = open (fname, O_RDONLY);
   if (fd == -1)
     {
       printf ("cannot open `%s' read-only: %s\n", fname, strerror (errno));