3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * @(#)eval.c 8.9 (Berkeley) 6/8/95
37 * $FreeBSD: src/bin/sh/eval.c,v 1.108 2011/06/09 23:12:23 jilles Exp $
41 #include <sys/resource.h>
42 #include <sys/wait.h> /* For WIFSIGNALED(status) */
74 #include "myhistedit.h"
78 int evalskip; /* set if we are skipping commands */
79 static int skipcount; /* number of levels to skip */
80 MKINIT int loopnest; /* current loop nesting level */
81 int funcnest; /* depth of function calls */
82 static int builtin_flags; /* evalcommand flags for builtins */
85 const char *commandname;
86 struct strlist *cmdenviron;
87 int exitstatus; /* exit status of last command */
88 int oexitstatus; /* saved exit status */
91 static void evalloop(union node *, int);
92 static void evalfor(union node *, int);
93 static void evalcase(union node *, int);
94 static void evalsubshell(union node *, int);
95 static void evalredir(union node *, int);
96 static void expredir(union node *);
97 static void evalpipe(union node *);
98 static int is_valid_fast_cmdsubst(union node *n);
99 static void evalcommand(union node *, int, struct backcmd *);
100 static void prehash(union node *);
104 * Called to reset things after an exception.
124 evalcmd(int argc, char **argv)
133 STARTSTACKSTR(concat);
137 if ((p = *ap++) == NULL)
141 STPUTC('\0', concat);
142 p = grabstackstr(concat);
144 evalstring(p, builtin_flags & EV_TESTED);
152 * Execute a command or commands contained in a string.
156 evalstring(char *s, int flags)
159 struct stackmark smark;
163 flags_exit = flags & EV_EXIT;
166 setstackmark(&smark);
167 setinputstring(s, 1);
168 while ((n = parsecmd(0)) != NEOF) {
169 if (n != NULL && !nflag) {
170 if (flags_exit && preadateof())
171 evaltree(n, flags | EV_EXIT);
176 popstackmark(&smark);
179 popstackmark(&smark);
188 * Evaluate a parse tree. The value is left in the global variable
193 evaltree(union node *n, int flags)
200 TRACE(("evaltree(NULL) called\n"));
207 displayhist = 1; /* show history substitutions done with fc */
209 TRACE(("evaltree(%p: %d) called\n", (void *)n, n->type));
212 evaltree(n->nbinary.ch1, flags & ~EV_EXIT);
215 next = n->nbinary.ch2;
218 evaltree(n->nbinary.ch1, EV_TESTED);
219 if (evalskip || exitstatus != 0) {
222 next = n->nbinary.ch2;
225 evaltree(n->nbinary.ch1, EV_TESTED);
226 if (evalskip || exitstatus == 0)
228 next = n->nbinary.ch2;
234 evalsubshell(n, flags);
235 do_etest = !(flags & EV_TESTED);
238 evalsubshell(n, flags);
241 evaltree(n->nif.test, EV_TESTED);
245 next = n->nif.ifpart;
246 else if (n->nif.elsepart)
247 next = n->nif.elsepart;
254 evalloop(n, flags & ~EV_EXIT);
257 evalfor(n, flags & ~EV_EXIT);
263 defun(n->narg.text, n->narg.next);
267 evaltree(n->nnot.com, EV_TESTED);
268 exitstatus = !exitstatus;
273 do_etest = !(flags & EV_TESTED);
276 evalcommand(n, flags, NULL);
277 do_etest = !(flags & EV_TESTED);
280 out1fmt("Node type = %d\n", n->type);
289 if (eflag && exitstatus != 0 && do_etest)
290 exitshell(exitstatus);
297 evalloop(union node *n, int flags)
304 evaltree(n->nbinary.ch1, EV_TESTED);
306 skipping: if (evalskip == SKIPCONT && --skipcount <= 0) {
310 if (evalskip == SKIPBREAK && --skipcount <= 0)
312 if (evalskip == SKIPFUNC || evalskip == SKIPFILE)
316 if (n->type == NWHILE) {
323 evaltree(n->nbinary.ch2, flags);
335 evalfor(union node *n, int flags)
337 struct arglist arglist;
340 struct stackmark smark;
342 setstackmark(&smark);
343 arglist.lastp = &arglist.list;
344 for (argp = n->nfor.args ; argp ; argp = argp->narg.next) {
345 oexitstatus = exitstatus;
346 expandarg(argp, &arglist, EXP_FULL | EXP_TILDE);
350 *arglist.lastp = NULL;
354 for (sp = arglist.list ; sp ; sp = sp->next) {
355 setvar(n->nfor.var, sp->text, 0);
356 evaltree(n->nfor.body, flags);
358 if (evalskip == SKIPCONT && --skipcount <= 0) {
362 if (evalskip == SKIPBREAK && --skipcount <= 0)
369 popstackmark(&smark);
375 evalcase(union node *n, int flags)
379 struct arglist arglist;
380 struct stackmark smark;
382 setstackmark(&smark);
383 arglist.lastp = &arglist.list;
384 oexitstatus = exitstatus;
386 expandarg(n->ncase.expr, &arglist, EXP_TILDE);
387 for (cp = n->ncase.cases ; cp && evalskip == 0 ; cp = cp->nclist.next) {
388 for (patp = cp->nclist.pattern ; patp ; patp = patp->narg.next) {
389 if (casematch(patp, arglist.list->text)) {
391 evaltree(cp->nclist.body, flags);
398 popstackmark(&smark);
404 * Kick off a subshell to evaluate a tree.
408 evalsubshell(union node *n, int flags)
411 int backgnd = (n->type == NBACKGND);
413 oexitstatus = exitstatus;
414 expredir(n->nredir.redirect);
415 if ((!backgnd && flags & EV_EXIT && !have_traps()) ||
416 forkshell(jp = makejob(n, 1), n, backgnd) == 0) {
419 redirect(n->nredir.redirect, 0);
420 evaltree(n->nredir.n, flags | EV_EXIT); /* never returns */
421 } else if (!backgnd) {
423 exitstatus = waitforjob(jp, NULL);
431 * Evaluate a redirected compound command.
435 evalredir(union node *n, int flags)
437 struct jmploc jmploc;
438 struct jmploc *savehandler;
439 volatile int in_redirect = 1;
441 oexitstatus = exitstatus;
442 expredir(n->nredir.redirect);
443 savehandler = handler;
444 if (setjmp(jmploc.loc)) {
447 handler = savehandler;
450 if (e == EXERROR || e == EXEXEC) {
456 longjmp(handler->loc, 1);
460 redirect(n->nredir.redirect, REDIR_PUSH);
463 evaltree(n->nredir.n, flags);
466 handler = savehandler;
473 * Compute the names of the files in a redirection list.
477 expredir(union node *n)
481 for (redir = n ; redir ; redir = redir->nfile.next) {
484 switch (redir->type) {
490 expandarg(redir->nfile.fname, &fn, EXP_TILDE | EXP_REDIR);
491 redir->nfile.expfname = fn.list->text;
495 if (redir->ndup.vname) {
496 expandarg(redir->ndup.vname, &fn, EXP_TILDE | EXP_REDIR);
497 fixredir(redir, fn.list->text, 1);
507 * Evaluate a pipeline. All the processes in the pipeline are children
508 * of the process creating the pipeline. (This differs from some versions
509 * of the shell, which make the last process in a pipeline the parent
514 evalpipe(union node *n)
522 TRACE(("evalpipe(%p) called\n", (void *)n));
524 for (lp = n->npipe.cmdlist ; lp ; lp = lp->next)
527 jp = makejob(n, pipelen);
529 for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) {
536 error("Pipe call failed: %s", strerror(errno));
539 if (forkshell(jp, lp->n, n->npipe.backgnd) == 0) {
546 if (!(prevfd >= 0 && pip[0] == 0))
553 evaltree(lp->n, EV_EXIT);
562 if (n->npipe.backgnd == 0) {
564 exitstatus = waitforjob(jp, NULL);
565 TRACE(("evalpipe: job done exit status %d\n", exitstatus));
574 is_valid_fast_cmdsubst(union node *n)
580 for (argp = n->ncmd.args ; argp ; argp = argp->narg.next)
581 if (expandhassideeffects(argp->narg.text))
587 * Execute a command inside back quotes. If it's a builtin command, we
588 * want to save its output in a block obtained from malloc. Otherwise
589 * we fork off a subprocess and get the output of the command via a pipe.
590 * Should be called with interrupts off.
594 evalbackcmd(union node *n, struct backcmd *result)
598 struct stackmark smark; /* unnecessary */
599 struct jmploc jmploc;
600 struct jmploc *savehandler;
602 setstackmark(&smark);
611 if (is_valid_fast_cmdsubst(n)) {
612 exitstatus = oexitstatus;
613 savehandler = handler;
614 if (setjmp(jmploc.loc)) {
615 if (exception == EXERROR || exception == EXEXEC)
617 else if (exception != 0) {
618 handler = savehandler;
619 longjmp(handler->loc, 1);
623 evalcommand(n, EV_BACKCMD, result);
625 handler = savehandler;
629 error("Pipe call failed: %s", strerror(errno));
631 if (forkshell(jp, n, FORK_NOJOB) == 0) {
638 evaltree(n, EV_EXIT);
645 popstackmark(&smark);
646 TRACE(("evalbackcmd done: fd=%d buf=%p nleft=%d jp=%p\n",
647 result->fd, result->buf, result->nleft, result->jp));
651 * Check if a builtin can safely be executed in the same process,
652 * even though it should be in a subshell (command substitution).
653 * Note that jobid, jobs, times and trap can show information not
654 * available in a child process; this is deliberate.
655 * The arguments should already have been expanded.
658 safe_builtin(int idx, int argc, char **argv)
660 if (idx == BLTINCMD || idx == COMMANDCMD || idx == ECHOCMD ||
661 idx == FALSECMD || idx == JOBIDCMD || idx == JOBSCMD ||
662 idx == KILLCMD || idx == PRINTFCMD || idx == PWDCMD ||
663 idx == TESTCMD || idx == TIMESCMD || idx == TRUECMD ||
666 if (idx == EXPORTCMD || idx == TRAPCMD || idx == ULIMITCMD ||
668 return (argc <= 1 || (argc == 2 && argv[1][0] == '-'));
670 return (argc <= 1 || (argc == 2 && (argv[1][0] == '-' ||
671 argv[1][0] == '+') && argv[1][1] == 'o' &&
672 argv[1][2] == '\0'));
677 * Execute a simple command.
678 * Note: This may or may not return if (flags & EV_EXIT).
682 evalcommand(union node *cmd, int flgs, struct backcmd *backcmd)
684 struct stackmark smark;
686 struct arglist arglist;
687 struct arglist varlist;
688 volatile int flags = flgs;
689 char **volatile argv;
696 struct cmdentry cmdentry;
697 struct job *volatile jp;
698 struct jmploc jmploc;
699 struct jmploc *savehandler;
700 const char *savecmdname;
701 struct shparam saveparam;
702 struct localvar *savelocalvars;
703 struct parsefile *savetopfile;
705 char *volatile lastarg;
707 volatile int do_clearcmdentry;
708 const char *path = pathval();
710 /* First expand the arguments. */
711 TRACE(("evalcommand(%p, %d) called\n", (void *)cmd, flags));
712 setstackmark(&smark);
713 arglist.lastp = &arglist.list;
714 varlist.lastp = &varlist.list;
717 do_clearcmdentry = 0;
718 oexitstatus = exitstatus;
720 for (argp = cmd->ncmd.args ; argp ; argp = argp->narg.next) {
721 if (varflag && isassignment(argp->narg.text)) {
722 expandarg(argp, &varlist, EXP_VARTILDE);
725 expandarg(argp, &arglist, EXP_FULL | EXP_TILDE);
728 *arglist.lastp = NULL;
729 *varlist.lastp = NULL;
730 expredir(cmd->ncmd.redirect);
732 for (sp = arglist.list ; sp ; sp = sp->next)
734 /* Add one slot at the beginning for tryexec(). */
735 argv = stalloc(sizeof (char *) * (argc + 2));
738 for (sp = arglist.list ; sp ; sp = sp->next) {
739 TRACE(("evalcommand arg: %s\n", sp->text));
744 if (iflag && funcnest == 0 && argc > 0)
748 /* Print the command if xflag is set. */
752 ps4 = expandstr(ps4val());
753 out2str(ps4 != NULL ? ps4 : ps4val());
754 for (sp = varlist.list ; sp ; sp = sp->next) {
757 p = strchr(sp->text, '=');
760 outbin(sp->text, p - sp->text, out2);
766 for (sp = arglist.list ; sp ; sp = sp->next) {
769 /* Disambiguate command looking like assignment. */
770 if (sp == arglist.list &&
771 strchr(sp->text, '=') != NULL &&
772 strchr(sp->text, '\'') == NULL) {
784 /* Now locate the command. */
786 /* Variable assignment(s) without command */
787 cmdentry.cmdtype = CMDBUILTIN;
788 cmdentry.u.index = BLTINCMD;
789 cmdentry.special = 0;
791 static const char PATH[] = "PATH=";
792 int cmd_flags = 0, bltinonly = 0;
795 * Modify the command lookup path, if a PATH= assignment
798 for (sp = varlist.list ; sp ; sp = sp->next)
799 if (strncmp(sp->text, PATH, sizeof(PATH) - 1) == 0) {
800 path = sp->text + sizeof(PATH) - 1;
802 * On `PATH=... command`, we need to make
803 * sure that the command isn't using the
804 * non-updated hash table of the outer PATH
805 * setting and we need to make sure that
806 * the hash table isn't filled with items
807 * from the temporary setting.
809 * It would be better to forbit using and
810 * updating the table while this command
811 * runs, by the command finding mechanism
812 * is heavily integrated with hash handling,
813 * so we just delete the hash before and after
814 * the command runs. Partly deleting like
815 * changepatch() does doesn't seem worth the
816 * bookinging effort, since most such runs add
817 * directories in front of the new PATH.
820 do_clearcmdentry = 1;
825 cmdentry.u.index = find_builtin(*argv, &cmdentry.special);
826 if (cmdentry.u.index < 0) {
827 cmdentry.u.index = BLTINCMD;
833 find_command(argv[0], &cmdentry, cmd_flags, path);
834 /* implement the bltin and command builtins here */
835 if (cmdentry.cmdtype != CMDBUILTIN)
837 if (cmdentry.u.index == BLTINCMD) {
843 } else if (cmdentry.u.index == COMMANDCMD) {
846 if (!strcmp(argv[1], "-p")) {
849 if (argv[2][0] == '-') {
850 if (strcmp(argv[2], "--"))
860 path = _PATH_STDPATH;
862 do_clearcmdentry = 1;
863 } else if (!strcmp(argv[1], "--")) {
868 } else if (argv[1][0] == '-')
874 cmd_flags |= DO_NOFUNC;
880 * Special builtins lose their special properties when
881 * called via 'command'.
883 if (cmd_flags & DO_NOFUNC)
884 cmdentry.special = 0;
887 /* Fork off a child process if necessary. */
888 if (cmd->ncmd.backgnd
889 || ((cmdentry.cmdtype == CMDNORMAL || cmdentry.cmdtype == CMDUNKNOWN)
890 && ((flags & EV_EXIT) == 0 || have_traps()))
891 || ((flags & EV_BACKCMD) != 0
892 && (cmdentry.cmdtype != CMDBUILTIN ||
893 !safe_builtin(cmdentry.u.index, argc, argv)))) {
894 jp = makejob(cmd, 1);
895 mode = cmd->ncmd.backgnd;
896 if (flags & EV_BACKCMD) {
899 error("Pipe call failed: %s", strerror(errno));
901 if (forkshell(jp, cmd, mode) != 0)
902 goto parent; /* at end of routine */
903 if (flags & EV_BACKCMD) {
914 /* This is the child process if a fork occurred. */
915 /* Execute the command. */
916 if (cmdentry.cmdtype == CMDFUNCTION) {
918 trputs("Shell function: "); trargs(argv);
920 saveparam = shellparam;
921 shellparam.malloc = 0;
922 shellparam.reset = 1;
923 shellparam.nparam = argc - 1;
924 shellparam.p = argv + 1;
925 shellparam.optnext = NULL;
927 savelocalvars = localvars;
929 reffunc(cmdentry.u.func);
930 savehandler = handler;
931 if (setjmp(jmploc.loc)) {
932 freeparam(&shellparam);
933 shellparam = saveparam;
935 unreffunc(cmdentry.u.func);
937 localvars = savelocalvars;
939 handler = savehandler;
940 longjmp(handler->loc, 1);
944 redirect(cmd->ncmd.redirect, REDIR_PUSH);
946 for (sp = varlist.list ; sp ; sp = sp->next)
948 exitstatus = oexitstatus;
949 evaltree(getfuncnode(cmdentry.u.func),
950 flags & (EV_TESTED | EV_EXIT));
952 unreffunc(cmdentry.u.func);
954 localvars = savelocalvars;
955 freeparam(&shellparam);
956 shellparam = saveparam;
957 handler = savehandler;
961 if (evalskip == SKIPFUNC) {
966 exitshell(exitstatus);
967 } else if (cmdentry.cmdtype == CMDBUILTIN) {
969 trputs("builtin command: "); trargs(argv);
971 mode = (cmdentry.u.index == EXECCMD)? 0 : REDIR_PUSH;
972 if (flags == EV_BACKCMD) {
974 memout.nextc = memout.buf;
977 cmdentry.special = 0;
979 savecmdname = commandname;
980 savetopfile = getcurrentfile();
981 cmdenviron = varlist.list;
983 savehandler = handler;
984 if (setjmp(jmploc.loc)) {
987 exitstatus = SIGINT+128;
988 else if (e != EXEXIT)
993 redirect(cmd->ncmd.redirect, mode);
995 * If there is no command word, redirection errors should
996 * not be fatal but assignment errors should.
998 if (argc == 0 && !(flags & EV_BACKCMD))
999 cmdentry.special = 1;
1000 listsetvar(cmdenviron, cmdentry.special ? 0 : VNOSET);
1003 commandname = argv[0];
1005 nextopt_optptr = NULL; /* initialize nextopt */
1006 builtin_flags = flags;
1007 exitstatus = (*builtinfunc[cmdentry.u.index])(argc, argv);
1016 handler = savehandler;
1017 commandname = savecmdname;
1019 exitshell(exitstatus);
1020 if (flags == EV_BACKCMD) {
1021 backcmd->buf = memout.buf;
1022 backcmd->nleft = memout.nextc - memout.buf;
1025 if (cmdentry.u.index != EXECCMD)
1028 if ((e != EXERROR && e != EXEXEC)
1029 || cmdentry.special)
1031 popfilesupto(savetopfile);
1032 if (flags != EV_BACKCMD)
1037 trputs("normal command: "); trargs(argv);
1039 redirect(cmd->ncmd.redirect, 0);
1040 for (sp = varlist.list ; sp ; sp = sp->next)
1041 setvareq(sp->text, VEXPORT|VSTACK);
1042 envp = environment();
1043 shellexec(argv, envp, path, cmdentry.u.index);
1048 parent: /* parent process gets here (if we forked) */
1049 if (mode == FORK_FG) { /* argument to fork */
1051 exitstatus = waitforjob(jp, &realstatus);
1053 if (iflag && loopnest > 0 && WIFSIGNALED(realstatus)) {
1054 evalskip = SKIPBREAK;
1055 skipcount = loopnest;
1057 } else if (mode == FORK_NOJOB) {
1058 backcmd->fd = pip[0];
1066 setvar("_", lastarg, 0);
1067 if (do_clearcmdentry)
1069 popstackmark(&smark);
1075 * Search for a command. This is called before we fork so that the
1076 * location of the command will be available in the parent as well as
1077 * the child. The check for "goodname" is an overly conservative
1078 * check that the name will not be subject to expansion.
1082 prehash(union node *n)
1084 struct cmdentry entry;
1086 if (n && n->type == NCMD && n->ncmd.args)
1087 if (goodname(n->ncmd.args->narg.text))
1088 find_command(n->ncmd.args->narg.text, &entry, 0,
1095 * Builtin commands. Builtin commands whose functions are closely
1096 * tied to evaluation are implemented here.
1100 * No command given, a bltin command with no arguments, or a bltin command
1101 * with an invalid name.
1105 bltincmd(int argc, char **argv)
1108 out2fmt_flush("%s: not found\n", argv[1]);
1112 * Preserve exitstatus of a previous possible redirection
1120 * Handle break and continue commands. Break, continue, and return are
1121 * all handled by setting the evalskip flag. The evaluation routines
1122 * above all check this flag, and if it is set they start skipping
1123 * commands rather than executing them. The variable skipcount is
1124 * the number of loops to break/continue, or the number of function
1125 * levels to return. (The latter is always 1.) It should probably
1126 * be an error to break out of more loops than exist, but it isn't
1127 * in the standard shell so we don't make it one here.
1131 breakcmd(int argc, char **argv)
1133 int n = argc > 1 ? number(argv[1]) : 1;
1138 evalskip = (**argv == 'c')? SKIPCONT : SKIPBREAK;
1145 * The `command' command.
1148 commandcmd(int argc, char **argv)
1154 path = bltinlookup("PATH", 1);
1156 optind = optreset = 1;
1158 while ((ch = getopt(argc, argv, "pvV")) != -1) {
1161 path = _PATH_STDPATH;
1164 cmd = TYPECMD_SMALLV;
1171 error("unknown option: -%c", optopt);
1179 error("wrong number of arguments");
1180 return typecmd_impl(2, argv - 1, cmd, path);
1183 error("commandcmd bad call");
1186 * Do nothing successfully if no command was specified;
1187 * ksh also does this.
1194 * The return command.
1198 returncmd(int argc, char **argv)
1200 int ret = argc > 1 ? number(argv[1]) : oexitstatus;
1203 evalskip = SKIPFUNC;
1206 /* skip the rest of the file */
1207 evalskip = SKIPFILE;
1215 falsecmd(int argc __unused, char **argv __unused)
1222 truecmd(int argc __unused, char **argv __unused)
1229 execcmd(int argc, char **argv)
1232 * Because we have historically not supported any options,
1233 * only treat "--" specially.
1235 if (argc > 1 && strcmp(argv[1], "--") == 0)
1240 iflag = 0; /* exit on error */
1243 for (sp = cmdenviron; sp ; sp = sp->next)
1244 setvareq(sp->text, VEXPORT|VSTACK);
1245 shellexec(argv + 1, environment(), pathval(), 0);
1253 timescmd(int argc __unused, char **argv __unused)
1256 long shumins, shsmins, chumins, chsmins;
1257 double shusecs, shssecs, chusecs, chssecs;
1259 if (getrusage(RUSAGE_SELF, &ru) < 0)
1261 shumins = ru.ru_utime.tv_sec / 60;
1262 shusecs = ru.ru_utime.tv_sec % 60 + ru.ru_utime.tv_usec / 1000000.;
1263 shsmins = ru.ru_stime.tv_sec / 60;
1264 shssecs = ru.ru_stime.tv_sec % 60 + ru.ru_stime.tv_usec / 1000000.;
1265 if (getrusage(RUSAGE_CHILDREN, &ru) < 0)
1267 chumins = ru.ru_utime.tv_sec / 60;
1268 chusecs = ru.ru_utime.tv_sec % 60 + ru.ru_utime.tv_usec / 1000000.;
1269 chsmins = ru.ru_stime.tv_sec / 60;
1270 chssecs = ru.ru_stime.tv_sec % 60 + ru.ru_stime.tv_usec / 1000000.;
1271 out1fmt("%ldm%.3fs %ldm%.3fs\n%ldm%.3fs %ldm%.3fs\n", shumins,
1272 shusecs, shsmins, shssecs, chumins, chusecs, chsmins, chssecs);