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.101 2011/02/05 14:08:51 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);
183 exitshell(exitstatus);
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 ((flags & EV_EXIT) || (eflag && exitstatus != 0 && do_etest))
290 exitshell(exitstatus);
295 evalloop(union node *n, int flags)
302 evaltree(n->nbinary.ch1, EV_TESTED);
304 skipping: if (evalskip == SKIPCONT && --skipcount <= 0) {
308 if (evalskip == SKIPBREAK && --skipcount <= 0)
310 if (evalskip == SKIPFUNC || evalskip == SKIPFILE)
314 if (n->type == NWHILE) {
321 evaltree(n->nbinary.ch2, flags);
333 evalfor(union node *n, int flags)
335 struct arglist arglist;
338 struct stackmark smark;
340 setstackmark(&smark);
341 arglist.lastp = &arglist.list;
342 for (argp = n->nfor.args ; argp ; argp = argp->narg.next) {
343 oexitstatus = exitstatus;
344 expandarg(argp, &arglist, EXP_FULL | EXP_TILDE);
348 *arglist.lastp = NULL;
352 for (sp = arglist.list ; sp ; sp = sp->next) {
353 setvar(n->nfor.var, sp->text, 0);
354 evaltree(n->nfor.body, flags);
356 if (evalskip == SKIPCONT && --skipcount <= 0) {
360 if (evalskip == SKIPBREAK && --skipcount <= 0)
367 popstackmark(&smark);
373 evalcase(union node *n, int flags)
377 struct arglist arglist;
378 struct stackmark smark;
380 setstackmark(&smark);
381 arglist.lastp = &arglist.list;
382 oexitstatus = exitstatus;
384 expandarg(n->ncase.expr, &arglist, EXP_TILDE);
385 for (cp = n->ncase.cases ; cp && evalskip == 0 ; cp = cp->nclist.next) {
386 for (patp = cp->nclist.pattern ; patp ; patp = patp->narg.next) {
387 if (casematch(patp, arglist.list->text)) {
389 evaltree(cp->nclist.body, flags);
396 popstackmark(&smark);
402 * Kick off a subshell to evaluate a tree.
406 evalsubshell(union node *n, int flags)
409 int backgnd = (n->type == NBACKGND);
411 expredir(n->nredir.redirect);
412 if ((!backgnd && flags & EV_EXIT && !have_traps()) ||
413 forkshell(jp = makejob(n, 1), n, backgnd) == 0) {
416 redirect(n->nredir.redirect, 0);
417 evaltree(n->nredir.n, flags | EV_EXIT); /* never returns */
418 } else if (!backgnd) {
420 exitstatus = waitforjob(jp, NULL);
427 * Evaluate a redirected compound command.
431 evalredir(union node *n, int flags)
433 struct jmploc jmploc;
434 struct jmploc *savehandler;
435 volatile int in_redirect = 1;
437 expredir(n->nredir.redirect);
438 savehandler = handler;
439 if (setjmp(jmploc.loc)) {
442 handler = savehandler;
444 if (e == EXERROR || e == EXEXEC) {
451 longjmp(handler->loc, 1);
455 redirect(n->nredir.redirect, REDIR_PUSH);
458 evaltree(n->nredir.n, flags);
461 handler = savehandler;
468 * Compute the names of the files in a redirection list.
472 expredir(union node *n)
476 for (redir = n ; redir ; redir = redir->nfile.next) {
479 oexitstatus = exitstatus;
480 switch (redir->type) {
486 expandarg(redir->nfile.fname, &fn, EXP_TILDE | EXP_REDIR);
487 redir->nfile.expfname = fn.list->text;
491 if (redir->ndup.vname) {
492 expandarg(redir->ndup.vname, &fn, EXP_TILDE | EXP_REDIR);
493 fixredir(redir, fn.list->text, 1);
503 * Evaluate a pipeline. All the processes in the pipeline are children
504 * of the process creating the pipeline. (This differs from some versions
505 * of the shell, which make the last process in a pipeline the parent
510 evalpipe(union node *n)
518 TRACE(("evalpipe(%p) called\n", (void *)n));
520 for (lp = n->npipe.cmdlist ; lp ; lp = lp->next)
523 jp = makejob(n, pipelen);
525 for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) {
532 error("Pipe call failed: %s", strerror(errno));
535 if (forkshell(jp, lp->n, n->npipe.backgnd) == 0) {
542 if (!(prevfd >= 0 && pip[0] == 0))
549 evaltree(lp->n, EV_EXIT);
557 if (n->npipe.backgnd == 0) {
559 exitstatus = waitforjob(jp, NULL);
560 TRACE(("evalpipe: job done exit status %d\n", exitstatus));
568 is_valid_fast_cmdsubst(union node *n)
574 for (argp = n->ncmd.args ; argp ; argp = argp->narg.next)
575 if (expandhassideeffects(argp->narg.text))
581 * Execute a command inside back quotes. If it's a builtin command, we
582 * want to save its output in a block obtained from malloc. Otherwise
583 * we fork off a subprocess and get the output of the command via a pipe.
584 * Should be called with interrupts off.
588 evalbackcmd(union node *n, struct backcmd *result)
592 struct stackmark smark; /* unnecessary */
593 struct jmploc jmploc;
594 struct jmploc *savehandler;
596 setstackmark(&smark);
605 if (is_valid_fast_cmdsubst(n)) {
606 exitstatus = oexitstatus;
607 savehandler = handler;
608 if (setjmp(jmploc.loc)) {
609 if (exception == EXERROR || exception == EXEXEC)
611 else if (exception != 0) {
612 handler = savehandler;
613 longjmp(handler->loc, 1);
617 evalcommand(n, EV_BACKCMD, result);
619 handler = savehandler;
623 error("Pipe call failed: %s", strerror(errno));
625 if (forkshell(jp, n, FORK_NOJOB) == 0) {
632 evaltree(n, EV_EXIT);
639 popstackmark(&smark);
640 TRACE(("evalbackcmd done: fd=%d buf=%p nleft=%d jp=%p\n",
641 result->fd, result->buf, result->nleft, result->jp));
645 * Check if a builtin can safely be executed in the same process,
646 * even though it should be in a subshell (command substitution).
647 * Note that jobid, jobs, times and trap can show information not
648 * available in a child process; this is deliberate.
649 * The arguments should already have been expanded.
652 safe_builtin(int idx, int argc, char **argv)
654 if (idx == BLTINCMD || idx == COMMANDCMD || idx == ECHOCMD ||
655 idx == FALSECMD || idx == JOBIDCMD || idx == JOBSCMD ||
656 idx == KILLCMD || idx == PRINTFCMD || idx == PWDCMD ||
657 idx == TESTCMD || idx == TIMESCMD || idx == TRUECMD ||
660 if (idx == EXPORTCMD || idx == TRAPCMD || idx == ULIMITCMD ||
662 return (argc <= 1 || (argc == 2 && argv[1][0] == '-'));
664 return (argc <= 1 || (argc == 2 && (argv[1][0] == '-' ||
665 argv[1][0] == '+') && argv[1][1] == 'o' &&
666 argv[1][2] == '\0'));
671 * Execute a simple command.
672 * Note: This may or may not return if (flags & EV_EXIT).
676 evalcommand(union node *cmd, int flgs, struct backcmd *backcmd)
678 struct stackmark smark;
680 struct arglist arglist;
681 struct arglist varlist;
682 volatile int flags = flgs;
683 char **volatile argv;
690 struct cmdentry cmdentry;
691 struct job *volatile jp;
692 struct jmploc jmploc;
693 struct jmploc *savehandler;
694 const char *savecmdname;
695 struct shparam saveparam;
696 struct localvar *savelocalvars;
697 struct parsefile *savetopfile;
699 char *volatile lastarg;
701 volatile int do_clearcmdentry;
702 const char *path = pathval();
704 /* First expand the arguments. */
705 TRACE(("evalcommand(%p, %d) called\n", (void *)cmd, flags));
706 setstackmark(&smark);
707 arglist.lastp = &arglist.list;
708 varlist.lastp = &varlist.list;
711 do_clearcmdentry = 0;
712 oexitstatus = exitstatus;
714 for (argp = cmd->ncmd.args ; argp ; argp = argp->narg.next) {
715 char *p = argp->narg.text;
716 if (varflag && is_name(*p)) {
719 } while (is_in_name(*p));
721 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. */
753 for (sp = varlist.list ; sp ; sp = sp->next) {
756 p = strchr(sp->text, '=');
759 outbin(sp->text, p - sp->text, out2);
765 for (sp = arglist.list ; sp ; sp = sp->next) {
768 /* Disambiguate command looking like assignment. */
769 if (sp == arglist.list &&
770 strchr(sp->text, '=') != NULL &&
771 strchr(sp->text, '\'') == NULL) {
783 /* Now locate the command. */
785 /* Variable assignment(s) without command */
786 cmdentry.cmdtype = CMDBUILTIN;
787 cmdentry.u.index = BLTINCMD;
788 cmdentry.special = 0;
790 static const char PATH[] = "PATH=";
791 int cmd_flags = 0, bltinonly = 0;
794 * Modify the command lookup path, if a PATH= assignment
797 for (sp = varlist.list ; sp ; sp = sp->next)
798 if (strncmp(sp->text, PATH, sizeof(PATH) - 1) == 0) {
799 path = sp->text + sizeof(PATH) - 1;
801 * On `PATH=... command`, we need to make
802 * sure that the command isn't using the
803 * non-updated hash table of the outer PATH
804 * setting and we need to make sure that
805 * the hash table isn't filled with items
806 * from the temporary setting.
808 * It would be better to forbit using and
809 * updating the table while this command
810 * runs, by the command finding mechanism
811 * is heavily integrated with hash handling,
812 * so we just delete the hash before and after
813 * the command runs. Partly deleting like
814 * changepatch() does doesn't seem worth the
815 * bookinging effort, since most such runs add
816 * directories in front of the new PATH.
819 do_clearcmdentry = 1;
824 cmdentry.u.index = find_builtin(*argv, &cmdentry.special);
825 if (cmdentry.u.index < 0) {
826 cmdentry.u.index = BLTINCMD;
832 find_command(argv[0], &cmdentry, cmd_flags, path);
833 /* implement the bltin and command builtins here */
834 if (cmdentry.cmdtype != CMDBUILTIN)
836 if (cmdentry.u.index == BLTINCMD) {
842 } else if (cmdentry.u.index == COMMANDCMD) {
845 if (!strcmp(argv[1], "-p")) {
848 if (argv[2][0] == '-') {
849 if (strcmp(argv[2], "--"))
859 path = _PATH_STDPATH;
861 do_clearcmdentry = 1;
862 } else if (!strcmp(argv[1], "--")) {
867 } else if (argv[1][0] == '-')
873 cmd_flags |= DO_NOFUNC;
879 * Special builtins lose their special properties when
880 * called via 'command'.
882 if (cmd_flags & DO_NOFUNC)
883 cmdentry.special = 0;
886 /* Fork off a child process if necessary. */
887 if (cmd->ncmd.backgnd
888 || ((cmdentry.cmdtype == CMDNORMAL || cmdentry.cmdtype == CMDUNKNOWN)
889 && ((flags & EV_EXIT) == 0 || have_traps()))
890 || ((flags & EV_BACKCMD) != 0
891 && (cmdentry.cmdtype != CMDBUILTIN ||
892 !safe_builtin(cmdentry.u.index, argc, argv)))) {
893 jp = makejob(cmd, 1);
894 mode = cmd->ncmd.backgnd;
895 if (flags & EV_BACKCMD) {
898 error("Pipe call failed: %s", strerror(errno));
900 if (forkshell(jp, cmd, mode) != 0)
901 goto parent; /* at end of routine */
902 if (flags & EV_BACKCMD) {
913 /* This is the child process if a fork occurred. */
914 /* Execute the command. */
915 if (cmdentry.cmdtype == CMDFUNCTION) {
917 trputs("Shell function: "); trargs(argv);
919 saveparam = shellparam;
920 shellparam.malloc = 0;
921 shellparam.reset = 1;
922 shellparam.nparam = argc - 1;
923 shellparam.p = argv + 1;
924 shellparam.optnext = NULL;
926 savelocalvars = localvars;
928 reffunc(cmdentry.u.func);
929 savehandler = handler;
930 if (setjmp(jmploc.loc)) {
931 freeparam(&shellparam);
932 shellparam = saveparam;
933 if (exception == EXERROR || exception == EXEXEC)
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 if (flags & EV_TESTED)
950 evaltree(getfuncnode(cmdentry.u.func), EV_TESTED);
952 evaltree(getfuncnode(cmdentry.u.func), 0);
954 unreffunc(cmdentry.u.func);
956 localvars = savelocalvars;
957 freeparam(&shellparam);
958 shellparam = saveparam;
959 handler = savehandler;
963 if (evalskip == SKIPFUNC) {
968 exitshell(exitstatus);
969 } else if (cmdentry.cmdtype == CMDBUILTIN) {
971 trputs("builtin command: "); trargs(argv);
973 mode = (cmdentry.u.index == EXECCMD)? 0 : REDIR_PUSH;
974 if (flags == EV_BACKCMD) {
976 memout.nextc = memout.buf;
979 cmdentry.special = 0;
981 savecmdname = commandname;
982 savetopfile = getcurrentfile();
983 cmdenviron = varlist.list;
985 savehandler = handler;
986 if (setjmp(jmploc.loc)) {
988 exitstatus = (e == EXINT)? SIGINT+128 : 2;
992 redirect(cmd->ncmd.redirect, mode);
994 * If there is no command word, redirection errors should
995 * not be fatal but assignment errors should.
997 if (argc == 0 && !(flags & EV_BACKCMD))
998 cmdentry.special = 1;
999 listsetvar(cmdenviron, cmdentry.special ? 0 : VNOSET);
1002 commandname = argv[0];
1004 nextopt_optptr = NULL; /* initialize nextopt */
1005 builtin_flags = flags;
1006 exitstatus = (*builtinfunc[cmdentry.u.index])(argc, argv);
1015 handler = savehandler;
1016 commandname = savecmdname;
1018 exitshell(exitstatus);
1019 if (flags == EV_BACKCMD) {
1020 backcmd->buf = memout.buf;
1021 backcmd->nleft = memout.nextc - memout.buf;
1024 if (cmdentry.u.index != EXECCMD &&
1025 (e == -1 || e == EXERROR || e == EXEXEC))
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];
1065 setvar("_", lastarg, 0);
1066 if (do_clearcmdentry)
1068 popstackmark(&smark);
1074 * Search for a command. This is called before we fork so that the
1075 * location of the command will be available in the parent as well as
1076 * the child. The check for "goodname" is an overly conservative
1077 * check that the name will not be subject to expansion.
1081 prehash(union node *n)
1083 struct cmdentry entry;
1085 if (n && n->type == NCMD && n->ncmd.args)
1086 if (goodname(n->ncmd.args->narg.text))
1087 find_command(n->ncmd.args->narg.text, &entry, 0,
1094 * Builtin commands. Builtin commands whose functions are closely
1095 * tied to evaluation are implemented here.
1099 * No command given, a bltin command with no arguments, or a bltin command
1100 * with an invalid name.
1104 bltincmd(int argc, char **argv)
1107 out2fmt_flush("%s: not found\n", argv[1]);
1111 * Preserve exitstatus of a previous possible redirection
1119 * Handle break and continue commands. Break, continue, and return are
1120 * all handled by setting the evalskip flag. The evaluation routines
1121 * above all check this flag, and if it is set they start skipping
1122 * commands rather than executing them. The variable skipcount is
1123 * the number of loops to break/continue, or the number of function
1124 * levels to return. (The latter is always 1.) It should probably
1125 * be an error to break out of more loops than exist, but it isn't
1126 * in the standard shell so we don't make it one here.
1130 breakcmd(int argc, char **argv)
1132 int n = argc > 1 ? number(argv[1]) : 1;
1137 evalskip = (**argv == 'c')? SKIPCONT : SKIPBREAK;
1144 * The `command' command.
1147 commandcmd(int argc, char **argv)
1153 path = bltinlookup("PATH", 1);
1155 optind = optreset = 1;
1157 while ((ch = getopt(argc, argv, "pvV")) != -1) {
1160 path = _PATH_STDPATH;
1163 cmd = TYPECMD_SMALLV;
1170 error("unknown option: -%c", optopt);
1178 error("wrong number of arguments");
1179 return typecmd_impl(2, argv - 1, cmd, path);
1182 error("commandcmd bad call");
1185 * Do nothing successfully if no command was specified;
1186 * ksh also does this.
1193 * The return command.
1197 returncmd(int argc, char **argv)
1199 int ret = argc > 1 ? number(argv[1]) : oexitstatus;
1202 evalskip = SKIPFUNC;
1205 /* skip the rest of the file */
1206 evalskip = SKIPFILE;
1214 falsecmd(int argc __unused, char **argv __unused)
1221 truecmd(int argc __unused, char **argv __unused)
1228 execcmd(int argc, char **argv)
1231 * Because we have historically not supported any options,
1232 * only treat "--" specially.
1234 if (argc > 1 && strcmp(argv[1], "--") == 0)
1239 iflag = 0; /* exit on error */
1242 for (sp = cmdenviron; sp ; sp = sp->next)
1243 setvareq(sp->text, VEXPORT|VSTACK);
1244 shellexec(argv + 1, environment(), pathval(), 0);
1252 timescmd(int argc __unused, char **argv __unused)
1255 long shumins, shsmins, chumins, chsmins;
1256 double shusecs, shssecs, chusecs, chssecs;
1258 if (getrusage(RUSAGE_SELF, &ru) < 0)
1260 shumins = ru.ru_utime.tv_sec / 60;
1261 shusecs = ru.ru_utime.tv_sec % 60 + ru.ru_utime.tv_usec / 1000000.;
1262 shsmins = ru.ru_stime.tv_sec / 60;
1263 shssecs = ru.ru_stime.tv_sec % 60 + ru.ru_stime.tv_usec / 1000000.;
1264 if (getrusage(RUSAGE_CHILDREN, &ru) < 0)
1266 chumins = ru.ru_utime.tv_sec / 60;
1267 chusecs = ru.ru_utime.tv_sec % 60 + ru.ru_utime.tv_usec / 1000000.;
1268 chsmins = ru.ru_stime.tv_sec / 60;
1269 chssecs = ru.ru_stime.tv_sec % 60 + ru.ru_stime.tv_usec / 1000000.;
1270 out1fmt("%ldm%.3fs %ldm%.3fs\n%ldm%.3fs %ldm%.3fs\n", shumins,
1271 shusecs, shsmins, shssecs, chumins, chusecs, chsmins, chssecs);