Print this page
make: unifdef for other OSes (undefined)

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/make/lib/mksh/dosys.cc
          +++ new/usr/src/cmd/make/lib/mksh/dosys.cc
↓ open down ↓ 49 lines elided ↑ open up ↑
  50   50  #include <mksh/dosys.h>
  51   51  #include <mksh/macro.h>         /* getvar() */
  52   52  #include <mksh/misc.h>          /* getmem(), fatal_mksh(), errmsg() */
  53   53  #include <mksdmsi18n/mksdmsi18n.h>      /* libmksdmsi18n_init() */
  54   54  #include <sys/signal.h>         /* SIG_DFL */
  55   55  #include <sys/stat.h>           /* open() */
  56   56  #include <sys/wait.h>           /* wait() */
  57   57  #include <ulimit.h>             /* ulimit() */
  58   58  #include <unistd.h>             /* close(), dup2() */
  59   59  
  60      -#if defined (HP_UX) || defined (linux)
  61      -#       include <sys/param.h>
  62      -#       include <wctype.h>
  63      -#       include <wchar.h>
  64      -#endif
  65   60  
  66      -#if defined (linux)
  67      -#       define wslen(x) wcslen(x)
  68      -#       define wscpy(x,y) wcscpy(x,y)
  69      -#endif
  70   61  
  71   62  /*
  72   63   * Defined macros
  73   64   */
  74   65  #if defined(DISTRIBUTED) || defined(MAKETOOL) /* tolik */
  75   66  #define SEND_MTOOL_MSG(cmds) \
  76   67          if (send_mtool_msgs) { \
  77   68                  cmds \
  78   69          }
  79   70  #else
↓ open down ↓ 14 lines elided ↑ open up ↑
  94   85  static Boolean  exec_vp(register char *name, register char **argv, char **envp, register Boolean ignore_error, pathpt vroot_path);
  95   86  
  96   87  /*
  97   88   * Workaround for NFS bug. Sometimes, when running 'open' on a remote
  98   89   * dmake server, it fails with "Stale NFS file handle" error.
  99   90   * The second attempt seems to work.
 100   91   */
 101   92  int
 102   93  my_open(const char *path, int oflag, mode_t mode) {
 103   94          int res = open(path, oflag, mode);
 104      -#ifdef linux
 105      -// Workaround for NFS problem: even when all directories in 'path'
 106      -// exist, 'open' (file creation) fails with ENOENT.
 107      -        int nattempt = 0;
 108      -        while (res < 0 && (errno == ESTALE || errno == EAGAIN || errno == ENOENT)) {
 109      -                nattempt++;
 110      -                if(nattempt > 30) {
 111      -                        break;
 112      -                }
 113      -                sleep(1);
 114      -#else
 115   95          if (res < 0 && (errno == ESTALE || errno == EAGAIN)) {
 116      -#endif
 117   96                  /* Stale NFS file handle. Try again */
 118   97                  res = open(path, oflag, mode);
 119   98          }
 120   99          return res;
 121  100  }
 122  101  
 123  102  /*
 124  103   *      void
 125  104   *      redirect_io(char *stdout_file, char *stderr_file)
 126  105   *
 127  106   *      Redirects stdout and stderr for a child mksh process.
 128  107   */
 129  108  void
 130  109  redirect_io(char *stdout_file, char *stderr_file)
 131  110  {        
 132  111          long            descriptor_limit;
 133  112          int             i;
 134  113  
 135      -#if defined (HP_UX) || defined (linux)
 136      -        /*
 137      -         *  HP-UX does not support the UL_GDESLIM command for ulimit().
 138      -         *  NOFILE == max num open files per process (from <sys/param.h>)
 139      -         */
 140      -        descriptor_limit = NOFILE;
 141      -#else
 142  114          if ((descriptor_limit = ulimit(UL_GDESLIM)) < 0) {
 143  115                  fatal_mksh(catgets(libmksdmsi18n_catd, 1, 89, "ulimit() failed: %s"), errmsg(errno));
 144  116          }
 145      -#endif
 146  117          for (i = 3; i < descriptor_limit; i++) {
 147  118                  (void) close(i);
 148  119          }
 149  120          if ((i = my_open(stdout_file,
 150  121                   O_WRONLY | O_CREAT | O_TRUNC | O_DSYNC,
 151  122                   S_IREAD | S_IWRITE)) < 0) {
 152  123                  fatal_mksh(catgets(libmksdmsi18n_catd, 1, 90, "Couldn't open standard out temp file `%s': %s"),
 153  124                        stdout_file,
 154  125                        errmsg(errno));
 155  126          } else {
↓ open down ↓ 181 lines elided ↑ open up ↑
 337  308           * Only prepend the /usr/bin/nice command to the original command
 338  309           * if the nice priority, nice_prio, is NOT zero (0).
 339  310           * Nice priorities can be a positive or a negative number.
 340  311           */
 341  312          if (nice_prio != 0) {
 342  313                  argv[argv_index++] = (char *)NOCATGETS("nice");
 343  314                  (void) sprintf(nice_prio_buf, NOCATGETS("-%d"), nice_prio);
 344  315                  argv[argv_index++] = strdup(nice_prio_buf);
 345  316          }
 346  317          argv[argv_index++] = shellname;
 347      -#if defined(linux)
 348      -        if(0 == strcmp(shell->string_mb, (char*)NOCATGETS("/bin/sh"))) {
 349      -                argv[argv_index++] = (char*)(ignore_error ? NOCATGETS("-c") : NOCATGETS("-ce"));
 350      -        } else {
 351      -                argv[argv_index++] = (char*)NOCATGETS("-c");
 352      -        }
 353      -#else
 354  318          argv[argv_index++] = (char*)(ignore_error ? NOCATGETS("-c") : NOCATGETS("-ce"));
 355      -#endif
 356  319          if ((length = wslen(command)) >= MAXPATHLEN) {
 357  320                  tmp_mbs_buffer = getmem((length * MB_LEN_MAX) + 1);
 358  321                  (void) wcstombs(tmp_mbs_buffer, command, (length * MB_LEN_MAX) + 1);
 359  322                  cmd_argv_index = argv_index;
 360  323                  argv[argv_index++] = strdup(tmp_mbs_buffer);
 361  324                  retmem_mb(tmp_mbs_buffer);
 362  325          } else {
 363  326                  WCSTOMBS(mbs_buffer, command);
 364  327                  cmd_argv_index = argv_index;
 365      -#if defined(linux)
 366      -                int mbl = strlen(mbs_buffer);
 367      -                if(mbl > 2) {
 368      -                        if(mbs_buffer[mbl-1] == '\n' && mbs_buffer[mbl-2] == '\\') {
 369      -                                mbs_buffer[mbl] = '\n';
 370      -                                mbs_buffer[mbl+1] = 0;
 371      -                        }
 372      -                }
 373      -#endif
 374  328                  argv[argv_index++] = strdup(mbs_buffer);
 375  329          }
 376  330          argv[argv_index] = NULL;
 377  331          (void) fflush(stdout);
 378  332          if ((childPid = fork()) == 0) {
 379  333                  enable_interrupt((void (*) (int)) SIG_DFL);
 380  334                  if (redirect_out_err) {
 381  335                          redirect_io(stdout_file, stderr_file);
 382  336                  }
 383  337  #if 0
↓ open down ↓ 426 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX