source: trunk/athena/bin/write/writed.c @ 5788

Revision 5788, 1.8 KB checked in by probe, 33 years ago (diff)
Allow the "write" executable to be redefined.
Line 
1/*
2 * Copyright (c) 1983 Regents of the University of California.
3 * All rights reserved.  The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6/*
7 * Copyright (c) 1985 Massachusetts Institute of Technology
8 * Note:  This is mostly fingerd.c with all occurances of
9 * "finger" changed to "write".
10 */
11#ifndef lint
12char copyright[] =
13"@(#) Copyright (c) 1983 Regents of the University of California.\n\
14 All rights reserved.\n";
15static char *rcsid_writed_c = "$Header: /afs/dev.mit.edu/source/repository/athena/bin/write/writed.c,v 1.5 1992-01-10 16:40:47 probe Exp $";
16#endif not lint
17
18#ifndef lint
19static char sccsid[] = "@(#)writed.c    5.1 (Berkeley) 6/6/85";
20#endif not lint
21
22/*
23 * Write server.
24 */
25#include <sys/types.h>
26#include <netinet/in.h>
27
28#include <stdio.h>
29#include <ctype.h>
30
31#if !defined(WRITE_PROG)
32#define WRITE_PROG "/usr/athena/bin/write"
33#endif
34
35main(argc, argv)
36        char *argv[];
37{
38        register char *sp;
39        char line[BUFSIZ];
40        struct sockaddr_in sin;
41        int i;
42        char *av[10]; /* space for 9 arguments, plus terminating null */
43
44
45        i = sizeof (sin);
46        if (getpeername(0, &sin, &i) < 0)
47                fatal(argv[0], "getpeername");
48        line[0] = '\0';
49
50        fgets(line, BUFSIZ, stdin);
51        sp = line;
52        av[0] = "write";
53        av[1] = "-f";
54        i = 2;
55        while (1) {
56                while (isspace(*sp))
57                        sp++;
58                if (!*sp)
59                        break;
60                av[i++] = sp;
61                if (i == 9)
62                        /* past end of av space -- throw out the rest */
63                        /* of the args                                */
64                        break;
65                while (*sp && !isspace(*sp)) sp++;
66                if (*sp) *sp++ = '\0';
67        }
68        av[i] = 0;
69        /* Put the socket on stdin, stdout, and stderr */
70        dup2(0, 1);
71        dup2(0, 2);
72#if (defined(vax) && !defined(ultrix) || defined(ibm032))
73        execv(WRITE_PROG, av);
74#else
75        execv("/usr/athena/bin/write", av);
76#endif
77        _exit(1);
78}
79
80fatal(prog, s)
81        char *prog, *s;
82{
83
84        fprintf(stderr, "%s: ", prog);
85        perror(s);
86        exit(1);
87}
Note: See TracBrowser for help on using the repository browser.