summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debuginfod/ChangeLog5
-rw-r--r--debuginfod/debuginfod-client.c6
-rw-r--r--lib/ChangeLog6
-rw-r--r--lib/system.h12
-rw-r--r--src/ChangeLog6
-rw-r--r--src/unstrip.c5
-rw-r--r--tests/ChangeLog15
-rw-r--r--tests/alldts.c3
-rw-r--r--tests/arextract.c2
-rw-r--r--tests/ecp.c2
-rw-r--r--tests/elfstrtab.c7
-rw-r--r--tests/emptyfile.c7
-rw-r--r--tests/fillfile.c7
-rw-r--r--tests/newdata.c3
-rw-r--r--tests/update1.c3
-rw-r--r--tests/update2.c3
-rw-r--r--tests/update3.c3
-rw-r--r--tests/update4.c3
-rw-r--r--tests/vendorelf.c5
19 files changed, 79 insertions, 24 deletions
diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog
index 5b743d76..a02643e1 100644
--- a/debuginfod/ChangeLog
+++ b/debuginfod/ChangeLog
@@ -1,5 +1,10 @@
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.
2020-11-01 Érico N. Rolim <erico.erc@gmail.com>
diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index 0e5177bc..ce1d819b 100644
--- a/debuginfod/debuginfod-client.c
+++ b/debuginfod/debuginfod-client.c
@@ -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)
diff --git a/lib/ChangeLog b/lib/ChangeLog
index f4ab6d48..663a7aa5 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -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.
diff --git a/lib/system.h b/lib/system.h
index 292082bd..7b650f11 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -85,6 +85,18 @@
__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)
{
diff --git a/src/ChangeLog b/src/ChangeLog
index ab7ae3f6..668b18b0 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,11 @@
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.
(ranlib_LDADD): Likewise.
(ar_LDADD): Likewise.
diff --git a/src/unstrip.c b/src/unstrip.c
index 0257d9cc..231b941d 100644
--- a/src/unstrip.c
+++ b/src/unstrip.c
@@ -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);
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 57fc4c8e..f7b78c83 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -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.
diff --git a/tests/alldts.c b/tests/alldts.c
index 28b3063c..3e9f9fe6 100644
--- a/tests/alldts.c
+++ b/tests/alldts.c
@@ -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);
diff --git a/tests/arextract.c b/tests/arextract.c
index 2c4dc758..936d7f55 100644
--- a/tests/arextract.c
+++ b/tests/arextract.c
@@ -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");
diff --git a/tests/ecp.c b/tests/ecp.c
index 1df40a32..44a7bda2 100644
--- a/tests/ecp.c
+++ b/tests/ecp.c
@@ -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]);
diff --git a/tests/elfstrtab.c b/tests/elfstrtab.c
index c27d6cfb..5fae37e0 100644
--- a/tests/elfstrtab.c
+++ b/tests/elfstrtab.c
@@ -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));
diff --git a/tests/emptyfile.c b/tests/emptyfile.c
index 6d086246..9124c397 100644
--- a/tests/emptyfile.c
+++ b/tests/emptyfile.c
@@ -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));
diff --git a/tests/fillfile.c b/tests/fillfile.c
index 915e249d..7f622536 100644
--- a/tests/fillfile.c
+++ b/tests/fillfile.c
@@ -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));
diff --git a/tests/newdata.c b/tests/newdata.c
index 9af99564..fcf26acf 100644
--- a/tests/newdata.c
+++ b/tests/newdata.c
@@ -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));
diff --git a/tests/update1.c b/tests/update1.c
index f4c14753..b7be4e5f 100644
--- a/tests/update1.c
+++ b/tests/update1.c
@@ -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));
diff --git a/tests/update2.c b/tests/update2.c
index 5805163d..71455633 100644
--- a/tests/update2.c
+++ b/tests/update2.c
@@ -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));
diff --git a/tests/update3.c b/tests/update3.c
index 7a4224dd..62f67f74 100644
--- a/tests/update3.c
+++ b/tests/update3.c
@@ -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));
diff --git a/tests/update4.c b/tests/update4.c
index a9bd4bf9..a703b592 100644
--- a/tests/update4.c
+++ b/tests/update4.c
@@ -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));
diff --git a/tests/vendorelf.c b/tests/vendorelf.c
index bc13cce3..8ce1e5ec 100644
--- a/tests/vendorelf.c
+++ b/tests/vendorelf.c
@@ -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));