/* hacked up cat ... */ /* so the lucent public license applies to this file. */ /* ron minnich rminnich@lanl.gov */ #include #include int nodeno = 0; char **dirno = nil; int totalenvsize = 32; /* leave some headroom */ int debugfd = 2; char *base = 0; int debuglevel = 0; void debug(int level, char *fmt, ...) { va_list arg; if (debuglevel < level) return; va_start(arg, fmt); vfprint(2, fmt, arg); va_end(arg); } int copy(int fromfd, int tofd) { int amtread, amtwrite; static char buf[8192]; while ((amtread = read(fromfd, buf, sizeof(buf))) > 0) { amtwrite = write(tofd, buf, amtread); if (amtwrite < amtread) return -1; } return 0; } void copybinary(char *dirnames[], int numdirs, char *execname){ char *name; int i; int rfd, wfd; rfd = open(execname, OREAD); if (rfd < 0) { perror(execname); exits(execname); } for(i = 0; i < numdirs; i++) { name = smprint("%s/exec", dirnames[i]); wfd = open(name, OWRITE); if (wfd < 0) { perror(name); exits(name); } free(name); copy(rfd, wfd); close(wfd); } } void catfile(char *dirnames[], int numdirs, char *filename, int wfd){ char *name; int i; int rfd; for(i = 0; i < numdirs; i++) { name = smprint("%s/%s", dirnames[i], filename); rfd = open(name, OREAD); if (rfd < 0) { perror(name); exits(name); } debug(2, "catfile: copy %s(%d) to %d\n", name, rfd, wfd); free(name); copy(rfd, wfd); } } void writestring(char *dirnames[], int numdirs, char *file, char *string) { int wfd; int slen = strlen(string); int i; int amt; for(i = 0; i < numdirs; i++) { char *name; name = smprint("%s/%s", dirnames[i], file); wfd = open(name, OWRITE); if (wfd < 0) { perror(name); exits(name); } debug(2, "Write %s to %s\n", string, name); amt = write(wfd, string, slen); if (amt < slen) perror(name); free(name); close(wfd); } } void openfiles(int f, char *s) { char buf[8192]; long n; memset(buf, 0, sizeof(buf)); n=read(f, buf, (long)sizeof buf); write(1, buf, n); debug(3,"now strdup the thing\n"); /* force it to be rooted ... */ dirno[nodeno++] = smprint("/%s/%s/xcpu/%s", base, s, buf); totalenvsize += strlen(buf) + 1; debug(3,"totales now %d\n", totalenvsize); } void main(int argc, char *argv[]) { void shell(void); int f, i; struct Waitmsg *m; char *envvar, *argvar; char *me = argv[0]; int nodecount = 0, arg_start = 0; int totalargsize; char *binary; if(argc == 1) exits("at least one"); base = getenv("XCPUBASE"); if (! base) base = "/mnt/xcpu"; /* we actually allocate too many, but who cares? */ dirno = malloc(argc * sizeof(char *)); if (! dirno) exits("dirno malloc failed"); /* format is nodes "--" argv */ else for(i=1; i