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.103 2011/04/25 20:54:12 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) {
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 expredir(n->nredir.redirect);
414 if ((!backgnd && flags & EV_EXIT && !have_traps()) ||
415 forkshell(jp = makejob(n, 1), n, backgnd) == 0) {
418 redirect(n->nredir.redirect, 0);
419 evaltree(n->nredir.n, flags | EV_EXIT); /* never returns */
420 } else if (!backgnd) {
422 exitstatus = waitforjob(jp, NULL);
430 * Evaluate a redirected compound command.
434 evalredir(union node *n, int flags)
436 struct jmploc jmploc;
437 struct jmploc *savehandler;
438 volatile int in_redirect = 1;
440 expredir(n->nredir.redirect);
441 savehandler = handler;
442 if (setjmp(jmploc.loc)) {
445 handler = savehandler;
448 if (e == EXERROR || e == EXEXEC) {
454 longjmp(handler->loc, 1);
458 redirect(n->nredir.redirect, REDIR_PUSH);
461 evaltree(n->nredir.n, flags);
464 handler = savehandler;
471 * Compute the names of the files in a redirection list.
475 expredir(union node *n)
479 for (redir = n ; redir ; redir = redir->nfile.next) {
482 oexitstatus = exitstatus;
483 switch (redir->type) {
489 expandarg(redir->nfile.fname, &fn, EXP_TILDE | EXP_REDIR);
490 redir->nfile.expfname = fn.list->text;
494 if (redir->ndup.vname) {
495 expandarg(redir->ndup.vname, &fn, EXP_TILDE | EXP_REDIR);
496 fixredir(redir, fn.list->text, 1);
506 * Evaluate a pipeline. All the processes in the pipeline are children
507 * of the process creating the pipeline. (This differs from some versions
508 * of the shell, which make the last process in a pipeline the parent
513 evalpipe(union node *n)
521 TRACE(("evalpipe(%p) called\n", (void *)n));
523 for (lp = n->npipe.cmdlist ; lp ; lp = lp->next)
526 jp = makejob(n, pipelen);
528 for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) {
535 error("Pipe call failed: %s", strerror(errno));
538 if (forkshell(jp, lp->n, n->npipe.backgnd) == 0) {
545 if (!(prevfd >= 0 && pip[0] == 0))
552 evaltree(lp->n, EV_EXIT);
560 if (n->npipe.backgnd == 0) {
562 exitstatus = waitforjob(jp, NULL);
563 TRACE(("evalpipe: job done exit status %d\n", exitstatus));
572 is_valid_fast_cmdsubst(union node *n)
578 for (argp = n->ncmd.args ; argp ; argp = argp->narg.next)
579 if (expandhassideeffects(argp->narg.text))
585 * Execute a command inside back quotes. If it's a builtin command, we
586 * want to save its output in a block obtained from malloc. Otherwise
587 * we fork off a subprocess and get the output of the command via a pipe.
588 * Should be called with interrupts off.
592 evalbackcmd(union node *n, struct backcmd *result)
596 struct stackmark smark; /* unnecessary */
597 struct jmploc jmploc;
598 struct jmploc *savehandler;
600 setstackmark(&smark);
609 if (is_valid_fast_cmdsubst(n)) {
610 exitstatus = oexitstatus;
611 savehandler = handler;
612 if (setjmp(jmploc.loc)) {
613 if (exception == EXERROR || exception == EXEXEC)
615 else if (exception != 0) {
616 handler = savehandler;
617 longjmp(handler->loc, 1);
621 evalcommand(n, EV_BACKCMD, result);
623 handler = savehandler;
627 error("Pipe call failed: %s", strerror(errno));
629 if (forkshell(jp, n, FORK_NOJOB) == 0) {
636 evaltree(n, EV_EXIT);
643 popstackmark(&smark);
644 TRACE(("evalbackcmd done: fd=%d buf=%p nleft=%d jp=%p\n",
645 result->fd, result->buf, result->nleft, result->jp));
649 * Check if a builtin can safely be executed in the same process,
650 * even though it should be in a subshell (command substitution).
651 * Note that jobid, jobs, times and trap can show information not
652 * available in a child process; this is deliberate.
653 * The arguments should already have been expanded.
656 safe_builtin(int idx, int argc, char **argv)
658 if (idx == BLTINCMD || idx == COMMANDCMD || idx == ECHOCMD ||
659 idx == FALSECMD || idx == JOBIDCMD || idx == JOBSCMD ||
660 idx == KILLCMD || idx == PRINTFCMD || idx == PWDCMD ||
661 idx == TESTCMD || idx == TIMESCMD || idx == TRUECMD ||
664 if (idx == EXPORTCMD || idx == TRAPCMD || idx == ULIMITCMD ||
666 return (argc <= 1 || (argc == 2 && argv[1][0] == '-'));
668 return (argc <= 1 || (argc == 2 && (argv[1][0] == '-' ||
669 argv[1][0] == '+') && argv[1][1] == 'o' &&
670 argv[1][2] == '\0'));
675 * Execute a simple command.
676 * Note: This may or may not return if (flags & EV_EXIT).
680 evalcommand(union node *cmd, int flgs, struct backcmd *backcmd)
682 struct stackmark smark;
684 struct arglist arglist;
685 struct arglist varlist;
686 volatile int flags = flgs;
687 char **volatile argv;
694 struct cmdentry cmdentry;
695 struct job *volatile jp;
696 struct jmploc jmploc;
697 struct jmploc *savehandler;
698 const char *savecmdname;
699 struct shparam saveparam;
700 struct localvar *savelocalvars;
701 struct parsefile *savetopfile;
703 char *volatile lastarg;
705 volatile int do_clearcmdentry;
706 const char *path = pathval();
708 /* First expand the arguments. */
709 TRACE(("evalcommand(%p, %d) called\n", (void *)cmd, flags));
710 setstackmark(&smark);
711 arglist.lastp = &arglist.list;
712 varlist.lastp = &varlist.list;
715 do_clearcmdentry = 0;
716 oexitstatus = exitstatus;
718 for (argp = cmd->ncmd.args ; argp ; argp = argp->narg.next) {
719 char *p = argp->narg.text;
720 if (varflag && is_name(*p)) {
723 } while (is_in_name(*p));
725 expandarg(argp, &varlist, EXP_VARTILDE);
729 expandarg(argp, &arglist, EXP_FULL | EXP_TILDE);
732 *arglist.lastp = NULL;
733 *varlist.lastp = NULL;
734 expredir(cmd->ncmd.redirect);
736 for (sp = arglist.list ; sp ; sp = sp->next)
738 /* Add one slot at the beginning for tryexec(). */
739 argv = stalloc(sizeof (char *) * (argc + 2));
742 for (sp = arglist.list ; sp ; sp = sp->next) {
743 TRACE(("evalcommand arg: %s\n", sp->text));
748 if (iflag && funcnest == 0 && argc > 0)
752 /* Print the command if xflag is set. */
757 for (sp = varlist.list ; sp ; sp = sp->next) {
760 p = strchr(sp->text, '=');
763 outbin(sp->text, p - sp->text, out2);
769 for (sp = arglist.list ; sp ; sp = sp->next) {
772 /* Disambiguate command looking like assignment. */
773 if (sp == arglist.list &&
774 strchr(sp->text, '=') != NULL &&
775 strchr(sp->text, '\'') == NULL) {
787 /* Now locate the command. */
789 /* Variable assignment(s) without command */
790 cmdentry.cmdtype = CMDBUILTIN;
791 cmdentry.u.index = BLTINCMD;
792 cmdentry.special = 0;
794 static const char PATH[] = "PATH=";
795 int cmd_flags = 0, bltinonly = 0;
798 * Modify the command lookup path, if a PATH= assignment
801 for (sp = varlist.list ; sp ; sp = sp->next)
802 if (strncmp(sp->text, PATH, sizeof(PATH) - 1) == 0) {
803 path = sp->text + sizeof(PATH) - 1;
805 * On `PATH=... command`, we need to make
806 * sure that the command isn't using the
807 * non-updated hash table of the outer PATH
808 * setting and we need to make sure that
809 * the hash table isn't filled with items
810 * from the temporary setting.
812 * It would be better to forbit using and
813 * updating the table while this command
814 * runs, by the command finding mechanism
815 * is heavily integrated with hash handling,
816 * so we just delete the hash before and after
817 * the command runs. Partly deleting like
818 * changepatch() does doesn't seem worth the
819 * bookinging effort, since most such runs add
820 * directories in front of the new PATH.
823 do_clearcmdentry = 1;
828 cmdentry.u.index = find_builtin(*argv, &cmdentry.special);
829 if (cmdentry.u.index < 0) {
830 cmdentry.u.index = BLTINCMD;
836 find_command(argv[0], &cmdentry, cmd_flags, path);
837 /* implement the bltin and command builtins here */
838 if (cmdentry.cmdtype != CMDBUILTIN)
840 if (cmdentry.u.index == BLTINCMD) {
846 } else if (cmdentry.u.index == COMMANDCMD) {
849 if (!strcmp(argv[1], "-p")) {
852 if (argv[2][0] == '-') {
853 if (strcmp(argv[2], "--"))
863 path = _PATH_STDPATH;
865 do_clearcmdentry = 1;
866 } else if (!strcmp(argv[1], "--")) {
871 } else if (argv[1][0] == '-')
877 cmd_flags |= DO_NOFUNC;
883 * Special builtins lose their special properties when
884 * called via 'command'.
886 if (cmd_flags & DO_NOFUNC)
887 cmdentry.special = 0;
890 /* Fork off a child process if necessary. */
891 if (cmd->ncmd.backgnd
892 || ((cmdentry.cmdtype == CMDNORMAL || cmdentry.cmdtype == CMDUNKNOWN)
893 && ((flags & EV_EXIT) == 0 || have_traps()))
894 || ((flags & EV_BACKCMD) != 0
895 && (cmdentry.cmdtype != CMDBUILTIN ||
896 !safe_builtin(cmdentry.u.index, argc, argv)))) {
897 jp = makejob(cmd, 1);
898 mode = cmd->ncmd.backgnd;
899 if (flags & EV_BACKCMD) {
902 error("Pipe call failed: %s", strerror(errno));
904 if (forkshell(jp, cmd, mode) != 0)
905 goto parent; /* at end of routine */
906 if (flags & EV_BACKCMD) {
917 /* This is the child process if a fork occurred. */
918 /* Execute the command. */
919 if (cmdentry.cmdtype == CMDFUNCTION) {
921 trputs("Shell function: "); trargs(argv);
923 saveparam = shellparam;
924 shellparam.malloc = 0;
925 shellparam.reset = 1;
926 shellparam.nparam = argc - 1;
927 shellparam.p = argv + 1;
928 shellparam.optnext = NULL;
930 savelocalvars = localvars;
932 reffunc(cmdentry.u.func);
933 savehandler = handler;
934 if (setjmp(jmploc.loc)) {
935 freeparam(&shellparam);
936 shellparam = saveparam;
938 unreffunc(cmdentry.u.func);
940 localvars = savelocalvars;
942 handler = savehandler;
943 longjmp(handler->loc, 1);
947 redirect(cmd->ncmd.redirect, REDIR_PUSH);
949 for (sp = varlist.list ; sp ; sp = sp->next)
951 exitstatus = oexitstatus;
952 evaltree(getfuncnode(cmdentry.u.func),
953 flags & (EV_TESTED | EV_EXIT));
955 unreffunc(cmdentry.u.func);
957 localvars = savelocalvars;
958 freeparam(&shellparam);
959 shellparam = saveparam;
960 handler = savehandler;
964 if (evalskip == SKIPFUNC) {
969 exitshell(exitstatus);
970 } else if (cmdentry.cmdtype == CMDBUILTIN) {
972 trputs("builtin command: "); trargs(argv);
974 mode = (cmdentry.u.index == EXECCMD)? 0 : REDIR_PUSH;
975 if (flags == EV_BACKCMD) {
977 memout.nextc = memout.buf;
980 cmdentry.special = 0;
982 savecmdname = commandname;
983 savetopfile = getcurrentfile();
984 cmdenviron = varlist.list;
986 savehandler = handler;
987 if (setjmp(jmploc.loc)) {
990 exitstatus = SIGINT+128;
991 else if (e != EXEXIT)
996 redirect(cmd->ncmd.redirect, mode);
998 * If there is no command word, redirection errors should
999 * not be fatal but assignment errors should.
1001 if (argc == 0 && !(flags & EV_BACKCMD))
1002 cmdentry.special = 1;
1003 listsetvar(cmdenviron, cmdentry.special ? 0 : VNOSET);
1006 commandname = argv[0];
1008 nextopt_optptr = NULL; /* initialize nextopt */
1009 builtin_flags = flags;
1010 exitstatus = (*builtinfunc[cmdentry.u.index])(argc, argv);
1019 handler = savehandler;
1020 commandname = savecmdname;
1022 exitshell(exitstatus);
1023 if (flags == EV_BACKCMD) {
1024 backcmd->buf = memout.buf;
1025 backcmd->nleft = memout.nextc - memout.buf;
1028 if (cmdentry.u.index != EXECCMD)
1031 if ((e != EXERROR && e != EXEXEC)
1032 || cmdentry.special)
1034 popfilesupto(savetopfile);
1035 if (flags != EV_BACKCMD)
1040 trputs("normal command: "); trargs(argv);
1042 redirect(cmd->ncmd.redirect, 0);
1043 for (sp = varlist.list ; sp ; sp = sp->next)
1044 setvareq(sp->text, VEXPORT|VSTACK);
1045 envp = environment();
1046 shellexec(argv, envp, path, cmdentry.u.index);
1051 parent: /* parent process gets here (if we forked) */
1052 if (mode == FORK_FG) { /* argument to fork */
1054 exitstatus = waitforjob(jp, &realstatus);
1056 if (iflag && loopnest > 0 && WIFSIGNALED(realstatus)) {
1057 evalskip = SKIPBREAK;
1058 skipcount = loopnest;
1060 } else if (mode == FORK_NOJOB) {
1061 backcmd->fd = pip[0];
1069 setvar("_", lastarg, 0);
1070 if (do_clearcmdentry)
1072 popstackmark(&smark);
1078 * Search for a command. This is called before we fork so that the
1079 * location of the command will be available in the parent as well as
1080 * the child. The check for "goodname" is an overly conservative
1081 * check that the name will not be subject to expansion.
1085 prehash(union node *n)
1087 struct cmdentry entry;
1089 if (n && n->type == NCMD && n->ncmd.args)
1090 if (goodname(n->ncmd.args->narg.text))
1091 find_command(n->ncmd.args->narg.text, &entry, 0,
1098 * Builtin commands. Builtin commands whose functions are closely
1099 * tied to evaluation are implemented here.
1103 * No command given, a bltin command with no arguments, or a bltin command
1104 * with an invalid name.
1108 bltincmd(int argc, char **argv)
1111 out2fmt_flush("%s: not found\n", argv[1]);
1115 * Preserve exitstatus of a previous possible redirection
1123 * Handle break and continue commands. Break, continue, and return are
1124 * all handled by setting the evalskip flag. The evaluation routines
1125 * above all check this flag, and if it is set they start skipping
1126 * commands rather than executing them. The variable skipcount is
1127 * the number of loops to break/continue, or the number of function
1128 * levels to return. (The latter is always 1.) It should probably
1129 * be an error to break out of more loops than exist, but it isn't
1130 * in the standard shell so we don't make it one here.
1134 breakcmd(int argc, char **argv)
1136 int n = argc > 1 ? number(argv[1]) : 1;
1141 evalskip = (**argv == 'c')? SKIPCONT : SKIPBREAK;
1148 * The `command' command.
1151 commandcmd(int argc, char **argv)
1157 path = bltinlookup("PATH", 1);
1159 optind = optreset = 1;
1161 while ((ch = getopt(argc, argv, "pvV")) != -1) {
1164 path = _PATH_STDPATH;
1167 cmd = TYPECMD_SMALLV;
1174 error("unknown option: -%c", optopt);
1182 error("wrong number of arguments");
1183 return typecmd_impl(2, argv - 1, cmd, path);
1186 error("commandcmd bad call");
1189 * Do nothing successfully if no command was specified;
1190 * ksh also does this.
1197 * The return command.
1201 returncmd(int argc, char **argv)
1203 int ret = argc > 1 ? number(argv[1]) : oexitstatus;
1206 evalskip = SKIPFUNC;
1209 /* skip the rest of the file */
1210 evalskip = SKIPFILE;
1218 falsecmd(int argc __unused, char **argv __unused)
1225 truecmd(int argc __unused, char **argv __unused)
1232 execcmd(int argc, char **argv)
1235 * Because we have historically not supported any options,
1236 * only treat "--" specially.
1238 if (argc > 1 && strcmp(argv[1], "--") == 0)
1243 iflag = 0; /* exit on error */
1246 for (sp = cmdenviron; sp ; sp = sp->next)
1247 setvareq(sp->text, VEXPORT|VSTACK);
1248 shellexec(argv + 1, environment(), pathval(), 0);
1256 timescmd(int argc __unused, char **argv __unused)
1259 long shumins, shsmins, chumins, chsmins;
1260 double shusecs, shssecs, chusecs, chssecs;
1262 if (getrusage(RUSAGE_SELF, &ru) < 0)
1264 shumins = ru.ru_utime.tv_sec / 60;
1265 shusecs = ru.ru_utime.tv_sec % 60 + ru.ru_utime.tv_usec / 1000000.;
1266 shsmins = ru.ru_stime.tv_sec / 60;
1267 shssecs = ru.ru_stime.tv_sec % 60 + ru.ru_stime.tv_usec / 1000000.;
1268 if (getrusage(RUSAGE_CHILDREN, &ru) < 0)
1270 chumins = ru.ru_utime.tv_sec / 60;
1271 chusecs = ru.ru_utime.tv_sec % 60 + ru.ru_utime.tv_usec / 1000000.;
1272 chsmins = ru.ru_stime.tv_sec / 60;
1273 chssecs = ru.ru_stime.tv_sec % 60 + ru.ru_stime.tv_usec / 1000000.;
1274 out1fmt("%ldm%.3fs %ldm%.3fs\n%ldm%.3fs %ldm%.3fs\n", shumins,
1275 shusecs, shsmins, shssecs, chumins, chusecs, chsmins, chssecs);