aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/srv.c
blob: 95dfef88c632338b1795ff735d73bf36cd67134a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <u.h>
#include <libc.h>
#include <auth.h>
#include <fcall.h>
#include <thread.h>

void
usage(void)
{
	fprint(2, "usage: srv addr [srvname]\n");
	threadexitsall("usage");
}

void
threadmain(int argc, char **argv)
{
	int fd;
	char *addr, *service;
	
	ARGBEGIN{
	default:
		usage();
	}ARGEND
	
	if(argc != 1 && argc != 2)
		usage();

	addr = netmkaddr(argv[0], "tcp", "9fs");
	if((fd = dial(addr, nil, nil, nil)) < 0)
		sysfatal("dial %s: %r", addr);
	
	if(argc == 2)
		service = argv[1];
	else
		service = argv[0];
	
	if(post9pservice(fd, service) < 0)
		sysfatal("post9pservice: %r");

	threadexitsall(0);
}