/* * File: main.c * CVS: $Id: main.c,v 1.4 2005/06/17 11:55:18 pek Exp $ * Author: Philip Mucci * mucci@cs.utk.edu * Mods: Per Ekman * pek@pdc.kth.se */ #include #include "iotrack.h" char *usage_long[] = {"Usage: [-hvtnd] [-f [prefix]] -- ", " -h\t\tPrint this message.", " -v\t\tPrint version information.", " -t\t\tEnable monitoring of multiple threads.", " -n\t\tDo not follow fork()'s.", " -d\t\tEnable debugging output.", " -f[prefix]\tOutput to .iotrack....", "", "This is OPEN SOURCE SOFTWARE written by Per Ekman", "of the Parallel Center for Computation, Royal Institute", "of Technology, Stockholm, Sweden and Philip Mucci of the", "Innovative Computing Laboratory at the University of", "Tennessee, Knoxville.\n", "See WEB-PAGE for further information.", "Email bug reports to: EMAIL-ADDRESS" }; static int debug = 0; static char *parse_args(int my_argc, char **my_argv, char **cmd, char ***cmd_argv, char *preload_env, char *preload_sep) { int c, i; static char option_string[PATH_MAX] = ""; #if defined(linux) || defined(sun) strcpy(preload_env,"LD_PRELOAD"); *preload_sep = ' '; #elif defined(sgi) strcpy(preload_env,"_RLD_LIST"); *preload_sep = ':'; #endif if (my_argc) { while (1) { c = getopt(my_argc, my_argv, "hvtndf::"); if (c == -1) break; switch(c) { case 'v': printf("iotrack version %s\n",IOTRACK_VERSION); exit(0); break; case 'h': for (i = 0; i < (sizeof usage_long / sizeof usage_long[0]); i++) { puts(usage_long[i]); } exit(0); break; case 'n': strcat(option_string,"NOFORK,"); break; case 't': strcat(option_string,"THREADS,"); break; case 'd': strcat(option_string,"DEBUG,"); debug = 1; break; case 'f': { if (optarg == NULL) strcat(option_string,"FILE,"); else { strcat(option_string,"FILE="); strcat(option_string,optarg); strcat(option_string,","); } } break; default: error: puts(usage_long[0]); fprintf(stderr,"Try `%s -h' for more information.\n",my_argv[0]); exit(1); } } } /* Construct argv for the fork/exec pair later on. */ if (my_argv[optind] == NULL) { fprintf(stderr,"%s: no command given\n",my_argv[0]); goto error; } { char **tmp_my_argv = (char **)malloc((my_argc-optind+1)*sizeof(char *)); for (i=optind;i