Print this page
make: unifdef for SGE (undefined)

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/make/bin/parallel.cc
          +++ new/usr/src/cmd/make/bin/parallel.cc
↓ open down ↓ 45 lines elided ↑ open up ↑
  46   46  #include <mksh/dosys.h>         /* redirect_io() */
  47   47  #include <mksh/macro.h>         /* expand_value() */
  48   48  #include <mksh/misc.h>          /* getmem() */
  49   49  #include <sys/signal.h>
  50   50  #include <sys/stat.h>
  51   51  #include <sys/types.h>
  52   52  #include <sys/utsname.h>
  53   53  #include <sys/wait.h>
  54   54  #include <unistd.h>
  55   55  
  56      -#ifdef SGE_SUPPORT
  57      -#include <dmthread/Avo_PathNames.h>
  58      -#endif
  59   56  
  60   57  
  61   58  /*
  62   59   * Defined macros
  63   60   */
  64   61  #define MAXRULES                100
  65   62  
  66   63  /*
  67   64   * This const should be in avo_dms/include/AvoDmakeCommand.h
  68   65   */
↓ open down ↓ 790 lines elided ↑ open up ↑
 859  856                                  tmpdir,
 860  857                                  getpid(),
 861  858                                  file_number++);
 862  859  
 863  860                  mktemp(mbstring);
 864  861  
 865  862                  stderr_file = strdup(mbstring);
 866  863          }
 867  864  #endif
 868  865  
 869      -#ifdef SGE_SUPPORT
 870      -        if (grid) {
 871      -                static char *dir4gridscripts = NULL;
 872      -                static char *hostName = NULL;
 873      -                if (dir4gridscripts == NULL) {
 874      -                        Name            dmakeOdir_name, dmakeOdir_value;
 875      -                        Property        prop;
 876      -                        MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_ODIR"));
 877      -                        dmakeOdir_name = GETNAME(wcs_buffer, FIND_LENGTH);
 878      -                        if (((prop = get_prop(dmakeOdir_name->prop, macro_prop)) != NULL) &&
 879      -                            ((dmakeOdir_value = prop->body.macro.value) != NULL)) {
 880      -                                dir4gridscripts = dmakeOdir_value->string_mb;
 881      -                        }
 882      -                        dir4gridscripts = Avo_PathNames::pathname_output_directory(dir4gridscripts);
 883      -                        hostName = Avo_PathNames::pathname_local_host();
 884      -                }
 885      -                (void) sprintf(script_file,
 886      -                                NOCATGETS("%s/dmake.script.%s.%d.%d.XXXXXX"),
 887      -                                dir4gridscripts,
 888      -                                hostName,
 889      -                                getpid(),
 890      -                                file_number++);
 891      -        }
 892      -#endif /* SGE_SUPPORT */
 893  866          process_running = run_rule_commands(local_host, commands);
 894  867  
 895  868          return build_running;
 896  869  }
 897  870  
 898  871  /*
 899  872   *      doname_parallel(target, do_get, implicit)
 900  873   *
 901  874   *      Processes the given target and finishes up any parallel
 902  875   *      processes left running.
↓ open down ↓ 1140 lines elided ↑ open up ↑
2043 2016                  return false;
2044 2017          } else {
2045 2018                  return (rp->state == build_running) ? true : false;
2046 2019          }
2047 2020  }
2048 2021  
2049 2022  /*
2050 2023   * This function replaces the makesh binary.
2051 2024   */
2052 2025   
2053      -#ifdef SGE_SUPPORT
2054      -#define DO_CHECK(f)     if (f <= 0) { \
2055      -                                fprintf(stderr, \
2056      -                                        catgets(catd, 1, 347, "Could not write to file: %s: %s\n"), \
2057      -                                                script_file, errmsg(errno)); \
2058      -                                _exit(1); \
2059      -                        }
2060      -#endif /* SGE_SUPPORT */
2061 2026  
2062 2027  static pid_t
2063 2028  run_rule_commands(char *host, char **commands)
2064 2029  {
2065 2030          Boolean         always_exec;
2066 2031          Name            command;
2067 2032          Boolean         ignore;
2068 2033          int             length;
2069 2034          Doname          result;
2070 2035          Boolean         silent_flag;
2071      -#ifdef SGE_SUPPORT
2072      -        wchar_t         *wcmd, *tmp_wcs_buffer = NULL;
2073      -        char            *cmd, *tmp_mbs_buffer = NULL;
2074      -        FILE            *scrfp;
2075      -        Name            shell = getvar(shell_name);
2076      -#else
2077 2036          wchar_t         *tmp_wcs_buffer;
2078      -#endif /* SGE_SUPPORT */
2079 2037  
2080 2038          childPid = fork();
2081 2039          switch (childPid) {
2082 2040          case -1:        /* Error */
2083 2041                  fatal(catgets(catd, 1, 337, "Could not fork child process for dmake job: %s"),
2084 2042                        errmsg(errno));
2085 2043                  break;
2086 2044          case 0:         /* Child */
2087 2045                  /* To control the processed targets list is not the child's business */
2088 2046                  running_list = NULL;
2089 2047  #if defined(REDIRECT_ERR)
2090 2048                  if(out_err_same) {
2091 2049                          redirect_io(stdout_file, (char*)NULL);
2092 2050                  } else {
2093 2051                          redirect_io(stdout_file, stderr_file);
2094 2052                  }
2095 2053  #else
2096 2054                  redirect_io(stdout_file, (char*)NULL);
2097 2055  #endif
2098      -#ifdef SGE_SUPPORT
2099      -                if (grid) {
2100      -                        int fdes = mkstemp(script_file);
2101      -                        if ((fdes < 0) || (scrfp = fdopen(fdes, "w")) == NULL) {
2102      -                                fprintf(stderr,
2103      -                                        catgets(catd, 1, 341, "Could not create file: %s: %s\n"),
2104      -                                        script_file, errmsg(errno));
2105      -                                _exit(1);
2106      -                        }
2107      -                        if (IS_EQUAL(shell->string_mb, "")) {
2108      -                                shell = shell_name;
2109      -                        }
2110      -                }
2111      -#endif /* SGE_SUPPORT */
2112 2056                  for (commands = commands;
2113 2057                       (*commands != (char *)NULL);
2114 2058                       commands++) {
2115 2059                          silent_flag = silent;
2116 2060                          ignore = false;
2117 2061                          always_exec = false;
2118 2062                          while ((**commands == (int) at_char) ||
2119 2063                                 (**commands == (int) hyphen_char) ||
2120 2064                                 (**commands == (int) plus_char)) {
2121 2065                                  if (**commands == (int) at_char) {
2122 2066                                          silent_flag = true;
2123 2067                                  }
2124 2068                                  if (**commands == (int) hyphen_char) {
2125 2069                                          ignore = true;
2126 2070                                  }
2127 2071                                  if (**commands == (int) plus_char) {
2128 2072                                          always_exec = true;
2129 2073                                  }
2130 2074                                  (*commands)++;
2131 2075                          }
2132      -#ifdef SGE_SUPPORT
2133      -                        if (grid) {
2134      -                                if ((length = strlen(*commands)) >= MAXPATHLEN / 2) {
2135      -                                        wcmd = tmp_wcs_buffer = ALLOC_WC(length * 2 + 1);
2136      -                                        (void) mbstowcs(tmp_wcs_buffer, *commands, length * 2 + 1);
2137      -                                } else {
2138      -                                        MBSTOWCS(wcs_buffer, *commands);
2139      -                                        wcmd = wcs_buffer;
2140      -                                        cmd = mbs_buffer;
2141      -                                }
2142      -                                wchar_t *from = wcmd + wslen(wcmd);
2143      -                                wchar_t *to = from + (from - wcmd);
2144      -                                *to = (int) nul_char;
2145      -                                while (from > wcmd) {
2146      -                                        *--to = *--from;
2147      -                                        if (*from == (int) newline_char) { // newline symbols are already quoted
2148      -                                                *--to = *--from;
2149      -                                        } else if (wschr(char_semantics_char, *from)) {
2150      -                                                *--to = (int) backslash_char;
2151      -                                        }
2152      -                                }
2153      -                                if (length >= MAXPATHLEN*MB_LEN_MAX/2) { // sizeof(mbs_buffer) / 2
2154      -                                        cmd = tmp_mbs_buffer = getmem((length * MB_LEN_MAX * 2) + 1);
2155      -                                        (void) wcstombs(tmp_mbs_buffer, to, (length * MB_LEN_MAX * 2) + 1);
2156      -                                } else {
2157      -                                        WCSTOMBS(mbs_buffer, to);
2158      -                                        cmd = mbs_buffer;
2159      -                                }
2160      -                                char *mbst, *mbend;
2161      -                                if ((length > 0) &&
2162      -                                    !silent_flag) {
2163      -                                        for (mbst = cmd; (mbend = strstr(mbst, "\\\n")) != NULL; mbst = mbend + 2) {
2164      -                                                *mbend = '\0';
2165      -                                                DO_CHECK(fprintf(scrfp, NOCATGETS("/usr/bin/printf '%%s\\n' %s\\\\\n"), mbst));
2166      -                                                *mbend = '\\';
2167      -                                        }
2168      -                                        DO_CHECK(fprintf(scrfp, NOCATGETS("/usr/bin/printf '%%s\\n' %s\n"), mbst));
2169      -                                }
2170      -                                if (!do_not_exec_rule ||
2171      -                                    !working_on_targets ||
2172      -                                    always_exec) {
2173      -                                        DO_CHECK(fprintf(scrfp, NOCATGETS("%s -ce %s\n"), shell->string_mb, cmd));
2174      -                                        DO_CHECK(fputs(NOCATGETS("__DMAKECMDEXITSTAT=$?\nif [ ${__DMAKECMDEXITSTAT} -ne 0 ]; then\n"), scrfp));
2175      -                                        if (ignore) {
2176      -                                                DO_CHECK(fprintf(scrfp, NOCATGETS("\techo %s ${__DMAKECMDEXITSTAT} %s\n"),
2177      -                                                        catgets(catd, 1, 343, "\"*** Error code"),
2178      -                                                        catgets(catd, 1, 344, "(ignored)\"")));
2179      -                                        } else {
2180      -                                                DO_CHECK(fprintf(scrfp, NOCATGETS("\techo %s ${__DMAKECMDEXITSTAT}\n"),
2181      -                                                        catgets(catd, 1, 342, "\"*** Error code\"")));
2182      -                                        }
2183      -                                        if (silent_flag) {
2184      -                                                DO_CHECK(fprintf(scrfp, NOCATGETS("\techo %s\n"),
2185      -                                                        catgets(catd, 1, 345, "The following command caused the error:")));
2186      -                                                for (mbst = cmd; (mbend = strstr(mbst, "\\\n")) != NULL; mbst = mbend + 2) {
2187      -                                                        *mbend = '\0';
2188      -                                                        DO_CHECK(fprintf(scrfp, NOCATGETS("\t/usr/bin/printf '%%s\\n' %s\\\\\n"), mbst));
2189      -                                                        *mbend = '\\';
2190      -                                                }
2191      -                                                DO_CHECK(fprintf(scrfp, NOCATGETS("\t/usr/bin/printf '%%s\\n' %s\n"), mbst));
2192      -                                        }
2193      -                                        if (!ignore) {
2194      -                                                DO_CHECK(fputs(NOCATGETS("\texit ${__DMAKECMDEXITSTAT}\n"), scrfp));
2195      -                                        }
2196      -                                        DO_CHECK(fputs(NOCATGETS("fi\n"), scrfp));
2197      -                                }
2198      -                                if (tmp_wcs_buffer) {
2199      -                                        retmem_mb(tmp_mbs_buffer);
2200      -                                        tmp_mbs_buffer = NULL;
2201      -                                }
2202      -                                if (tmp_wcs_buffer) {
2203      -                                        retmem(tmp_wcs_buffer);
2204      -                                        tmp_wcs_buffer = NULL;
2205      -                                }
2206      -                                continue;
2207      -                        }
2208      -#endif /* SGE_SUPPORT */
2209 2076                          if ((length = strlen(*commands)) >= MAXPATHLEN) {
2210 2077                                  tmp_wcs_buffer = ALLOC_WC(length + 1);
2211 2078                                  (void) mbstowcs(tmp_wcs_buffer, *commands, length + 1);
2212 2079                                  command = GETNAME(tmp_wcs_buffer, FIND_LENGTH);
2213 2080                                  retmem(tmp_wcs_buffer);
2214 2081                          } else {
2215 2082                                  MBSTOWCS(wcs_buffer, *commands);
2216 2083                                  command = GETNAME(wcs_buffer, FIND_LENGTH);
2217 2084                          }
2218 2085                          if ((command->hash.length > 0) &&
↓ open down ↓ 10 lines elided ↑ open up ↑
2229 2096                                         false);
2230 2097                          if (result == build_failed) {
2231 2098                                  if (silent_flag) {
2232 2099                                          (void) printf(catgets(catd, 1, 152, "The following command caused the error:\n%s\n"), command->string_mb);
2233 2100                                  }
2234 2101                                  if (!ignore) {
2235 2102                                          _exit(1);
2236 2103                                  }
2237 2104                          }
2238 2105                  }
2239      -#ifndef SGE_SUPPORT
2240 2106                  _exit(0);
2241      -#else
2242      -                if (!grid) {
2243      -                        _exit(0);
2244      -                }
2245      -                DO_CHECK(fputs(NOCATGETS("exit 0\n"), scrfp));
2246      -                if (fclose(scrfp) != 0) {
2247      -                        fprintf(stderr,
2248      -                                catgets(catd, 1, 346, "Could not close file: %s: %s\n"),
2249      -                                script_file, errmsg(errno));
2250      -                        _exit(1);
2251      -                }
2252      -                {
2253      -
2254      -#define DEFAULT_QRSH_TRIES_NUMBER       1
2255      -#define DEFAULT_QRSH_TIMEOUT            0
2256      -
2257      -                static char     *sge_env_var = NULL;
2258      -                static int      qrsh_tries_number = DEFAULT_QRSH_TRIES_NUMBER;
2259      -                static int      qrsh_timeout = DEFAULT_QRSH_TIMEOUT;
2260      -#define SGE_DEBUG
2261      -#ifdef SGE_DEBUG
2262      -                static  Boolean do_not_remove = false;
2263      -#endif /* SGE_DEBUG */
2264      -                if (sge_env_var == NULL) {
2265      -                        sge_env_var = getenv(NOCATGETS("__SPRO_DMAKE_SGE_TRIES"));
2266      -                        if (sge_env_var != NULL) {
2267      -                                qrsh_tries_number = atoi(sge_env_var);
2268      -                                if (qrsh_tries_number < 1 || qrsh_tries_number > 9) {
2269      -                                        qrsh_tries_number = DEFAULT_QRSH_TRIES_NUMBER;
2270      -                                }
2271      -                        }
2272      -                        sge_env_var = getenv(NOCATGETS("__SPRO_DMAKE_SGE_TIMEOUT"));
2273      -                        if (sge_env_var != NULL) {
2274      -                                qrsh_timeout = atoi(sge_env_var);
2275      -                                if (qrsh_timeout <= 0) {
2276      -                                        qrsh_timeout = DEFAULT_QRSH_TIMEOUT;
2277      -                                }
2278      -                        } else {
2279      -                                sge_env_var = "";
2280      -                        }
2281      -#ifdef SGE_DEBUG
2282      -                        sge_env_var = getenv(NOCATGETS("__SPRO_DMAKE_SGE_DEBUG"));
2283      -                        if (sge_env_var == NULL) {
2284      -                                sge_env_var = "";
2285      -                        }
2286      -                        if (strstr(sge_env_var, NOCATGETS("noqrsh")) != NULL)
2287      -                                qrsh_tries_number = 0;
2288      -                        if (strstr(sge_env_var, NOCATGETS("donotremove")) != NULL)
2289      -                                do_not_remove = true;
2290      -#endif /* SGE_DEBUG */
2291      -                }
2292      -                for (int i = qrsh_tries_number; ; i--)
2293      -                if ((childPid = fork()) < 0) {
2294      -                        fatal(catgets(catd, 1, 348, "Could not fork child process for qrsh job: %s"),
2295      -                                errmsg(errno));
2296      -                        _exit(1);
2297      -                } else if (childPid == 0) {
2298      -                        enable_interrupt((void (*) (int))SIG_DFL);
2299      -                        if (i > 0) {
2300      -                                static char qrsh_cmd[50+MAXPATHLEN] = NOCATGETS("qrsh -cwd -V -noshell -nostdin /bin/sh ");
2301      -                                static char *fname_ptr = NULL;
2302      -                                static char *argv[] = { NOCATGETS("sh"),
2303      -                                                        NOCATGETS("-fce"),
2304      -                                                        qrsh_cmd,
2305      -                                                        NULL};
2306      -                                if (fname_ptr == NULL) {
2307      -                                        fname_ptr = qrsh_cmd + strlen(qrsh_cmd);
2308      -                                }
2309      -                                strcpy(fname_ptr, script_file);
2310      -                                (void) execve(NOCATGETS("/bin/sh"), argv, environ);
2311      -                        } else {
2312      -                                static char *argv[] = { NOCATGETS("sh"),
2313      -                                                        script_file,
2314      -                                                        NULL};
2315      -                                (void) execve(NOCATGETS("/bin/sh"), argv, environ);
2316      -                        }
2317      -                        fprintf(stderr,
2318      -                                catgets(catd, 1, 349, "Could not load `qrsh': %s\n"),
2319      -                                errmsg(errno));
2320      -                        _exit(1);
2321      -                } else {
2322      -                        int             status;
2323      -                        pid_t pid;
2324      -                        while ((pid = wait(&status)) != childPid) {
2325      -                                if (pid == -1) {
2326      -                                        fprintf(stderr,
2327      -                                                catgets(catd, 1, 350, "wait() failed: %s\n"),
2328      -                                                errmsg(errno));
2329      -                                        _exit(1);
2330      -                                }
2331      -                        }
2332      -                        if (status != 0 && i > 0) {
2333      -                                if (i > 1) {
2334      -                                        sleep(qrsh_timeout);
2335      -                                }
2336      -                                continue;
2337      -                        }
2338      -#ifdef SGE_DEBUG
2339      -                        if (do_not_remove) {
2340      -                                if (status) {
2341      -                                        fprintf(stderr,
2342      -                                                NOCATGETS("SGE script failed: %s\n"),
2343      -                                                script_file);
2344      -                                }
2345      -                                _exit(status ? 1 : 0);
2346      -                        }
2347      -#endif /* SGE_DEBUG */
2348      -                        (void) unlink(script_file);
2349      -                        _exit(status ? 1 : 0);
2350      -                }
2351      -                }
2352      -#endif /* SGE_SUPPORT */
2353 2107                  break;
2354 2108          default:
2355 2109                  break;
2356 2110          }
2357 2111          return childPid;
2358 2112  }
2359 2113  
2360 2114  static void
2361 2115  maybe_reread_make_state(void)
2362 2116  {
↓ open down ↓ 97 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX