Index: usr.bin/sockstat/sockstat.c =================================================================== --- usr.bin/sockstat/sockstat.c +++ usr.bin/sockstat/sockstat.c @@ -1367,10 +1367,19 @@ usage(); if (opt_j > 0) { + char buf[MAXPATHLEN]; + switch (jail_getvnet(opt_j)) { case -1: - errx(2, "%s", jail_errmsg); + errx(2, "Unable to get jail vnet: %s", jail_errmsg); case JAIL_SYS_NEW: + if (snprintf(buf, sizeof(buf), "%d", opt_j) < 0) + err(3, "snprintf()"); + if (jail_getv(0, "jid", buf, "path", buf, NULL) < 0) + errx(3, "Unable to get jail path: %s", + jail_errmsg); + if (chdir(buf) < 0) + err(3, "Unable to chdir to jail path"); if (jail_attach(opt_j) < 0) err(3, "jail_attach()"); /* Set back to -1 for normal output in vnet jail. */