1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837
|
/*
* main.c - common main function for lsof
*
* V. Abell, Purdue University
*/
/*
* Copyright 1994 Purdue Research Foundation, West Lafayette, Indiana
* 47907. All rights reserved.
*
* Written by Victor A. Abell
*
* This software is not subject to any license of the American Telephone
* and Telegraph Company or the Regents of the University of California.
*
* Permission is granted to anyone to use this software for any purpose on
* any computer system, and to alter it and redistribute it freely, subject
* to the following restrictions:
*
* 1. Neither the authors nor Purdue University are responsible for any
* consequences of the use of this software.
*
* 2. The origin of this software must not be misrepresented, either by
* explicit claim or by omission. Credit to the authors and Purdue
* University must appear in documentation and sources.
*
* 3. Altered versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 4. This notice may not be removed or altered.
*/
#ifndef lint
static char copyright[] =
"@(#) Copyright 1994 Purdue Research Foundation.\nAll rights reserved.\n";
static char *rcsid = "$Id: main.c,v 1.57 2015/07/07 20:16:58 abe Exp $";
#endif
#include "lsof.h"
/*
* Local definitions
*/
static int GObk[] = { 1, 1 }; /* option backspace values */
static char GOp; /* option prefix -- '+' or '-' */
static char *GOv = (char *)NULL; /* option `:' value pointer */
static int GOx1 = 1; /* first opt[][] index */
static int GOx2 = 0; /* second opt[][] index */
_PROTOTYPE(static int GetOpt,(int ct, char *opt[], char *rules, int *err));
_PROTOTYPE(static char *sv_fmt_str,(char *f));
/*
* main() - main function for lsof
*/
int
main(argc, argv)
int argc;
char *argv[];
{
int ad, c, i, n, rv, se1, se2, ss;
char *cp;
int err = 0;
int ev = 0;
int fh = 0;
char *fmtr = (char *)NULL;
long l;
MALLOC_S len;
struct lfile *lf;
struct nwad *np, *npn;
char options[128];
int rc = 0;
struct stat sb;
struct sfile *sfp;
struct lproc **slp = (struct lproc **)NULL;
int sp = 0;
struct str_lst *str, *strt;
int version = 0;
int xover = 0;
#if defined(HAS_STRFTIME)
char *fmt = (char *)NULL;
size_t fmtl = (size_t)0;
#endif /* defined(HAS_STRFTIME) */
#if defined(HASZONES)
znhash_t *zp;
#endif /* defined(HASZONES) */
#if defined(HASSELINUX)
/*
* This stanza must be immediately before the "Save progam name." code, since
* it contains code itself.
*/
cntxlist_t *cntxp;
CntxStatus = is_selinux_enabled() ? 1 : 0;
#endif /* defined(HASSELINUX) */
/*
* Save program name.
*/
if ((Pn = strrchr(argv[0], '/')))
Pn++;
else
Pn = argv[0];
/*
* Close enough file descriptors above 2 that library functions will have
* open descriptors.
*
* Make sure stderr, stdout, and stdin are open descriptors. Open /dev/null
* for ones that aren't. Be terse.
*
* Make sure umask allows lsof to define its own file permissions.
*/
if ((MaxFd = (int) GET_MAX_FD()) < 53)
MaxFd = 53;
for (i = 3; i < MaxFd; i++)
(void) close(i);
while (((i = open("/dev/null", O_RDWR, 0)) >= 0) && (i < 2))
;
if (i < 0)
Exit(1);
if (i > 2)
(void) close(i);
(void) umask(0);
#if defined(HASSETLOCALE)
/*
* Set locale to environment's definition.
*/
(void) setlocale(LC_CTYPE, "");
#endif /* defined(HASSETLOCALE) */
/*
* Common initialization.
*/
Mypid = getpid();
if ((Mygid = (gid_t)getgid()) != getegid())
Setgid = 1;
Euid = geteuid();
if ((Myuid = (uid_t)getuid()) && !Euid)
Setuidroot = 1;
if (!(Namech = (char *)malloc(MAXPATHLEN + 1))) {
(void) fprintf(stderr, "%s: no space for name buffer\n", Pn);
Exit(1);
}
Namechl = (size_t)(MAXPATHLEN + 1);
/*
* Create option mask.
*/
(void) snpf(options, sizeof(options),
"?a%sbc:%sD:d:%s%sf:F:g:hi:%s%slL:%s%snNo:Op:Pr:%ss:S:tT:u:UvVwx:%s%s%s",
#if defined(HAS_AFS) && defined(HASAOPT)
"A:",
#else /* !defined(HAS_AFS) || !defined(HASAOPT) */
"",
#endif /* defined(HAS_AFS) && defined(HASAOPT) */
#if defined(HASNCACHE)
"C",
#else /* !defined(HASNCACHE) */
"",
#endif /* defined(HASNCACHE) */
#if defined(HASEOPT)
"e:",
#else /* !defined(HASEOPT) */
"",
#endif /* defined(HASEOPT) */
#if defined(HASEPTOPTS)
"E",
#else /* !defined(HASEPTOPTS) */
"",
#endif /* defined(HASEPTOPTS) */
#if defined(HASKOPT)
"k:",
#else /* !defined(HASKOPT) */
"",
#endif /* defined(HASKOPT) */
#if defined(HASTASKS)
"K",
#else /* !defined(HASTASKS) */
"",
#endif /* defined(HASTASKS) */
#if defined(HASMOPT) || defined(HASMNTSUP)
"m:",
#else /* !defined(HASMOPT) && !defined(HASMNTSUP) */
"",
#endif /* defined(HASMOPT) || defined(HASMNTSUP) */
#if defined(HASNORPC_H)
"",
#else /* !defined(HASNORPC_H) */
"M",
#endif /* defined(HASNORPC_H) */
#if defined(HASPPID)
"R",
#else /* !defined(HASPPID) */
"",
#endif /* defined(HASPPID) */
#if defined(HASXOPT)
# if defined(HASXOPT_ROOT)
(Myuid == 0) ? "X" : "",
# else /* !defined(HASXOPT_ROOT) */
"X",
# endif /* defined(HASXOPT_ROOT) */
#else /* !defined(HASXOPT) */
"",
#endif /* defined(HASXOPT) */
#if defined(HASZONES)
"z:",
#else /* !defined(HASZONES) */
"",
#endif /* defined(HASZONES) */
#if defined(HASSELINUX)
"Z:"
#else /* !defined(HASSELINUX) */
""
#endif /* defined(HASSELINUX) */
);
/*
* Loop through options.
*/
while ((c = GetOpt(argc, argv, options, &rv)) != EOF) {
if (rv) {
err = 1;
continue;
}
switch (c) {
case 'a':
Fand = 1;
break;
#if defined(HAS_AFS) && defined(HASAOPT)
case 'A':
if (!GOv || *GOv == '-' || *GOv == '+') {
(void) fprintf(stderr, "%s: -A not followed by path\n", Pn);
err = 1;
if (GOv) {
GOx1 = GObk[0];
GOx2 = GObk[1];
}
} else
AFSApath = GOv;
break;
#endif /* defined(HAS_AFS) && defined(HASAOPT) */
case 'b':
Fblock = 1;
break;
case 'c':
if (GOp == '+') {
if (!GOv || (*GOv == '-') || (*GOv == '+')
|| !isdigit((int)*GOv))
{
(void) fprintf(stderr,
"%s: +c not followed by width number\n", Pn);
err = 1;
if (GOv) {
GOx1 = GObk[0];
GOx2 = GObk[1];
}
} else {
CmdLim = atoi(GOv);
#if defined(MAXSYSCMDL)
if (CmdLim > MAXSYSCMDL) {
(void) fprintf(stderr,
"%s: +c %d > what system provides (%d)\n",
Pn, CmdLim, MAXSYSCMDL);
err = 1;
}
#endif /* defined(MAXSYSCMDL) */
}
break;
}
if (GOv && (*GOv == '/')) {
if (enter_cmd_rx(GOv))
err = 1;
} else {
if (enter_str_lst("-c", GOv, &Cmdl, &Cmdni, &Cmdnx))
err = 1;
#if defined(MAXSYSCMDL)
else if (Cmdl->len > MAXSYSCMDL) {
(void) fprintf(stderr, "%s: \"-c ", Pn);
(void) safestrprt(Cmdl->str, stderr, 2);
(void) fprintf(stderr, "\" length (%d) > what system",
Cmdl->len);
(void) fprintf(stderr, " provides (%d)\n",
MAXSYSCMDL);
Cmdl->len = 0; /* (to avoid later error report) */
err = 1;
}
#endif /* defined(MAXSYSCMDL) */
}
break;
#if defined(HASNCACHE)
case 'C':
Fncache = (GOp == '-') ? 0 : 1;
break;
#endif /* defined(HASNCACHE) */
case 'd':
if (GOp == '+') {
if (enter_dir(GOv, 0))
err = 1;
else {
Selflags |= SELNM;
xover = 1;
}
} else {
if (enter_fd(GOv))
err = 1;
}
break;
case 'D':
if (GOp == '+') {
if (enter_dir(GOv, 1))
err = 1;
else {
Selflags |= SELNM;
xover = 1;
}
} else {
#if defined(HASDCACHE)
if (ctrl_dcache(GOv))
err = 1;
#else /* !defined(HASDCACHE) */
(void) fprintf(stderr, "%s: unsupported option: -D\n", Pn);
err = 1;
#endif /* defined(HASDCACHE) */
}
break;
#if defined(HASEOPT)
case 'e':
if (enter_efsys(GOv, ((GOp == '+') ? 1 : 0)))
err = 1;
break;
#endif /* defined(HASEOPT) */
#if defined(HASEPTOPTS)
case 'E':
FeptE = (GOp == '+') ? 2 : 1;
break;
#endif /* defined(HASEPTOPTS) */
case 'f':
if (!GOv || *GOv == '-' || *GOv == '+') {
Ffilesys = (GOp == '+') ? 2 : 1;
if (GOv) {
GOx1 = GObk[0];
GOx2 = GObk[1];
}
break;
}
#if defined(HASFSTRUCT)
for (; *GOv; GOv++) {
switch (*GOv) {
# if !defined(HASNOFSCOUNT)
case 'c':
case 'C':
if (GOp == '+') {
Fsv |= FSV_CT;
FsvByf = 1;
} else
Fsv &= (unsigned char)~FSV_CT;
break;
# endif /* !defined(HASNOFSCOUNT) */
# if !defined(HASNOFSADDR)
case 'f':
case 'F':
if (GOp == '+') {
Fsv |= FSV_FA;
FsvByf = 1;
} else
Fsv &= (unsigned char)~FSV_FA;
break;
# endif /* !defined(HASNOFSADDR) */
# if !defined(HASNOFSFLAGS)
case 'g':
case 'G':
if (GOp == '+') {
Fsv |= FSV_FG;
FsvByf = 1;
} else
Fsv &= (unsigned char)~FSV_FG;
FsvFlagX = (*GOv == 'G') ? 1 : 0;
break;
# endif /* !defined(HASNOFSFLAGS) */
# if !defined(HASNOFSNADDR)
case 'n':
case 'N':
if (GOp == '+') {
Fsv |= FSV_NI;
FsvByf = 1;
} else
Fsv &= (unsigned char)~FSV_NI;
break;
# endif /* !defined(HASNOFSNADDR */
default:
(void) fprintf(stderr,
"%s: unknown file struct option: %c\n", Pn, *GOv);
err++;
}
}
#else /* !defined(HASFSTRUCT) */
(void) fprintf(stderr,
"%s: unknown string for %cf: %s\n", Pn, GOp, GOv);
err++;
#endif /* defined(HASFSTRUCT) */
break;
case 'F':
if (!GOv || *GOv == '-' || *GOv == '+'
|| strcmp(GOv, "0") == 0) {
if (GOv) {
if (*GOv == '-' || *GOv == '+') {
GOx1 = GObk[0];
GOx2 = GObk[1];
} else if (*GOv == '0')
Terminator = '\0';
}
for (i = 0; FieldSel[i].nm; i++) {
#if !defined(HASPPID)
if (FieldSel[i].id == LSOF_FID_PPID)
continue;
#endif /* !defined(HASPPID) */
#if !defined(HASFSTRUCT)
if (FieldSel[i].id == LSOF_FID_CT
|| FieldSel[i].id == LSOF_FID_FA
|| FieldSel[i].id == LSOF_FID_FG
|| FieldSel[i].id == LSOF_FID_NI)
continue;
#endif /* !defined(HASFSTRUCT) */
#if defined(HASSELINUX)
if ((FieldSel[i].id == LSOF_FID_CNTX) && !CntxStatus)
continue;
#else /* !defined(HASSELINUX) */
if (FieldSel[i].id == LSOF_FID_CNTX)
continue;
#endif /* !defined(HASSELINUX) */
if (FieldSel[i].id == LSOF_FID_RDEV)
continue; /* for compatibility */
#if !defined(HASTASKS)
if (FieldSel[i].id == LSOF_FID_TID)
continue;
#endif /* !defined(HASTASKS) */
#if !defined(HASZONES)
if (FieldSel[i].id == LSOF_FID_ZONE)
continue;
#endif /* !defined(HASZONES) */
FieldSel[i].st = 1;
if (FieldSel[i].opt && FieldSel[i].ov)
*(FieldSel[i].opt) |= FieldSel[i].ov;
}
#if defined(HASFSTRUCT)
Ffield = FsvFlagX = 1;
#else /* !defined(HASFSTRUCT) */
Ffield = 1;
#endif /* defined(HASFSTRUCT) */
break;
}
if (strcmp(GOv, "?") == 0) {
fh = 1;
break;
}
for (; *GOv; GOv++) {
for (i = 0; FieldSel[i].nm; i++) {
#if !defined(HASPPID)
if (FieldSel[i].id == LSOF_FID_PPID)
continue;
#endif /* !defined(HASPPID) */
#if !defined(HASFSTRUCT)
if (FieldSel[i].id == LSOF_FID_CT
|| FieldSel[i].id == LSOF_FID_FA
|| FieldSel[i].id == LSOF_FID_FG
|| FieldSel[i].id == LSOF_FID_NI)
continue;
#endif /* !defined(HASFSTRUCT) */
#if !defined(HASTASKS)
if (FieldSel[i].id == LSOF_FID_TID)
continue;
#endif /* !defined(HASTASKS) */
if (FieldSel[i].id == *GOv) {
FieldSel[i].st = 1;
if (FieldSel[i].opt && FieldSel[i].ov)
*(FieldSel[i].opt) |= FieldSel[i].ov;
#if defined(HASFSTRUCT)
if (i == LSOF_FIX_FG)
FsvFlagX = 1;
#endif /* defined(HASFSTRUCT) */
if (i == LSOF_FIX_TERM)
Terminator = '\0';
break;
}
}
if ( ! FieldSel[i].nm) {
(void) fprintf(stderr,
"%s: unknown field: %c\n", Pn, *GOv);
err++;
}
}
Ffield = 1;
break;
case 'g':
if (GOv) {
if (*GOv == '-' || *GOv == '+') {
GOx1 = GObk[0];
GOx2 = GObk[1];
} else if (enter_id(PGID, GOv))
err = 1;
}
Fpgid = 1;
break;
case 'h':
case '?':
Fhelp = 1;
break;
case 'i':
if (!GOv || *GOv == '-' || *GOv == '+') {
Fnet = 1;
FnetTy = 0;
if (GOv) {
GOx1 = GObk[0];
GOx2 = GObk[1];
}
break;
}
if (enter_network_address(GOv))
err = 1;
break;
#if defined(HASKOPT)
case 'k':
if (!GOv || *GOv == '-' || *GOv == '+') {
(void) fprintf(stderr, "%s: -k not followed by path\n", Pn);
err = 1;
if (GOv) {
GOx1 = GObk[0];
GOx2 = GObk[1];
}
} else
Nmlst = GOv;
break;
#endif /* defined(HASKOPT) */
#if defined(HASTASKS)
case 'K':
Ftask = 1;
Selflags |= SELTASK;
break;
#endif /* defined(HASTASKS) */
case 'l':
Futol = 0;
break;
case 'L':
Fnlink = (GOp == '+') ? 1 : 0;
if (!GOv || *GOv == '-' || *GOv == '+') {
Nlink = 0l;
if (GOv) {
GOx1 = GObk[0];
GOx2 = GObk[1];
}
break;
}
for (cp = GOv, l = 0l, n = 0; *cp; cp++) {
if (!isdigit((unsigned char)*cp))
break;
l = (l * 10l) + ((long)*cp - (long)'0');
n++;
}
if (n) {
if (GOp != '+') {
(void) fprintf(stderr,
"%s: no number may follow -L\n", Pn);
err = 1;
} else {
Nlink = l;
Selflags |= SELNLINK;
}
} else
Nlink = 0l;
if (*cp) {
GOx1 = GObk[0];
GOx2 = GObk[1] + n;
}
break;
#if defined(HASMOPT) || defined(HASMNTSUP)
case 'm':
if (GOp == '-') {
# if defined(HASMOPT)
if (!GOv || *GOv == '-' || *GOv == '+') {
(void) fprintf(stderr,
"%s: -m not followed by path\n", Pn);
err = 1;
if (GOv) {
GOx1 = GObk[0];
GOx2 = GObk[1];
}
} else
Memory = GOv;
# else /* !defined(HASMOPT) */
(void) fprintf(stderr, "%s: -m not supported\n", Pn);
err = 1;
# endif /* defined(HASMOPT) */
} else if (GOp == '+') {
# if defined(HASMNTSUP)
if (!GOv || *GOv == '-' || *GOv == '+') {
MntSup = 1;
if (GOv) {
GOx1 = GObk[0];
GOx2 = GObk[1];
}
} else {
MntSup = 2;
MntSupP = GOv;
}
# else /* !defined(HASMNTSUP) */
(void) fprintf(stderr, "%s: +m not supported\n", Pn);
err = 1;
# endif /* defined(HASMNTSUP) */
} else {
(void) fprintf(stderr, "%s: %cm not supported\n", Pn, GOp);
err = 1;
}
break;
#endif /* defined(HASMOPT) || defined(HASMNTSUP) */
#if !defined(HASNORPC_H)
case 'M':
FportMap = (GOp == '+') ? 1 : 0;
break;
#endif /* !defined(HASNORPC_H) */
case 'n':
Fhost = (GOp == '-') ? 0 : 1;
break;
case 'N':
Fnfs = 1;
break;
case 'o':
if (!GOv || *GOv == '-' || *GOv == '+') {
Foffset = 1;
if (GOv) {
GOx1 = GObk[0];
GOx2 = GObk[1];
}
break;
}
for (cp = GOv, i = n = 0; *cp; cp++) {
if (!isdigit((unsigned char)*cp))
break;
i = (i * 10) + ((int)*cp - '0');
n++;
}
if (n)
OffDecDig = i;
else
Foffset = 1;
if (*cp) {
GOx1 = GObk[0];
GOx2 = GObk[1] + n;
}
break;
case 'O':
Fovhd = (GOp == '-') ? 1 : 0;
break;
case 'p':
if (enter_id(PID, GOv))
err = 1;
break;
case 'P':
Fport = (GOp == '-') ? 0 : 1;
break;
case 'r':
if (GOp == '+')
ev = rc = 1;
if (!GOv || *GOv == '-' || *GOv == '+') {
RptTm = RPTTM;
if (GOv) {
GOx1 = GObk[0];
GOx2 = GObk[1];
}
break;
}
for (cp = GOv, i = n = 0; *cp; cp++) {
if (!isdigit((unsigned char)*cp))
break;
i = (i * 10) + ((int)*cp - '0');
n++;
}
if (n)
RptTm = i;
else
RptTm = RPTTM;
if (!*cp)
break;
while(*cp && (*cp == ' '))
cp++;
if (*cp != LSOF_FID_MARK) {
GOx1 = GObk[0];
GOx2 = GObk[1] + n;
break;
}
#if defined(HAS_STRFTIME)
/*
* Collect the strftime(3) format and test it.
*/
cp++;
if ((fmtl = strlen(cp) + 1) < 1) {
(void) fprintf(stderr, "%s: <fmt> too short: \"%s\"\n",
Pn, cp);
err = 1;
} else {
fmt = cp;
fmtl = (fmtl * 8) + 1;
if (!(fmtr = (char *)malloc((MALLOC_S)fmtl))) {
(void) fprintf(stderr,
"%s: no space (%d) for <fmt> result: \"%s\"\n",
Pn, (int)fmtl, cp);
Exit(1);
}
if (util_strftime(fmtr, fmtl - 1, fmt) < 1) {
(void) fprintf(stderr, "%s: illegal <fmt>: \"%s\"\n",
Pn, fmt);
err = 1;
}
}
#else /* !defined(HAS_STRFTIME) */
(void) fprintf(stderr, "%s: m<fmt> not supported: \"%s\"\n",
Pn, cp);
err = 1;
#endif /* defined(HAS_STRFTIME) */
break;
#if defined(HASPPID)
case 'R':
Fppid = 1;
break;
#endif /* defined(HASPPID) */
case 's':
#if defined(HASTCPUDPSTATE)
if (!GOv || *GOv == '-' || *GOv == '+') {
Fsize = 1;
if (GOv) {
GOx1 = GObk[0];
GOx2 = GObk[1];
}
} else {
if (enter_state_spec(GOv))
err = 1;
}
#else /* !defined(HASTCPUDPSTATE) */
Fsize = 1;
#endif /* defined(HASTCPUDPSTATE) */
break;
case 'S':
if (!GOv || *GOv == '-' || *GOv == '+') {
TmLimit = TMLIMIT;
if (GOv) {
GOx1 = GObk[0];
GOx2 = GObk[1];
}
break;
}
for (cp = GOv, i = n = 0; *cp; cp++) {
if (!isdigit((unsigned char)*cp))
break;
i = (i * 10) + ((int)*cp - '0');
n++;
}
if (n)
TmLimit = i;
else
TmLimit = TMLIMIT;
if (*cp) {
GOx1 = GObk[0];
GOx2 = GObk[1] + n;
}
if (TmLimit < TMLIMMIN) {
(void) fprintf(stderr,
"%s: WARNING: -S time (%d) changed to %d\n",
Pn, TmLimit, TMLIMMIN);
TmLimit = TMLIMMIN;
}
break;
case 't':
Fterse = Fwarn = 1;
break;
case 'T':
if (!GOv || *GOv == '-' || *GOv == '+') {
Ftcptpi = (GOp == '-') ? 0 : TCPTPI_STATE;
if (GOv) {
GOx1 = GObk[0];
GOx2 = GObk[1];
}
break;
}
for (Ftcptpi = 0; *GOv; GOv++) {
switch (*GOv) {
#if defined(HASSOOPT) || defined(HASSOSTATE) || defined(HASTCPOPT)
case 'f':
Ftcptpi |= TCPTPI_FLAGS;
break;
#endif /* defined(HASSOOPT) || defined(HASSOSTATE) || defined(HASTCPOPT) */
#if defined(HASTCPTPIQ)
case 'q':
Ftcptpi |= TCPTPI_QUEUES;
break;
#endif /* defined(HASTCPTPIQ) */
case 's':
Ftcptpi |= TCPTPI_STATE;
break;
#if defined(HASTCPTPIW)
case 'w':
Ftcptpi |= TCPTPI_WINDOWS;
break;
#endif /* defined(HASTCPTPIW) */
default:
(void) fprintf(stderr,
"%s: unsupported TCP/TPI info selection: %c\n",
Pn, *GOv);
err = 1;
}
}
break;
case 'u':
if (enter_uid(GOv))
err = 1;
break;
case 'U':
Funix = 1;
break;
case 'v':
version = 1;
break;
case 'V':
Fverbose = 1;
break;
case 'w':
Fwarn = (GOp == '+') ? 0 : 1;
break;
case 'x':
if (!GOv || *GOv == '-' || *GOv == '+') {
Fxover = XO_ALL;
if (GOv) {
GOx1 = GObk[0];
GOx2 = GObk[1];
}
break;
} else {
for (; *GOv; GOv++) {
switch (*GOv) {
case 'f':
Fxover |= XO_FILESYS;
break;
case 'l':
Fxover |= XO_SYMLINK;
break;
default:
(void) fprintf(stderr,
"%s: unknown cross-over option: %c\n",
Pn, *GOv);
err++;
}
}
}
break;
#if defined(HASXOPT)
case 'X':
Fxopt = Fxopt ? 0 : 1;
break;
#endif /* defined(HASXOPT) */
#if defined(HASZONES)
case 'z':
Fzone = 1;
if (GOv && (*GOv != '-') && (*GOv != '+')) {
/*
* Add to the zone name argument hash.
*/
if (enter_zone_arg(GOv))
err = 1;
} else if (GOv) {
GOx1 = GObk[0];
GOx2 = GObk[1];
}
break;
#endif /* defined(HASZONES) */
#if defined(HASSELINUX)
case 'Z':
if (!CntxStatus) {
(void) fprintf(stderr, "%s: -Z limited to SELinux\n", Pn);
err = 1;
} else {
Fcntx = 1;
if (GOv && (*GOv != '-') && (*GOv != '+')) {
/*
* Add to the context name argument hash.
*/
if (enter_cntx_arg(GOv))
err = 1;
} else if (GOv) {
GOx1 = GObk[0];
GOx2 = GObk[1];
}
}
break;
#endif /* defined(HASSELINUX) */
default:
(void) fprintf(stderr, "%s: unknown option (%c)\n", Pn, c);
err = 1;
}
}
/*
* Check for argument consistency.
*/
if (Cmdnx && Cmdni) {
/*
* Check for command inclusion/exclusion conflicts.
*/
for (str = Cmdl; str; str = str->next) {
if (str->x) {
for (strt = Cmdl; strt; strt = strt->next) {
if (!strt->x) {
if (!strcmp(str->str, strt->str)) {
(void) fprintf(stderr,
"%s: -c^%s and -c%s conflict.\n",
Pn, str->str, strt->str);
err++;
}
}
}
}
}
}
#if defined(HASTCPUDPSTATE)
if (TcpStXn && TcpStIn) {
/*
* Check for excluded and included TCP states.
*/
for (i = 0; i < TcpNstates; i++) {
if (TcpStX[i] && TcpStI[i]) {
(void) fprintf(stderr,
"%s: can't include and exclude TCP state: %s\n",
Pn, TcpSt[i]);
err = 1;
}
}
}
if (UdpStXn && UdpStIn) {
/*
* Check for excluded and included UDP states.
*/
for (i = 0; i < UdpNstates; i++) {
if (UdpStX[i] && UdpStI[i]) {
(void) fprintf(stderr,
"%s: can't include and exclude UDP state: %s\n",
Pn, UdpSt[i]);
err = 1;
}
}
}
#endif /* defined(HASTCPUDPSTATE) */
if (Fsize && Foffset) {
(void) fprintf(stderr, "%s: -o and -s are mutually exclusive\n",
Pn);
err++;
}
if (Ffield) {
if (Fterse) {
(void) fprintf(stderr,
"%s: -F and -t are mutually exclusive\n", Pn);
err++;
}
FieldSel[LSOF_FIX_PID].st = 1;
#if defined(HAS_STRFTIME)
if (fmtr) {
/*
* The field output marker format can't contain "%n" new line
* requests.
*/
for (cp = strchr(fmt, '%'); cp; cp = strchr(cp, '%')) {
if (*++cp == 'n') {
(void) fprintf(stderr,
"%s: %%n illegal in -r m<fmt> when -F has", Pn);
(void) fprintf(stderr,
" been specified: \"%s\"\n", fmt);
err++;
break;
} else if (*cp == '%')
cp++;
}
}
#endif /* defined(HAS_STRFTIME) */
}
if (Fxover && !xover) {
(void) fprintf(stderr, "%s: -x must accompany +d or +D\n", Pn);
err++;
}
#if defined(HASEOPT)
if (Efsysl) {
/*
* If there are file systems specified by -e options, check them.
*/
efsys_list_t *ep; /* Efsysl pointer */
struct mounts *mp, *mpw; /* local mount table pointers */
if ((mp = readmnt())) {
for (ep = Efsysl; ep; ep = ep->next) {
for (mpw = mp; mpw; mpw = mpw->next) {
if (!strcmp(mpw->dir, ep->path)) {
ep->mp = mpw;
break;
}
}
if (!ep->mp) {
(void) fprintf(stderr,
"%s: \"-e %s\" is not a mounted file system.\n",
Pn, ep->path);
err++;
}
}
}
}
#endif /* defined(HASEOPT) */
if (DChelp || err || Fhelp || fh || version)
usage(err ? 1 : 0, fh, version);
/*
* Reduce the size of Suid[], if necessary.
*/
if (Suid && Nuid && Nuid < Mxuid) {
if (!(Suid = (struct seluid *)realloc((MALLOC_P *)Suid,
(MALLOC_S)(sizeof(struct seluid) * Nuid))))
{
(void) fprintf(stderr, "%s: can't realloc UID table\n", Pn);
Exit(1);
}
Mxuid = Nuid;
}
/*
* Compute the selection flags.
*/
if ((Cmdl && Cmdni) || CmdRx)
Selflags |= SELCMD;
#if defined(HASSELINUX)
if (CntxArg)
Selflags |= SELCNTX;
#endif /* defined(HASSELINUX) */
if (Fdl)
Selflags |= SELFD;
if (Fnet)
Selflags |= SELNET;
if (Fnfs)
Selflags |= SELNFS;
if (Funix)
Selflags |= SELUNX;
if (Npgid && Npgidi)
Selflags |= SELPGID;
if (Npid && Npidi)
Selflags |= SELPID;
if (Nuid && Nuidincl)
Selflags |= SELUID;
if (Nwad)
Selflags |= SELNA;
#if defined(HASZONES)
if (ZoneArg)
Selflags |= SELZONE;
#endif /* defined(HASZONES) */
if (GOx1 < argc)
Selflags |= SELNM;
if (Selflags == 0) {
if (Fand) {
(void) fprintf(stderr,
"%s: no select options to AND via -a\n", Pn);
usage(1, 0, 0);
}
Selflags = SELALL;
} else {
if (GOx1 >= argc && (Selflags & (SELNA|SELNET)) != 0
&& (Selflags & ~(SELNA|SELNET)) == 0)
Selinet = 1;
Selall = 0;
}
/*
* Get the device for DEVDEV_PATH.
*/
if (stat(DEVDEV_PATH, &sb)) {
se1 = errno;
if ((ad = strcmp(DEVDEV_PATH, "/dev"))) {
if ((ss = stat("/dev", &sb)))
se2 = errno;
else
se2 = 0;
} else {
se2 = 0;
ss = 1;
}
if (ss) {
(void) fprintf(stderr, "%s: can't stat(%s): %s\n", Pn,
DEVDEV_PATH, strerror(se1));
if (ad) {
(void) fprintf(stderr, "%s: can't stat(/dev): %s\n", Pn,
strerror(se2));
}
Exit(1);
}
}
DevDev = sb.st_dev;
/*
* Process the file arguments.
*/
if (GOx1 < argc) {
if (ck_file_arg(GOx1, argc, argv, Ffilesys, 0, (struct stat *)NULL))
usage(1, 0, 0);
}
/*
* Do dialect-specific initialization.
*/
initialize();
if (Sfile)
(void) hashSfile();
#if defined(WILLDROPGID)
/*
* If this process isn't setuid(root), but it is setgid(not_real_gid),
* relinquish the setgid power. (If it hasn't already been done.)
*/
(void) dropgid();
#endif /* defined(WILLDROPGID) */
#if defined(HASDCACHE)
/*
* If there is a device cache, prepare the device table.
*/
if (DCstate)
readdev(0);
#endif /* defined(HASDCACHE) */
/*
* Define the size and offset print formats.
*/
(void) snpf(options, sizeof(options), "%%%su", INODEPSPEC);
InodeFmt_d = sv_fmt_str(options);
(void) snpf(options, sizeof(options), "%%#%sx", INODEPSPEC);
InodeFmt_x = sv_fmt_str(options);
(void) snpf(options, sizeof(options), "0t%%%su", SZOFFPSPEC);
SzOffFmt_0t = sv_fmt_str(options);
(void) snpf(options, sizeof(options), "%%%su", SZOFFPSPEC);
SzOffFmt_d = sv_fmt_str(options);
(void) snpf(options, sizeof(options), "%%*%su", SZOFFPSPEC);
SzOffFmt_dv = sv_fmt_str(options);
(void) snpf(options, sizeof(options), "%%#%sx", SZOFFPSPEC);
SzOffFmt_x = sv_fmt_str(options);
#if defined(HASMNTSUP)
/*
* Report mount supplement information, as requested.
*/
if (MntSup == 1) {
(void) readmnt();
Exit(0);
}
#endif /* defined(HASMNTSUP) */
/*
* Gather and report process information every RptTm seconds.
*/
if (RptTm)
CkPasswd = 1;
do {
/*
* Gather information about processes.
*/
gather_proc_info();
/*
* If the local process table has more than one entry, sort it by PID.
*/
if (Nlproc > 1) {
if (Nlproc > sp) {
len = (MALLOC_S)(Nlproc * sizeof(struct lproc *));
sp = Nlproc;
if (!slp)
slp = (struct lproc **)malloc(len);
else
slp = (struct lproc **)realloc((MALLOC_P *)slp, len);
if (!slp) {
(void) fprintf(stderr,
"%s: no space for %d sort pointers\n", Pn, Nlproc);
Exit(1);
}
}
for (i = 0; i < Nlproc; i++) {
slp[i] = &Lproc[i];
}
(void) qsort((QSORT_P *)slp, (size_t)Nlproc,
(size_t)sizeof(struct lproc *), comppid);
}
if ((n = Nlproc)) {
#if defined(HASNCACHE)
/*
* If using the kernel name cache, force its reloading.
*/
NcacheReload = 1;
#endif /* defined(HASNCACHE) */
#if defined(HASEPTOPTS)
/*
* If endpoint info has been requested, make sure it is coded for
* printing.
*
* Lf contents must be preserved, since they may point to a
* malloc()'d area, and since Lf is used throughout the print
*/
if (FeptE) {
lf = Lf;
/*
* Check the files that have been selected for printing by
* by some selection criterion other than being a pipe.
*/
for (i = 0; i < Nlproc; i++) {
Lp = (Nlproc > 1) ? slp[i] : &Lproc[i];
if (Lp->pss && (Lp->ept & EPT_PIPE))
(void) process_pinfo(0);
}
/*
* In a second pass, process unselected endpoint files,
* possibly selecting them for printing.
*/
for (i = 0; i < Nlproc; i++) {
Lp = (Nlproc > 1) ? slp[i] : &Lproc[i];
if (Lp->ept & EPT_PIPE_END)
(void) process_pinfo(1);
}
# if defined(HASUXSOCKEPT)
/*
* Process UNIX socket endpoint files in a similar fashion.
*/
for (i = 0; i < Nlproc; i++) {
Lp = (Nlproc > 1) ? slp[i] : &Lproc[i];
if (Lp->pss && (Lp->ept & EPT_UXS))
(void) process_uxsinfo(0);
}
for (i = 0; i < Nlproc; i++) {
Lp = (Nlproc > 1) ? slp[i] : &Lproc[i];
if (Lp->ept & EPT_UXS_END) {
(void) process_uxsinfo(1);
}
}
# endif /* defined(HASUXSOCKEPT) */
Lf = lf;
}
#endif /* defined(HASEPTOPTS) */
/*
* Print the selected processes and count them.
*
* Lf contents must be preserved, since they may point to a
* malloc()'d area, and since Lf is used throughout the print
* process.
*/
for (lf = Lf, print_init(); PrPass < 2; PrPass++) {
for (i = n = 0; i < Nlproc; i++) {
Lp = (Nlproc > 1) ? slp[i] : &Lproc[i];
if (Lp->pss) {
if (print_proc())
n++;
}
if (RptTm && PrPass)
(void) free_lproc(Lp);
}
}
Lf = lf;
}
/*
* If a repeat time is set, sleep for the specified time.
*
* If conditional repeat mode is in effect, see if it's time to exit.
*/
if (RptTm) {
#if defined(HASEPTOPTS)
(void) clear_pinfo();
#endif /* defined(HASEPTOPTS) */
if (rc) {
if (!n)
break;
else
ev = 0;
}
#if defined(HAS_STRFTIME)
if (fmt && fmtr) {
/*
* Format the marker line.
*/
(void) util_strftime(fmtr, fmtl - 1, fmt);
fmtr[fmtl - 1] = '\0';
}
#endif /* defined(HAS_STRFTIME) */
if (Ffield) {
putchar(LSOF_FID_MARK);
#if defined(HAS_STRFTIME)
if (fmtr)
(void) printf("%s", fmtr);
#endif /* defined(HAS_STRFTIME) */
putchar(Terminator);
if (Terminator != '\n')
putchar('\n');
} else {
#if defined(HAS_STRFTIME)
if (fmtr)
cp = fmtr;
else
#endif /* defined(HAS_STRFTIME) */
cp = "=======";
puts(cp);
}
(void) fflush(stdout);
(void) childx();
(void) sleep(RptTm);
Hdr = Nlproc = 0;
CkPasswd = 1;
}
} while (RptTm);
/*
* See if all requested information was displayed. Return zero if it
* was; one, if not. If -V was specified, report what was not displayed.
*/
(void) childx();
rv = 0;
for (str = Cmdl; str; str = str->next) {
/*
* Check command specifications.
*/
if (str->f)
continue;
rv = 1;
if (Fverbose) {
(void) printf("%s: command not located: ", Pn);
safestrprt(str->str, stdout, 1);
}
}
for (i = 0; i < NCmdRxU; i++) {
/*
* Check command regular expressions.
*/
if (CmdRx[i].mc)
continue;
rv = 1;
if (Fverbose) {
(void) printf("%s: no command found for regex: ", Pn);
safestrprt(CmdRx[i].exp, stdout, 1);
}
}
for (sfp = Sfile; sfp; sfp = sfp->next) {
/*
* Check file specifications.
*/
if (sfp->f)
continue;
rv = 1;
if (Fverbose) {
(void) printf("%s: no file%s use located: ", Pn,
sfp->type ? "" : " system");
safestrprt(sfp->aname, stdout, 1);
}
}
#if defined(HASPROCFS)
/*
* Report on proc file system search results.
*/
if (Procsrch && !Procfind) {
rv = 1;
if (Fverbose) {
(void) printf("%s: no file system use located: ", Pn);
safestrprt(Mtprocfs ? Mtprocfs->dir : HASPROCFS, stdout, 1);
}
}
{
struct procfsid *pfi;
for (pfi = Procfsid; pfi; pfi = pfi->next) {
if (!pfi->f) {
rv = 1;
if (Fverbose) {
(void) printf("%s: no file use located: ", Pn);
safestrprt(pfi->nm, stdout, 1);
}
}
}
}
#endif /* defined(HASPROCFS) */
if ((np = Nwad)) {
/*
* Check Internet address specifications.
*
* If any Internet address derived from the same argument was found,
* consider all derivations found. If no derivation from the same
* argument was found, report only the first failure.
*
*/
for (; np; np = np->next) {
if (!(cp = np->arg))
continue;
for (npn = np->next; npn; npn = npn->next) {
if (!npn->arg)
continue;
if (!strcmp(cp, npn->arg)) {
/*
* If either of the duplicate specifications was found,
* mark them both found. If neither was found, mark all
* but the first one found.
*/
if (np->f)
npn->f = np->f;
else if (npn->f)
np->f = npn->f;
else
npn->f = 1;
}
}
}
for (np = Nwad; np; np = np->next) {
if (!np->f && (cp = np->arg)) {
rv = 1;
if (Fverbose) {
(void) printf("%s: Internet address not located: ", Pn);
safestrprt(cp ? cp : "(unknown)", stdout, 1);
}
}
}
}
if (Fnet && Fnet < 2) {
/*
* Report no Internet files located.
*/
rv = 1;
if (Fverbose)
(void) printf("%s: no Internet files located\n", Pn);
}
#if defined(HASTCPUDPSTATE)
if (TcpStIn) {
/*
* Check for included TCP states not located.
*/
for (i = 0; i < TcpNstates; i++) {
if (TcpStI[i] == 1) {
rv = 1;
if (Fverbose)
(void) printf("%s: TCP state not located: %s\n",
Pn, TcpSt[i]);
}
}
}
if (UdpStIn) {
/*
* Check for included UDP states not located.
*/
for (i = 0; i < UdpNstates; i++) {
if (UdpStI[i] == 1) {
rv = 1;
if (Fverbose)
(void) printf("%s: UDP state not located: %s\n",
Pn, UdpSt[i]);
}
}
}
#endif /* defined(HASTCPUDPSTATE) */
if (Fnfs && Fnfs < 2) {
/*
* Report no NFS files located.
*/
rv = 1;
if (Fverbose)
(void) printf("%s: no NFS files located\n", Pn);
}
for (i = 0; i < Npid; i++) {
/*
* Check inclusionary process ID specifications.
*/
if (Spid[i].f || Spid[i].x)
continue;
rv = 1;
if (Fverbose)
(void) printf("%s: process ID not located: %d\n",
Pn, Spid[i].i);
}
#if defined(HASTASKS)
if (Ftask && Ftask < 2) {
/*
* Report no tasks located.
*/
rv = 1;
if (Fverbose)
(void) printf("%s: no tasks located\n", Pn);
}
#endif /* defined(HASTASKS) */
#if defined(HASZONES)
if (ZoneArg) {
/*
* Check zone argument results.
*/
for (i = 0; i < HASHZONE; i++) {
for (zp = ZoneArg[i]; zp; zp = zp->next) {
if (!zp->f) {
rv = 1;
if (Fverbose) {
(void) printf("%s: zone not located: ", Pn);
safestrprt(zp->zn, stdout, 1);
}
}
}
}
}
#endif /* defined(HASZONES) */
#if defined(HASSELINUX)
if (CntxArg) {
/*
* Check context argument results.
*/
for (cntxp = CntxArg; cntxp; cntxp = cntxp->next) {
if (!cntxp->f) {
rv = 1;
if (Fverbose) {
(void) printf("%s: context not located: ", Pn);
safestrprt(cntxp->cntx, stdout, 1);
}
}
}
}
#endif /* defined(HASSELINUX) */
for (i = 0; i < Npgid; i++) {
/*
* Check inclusionary process group ID specifications.
*/
if (Spgid[i].f || Spgid[i].x)
continue;
rv = 1;
if (Fverbose)
(void) printf("%s: process group ID not located: %d\n",
Pn, Spgid[i].i);
}
for (i = 0; i < Nuid; i++) {
/*
* Check inclusionary user ID specifications.
*/
if (Suid[i].excl || Suid[i].f)
continue;
rv = 1;
if (Fverbose) {
if (Suid[i].lnm) {
(void) printf("%s: login name (UID %lu) not located: ",
Pn, (unsigned long)Suid[i].uid);
safestrprt(Suid[i].lnm, stdout, 1);
} else
(void) printf("%s: user ID not located: %lu\n", Pn,
(unsigned long)Suid[i].uid);
}
}
if (!rv && rc)
rv = ev;
if (!rv && ErrStat)
rv = 1;
Exit(rv);
return(rv); /* to make code analyzers happy */
}
/*
* GetOpt() -- Local get option
*
* Liberally adapted from the public domain AT&T getopt() source,
* distributed at the 1985 UNIFORM conference in Dallas
*
* The modifications allow `?' to be an option character and allow
* the caller to decide that an option that may be followed by a
* value doesn't have one -- e.g., has a default instead.
*/
static int
GetOpt(ct, opt, rules, err)
int ct; /* option count */
char *opt[]; /* options */
char *rules; /* option rules */
int *err; /* error return */
{
register int c;
register char *cp = (char *)NULL;
if (GOx2 == 0) {
/*
* Move to a new entry of the option array.
*
* EOF if:
*
* Option list has been exhausted;
* Next option doesn't start with `-' or `+';
* Next option has nothing but `-' or `+';
* Next option is ``--'' or ``++''.
*/
if (GOx1 >= ct
|| (opt[GOx1][0] != '-' && opt[GOx1][0] != '+')
|| !opt[GOx1][1])
return(EOF);
if (strcmp(opt[GOx1], "--") == 0 || strcmp(opt[GOx1], "++") == 0) {
GOx1++;
return(EOF);
}
GOp = opt[GOx1][0];
GOx2 = 1;
}
/*
* Flag `:' option character as an error.
*
* Check for a rule on this option character.
*/
*err = 0;
if ((c = opt[GOx1][GOx2]) == ':') {
(void) fprintf(stderr,
"%s: colon is an illegal option character.\n", Pn);
*err = 1;
} else if (!(cp = strchr(rules, c))) {
(void) fprintf(stderr, "%s: illegal option character: %c\n", Pn, c);
*err = 2;
}
if (*err) {
/*
* An error was detected.
*
* Advance to the next option character.
*
* Return the character causing the error.
*/
if (opt[GOx1][++GOx2] == '\0') {
GOx1++;
GOx2 = 0;
}
return(c);
}
if (*(cp + 1) == ':') {
/*
* The option may have a following value. The caller decides
* if it does.
*
* Save the position of the possible value in case the caller
* decides it does not belong to the option and wants it
* reconsidered as an option character. The caller does that
* with:
* GOx1 = GObk[0]; GOx2 = GObk[1];
*
* Don't indicate that an option of ``--'' is a possible value.
*
* Finally, on the assumption that the caller will decide that
* the possible value belongs to the option, position to the
* option following the possible value, so that the next call
* to GetOpt() will find it.
*/
if(opt[GOx1][GOx2 + 1] != '\0') {
GObk[0] = GOx1;
GObk[1] = ++GOx2;
GOv = &opt[GOx1++][GOx2];
} else if (++GOx1 >= ct)
GOv = (char *)NULL;
else {
GObk[0] = GOx1;
GObk[1] = 0;
GOv = opt[GOx1];
if (strcmp(GOv, "--") == 0)
GOv = (char *)NULL;
else
GOx1++;
}
GOx2 = 0;
} else {
/*
* The option character stands alone with no following value.
*
* Advance to the next option character.
*/
if (opt[GOx1][++GOx2] == '\0') {
GOx2 = 0;
GOx1++;
}
GOv = (char *)NULL;
}
/*
* Return the option character.
*/
return(c);
}
/*
* sv_fmt_str() - save format string
*/
static char *
sv_fmt_str(f)
char *f; /* format string */
{
char *cp;
MALLOC_S l;
l = (MALLOC_S)(strlen(f) + 1);
if (!(cp = (char *)malloc(l))) {
(void) fprintf(stderr,
"%s: can't allocate %d bytes for format: %s\n", Pn, (int)l, f);
Exit(1);
}
(void) snpf(cp, l, "%s", f);
return(cp);
}
|