BSD 4_3 development
authorCSRG <csrg@ucbvax.Berkeley.EDU>
Sat, 20 Aug 1983 08:39:32 +0000 (00:39 -0800)
committerCSRG <csrg@ucbvax.Berkeley.EDU>
Sat, 20 Aug 1983 08:39:32 +0000 (00:39 -0800)
Work on file usr/guest/sam/tests/chmod.c
Work on file usr/guest/sam/tests/Makefile
Work on file usr/guest/sam/tests/chown.c
Work on file usr/guest/sam/tests/datain.c
Work on file usr/guest/sam/tests/dgclient.c
Work on file usr/guest/sam/tests/client.c
Work on file usr/guest/sam/tests/dataout.c
Work on file usr/guest/sam/tests/efault.c
Work on file usr/guest/sam/tests/fdclient.c
Work on file usr/guest/sam/tests/emfile.c
Work on file usr/guest/sam/tests/exlock.c
Work on file usr/guest/sam/tests/dgserver.c
Work on file usr/guest/sam/tests/fds.c
Work on file usr/guest/sam/tests/fdserver.c
Work on file usr/guest/sam/tests/getpeer.c
Work on file usr/guest/sam/tests/iov.c
Work on file usr/guest/sam/tests/ipc.c
Work on file usr/guest/sam/tests/grow.c
Work on file usr/guest/sam/tests/hole.c
Work on file usr/guest/sam/tests/reader.c
Work on file usr/guest/sam/tests/raw.c
Work on file usr/guest/sam/tests/mkdir.c
Work on file usr/guest/sam/tests/pipe.c
Work on file usr/guest/sam/tests/pup.c
Work on file usr/guest/sam/tests/server.c
Work on file usr/guest/sam/tests/sendto.c
Work on file usr/guest/sam/tests/rmdir.c
Work on file usr/guest/sam/tests/rename.c
Work on file usr/guest/sam/tests/shlock.c
Work on file usr/guest/sam/tests/setuid.c
Work on file usr/guest/sam/tests/sig.c
Work on file usr/guest/sam/tests/sigstack2.c
Work on file usr/guest/sam/tests/sigstack.c
Work on file usr/guest/sam/tests/sigtstp.c
Work on file usr/guest/sam/tests/truncate.c
Work on file usr/guest/sam/tests/writer.c

Synthesized-from: CSRG/cd1/4.3

36 files changed:
usr/guest/sam/tests/Makefile [new file with mode: 0644]
usr/guest/sam/tests/chmod.c [new file with mode: 0644]
usr/guest/sam/tests/chown.c [new file with mode: 0644]
usr/guest/sam/tests/client.c [new file with mode: 0644]
usr/guest/sam/tests/datain.c [new file with mode: 0644]
usr/guest/sam/tests/dataout.c [new file with mode: 0644]
usr/guest/sam/tests/dgclient.c [new file with mode: 0644]
usr/guest/sam/tests/dgserver.c [new file with mode: 0644]
usr/guest/sam/tests/efault.c [new file with mode: 0644]
usr/guest/sam/tests/emfile.c [new file with mode: 0644]
usr/guest/sam/tests/exlock.c [new file with mode: 0644]
usr/guest/sam/tests/fdclient.c [new file with mode: 0644]
usr/guest/sam/tests/fds.c [new file with mode: 0644]
usr/guest/sam/tests/fdserver.c [new file with mode: 0644]
usr/guest/sam/tests/getpeer.c [new file with mode: 0644]
usr/guest/sam/tests/grow.c [new file with mode: 0644]
usr/guest/sam/tests/hole.c [new file with mode: 0644]
usr/guest/sam/tests/iov.c [new file with mode: 0644]
usr/guest/sam/tests/ipc.c [new file with mode: 0644]
usr/guest/sam/tests/mkdir.c [new file with mode: 0644]
usr/guest/sam/tests/pipe.c [new file with mode: 0644]
usr/guest/sam/tests/pup.c [new file with mode: 0644]
usr/guest/sam/tests/raw.c [new file with mode: 0644]
usr/guest/sam/tests/reader.c [new file with mode: 0644]
usr/guest/sam/tests/rename.c [new file with mode: 0644]
usr/guest/sam/tests/rmdir.c [new file with mode: 0644]
usr/guest/sam/tests/sendto.c [new file with mode: 0644]
usr/guest/sam/tests/server.c [new file with mode: 0644]
usr/guest/sam/tests/setuid.c [new file with mode: 0644]
usr/guest/sam/tests/shlock.c [new file with mode: 0644]
usr/guest/sam/tests/sig.c [new file with mode: 0644]
usr/guest/sam/tests/sigstack.c [new file with mode: 0644]
usr/guest/sam/tests/sigstack2.c [new file with mode: 0644]
usr/guest/sam/tests/sigtstp.c [new file with mode: 0644]
usr/guest/sam/tests/truncate.c [new file with mode: 0644]
usr/guest/sam/tests/writer.c [new file with mode: 0644]

diff --git a/usr/guest/sam/tests/Makefile b/usr/guest/sam/tests/Makefile
new file mode 100644 (file)
index 0000000..cfcdd4a
--- /dev/null
@@ -0,0 +1,192 @@
+# test programs for new stuff; also,
+# some performance evaluation programs
+#
+CFLAGS=-O
+TESTS= chmod chown client dgclient dgserver efault emfile exlock \
+       getpeer grow fds fdclient fdserver hole iov ipc mkdir pipe \
+       pup raw reader rename rmdir sendto server setuid \
+       shlock sig sigstack sigstack2 sigstack3 sigtstp truncate \
+       writer
+PERF=  datain dataout
+
+all:   ${TESTS} ${PERF}
+
+${TESTS} ${PERF}:
+       ${CC} ${CFLAGS} -o $@ $@.c
+
+clean:
+       rm -f a.out core errs ${TESTS} ${PERF}
+
+depend:
+       cat </dev/null >x.c
+       for i in ${TESTS} ${PERF}; do \
+               (echo $$i: $$i.c >>makedep; \
+               /bin/grep '^#[  ]*include' x.c $$i.c | sed \
+                       -e 's,<\(.*\)>,"/usr/include/\1",' \
+                       -e 's/:[^"]*"\([^"]*\)".*/: \1/' \
+                       -e 's/\.c//' >>makedep); done
+       echo '/^# DO NOT DELETE THIS LINE/+2,$$d' >eddep
+       echo '$$r makedep' >>eddep
+       echo 'w' >>eddep
+       cp Makefile Makefile.bak
+       ed - Makefile < eddep
+       rm eddep makedep x.c
+       echo '# DEPENDENCIES MUST END AT END OF FILE' >> Makefile
+       echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >> Makefile
+       echo '# see make depend above' >> Makefile
+
+# DO NOT DELETE THIS LINE
+# DEPENDENCIES MUST END AT END OF FILE
+chmod: chmod.c
+chmod: /usr/include/sys/file.h
+chmod: /usr/include/stdio.h
+chown: chown.c
+chown: /usr/include/sys/file.h
+client: client.c
+client: /usr/include/stdio.h
+client: /usr/include/sys/types.h
+client: /usr/include/sys/socket.h
+client: /usr/include/sys/un.h
+dgclient: dgclient.c
+dgclient: /usr/include/stdio.h
+dgclient: /usr/include/strings.h
+dgclient: /usr/include/signal.h
+dgclient: /usr/include/sys/types.h
+dgclient: /usr/include/sys/socket.h
+dgclient: /usr/include/sys/un.h
+dgserver: dgserver.c
+dgserver: /usr/include/sys/types.h
+dgserver: /usr/include/sys/socket.h
+dgserver: /usr/include/sys/un.h
+dgserver: /usr/include/stdio.h
+dgserver: /usr/include/signal.h
+dgserver: /usr/include/setjmp.h
+dgserver: /usr/include/errno.h
+efault: efault.c
+efault: /usr/include/errno.h
+emfile: emfile.c
+emfile: /usr/include/stdio.h
+exlock: exlock.c
+exlock: /usr/include/sys/file.h
+getpeer: getpeer.c
+getpeer: /usr/include/sys/types.h
+getpeer: /usr/include/sys/socket.h
+getpeer: /usr/include/netinet/in.h
+getpeer: /usr/include/stdio.h
+getpeer: /usr/include/netdb.h
+grow: grow.c
+grow: /usr/include/signal.h
+fds: fds.c
+fds: /usr/include/stdio.h
+fds: /usr/include/sys/param.h
+fds: /usr/include/sys/stat.h
+fdclient: fdclient.c
+fdclient: /usr/include/sys/types.h
+fdclient: /usr/include/sys/socket.h
+fdclient: /usr/include/sys/stat.h
+fdclient: /usr/include/sys/file.h
+fdclient: /usr/include/sys/uio.h
+fdclient: /usr/include/sys/un.h
+fdclient: /usr/include/stdio.h
+fdclient: /usr/include/signal.h
+fdserver: fdserver.c
+fdserver: /usr/include/sys/types.h
+fdserver: /usr/include/sys/socket.h
+fdserver: /usr/include/sys/wait.h
+fdserver: /usr/include/sys/uio.h
+fdserver: /usr/include/sys/un.h
+fdserver: /usr/include/stdio.h
+fdserver: /usr/include/signal.h
+fdserver: /usr/include/setjmp.h
+fdserver: /usr/include/errno.h
+hole: hole.c
+hole: /usr/include/stdio.h
+hole: /usr/include/sys/file.h
+iov: iov.c
+iov: /usr/include/stdio.h
+iov: /usr/include/sys/types.h
+iov: /usr/include/sys/socket.h
+iov: /usr/include/sys/uio.h
+ipc: ipc.c
+ipc: /usr/include/stdio.h
+ipc: /usr/include/sys/types.h
+ipc: /usr/include/sys/socket.h
+ipc: /usr/include/sys/un.h
+mkdir: mkdir.c
+mkdir: /usr/include/stdio.h
+pipe: pipe.c
+pipe: /usr/include/sys/types.h
+pipe: /usr/include/sys/socket.h
+pipe: /usr/include/signal.h
+pup: pup.c
+pup: /usr/include/stdio.h
+pup: /usr/include/netdb.h
+pup: /usr/include/sys/types.h
+pup: /usr/include/sys/uio.h
+pup: /usr/include/sys/socket.h
+pup: /usr/include/netpup/pup.h
+raw: raw.c
+raw: /usr/include/stdio.h
+raw: /usr/include/netdb.h
+raw: /usr/include/sys/types.h
+raw: /usr/include/sys/uio.h
+raw: /usr/include/sys/socket.h
+raw: /usr/include/netinet/in.h
+raw: /usr/include/netinet/in_systm.h
+raw: /usr/include/netinet/ip.h
+reader: reader.c
+reader: /usr/include/sys/file.h
+rename: rename.c
+rmdir: rmdir.c
+rmdir: /usr/include/stdio.h
+sendto: sendto.c
+sendto: /usr/include/stdio.h
+sendto: /usr/include/sys/types.h
+sendto: /usr/include/sys/socket.h
+sendto: /usr/include/netinet/in.h
+sendto: /usr/include/netdb.h
+server: server.c
+server: /usr/include/sys/types.h
+server: /usr/include/sys/socket.h
+server: /usr/include/sys/wait.h
+server: /usr/include/sys/un.h
+server: /usr/include/stdio.h
+server: /usr/include/signal.h
+server: /usr/include/setjmp.h
+server: /usr/include/errno.h
+setuid: setuid.c
+shlock: shlock.c
+shlock: /usr/include/sys/file.h
+sig: sig.c
+sig: /usr/include/signal.h
+sigstack: sigstack.c
+sigstack: /usr/include/stdio.h
+sigstack: /usr/include/signal.h
+sigstack2: sigstack2.c
+sigstack2: /usr/include/stdio.h
+sigstack2: /usr/include/signal.h
+sigstack3: sigstack3.c
+sigstack3: /usr/include/stdio.h
+sigstack3: /usr/include/signal.h
+sigtstp: sigtstp.c
+sigtstp: /usr/include/signal.h
+truncate: truncate.c
+writer: writer.c
+writer: /usr/include/sys/file.h
+datain: datain.c
+datain: /usr/include/sys/types.h
+datain: /usr/include/sys/socket.h
+datain: /usr/include/sys/wait.h
+datain: /usr/include/netinet/in.h
+datain: /usr/include/signal.h
+datain: /usr/include/errno.h
+dataout: dataout.c
+dataout: /usr/include/sys/types.h
+dataout: /usr/include/sys/socket.h
+dataout: /usr/include/netinet/in.h
+dataout: /usr/include/signal.h
+dataout: /usr/include/stdio.h
+dataout: /usr/include/netdb.h
+# DEPENDENCIES MUST END AT END OF FILE
+# IF YOU PUT STUFF HERE IT WILL GO AWAY
+# see make depend above
diff --git a/usr/guest/sam/tests/chmod.c b/usr/guest/sam/tests/chmod.c
new file mode 100644 (file)
index 0000000..bfebe82
--- /dev/null
@@ -0,0 +1,24 @@
+#include <sys/file.h>
+#include <stdio.h>
+
+main(argc, argv)
+       char *argv[];
+{
+       int fd, mode;
+
+       if (argc < 3) {
+               printf("usage: chmod file mode\n");
+               exit(1);
+       }
+       fd = open(argv[1], O_WRONLY);
+       if (fd < 0) {
+               perror("open");
+               exit(2);
+       }
+       sscanf(argv[2], "%o", &mode);
+       fprintf(stderr, "chmod %s to 0%o", argv[1], mode);
+       if (fchmod(fd, mode) < 0)
+               perror(" ");
+       else
+               fprintf(stderr, "\n");
+}
diff --git a/usr/guest/sam/tests/chown.c b/usr/guest/sam/tests/chown.c
new file mode 100644 (file)
index 0000000..74ae9fa
--- /dev/null
@@ -0,0 +1,21 @@
+#include <sys/file.h>
+
+main(argc, argv)
+       char *argv[];
+{
+       int fd, uid, gid;
+
+       if (argc < 4) {
+               printf("usage: chown file uid gid\n");
+               exit(1);
+       }
+       fd = open(argv[1], O_WRONLY);
+       if (fd < 0) {
+               perror("open");
+               exit(2);
+       }
+       uid = atoi(argv[2]);
+       gid = atoi(argv[3]);
+       if (fchown(fd, uid, gid) < 0)
+               perror("fchown");
+}
diff --git a/usr/guest/sam/tests/client.c b/usr/guest/sam/tests/client.c
new file mode 100644 (file)
index 0000000..b475ec9
--- /dev/null
@@ -0,0 +1,33 @@
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+struct sockaddr_un sun;
+
+main(argc, argv)
+       char *argv[];
+{
+       int s;
+       char buf[BUFSIZ];
+
+       s = socket(AF_UNIX, SOCK_STREAM, 0);
+       if (s < 0) {
+               perror("socket");
+               exit(1);
+       }
+       sun.sun_family = AF_UNIX;
+       strcpy(sun.sun_path, argv[1]);
+#ifdef notdef
+       if (bind(s, &sun1, strlen(argv[1]) + 2) < 0) {
+               perror("bind");
+               exit(1);
+       }
+#endif
+       if (connect(s, &sun, strlen(argv[1]) + 2) < 0) {
+               perror("connect");
+               exit(1);
+       }
+       while (fgets(buf, sizeof (buf), stdin) != NULL)
+               write(s, buf, strlen(buf));
+}
diff --git a/usr/guest/sam/tests/datain.c b/usr/guest/sam/tests/datain.c
new file mode 100644 (file)
index 0000000..cb159a8
--- /dev/null
@@ -0,0 +1,63 @@
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/wait.h>
+
+#include <netinet/in.h>
+
+#include <signal.h>
+#include <errno.h>
+
+int    catcher();
+extern int errno;
+
+main(argc, argv)
+       char *argv[];
+{
+       struct sockaddr_in sin;
+       char buf[1024];
+       int s;
+
+       if (argc < 2) {
+               printf("usage: datain port\n");
+               exit(1);
+       }
+       sin.sin_port = htons(atoi(argv[1]));
+       sin.sin_addr.s_addr = INADDR_ANY;
+       sin.sin_family = AF_INET;
+       signal(SIGPIPE, SIG_IGN);
+       signal(SIGCHLD, catcher);
+       s = socket(AF_INET, SOCK_STREAM, 0);
+       if (s < 0) {
+               perror("socket");
+               exit(1);
+       }
+       if (bind(s, &sin, sizeof (sin)) < 0) {
+               perror("bind");
+               exit(1);
+       }
+       listen(s, 3);
+       for (;;) {
+               int new = accept(s, 0, 0);
+
+               if (new < 0) {
+                       if (errno != EINTR)
+                               perror("accept");
+                       continue;
+               }
+               if (fork() == 0) {
+                       close(s);
+                       while (read(new, buf, sizeof (buf)) > 0)
+                               ;
+                       exit(0);
+               }
+               close(new);
+       }
+}
+
+catcher()
+{
+       int stat;
+
+       while (wait3(&stat, WNOHANG, 0) >= 0)
+               ;
+}
diff --git a/usr/guest/sam/tests/dataout.c b/usr/guest/sam/tests/dataout.c
new file mode 100644 (file)
index 0000000..d5e2fee
--- /dev/null
@@ -0,0 +1,67 @@
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+
+#include <signal.h>
+#include <stdio.h>
+#include <netdb.h>
+
+#define        MEGABYTES       4
+
+main(argc, argv)
+       char *argv[];
+{
+       register int i, j, mega = MEGABYTES;
+       struct sockaddr_in sin, myaddr;
+       char buf[1024];
+       int s;
+       struct hostent *hp;
+
+       if (argc < 3) {
+               printf("usage: dataout host port [# megabytes]\n");
+               exit(1);
+       }
+       hp = gethostbyname(argv[1]);
+       if (hp == NULL) {
+               printf("%s: unknown host\n", argv[1]);
+               exit(1);
+       }
+       bzero(&sin, sizeof (sin));
+       sin.sin_family = hp->h_addrtype;
+       bcopy(hp->h_addr, &sin.sin_addr, hp->h_length);
+       argv++, argc--;
+       sin.sin_port = htons(atoi(argv[1]));
+       argv++, argc--;
+       if (argc > 1) {
+               mega = atoi(argv[1]);
+               if (mega < 0 || mega > 2*MEGABYTES)
+                       printf("%d: bad # megabytes\n", mega), exit(2);
+       }
+       signal(SIGPIPE, SIG_IGN);
+       printf("send %d megabytes\n", mega);
+       s = socket(AF_INET, SOCK_STREAM, 0);
+       if (s < 0) {
+               perror("socket");
+               exit(1);
+       }
+       bzero(&myaddr, sizeof (myaddr));
+       myaddr.sin_family = sin.sin_family;
+       myaddr.sin_addr.s_addr = INADDR_ANY;
+       if (bind(s, &myaddr, sizeof (myaddr)) < 0) {
+               perror("bind");
+               exit(1);
+       }
+       if (connect(s, &sin, sizeof (sin)) < 0) {
+               perror("connect");
+               close(s);
+               exit(2);
+       }
+       mega *= 1024;
+       for (i = 0; i < mega; i++)
+               if (write(s, buf, sizeof (buf)) < 0) {
+                       perror("write");
+                       break;
+               }
+       close(s);
+}
diff --git a/usr/guest/sam/tests/dgclient.c b/usr/guest/sam/tests/dgclient.c
new file mode 100644 (file)
index 0000000..45068bd
--- /dev/null
@@ -0,0 +1,59 @@
+#include <stdio.h>
+#include <strings.h>
+#include <signal.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+struct sockaddr_un sun;
+struct sockaddr_un myname;
+
+int    catchsig();
+
+main(argc, argv)
+       char *argv[];
+{
+       int s, sunlen;
+       char buf[BUFSIZ];
+
+       if (argc < 2) {
+               printf("usage: %s socket\n", argv[0]);
+               exit(1);
+       }
+       s = socket(AF_UNIX, SOCK_DGRAM, 0);
+       if (s < 0) {
+               perror("socket");
+               exit(1);
+       }
+       sun.sun_family = AF_UNIX;
+       strcpy(sun.sun_path, argv[1]);
+       sunlen = strlen(argv[1]) + 2;
+       myname.sun_family = AF_UNIX;
+       sprintf(myname.sun_path, "dgclient%d", getpid());
+       if (bind(s, &myname, strlen(myname.sun_path) + 2) < 0) {
+               perror("dgclient: bind");
+               exit(1);
+       }
+       signal(SIGPIPE, catchsig);
+       signal(SIGINT, catchsig);
+       signal(SIGTERM, catchsig);
+       while (fgets(buf, sizeof (buf), stdin) != NULL) {
+               register char *cp = index(buf, '\n');
+
+               if (cp)
+                       *cp = '\0';
+               if (sendto(s, buf, strlen(buf), 0, &sun, sunlen) < 0)
+                       perror("dgclient: sendto");
+       }
+       unlink(myname.sun_path);
+}
+
+catchsig(s)
+       int s;
+{
+
+       psignal(s, "Client");
+       unlink(myname.sun_path);
+       exit(1);
+}
diff --git a/usr/guest/sam/tests/dgserver.c b/usr/guest/sam/tests/dgserver.c
new file mode 100644 (file)
index 0000000..4acbe04
--- /dev/null
@@ -0,0 +1,58 @@
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include <stdio.h>
+#include <signal.h>
+#include <setjmp.h>
+#include <errno.h>
+
+struct sockaddr_un sun;
+jmp_buf        j;
+int    catchsig();
+
+main(argc, argv)
+       char *argv[];
+{
+       int s, n;
+       char buf[BUFSIZ];
+
+       s = socket(AF_UNIX, SOCK_DGRAM, 0);
+       if (s < 0) {
+               perror("dgserver: socket");
+               exit(1);
+       }
+       sun.sun_family = AF_UNIX;
+       strcpy(sun.sun_path, argv[1]);
+       if (bind(s, &sun, strlen(argv[1]) + 2) < 0) {
+               perror("dgserver: bind");
+               exit(1);
+       }
+       signal(SIGTERM, catchsig);
+       signal(SIGPIPE, catchsig);
+       if (setjmp(j)) {
+               unlink(argv[1]);
+               exit(1);
+       }
+       for (;;) {
+               struct sockaddr_un from;
+               int fromlen = sizeof (from);
+               extern int errno;
+
+               n = recvfrom(s, buf, sizeof (buf), 0, &from, &fromlen);
+               if (n < 0) {
+                       if (errno != EINTR)
+                               perror("dgserver: recvfrom");
+                       continue;
+               }
+               printf("Server: message \"%.*s\"\n", n, buf);
+       }
+}
+
+catchsig(s)
+       int s;
+{
+
+       psignal(s, "Server");
+       longjmp(j, 1);
+}
diff --git a/usr/guest/sam/tests/efault.c b/usr/guest/sam/tests/efault.c
new file mode 100644 (file)
index 0000000..bf97d6b
--- /dev/null
@@ -0,0 +1,8 @@
+#include <errno.h>
+
+main()
+{
+
+       write(1, 0xabcd, 1024);
+       perror("write");
+}
diff --git a/usr/guest/sam/tests/emfile.c b/usr/guest/sam/tests/emfile.c
new file mode 100644 (file)
index 0000000..c7c4990
--- /dev/null
@@ -0,0 +1,25 @@
+#include <stdio.h>
+
+main(argc,argv)
+       char *argv[];
+{
+       int fd, count, cc, buffer;
+       char buf[BUFSIZ + 8];
+
+       fd = open(argv[1], 0);
+       if (fd < 0) {
+               perror(argv[1]);
+               exit(-1);
+       }
+       buffer = count = 0;
+       while ((cc = read(fd, buf, BUFSIZ)) != 0 ) {
+               if (cc == -1)
+                        perror("read");
+               else {
+                        count += cc;
+                        buf[cc] = '\0';
+               }
+               buffer++;
+       }
+       fprintf(stderr,"%s: %d\n", argv[1], count);
+}
diff --git a/usr/guest/sam/tests/exlock.c b/usr/guest/sam/tests/exlock.c
new file mode 100644 (file)
index 0000000..1e2b0c5
--- /dev/null
@@ -0,0 +1,14 @@
+#include <sys/file.h>
+
+main(argc, argv)
+       char *argv[];
+{
+       int fd = open(argv[1], O_RDONLY);
+
+       if (fd < 0)
+               exit(1);
+       if (flock(fd, LOCK_EX) < 0)
+               perror("flock");
+       printf("got exclusive lock\n");
+       sigpause(0);
+}
diff --git a/usr/guest/sam/tests/fdclient.c b/usr/guest/sam/tests/fdclient.c
new file mode 100644 (file)
index 0000000..c00a3d8
--- /dev/null
@@ -0,0 +1,117 @@
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/file.h>
+#include <sys/uio.h>
+#include <sys/un.h>
+
+#include <stdio.h>
+#include <signal.h>
+
+struct sockaddr_un to;
+struct sockaddr_un from;
+struct msghdr msg;
+struct iovec iov[1];
+char   myname[1024];
+
+int    catchsig();
+
+main(argc, argv)
+       char *argv[];
+{
+       int s, len, tolen, fromlen, fd;
+       char buf[BUFSIZ];
+       struct stat sb;
+
+       if (argc < 3) {
+               printf("usage: %s socket file\n", argv[0]);
+               exit(1);
+       }
+       if (stat(argv[1], &sb) < 0) {
+               perror(argv[1]);
+               exit(1);
+       }
+       if ((sb.st_mode & S_IFMT) != S_IFSOCK) {
+               printf("%s: not a socket\n", argv[1]);
+               exit(1);
+       }
+       fd = open(argv[2], O_RDONLY);
+       if (fd < 0) {
+               perror(argv[2]);
+               exit(1);
+       }
+       s = socket(AF_UNIX, SOCK_DGRAM, 0);
+       if (s < 0) {
+               perror("socket");
+               exit(1);
+       }
+       from.sun_family = AF_UNIX;
+       sprintf(myname, "client%d", getpid());
+       strcpy(from.sun_path, myname);
+       if (bind(s, &from, strlen(from.sun_path) + 2) < 0) {
+               perror("fdclient: bind");
+               exit(1);
+       }
+       signal(SIGPIPE, catchsig);
+       signal(SIGINT, catchsig);
+       to.sun_family = AF_UNIX;
+       strcpy(to.sun_path, argv[1]);
+       strcpy(buf, myname);
+       len = strlen(buf);
+       tolen = strlen(to.sun_path) + 2;
+       printf("Client: send greeting from %s\n", myname); fflush(stdout);
+       if (sendto(s, buf, len, 0, &to, tolen) < 0) {
+               perror("fdclient: sendto");
+               goto bad;
+       }
+       *from.sun_path = '\0';
+       fromlen = sizeof (from);
+       len = recvfrom(s, buf, sizeof (buf), 0, &from, &fromlen);
+       if (len < 0) {
+               perror("fdclient: recvfrom");
+               goto bad;
+       }
+       printf("Client: message received");
+       if (strlen(from.sun_path) > 0)
+               printf(" from %s", from.sun_path);
+       if (len > 0)
+               printf(" \"%.*s\"", len, buf);
+       putchar('\n'); fflush(stdout);
+       msg.msg_name = (caddr_t)&to;
+       msg.msg_namelen = tolen;
+       iov->iov_base = argv[2];
+       iov->iov_len = strlen(argv[2]);
+       msg.msg_iov = iov;
+       msg.msg_iovlen = 1;
+       msg.msg_accrights = (caddr_t)&fd;
+       msg.msg_accrightslen = sizeof (fd);
+       printf("Client: send \"%s\"\n", argv[2]); fflush(stdout);
+       if (sendmsg(s, &msg, 0) < 0) {
+               perror("fdclient: sendmsg");
+               goto bad;
+       }
+       *from.sun_path = '\0';
+       fromlen = sizeof (from);
+       len = recvfrom(s, buf, sizeof (buf), 0, &from, &fromlen);
+       if (len < 0) {
+               perror("fdclient: recvfrom");
+               goto bad;
+       }
+       printf("Client: message received");
+       if (strlen(from.sun_path) > 0)
+               printf(" from %s", from.sun_path);
+       if (len > 0)
+               printf(" \"%.*s\"", len, buf);
+       putchar('\n'); fflush(stdout);
+bad:
+       unlink(myname);
+}
+
+catchsig(s)
+       int s;
+{
+
+       psignal(s, "Client");
+       unlink(myname);
+       exit(1);
+}
diff --git a/usr/guest/sam/tests/fds.c b/usr/guest/sam/tests/fds.c
new file mode 100644 (file)
index 0000000..067ea7a
--- /dev/null
@@ -0,0 +1,50 @@
+#include <stdio.h>
+#include <sys/param.h>
+#include <sys/stat.h>
+
+struct types {
+       int     mode;
+       char    *name;
+} types[] = {
+       { S_IFDIR,      "directory" },
+       { S_IFCHR,      "character special" },
+       { S_IFBLK,      "block special" },
+       { S_IFREG,      "regular" },
+       { S_IFLNK,      "symbolic link" },
+       { S_IFSOCK,     "socket" },
+       { 0, 0 }
+};
+
+main()
+{
+       register int i, j = getdtablesize();
+       struct stat sb;
+       char *filetype();
+
+       for (i = 0; i < j; i++) {
+               if (fstat(i, &sb) < 0)
+                       continue;
+               fprintf(stderr, "%d: %s, inode #%d, mode %o, dev (%d,%d)",
+                   i, filetype(sb.st_mode & S_IFMT), sb.st_ino,
+                   sb.st_mode &~ S_IFMT,
+                   major(sb.st_dev), minor(sb.st_dev));
+               if ((sb.st_mode & S_IFMT) == S_IFCHR ||
+                   (sb.st_mode & S_IFMT) == S_IFBLK)
+                       fprintf(stderr, ", rdev (%d, %d)",
+                           major(sb.st_rdev), minor(sb.st_rdev));
+               putc('\n', stderr);
+       }
+       exit(0);
+}
+
+char *
+filetype(t)
+       register int t;
+{
+       register struct types *p;
+
+       for (p = types; p->mode; p++)
+               if (p->mode == t)
+                       return (p->name);
+       return ("???");
+}
diff --git a/usr/guest/sam/tests/fdserver.c b/usr/guest/sam/tests/fdserver.c
new file mode 100644 (file)
index 0000000..dd1185d
--- /dev/null
@@ -0,0 +1,136 @@
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/wait.h>
+#include <sys/uio.h>
+#include <sys/un.h>
+
+#include <stdio.h>
+#include <signal.h>
+#include <setjmp.h>
+#include <errno.h>
+
+struct sockaddr_un sun;
+jmp_buf        j;
+int    catchsig();
+
+main(argc, argv)
+       char *argv[];
+{
+       int s, n;
+       char buf[BUFSIZ];
+
+       if (argc < 2) {
+               printf("usage: %s socket\n", argv[0]);
+               exit(1);
+       }
+       s = socket(AF_UNIX, SOCK_DGRAM, 0);
+       if (s < 0) {
+               perror("socket");
+               exit(1);
+       }
+       sun.sun_family = AF_UNIX;
+       strcpy(sun.sun_path, argv[1]);
+       if (bind(s, &sun, strlen(argv[1]) + 2) < 0) {
+               perror("fdserver: bind");
+               exit(1);
+       }
+       signal(SIGINT, catchsig);
+       signal(SIGTERM, catchsig);
+       signal(SIGPIPE, catchsig);
+       if (setjmp(j)) {
+               unlink(argv[1]);
+               exit(1);
+       }
+       for (;;) {
+               struct sockaddr_un from;
+               int fromlen = sizeof (from), f;
+               extern int errno;
+
+               n = recvfrom(s, buf, sizeof (buf), 0, &from, &fromlen);
+               if (n < 0) {
+                       if (errno != EINTR)
+                               perror("fdserver: recvfrom");
+                       continue;
+               }
+               printf("Server: message received");
+               if (strlen(from.sun_path) > 0)
+                       printf(" from %s", from.sun_path);
+               if (n > 0)
+                       printf(" \"%.*s\"", n, buf);
+               putchar('\n'); fflush(stdout);
+               if (n > 0)
+                       shake(s, buf);
+       }
+}
+
+catchsig(s)
+       int s;
+{
+
+       psignal(s, "Server");
+       longjmp(j, 1);
+}
+
+shake(s, name)
+       int s;
+       char *name;
+{
+       char buf[BUFSIZ], filename[BUFSIZ];
+       struct msghdr msg;
+       struct iovec iov[1];
+       struct sockaddr_un to, *sun = &to;
+       int newfd, n;
+
+       strcpy(buf, "gotcha...");
+       sun->sun_family = AF_UNIX;
+       strcpy(sun->sun_path, name);
+       n = sizeof (sun->sun_family) + strlen(sun->sun_path);
+       printf("Server: send ack\n"); fflush(stdout);
+       if (sendto(s, buf, strlen(buf), 0, sun, n) < 0) {
+               perror("fdserver: sendto");
+               return;
+       }
+#ifdef notdef
+       newfd = sizeof (to);
+       n = recvfrom(s, buf, sizeof (buf), 0, sun, n);
+       if (n < 0) {
+               perror("fdserver: recvfrom");
+               return;
+       }
+       printf("Server: recvfrom %d, from %s, buf \"%.*s\"\n", n,
+           sun->sun_path, n, buf);
+#endif
+       msg.msg_name = (caddr_t)sun;
+       msg.msg_namelen = sizeof (*sun);
+       iov->iov_base = filename;
+       iov->iov_len = sizeof (filename);
+       msg.msg_iov = iov;
+       msg.msg_iovlen = 1;
+       msg.msg_accrights = (caddr_t)&newfd;
+       msg.msg_accrightslen = sizeof (newfd);
+       n = recvmsg(s, &msg, 0);
+       if (n < 0) {
+               perror("fdserver: recvmsg");
+               return;
+       }
+       printf("Server: received file");
+       if (iov->iov_len > 0)
+               printf(" \"%.*s\"", iov->iov_len, iov->iov_base);
+       if (strlen(sun->sun_path) > 0)
+               printf(" from %s", sun->sun_path);
+       printf("; n %d\n", n); fflush(stdout);
+       if (n <= 0 || newfd < 0 || newfd >= getdtablesize())
+               printf("fdserver: bad new fd %d\n", newfd);
+       else {
+               printf("Server: file contents:\n");
+               while ((n = read(newfd, buf, sizeof (buf))) > 0)
+                       write(1, buf, n);
+               close(newfd);
+       }
+       strcpy(buf, "thank you...");
+       strcpy(sun->sun_path, name);
+       n = sizeof (sun->sun_family) + strlen(sun->sun_path);
+       printf("Server: send thank you\n"); fflush(stdout);
+       if (sendto(s, buf, strlen(buf), 0, sun, n) < 0)
+               perror("fdserver: sendto");
+}
diff --git a/usr/guest/sam/tests/getpeer.c b/usr/guest/sam/tests/getpeer.c
new file mode 100644 (file)
index 0000000..42bf2b3
--- /dev/null
@@ -0,0 +1,54 @@
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+
+#include <stdio.h>
+#include <netdb.h>
+
+main(argc, argv)
+       char *argv[];
+{
+       struct sockaddr_in sin, myaddr;
+       int s, sinlen;
+       struct hostent *hp;
+
+       if (argc < 3) {
+               printf("usage: getpeer host port\n");
+               exit(1);
+       }
+       hp = gethostbyname(argv[1]);
+       if (hp == NULL) {
+               printf("%s: unknown host\n", argv[1]);
+               exit(1);
+       }
+       bzero(&sin, sizeof (sin));
+       sin.sin_family = hp->h_addrtype;
+       bcopy(hp->h_addr, &sin.sin_addr, hp->h_length);
+       argv++, argc--;
+       sin.sin_port = htons(atoi(argv[1]));
+       s = socket(AF_INET, SOCK_STREAM, 0);
+       if (s < 0) {
+               perror("socket");
+               exit(1);
+       }
+       bzero(&myaddr, sizeof (myaddr));
+       myaddr.sin_family = sin.sin_family;
+       myaddr.sin_addr.s_addr = INADDR_ANY;
+       if (bind(s, &myaddr, sizeof (myaddr)) < 0) {
+               perror("bind");
+               exit(1);
+       }
+       if (connect(s, &sin, sizeof (sin)) < 0) {
+               perror("connect");
+               close(s);
+               exit(2);
+       }
+       sinlen = sizeof (sin);
+       if (getpeername(s, &sin, &sinlen) < 0)
+               perror("getpeer");
+       else
+               printf("peer: len %d, %s.%d\n", sinlen, 
+                   inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
+       close(s);
+}
diff --git a/usr/guest/sam/tests/grow.c b/usr/guest/sam/tests/grow.c
new file mode 100644 (file)
index 0000000..f94726b
--- /dev/null
@@ -0,0 +1,18 @@
+#include <signal.h>
+
+catch(s, code, scp)
+       int s, code;
+       struct sigcontext *scp;
+{
+
+       sigsetmask(0);
+       kill(getpid(), s);
+}
+
+main()
+{
+
+       signal(SIGINT, catch);
+       for (;;)
+               sigpause(0);
+}
diff --git a/usr/guest/sam/tests/hole.c b/usr/guest/sam/tests/hole.c
new file mode 100644 (file)
index 0000000..ced04a0
--- /dev/null
@@ -0,0 +1,32 @@
+#include <stdio.h>
+#include <sys/file.h>
+
+main(argc, argv)
+       char *argv[];
+{
+       int fd, n, i;
+       char buf[BUFSIZ];
+
+       if (argc < 2)
+               exit(1);
+       fd = open(argv[1], O_RDWR|O_CREAT|O_TRUNC, 0666);
+       if (write(fd, "test\n", 5) < 0)
+               perror("write");
+       if (lseek(fd, 1024*100, L_XTND) < 0)
+               perror("lseek XTND");
+       if (write(fd, "hole\n", 5) < 0)
+               perror("write");
+       if (lseek(fd, 0, L_SET) < 0)
+               perror("lseek SET");
+       do {
+               n = read(fd, buf, sizeof (buf));
+               if (n < 0) {
+                       perror("read");
+                       break;
+               }
+               for (i = 0; i < n; i++)
+                       if (buf[i])
+                               printf("%d: %c\n",
+                                   tell(fd) - (sizeof (buf) - i), buf[i]);
+       } while (n > 0);
+}
diff --git a/usr/guest/sam/tests/iov.c b/usr/guest/sam/tests/iov.c
new file mode 100644 (file)
index 0000000..2f4814d
--- /dev/null
@@ -0,0 +1,49 @@
+#include <stdio.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
+
+char   buf[BUFSIZ];
+struct iovec iov[16];
+
+main()
+{
+       int sv[2], i;
+       char c1, c2, c3;
+       register struct iovec *v;
+
+       if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv) < 0)
+               perror("socketpair");
+       iov[0].iov_base = &c1;
+       iov[0].iov_len = sizeof (c1);
+       iov[1].iov_base = &c2;
+       iov[1].iov_len = sizeof (c2);
+       iov[2].iov_base = &c3;
+       iov[2].iov_len = sizeof (c3);
+       iov[3].iov_base = buf;
+       iov[3].iov_len = sizeof (buf);
+       if (fork() == 0) {
+               close(sv[0]);
+               c1 = '1'; c2 = '2'; c3 = '3';
+               strcpy(buf, "this is a test");
+               iov[3].iov_len = strlen(buf);
+               i = writev(sv[1], iov, 4);
+               if (i < 0)
+                       perror("writev");
+               exit(0);
+       }
+       close(sv[1]);
+       i = readv(sv[0], iov, 4);
+       if (i < 0) {
+               perror("readv");
+               exit(1);
+       }
+       for (v = iov; v < iov + 4; v++) {
+               if (i < v->iov_len)
+                       v->iov_len = i;
+               printf("iov[%d] <%d, %.*s>\n", v - iov,
+                       v->iov_len, v->iov_len, v->iov_base);
+               i -= v->iov_len;
+       }
+}
diff --git a/usr/guest/sam/tests/ipc.c b/usr/guest/sam/tests/ipc.c
new file mode 100644 (file)
index 0000000..5c288f2
--- /dev/null
@@ -0,0 +1,37 @@
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+main(argc, argv)
+       char *argv[];
+{
+       char buf[BUFSIZ];
+       int sv[2], n;
+
+       if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv) < 0) {
+               perror("socketpair");
+               exit(1);
+       }
+       if (fork() == 0) {
+               close(sv[0]);
+               for (;;) {
+                       n = read(sv[1], buf, sizeof (buf));
+                       if (n < 0) {
+                               perror("read");
+                               break;
+                       }
+                       if (n == 0)
+                               break;
+                       printf("read %d:\n", n);
+                       write(1, buf, n);
+               }
+               printf("done...\n");
+               exit(0);
+       }
+       close(sv[1]);
+       while (fgets(buf, sizeof (buf), stdin) != NULL)
+               write(sv[0], buf, strlen(buf));
+       close(sv[0]);
+       wait((int *)0);
+}
diff --git a/usr/guest/sam/tests/mkdir.c b/usr/guest/sam/tests/mkdir.c
new file mode 100644 (file)
index 0000000..8c94eca
--- /dev/null
@@ -0,0 +1,20 @@
+static char *sccsid = "%W% (Berkeley) %G%";
+/*
+ * make directory
+ */
+#include <stdio.h>
+
+main(argc, argv)
+       char *argv[];
+{
+       register int errors = 0;
+
+       if(argc < 2) {
+               fprintf(stderr, "mkdir: arg count\n");
+               exit(1);
+       }
+       while(--argc)
+               if (mkdir(*++argv, 0777) < 0)
+                       perror(*argv), errors++;
+       exit(errors != 0);
+}
diff --git a/usr/guest/sam/tests/pipe.c b/usr/guest/sam/tests/pipe.c
new file mode 100644 (file)
index 0000000..8dafba8
--- /dev/null
@@ -0,0 +1,34 @@
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <signal.h>
+
+#define        MEGABYTES       2
+
+char buf[1024];
+int p[2];
+
+main(argc, argv)
+       char *argv[];
+{
+       register int i, j, child;
+
+       pipe(p);
+       if (child = fork()) {
+               sleep(2);
+               for (i = 0; i < MEGABYTES; i++)
+                       for (j = 0; j < 1000; j++)
+                               if (write(p[1], buf, sizeof (buf)) < 0) {
+                                       perror("write");
+                                       kill(child, SIGKILL);
+                                       exit(5);
+                               }
+               close(p[1]);
+               exit(0);
+       }
+       for (i = 0; i < MEGABYTES; i++)
+               for (j = 0; j < 1000; j++)
+                       if (read(p[0], buf, sizeof (buf)) < 0) {
+                               perror("read");
+                               exit(1);
+                       }
+}
diff --git a/usr/guest/sam/tests/pup.c b/usr/guest/sam/tests/pup.c
new file mode 100644 (file)
index 0000000..c59b369
--- /dev/null
@@ -0,0 +1,84 @@
+#include <stdio.h>
+#include <netdb.h>
+
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <sys/socket.h>
+
+#include <netpup/pup.h>
+
+char   myname[32];
+struct pup_header pup;
+char   buf[BUFSIZ];
+struct iovec iov[2];
+
+main(argc, argv)
+       char *argv[];
+{
+       struct sockaddr_pup sup;
+       struct hostent *hp;
+       int s, n, i;
+
+       if (argc < 2) {
+               printf("nothing to send\n");
+               exit(1);
+       }
+       s = socket(AF_PUP, SOCK_RAW, 0);
+       if (s < 0) {
+               perror("socket");
+               exit(1);
+       }
+       bzero(&sup, sizeof (sup));
+       sup.spup_family = AF_PUP;
+       if (gethostname(myname, sizeof (myname)) < 0) {
+               perror("gethostname");
+               exit(1);
+       }
+       hp = gethostbyname(myname);
+       if (hp == 0) {
+               printf("%s: don't know my name\n", myname);
+               exit(1);
+       }
+       sup.spup_host = inet_lnaof(*(int *)hp->h_addr);
+       sup.spup_net = inet_netof(*(int *)hp->h_addr);
+       if (connect(s, &sup, sizeof (sup)) < 0) {
+               perror("connect");
+               exit(1);
+       }
+       iov[0].iov_base = (caddr_t)&pup;
+       iov[0].iov_len = sizeof (pup);
+       iov[1].iov_base = buf;
+       pup.pup_type = 99;
+       strcpy(buf, argv[1]);
+#define        even(x) (((x) + 1) & ~1)
+       iov[1].iov_len = even(strlen(iov[1].iov_base)) + 2;
+       if (writev(s, iov, 2) < 0) {
+               perror("writev");
+               exit(1);
+       }
+       iov[1].iov_len = sizeof (buf);
+       n = readv(s, iov, 2);
+       if (n < 0) {
+               perror("readv");
+               exit(1);
+       }
+       printf("read returns %d bytes, %d data\n", n, n - sizeof (pup));
+       printpup(&pup);
+       n -= sizeof (pup);
+       printf("checksum: %x\n", ntohs(*(u_short *)(buf + n - 2)));
+       buf[n - 2] = '\0';
+       printf("data: %s\n", buf);
+}
+
+printpup(p)
+       register struct pup_header *p;
+{
+
+       printf("length: %d tcontrol %d\n", ntohs(p->pup_length),
+           p->pup_tcontrol);
+       printf("type: %d id: %d\n", p->pup_type, ntohs(p->pup_id));
+       printf("dnet: %d dhost: %d dsock: %x\n",
+           p->pup_dnet, p->pup_dhost, ntohl(*(int *)(p->pup_dsock)));
+       printf("snet: %d shost: %d ssock: %x\n",
+           p->pup_snet, p->pup_shost, ntohl(*(int *)(p->pup_ssock)));
+}
diff --git a/usr/guest/sam/tests/raw.c b/usr/guest/sam/tests/raw.c
new file mode 100644 (file)
index 0000000..7c27a80
--- /dev/null
@@ -0,0 +1,77 @@
+#include <stdio.h>
+#include <netdb.h>
+
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+
+char   myname[32];
+struct ip ip;
+char   buf[BUFSIZ];
+struct iovec iov[2];
+
+main(argc, argv)
+       char *argv[];
+{
+       struct sockaddr_in sin;
+       struct hostent *hp;
+       int s, n, i;
+
+       if (argc < 2) {
+               printf("nothing to send\n");
+               exit(1);
+       }
+       s = socket(AF_INET, SOCK_RAW, 0);
+       if (s < 0) {
+               perror("socket");
+               exit(1);
+       }
+       bzero(&sin, sizeof (sin));
+       sin.sin_family = AF_INET;
+       if (gethostname(myname, sizeof (myname)) < 0) {
+               perror("gethostname");
+               exit(1);
+       }
+       hp = gethostbyname(myname);
+       if (hp == 0) {
+               printf("%s: don't know my name\n", myname);
+               exit(1);
+       }
+       bcopy(hp->h_addr, &sin.sin_addr, hp->h_length);
+       if (connect(s, &sin, sizeof (sin)) < 0) {
+               perror("connect");
+               exit(1);
+       }
+       if (write(s, argv[1], strlen(argv[1])) < 0) {
+               perror("writev");
+               exit(1);
+       }
+       iov[0].iov_base = (caddr_t)&ip;
+       iov[0].iov_len = sizeof (ip);
+       iov[1].iov_base = buf;
+       iov[1].iov_len = sizeof (buf);
+       n = readv(s, iov, 2);
+       if (n < 0) {
+               perror("readv");
+               exit(1);
+       }
+       printf("read returns %d bytes, %d data\n", n, n - sizeof (ip));
+       printip(&ip);
+       printf("data: %s\n", buf);
+}
+
+printip(ip)
+       register struct ip *ip;
+{
+
+       printf("header length: %d version %d\n", ip->ip_hl, ip->ip_v);
+       printf("type of service: %d total length %d\n", ip->ip_tos, ip->ip_len);
+       printf("id: %x frag offset: %x ttl: %d protocol: %d\n",
+           ip->ip_id, ip->ip_off, ip->ip_ttl, ip->ip_p);
+       printf("checksum: %d source: %s dst: %s\n", ip->ip_sum,
+           inet_ntoa(ip->ip_src), inet_ntoa(ip->ip_dst));
+}
diff --git a/usr/guest/sam/tests/reader.c b/usr/guest/sam/tests/reader.c
new file mode 100644 (file)
index 0000000..922385f
--- /dev/null
@@ -0,0 +1,40 @@
+#include <sys/file.h>
+
+char buf[10] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
+main()
+{
+       int fd, n;
+
+       fd = open("./foo", FRDWR|FCREATE, 0666);
+       if (fd < 0)
+               perror("open");
+       printf("open successful\n");
+       n = flock(fd, FSHLOCK);
+       if (n < 0)
+               perror("read lock");
+       else
+               printf("got read lock\n");
+       n = read(fd, buf, sizeof (buf));
+       printf("n = %d ", n);
+       if (n < 0)
+               perror("read");
+       else
+               putchar('\n');
+       n = flock(fd, FUNLOCK);
+       if (n < 0)
+               perror("unlock");
+       else
+               printf("unlocked\n");
+       n = flock(fd, FSHLOCK);
+       if (n < 0)
+               perror("read lock");
+       else
+               printf("got read lock\n");
+       n = read(fd, buf, sizeof (buf));
+       printf("n = %d ", n);
+       if (n < 0)
+               perror("read");
+       else
+               putchar('\n');
+       pause();
+}
diff --git a/usr/guest/sam/tests/rename.c b/usr/guest/sam/tests/rename.c
new file mode 100644 (file)
index 0000000..b7ff783
--- /dev/null
@@ -0,0 +1,10 @@
+main(argc, argv)
+       char *argv[];
+{
+       if (argc < 3) {
+               printf("rename from to\n");
+               exit(1);
+       }
+       if (rename(argv[1], argv[2]) < 0)
+               perror("rename");
+}
diff --git a/usr/guest/sam/tests/rmdir.c b/usr/guest/sam/tests/rmdir.c
new file mode 100644 (file)
index 0000000..adfe111
--- /dev/null
@@ -0,0 +1,20 @@
+static char *sccsid = "%W% (Berkeley) %G%";
+/*
+ * remove directory
+ */
+#include <stdio.h>
+
+main(argc, argv)
+       char *argv[];
+{
+       register int errors = 0;
+
+       if(argc < 2) {
+               fprintf(stderr, "rmdir: arg count\n");
+               exit(1);
+       }
+       while(--argc)
+               if (rmdir(*++argv) < 0)
+                       perror(*argv), errors++;
+       exit(errors != 0);
+}
diff --git a/usr/guest/sam/tests/sendto.c b/usr/guest/sam/tests/sendto.c
new file mode 100644 (file)
index 0000000..9ab7415
--- /dev/null
@@ -0,0 +1,67 @@
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+
+main(argc, argv)
+       char *argv[];
+{
+       struct sockaddr_in sin;
+       struct hostent *hp;
+       struct servent *sp;
+       int s, buflen;
+       char buf[BUFSIZ], *ntoa();
+
+       if (argc < 2) {
+               printf("usage: mesg service\n");
+               exit(1);
+       }
+       sp = getservbyname(argv[1], "udp");
+       if (sp == NULL)   {
+               printf("biff: no service\n");
+               exit(1);
+       }
+       hp = gethostbyname("localhost");
+       if (hp == NULL) {
+               printf("localhost: no host entry\n");
+               exit(1);
+       }
+       bzero(&sin, sizeof (sin));
+       sin.sin_family = hp->h_addrtype;
+       sin.sin_port = sp->s_port;
+       bcopy(hp->h_addr, &sin.sin_addr, hp->h_length);
+       s = socket(SOCK_DGRAM, AF_INET, 0);
+       if (s < 0) {
+               perror("socket");
+               exit(1);
+       }
+       printf("Test message?\n");
+       fflush(stdout);
+       if (fgets(buf, sizeof (buf), stdin) == NULL) {
+               printf("No text?\n");
+               exit(1);
+       }
+       buflen = strlen(buf);
+       printf("sendto %s.%d\n", ntoa(sin.sin_addr),
+               (unsigned)ntohs(sin.sin_port));
+       if (sendto(s, buf, buflen, 0, &sin, sizeof (sin)) < 0)
+               perror("sendto");
+}
+
+/*
+ * Convert network-format internet address
+ * to base 256 d.d.d.d representation.
+ */
+char *
+ntoa(in)
+       struct in_addr in;
+{
+       static char b[18];
+       register char *p;
+
+       p = (char *)&in;
+#define        UC(b)   (((int)b)&0xff)
+       sprintf(b, "%d.%d.%d.%d", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3]));
+       return (b);
+}
diff --git a/usr/guest/sam/tests/server.c b/usr/guest/sam/tests/server.c
new file mode 100644 (file)
index 0000000..ee8e978
--- /dev/null
@@ -0,0 +1,99 @@
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/wait.h>
+#include <sys/un.h>
+
+#include <stdio.h>
+#include <signal.h>
+#include <setjmp.h>
+#include <errno.h>
+
+struct sockaddr_un sun;
+jmp_buf        j;
+int    reapchild();
+int    catchkill();
+
+main(argc, argv)
+       char *argv[];
+{
+       int s;
+
+       s = socket(AF_UNIX, SOCK_STREAM, 0);
+       if (s < 0) {
+               perror("socket");
+               exit(1);
+       }
+       sun.sun_family = AF_UNIX;
+       strcpy(sun.sun_path, argv[1]);
+       if (bind(s, &sun, strlen(argv[1]) + 2) < 0) {
+               perror("bind");
+               exit(1);
+       }
+       if (listen(s, 2) < 0) {
+               perror("listen");
+               unlink(argv[1]);
+               exit(1);
+       }
+       signal(SIGTERM, catchkill);
+       signal(SIGCHLD, reapchild);
+       if (setjmp(j)) {
+               unlink(argv[1]);
+               exit(1);
+       }
+       for (;;) {
+               struct sockaddr_un from;
+               int fromlen = sizeof (from), f;
+               extern int errno;
+
+               f = accept(s, &from, &fromlen);
+               if (f < 0) {
+                       if (errno != EINTR)
+                               perror("accept");
+                       continue;
+               }
+               printf("connection");
+               if (fromlen > 0)
+                       printf(" from %.*s\n", fromlen, from.sun_path);
+               if (fork() == 0) {
+                       close(s);
+                       doit(f);
+                       exit(0);
+               }
+               close(f);
+       }
+}
+
+reapchild()
+{
+       struct wait status;
+
+       while (wait3(&status, WNOHANG, 0) > 0)
+               ;
+}
+
+catchkill()
+{
+
+       longjmp(j, 1);
+}
+
+doit(s)
+       int s;
+{
+       char buf[BUFSIZ];
+       int n;
+
+       for (;;) {
+               n = read(s, buf, sizeof (buf));
+               if (n < 0) {
+                       perror("read");
+                       break;
+               }
+               if (n == 0)
+                       break;
+               printf("read %d:\n", n);
+               fflush(stdout);
+               write(fileno(stdout), buf, n);
+       }
+       printf("done...\n");
+}
diff --git a/usr/guest/sam/tests/setuid.c b/usr/guest/sam/tests/setuid.c
new file mode 100644 (file)
index 0000000..4e834fb
--- /dev/null
@@ -0,0 +1,9 @@
+main()
+{
+       int uid;
+
+       printf("euid=%d ruid=%d\n", geteuid(), uid = getuid());
+       if (setuid(uid) < 0)
+               perror("setuid");
+       printf("euid=%d ruid=%d\n", geteuid(), uid = getuid());
+}
diff --git a/usr/guest/sam/tests/shlock.c b/usr/guest/sam/tests/shlock.c
new file mode 100644 (file)
index 0000000..1003dd5
--- /dev/null
@@ -0,0 +1,14 @@
+#include <sys/file.h>
+
+main(argc, argv)
+       char *argv[];
+{
+       int fd = open(argv[1], O_RDONLY);
+
+       if (fd < 0)
+               exit(1);
+       if (flock(fd, LOCK_SH) < 0)
+               perror("flock");
+       printf("got shared lock\n");
+       sigpause(0);
+}
diff --git a/usr/guest/sam/tests/sig.c b/usr/guest/sam/tests/sig.c
new file mode 100644 (file)
index 0000000..5ae8be7
--- /dev/null
@@ -0,0 +1,20 @@
+#include <signal.h>
+
+main()
+{
+       int i, (*a)();
+       extern char *sys_siglist[];
+
+       if (sigblock(0))
+               printf("blocked: %x\n", sigblock(0));
+       for (i = 1; i < NSIG; i++) {
+               a = signal(i, SIG_DFL); signal(i, a);
+               if (a == SIG_DFL || a == BADSIG)
+                       continue;
+               printf("%s: ", sys_siglist[i]);
+               if (a == SIG_IGN)
+                       printf("SIG_IGN\n");
+               else
+                       printf("%x\n", a);
+       }
+}
diff --git a/usr/guest/sam/tests/sigstack.c b/usr/guest/sam/tests/sigstack.c
new file mode 100644 (file)
index 0000000..0ea1526
--- /dev/null
@@ -0,0 +1,35 @@
+
+#include <stdio.h>
+#include <signal.h>
+
+onintr(signo, code, sc)
+       struct sigcontext *sc;
+{
+       int x;
+
+       fprintf(stderr,
+           "sig=%u, code=%u, onstack=%u, mask=%u, sp=%x, pc=%x, ps=%x\n",
+           signo, code, sc->sc_onstack, sc->sc_mask, sc->sc_sp, sc->sc_pc,
+           sc->sc_ps);
+       fprintf(stderr, "&x=%x\n", &x);
+}
+
+char   stack[1024];
+
+main(argc)
+{
+       float x, y;
+       struct sigvec sv;
+       struct sigstack ss;
+
+       sv.sv_handler = onintr;
+       sv.sv_mask = 0;
+       sv.sv_onstack = argc > 1;
+       ss.ss_sp = stack + sizeof (stack) - 1;  /* grows down on vax */
+       ss.ss_onstack = 0;
+       if (sigstack(&ss, (struct sigstack *)0) < 0)
+               perror("sigstack");
+       if (sigvec(SIGFPE, &sv, (struct sigvec *)0) < 0)
+               perror("sigvec");
+       x = 1.; y = 0.; x = x / y;
+}
diff --git a/usr/guest/sam/tests/sigstack2.c b/usr/guest/sam/tests/sigstack2.c
new file mode 100644 (file)
index 0000000..c1a09c3
--- /dev/null
@@ -0,0 +1,40 @@
+
+#include <stdio.h>
+#include <signal.h>
+
+onintr(signo, code, sc)
+       struct sigcontext *sc;
+{
+       int x;
+
+       fprintf(stderr,
+           "sig=%u, code=%u, onstack=%u, mask=%u, sp=%x, pc=%x, ps=%x\n",
+           signo, code, sc->sc_onstack, sc->sc_mask, sc->sc_sp, sc->sc_pc,
+           sc->sc_ps);
+       fprintf(stderr, "handler local var: &x=%x\n", &x);
+}
+
+char   stack[1024];
+
+main(argc)
+{
+       int i;
+       register int j;
+       struct sigvec sv;
+       struct sigstack ss;
+
+       sv.sv_handler = onintr;
+       sv.sv_mask = 0;
+       sv.sv_onstack = argc > 1;
+       ss.ss_sp = stack + sizeof (stack) - 1;  /* grows down on vax */
+       ss.ss_onstack = 0;
+       if (sigstack(&ss, (struct sigstack *)0) < 0)
+               perror("sigstack");
+       if (sigvec(SIGINT, &sv, (struct sigvec *)0) < 0)
+               perror("sigvec");
+       for (i = 0;; i++) {
+               for (j = 0; j < 32767; j++)
+                       ;
+               printf("&i=%x, i=%d, j=%d\n", &i, i, j);
+       }
+}
diff --git a/usr/guest/sam/tests/sigtstp.c b/usr/guest/sam/tests/sigtstp.c
new file mode 100644 (file)
index 0000000..b80777e
--- /dev/null
@@ -0,0 +1,19 @@
+#include <signal.h>
+
+catch()
+{
+
+       printf("catch SIGTSTP\n");
+       sigsetmask(0);
+       signal(SIGTSTP, SIG_DFL);
+       kill(getpid(), SIGTSTP);
+       signal(SIGTSTP, catch);
+}
+
+main()
+{
+
+       signal(SIGTSTP, catch);
+       for (;;)
+               kill(getpid(), SIGTSTP);
+}
diff --git a/usr/guest/sam/tests/truncate.c b/usr/guest/sam/tests/truncate.c
new file mode 100644 (file)
index 0000000..16c25f9
--- /dev/null
@@ -0,0 +1,18 @@
+main(argc, argv)
+       char *argv[];
+{
+       int size = 0;
+
+       if (argc < 2 || argc > 4) {
+               printf("usage: truncate file [size]\n");
+               exit(1);
+       }
+       if (argc == 3)
+               size = atoi(argv[2]);
+       if (size < 0) {
+               printf("truncate: size %d?\n", size);
+               exit(1);
+       }
+       if (truncate(argv[1], size) < 0)
+               perror(argv[1]);
+}
diff --git a/usr/guest/sam/tests/writer.c b/usr/guest/sam/tests/writer.c
new file mode 100644 (file)
index 0000000..706e048
--- /dev/null
@@ -0,0 +1,24 @@
+#include <sys/file.h>
+
+char buf[10] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
+main()
+{
+       int fd, n;
+
+       fd = open("./foo", FRDWR|FCREATE, 0666);
+       if (fd < 0)
+               perror("open");
+       printf("open successful\n");
+       n = flock(fd, FEXLOCK);
+       if (n < 0)
+               perror("write lock");
+       else
+               printf("got write lock\n");
+       n = write(fd, buf, sizeof (buf));
+       printf("n = %d ", n);
+       if (n < 0)
+               perror("write");
+       else
+               putchar('\n');
+       pause();
+}