24 */
25
26 #ifdef TEAMWARE_MAKE_CMN
27
28 /*
29 * parallel.cc
30 *
31 * Deal with the parallel processing
32 */
33
34 /*
35 * Included files
36 */
37 #ifdef DISTRIBUTED
38 #include <avo/strings.h> /* AVO_STRDUP() */
39 #include <dm/Avo_DoJobMsg.h>
40 #include <dm/Avo_MToolJobResultMsg.h>
41 #endif
42 #include <errno.h> /* errno */
43 #include <fcntl.h>
44 #include <avo/util.h> /* avo_get_user(), avo_hostname() */
45 #include <mk/defs.h>
46 #include <mksh/dosys.h> /* redirect_io() */
47 #include <mksh/macro.h> /* expand_value() */
48 #include <mksh/misc.h> /* getmem() */
49 #include <sys/signal.h>
50 #include <sys/stat.h>
51 #include <sys/types.h>
52 #include <sys/utsname.h>
53 #include <sys/wait.h>
54 #include <unistd.h>
55
56
57
58 /*
59 * Defined macros
60 */
61 #define MAXRULES 100
62
63 /*
64 * This const should be in avo_dms/include/AvoDmakeCommand.h
65 */
66 const int local_host_mask = 0x20;
67
68
69 /*
70 * typedefs & structs
71 */
72
73
74 /*
128 int cmd_options = 0;
129 char *commands[MAXRULES + 5];
130 char *cp;
131 #ifdef DISTRIBUTED
132 Avo_DoJobMsg *dmake_job_msg = NULL;
133 #endif
134 Name dmake_name;
135 Name dmake_value;
136 int ignore;
137 Name make_machines_name;
138 char **p;
139 Property prop;
140 Doname result = build_ok;
141 Cmd_line rule;
142 Boolean silent_flag;
143 Name target = line->body.line.target;
144 Boolean wrote_state_file = false;
145
146 if ((pmake_max_jobs == 0) &&
147 (dmake_mode_type == parallel_mode)) {
148 if (user_name[0] == '\0') {
149 avo_get_user(user_name, NULL);
150 }
151 if (local_host[0] == '\0') {
152 strcpy(local_host, avo_hostname());
153 }
154 MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_MAX_JOBS"));
155 dmake_name = GETNAME(wcs_buffer, FIND_LENGTH);
156 if (((prop = get_prop(dmake_name->prop, macro_prop)) != NULL) &&
157 ((dmake_value = prop->body.macro.value) != NULL)) {
158 pmake_max_jobs = atoi(dmake_value->string_mb);
159 if (pmake_max_jobs <= 0) {
160 warning(catgets(catd, 1, 308, "DMAKE_MAX_JOBS cannot be less than or equal to zero."));
161 warning(catgets(catd, 1, 309, "setting DMAKE_MAX_JOBS to %d."), PMAKE_DEF_MAX_JOBS);
162 pmake_max_jobs = PMAKE_DEF_MAX_JOBS;
163 }
164 } else {
165 /*
166 * For backwards compatibility w/ PMake 1.x, when
167 * DMake 2.x is being run in parallel mode, DMake
168 * should parse the PMake startup file
169 * $(HOME)/.make.machines to get the pmake_max_jobs.
170 */
171 MBSTOWCS(wcs_buffer, NOCATGETS("PMAKE_MACHINESFILE"));
172 dmake_name = GETNAME(wcs_buffer, FIND_LENGTH);
652 *
653 * Environment:
654 * DMAKE_ADJUST_MAX_JOBS
655 *
656 * External functions:
657 * putenv()
658 *
659 * Static variables:
660 * job_adjust_mode Current job adjust mode
661 */
662 static void
663 job_adjust_error() {
664 if (job_adjust_mode != ADJUST_NONE) {
665 /* cleanup internals */
666 job_adjust_fini();
667
668 /* warning message for the user */
669 warning(catgets(catd, 1, 339, "Encountered max jobs auto adjustment error - disabling auto adjustment."));
670
671 /* switch off job adjustment for the children */
672 putenv(NOCATGETS("DMAKE_ADJUST_MAX_JOBS=NO"));
673
674 /* and for this dmake */
675 job_adjust_mode = ADJUST_NONE;
676 }
677 }
678
679 /*
680 * void job_adjust_init()
681 *
682 * Description:
683 * Parses DMAKE_ADJUST_MAX_JOBS env variable
684 * and performs appropriate initializations.
685 *
686 * Environment:
687 * DMAKE_ADJUST_MAX_JOBS
688 * DMAKE_ADJUST_MAX_JOBS == "NO" - no adjustment
689 * DMAKE_ADJUST_MAX_JOBS == "M2" - M2 adjust mode
690 * other - M1 adjust mode
691 *
692 * External functions:
1719 * process_running PID of process
1720 *
1721 * Global variables used:
1722 * current_line Current line for target
1723 * current_target Current target being built
1724 * stderr_file Temporary file for stdout
1725 * stdout_file Temporary file for stdout
1726 * temp_file_name Temporary file for auto dependencies
1727 */
1728 void
1729 add_running(Name target, Name true_target, Property command, int recursion_level, int auto_count, Name *automatics, Boolean do_get, Boolean implicit)
1730 {
1731 Running rp;
1732 Name *p;
1733
1734 rp = new_running_struct();
1735 rp->state = build_running;
1736 rp->target = target;
1737 rp->true_target = true_target;
1738 rp->command = command;
1739 Property spro_val = get_prop(sunpro_dependencies->prop, macro_prop);
1740 if(spro_val) {
1741 rp->sprodep_value = spro_val->body.macro.value;
1742 spro_val->body.macro.value = NULL;
1743 spro_val = get_prop(sunpro_dependencies->prop, env_mem_prop);
1744 if(spro_val) {
1745 rp->sprodep_env = spro_val->body.env_mem.value;
1746 spro_val->body.env_mem.value = NULL;
1747 }
1748 }
1749 rp->recursion_level = recursion_level;
1750 rp->do_get = do_get;
1751 rp->implicit = implicit;
1752 rp->auto_count = auto_count;
1753 if (auto_count > 0) {
1754 rp->automatics = (Name *) getmem(auto_count * sizeof (Name));
1755 for (p = rp->automatics; auto_count > 0; auto_count--) {
1756 *p++ = *automatics++;
1757 }
1758 } else {
1759 rp->automatics = NULL;
1760 }
1761 #ifdef DISTRIBUTED
1762 if (dmake_mode_type == distributed_mode) {
1763 rp->make_refd = called_make;
1764 called_make = false;
1765 } else
1766 #endif
1767 {
1768 rp->pid = process_running;
|
24 */
25
26 #ifdef TEAMWARE_MAKE_CMN
27
28 /*
29 * parallel.cc
30 *
31 * Deal with the parallel processing
32 */
33
34 /*
35 * Included files
36 */
37 #ifdef DISTRIBUTED
38 #include <avo/strings.h> /* AVO_STRDUP() */
39 #include <dm/Avo_DoJobMsg.h>
40 #include <dm/Avo_MToolJobResultMsg.h>
41 #endif
42 #include <errno.h> /* errno */
43 #include <fcntl.h>
44 #include <mk/defs.h>
45 #include <mksh/dosys.h> /* redirect_io() */
46 #include <mksh/macro.h> /* expand_value() */
47 #include <mksh/misc.h> /* getmem() */
48 #include <sys/signal.h>
49 #include <sys/stat.h>
50 #include <sys/types.h>
51 #include <sys/utsname.h>
52 #include <sys/wait.h>
53 #include <unistd.h>
54 #include <netdb.h>
55
56
57
58 /*
59 * Defined macros
60 */
61 #define MAXRULES 100
62
63 /*
64 * This const should be in avo_dms/include/AvoDmakeCommand.h
65 */
66 const int local_host_mask = 0x20;
67
68
69 /*
70 * typedefs & structs
71 */
72
73
74 /*
128 int cmd_options = 0;
129 char *commands[MAXRULES + 5];
130 char *cp;
131 #ifdef DISTRIBUTED
132 Avo_DoJobMsg *dmake_job_msg = NULL;
133 #endif
134 Name dmake_name;
135 Name dmake_value;
136 int ignore;
137 Name make_machines_name;
138 char **p;
139 Property prop;
140 Doname result = build_ok;
141 Cmd_line rule;
142 Boolean silent_flag;
143 Name target = line->body.line.target;
144 Boolean wrote_state_file = false;
145
146 if ((pmake_max_jobs == 0) &&
147 (dmake_mode_type == parallel_mode)) {
148 if (local_host[0] == '\0') {
149 (void) gethostname(local_host, MAXNAMELEN);
150 }
151 MBSTOWCS(wcs_buffer, NOCATGETS("DMAKE_MAX_JOBS"));
152 dmake_name = GETNAME(wcs_buffer, FIND_LENGTH);
153 if (((prop = get_prop(dmake_name->prop, macro_prop)) != NULL) &&
154 ((dmake_value = prop->body.macro.value) != NULL)) {
155 pmake_max_jobs = atoi(dmake_value->string_mb);
156 if (pmake_max_jobs <= 0) {
157 warning(catgets(catd, 1, 308, "DMAKE_MAX_JOBS cannot be less than or equal to zero."));
158 warning(catgets(catd, 1, 309, "setting DMAKE_MAX_JOBS to %d."), PMAKE_DEF_MAX_JOBS);
159 pmake_max_jobs = PMAKE_DEF_MAX_JOBS;
160 }
161 } else {
162 /*
163 * For backwards compatibility w/ PMake 1.x, when
164 * DMake 2.x is being run in parallel mode, DMake
165 * should parse the PMake startup file
166 * $(HOME)/.make.machines to get the pmake_max_jobs.
167 */
168 MBSTOWCS(wcs_buffer, NOCATGETS("PMAKE_MACHINESFILE"));
169 dmake_name = GETNAME(wcs_buffer, FIND_LENGTH);
649 *
650 * Environment:
651 * DMAKE_ADJUST_MAX_JOBS
652 *
653 * External functions:
654 * putenv()
655 *
656 * Static variables:
657 * job_adjust_mode Current job adjust mode
658 */
659 static void
660 job_adjust_error() {
661 if (job_adjust_mode != ADJUST_NONE) {
662 /* cleanup internals */
663 job_adjust_fini();
664
665 /* warning message for the user */
666 warning(catgets(catd, 1, 339, "Encountered max jobs auto adjustment error - disabling auto adjustment."));
667
668 /* switch off job adjustment for the children */
669 putenv(strdup(NOCATGETS("DMAKE_ADJUST_MAX_JOBS=NO")));
670
671 /* and for this dmake */
672 job_adjust_mode = ADJUST_NONE;
673 }
674 }
675
676 /*
677 * void job_adjust_init()
678 *
679 * Description:
680 * Parses DMAKE_ADJUST_MAX_JOBS env variable
681 * and performs appropriate initializations.
682 *
683 * Environment:
684 * DMAKE_ADJUST_MAX_JOBS
685 * DMAKE_ADJUST_MAX_JOBS == "NO" - no adjustment
686 * DMAKE_ADJUST_MAX_JOBS == "M2" - M2 adjust mode
687 * other - M1 adjust mode
688 *
689 * External functions:
1716 * process_running PID of process
1717 *
1718 * Global variables used:
1719 * current_line Current line for target
1720 * current_target Current target being built
1721 * stderr_file Temporary file for stdout
1722 * stdout_file Temporary file for stdout
1723 * temp_file_name Temporary file for auto dependencies
1724 */
1725 void
1726 add_running(Name target, Name true_target, Property command, int recursion_level, int auto_count, Name *automatics, Boolean do_get, Boolean implicit)
1727 {
1728 Running rp;
1729 Name *p;
1730
1731 rp = new_running_struct();
1732 rp->state = build_running;
1733 rp->target = target;
1734 rp->true_target = true_target;
1735 rp->command = command;
1736 rp->recursion_level = recursion_level;
1737 rp->do_get = do_get;
1738 rp->implicit = implicit;
1739 rp->auto_count = auto_count;
1740 if (auto_count > 0) {
1741 rp->automatics = (Name *) getmem(auto_count * sizeof (Name));
1742 for (p = rp->automatics; auto_count > 0; auto_count--) {
1743 *p++ = *automatics++;
1744 }
1745 } else {
1746 rp->automatics = NULL;
1747 }
1748 #ifdef DISTRIBUTED
1749 if (dmake_mode_type == distributed_mode) {
1750 rp->make_refd = called_make;
1751 called_make = false;
1752 } else
1753 #endif
1754 {
1755 rp->pid = process_running;
|