Bump to lsof 4.91
[platform/upstream/lsof.git] / usage.c
1 /*
2  * usage.c - usage functions for lsof
3  */
4
5
6 /*
7  * Copyright 1998 Purdue Research Foundation, West Lafayette, Indiana
8  * 47907.  All rights reserved.
9  *
10  * Written by Victor A. Abell
11  *
12  * This software is not subject to any license of the American Telephone
13  * and Telegraph Company or the Regents of the University of California.
14  *
15  * Permission is granted to anyone to use this software for any purpose on
16  * any computer system, and to alter it and redistribute it freely, subject
17  * to the following restrictions:
18  *
19  * 1. Neither the authors nor Purdue University are responsible for any
20  *    consequences of the use of this software.
21  *
22  * 2. The origin of this software must not be misrepresented, either by
23  *    explicit claim or by omission.  Credit to the authors and Purdue
24  *    University must appear in documentation and sources.
25  *
26  * 3. Altered versions must be plainly marked as such, and must not be
27  *    misrepresented as being the original software.
28  *
29  * 4. This notice may not be removed or altered.
30  */
31
32 #ifndef lint
33 static char copyright[] =
34 "@(#) Copyright 1998 Purdue Research Foundation.\nAll rights reserved.\n";
35 static char *rcsid = "$Id: usage.c,v 1.33 2018/02/14 14:20:14 abe Exp $";
36 #endif
37
38
39 #include "lsof.h"
40 #include "version.h"
41
42
43 /*
44  * Local function prototypes
45  */
46
47 _PROTOTYPE(static char *isnullstr,(char *s));
48 _PROTOTYPE(static int print_in_col,(int col, char *cp));
49 _PROTOTYPE(static void report_HASDCACHE,(int type, char *ttl, char *det));
50 _PROTOTYPE(static void report_HASKERNIDCK,(char *pfx, char *verb));
51 _PROTOTYPE(static void report_SECURITY,(char *pfx, char *punct));
52 _PROTOTYPE(static void report_WARNDEVACCESS,(char *pfx, char *verb,
53                                              char *punct));
54
55
56 /*
57  * isnullstr() - is it a null string?
58  */
59
60 static char *
61 isnullstr(s)
62         char *s;                        /* string pointer */
63 {
64         if (!s)
65                 return((char *)NULL);
66         while (*s) {
67                 if (*s != ' ')
68                         return(s);
69                 s++;
70         }
71         return((char *)NULL);
72 }
73
74
75 /*
76  * print_in_col() -- print character string in help column
77  */
78
79 static int
80 print_in_col(col, cp)
81         int col;                                /* column number */
82         char *cp;                               /* what to print */
83 {
84         if (cp && *cp) {
85             switch (col) {
86             case 1:
87                 (void) fprintf(stderr, "  %-23.23s", cp);
88                 break;
89             case 2:
90                 (void) fprintf(stderr, "  %-25.25s", cp);
91                 break;
92             default:
93                 (void) fprintf(stderr, "  %s\n", cp);
94                 col = 0;
95             }
96             col++;
97         }
98         return(col);
99 }
100
101
102 /*
103  * report_HASDCACHE() -- report device cache file state
104  */
105
106 static void
107 report_HASDCACHE(type, ttl, det)
108         int type;                               /* type: 0 == read path report
109                                                  *       1 == full report */
110         char *ttl;                              /* title lines prefix
111                                                  * (NULL if none) */
112         char *det;                              /* detail lines prefix
113                                                  * (NULL if none) */
114 {
115
116 #if     defined(HASDCACHE)
117         char *cp;
118         int dx;
119
120 # if    defined(WILLDROPGID)
121         int saved_Setgid = Setgid;
122
123         Setgid = 0;
124 # endif /* defined(WILLDROPGID) */
125
126         if (type) {
127
128         /*
129          * Report full device cache information.
130          */
131             (void) fprintf(stderr, "%sDevice cache file read-only paths:\n",
132                 ttl ? ttl : "");
133             if ((dx = dcpath(1, 0)) < 0)
134                 (void) fprintf(stderr, "%snone\n", det ? det : "");
135             else {
136                 (void) fprintf(stderr, "%sNamed via -D: %s\n",
137                     det ? det : "",
138                     DCpath[0] ? DCpath[0] : "none");
139
140 # if    defined(HASENVDC)
141                 (void) fprintf(stderr,
142                     "%sNamed in environment variable %s: %s\n",
143                     det ? det : "",
144                     HASENVDC, DCpath[1] ? DCpath[1] : "none");
145 # endif /* defined(HASENVDC) */
146
147 # if    defined(HASSYSDC)
148                 if (DCpath[2])
149                     (void) fprintf(stderr,
150                         "%sSystem-wide device cache: %s\n",
151                         det ? det : "",
152                         DCpath[2]);
153 # endif /* defined(HASSYSDC) */
154
155 # if    defined(HASPERSDC)
156                 (void) fprintf(stderr,
157                     "%sPersonal path format (HASPERSDC): \"%s\"\n",
158                     det ? det : "",
159                     HASPERSDC);
160 #  if   defined(HASPERSDCPATH)
161                 (void) fprintf(stderr,
162                     "%sModified personal path environment variable: %s\n",
163                     det ? det : "",
164                     HASPERSDCPATH);
165                 cp = getenv(HASPERSDCPATH);
166                 (void) fprintf(stderr, "%s%s value: %s\n",
167                     det ? det : "",
168                     HASPERSDCPATH, cp ? cp : "none");
169 #  endif        /* defined(HASPERSDCPATH) */
170                 (void) fprintf(stderr, "%sPersonal path: %s\n",
171                     det ? det : "",
172                     DCpath[3] ? DCpath[3] : "none");
173 # endif /* defined(HASPERSDC) */
174             }
175             (void) fprintf(stderr, "%sDevice cache file write paths:\n",
176                 ttl ? ttl : "");
177             if ((dx = dcpath(2, 0)) < 0)
178                 (void) fprintf(stderr, "%snone\n", det ? det : "");
179             else {
180                 (void) fprintf(stderr, "%sNamed via -D: %s\n",
181                     det ? det : "",
182                     DCstate == 2 ? "none"
183                                  : DCpath[0] ? DCpath[0] : "none");
184
185 # if    defined(HASENVDC)
186                 (void) fprintf(stderr,
187                     "%sNamed in environment variable %s: %s\n",
188                     det ? det : "",
189                     HASENVDC, DCpath[1] ? DCpath[1] : "none");
190 # endif /* defined(HASENVDC) */
191
192 # if    defined(HASPERSDC)
193                 (void) fprintf(stderr,
194                     "%sPersonal path format (HASPERSDC): \"%s\"\n",
195                     det ? det : "",
196                     HASPERSDC);
197 #  if   defined(HASPERSDCPATH)
198                 (void) fprintf(stderr,
199                     "%sModified personal path environment variable: %s\n",
200                     det ? det : "",
201                     HASPERSDCPATH);
202                 cp = getenv(HASPERSDCPATH);
203                 (void) fprintf(stderr, "%s%s value: %s\n",
204                     det ? det : "",
205                     HASPERSDCPATH, cp ? cp : "none");
206 #  endif        /* defined(HASPERSDCPATH) */
207                  (void) fprintf(stderr, "%sPersonal path: %s\n",
208                     det ? det : "",
209                     DCpath[3] ? DCpath[3] : "none");
210 # endif /* defined(HASPERSDC) */
211             }
212         } else {
213
214         /*
215          * Report device cache read file path.
216          */
217
218 # if    defined(HASENVDC) || defined(HASPERSDC) || defined(HASSYSDC)
219             cp = NULL;
220 #  if   defined(HASENVDC)
221             if ((dx = dcpath(1, 0)) >= 0)
222                 cp = DCpath[1];
223 #  endif        /* defined(HASENVDC) */
224 #  if   defined(HASSYSDC)
225             if (!cp)
226                 cp = HASSYSDC;
227 #  endif        /* defined(HASSYSDC) */
228 #  if   defined(HASPERSDC)
229             if (!cp && dx != -1 && (dx = dcpath(1, 0)) >= 0)
230                 cp = DCpath[3];
231 #  endif        /* defined(HASPERSDC) */
232             if (cp)
233                 (void) fprintf(stderr,
234                     "%s%s is the default device cache file read path.\n",
235                     ttl ? ttl : "",
236                     cp
237                 );
238 # endif    /* defined(HASENVDC) || defined(HASPERSDC) || defined(HASSYSDC) */
239         }
240
241 # if    defined(WILLDROPGID)
242         Setgid = saved_Setgid;
243 # endif /* defined(WILLDROPGID) */
244
245 #endif  /* defined(HASDCACHE) */
246
247 }
248
249
250 /*
251  * report_HASKERNIDCK() -- report HASKERNIDCK state
252  */
253
254 static void
255 report_HASKERNIDCK(pfx, verb)
256         char *pfx;                              /* prefix (NULL if none) */
257         char *verb;                             /* verb (NULL if none) */
258 {
259         (void) fprintf(stderr, "%sernel ID check %s%s%s.\n",
260             pfx ? pfx : "",
261             verb ? verb : "",
262             verb ? " " : "",
263
264 #if     defined(HASKERNIDCK)
265                 "enabled"
266 #else   /* !defined(HASKERNIDCK) */
267                 "disabled"
268 #endif  /* defined(HASKERNIDCK) */
269
270             );
271 }
272
273
274 /*
275  * report_SECURITY() -- report *SECURITY states
276  */
277
278 static void
279 report_SECURITY(pfx, punct)
280         char *pfx;                              /* prefix (NULL if none) */
281         char *punct;                            /* short foem punctuation
282                                                  * (NULL if none) */
283 {
284         fprintf(stderr, "%s%s can list all files%s",
285             pfx ? pfx : "",
286
287 #if     defined(HASSECURITY)
288             "Only root",
289 # if    defined(HASNOSOCKSECURITY)
290             ", but anyone can list socket files.\n"
291 # else  /* !defined(HASNOSOCKSECURITY) */
292             punct ? punct : ""
293 # endif /* defined(HASNOSOCKSECURITY) */
294 #else   /* !defined(HASSECURITY) */
295             "Anyone",
296             punct ? punct : ""
297 #endif  /* defined(HASSECURITY) */
298
299         );
300 }
301
302
303 /*
304  * report_WARNDEVACCESS() -- report WEARNDEVACCESS state
305  */
306
307 static void
308 report_WARNDEVACCESS(pfx, verb, punct)
309         char *pfx;                              /* prefix (NULL if none) */
310         char *verb;                             /* verb (NULL if none) */
311         char *punct;                            /* punctuation */
312 {
313         (void) fprintf(stderr, "%s/dev warnings %s%s%s%s",
314             pfx ? pfx : "",
315             verb ? verb : "",
316             verb ? " " : "",
317
318 #if     defined(WARNDEVACCESS)
319             "enabled",
320 #else   /* !defined(WARNDEVACCESS) */
321             "disabled",
322 #endif  /* defined(WARNDEVACCESS) */
323
324             punct);
325 }
326
327
328 /*
329  * usage() - display usage and exit
330  */
331
332 void
333 usage(xv, fh, version)
334         int xv;                         /* exit value */
335         int fh;                         /* ``-F ?'' status */
336         int version;                    /* ``-v'' status */
337 {
338         char buf[MAXPATHLEN+1], *cp, *cp1, *cp2;
339         int col, i;
340
341         if (Fhelp || xv) {
342             (void) fprintf(stderr, "%s %s\n latest revision: %s\n",
343                 Pn, LSOF_VERSION, LSOF_URL);
344             (void) fprintf(stderr, " latest FAQ: %sFAQ\n", LSOF_URL);
345             (void) fprintf(stderr, " latest man page: %slsof_man\n", LSOF_URL);
346             (void) fprintf(stderr,
347                 " usage: [-?ab%sh%slnNoOP%s%stUvV%s]",
348
349 #if     defined(HASNCACHE)
350                 "C",
351 #else   /* !defined(HASNCACHE) */
352                 "",
353 #endif  /* defined(HASNCACHE) */
354
355 #if     defined(HASTASKS)
356                 "K",
357 #else   /* !defined(HASTASKS) */
358                 "",
359 #endif  /* defined(HASTASKS) */
360
361 #if     defined(HASPPID)
362                 "R",
363 #else   /* !defined(HASPPID) */
364                 "",
365 #endif  /* defined(HASPPID) */
366
367 #if     defined(HASTCPUDPSTATE)
368                 "",
369 #else   /* !defined(HASTCPUDPSTATE) */
370                 "s",
371 #endif  /* defined(HASTCPUDPSTATE) */
372
373 #if     defined(HASXOPT)
374 # if    defined(HASXOPT_ROOT)
375                 (Myuid == 0) ? "X" : ""
376 # else  /* !defined(HASXOPT_ROOT) */
377                 "X"
378 # endif /* defined(HASXOPT_ROOT) */
379 #else   /* !defined(HASXOPT) */
380                 ""
381 #endif  /* defined(HASXOPT) */
382
383             );
384
385 #if     defined(HAS_AFS) && defined(HASAOPT)
386             (void) fprintf(stderr, " [-A A]");
387 #endif  /* defined(HAS_AFS) && defined(HASAOPT) */
388
389             (void) fprintf(stderr, " [+|-c c] [+|-d s] [+%sD D]%s",
390 #if     defined(HASDCACHE)
391                 "|-",
392 #else   /* !defined(HASDCACHE) */
393                 "",
394 #endif  /* defined(HASDCACHE) */
395
396 #if     defined(HASEPTOPTS)
397                 " [+|-E]"
398 #else   /* !defined(HASEPTOPTS) */
399                 ""
400 #endif  /* defined(HASEPTOPTS) */
401
402                 );
403
404             (void) fprintf(stderr,
405                 " %s[+|-f%s%s%s%s%s%s]\n [-F [f]] [-g [s]] [-i [i]]",
406
407 #if     defined(HASEOPT)
408                 "[+|-e s] ",
409 #else   /* !defined(HASEOPT) */
410                 "",
411 #endif  /* defined(HASEOPT) */
412
413 #if     defined(HASFSTRUCT)
414                 "[",
415
416 # if    defined(HASNOFSCOUNT)
417                 "",
418 # else  /* !defined(HASNOFSCOUNT) */
419                 "c",
420 # endif /* defined(HASNOFSCOUNT) */
421
422 # if    defined(HASNOFSADDR)
423                 "",
424 # else  /* !defined(HASNOFSADDR) */
425                 "f",
426 # endif /* defined(HASNOFSADDR) */
427
428 # if    defined(HASNOFSFLAGS)
429                 "",
430 # else  /* !defined(HASNOFSFLAGS) */
431                 "gG",
432 # endif /* defined(HASNOFSFLAGS) */
433
434 # if    defined(HASNOFSNADDR)
435                 "",
436 # else  /* !defined(HASNOFSNADDR) */
437                 "n",
438 # endif /* defined(HASNOFSNADDR) */
439
440                 "]"
441 #else   /* !defined(HASFSTRUCT) */
442                 "", "", "", "", "", ""
443 #endif  /* defined(HASFSTRUCT) */
444
445                 );
446
447 #if     defined(HASKOPT)
448             (void) fprintf(stderr, " [-k k]");
449 #endif  /* defined(HASKOPT) */
450
451             (void) fprintf(stderr, " [+|-L [l]]");
452
453 #if     defined(HASMOPT) || defined(HASMNTSUP)
454             (void) fprintf(stderr,
455 # if    defined(HASMOPT)
456 #  if   defined(HASMNTSUP)
457                 " [+|-m [m]]"
458 #  else /* !defined(HASMNTSUP) */
459                 " [-m m]"
460 #  endif        /* defined(HASMNTSUP) */
461 # else  /* !defined(HASMOPT) */
462                 " [+m [m]]"
463 # endif /* defined(HASMOPT) */
464                 );
465 #endif  /* defined(HASMOPT) || defined(HASMNTSUP) */
466
467 #if     !defined(HASNORPC_H)
468             (void) fprintf(stderr, " [+|-M]");
469 #endif  /* !defined(HASNORPC_H) */
470
471             (void) fprintf(stderr,
472                 " [-o [o]] [-p s]\n [+|-r [t]]%s [-S [t]] [-T [t]]",
473
474 #if     defined(HASTCPUDPSTATE)
475                 " [-s [p:s]]"
476 #else   /* !defined(HASTCPUDPSTATE) */
477                 ""
478 #endif  /* defined(HASTCPUDPSTATE) */
479
480                 );
481             (void) fprintf(stderr, " [-u s] [+|-w] [-x [fl]]");
482
483 #if     defined(HASZONES)
484             (void) fprintf(stderr, " [-z [z]]");
485 #else   /* !defined(HASZONES) */
486 # if    defined(HASSELINUX)
487             if (CntxStatus)
488                 (void) fprintf(stderr, " [-Z [Z]]");
489 # endif /* defined(HASSELINUX) */
490 #endif  /* defined(HASZONES) */
491
492             (void) fprintf(stderr, " [--] [names]\n");
493         }
494         if (xv && !Fhelp) {
495             (void) fprintf(stderr,
496                 "Use the ``-h'' option to get more help information.\n");
497             if (!fh)
498                 Exit(xv);
499         }
500         if (Fhelp) {
501             (void) fprintf(stderr,
502                 "Defaults in parentheses; comma-separated set (s) items;");
503             (void) fprintf(stderr, " dash-separated ranges.\n");
504             col = print_in_col(1, "-?|-h list help");
505             col = print_in_col(col, "-a AND selections (OR)");
506             col = print_in_col(col, "-b avoid kernel blocks");
507             col = print_in_col(col,  "-c c  cmd c ^c /c/[bix]");
508             (void) snpf(buf, sizeof(buf), "+c w  COMMAND width (%d)", CMDL);
509             col = print_in_col(col, buf);
510
511 #if     defined(HASNCACHE)
512            col = print_in_col(col, "-C no kernel name cache");
513 #endif  /* defined(HASNCACHE) */
514
515             col = print_in_col(col, "+d s  dir s files");
516             col = print_in_col(col,  "-d s  select by FD set");
517             col = print_in_col(col,  "+D D  dir D tree *SLOW?*");
518
519 #if     defined(HASDCACHE)
520             if (Setuidroot)
521                 cp = "?|i|r";
522
523 # if    !defined(WILLDROPGID)
524             else if (Myuid)
525                 cp = "?|i|r<path>";
526 # endif /* !defined(WILLDROPGID) */
527
528             else
529                 cp = "?|i|b|r|u[path]";
530             (void) snpf(buf, sizeof(buf), "-D D  %s", cp);
531 #else   /* !defined(HASDCACHE) */
532             buf[0] = '\0';
533 #endif  /* defined(HASDCACHE) */
534
535             col = print_in_col(col, buf);
536
537 #if     defined(HASEOPT)
538             col = print_in_col(col, "+|-e s  exempt s *RISKY*");
539 #endif  /* defined(HASEOPT) */
540
541             (void) snpf(buf, sizeof(buf), "-i select IPv%s files",
542
543 #if     defined(HASIPv6)
544                           "[46]"
545 #else   /* !defined(HASIPv6) */
546                           "4"
547 #endif  /* defined(HASIPv6) */
548
549                           );
550             col = print_in_col(col, buf);
551
552 #if     defined(HASTASKS)
553 /* DEBUG            col = print_in_col(col, "-K list tasKs (threads)"); */
554             col = print_in_col(col, "-K [i] list|(i)gn tasKs");
555 #endif  /* defined(HASTASKS) */
556
557             col = print_in_col(col, "-l list UID numbers");
558             col = print_in_col(col, "-n no host names");
559             col = print_in_col(col, "-N select NFS files");
560             col = print_in_col(col, "-o list file offset");
561             col = print_in_col(col, "-O no overhead *RISKY*");
562             col = print_in_col(col, "-P no port names");
563
564 #if     defined(HASPPID)
565              col = print_in_col(col, "-R list paRent PID");
566 #endif  /* defined(HASPPID) */
567
568             col = print_in_col(col,  "-s list file size");
569             col = print_in_col(col,  "-t terse listing");
570             col = print_in_col(col,  "-T disable TCP/TPI info");
571             col = print_in_col(col,  "-U select Unix socket");
572             col = print_in_col(col,  "-v list version info");
573             col = print_in_col(col,  "-V verbose search");
574             (void) snpf(buf, sizeof(buf), "+|-w  Warnings (%s)",
575
576 #if     defined(WARNINGSTATE)
577                 "-");
578 #else   /* !defined(WARNINGSTATE) */
579                 "+");
580 #endif  /* defined(WARNINGSTATE) */
581
582             col = print_in_col(col, buf);
583
584 #if     defined(HASXOPT)
585 # if    defined(HASXOPT_ROOT)
586             if (Myuid == 0)
587                 (void) snpf(buf, sizeof(buf), "-X %s", HASXOPT);
588             else
589                 buf[0] = '\0';
590 # else  /* !defined(HASXOPT_ROOT) */
591             (void) snpf(buf, sizeof(buf), "-X %s", HASXOPT);
592 # endif /* defined(HASXOPT_ROOT) */
593 # else  /* !defined(HASXOPT) */
594             buf[0] = '\0';
595 #endif  /* defined(HASXOPT) */
596
597             col = print_in_col(col, buf);
598
599 #if     defined(HASZONES)
600             col = print_in_col(col, "-z z  zone [z]");
601 #endif  /* defined(HASZONES) */
602
603 #if     defined(HASSELINUX)
604             col = print_in_col(col, "-Z Z  context [Z]");
605 #endif  /* defined(HASSELINUX) */
606
607             col = print_in_col(col, "-- end option scan");
608             if (col != 1)
609                 (void) fprintf(stderr, "\n");
610
611 #if     defined(HASEPTOPTS)
612             (void) fprintf(stderr, "  %-36.36s  %s\n",
613                 "-E display endpoint info",
614                 "+E display endpoint info and files"
615             );
616 #endif  /* defined(HASEPTOPTS) */
617
618             (void) fprintf(stderr, "  %-36.36s",
619                 "+f|-f  +filesystem or -file names");
620
621 #if     defined(HASFSTRUCT)
622             (void) fprintf(stderr,
623                 "  +|-f[%s%s%s%s]%s%s%s%s %s%s%s%s%s%s%s\n",
624
625 # if    defined(HASNOFSCOUNT)
626                 "",
627 # else  /* !defined(HASNOFSCOUNT) */
628                 "c",
629 # endif /* defined(HASNOFSCOUNT) */
630
631 # if    defined(HASNOFSADDR)
632                 "",
633 # else  /* !defined(HASNOFSADDR) */
634                 "f",
635 # endif /* defined(HASNOFSADDR) */
636
637 # if    defined(HASNOFSFLAGS)
638                 "",
639 # else  /* !defined(HASNOFSFLAGS) */
640                 "gG",
641 # endif /* defined(HASNOFSFLAGS) */
642
643 # if    defined(HASNOFSNADDR)
644                 "",
645 # else  /* !defined(HASNOFSNADDR) */
646                 "n",
647 # endif /* defined(HASNOFSNADDR) */
648
649 # if    defined(HASNOFSCOUNT)
650                 "",
651 # else  /* !defined(HASNOFSCOUNT) */
652                 " Ct",
653 # endif /* defined(HASNOFSCOUNT) */
654
655 # if    defined(HASNOFSADDR)
656                 "",
657 # else  /* !defined(HASNOFSADDR) */
658                 " Fstr",
659 # endif /* defined(HASNOFSADDR) */
660
661 # if    defined(HASNOFSFLAGS)
662                 "",
663 # else  /* !defined(HASNOFSFLAGS) */
664                 " flaGs",
665 # endif /* defined(HASNOFSFLAGS) */
666
667 # if    defined(HASNOFSNADDR)
668                 "",
669 # else  /* !defined(HASNOFSNADDR) */
670                 " Node",
671 # endif /* defined(HASNOFSNADDR) */
672
673                 Fsv ? "(" : "",
674                 (Fsv & FSV_CT) ? "C" : "",
675                 (Fsv & FSV_FA) ? "F" : "",
676                 ((Fsv & FSV_FG) && FsvFlagX)  ? "g" : "",
677                 ((Fsv & FSV_FG) && !FsvFlagX) ? "G" : "",
678                 (Fsv & FSV_NI) ? "N" : "",
679                 Fsv ? ")" : "");
680 #else   /* !defined(HASFSTRUCT) */
681             putc('\n', stderr);
682 #endif  /* defined(HASFSTRUCT) */
683
684             (void) fprintf(stderr, "  %-36.36s",
685                 "-F [f] select fields; -F? for help");
686
687 #if     defined(HASKOPT)
688             (void) fprintf(stderr,
689                 "  -k k   kernel symbols (%s)\n",
690                 Nmlst ? Nmlst
691 # if    defined(N_UNIX)
692                       : N_UNIX
693 # else  /* !defined(N_UNIX) */
694                       : (Nmlst = get_nlist_path(1)) ? Nmlst
695                                                     : "none found"
696 # endif /* defined(N_UNIX) */
697
698             );
699 #else   /* !defined(HASKOPT) */
700             putc('\n', stderr);
701 #endif  /* defined(HASKOPT) */
702
703             (void) fprintf(stderr,
704                 "  +|-L [l] list (+) suppress (-) link counts < l (0 = all; default = 0)\n");
705
706 #if     defined(HASMOPT) || defined(HASMNTSUP)
707 # if    defined(HASMOPT)
708             (void) snpf(buf, sizeof(buf), "-m m   kernel memory (%s)", KMEM);
709 # else  /* !defined(HASMOPT) */
710             buf[0] = '\0';
711 # endif /* defined(HASMOPT) */
712
713             (void) fprintf(stderr, "  %-36.36s", buf);
714
715 # if    defined(HASMNTSUP)
716             (void) fprintf(stderr, "  +m [m] use|create mount supplement\n");
717 # else  /* !defined(HASMNTSUP) */
718             (void) fprintf(stderr, "\n");
719 # endif /* defined(HASMNTSUP) */
720 #endif  /* defined(HASMOPT) || defined(HASMNTSUP) */
721
722 #if     !defined(HASNORPC_H)
723             (void) snpf(buf, sizeof(buf), "+|-M   portMap registration (%s)",
724
725 # if    defined(HASPMAPENABLED)
726                 "+"
727 # else  /* !defined(HASPMAPENABLED) */
728                 "-"
729 # endif /* defined(HASPMAPENABLED) */
730
731             );
732 #else   /* defined(HASNORPC_H) */
733             buf[0] = '\0';
734 #endif  /* !defined(HASNORPC_H) */
735
736             (void) fprintf(stderr, "  %-36.36s", buf);
737             (void) snpf(buf, sizeof(buf), "-o o   o 0t offset digits (%d)",
738                 OFFDECDIG);
739             (void) fprintf(stderr, "  %s\n", buf);
740             (void) fprintf(stderr, "  %-36.36s",
741                 "-p s   exclude(^)|select PIDs");
742             (void) fprintf(stderr, "  -S [t] t second stat timeout (%d)\n",
743                 TMLIMIT);
744             (void) snpf(buf, sizeof(buf),
745                 "-T %s%ss%s TCP/TPI %s%sSt%s (s) info",
746
747 #if     defined(HASSOOPT) || defined(HASSOSTATE) || defined(HASTCPOPT)
748                 "f",
749 #else   /* !defined(HASSOOPT) && !defined(HASSOSTATE) && !defined(HASTCPOPT)*/
750                 "",
751 #endif  /* defined(HASSOOPT) || defined(HASSOSTATE) || defined(HASTCPOPT)*/
752
753 #if     defined(HASTCPTPIQ)
754                 "q",
755 #else   /* !defined(HASTCPTPIQ) */
756                 " ",
757 #endif  /* defined(HASTCPTPIQ) */
758
759 #if     defined(HASTCPTPIW)
760                 "w",
761 #else   /* !defined(HASTCPTPIW) */
762                 "",
763 #endif  /* defined(HASTCPTPIW) */
764
765 #if     defined(HASSOOPT) || defined(HASSOSTATE) || defined(HASTCPOPT)
766                 "Fl,",
767 #else   /* !defined(HASSOOPT) && !defined(HASSOSTATE) && !defined(HASTCPOPT)*/
768                 "",
769 #endif  /* defined(HASSOOPT) || defined(HASSOSTATE) || defined(HASTCPOPT)*/
770
771 #if     defined(HASTCPTPIQ)
772                 "Q,",
773 #else   /* !defined(HASTCPTPIQ) */
774                 "",
775 #endif  /* defined(HASTCPTPIQ) */
776
777 #if     defined(HASTCPTPIW)
778                 ",Win"
779 #else   /* !defined(HASTCPTPIW) */
780                 ""
781 #endif  /* defined(HASTCPTPIW) */
782
783             );
784             (void) fprintf(stderr, "  %s\n", buf);
785
786 #if     defined(HAS_AFS) && defined(HASAOPT)
787             (void) fprintf(stderr,
788                 "  -A A   AFS name list file (%s)\n", AFSAPATHDEF);
789 #endif  /* defined(HAS_AFS) && defined(HASAOPT) */
790
791             (void) fprintf(stderr,
792                 "  -g [s] exclude(^)|select and print process group IDs\n");
793             (void) fprintf(stderr, "  -i i   select by IPv%s address:",
794
795 #if     defined(HASIPv6)
796                           "[46]"
797 #else   /* !defined(HASIPv6) */
798                           "4"
799 #endif  /* defined(HASIPv6) */
800
801                           );
802             (void) fprintf(stderr,
803                 " [%s][proto][@host|addr][:svc_list|port_list]\n",
804
805 #if     defined(HASIPv6)
806                 "46"
807 #else   /* !defined(HASIPv6) */
808                 "4"
809 #endif  /* defined(HASIPv6) */
810
811                 );
812
813             (void) fprintf(stderr,
814                 "  +|-r [%s] repeat every t seconds (%d); %s",
815
816 #if     defined(HAS_STRFTIME)
817                 "t[m<fmt>]",
818 #else   /* !defined(has_STRFTIME) */
819                 "t",
820 #endif  /* defined(HAS_STRFTIME) */
821
822                 RPTTM,
823                 " + until no files, - forever.\n");
824
825 #if     defined(HAS_STRFTIME)
826             (void) fprintf(stderr,
827                 "       An optional suffix to t is m<fmt>; m must separate %s",
828                 "t from <fmt> and\n");
829             (void) fprintf(stderr, "      <fmt> is an strftime(3) format %s",
830                 "for the marker line.\n");
831 #endif  /* defined(HAS_STRFTIME) */
832
833 #if     defined(HASTCPUDPSTATE)
834             (void) fprintf(stderr,
835                 "  -s p:s  exclude(^)|select protocol (p = TCP|UDP) states");
836             (void) fprintf(stderr, " by name(s).\n");
837 #endif  /* defined(HASTCPUDPSTATE) */
838
839             (void) fprintf(stderr,
840                 "  -u s   exclude(^)|select login|UID set s\n");
841             (void) fprintf(stderr,
842                 "  -x [fl] cross over +d|+D File systems or symbolic Links\n");
843             (void) fprintf(stderr,
844                 "  names  select named files or files on named file systems\n");
845             (void) report_SECURITY(NULL, "; ");
846             (void) report_WARNDEVACCESS(NULL, NULL, ";");
847             (void) report_HASKERNIDCK(" k", NULL);
848             (void) report_HASDCACHE(0, NULL, NULL);
849
850 #if     defined(DIALECT_WARNING)
851             (void) fprintf(stderr, "WARNING: %s\n", DIALECT_WARNING);
852 #endif  /* defined(DIALECT_WARNING) */
853
854         }
855         if (fh) {
856             (void) fprintf(stderr, "%s:\tID    field description\n", Pn);
857             for (i = 0; FieldSel[i].nm; i++) {
858
859 #if     !defined(HASPPID)
860                 if (FieldSel[i].id == LSOF_FID_PPID)
861                     continue;
862 #endif  /* !defined(HASPPID) */
863
864 #if     !defined(HASFSTRUCT)
865                 if (FieldSel[i].id == LSOF_FID_FA
866                 ||  FieldSel[i].id == LSOF_FID_CT
867                 ||  FieldSel[i].id == LSOF_FID_FG
868                 ||  FieldSel[i].id == LSOF_FID_NI)
869                     continue;
870 #else   /* defined(HASFSTRUCT) */
871 # if    defined(HASNOFSADDR)
872                 if (FieldSel[i].id == LSOF_FID_FA)
873                     continue;
874 # endif /* defined(HASNOFSADDR) */
875
876 # if    defined(HASNOFSCOUNT)
877                 if (FieldSel[i].id == LSOF_FID_CT)
878                     continue;
879 # endif /* !defined(HASNOFSCOUNT) */
880
881 # if    defined(HASNOFSFLAGS)
882                 if (FieldSel[i].id == LSOF_FID_FG)
883                     continue;
884 # endif /* defined(HASNOFSFLAGS) */
885
886 # if    defined(HASNOFSNADDR)
887                 if (FieldSel[i].id == LSOF_FID_NI)
888                     continue;
889 # endif /* defined(HASNOFSNADDR) */
890 #endif  /* !defined(HASFSTRUCT) */
891
892 #if     !defined(HASZONES)
893                 if (FieldSel[i].id == LSOF_FID_ZONE)
894                     continue;
895 #endif  /* !defined(HASZONES) */
896  
897 #if     defined(HASSELINUX)
898                 if ((FieldSel[i].id == LSOF_FID_CNTX) && !CntxStatus)
899                     continue;
900 #else   /* !defined(HASSELINUX) */
901                 if (FieldSel[i].id == LSOF_FID_CNTX)
902                     continue;
903 #endif  /* !defined(HASSELINUX) */
904
905                 (void) fprintf(stderr, "\t %c    %s\n",
906                     FieldSel[i].id, FieldSel[i].nm);
907             }
908         }
909
910 #if     defined(HASDCACHE)
911         if (DChelp)
912             report_HASDCACHE(1, NULL, "    ");
913 #endif  /* defined(HASDCACHE) */
914
915         if (version) {
916
917         /*
918          * Display version information in reponse to ``-v''.
919          */
920             (void) fprintf(stderr, "%s version information:\n", Pn);
921             (void) fprintf(stderr, "    revision: %s\n", LSOF_VERSION);
922             (void) fprintf(stderr, "    latest revision: %s\n", LSOF_URL);
923             (void) fprintf(stderr, "    latest FAQ: %sFAQ\n",
924                 LSOF_URL);
925             (void) fprintf(stderr, "    latest man page: %slsof_man\n",
926                 LSOF_URL);
927
928 #if     defined(LSOF_CINFO)
929             if ((cp = isnullstr(LSOF_CINFO)))
930                 (void) fprintf(stderr, "    configuration info: %s\n", cp);
931 #endif  /* defined(LSOF_CINFO) */
932
933             if ((cp = isnullstr(LSOF_CCDATE)))
934                 (void) fprintf(stderr, "    constructed: %s\n", cp);
935             cp = isnullstr(LSOF_HOST);
936             if (!(cp1 = isnullstr(LSOF_LOGNAME)))
937                 cp1 = isnullstr(LSOF_USER);
938             if (cp || cp1) {
939                 if (cp && cp1)
940                     cp2 = "by and on";
941                 else if (cp)
942                     cp2 = "on";
943                 else
944                     cp2 = "by";
945                 (void) fprintf(stderr, "    constructed %s: %s%s%s\n",
946                     cp2,
947                     cp1 ? cp1 : "",
948                     (cp && cp1) ? "@" : "",
949                     cp  ? cp  : ""
950                 );
951             }
952
953 #if     defined(LSOF_BLDCMT)
954             if ((cp = isnullstr(LSOF_BLDCMT)))
955                 (void) fprintf(stderr, "    builder's comment: %s\n", cp);
956 #endif  /* defined(LSOF_BLDCMT) */
957
958             if ((cp = isnullstr(LSOF_CC)))
959                 (void) fprintf(stderr, "    compiler: %s\n", cp);
960             if ((cp = isnullstr(LSOF_CCV)))
961                 (void) fprintf(stderr, "    compiler version: %s\n", cp);
962             if ((cp = isnullstr(LSOF_CCFLAGS)))
963                 (void) fprintf(stderr, "    compiler flags: %s\n", cp);
964             if ((cp = isnullstr(LSOF_LDFLAGS)))
965                 (void) fprintf(stderr, "    loader flags: %s\n", cp);
966             if ((cp = isnullstr(LSOF_SYSINFO)))
967                 (void) fprintf(stderr, "    system info: %s\n", cp);
968             (void) report_SECURITY("    ", ".\n");
969             (void) report_WARNDEVACCESS("    ", "are", ".\n");
970             (void) report_HASKERNIDCK("    K", "is");
971
972 #if     defined(DIALECT_WARNING)
973             (void) fprintf(stderr, "    WARNING: %s\n", DIALECT_WARNING);
974 #endif  /* defined(DIALECT_WARNING) */
975
976             (void) report_HASDCACHE(1, "    ", "\t");
977         }
978         Exit(xv);
979 }