1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 *
22 * Copyright 1992 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 #pragma ident "%Z%%M% %I% %E% SMI"
27
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <unistd.h>
31
32 #include <sys/param.h>
33
34 static char **Argv; /* saved argument vector (for ps) */
35 static char *LastArgv; /* saved end-of-argument vector */
36
37 int child = 0; /* pid of the executed process */
38 int ChildDied = 0; /* true when above is valid */
39 int HasHelper = 0; /* must kill helpers (interactive mode) */
40
41
42 int Debug = 0;
43
44
45 void
main(argc,argv)46 main(argc, argv)
47 char **argv;
48 {
49 char host[MAXPATHLEN];
50 char fsname[MAXPATHLEN];
51 char within[MAXPATHLEN];
52 char *pn;
53 int many;
54
55 /*
56 * argv start and extent for setproctitle()
57 */
58 Argv = argv;
59 if (argc > 0)
60 LastArgv = argv[argc-1] + strlen(argv[argc-1]);
61 else
62 LastArgv = NULL;
63
64 many = argc > 2;
65 while (--argc > 0) {
66
67 if ( strcmp( "-d", *argv ) == 0 )
68 {
69 Debug = 1;
70 argv++;
71 continue;
72 }
73 pn = *++argv;
74 where(pn, host, fsname, within);
75 if (many)
76 printf("%s:\t", pn);
77 printf("%s:%s%s\n", host, fsname, within);
78 }
79 exit(0);
80 /* NOTREACHED */
81 }
82
83 /*
84 * SETPROCTITLE -- set the title of this process for "ps"
85 *
86 * Does nothing if there were not enough arguments on the command
87 * line for the information.
88 *
89 * Side Effects:
90 * Clobbers argv[] of our main procedure.
91 */
92 void
setproctitle(user,host)93 setproctitle(user, host)
94 char *user, *host;
95 {
96 register char *tohere;
97
98 tohere = Argv[0];
99 if (LastArgv == NULL ||
100 strlen(user)+strlen(host)+3 > (LastArgv - tohere))
101 return;
102 *tohere++ = '-'; /* So ps prints (rpc.rexd) */
103 sprintf(tohere, "%s@%s", user, host);
104 while (*tohere++) /* Skip to end of printf output */
105 ;
106 while (tohere < LastArgv) /* Avoid confusing ps */
107 *tohere++ = ' ';
108 }
109