* srv cleanup
@ 2015-01-25 0:39 mischief
0 siblings, 0 replies; only message in thread
From: mischief @ 2015-01-25 0:39 UTC (permalink / raw)
To: 9front
[-- Attachment #1: Type: text/plain, Size: 13 bytes --]
srv cleanup.
[-- Attachment #2: Type: text/plain, Size: 3542 bytes --]
diff -r 27d6b9ab8cce sys/src/cmd/srv.c
--- a/sys/src/cmd/srv.c Fri Jan 23 14:01:56 2015 +0100
+++ b/sys/src/cmd/srv.c Sat Jan 24 16:23:54 2015 -0800
@@ -4,11 +4,6 @@
char *dest = "system";
int mountflag = MREPL;
-
-void error(char *);
-void rpc(int, int);
-void post(char*, int);
-void mountfs(char*, int);
int doauth = 1;
void
@@ -16,18 +11,14 @@
{
fprint(2, "usage: %s [-abcCm] [net!]host [srvname [mtpt]]\n", argv0);
fprint(2, " or %s -e [-abcCm] command [srvname [mtpt]]\n", argv0);
-
exits("usage");
}
void
-ignore(void *a, char *c)
+ignore(void*, char *c)
{
- USED(a);
- if(strcmp(c, "alarm") == 0){
- fprint(2, "srv: timeout establishing connection to %s\n", dest);
- exits("timeout");
- }
+ if(strcmp(c, "alarm") == 0)
+ sysfatal("timeout establishing connection to %s", dest);
if(strstr(c, "write on closed pipe") == 0){
fprint(2, "write on closed pipe\n");
noted(NCONT);
@@ -44,8 +35,7 @@
return -1;
switch(fork()){
case -1:
- fprint(2, "fork failed: %r\n");
- _exits("exec");
+ sysfatal("fork failed: %r");
case 0:
rfork(RFNOTEG);
dup(p[0], 0);
@@ -53,8 +43,7 @@
close(p[0]);
close(p[1]);
execl("/bin/rc", "rc", "-c", cmd, nil);
- fprint(2, "exec failed: %r\n");
- _exits("exec");
+ sysfatal("exec failed: %r");
default:
close(p[0]);
return p[1];
@@ -62,11 +51,23 @@
}
void
+post(char *srv, int fd)
+{
+ int f;
+ char buf[128];
+
+ if((f = create(srv, OWRITE, 0666)) < 0)
+ sysfatal("%s: create(%s): %r", dest, srv);
+ sprint(buf, "%d", fd);
+ if(write(f, buf, strlen(buf)) != strlen(buf))
+ sysfatal("%s: write: %r", dest);
+}
+
+void
main(int argc, char *argv[])
{
int fd, doexec;
char *srv, *mtpt;
- char dir[1024];
char err[ERRMAX];
char *p, *p2;
int domount, reallymount, try, sleeptime;
@@ -155,21 +156,23 @@
usage();
}
+ fmtinstall('H', encodefmt);
+
try = 0;
dest = *argv;
Again:
+ werrstr("");
try++;
- if(access(srv, 0) == 0){
+ if(access(srv, AEXIST) == 0){
if(domount){
fd = open(srv, ORDWR);
if(fd >= 0)
goto Mount;
remove(srv);
- }
- else{
+ } else {
fprint(2, "srv: %s already exists\n", srv);
- exits(0);
+ exits(nil);
}
}
@@ -178,12 +181,10 @@
fd = connectcmd(dest);
else{
dest = netmkaddr(dest, 0, "9fs");
- fd = dial(dest, 0, dir, 0);
+ fd = dial(dest, nil, nil, nil);
}
- if(fd < 0) {
- fprint(2, "srv: dial %s: %r\n", dest);
- exits("dial");
- }
+ if(fd < 0)
+ sysfatal("dial %s: %r", dest);
alarm(0);
if(sleeptime){
@@ -191,47 +192,24 @@
sleep(sleeptime*1000);
}
+ fprint(2, "post...\n");
post(srv, fd);
Mount:
if(domount == 0 || reallymount == 0)
- exits(0);
+ exits(nil);
if((!doauth && mount(fd, -1, mtpt, mountflag, "") < 0)
|| (doauth && amount(fd, mtpt, mountflag, "") < 0)){
err[0] = 0;
- errstr(err, sizeof err);
+ rerrstr(err, sizeof err);
if(strstr(err, "Hangup") || strstr(err, "hungup") || strstr(err, "timed out")){
remove(srv);
if(try == 1)
goto Again;
}
- fprint(2, "srv %s: mount failed: %s\n", dest, err);
- exits("mount");
+ sysfatal("%s: mount failed: %r", dest);
}
- exits(0);
+ exits(nil);
}
-void
-post(char *srv, int fd)
-{
- int f;
- char buf[128];
-
- fprint(2, "post...\n");
- f = create(srv, OWRITE, 0666);
- if(f < 0){
- sprint(buf, "create(%s)", srv);
- error(buf);
- }
- sprint(buf, "%d", fd);
- if(write(f, buf, strlen(buf)) != strlen(buf))
- error("write");
-}
-
-void
-error(char *s)
-{
- fprint(2, "srv %s: %s: %r\n", dest, s);
- exits("srv: error");
-}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2015-01-25 0:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-25 0:39 srv cleanup mischief
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).