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