3 # $Id: Customize,v 1.9 2005/05/11 13:02:18 abe Exp $
5 # Customize: customize dialect's machine.h header file.
7 # Allows easy modification of some important compile-time definitions for
8 # lsof, made in the dialect's machine.h header file, including:
10 # HASSECURITY the security option
12 # the socket oberalization of HASSECURITY
13 # HASDCACHE enabling/disabling the device cache file
14 # (Note: changing the device cache file option isn't
15 # offered when machine.h contains NEVER_HASDCACHE
16 # anywhere, including in a comment.)
17 # HASENVDC enabling/disabling device cache path from environment
18 # HASKERNIDCK enabling/disabling the kernel identity check
19 # (not done for some dialects)
20 # HASPERSDC enabling/disabling personal device cache path
22 # HASPERSDCPATH enabling/disabling additional personal device cache
24 # HASSYSDC enabling/disabling system-wide device cache file path
25 # HASXOPT_ROOT enabling/disabling root use of the -X option
26 # WARNDEVACCESS enabling inaccessible /dev node warnings
27 # (Note: changing the inaccessible /dev/node warning
28 # option isn't offered when machine.h contains
29 # NEVER_WARNDEVACCESS anywhere, including in a
31 # WARNINGSTATE enable/disabling default warning message state
33 # Usage: Customize [dialect_directory]
35 # where: dialect_directory (optional) is the directory in which the dialect's
36 # dialect's sources, Makefile and scripts are found
41 # Save optional dialect directory.
50 # Establish trap and stty handling.
53 trap 'rm -f $NEW; $ISIG; exit 1' 1 2 3 15
54 stty -a 2>&1 | grep isig > /dev/null
57 stty -a 2>&1 | egrep -e -isig > /dev/null
65 # Decide how to use echo.
68 if test "X$ECHO" = "X-n "
77 # Decide how to use tail(1).
79 TMP1=`tail -n 1 $0 2> /dev/null`
80 if test $? -eq 0 -a "X$TMP1" = "X#LAST_LINE"
87 # Display the introduction and basic explanation.
91 You may now customize the machine.h header file for this UNIX
92 dialect. The customizations will take effect when you compile
93 lsof. You may also choose to skip customization and proceed to
94 the compilation of lsof.
96 If you don't know if you need to customize or want to know more
97 about what you can customize, consult the 00DCACHE, 00FAQ, 00PORTING,
98 and 00README files of the lsof distribution. You might also find
99 it helpful to examine the machine.h header file for the dialect
102 You don't need to use this procedure to customize lsof; you can
103 edit the machine.h header file directly. If you later decide you
104 want to use this procedure to customize machine.h, execute the
109 while test $END -eq 0
112 echo $EO "Do you want to customize (y|n) [y]? $EC"
114 if test "X$ANS" = "Xn" -o "X$ANS" = "XN"
118 if test "X$ANS" = "Xy" -o "X$ANS" = "XY" -o "X$ANS" = "X"
121 echo "Customizing ..."
125 echo "Please answer y|n [y]."
129 # See if $OLD exists.
134 echo "FATAL: The file \"$OLD\" doesn't exist. Customization can't"
135 echo "continue without it."
137 echo "Did you run the Configure script?"
139 echo "Customize quits."
144 # See if $NEW exists.
149 echo "====================================================================="
151 echo "WARNING: \"$NEW\" exists. Customization will replace it."
153 while test $END -eq 0
156 echo $EO "Do you want to remove $NEW (y|n) [y]? $EC"
158 if test "X$ANS" = "Xy" -o "X$ANS" = "XY" -o "X$ANS" = "X"
166 if test "X$ANS" = "Xn" -o "X$ANS" = "XN"
169 echo "FATAL: Customize quits; it must be able to create \"$NEW\"."
174 echo "Please answer y|n [y]."
180 # Process HASSECURITY.
184 =====================================================================
186 When HASSECURITY is enabled, only the root user may use lsof to
187 examine all open files; other users may examine only the files
188 belonging to the real user ID of their lsof process. If
189 HASNOSOCKSECURITY is also defined, anyone may list anyone else's
190 open socket files, provided their listing is selected with the "-i"
193 When HASSECURITY is disabled, anyone may use lsof to examine all
198 grep HASSECURITY $OLD | tail $TA | egrep "^#define" > /dev/null
201 echo "HASSECURITY is enabled."
204 echo "HASSECURITY is disabled."
208 while test $END -eq 0
213 echo $EO "Disable HASSECURITY (y|n) [n]? $EC"
215 echo $EO "Enable HASSECURITY (y|n) [n]? $EC"
218 if test "X$ANS" = "Xy" -o "X$ANS" = "XY"
224 echo "HASSECURITY will be disabled."
227 echo "HASSECURITY will be enabled."
231 if test "X$ANS" = "Xn" -o "X$ANS" = "XN" -o "X$ANS" = "X"
234 echo "HASSECURITY will not be changed."
238 echo "Please answer y|n [n]."
243 # If HASSECURITY is enabled, see if HASNOSOCKSECURITY should also be defined.
249 ====================================================================
251 When HASSECURITY is enabled, you may also define HASNOSOCKSECURITY.
253 When both are defined, no one but root may list all of anyone else's
254 open files -- only their own open files -- but anyone may list
255 anyone else's open socket files.
257 This option is useful with ntop (http://www.ntop.org).
261 grep HASNOSOCKSECURITY $OLD | tail $TA | egrep "^#define" > /dev/null
264 echo "HASNOSOCKSECURITY is enabled."
267 echo "HASNOSOCKSECURITY is disabled."
271 while test $END -eq 0
274 if test $SOCKSEC -eq 1
276 echo $EO "Disable HASNOSOCKSECURITY (y|n) [n]? $EC"
278 echo $EO "Enable HASNOSOCKSECURITY (y|n) [n]? $EC"
281 if test "X$ANS" = "Xy" -o "X$ANS" = "XY"
284 if test $SOCKSEC -eq 1
287 echo "HASNOSOCKSECURITY will be disabled."
290 echo "HASNOSOCKSECURITY will be enabled."
294 if test "X$ANS" = "Xn" -o "X$ANS" = "XN" -o "X$ANS" = "X"
297 echo "HASNOSOCKSECURITY will not be changed."
301 echo "Please answer y|n [n]."
309 # Process WARNINGSTATE.
313 =====================================================================
315 When WARNINGSTATE is enabled, lsof will will issue whatever warning
316 messages it finds necessary. When WARNINGSTATE is disabled, lsof
317 will issue no warning messages. For individual uses of lsof, -w
318 disables warning state and +w enables it.
322 grep WARNINGSTATE $OLD | tail $TA | egrep "^#define" > /dev/null
325 echo "WARNINGSTATE is disabled."
328 echo "WARNINGSTATE is enabled."
333 while test $END -eq 0
338 echo $EO "Enable WARNINGSTATE? (y|n) [n]? $EC"
340 echo $EO "Disable WARNINGSTATE? (y|n) [n]? $EC"
343 if test "X$ANS" = "Xy" -o "X$ANS" = "XY"
348 echo "WARNINGSTATE will be enabled."
351 echo "WARNINGSTATE will be disabled."
356 if test "X$ANS" = "Xn" -o "X$ANS" = "XN" -o "X$ANS" = "X"
359 echo "WARNINGSTATE will not be changed."
363 echo "Please answer y|n [n]."
368 # Process WARNDEVACCESS, unless the dialect's machine.h header file contains
369 # NEVER_WARNDEVACCESS.
371 grep NEVER_WARNDEVACCESS $OLD > /dev/null
380 =====================================================================
382 When WARNDEVACCESS is enabled, lsof will issue warning messages
383 when it can't access nodes in /dev (or /devices), subject to the
384 default or explicit (-w) WARNINGSTATE.
386 When WARNDEVACCESS is disabled, lsof will silently skip nodes in
387 /dev (or /devices) that it can't access.
391 grep WARNDEVACCESS $OLD | tail $TA | egrep "^#define" > /dev/null
394 echo "WARNDEVACCESS is enabled."
397 echo "WARNDEVACCESS is disabled."
402 while test $END -eq 0
407 echo $EO "Disable WARNDEVACCESS (y|n) [n]? $EC"
409 echo $EO "Enable WARNDEVACCESS (y|n) [n]? $EC"
412 if test "X$ANS" = "Xy" -o "X$ANS" = "XY"
417 echo "WARNDEVACCESS will be disabled."
420 echo "WARNDEVACCESS will be enabled."
425 if test "X$ANS" = "Xn" -o "X$ANS" = "XN" -o "X$ANS" = "X"
428 echo "WARNDEVACCESS will not be changed."
432 echo "Please answer y|n [n]."
438 # Process HASDCACHE, unless the dialect's machine.h header file contains
449 grep NEVER_HASDCACHE $OLD > /dev/null
460 =====================================================================
462 When HASDCACHE is enabled, lsof will write a device cache file that
463 contains information about the nodes in /dev (or /devices). The
464 options HASENVDC, HASPERSDC, HASPERSDCPATH, and HASSYSDC define
465 the device cache file path.
467 When HASDCACHE is disabled, lsof won't write a device cache file.
469 Consult the 00DCACHE and 00FAQ files of the lsof distribution for
474 grep HASDCACHE $OLD | tail $TA | egrep "^#define" > /dev/null
477 echo "HASDCACHE is enabled."
480 echo "HASDCACHE is disabled."
485 while test $END -eq 0
490 echo $EO "Disable HASDCACHE (y|n) [n]? $EC"
492 echo $EO "Enable HASDCACHE (y|n) [n]? $EC"
495 if test "X$ANS" = "Xy" -o "X$ANS" = "XY"
500 echo "HASDCACHE will be disabled."
503 echo "HASDCACHE will be enabled."
508 if test "X$ANS" = "Xn" -o "X$ANS" = "XN" -o "X$ANS" = "X"
511 echo "HASDCACHE will not be changed."
515 echo "Please answer y|n [n]."
520 # See if other device cache options need to be declared.
522 if test $DC -eq 1 -a $NDC -eq 1
526 =====================================================================
528 You have decided that HASDCACHE should be defined. There are other
529 definitions associated with HASDCACHE that specify options for the
530 formation of the device cache file path. You may change them.
532 Consult the 00DCACHE and 00FAQ files of the lsof distribution for
535 The current path options are:
539 grep HASENVDC $OLD | tail $TA | egrep "^#define"
540 egrep "HASPERSDC$|HASPERSDC[ ]" $OLD | tail $TA | egrep "^#define"
541 grep HASPERSDCPATH $OLD | tail $TA | egrep "^#define"
542 grep HASSYSDC $OLD | tail $TA | egrep "^#define"
544 while test $END -eq 0
547 echo $EO "Do you want to change path options (y|n) [n]? $EC"
549 if test "X$ANS" = "Xy" -o "X$ANS" = "XY"
554 if test "X$ANS" = "Xn" -o "X$ANS" = "XN"
559 if test "X$ANS" = "X"
562 echo "The path options will not be changed."
567 echo "Please answer y|n [n]."
575 if test \( $NDC -eq 1 -a $DC -eq 0 \) -o \( $DC -eq 1 -a $CDC -eq 1 \)
579 =====================================================================
581 You may specify for HASENVDC the name of the environment variable
582 from which lsof should take the device cache file path for non-root
583 users. Press ENTER to use the current value of HASENVDC:
588 TMP1=`grep HASENVDC $OLD | tail $TA | egrep "^#define"`
589 if test "X$TMP1" != "X"
591 TMP1=`echo "$TMP1" | sed 's/^#define[ ]HASENVDC[ ]"\([^"]*\)".*$/\1/'`
594 echo "no current HASENVDC value"
598 while test $END -eq 0
601 echo $EO "Do you want to define a name for HASENVDC (y|n) [n]? $EC"
603 if test "X$ANS" = "Xn" -o "X$ANS" = "XN"
608 if test "X$ANS" = "Xy" -o "X$ANS" = "XY"
613 if test "X$ANS" = "X"
616 echo "HASENVDC will not be changed."
621 echo "Please answer y|n [n]."
629 echo $EO "Please enter the HASENVDC name (no quotes): $EC"
631 ENVV=`echo $TMP1 | sed 's/^\"//' | sed 's/\"$//'`
632 if test "X$ENVV" = "X"
639 =====================================================================
641 HASPERSDC is a format that specifies how the personal device cache
642 path is constructed. Consult the 00DCACHE and 00FAQ files of the
643 lsof distribution for information on the conversions supported in
644 HASPERSDC. Press ENTER to use the curent HASPERSDC format:
649 TMP1=`egrep "HASPERSDC$|HASPERSDC[ ]" $OLD | tail $TA | egrep "^#define"`
650 if test "X$TMP1" != "X"
652 TMP1=`echo "$TMP1" | sed 's/^#define[ ]HASPERSDC[ ]"\([^"]*\)".*$/\1/'`
655 echo "no current HASPERSDC format"
659 while test $END -eq 0
662 echo $EO "Do you want to define a format for HASPERSDC (y|n) [n]? $EC"
664 if test "X$ANS" = "Xn" -o "X$ANS" = "XN"
668 if test "X$ANS" = "Xy" -o "X$ANS" = "XY"
673 if test "X$ANS" = "X"
676 echo "HASPERSDC will not be changed."
681 echo "Please answer y|n [n]."
689 echo $EO "Please enter the HASPERSDC format (no quotes): $EC"
691 PDCV=`echo $TMP1 | sed 's/^\"//' | sed 's/\"$//'`
692 if test "X$PDCV" = "X"
699 =====================================================================
701 Specify for HASPERSDCPATH the name of the environment variable from
702 which lsof should take a path name component to insert at the %p
703 conversion in the HASPERSDC format.
705 Consult the 00FAQ and 00DCACHE files of the lsof distribution for
706 more information on HASPERSDCPATH usage.
708 Press ENTER to use the current value for HASPERSDCPATH:
713 TMP1=`grep HASPERSDCPATH $OLD | tail $TA | egrep "^#define"`
714 if test "X$TMP1" != "X"
716 TMP1=`echo "$TMP1" | sed 's/^#define[ ]HASPERSDCPATH[ ]"\([^"]*\)".*$/\1/'`
719 echo "no current HASPERSDCPATH value"
723 while test $END -eq 0
726 echo $EO "Do you want to change HASPERSDCPATH (y|n) [n]? $EC"
728 if test "X$ANS" = "Xn" -o "X$ANS" = "XN" -o "X$ANS" = "X"
731 echo "HASPERSDCPATH will not be changed."
735 if test "X$ANS" = "Xy" -o "X$ANS" = "XY"
741 echo "Please answer y|n [n]."
748 echo $EO "Please enter the HASPERSDCPATH name (no quotes): $EC"
750 PDCPV=`echo $TMP1 | sed 's/^\"//' | sed 's/\"$//'`
751 if test "X$PDCPV" = "X"
758 =====================================================================
760 Specify for HASSYSDC the system-wide device cache file path. Press
761 ENTER to use the current HASSYSDC value:
766 TMP1=`grep HASSYSDC $OLD | tail $TA | egrep "^#define"`
767 if test "X$TMP1" != "X"
769 TMP1=`echo "$TMP1" | sed 's/^#define[ ]HASSYSDC[ ]"\([^"]*\)".*$/\1/'`
772 echo "no current HASSYSDC value"
776 while test $END -eq 0
779 echo $EO "Do you want to define a system-device path (y|n) [n]? $EC"
781 if test "X$ANS" = "Xn" -o "X$ANS" = "XN"
785 if test "X$ANS" = "Xy" -o "X$ANS" = "XY"
790 if test "X$ANS" = "X"
793 echo "No HASSYSDC change will be made."
798 echo "Please answer y|n [n]."
806 echo $EO "Please enter the system-wide path (no quotes): $EC"
808 SDCV=`echo $TMP1 | sed 's/^\"//' | sed 's/\"$//'`
809 if test "X$SDCV" = "X"
817 # If HASXOPT is defined, and HASXOPT_ROOT is mentioned,
818 # ask about changing HASXOPT_ROOT.
821 grep HASXOPT $OLD | tail $TA | egrep "^#define" > /dev/null
824 grep HASXOPT_ROOT $OLD > /dev/null
829 =====================================================================
831 HASXOPT is defined. If the dialect for which you are customizing
832 appears in the following list, you may want to change the definition
833 of HASXOPT_ROOT to restrict the use of the X option to lsof processes
834 whose real user ID is root, or enable use of it by all user IDs.
836 AIX the -X option enables the risky operation of letting
837 lsof read library entry structures with readx().
838 If HASXOPT_ROOT is defined, only processes whose
839 real user ID is root will be allowed to use -X.
840 If HASXOPT_ROOT is undefined, any process will be
841 allowed to use -X. Consult the 00FAQ file of the
842 lsof distribution for more information on why
843 readx() may be risky.
847 grep HASXOPT_ROOT $OLD | tail $TA | egrep "^#define" > /dev/null
850 echo "HASXOPT_ROOT is defined."
854 echo "HASXOPT_ROOT is not defined."
859 while test $END -eq 0
862 echo $EO "Do you want to $HXR HASXOPT_ROOT (y|n) [n]? $EC"
864 if test "X$ANS" = "Xy" -o "X$ANS" = "XY"
869 if test "X$ANS" = "Xn" -o "X$ANS" = "XN" -o "X$ANS" = "X"
872 echo "HASXOPT_ROOT will not be changed."
877 echo "Please answer y|n [n]."
888 # Process HASKERNIDCK. Skip processing for selected dialect directories.
897 =====================================================================
899 When HASKERNIDCK is enabled, lsof compares the identity of the
900 kernel where it was built to the identity of the kernel where it
901 is running. This check can detect an lsof executable inappropriate
902 for the system on which it is being run.
904 The kernel identity check can take considerable time on some UNIX
905 dialects -- e.g., AIX -- so there may be occasions when it is
906 desirable to disable it, in spite of the increased risk of using
907 an inappropriate lsof executable.
911 grep HASKERNIDCK $OLD | tail $TA | grep "^#define" > /dev/null
914 echo "HASKERNIDCK is enabled."
917 echo "HASKERNIDCK is disabled."
922 while test $END -eq 0
927 echo $EO "Disable HASKERNIDCK (y|n) [n]? $EC"
929 echo $EO "Enable HASKERNIDCK (y|n) [n]? $EC"
932 if test "X$ANS" = "Xy" -o "X$ANS" = "XY"
938 echo "HASKERNIDCK will be disabled."
941 echo "HASKERNIDCK will be enabled."
945 if test "X$ANS" = "Xn" -o "X$ANS" = "XN" -o "X$ANS" = "X"
948 echo "HASKERNIDCK will not be changed."
953 echo "Please answer y|n [n]."
960 # Initialize new machine.h.
967 echo $EO " * Added by Customize on $EC" >> $NEW
972 # Change HASSECURITY and HASNOSOCKSECURITY, as required.
974 echo "#undef HASSECURITY" >> $NEW
975 echo "#undef HASNOSOCKSECURITY" >> $NEW
978 echo "#define HASSECURITY 1" >> $NEW
979 if test $SOCKSEC -eq 1
981 echo "#define HASNOSOCKSECURITY 1" >> $NEW
985 # Change WARNDEVACCESS, as required.
987 if test $NEVERWDA -eq 0
989 echo "#undef WARNDEVACCESS" >> $NEW
992 echo "#define WARNDEVACCESS 1" >> $NEW
996 # Change WARNINGSTATE, as required.
998 echo "#undef WARNINGSTATE" >> $NEW
1001 echo "#define WARNINGSTATE 1" >> $NEW
1004 # Change device cache definitions, as required.
1006 if test \( $NDC -eq 1 -a $DC -eq 0 \) -o \( $DC -eq 1 -a $CDC -eq 1 \)
1008 if test "X$ENVV" = "X" -a "X$PDCV" = "X" -a "X$SDCV" = "X"
1012 FATAL: HASDCACHE is defined, but there is no definition for
1013 any of HASENVDC, HASPERSDC, or HASSYSDC
1015 No new machine.h has been created.
1019 Restart Customize and define at least one of HASENVDC,
1020 HASPERSDC, or HASSYSDC.
1028 if test "X$PDCV" != "X"
1030 echo "$PDCV" | grep "%p" > /dev/null
1031 if test $? -eq 0 -a $PDCPN -eq 1
1035 FATAL: HASDCACHE is defined and HASPERSDC has a %p conversion,
1036 but HASPERSDCPATH is NULL.
1038 No new machine.h has been created.
1042 Restart Customize and define HASPERSDCPATH.
1050 echo "#undef HASDCACHE" >> $NEW
1051 if test $NEVERDC -eq 1
1053 echo "#undef HASENVDC" >> $NEW
1054 echo "#undef HASPERSDC" >> $NEW
1055 echo "#undef HASPERSDCPATH" >> $NEW
1056 echo "#undef HASSYSDC" >> $NEW
1060 echo "#define HASDCACHE 1" >> $NEW
1061 if test "X$ENVV" != "X" -o $ENVN -eq 1
1063 echo "#undef HASENVDC" >> $NEW
1066 echo "#define HASENVDC \"$ENVV\"" >> $NEW
1069 if test "X$PDCV" != "X" -o $PDCN -eq 1
1071 echo "#undef HASPERSDC" >> $NEW
1074 echo "#define HASPERSDC \"$PDCV\"" >> $NEW
1077 if test "X$PDCPV" != "X" -o $PDCPN -eq 1
1079 echo "#undef HASPERSDCPATH" >> $NEW
1080 if test $PDCPN -eq 0
1082 echo "#define HASPERSDCPATH \"$PDCPV\"" >> $NEW
1085 if test "X$SDCV" != "X" -o $SDCN -eq 1
1087 echo "#undef HASSYSDC" >> $NEW
1090 echo "#define HASSYSDC \"$SDCV\"" >> $NEW
1096 # Change HASXOPT_ROOT, as required.
1102 echo "#undef HASXOPT_ROOT" >> $NEW
1104 echo "#define HASXOPT_ROOT 1" >> $NEW
1108 # Change HASKERNIDCK, as required.
1110 echo "#undef HASKERNIDCK" >> $NEW
1111 if test $NIDCK -eq 1
1113 echo "#define HASKERNIDCK 1" >> $NEW
1116 # Replace the current machine.h with the new one, as requested.
1119 echo "====================================================================="
1121 echo "A new $OLD file has been created in \"$NEW\"."
1123 while test $END -eq 0
1126 echo "Do you want to rename $OLD to ${OLD}.old and replace it with"
1127 echo $EO "$NEW (y|n) [y]? $EC"
1129 if test "X$ANS" = "Xn" -o "X$ANS" = "XN"
1133 if test "X$ANS" = "Xy" -o "X$ANS" = "XY" -o "X$ANS" = "X"
1141 echo "Please answer y|n [y]."
1146 echo "You may now run the make command -- e.g.,"