19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26
27 /*
28 * dosys.cc
29 *
30 * Execute one commandline
31 */
32
33 /*
34 * Included files
35 */
36 #include <sys/wait.h> /* WIFEXITED(status) */
37 #include <alloca.h> /* alloca() */
38
39 #if defined(TEAMWARE_MAKE_CMN) || defined(MAKETOOL) /* tolik */
40 #if defined(DISTRIBUTED)
41 # include <dm/Avo_CmdOutput.h>
42 # include <rw/xdrstrea.h>
43 #endif
44 #endif
45
46 #include <stdio.h> /* errno */
47 #include <errno.h> /* errno */
48 #include <fcntl.h> /* open() */
49 #include <mksh/dosys.h>
50 #include <mksh/macro.h> /* getvar() */
51 #include <mksh/misc.h> /* getmem(), fatal_mksh(), errmsg() */
52 #include <mksdmsi18n/mksdmsi18n.h> /* libmksdmsi18n_init() */
53 #include <sys/signal.h> /* SIG_DFL */
54 #include <sys/stat.h> /* open() */
55 #include <sys/wait.h> /* wait() */
56 #include <ulimit.h> /* ulimit() */
57 #include <unistd.h> /* close(), dup2() */
58
59
60
61 /*
62 * Defined macros
63 */
64 #if defined(DISTRIBUTED) || defined(MAKETOOL) /* tolik */
65 #define SEND_MTOOL_MSG(cmds) \
66 if (send_mtool_msgs) { \
67 cmds \
68 }
69 #else
70 #define SEND_MTOOL_MSG(cmds)
71 #endif
72
73 /*
74 * typedefs & structs
75 */
76
77 /*
78 * Static variables
79 */
80
81 /*
82 * File table of contents
83 */
84 static Boolean exec_vp(register char *name, register char **argv, char **envp, register Boolean ignore_error, pathpt vroot_path);
85
86 /*
87 * Workaround for NFS bug. Sometimes, when running 'open' on a remote
88 * dmake server, it fails with "Stale NFS file handle" error.
89 * The second attempt seems to work.
90 */
91 int
555 * Wait for one child process and analyzes
556 * the returned status when the child process terminates.
557 *
558 * Return value:
559 * Returns true if commands ran OK
560 *
561 * Parameters:
562 * ignore_error Should we abort on error?
563 * silent_error Should error messages be suppressed for dmake?
564 * target The target we are building, for error msgs
565 * command The command we ran, for error msgs
566 * running_pid The pid of the process we are waiting for
567 *
568 * Static variables used:
569 * filter_file The fd for the filter file
570 * filter_file_name The name of the filter file
571 *
572 * Global variables used:
573 * filter_stderr Set if -X is on
574 */
575 #if defined(DISTRIBUTED) || defined(MAKETOOL) /* tolik */
576 Boolean
577 await(register Boolean ignore_error, register Boolean silent_error, Name target, wchar_t *command, pid_t running_pid, Boolean send_mtool_msgs, XDR *xdrs_p, int job_msg_id)
578 #else
579 Boolean
580 await(register Boolean ignore_error, register Boolean silent_error, Name target, wchar_t *command, pid_t running_pid, Boolean send_mtool_msgs, void *xdrs_p, int job_msg_id)
581 #endif
582 {
583 int status;
584 char *buffer;
585 int core_dumped;
586 int exit_status;
587 #if defined(DISTRIBUTED) || defined(MAKETOOL) /* tolik */
588 Avo_CmdOutput *make_output_msg;
589 #endif
590 FILE *outfp;
591 register pid_t pid;
592 struct stat stat_buff;
593 int termination_signal;
594 char tmp_buf[MAXPATHLEN];
595 #if defined(DISTRIBUTED) || defined(MAKETOOL) /* tolik */
596 RWCollectable *xdr_msg;
597 #endif
598
599 while ((pid = wait(&status)) != running_pid) {
600 if (pid == -1) {
601 fatal_mksh(catgets(libmksdmsi18n_catd, 1, 98, "wait() failed: %s"), errmsg(errno));
602 }
603 }
604 (void) fflush(stdout);
605 (void) fflush(stderr);
606
607 if (status == 0) {
608
609 #ifdef PRINT_EXIT_STATUS
610 warning_mksh(NOCATGETS("I'm in await(), and status is 0."));
611 #endif
612
613 return succeeded;
614 }
615
616 #ifdef PRINT_EXIT_STATUS
617 warning_mksh(NOCATGETS("I'm in await(), and status is *NOT* 0."));
|
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26
27 /*
28 * dosys.cc
29 *
30 * Execute one commandline
31 */
32
33 /*
34 * Included files
35 */
36 #include <sys/wait.h> /* WIFEXITED(status) */
37 #include <alloca.h> /* alloca() */
38
39 #include <stdio.h> /* errno */
40 #include <errno.h> /* errno */
41 #include <fcntl.h> /* open() */
42 #include <mksh/dosys.h>
43 #include <mksh/macro.h> /* getvar() */
44 #include <mksh/misc.h> /* getmem(), fatal_mksh(), errmsg() */
45 #include <mksdmsi18n/mksdmsi18n.h> /* libmksdmsi18n_init() */
46 #include <sys/signal.h> /* SIG_DFL */
47 #include <sys/stat.h> /* open() */
48 #include <sys/wait.h> /* wait() */
49 #include <ulimit.h> /* ulimit() */
50 #include <unistd.h> /* close(), dup2() */
51
52
53
54 /*
55 * Defined macros
56 */
57 #define SEND_MTOOL_MSG(cmds)
58
59 /*
60 * typedefs & structs
61 */
62
63 /*
64 * Static variables
65 */
66
67 /*
68 * File table of contents
69 */
70 static Boolean exec_vp(register char *name, register char **argv, char **envp, register Boolean ignore_error, pathpt vroot_path);
71
72 /*
73 * Workaround for NFS bug. Sometimes, when running 'open' on a remote
74 * dmake server, it fails with "Stale NFS file handle" error.
75 * The second attempt seems to work.
76 */
77 int
541 * Wait for one child process and analyzes
542 * the returned status when the child process terminates.
543 *
544 * Return value:
545 * Returns true if commands ran OK
546 *
547 * Parameters:
548 * ignore_error Should we abort on error?
549 * silent_error Should error messages be suppressed for dmake?
550 * target The target we are building, for error msgs
551 * command The command we ran, for error msgs
552 * running_pid The pid of the process we are waiting for
553 *
554 * Static variables used:
555 * filter_file The fd for the filter file
556 * filter_file_name The name of the filter file
557 *
558 * Global variables used:
559 * filter_stderr Set if -X is on
560 */
561 Boolean
562 await(register Boolean ignore_error, register Boolean silent_error, Name target, wchar_t *command, pid_t running_pid, Boolean send_mtool_msgs, void *xdrs_p, int job_msg_id)
563 {
564 int status;
565 char *buffer;
566 int core_dumped;
567 int exit_status;
568 FILE *outfp;
569 register pid_t pid;
570 struct stat stat_buff;
571 int termination_signal;
572 char tmp_buf[MAXPATHLEN];
573
574 while ((pid = wait(&status)) != running_pid) {
575 if (pid == -1) {
576 fatal_mksh(catgets(libmksdmsi18n_catd, 1, 98, "wait() failed: %s"), errmsg(errno));
577 }
578 }
579 (void) fflush(stdout);
580 (void) fflush(stderr);
581
582 if (status == 0) {
583
584 #ifdef PRINT_EXIT_STATUS
585 warning_mksh(NOCATGETS("I'm in await(), and status is 0."));
586 #endif
587
588 return succeeded;
589 }
590
591 #ifdef PRINT_EXIT_STATUS
592 warning_mksh(NOCATGETS("I'm in await(), and status is *NOT* 0."));
|