From 69819d5f00b2163d89d38cf63e615ee6be3db755 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 22 Aug 2008 17:55:50 +0200 Subject: [PATCH] Added basic support for writing meta-files. Original patch by TomGav, cleaned up by me. --- box/box.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/box/box.c b/box/box.c index 6fcb66e..5817264 100644 --- a/box/box.c +++ b/box/box.c @@ -670,6 +670,34 @@ check_timeout(void) } } +static FILE *metafile; + +static void +metafile_open(const char *name) +{ + if (!name) + { + metafile=NULL; + return; + } + if (!strcmp(name,"-")) + { + metafile=stdout; + return; + } + metafile=fopen(name, "w"); + if (!metafile) + die("Failed to open metafile '%s'",name); +} + +static void +metafile_write(double t_total, double t_wall) +{ + if (!metafile) + return; + fprintf(metafile, "time:%0.3f\ntime_wall:%0.3f\n", t_total, t_wall); +} + static void boxkeeper(void) { @@ -730,6 +758,7 @@ boxkeeper(void) (int) total.tv_sec, (int) total.tv_usec/1000, (int) wall.tv_sec, (int) wall.tv_usec/1000, syscall_count); + metafile_write(total.tv_sec+total.tv_usec/1000000.0,wall.tv_sec+wall.tv_usec/1000000.0); exit(0); } if (WIFSIGNALED(stat)) @@ -860,6 +889,7 @@ Options:\n\ -f\t\tFilter system calls (-ff=very restricted)\n\ -i \tRedirect stdin from \n\ -m \tLimit address space to KB\n\ +-M \tOutput process information to (name:value)\n\ -o \tRedirect stdout to \n\ -p \tPermit access to the specified path (or subtree if it ends with a `/')\n\ -p =\tDefine action for the specified path (=yes/no)\n\ @@ -880,7 +910,7 @@ main(int argc, char **argv) int c; uid_t uid; - while ((c = getopt(argc, argv, "a:c:eE:fi:m:o:p:r:s:t:Tvw:")) >= 0) + while ((c = getopt(argc, argv, "a:c:eE:fi:m:M:o:p:r:s:t:Tvw:")) >= 0) switch (c) { case 'a': @@ -905,6 +935,9 @@ main(int argc, char **argv) case 'm': memory_limit = atol(optarg); break; + case 'M': + metafile_open(optarg); + break; case 'o': redir_stdout = optarg; break; -- 2.39.2