diff options
author | rsc <devnull@localhost> | 2005-01-18 20:45:12 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2005-01-18 20:45:12 +0000 |
commit | 58698c9c1205e44c77734e7a32338f6c08bc4aaa (patch) | |
tree | 96a326849c35d95ade1a8b7348468c60e6539bf8 /src/cmd/core.c | |
parent | 20173464d2169892bde1a91bbfd1c2a811a79ace (diff) | |
download | plan9port-58698c9c1205e44c77734e7a32338f6c08bc4aaa.tar.gz plan9port-58698c9c1205e44c77734e7a32338f6c08bc4aaa.tar.bz2 plan9port-58698c9c1205e44c77734e7a32338f6c08bc4aaa.zip |
add
Diffstat (limited to 'src/cmd/core.c')
-rw-r--r-- | src/cmd/core.c | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/src/cmd/core.c b/src/cmd/core.c new file mode 100644 index 00000000..8aa5e1d9 --- /dev/null +++ b/src/cmd/core.c @@ -0,0 +1,102 @@ +#include <u.h> +#include <libc.h> +#include <mach.h> + +char *coredir(void); +void coreall(char*); +void corefile(char*, int); + +void +usage(void) +{ + fprint(2, "usage: core [dir | corefile]...\n"); + exits("usage"); +} + +void +main(int argc, char **argv) +{ + int i; + + ARGBEGIN{ + default: + usage(); + }ARGEND + + if(argc == 0){ + argc++; + *--argv = coredir(); + } + + for(i=0; i<argc; i++) + coreall(argv[i]); +} + +char* +coredir(void) +{ + char *dir; + + dir = getenv("COREDIR"); + if(dir == nil) + dir = "."; + return dir; +} + +void +coreall(char *name) +{ + Dir *d; + int fd, i, n; + char *p; + + if((d = dirstat(name)) == nil){ + fprint(2, "%s: %r\n", name); + return; + } + if((d->mode&DMDIR) == 0) + corefile(name, 1); + free(d); + if((fd = open(name, OREAD)) < 0){ + fprint(2, "open %s: %r\n", name); + return; + } + n = dirreadall(fd, &d); + for(i=0; i<n; i++){ + p = smprint("%s/%s", name, d[i].name); + if(p == nil) + sysfatal("out of memory"); + corefile(p, 0); + free(p); + } +} + +void +corefile(char *name, int explicit) +{ + Fhdr *hdr; + char t[100]; + Dir *d; + + if((d = dirstat(name)) == nil){ + if(explicit) + fprint(2, "%s; %r\n", name); + return; + } + strcpy(t, ctime(d->mtime)); + t[strlen(t)-1] = 0; /* newline */ + + if((hdr = crackhdr(name, OREAD)) == nil){ + if(explicit) + fprint(2, "%s: %r\n", name); + return; + } + if(hdr->ftype != FCORE){ + uncrackhdr(hdr); + if(explicit) + fprint(2, "%s: not a core file\n", name); + return; + } + print("acid %s # %s %s\n", name, t, hdr->cmd); + uncrackhdr(hdr); +} |