Changeset 3140 for trunk/src/kmk/misc.c


Ignore:
Timestamp:
Mar 14, 2018, 10:28:10 PM (7 years ago)
Author:
bird
Message:

kmk: Merged in changes from GNU make 4.2.1 (2e55f5e4abdc0e38c1d64be703b446695e70b3b6 / https://git.savannah.gnu.org/git/make.git).

Location:
trunk/src/kmk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk

  • trunk/src/kmk/misc.c

    r3068 r3140  
    11/* Miscellaneous generic support functions for GNU Make.
    2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
    3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
    4 2010 Free Software Foundation, Inc.
     2Copyright (C) 1988-2016 Free Software Foundation, Inc.
    53This file is part of GNU Make.
    64
     
    1715this program.  If not, see <http://www.gnu.org/licenses/>.  */
    1816
    19 #include "make.h"
     17#include "makeint.h"
     18#include "filedef.h"
    2019#include "dep.h"
    2120#include "debug.h"
     21
     22/* GNU make no longer supports pre-ANSI89 environments.  */
     23
     24#include <stdarg.h>
     25
     26#ifdef HAVE_FCNTL_H
     27# include <fcntl.h>
     28#else
     29# include <sys/file.h>
     30#endif
     31
    2232#if defined (CONFIG_WITH_VALUE_LENGTH) || defined (CONFIG_WITH_ALLOC_CACHES)
    2333# include <assert.h>
     
    3141# endif
    3242#endif
    33 
    3443#if defined (CONFIG_WITH_NANOTS) || defined (CONFIG_WITH_PRINT_TIME_SWITCH)
    3544# ifdef WINDOWS32
     
    4857#endif
    4958
    50 /* Variadic functions.  We go through contortions to allow proper function
    51    prototypes for both ANSI and pre-ANSI C compilers, and also for those
    52    which support stdarg.h vs. varargs.h, and finally those which have
    53    vfprintf(), etc. and those who have _doprnt... or nothing.
    54 
    55    This fancy stuff all came from GNU fileutils, except for the VA_PRINTF and
    56    VA_END macros used here since we have multiple print functions.  */
    57 
    58 #if USE_VARIADIC
    59 # if HAVE_STDARG_H
    60 #  include <stdarg.h>
    61 #  define VA_START(args, lastarg) va_start(args, lastarg)
    62 # else
    63 #  include <varargs.h>
    64 #  define VA_START(args, lastarg) va_start(args)
    65 # endif
    66 # if HAVE_VPRINTF
    67 #  define VA_PRINTF(fp, lastarg, args) vfprintf((fp), (lastarg), (args))
    68 # else
    69 #  define VA_PRINTF(fp, lastarg, args) _doprnt((lastarg), (args), (fp))
    70 # endif
    71 # define VA_END(args) va_end(args)
    72 #else
    73 /* We can't use any variadic interface! */
    74 # define va_alist a1, a2, a3, a4, a5, a6, a7, a8
    75 # define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
    76 # define VA_START(args, lastarg)
    77 # define VA_PRINTF(fp, lastarg, args) fprintf((fp), (lastarg), va_alist)
    78 # define VA_END(args)
    79 #endif
    80 
    8159
    8260/* Compare strings *S1 and *S2.
     
    10886#endif
    10987{
    110   register char *in, *out, *p;
    111   register int backslash;
    112   register unsigned int bs_write;
     88  char *in, *out, *p;
    11389
    11490#ifndef CONFIG_WITH_VALUE_LENGTH
     
    143119    {
    144120      /* BS_WRITE gets the number of quoted backslashes at
    145         the end just before IN, and BACKSLASH gets nonzero
    146         if the next character is quoted.  */
    147       backslash = 0;
    148       bs_write = 0;
     121        the end just before IN, and BACKSLASH gets nonzero
     122        if the next character is quoted.  */
     123      unsigned int backslash = 0;
     124      unsigned int bs_write = 0;
    149125      for (p = in - 1; p >= line && *p == '\\'; --p)
    150         {
    151           if (backslash)
    152             ++bs_write;
    153           backslash = !backslash;
    154 
    155           /* It should be impossible to go back this far without exiting,
    156              but if we do, we can't get the right answer.  */
    157           if (in == out - 1)
    158             abort ();
    159         }
     126        {
     127          if (backslash)
     128            ++bs_write;
     129          backslash = !backslash;
     130
     131          /* It should be impossible to go back this far without exiting,
     132             but if we do, we can't get the right answer.  */
     133          if (in == out - 1)
     134            abort ();
     135        }
    160136
    161137      /* Output the appropriate number of backslashes.  */
    162138      while (bs_write-- > 0)
    163         *out++ = '\\';
     139        *out++ = '\\';
    164140
    165141      /* Skip the newline.  */
    166142      ++in;
    167143
    168       /* If the newline is escaped, discard following whitespace leaving just
    169          one space.  POSIX requires that each backslash/newline/following
    170          whitespace sequence be reduced to a single space.  */
    171144      if (backslash)
    172         {
    173           in = next_token (in);
    174           /* Removing this loop will fix Savannah bug #16670: do we want to? */
    175           while (out > line && isblank ((unsigned char)out[-1]))
    176             --out;
    177           *out++ = ' ';
    178         }
     145        {
     146          /* Backslash/newline handling:
     147             In traditional GNU make all trailing whitespace, consecutive
     148             backslash/newlines, and any leading non-newline whitespace on the
     149             next line is reduced to a single space.
     150             In POSIX, each backslash/newline and is replaced by a space.  */
     151          while (ISBLANK (*in))
     152            ++in;
     153          if (! posix_pedantic)
     154            while (out > line && ISBLANK (out[-1]))
     155              --out;
     156          *out++ = ' ';
     157        }
    179158      else
    180         /* If the newline isn't quoted, put it in the output.  */
    181         *out++ = '\n';
     159        /* If the newline isn't quoted, put it in the output.  */
     160        *out++ = '\n';
    182161
    183162      /* Now copy the following line to the output.
    184         Stop when we find backslashes followed by a newline.  */
     163        Stop when we find backslashes followed by a newline.  */
    185164      while (*in != '\0')
    186         if (*in == '\\')
    187           {
    188             p = in + 1;
    189             while (*p == '\\')
    190               ++p;
    191             if (*p == '\n')
    192               {
    193                 in = p;
    194                 break;
    195               }
    196             while (in < p)
    197               *out++ = *in++;
    198           }
    199         else
    200           *out++ = *in++;
     165        if (*in == '\\')
     166          {
     167            p = in + 1;
     168            while (*p == '\\')
     169              ++p;
     170            if (*p == '\n')
     171              {
     172                in = p;
     173                break;
     174              }
     175            while (in < p)
     176              *out++ = *in++;
     177          }
     178        else
     179          *out++ = *in++;
    201180    }
    202181
     
    224203
    225204const char *
    226 #if HAVE_ANSI_COMPILER && USE_VARIADIC && HAVE_STDARG_H
    227205concat (unsigned int num, ...)
    228 #else
    229 concat (num, va_alist)
    230      unsigned int num;
    231      va_dcl
    232 #endif
    233206{
    234207  static unsigned int rlen = 0;
    235208  static char *result = NULL;
    236   unsigned int ri = 0; /* bird: must be unsigned */
    237 
    238 #if USE_VARIADIC
     209  unsigned int ri = 0;
    239210  va_list args;
    240 #endif
    241 
    242   VA_START (args, num);
     211
     212  va_start (args, num);
    243213
    244214  while (num-- > 0)
    245215    {
    246216      const char *s = va_arg (args, const char *);
    247       unsigned int l = s ? strlen (s) : 0;
     217      unsigned int l = xstrlen (s);
    248218
    249219      if (l == 0)
     
    260230    }
    261231
    262   VA_END (args);
     232  va_end (args);
    263233
    264234  /* Get some more memory if we don't have enough space for the
     
    276246
    277247
    278 /* Print a message on stdout.  */
    279 
    280 void
    281 #if HAVE_ANSI_COMPILER && USE_VARIADIC && HAVE_STDARG_H
    282 message (int prefix, const char *fmt, ...)
    283 #else
    284 message (prefix, fmt, va_alist)
    285      int prefix;
    286      const char *fmt;
    287      va_dcl
    288 #endif
    289 {
    290 #if USE_VARIADIC
    291   va_list args;
    292 #endif
    293 
    294   log_working_directory (1);
    295 
    296   if (fmt != 0)
    297     {
    298 #ifdef KBUILD_OS_WINDOWS
    299       char szMsg[16384];
    300       int cchMsg = 0;
    301       int cchUser;
    302       if (prefix)
    303         {
    304           if (makelevel == 0)
    305             cchMsg = snprintf (szMsg, sizeof(szMsg), "%s: ", program);
    306           else
    307             cchMsg = snprintf (szMsg, sizeof(szMsg), "%s[%u]: ", program, makelevel);
    308         }
    309       VA_START (args, fmt);
    310       cchMsg += cchUser = vsnprintf (&szMsg[cchMsg], sizeof(szMsg) - cchMsg, fmt, args);
    311       VA_END (args);
    312       if (   cchMsg < sizeof(szMsg)
    313           && cchUser >= 0)
    314         {
    315           extern size_t maybe_con_fwrite(void const *, size_t, size_t, FILE *);
    316           szMsg[cchMsg++] = '\n';
    317           maybe_con_fwrite(szMsg, cchMsg, 1, stdout);
    318         }
    319       else
    320         {
    321 #endif
    322       if (prefix)
    323         {
    324           if (makelevel == 0)
    325             printf ("%s: ", program);
    326           else
    327             printf ("%s[%u]: ", program, makelevel);
    328         }
    329       VA_START (args, fmt);
    330       VA_PRINTF (stdout, fmt, args);
    331       VA_END (args);
    332       putchar ('\n');
    333 #ifdef KBUILD_OS_WINDOWS
    334         }
    335 #endif
    336     }
    337 
    338   fflush (stdout);
    339 }
    340 
    341 /* Print an error message.  */
    342 
    343 void
    344 #if HAVE_ANSI_COMPILER && USE_VARIADIC && HAVE_STDARG_H
    345 error (const struct floc *flocp, const char *fmt, ...)
    346 #else
    347 error (flocp, fmt, va_alist)
    348      const struct floc *flocp;
    349      const char *fmt;
    350      va_dcl
    351 #endif
    352 {
    353 #if USE_VARIADIC
    354   va_list args;
    355 #endif
    356 #ifdef KMK
    357   char szMsg[16384];
    358   int cchMsg = 0;
    359   int cchUser;
    360 #endif
    361 
    362   log_working_directory (1);
    363 
    364 #ifdef KMK /* Try avoid getting the error split by child output.  */
    365   if (flocp && flocp->filenm)
    366     cchMsg = snprintf (szMsg, sizeof(szMsg), "%s:%lu: ", flocp->filenm, flocp->lineno);
    367   else if (makelevel == 0)
    368     cchMsg = snprintf (szMsg, sizeof(szMsg), "%s: ", program);
    369   else
    370     cchMsg = snprintf (szMsg, sizeof(szMsg), "%s[%u]: ", program, makelevel);
    371 
    372   VA_START (args, fmt);
    373   cchMsg += cchUser = vsnprintf (&szMsg[cchMsg], sizeof(szMsg) - cchMsg, fmt, args);
    374   VA_END (args);
    375   if (   cchMsg < (int)sizeof(szMsg)
    376       && cchUser >= 0)
    377     {
    378       extern size_t maybe_con_fwrite(void const *, size_t, size_t, FILE *);
    379       szMsg[cchMsg++] = '\n';
    380       maybe_con_fwrite(szMsg, cchMsg, 1, stderr);
    381     }
    382   else
    383     {
    384 #endif /* KMK */
    385 
    386   if (flocp && flocp->filenm)
    387     fprintf (stderr, "%s:%lu: ", flocp->filenm, flocp->lineno);
    388   else if (makelevel == 0)
    389     fprintf (stderr, "%s: ", program);
    390   else
    391     fprintf (stderr, "%s[%u]: ", program, makelevel);
    392 
    393   VA_START(args, fmt);
    394   VA_PRINTF (stderr, fmt, args);
    395   VA_END (args);
    396 
    397   putc ('\n', stderr);
    398 #ifdef KMK
    399     }
    400 #endif
    401   fflush (stderr);
    402 }
    403 
    404 /* Print an error message and exit.  */
    405 
    406 void
    407 #if HAVE_ANSI_COMPILER && USE_VARIADIC && HAVE_STDARG_H
    408 fatal (const struct floc *flocp, const char *fmt, ...)
    409 #else
    410 fatal (flocp, fmt, va_alist)
    411      const struct floc *flocp;
    412      const char *fmt;
    413      va_dcl
    414 #endif
    415 {
    416 #if USE_VARIADIC
    417   va_list args;
    418 #endif
    419 #ifdef KMK
    420   char szMsg[16384];
    421   int cchMsg = 0;
    422   int cchUser;
    423   const char *pszStop = _(".  Stop.\n");
    424   int         cchStop = (int)strlen(pszStop);
    425 #endif
    426 
    427   log_working_directory (1);
    428 
    429 #ifdef KMK /* Try avoid getting the error split by child output.  */
    430   if (flocp && flocp->filenm)
    431     cchMsg = snprintf (szMsg, sizeof(szMsg), "%s:%lu: *** ", flocp->filenm, flocp->lineno);
    432   else if (makelevel == 0)
    433     cchMsg = snprintf (szMsg, sizeof(szMsg), "%s: *** ", program);
    434   else
    435     cchMsg = snprintf (szMsg, sizeof(szMsg), "%s[%u]: *** ", program, makelevel);
    436 
    437   VA_START (args, fmt);
    438   cchMsg += cchUser = vsnprintf (&szMsg[cchMsg], sizeof(szMsg) - cchMsg, fmt, args);
    439   VA_END (args);
    440   if (   cchMsg + cchStop <= (int)sizeof(szMsg)
    441       && cchUser >= 0)
    442     {
    443       extern size_t maybe_con_fwrite(void const *, size_t, size_t, FILE *);
    444       memcpy(&szMsg[cchMsg], pszStop, cchStop);
    445       cchMsg += cchStop;
    446       maybe_con_fwrite(szMsg, cchMsg, 1, stderr);
    447     }
    448   else
    449     {
    450 #endif /* KMK */
    451   if (flocp && flocp->filenm)
    452     fprintf (stderr, "%s:%lu: *** ", flocp->filenm, flocp->lineno);
    453   else if (makelevel == 0)
    454     fprintf (stderr, "%s: *** ", program);
    455   else
    456     fprintf (stderr, "%s[%u]: *** ", program, makelevel);
    457 
    458   VA_START(args, fmt);
    459   VA_PRINTF (stderr, fmt, args);
    460   VA_END (args);
    461 
    462   fputs (_(".  Stop.\n"), stderr);
    463 #ifdef KMK
    464     }
    465 #endif
    466 
    467   die (2);
    468 }
    469248
    470249#ifndef HAVE_STRERROR
    471 
    472 #undef  strerror
    473 
     250#undef  strerror
    474251char *
    475252strerror (int errnum)
     
    488265}
    489266#endif
    490 
    491 /* Print an error message from errno.  */
    492 
    493 void
    494 perror_with_name (const char *str, const char *name)
    495 {
    496   error (NILF, _("%s%s: %s"), str, name, strerror (errno));
    497 }
    498 
    499 /* Print an error message from errno and exit.  */
    500 
    501 void
    502 pfatal_with_name (const char *name)
    503 {
    504   fatal (NILF, _("%s: %s"), name, strerror (errno));
    505 
    506   /* NOTREACHED */
    507 }
    508267
    509268
     
    524283  void *result = malloc (size ? size : 1);
    525284  if (result == 0)
    526     fatal (NILF, _("virtual memory exhausted"));
     285    OUT_OF_MEM();
    527286
    528287#ifdef CONFIG_WITH_MAKE_STATS
     
    543302  void *result = calloc (size ? size : 1, 1);
    544303  if (result == 0)
    545     fatal (NILF, _("virtual memory exhausted"));
     304    OUT_OF_MEM();
    546305
    547306#ifdef CONFIG_WITH_MAKE_STATS
     
    574333  result = ptr ? realloc (ptr, size) : malloc (size);
    575334  if (result == 0)
    576     fatal (NILF, _("virtual memory exhausted"));
     335    OUT_OF_MEM();
    577336
    578337#ifdef CONFIG_WITH_MAKE_STATS
     
    598357
    599358  if (result == 0)
    600     fatal (NILF, _("virtual memory exhausted"));
     359    OUT_OF_MEM();
    601360
    602361#ifdef CONFIG_WITH_MAKE_STATS
     
    624383  result = strndup (str, length);
    625384  if (result == 0)
    626     fatal (NILF, _("virtual memory exhausted"));
     385    OUT_OF_MEM();
    627386#else
    628387  result = xmalloc (length + 1);
     
    663422end_of_token (const char *s)
    664423{
    665 #ifdef KMK
     424#if 0 /* @todo def KMK */
    666425    for (;;)
    667426      {
     
    685444
    686445#else
    687   while (*s != '\0' && !isblank ((unsigned char)*s))
    688     ++s;
     446  END_OF_TOKEN (s);
    689447  return (char *)s;
    690448#endif
    691449}
    692 
    693 #ifdef WINDOWS32
    694 /*
    695  * Same as end_of_token, but take into account a stop character
    696  */
    697 char *
    698 end_of_token_w32 (const char *s, char stopchar)
    699 {
    700   const char *p = s;
    701   int backslash = 0;
    702 
    703   while (*p != '\0' && *p != stopchar
    704          && (backslash || !isblank ((unsigned char)*p)))
    705     {
    706       if (*p++ == '\\')
    707         {
    708           backslash = !backslash;
    709           while (*p == '\\')
    710             {
    711               backslash = !backslash;
    712               ++p;
    713             }
    714         }
    715       else
    716         backslash = 0;
    717     }
    718 
    719   return (char *)p;
    720 }
    721 #endif
    722450
    723451/* Return the address of the first nonwhitespace or null in the string S.  */
     
    726454next_token (const char *s)
    727455{
    728 #ifdef KMK
     456#if 0 /* @todo def KMK */
    729457  for (;;)
    730458    {
     
    748476
    749477#else  /* !KMK */
    750   while (isblank ((unsigned char)*s))
    751     ++s;
     478  NEXT_TOKEN (s);
    752479  return (char *)s;
    753480#endif /* !KMK */
     
    932659
    933660
    934 /* Copy a chain of `struct dep'.  For 2nd expansion deps, dup the name.  */
     661/* Copy a chain of 'struct dep'.  For 2nd expansion deps, dup the name.  */
    935662
    936663struct dep *
     
    955682      c->next = 0;
    956683      if (firstnew == 0)
    957         firstnew = lastnew = c;
     684        firstnew = lastnew = c;
    958685      else
    959         lastnew = lastnew->next = c;
     686        lastnew = lastnew->next = c;
    960687
    961688      d = d->next;
     
    963690
    964691  return firstnew;
    965 }
    966 
    967 /* Free a chain of 'struct dep'.  */
    968 
    969 void
    970 free_dep_chain (struct dep *d)
    971 {
    972   while (d != 0)
    973     {
    974       struct dep *df = d;
    975       d = d->next;
    976       free_dep (df);
    977     }
    978692}
    979693
     
    989703      ns = ns->next;
    990704#ifndef CONFIG_WITH_ALLOC_CACHES
    991       free (t);
     705      free_ns (t);
    992706#else
    993707      alloccache_free (&nameseq_cache, t);
     
    997711
    998712
     713#ifdef CONFIG_WITH_ALLOC_CACHES
     714
     715void
     716free_dep_chain (struct dep *d)
     717{
     718  while (d != 0)
     719    {
     720      struct dep *tofree = d;
     721      d = d->next;
     722      alloccache_free (&dep_cache, tofree);
     723    }
     724}
     725
     726void
     727free_goal_chain (struct goaldep *g)
     728{
     729  while (g != 0)
     730    {
     731      struct goaldep *tofree = g;
     732      g = g->next;
     733      alloccache_free (&dep_cache, tofree);
     734    }
     735}
     736
     737#endif /* CONFIG_WITH_ALLOC_CACHES */
     738
     739
    999740
    1000741#if !HAVE_STRCASECMP && !HAVE_STRICMP && !HAVE_STRCMPI
    1001 
    1002742/* If we don't have strcasecmp() (from POSIX), or anything that can substitute
    1003743   for it, define our own version.  */
     
    1025765
    1026766#if !HAVE_STRNCASECMP && !HAVE_STRNICMP && !HAVE_STRNCMPI
    1027 
    1028767/* If we don't have strncasecmp() (from POSIX), or anything that can
    1029768   substitute for it, define our own version.  */
     
    1053792
    1054793
    1055 #ifdef  GETLOADAVG_PRIVILEGED
     794#ifdef  GETLOADAVG_PRIVILEGED
    1056795
    1057796#ifdef POSIX
     
    1066805#undef HAVE_SETREGID
    1067806
    1068 #else   /* Not POSIX.  */
     807#else   /* Not POSIX.  */
    1069808
    1070809/* Some POSIX.1 systems have the seteuid and setegid functions.  In a
     
    1076815#undef HAVE_SETEGID
    1077816
    1078 #endif  /* POSIX.  */
    1079 
    1080 #ifndef HAVE_UNISTD_H
     817#endif  /* POSIX.  */
     818
     819#ifndef HAVE_UNISTD_H
    1081820extern int getuid (), getgid (), geteuid (), getegid ();
    1082821extern int setuid (), setgid ();
     
    1084823extern int seteuid ();
    1085824#else
    1086 #ifdef  HAVE_SETREUID
     825#ifdef  HAVE_SETREUID
    1087826extern int setreuid ();
    1088 #endif  /* Have setreuid.  */
    1089 #endif  /* Have seteuid.  */
     827#endif  /* Have setreuid.  */
     828#endif  /* Have seteuid.  */
    1090829#ifdef HAVE_SETEGID
    1091830extern int setegid ();
    1092831#else
    1093 #ifdef  HAVE_SETREGID
     832#ifdef  HAVE_SETREGID
    1094833extern int setregid ();
    1095 #endif  /* Have setregid.  */
    1096 #endif  /* Have setegid.  */
    1097 #endif  /* No <unistd.h>.  */
     834#endif  /* Have setregid.  */
     835#endif  /* Have setegid.  */
     836#endif  /* No <unistd.h>.  */
    1098837
    1099838/* Keep track of the user and group IDs for user- and make- access.  */
    1100839static int user_uid = -1, user_gid = -1, make_uid = -1, make_gid = -1;
    1101 #define access_inited   (user_uid != -1)
     840#define access_inited   (user_uid != -1)
    1102841static enum { make, user } current_access;
    1103842
     
    1116855
    1117856  fprintf (stderr, _("%s: user %lu (real %lu), group %lu (real %lu)\n"),
    1118            flavor, (unsigned long) geteuid (), (unsigned long) getuid (),
     857           flavor, (unsigned long) geteuid (), (unsigned long) getuid (),
    1119858           (unsigned long) getegid (), (unsigned long) getgid ());
    1120859  fflush (stderr);
     
    1142881}
    1143882
    1144 #endif  /* GETLOADAVG_PRIVILEGED */
     883#endif  /* GETLOADAVG_PRIVILEGED */
    1145884
    1146885/* Give the process appropriate permissions for access to
     
    1149888user_access (void)
    1150889{
    1151 #ifdef  GETLOADAVG_PRIVILEGED
     890#ifdef  GETLOADAVG_PRIVILEGED
    1152891
    1153892  if (!access_inited)
     
    1162901     which are the IDs of the process that exec'd make.  */
    1163902
    1164 #ifdef  HAVE_SETEUID
     903#ifdef  HAVE_SETEUID
    1165904
    1166905  /* Modern systems have the seteuid/setegid calls which set only the
     
    1170909    pfatal_with_name ("user_access: seteuid");
    1171910
    1172 #else   /* Not HAVE_SETEUID.  */
    1173 
    1174 #ifndef HAVE_SETREUID
     911#else   /* Not HAVE_SETEUID.  */
     912
     913#ifndef HAVE_SETREUID
    1175914
    1176915  /* System V has only the setuid/setgid calls to set user/group IDs.
     
    1185924    pfatal_with_name ("user_access: setuid");
    1186925
    1187 #else   /* HAVE_SETREUID.  */
     926#else   /* HAVE_SETREUID.  */
    1188927
    1189928  /* In 4BSD, the setreuid/setregid calls set both the real and effective IDs.
     
    1197936    pfatal_with_name ("user_access: setreuid");
    1198937
    1199 #endif  /* Not HAVE_SETREUID.  */
    1200 #endif  /* HAVE_SETEUID.  */
    1201 
    1202 #ifdef  HAVE_SETEGID
     938#endif  /* Not HAVE_SETREUID.  */
     939#endif  /* HAVE_SETEUID.  */
     940
     941#ifdef  HAVE_SETEGID
    1203942  if (setegid (user_gid) < 0)
    1204943    pfatal_with_name ("user_access: setegid");
    1205944#else
    1206 #ifndef HAVE_SETREGID
     945#ifndef HAVE_SETREGID
    1207946  if (setgid (user_gid) < 0)
    1208947    pfatal_with_name ("user_access: setgid");
     
    1217956  log_access (_("User access"));
    1218957
    1219 #endif  /* GETLOADAVG_PRIVILEGED */
     958#endif  /* GETLOADAVG_PRIVILEGED */
    1220959}
    1221960
     
    1225964make_access (void)
    1226965{
    1227 #ifdef  GETLOADAVG_PRIVILEGED
     966#ifdef  GETLOADAVG_PRIVILEGED
    1228967
    1229968  if (!access_inited)
     
    1235974  /* See comments in user_access, above.  */
    1236975
    1237 #ifdef  HAVE_SETEUID
     976#ifdef  HAVE_SETEUID
    1238977  if (seteuid (make_uid) < 0)
    1239978    pfatal_with_name ("make_access: seteuid");
    1240979#else
    1241 #ifndef HAVE_SETREUID
     980#ifndef HAVE_SETREUID
    1242981  if (setuid (make_uid) < 0)
    1243982    pfatal_with_name ("make_access: setuid");
     
    1248987#endif
    1249988
    1250 #ifdef  HAVE_SETEGID
     989#ifdef  HAVE_SETEGID
    1251990  if (setegid (make_gid) < 0)
    1252991    pfatal_with_name ("make_access: setegid");
    1253992#else
    1254 #ifndef HAVE_SETREGID
     993#ifndef HAVE_SETREGID
    1255994  if (setgid (make_gid) < 0)
    1256995    pfatal_with_name ("make_access: setgid");
     
    12651004  log_access (_("Make access"));
    12661005
    1267 #endif  /* GETLOADAVG_PRIVILEGED */
     1006#endif  /* GETLOADAVG_PRIVILEGED */
    12681007}
    12691008
     
    12731012child_access (void)
    12741013{
    1275 #ifdef  GETLOADAVG_PRIVILEGED
     1014#ifdef  GETLOADAVG_PRIVILEGED
    12761015
    12771016  if (!access_inited)
     
    12811020     They cannot be changed back to make's.  */
    12821021
    1283 #ifndef HAVE_SETREUID
     1022#ifndef HAVE_SETREUID
    12841023  if (setuid (user_uid) < 0)
    12851024    pfatal_with_name ("child_access: setuid");
     
    12891028#endif
    12901029
    1291 #ifndef HAVE_SETREGID
     1030#ifndef HAVE_SETREGID
    12921031  if (setgid (user_gid) < 0)
    12931032    pfatal_with_name ("child_access: setgid");
     
    12991038  log_access (_("Child access"));
    13001039
    1301 #endif  /* GETLOADAVG_PRIVILEGED */
    1302 }
    1303 
     1040#endif  /* GETLOADAVG_PRIVILEGED */
     1041}
    13041042
    13051043#ifdef NEED_GET_PATH_MAX
     
    13131051      long int x = pathconf ("/", _PC_PATH_MAX);
    13141052      if (x > 0)
    1315         value = x;
     1053        value = x;
    13161054      else
    1317         return MAXPATHLEN;
     1055        return MAXPATHLEN;
    13181056    }
    13191057
     
    13211059}
    13221060#endif
    1323 
    1324 
    1325 
    1326 /* This code is stolen from gnulib.
    1327    If/when we abandon the requirement to work with K&R compilers, we can
    1328    remove this (and perhaps other parts of GNU make!) and migrate to using
    1329    gnulib directly.
    1330 
    1331    This is called only through atexit(), which means die() has already been
    1332    invoked.  So, call exit() here directly.  Apparently that works...?
    1333 */
    1334 
    1335 /* Close standard output, exiting with status 'exit_failure' on failure.
    1336    If a program writes *anything* to stdout, that program should close
    1337    stdout and make sure that it succeeds before exiting.  Otherwise,
    1338    suppose that you go to the extreme of checking the return status
    1339    of every function that does an explicit write to stdout.  The last
    1340    printf can succeed in writing to the internal stream buffer, and yet
    1341    the fclose(stdout) could still fail (due e.g., to a disk full error)
    1342    when it tries to write out that buffered data.  Thus, you would be
    1343    left with an incomplete output file and the offending program would
    1344    exit successfully.  Even calling fflush is not always sufficient,
    1345    since some file systems (NFS and CODA) buffer written/flushed data
    1346    until an actual close call.
    1347 
    1348    Besides, it's wasteful to check the return value from every call
    1349    that writes to stdout -- just let the internal stream state record
    1350    the failure.  That's what the ferror test is checking below.
    1351 
    1352    It's important to detect such failures and exit nonzero because many
    1353    tools (most notably `make' and other build-management systems) depend
    1354    on being able to detect failure in other tools via their exit status.  */
    1355 
    1356 void
    1357 close_stdout (void)
    1358 {
    1359   int prev_fail = ferror (stdout);
    1360   int fclose_fail = fclose (stdout);
    1361 
    1362   if (prev_fail || fclose_fail)
    1363     {
    1364       if (fclose_fail)
    1365         error (NILF, _("write error: %s"), strerror (errno));
    1366       else
    1367         error (NILF, _("write error"));
    1368       exit (EXIT_FAILURE);
    1369     }
    1370 }
    13711061
    13721062#ifdef CONFIG_WITH_PRINT_STATS_SWITCH
     
    15051195  else
    15061196    {
    1507       error (NILF, _("gettimeofday failed"));
     1197      O (error, NILF, _("gettimeofday failed"));
    15081198      ts = -1;
    15091199    }
     
    15551245    }
    15561246  if (sz >= size)
    1557     fatal (NILF, _("format_elapsed_nano buffer overflow: %u written, %lu buffer"),
    1558            sz, (unsigned long)size);
     1247    ONN (fatal, NILF, _("format_elapsed_nano buffer overflow: %u written, %lu buffer"),
     1248         sz, (unsigned long)size);
    15591249  return sz;
    15601250}
    15611251#endif /* CONFIG_WITH_PRINT_TIME_SWITCH */
     1252
Note: See TracChangeset for help on using the changeset viewer.