Changeset 1917
- Timestamp:
- Apr 26, 2005, 2:48:42 AM (21 years ago)
- Location:
- trunk/src/emx/src/lib/misc
- Files:
-
- 2 edited
-
sysctl.c (modified) (38 diffs, 1 prop)
-
sysctl_mib.c (modified) (11 diffs, 1 prop)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/emx/src/lib/misc/sysctl.c
-
Property cvs2svn:cvs-rev
changed from
1.1to1.2
r1916 r1917 36 36 */ 37 37 38 38 39 #include <sys/cdefs.h> 39 __FBSDID("$FreeBSD: src/sys/kern/kern_sysctl.c,v 1.159 2004/07/28 06:42:41 kan Exp $"); 40 41 #include "opt_compat.h" 42 #include "opt_mac.h" 40 //__FBSDID("$FreeBSD: src/sys/kern/kern_sysctl.c,v 1.159 2004/07/28 06:42:41 kan Exp $"); 43 41 44 42 #include <sys/param.h> 45 #include <sys/systm.h> 46 #include <sys/kernel.h> 43 #define _KERNEL 47 44 #include <sys/sysctl.h> 48 #include <sys/mac.h> 49 #include <sys/malloc.h> 50 #include <sys/proc.h> 51 #include <sys/lock.h> 52 #include <sys/mutex.h> 53 #include <sys/sx.h> 54 #include <sys/sysproto.h> 55 #include <vm/vm.h> 56 #include <vm/vm_extern.h> 57 58 static MALLOC_DEFINE(M_SYSCTL, "sysctl", "sysctl internal magic"); 59 static MALLOC_DEFINE(M_SYSCTLOID, "sysctloid", "sysctl dynamic oids"); 60 static MALLOC_DEFINE(M_SYSCTLTMP, "sysctltmp", "sysctl temp output buffer"); 45 #include <386/builtin.h> 46 #include <sys/fmutex.h> 47 #include <sys/smutex.h> 48 #include <errno.h> 49 #include <string.h> 50 #include <stdio.h> 51 52 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_MISC 53 #include <InnoTekLIBC/logstrict.h> 54 #undef printf 55 #define printf LIBCLOG_MSG2 56 #undef panic 57 #define panic LIBC_ASSERTM_FAILED 58 #undef copyout 59 #define copyout(x,y,z) !memcpy((y),(x),(z)) 60 #undef copyin 61 #define copyin(x,y,z) !memcpy((y),(x),(z)) 62 #undef securelevel_gt 63 #define securelevel_gt(cr, level) 0 61 64 62 65 /* 63 66 * Locking - this locks the sysctl tree in memory. 64 67 */ 65 static struct sx sysctllock;66 67 #define SYSCTL_LOCK() sx_xlock(&sysctllock)68 #define SYSCTL_UNLOCK() sx_xunlock(&sysctllock)69 #define SYSCTL_INIT() sx_init(&sysctllock, "sysctl lock")68 static x sysctllock; 69 70 #define SYSCTL_LOCK() ) 71 #define SYSCTL_UNLOCK() (&sysctllock) 72 #define SYSCTL_INIT() , "sysctl lock") 70 73 71 74 static int sysctl_root(SYSCTL_HANDLER_ARGS); … … 92 95 */ 93 96 94 void97 void 95 98 sysctl_register_oid(struct sysctl_oid *oidp) 96 99 { … … 149 152 } 150 153 154 151 155 void 152 156 sysctl_unregister_oid(struct sysctl_oid *oidp) … … 169 173 } 170 174 171 /* 175 /* 172 176 * This can happen when a module fails to register and is 173 177 * being unloaded afterwards. It should not be a panic() … … 177 181 printf("%s: failed to unregister sysctl\n", __func__); 178 182 } 183 184 185 186 179 187 180 188 /* Initialize a new context to keep track of dynamically added sysctls. */ … … 288 296 } 289 297 298 299 300 290 301 /* 291 302 * Remove dynamically created sysctl trees. … … 431 442 return (0); 432 443 } 444 445 433 446 434 447 /* 435 448 * Register the kernel's oids on startup. 436 449 */ 437 SET_DECLARE(sysctl_set, struct sysctl_oid);438 439 450 static void 440 451 sysctl_register_all(void *arg) … … 443 454 444 455 SYSCTL_INIT(); 445 SET_FOREACH(oidp, sysctl_set) 446 sysctl_register_oid(*oidp); 447 } 448 SYSINIT(sysctl, SI_SUB_KMEM, SI_ORDER_ANY, sysctl_register_all, 0); 449 456 extern int __sysctl_set__; 457 int *ptr = &__sysctl_set__; 458 if (*ptr == -2) 459 for (oidp = (struct sysctl_oid **)(ptr + 1); *oidp != NULL; oidp++) 460 sysctl_register_oid(*oidp); 461 else 462 { 463 if (*ptr == -1) --ptr; /* Fix GNU ld bug */ 464 int n = *ptr++; /* Get size of vector */ 465 if (*ptr == -1) /* First element must be -1, see crt0.s */ 466 for (oidp = (struct sysctl_oid **)(ptr + 1); n > 1; oidp++, n--) 467 sysctl_register_oid(*oidp); 468 } 469 470 } 471 //SYSINIT(sysctl, SI_SUB_KMEM, SI_ORDER_ANY, sysctl_register_all, 0); 472 473 #if 0 /* no debug stuff just yet */ 450 474 /* 451 475 * "Staff-functions" 452 476 * 453 * These functions implement a presently undocumented interface 477 * These functions implement a presently undocumented interface 454 478 * used by the sysctl program to walk the tree, and get the type 455 479 * so it can print the value. … … 519 543 SYSCTL_PROC(_sysctl, 0, debug, CTLTYPE_STRING|CTLFLAG_RD, 520 544 0, 0, sysctl_sysctl_debug, "-", ""); 545 521 546 522 547 static int … … 559 584 name++; 560 585 561 if ((oid->oid_kind & CTLTYPE) != CTLTYPE_NODE) 586 if ((oid->oid_kind & CTLTYPE) != CTLTYPE_NODE) 562 587 break; 563 588 … … 576 601 577 602 static int 578 sysctl_sysctl_next_ls(struct sysctl_oid_list *lsp, int *name, u_int namelen, 603 sysctl_sysctl_next_ls(struct sysctl_oid_list *lsp, int *name, u_int namelen, 579 604 int *next, int *len, int level, struct sysctl_oid **oidpp) 580 605 { … … 590 615 591 616 if (!namelen) { 592 if ((oidp->oid_kind & CTLTYPE) != CTLTYPE_NODE) 617 if ((oidp->oid_kind & CTLTYPE) != CTLTYPE_NODE) 593 618 return 0; 594 if (oidp->oid_handler) 619 if (oidp->oid_handler) 595 620 /* We really should call the handler here...*/ 596 621 return 0; 597 622 lsp = (struct sysctl_oid_list *)oidp->oid_arg1; 598 if (!sysctl_sysctl_next_ls(lsp, 0, 0, next+1, 623 if (!sysctl_sysctl_next_ls(lsp, 0, 0, next+1, 599 624 len, level+1, oidpp)) 600 625 return 0; … … 611 636 return 0; 612 637 lsp = (struct sysctl_oid_list *)oidp->oid_arg1; 613 if (!sysctl_sysctl_next_ls(lsp, name+1, namelen-1, 638 if (!sysctl_sysctl_next_ls(lsp, name+1, namelen-1, 614 639 next+1, len, level+1, oidpp)) 615 640 return (0); … … 623 648 624 649 lsp = (struct sysctl_oid_list *)oidp->oid_arg1; 625 if (!sysctl_sysctl_next_ls(lsp, name+1, namelen-1, next+1, 650 if (!sysctl_sysctl_next_ls(lsp, name+1, namelen-1, next+1, 626 651 len, level+1, oidpp)) 627 652 return (0); … … 670 695 *len = 0; 671 696 672 for (p = name; *p && *p != '.'; p++) 697 for (p = name; *p && *p != '.'; p++) 673 698 ; 674 699 i = *p; … … 701 726 oidp = SLIST_FIRST(lsp); 702 727 name = p+1; 703 for (p = name; *p && *p != '.'; p++) 728 for (p = name; *p && *p != '.'; p++) 704 729 ; 705 730 i = *p; … … 717 742 struct sysctl_oid *op = 0; 718 743 719 if (!req->newlen) 744 if (!req->newlen) 720 745 return ENOENT; 721 746 if (req->newlen >= MAXPATHLEN) /* XXX arbitrary, undocumented */ 722 747 return (ENAMETOOLONG); 723 748 724 p = malloc(req->newlen+1 , M_SYSCTL, M_WAITOK);749 p = malloc(req->newlen+1); 725 750 726 751 error = SYSCTL_IN(req, p, req->newlen); 727 752 if (error) { 728 free(p , M_SYSCTL);753 free(p); 729 754 return (error); 730 755 } … … 734 759 error = name2oid(p, oid, &len, &op); 735 760 736 free(p , M_SYSCTL);761 free(p); 737 762 738 763 if (error) … … 743 768 } 744 769 745 SYSCTL_PROC(_sysctl, 3, name2oid, CTLFLAG_RW|CTLFLAG_ANYBODY, 0, 0, 770 SYSCTL_PROC(_sysctl, 3, name2oid, CTLFLAG_RW|CTLFLAG_ANYBODY, 0, 0, 746 771 sysctl_sysctl_name2oid, "I", ""); 772 773 774 775 747 776 748 777 static int … … 866 895 retry: 867 896 outlen = strlen((char *)arg1)+1; 868 tmparg = malloc(outlen , M_SYSCTLTMP, M_WAITOK);897 tmparg = malloc(outlen); 869 898 870 899 if (strlcpy(tmparg, (char *)arg1, outlen) >= outlen) { 871 free(tmparg , M_SYSCTLTMP);900 free(tmparg); 872 901 goto retry; 873 902 } 874 903 875 904 error = SYSCTL_OUT(req, tmparg, outlen); 876 free(tmparg , M_SYSCTLTMP);905 free(tmparg); 877 906 878 907 if (error || !req->newptr) … … 898 927 sysctl_handle_opaque(SYSCTL_HANDLER_ARGS) 899 928 { 900 int error , tries;901 u_int generation;929 int error; 930 u_int generation; 902 931 struct sysctl_req req2; 903 932 … … 909 938 * If we encounter an error, stop immediately. 910 939 */ 911 tries = 0;940 tries = 0; 912 941 req2 = *req; 913 retry:914 generation = curthread->td_generation;942 retry: 943 generation = curthread->td_generation; 915 944 error = SYSCTL_OUT(req, arg1, arg2); 916 945 if (error) 917 946 return (error); 918 tries++;919 if (generation != curthread->td_generation && tries < 3) {920 *req = req2;921 goto retry;922 }947 tries++; 948 if (generation != curthread->td_generation && tries < 3) { 949 *req = req2; 950 goto retry; 951 } 923 952 924 953 error = SYSCTL_IN(req, arg1, arg2); … … 927 956 } 928 957 958 929 959 /* 930 960 * Transfer functions to/from kernel space. … … 997 1027 error = sysctl_root(0, name, namelen, &req); 998 1028 999 if (req.lock == REQ_WIRED && req.validlen > 0)1000 vsunlock(req.oldptr, req.validlen);1029 if (req.lock == REQ_WIRED && req.validlen > 0) 1030 vsunlock(req.oldptr, req.validlen); 1001 1031 1002 1032 SYSCTL_UNLOCK(); … … 1035 1065 return (error); 1036 1066 } 1067 1037 1068 1038 1069 /* … … 1049 1080 if (req->oldptr == NULL) 1050 1081 return (0); 1051 if (req->lock == REQ_LOCKED)1052 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,1053 "sysctl_old_user()");1082 if (req->lock == REQ_LOCKED) 1083 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, 1084 "sysctl_old_user()"); 1054 1085 i = l; 1055 1086 len = req->validlen; … … 1082 1113 } 1083 1114 1115 1084 1116 /* 1085 1117 * Wire the user space destination buffer. If set to a value greater than … … 1113 1145 return (0); 1114 1146 } 1115 1116 int 1147 #endif /* don't need you.. */ 1148 1149 static int 1117 1150 sysctl_find_oid(int *name, u_int namelen, struct sysctl_oid **noid, 1118 1151 int *nindx, struct sysctl_req *req) … … 1182 1215 return (EPERM); 1183 1216 1184 KASSERT(req->td != NULL, ("sysctl_root(): req->td == NULL"));1217 KASSERT(req->td != NULL, ("sysctl_root(): req->td == NULL")); 1185 1218 1186 1219 /* Is this sysctl sensitive to securelevels? */ … … 1194 1227 /* Is this sysctl writable by only privileged users? */ 1195 1228 if (req->newptr && !(oid->oid_kind & CTLFLAG_ANYBODY)) { 1229 1196 1230 int flags; 1197 1231 … … 1203 1237 if (error) 1204 1238 return (error); 1239 1205 1240 } 1206 1241 … … 1225 1260 return (error); 1226 1261 } 1262 1263 1264 1265 1227 1266 1228 1267 #ifndef _SYS_SYSPROTO_H_ … … 1237 1276 #endif 1238 1277 1278 1239 1279 /* 1240 1280 * MPSAFE 1241 1281 */ 1242 int1282 int 1243 1283 __sysctl(struct thread *td, struct sysctl_args *uap) 1244 1284 { … … 1269 1309 return (error); 1270 1310 } 1311 1271 1312 1272 1313 /* … … 1274 1315 * must be in kernel space. 1275 1316 */ 1276 int1317 int 1277 1318 userland_sysctl(struct thread *td, int *name, u_int namelen, void *old, 1278 1319 size_t *oldlenp, int inkernel, void *new, size_t newlen, size_t *retval) … … 1297 1338 1298 1339 if (old) { 1299 if (!useracc(old, req.oldlen, VM_PROT_WRITE))1300 return (EFAULT);1340 if (!useracc(old, req.oldlen, VM_PROT_WRITE)) 1341 return (EFAULT); 1301 1342 req.oldptr= old; 1302 1343 } 1303 1344 1304 1345 if (new != NULL) { 1305 if (!useracc(new, req.newlen, VM_PROT_READ))1306 return (EFAULT);1346 if (!useracc(new, req.newlen, VM_PROT_READ)) 1347 return (EFAULT); 1307 1348 req.newlen = newlen; 1308 1349 req.newptr = new; … … 1321 1362 } while (error == EAGAIN); 1322 1363 1323 if (req.lock == REQ_WIRED && req.validlen > 0)1324 vsunlock(req.oldptr, req.validlen);1364 if (req.lock == REQ_WIRED && req.validlen > 0) 1365 vsunlock(req.oldptr, req.validlen); 1325 1366 1326 1367 SYSCTL_UNLOCK(); … … 1554 1595 } 1555 1596 #endif /* COMPAT_43 */ 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 -
Property cvs2svn:cvs-rev
changed from
