Date: Tue, 8 Feb 2011 17:30:32 +0100 From: Julian Fagir <gnrp@gnrp.in-berlin.de> To: freebsd-jail@freebsd.org Subject: Getting hostname from jail_getid(3) or ezjail(5) Message-ID: <20110208173032.38e0a073@adolfputzen>
next in thread | raw e-mail | index | archive | help
--Sig_/kBFS2/z_8wPD5P98fiXMbU4 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Hi, I wanted to write a tool starting a shell in a jail. I know, jexec accomplishes this too, but I want to compile the name of the jail into the program, no commandline-parameters (more about this topic will be posted on this list soon). Thus, I used libjail, more specific jail_getid(3) to get the id of the jail and start a shell in it. The name of the jail is 'jail2', it was created by ezjail(5), and the important lines in /usr/local/etc/ezjail/jail2 are: export jail_jail2_hostname=3D"zweihorn2" export jail_jail2_ip=3D"IPADDRESS" export jail_jail22_rootdir=3D"/usr/jails/jail2" Anyway, when starting the jail, `jls` bravely shows as the hostname of the jail 'jail2'. But when I compile this program (with `cc -ljail jexec_sh.c -o jexec_sh`) #include <sys/types.h> #include <sys/param.h> #include <sys/jail.h> #include <string.h> #include <unistd.h> #include <stdio.h> #include <jail.h> #define JAIL_NAME "jail2" int main(int argc, char* argv[]) { char *jname; int jid; jid =3D jail_getid(JAIL_NAME); printf("Jail 2 is running: %d\n", jid); jname =3D jail_getname(jid); printf("Jailname: '%s' to jid %d\n", jname, jid); return(0); } jail_getid returns -1; meaning the jailname does not exist. When setting JAIL_NAME to "1" (or "2", etc., according to the jid, if I restarted it), t= he jid is correctly returned: zweihorn1# /home/julian/jexec_sh Jail 1 is running: 1 Jailname: '1' to jid 1 Am i missing something? jail_getid/jail_getname should return exactly the output I expected?! ezjail must be setting the name right as jls returns the correct name. jls does nearly the same, though requesting directly the para= ms without libjail, but libjail does that internally, too. Regards, Julian --Sig_/kBFS2/z_8wPD5P98fiXMbU4 Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAk1Rb6gACgkQc7h7cu1Hpp61dgCfTHtiwH9M33CHSzGVh39tBvE5 sPoAnjz06lAWBpN7+Hm/yWbMCfpiqtcs =j+2d -----END PGP SIGNATURE----- --Sig_/kBFS2/z_8wPD5P98fiXMbU4--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20110208173032.38e0a073>