Adds srv utility program
authorBarret Rhoden <brho@cs.berkeley.edu>
Fri, 24 Jan 2014 21:16:39 +0000 (13:16 -0800)
committerBarret Rhoden <brho@cs.berkeley.edu>
Fri, 24 Jan 2014 21:26:07 +0000 (13:26 -0800)
Usage: srv DIALSTRING SRVNAME

tests/srv.c [new file with mode: 0644]
tests/write_to.c [new file with mode: 0644]

diff --git a/tests/srv.c b/tests/srv.c
new file mode 100644 (file)
index 0000000..86230b9
--- /dev/null
@@ -0,0 +1,58 @@
+/* Copyright (c) 2014 The Regents of the University of California
+ * Barret Rhoden <brho@cs.berkeley.edu>
+ * See LICENSE for details.
+ *
+ * srv DIALSTRING SRVNAME
+ *
+ * Opens DIALSTRING and drops its chan in #s at SRVNAME */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <assert.h>
+#include <net.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+int main(int argc, char *argv[])
+{
+       char *dialstring, *srvname;
+       int dfd, srvfd, ret;
+
+       #define buf_len 128
+       char buf[buf_len];
+
+       if (argc != 3) {
+               printf("Usage: %s DIALSTRING SRVNAME\n", argv[0]);
+               exit(-1);
+       }
+       dialstring = argv[1];
+       srvname = argv[2];
+
+       dfd = dial(dialstring, 0, 0, 0);
+       if (dfd < 0) {
+               perror("Unable to dial!");
+               exit(-1);
+       }
+       ret = snprintf(buf, buf_len, "#s/%s", srvname);
+       if (snprintf_overflow(ret, buf, buf_len)) {
+               printf("srvname too long\n");
+               exit(-1);
+       }
+       srvfd = open(buf, O_RDWR | O_EXCL | O_CREAT, 0666);
+       if (srvfd < 0) {
+               perror("Can't create srvvile");
+               close(dfd);
+               exit(-1);
+       }
+       ret = snprintf(buf, buf_len, "%d", dfd);
+       ret = write(srvfd, buf, ret);
+       if (ret < 0) {
+               perror("Failed to post fd");
+               close(dfd);
+               exit(-1);
+       }
+}
diff --git a/tests/write_to.c b/tests/write_to.c
new file mode 100644 (file)
index 0000000..dbca2a4
--- /dev/null
@@ -0,0 +1,42 @@
+/* Debugging app.
+ *
+ * write_to PATH STRING
+ *
+ * opens PATH, writes STRING to it */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <assert.h>
+#include <net.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+int main(int argc, char *argv[])
+{
+       char *path, *string;
+       int fd, ret;
+
+       if (argc != 3) {
+               printf("Usage: %s PATH STRING\n", argv[0]);
+               exit(-1);
+       }
+       path = argv[1];
+       string = argv[2];
+
+       fd = open(path, O_RDWR);
+       if (fd < 0) {
+               perror("Can't open path");
+               exit(-1);
+       }
+       ret = write(fd, string, strlen(string));
+       if (ret < 0) {
+               perror("Failed to write string");
+               close(fd);
+               exit(-1);
+       }
+       close(fd);
+}