diff options
author | pjd <pjd@FreeBSD.org> | 2005-08-15 12:15:21 +0000 |
---|---|---|
committer | pjd <pjd@FreeBSD.org> | 2005-08-15 12:15:21 +0000 |
commit | d5f324cb09368c2d209854d95fa99d3670ec760b (patch) | |
tree | 7b6531c0ee73162dfb13a97d0ac30c8069d4cfc7 /usr.sbin/jls/jls.c | |
parent | 50f5e50a7bf1405b73d63b5d0aa18d701726e857 (diff) | |
download | FreeBSD-src-d5f324cb09368c2d209854d95fa99d3670ec760b.zip FreeBSD-src-d5f324cb09368c2d209854d95fa99d3670ec760b.tar.gz |
Not sure why, but SYSCTL_OUT() can sometimes keep returning ENOMEM
in sysctl_jail_list(). Because of this, jls(8) could enter into
an endless loop. The strange thing is, that we can call jls(8) while
the other one is in loop and it will succeed - SYSCTL_OUT() will
not return ENOMEM there.
Maybe SYSCTL_OUT() returns first ENOMEM, because there is no memory,
but is marking some memory range as wired even on failure and another
SYSCTL_OUT() calls are not going to succeed, because process exceeds
limit of wired memory? ENOVMCLUE.
Anyway. Fix jls(8) to ignore ENOMEM and retry only 4 times.
Submitted by: Niklas Saers
PR: kern/79245
MFC after: 3 days
Diffstat (limited to 'usr.sbin/jls/jls.c')
-rw-r--r-- | usr.sbin/jls/jls.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/usr.sbin/jls/jls.c b/usr.sbin/jls/jls.c index 0ad36d1..e8446bb 100644 --- a/usr.sbin/jls/jls.c +++ b/usr.sbin/jls/jls.c @@ -47,20 +47,26 @@ main(void) if (sysctlbyname("security.jail.list", NULL, &len, NULL, 0) == -1) err(1, "sysctlbyname(): security.jail.list"); -retry: - if (len <= 0) - exit(0); - sxp = xp = calloc(len, 1); - if (sxp == NULL) - err(1, "malloc()"); - if (sysctlbyname("security.jail.list", xp, &len, NULL, 0) == -1) { - if (errno == ENOMEM) { - free(sxp); - goto retry; + for (i = 0; i < 4; i++) { + if (len <= 0) + exit(0); + sxp = xp = calloc(len, 1); + if (sxp == NULL) + err(1, "malloc()"); + + if (sysctlbyname("security.jail.list", xp, &len, NULL, 0) == -1) { + if (errno == ENOMEM) { + free(sxp); + sxp = NULL; + continue; + } + err(1, "sysctlbyname(): security.jail.list"); } - err(1, "sysctlbyname(): security.jail.list"); + break; } + if (sxp == NULL) + err(1, "sysctlbyname(): security.jail.list"); if (len < sizeof(*xp) || len % sizeof(*xp) || xp->pr_version != XPRISON_VERSION) errx(1, "Kernel and userland out of sync"); |