From bbd248ce2915d9b78edda706e4274652ebad933c Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Fri, 12 Jun 2009 12:04:19 +0000 Subject: [PATCH] * opncls.c (_maybe_make_executable): New function. Gives execute permission to an executable bfd that was opened for writing provided that it is a regular file. Replaces common code found in... (bfd_close): here and ... (bfd_close_all_done): here. --- bfd/ChangeLog | 9 ++++++++ bfd/opncls.c | 66 +++++++++++++++++++++++++++-------------------------------- 2 files changed, 39 insertions(+), 36 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index c0002d030..b6945c994 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -108,6 +108,15 @@ (bfd_mach_o_bfd_reloc_type_lookup) (bfd_mach_o_bfd_reloc_name_lookup): Ditto. +2009-06-11 Eric Paris + Nick Clifton + + * opncls.c (_maybe_make_executable): New function. Gives execute + permission to an executable bfd that was opened for writing + provided that it is a regular file. Replaces common code found in... + (bfd_close): here and ... + (bfd_close_all_done): here. + 2009-06-11 Anthony Green * reloc.c: Add BFD_RELOC_MOXIE_10_PCREL. diff --git a/bfd/opncls.c b/bfd/opncls.c index 3add02f18..6a4f319d3 100644 --- a/bfd/opncls.c +++ b/bfd/opncls.c @@ -629,6 +629,32 @@ bfd_openw (const char *filename, const char *target) return nbfd; } +static inline void +_maybe_make_executable (bfd * abfd) +{ + /* If the file was open for writing and is now executable, + make it so. */ + if (abfd->direction == write_direction + && abfd->flags & EXEC_P) + { + struct stat buf; + + if (stat (abfd->filename, &buf) == 0 + /* Do not attempt to change non-regular files. This is + here especially for configure scripts and kernel builds + which run tests with "ld [...] -o /dev/null". */ + && S_ISREG(buf.st_mode)) + { + unsigned int mask = umask (0); + + umask (mask); + chmod (abfd->filename, + (0777 + & (buf.st_mode | ((S_IXUSR | S_IXGRP | S_IXOTH) &~ mask)))); + } + } +} + /* FUNCTION @@ -684,24 +710,8 @@ bfd_close (bfd *abfd) else ret = TRUE; - /* If the file was open for writing and is now executable, - make it so. */ - if (ret - && abfd->direction == write_direction - && abfd->flags & EXEC_P) - { - struct stat buf; - - if (stat (abfd->filename, &buf) == 0) - { - unsigned int mask = umask (0); - - umask (mask); - chmod (abfd->filename, - (0777 - & (buf.st_mode | ((S_IXUSR | S_IXGRP | S_IXOTH) &~ mask)))); - } - } + if (ret) + _maybe_make_executable (abfd); _bfd_delete_bfd (abfd); @@ -737,24 +747,8 @@ bfd_close_all_done (bfd *abfd) ret = bfd_cache_close (abfd); - /* If the file was open for writing and is now executable, - make it so. */ - if (ret - && abfd->direction == write_direction - && abfd->flags & EXEC_P) - { - struct stat buf; - - if (stat (abfd->filename, &buf) == 0) - { - unsigned int mask = umask (0); - - umask (mask); - chmod (abfd->filename, - (0777 - & (buf.st_mode | ((S_IXUSR | S_IXGRP | S_IXOTH) &~ mask)))); - } - } + if (ret) + _maybe_make_executable (abfd); _bfd_delete_bfd (abfd); -- 2.11.4.GIT