X-Recipient: archive-cygwin@delorie.com
X-Spam-Check-By: sourceware.org
Date: Mon, 16 Mar 2009 13:43:34 +0100
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: peflags utility
Message-ID: <20090316124334.GU9322@calimero.vinschen.de>
Reply-To: cygwin@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
References: <49A9AA0C.9020904@cwilson.fastmail.fm> <20090301102035.GB10046@calimero.vinschen.de> <49AE18D8.3010009@cwilson.fastmail.fm> <49AE191D.2000307@cwilson.fastmail.fm> <20090304084923.GA10046@calimero.vinschen.de> <20090304111849.GB10046@calimero.vinschen.de> <49AE9742.4070108@cwilson.fastmail.fm> <20090304152955.GE10046@calimero.vinschen.de> <49AF4961.1020108@cwilson.fastmail.fm> <49BDF28C.8030300@cwilson.fastmail.fm>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <49BDF28C.8030300@cwilson.fastmail.fm>
User-Agent: Mutt/1.5.19 (2009-02-20)
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
Precedence: bulk
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie.com@cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

On Mar 16 02:32, Charles Wilson wrote:
> Here's revision 3. I've revised the UI to be more like what was
> eventually accepted by binutils.  One difference is that the ld options
> allow only to set flags:
>   ld --tsaware
> 
> With peflags we can set, clear, or display them:
>   peflags --tsaware    : display
>   peflags --tsaware=1  : set
>   peflags --tsaware=0  : clear
> 
> If this is more-or-less ok, I'll get started on the peflagsall script,
> and send it all with updated docu as a patch for Jason to use in the
> next rebase release.
> 
> gcc -o peflags.exe -DVERSION='"2.4.5"' peflags.c

Looks good, except for three minor details I found.  Patch attached.

- The output is missing a trailing \n.

- Error output is missing an error description:

    $ ./peflags --tsaware=1 /bin/tcsh
    Error: could not update pe characteristics (/bin/tcsh)

  Yes, but... why?  The patch adds errno output, like this:

    $ ./peflags --tsaware=1 /bin/tcsh
    Error: could not update pe characteristics (/bin/tcsh): Device or resource busy

- The get/set characteristics function are calling close(fd) even
  if open failed.  This leads to wrong errno output after applying the
  above errno output.


Corinna


--- peflags.c.ORIG	2009-03-16 13:18:06.000000000 +0100
+++ peflags.c	2009-03-16 13:37:55.000000000 +0100
@@ -317,16 +317,16 @@ do_mark (const char *pathname)
         if (set_coff_characteristics (pathname,new_coff_characteristics) != 0)
           {
             fprintf (stderr,
-                     "Error: could not update coff characteristics (%s)\n",
-                      pathname);
+                     "Error: could not update coff characteristics (%s): %s\n",
+                      pathname, strerror (errno));
             return 1;
           }
       if (new_pe_characteristics != old_pe_characteristics)
         if (set_pe_characteristics (pathname,new_pe_characteristics) != 0)
           {
             fprintf (stderr,
-                     "Error: could not update pe characteristics (%s)\n",
-                      pathname);
+                     "Error: could not update pe characteristics (%s): %s\n",
+                      pathname, strerror (errno));
             return 1;
           }
     }
@@ -393,6 +393,7 @@ do_mark (const char *pathname)
           else
             printf ("pe(0x%04x) ", old_pe_characteristics);
         }
+      puts ("");
     }
 
   return 0;
@@ -704,7 +705,7 @@ get_characteristics(const char *pathname
 
   fd = open (pathname, O_RDONLY|O_BINARY);
   if (fd == -1)
-    goto done;
+    return status;
 
   if (pe_get32 (fd, 0x3c, &pe_header_offset) != 0)
     goto done;
@@ -741,7 +742,7 @@ set_coff_characteristics(const char *pat
      get_characteristics already did that */
   fd = open (pathname, O_RDWR|O_BINARY);
   if (fd == -1)
-    goto done;
+    return status;
 
   if (pe_get32 (fd, 0x3c, &pe_header_offset) != 0)
     goto done;
@@ -774,7 +775,7 @@ set_pe_characteristics(const char *pathn
      get_characteristics already did that */
   fd = open (pathname, O_RDWR|O_BINARY);
   if (fd == -1)
-    goto done;
+    return status;
 
   if (pe_get32 (fd, 0x3c, &pe_header_offset) != 0)
     goto done;


-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

