From 36987df385cbbcd8b7e72c97af620d76b8f1ae8f Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Wed, 19 May 2004 17:34:15 +0000 Subject: Bug fixes for kvm prepare --- srcx/jails.c | 2 +- srcx/jid.c | 41 ++++++++++++++--------------------------- srcx/jkill.c | 5 +++-- srcx/jps.c | 1 + srcx/util.c | 2 +- 5 files changed, 20 insertions(+), 31 deletions(-) diff --git a/srcx/jails.c b/srcx/jails.c index 5651f8a..b2b3d17 100644 --- a/srcx/jails.c +++ b/srcx/jails.c @@ -62,7 +62,7 @@ int main(int argc, char* argv[]) if(argc > 1) usage(); - if(running_in_jail()) + if(running_in_jail() != 0) errx(1, "can't run from inside jail"); list_jails(); diff --git a/srcx/jid.c b/srcx/jid.c index 5d2e4d0..93d0e94 100644 --- a/srcx/jid.c +++ b/srcx/jid.c @@ -54,7 +54,9 @@ static void usage(); int main(int argc, char* argv[]) { - int jid = 0; + struct xprison* sxp = NULL; + struct xprison* xp = NULL; + size_t len; char* e; /* Remove the program name */ @@ -64,45 +66,30 @@ int main(int argc, char* argv[]) if(argc != 1) usage(); - if(running_in_jail()) + if(running_in_jail() != 0) errx(1, "can't run from inside jail"); - jid = strtol(argv[0], &e, 10); + len = get_jail_sysctl(&xp); + xp = find_jail(argv[0], len, sxp); + + strtol(argv[0], &e, 10); /* If it was all a number ... */ if(!*e) { - struct xprison* xp; - size_t len, i; - - len = get_jail_sysctl(&xp); - if(len > 0) - { - for(i = 0; i < len; i++) - { - if(xp[i].pr_id == jid) - { - printf("%s\n", xp[i].pr_host); - jid = -1; - break; - } - } - - free(xp); - - if(jid != -1) - errx(1, "unknown jail id: %s", argv[0]); - } + if(xp == NULL) + errx(1, "unknown jail id: %s", argv[0]); + + printf("%s\n", xp->pr_host); } /* otherwise it's a host name */ else { - jid = translate_jail_name(argv[0]); - if(jid == -1) + if(xp == NULL) errx(1, "unknown jail host name: %s", argv[0]); - printf("%d\n", (int)jid); + printf("%d\n", xp->pr_host); } return 0; diff --git a/srcx/jkill.c b/srcx/jkill.c index 953095e..4afb703 100644 --- a/srcx/jkill.c +++ b/srcx/jkill.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -121,7 +122,7 @@ int main(int argc, char* argv[]) /* For each jail */ for(; argc > 0; argc--, argv++) { - xp = find_jail(str, len, sxp); + xp = find_jail(argv[0], len, sxp); if(xp == NULL) { @@ -149,7 +150,7 @@ int main(int argc, char* argv[]) /* The child */ case 0: #endif - jid = xp->pri_id; + jid = xp->pr_id; /* Always free jail info before going into jail */ free_jail_sysctl(len, sxp); diff --git a/srcx/jps.c b/srcx/jps.c index 867364d..85f7184 100644 --- a/srcx/jps.c +++ b/srcx/jps.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include diff --git a/srcx/util.c b/srcx/util.c index 137ca24..c406163 100644 --- a/srcx/util.c +++ b/srcx/util.c @@ -153,7 +153,7 @@ int translate_jail_name(const char* str) len = get_jail_sysctl(&sxp); if(sxp) { - xp = find_jail(str, sxp); + xp = find_jail(str, len, sxp); if(xp != NULL) jid = xp->pr_id; -- cgit v1.2.3