| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: main.c,v 1.392 2020/10/26 23:28:52 rillig Exp $ */ | | 1 | /* $NetBSD: main.c,v 1.393 2020/10/27 06:59:20 rillig Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1988, 1989, 1990, 1993 | | 4 | * Copyright (c) 1988, 1989, 1990, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to Berkeley by | | 7 | * This code is derived from software contributed to Berkeley by |
8 | * Adam de Boor. | | 8 | * Adam de Boor. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -108,27 +108,27 @@ | | | @@ -108,27 +108,27 @@ |
108 | | | 108 | |
109 | #include <errno.h> | | 109 | #include <errno.h> |
110 | #include <signal.h> | | 110 | #include <signal.h> |
111 | #include <stdarg.h> | | 111 | #include <stdarg.h> |
112 | #include <time.h> | | 112 | #include <time.h> |
113 | | | 113 | |
114 | #include "make.h" | | 114 | #include "make.h" |
115 | #include "dir.h" | | 115 | #include "dir.h" |
116 | #include "job.h" | | 116 | #include "job.h" |
117 | #include "pathnames.h" | | 117 | #include "pathnames.h" |
118 | #include "trace.h" | | 118 | #include "trace.h" |
119 | | | 119 | |
120 | /* "@(#)main.c 8.3 (Berkeley) 3/19/94" */ | | 120 | /* "@(#)main.c 8.3 (Berkeley) 3/19/94" */ |
121 | MAKE_RCSID("$NetBSD: main.c,v 1.392 2020/10/26 23:28:52 rillig Exp $"); | | 121 | MAKE_RCSID("$NetBSD: main.c,v 1.393 2020/10/27 06:59:20 rillig Exp $"); |
122 | #if defined(MAKE_NATIVE) && !defined(lint) | | 122 | #if defined(MAKE_NATIVE) && !defined(lint) |
123 | __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 " | | 123 | __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 " |
124 | "The Regents of the University of California. " | | 124 | "The Regents of the University of California. " |
125 | "All rights reserved."); | | 125 | "All rights reserved."); |
126 | #endif | | 126 | #endif |
127 | | | 127 | |
128 | #ifndef DEFMAXLOCAL | | 128 | #ifndef DEFMAXLOCAL |
129 | #define DEFMAXLOCAL DEFMAXJOBS | | 129 | #define DEFMAXLOCAL DEFMAXJOBS |
130 | #endif | | 130 | #endif |
131 | | | 131 | |
132 | CmdOpts opts; | | 132 | CmdOpts opts; |
133 | time_t now; /* Time at start of make */ | | 133 | time_t now; /* Time at start of make */ |
134 | GNode *DEFAULT; /* .DEFAULT node */ | | 134 | GNode *DEFAULT; /* .DEFAULT node */ |
| @@ -1037,26 +1037,40 @@ HandlePWD(const struct stat *curdir_st) | | | @@ -1037,26 +1037,40 @@ HandlePWD(const struct stat *curdir_st) |
1037 | if (makeobjdir != NULL && strchr(makeobjdir, '$') != NULL) | | 1037 | if (makeobjdir != NULL && strchr(makeobjdir, '$') != NULL) |
1038 | goto ignore_pwd; | | 1038 | goto ignore_pwd; |
1039 | | | 1039 | |
1040 | if (stat(pwd, &pwd_st) == 0 && | | 1040 | if (stat(pwd, &pwd_st) == 0 && |
1041 | curdir_st->st_ino == pwd_st.st_ino && | | 1041 | curdir_st->st_ino == pwd_st.st_ino && |
1042 | curdir_st->st_dev == pwd_st.st_dev) | | 1042 | curdir_st->st_dev == pwd_st.st_dev) |
1043 | (void)strncpy(curdir, pwd, MAXPATHLEN); | | 1043 | (void)strncpy(curdir, pwd, MAXPATHLEN); |
1044 | | | 1044 | |
1045 | ignore_pwd: | | 1045 | ignore_pwd: |
1046 | bmake_free(makeobjdir_freeIt); | | 1046 | bmake_free(makeobjdir_freeIt); |
1047 | } | | 1047 | } |
1048 | #endif | | 1048 | #endif |
1049 | | | 1049 | |
| | | 1050 | /* get rid of resource limit on file descriptors */ |
| | | 1051 | static void |
| | | 1052 | UnlimitFiles(void) |
| | | 1053 | { |
| | | 1054 | #if defined(MAKE_NATIVE) || (defined(HAVE_SETRLIMIT) && defined(RLIMIT_NOFILE)) |
| | | 1055 | struct rlimit rl; |
| | | 1056 | if (getrlimit(RLIMIT_NOFILE, &rl) != -1 && |
| | | 1057 | rl.rlim_cur != rl.rlim_max) { |
| | | 1058 | rl.rlim_cur = rl.rlim_max; |
| | | 1059 | (void)setrlimit(RLIMIT_NOFILE, &rl); |
| | | 1060 | } |
| | | 1061 | #endif |
| | | 1062 | } |
| | | 1063 | |
1050 | /*- | | 1064 | /*- |
1051 | * main -- | | 1065 | * main -- |
1052 | * The main function, for obvious reasons. Initializes variables | | 1066 | * The main function, for obvious reasons. Initializes variables |
1053 | * and a few modules, then parses the arguments give it in the | | 1067 | * and a few modules, then parses the arguments give it in the |
1054 | * environment and on the command line. Reads the system makefile | | 1068 | * environment and on the command line. Reads the system makefile |
1055 | * followed by either Makefile, makefile or the file given by the | | 1069 | * followed by either Makefile, makefile or the file given by the |
1056 | * -f argument. Sets the .MAKEFLAGS PMake variable based on all the | | 1070 | * -f argument. Sets the .MAKEFLAGS PMake variable based on all the |
1057 | * flags it has received by then uses either the Make or the Compat | | 1071 | * flags it has received by then uses either the Make or the Compat |
1058 | * module to create the initial list of targets. | | 1072 | * module to create the initial list of targets. |
1059 | * | | 1073 | * |
1060 | * Results: | | 1074 | * Results: |
1061 | * If -q was given, exits -1 if anything was out-of-date. Else it exits | | 1075 | * If -q was given, exits -1 if anything was out-of-date. Else it exits |
1062 | * 0. | | 1076 | * 0. |
| @@ -1088,39 +1102,28 @@ main(int argc, char **argv) | | | @@ -1088,39 +1102,28 @@ main(int argc, char **argv) |
1088 | (void)bmake_signal(SIGINFO, siginfo); | | 1102 | (void)bmake_signal(SIGINFO, siginfo); |
1089 | #endif | | 1103 | #endif |
1090 | /* | | 1104 | /* |
1091 | * Set the seed to produce a different random sequence | | 1105 | * Set the seed to produce a different random sequence |
1092 | * on each program execution. | | 1106 | * on each program execution. |
1093 | */ | | 1107 | */ |
1094 | gettimeofday(&rightnow, NULL); | | 1108 | gettimeofday(&rightnow, NULL); |
1095 | srandom((unsigned int)(rightnow.tv_sec + rightnow.tv_usec)); | | 1109 | srandom((unsigned int)(rightnow.tv_sec + rightnow.tv_usec)); |
1096 | | | 1110 | |
1097 | if ((progname = strrchr(argv[0], '/')) != NULL) | | 1111 | if ((progname = strrchr(argv[0], '/')) != NULL) |
1098 | progname++; | | 1112 | progname++; |
1099 | else | | 1113 | else |
1100 | progname = argv[0]; | | 1114 | progname = argv[0]; |
1101 | #if defined(MAKE_NATIVE) || (defined(HAVE_SETRLIMIT) && defined(RLIMIT_NOFILE)) | | 1115 | |
1102 | /* | | 1116 | UnlimitFiles(); |
1103 | * get rid of resource limit on file descriptors | | | |
1104 | */ | | | |
1105 | { | | | |
1106 | struct rlimit rl; | | | |
1107 | if (getrlimit(RLIMIT_NOFILE, &rl) != -1 && | | | |
1108 | rl.rlim_cur != rl.rlim_max) { | | | |
1109 | rl.rlim_cur = rl.rlim_max; | | | |
1110 | (void)setrlimit(RLIMIT_NOFILE, &rl); | | | |
1111 | } | | | |
1112 | } | | | |
1113 | #endif | | | |
1114 | | | 1117 | |
1115 | if (uname(&utsname) == -1) { | | 1118 | if (uname(&utsname) == -1) { |
1116 | (void)fprintf(stderr, "%s: uname failed (%s).\n", progname, | | 1119 | (void)fprintf(stderr, "%s: uname failed (%s).\n", progname, |
1117 | strerror(errno)); | | 1120 | strerror(errno)); |
1118 | exit(2); | | 1121 | exit(2); |
1119 | } | | 1122 | } |
1120 | | | 1123 | |
1121 | /* | | 1124 | /* |
1122 | * Get the name of this type of MACHINE from utsname | | 1125 | * Get the name of this type of MACHINE from utsname |
1123 | * so we can share an executable for similar machines. | | 1126 | * so we can share an executable for similar machines. |
1124 | * (i.e. m68k: amiga hp300, mac68k, sun3, ...) | | 1127 | * (i.e. m68k: amiga hp300, mac68k, sun3, ...) |
1125 | * | | 1128 | * |
1126 | * Note that both MACHINE and MACHINE_ARCH are decided at | | 1129 | * Note that both MACHINE and MACHINE_ARCH are decided at |