Plan 9 from Bell Labs’s /usr/web/sources/contrib/cinap_lenrek/dialtest.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>

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);
	}
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].