kernel: restore setting KTS_NONE
[minix.git] / commands / fingerd / fingerd.c
blob92cacab7a16a5e9030f03f98a77752063e942036
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 */
7 #ifndef lint
8 static char sccsid[] = "@(#)in.fingerd.c 1.1 87/12/21 SMI"; /* from UCB 5.1 6/6/85 */
9 #endif /* not lint */
12 * Finger server.
14 #include <sys/types.h>
15 #include <sys/wait.h>
16 #include <stdio.h>
17 #include <ctype.h>
18 #include <unistd.h>
19 #include <stdlib.h>
20 #include <string.h>
22 int main( int argc, char *argv[] );
23 void fatal( char *prog, char *s );
25 int main(argc, argv)
26 char *argv[];
28 register char *sp;
29 char line[512];
30 int i, p[2], pid, status;
31 FILE *fp;
32 char *av[4];
34 line[0] = '\0';
35 fgets(line, sizeof(line), stdin);
36 sp = line + strlen(line);
37 if (sp > line && *--sp == '\n') *sp = '\0';
38 sp = line;
39 av[0] = "finger";
40 i = 1;
41 while (1) {
42 while (isspace(*sp))
43 sp++;
44 if (!*sp)
45 break;
46 if (*sp == '/' && (sp[1] == 'W' || sp[1] == 'w')) {
47 sp += 2;
48 av[i++] = "-l";
50 if (*sp && !isspace(*sp)) {
51 av[i++] = sp;
52 while (*sp && !isspace(*sp))
53 sp++;
54 *sp = '\0';
57 av[i] = 0;
58 if (pipe(p) < 0)
59 fatal(argv[0], "pipe");
60 if ((pid = fork()) == 0) {
61 close(p[0]);
62 if (p[1] != 1) {
63 dup2(p[1], 1);
64 close(p[1]);
66 execv("/usr/bin/finger", av);
67 printf("No finger program found\n");
68 fflush(stdout);
69 _exit(1);
71 if (pid == -1)
72 fatal(argv[0], "fork");
73 close(p[1]);
74 if ((fp = fdopen(p[0], "r")) == NULL)
75 fatal(argv[0], "fdopen");
76 while ((i = getc(fp)) != EOF) {
77 if (i == '\n')
78 putchar('\r');
79 putchar(i);
81 fclose(fp);
82 while ((i = wait(&status)) != pid && i != -1)
84 return(0);
87 void fatal(prog, s)
88 char *prog, *s;
91 fprintf(stderr, "%s: ", prog);
92 perror(s);
93 exit(1);