source: trunk/minix/commands/simple/in.fingerd.c@ 15

Last change on this file since 15 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.7 KB
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#ifndef lint
8static char sccsid[] = "@(#)in.fingerd.c 1.1 87/12/21 SMI"; /* from UCB 5.1 6/6/85 */
9#endif /* not lint */
10
11/*
12 * Finger server.
13 */
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>
21
22int main _ARGS(( int argc, char *argv[] ));
23void fatal _ARGS(( char *prog, char *s ));
24
25int main(argc, argv)
26 char *argv[];
27{
28 register char *sp;
29 char line[512];
30 int i, p[2], pid, status;
31 FILE *fp;
32 char *av[4];
33
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";
49 }
50 if (*sp && !isspace(*sp)) {
51 av[i++] = sp;
52 while (*sp && !isspace(*sp))
53 sp++;
54 *sp = '\0';
55 }
56 }
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]);
65 }
66 execv("/usr/bin/finger", av);
67 printf("No finger program found\n");
68 fflush(stdout);
69 _exit(1);
70 }
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);
80 }
81 fclose(fp);
82 while ((i = wait(&status)) != pid && i != -1)
83 ;
84 return(0);
85}
86
87void fatal(prog, s)
88 char *prog, *s;
89{
90
91 fprintf(stderr, "%s: ", prog);
92 perror(s);
93 exit(1);
94}
Note: See TracBrowser for help on using the repository browser.