RPM Community Forums

Mailing List Message of <rpm-cvs>

[CVS] RPM: rpm/ CHANGES rpm/rpmio/ macro.c

From: Ralf S. Engelschall <rse@rpm5.org>
Date: Thu 31 Jan 2008 - 22:10:13 CET
Message-Id: <20080131211013.85468348471@rpm5.org>
  RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Ralf S. Engelschall
  Root:   /v/rpm/cvs                       Email:  rse@rpm5.org
  Module: rpm                              Date:   31-Jan-2008 22:10:13
  Branch: HEAD                             Handle: 2008013121101300

  Modified files:
    rpm                     CHANGES
    rpm/rpmio               macro.c

  Log:
    Ensure that under Linux GLIBC option parsing is done without allowing
    option/argument permutations to avoid accidentally picking up and
    complaining about unknown options.
    
    Required standard POSIX getopt(3) behavior:
      $ rpm --define '%foo() <%*>' --eval '%{foo bar %(echo -n "quux") baz}'
      <bar quux baz>
    
    Unexpected non-standard Linux GLIBC getopt(3) behavior:
      $ rpm --define '%foo() <%*>' --eval '%{foo bar %(echo -n "quux") baz}'
      foo: invalid option -- n
      error: Unknown option ? in foo()
      <%*>
    
    Fixed standard POSIX getopt(3) behavior also under Linux GLIBC:
      $ POSIXLY_CORRECT=1 rpm --define '%foo() <%*>' --eval '%{foo bar %(echo -n "quux") baz}'
      <bar quux baz>

  Summary:
    Revision    Changes     Path
    1.2116      +1  -0      rpm/CHANGES
    2.181       +33 -0      rpm/rpmio/macro.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/CHANGES
  ============================================================================
  $ cvs diff -u -r1.2115 -r1.2116 CHANGES
  --- rpm/CHANGES	31 Jan 2008 18:46:27 -0000	1.2115
  +++ rpm/CHANGES	31 Jan 2008 21:10:13 -0000	1.2116
  @@ -1,4 +1,5 @@
   5.0.0 -> 5.1a1:
  +    - rse: ensure macro option parsing is done correctly also under GLIBC by not allowing option/argument permutations
       - jbj: retrieve old originTime earlier to include identical package replace.
       - jbj: fix: functional "-N-V-R.A" erasures-within-upgrade transactions.
       - jbj: fix: retrieve originTime from old, not new, header.
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/macro.c
  ============================================================================
  $ cvs diff -u -r2.180 -r2.181 macro.c
  --- rpm/rpmio/macro.c	25 Jan 2008 22:19:12 -0000	2.180
  +++ rpm/rpmio/macro.c	31 Jan 2008 21:10:13 -0000	2.181
  @@ -995,6 +995,9 @@
       int argc = 0;
       const char **argv;
       int c;
  +#ifdef __GLIBC__
  +    char *posixly_correct;
  +#endif
   
       /* Copy macro name as argv[0], save beginning of args.  */
       buf[0] = '\0';
  @@ -1080,6 +1083,29 @@
   
       opts = me->opts;
   
  +#ifdef __GLIBC__
  +    /*
  +     *  Ensure option parsing is done without allowing option/argument permutations
  +     *  to avoid accidentally picking up and complaining about unknown options.
  +     *
  +     *  Required standard POSIX getopt(3) behavior:
  +     *  $ rpm --define '%foo() <%*>' --eval '%{foo bar %(echo -n "quux") baz}'
  +     *  <bar quux baz>
  +     *
  +     *  Unexpected non-standard Linux GLIBC getopt(3) behavior:
  +     *  $ rpm --define '%foo() <%*>' --eval '%{foo bar %(echo -n "quux") baz}'
  +     *  foo: invalid option -- n
  +     *  error: Unknown option ? in foo()
  +     *  <%*>
  +     *
  +     *  Fixed standard POSIX getopt(3) behavior also under Linux GLIBC:
  +     *  $ POSIXLY_CORRECT=1 rpm --define '%foo() <%*>' --eval '%{foo bar %(echo -n "quux") baz}'
  +     *  <bar quux baz>
  +     */
  +    posixly_correct = getenv("POSIXLY_CORRECT");
  +    setenv("POSIXLY_CORRECT", "1", 1);
  +#endif
  +
       /* Define option macros. */
   /*@-nullstate@*/ /* FIX: argv[] can be NULL */
       while((c = getopt(argc, (char **)argv, opts)) != -1)
  @@ -1106,6 +1132,13 @@
   	be = b; /* reuse the space */
       }
   
  +#ifdef __GLIBC__
  +    if (posixly_correct != NULL)
  +        setenv("POSIXLY_CORRECT", posixly_correct, 1);
  +    else
  +        unsetenv("POSIXLY_CORRECT");
  +#endif
  +
       /* Add arg count as macro. */
       sprintf(aname, "%d", (argc - optind));
       addMacro(mb->mc, "#", NULL, aname, mb->depth);
  @@ .
Received on Thu Jan 31 22:10:13 2008
Driven by Jeff Johnson and the RPM project team.
Hosted by OpenPKG and Ralf S. Engelschall.
Powered by FreeBSD and OpenPKG.