#include #include int fd; int tmout; void usage(void) { fprint(2, "usage: %s [ -t timeout ] addr\n", argv0); exits("usage"); } void catch(void *, char *msg) { fprint(2, "catch: %s\n", msg); if(strstr(msg, "alarm")) noted(NCONT); noted(NDFLT); } void main(int argc, char *argv[]) { int i; ARGBEGIN { case 't': tmout = atoi(EARGF(usage())); break; } ARGEND; if(*argv == nil) usage(); notify(catch); for(i=0; i<5; i++){ if(tmout > 0) alarm(tmout); if((fd = dial(*argv, 0, 0, 0)) < 0){ fprint(2, "dial: %r\n"); } else { fprint(2, "fd = %d\n", fd); close(fd); } if(tmout > 0) alarm(0); } for(fd=3; fd<100; fd++){ char buf[1024]; if(fd2path(fd, buf, sizeof(buf)) != 0) continue; fprint(2, "leaked fd %d: %s\n", fd, buf); } }