From owner-freebsd-jail@freebsd.org Sat May 21 21:49:15 2016 Return-Path: Delivered-To: freebsd-jail@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A335EB4499B for ; Sat, 21 May 2016 21:49:15 +0000 (UTC) (envelope-from jamie@freebsd.org) Received: from gritton.org (gritton.org [162.220.209.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "www.gritton.org", Issuer "StartCom Class 1 Primary Intermediate Server CA" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 5BCB81946 for ; Sat, 21 May 2016 21:49:14 +0000 (UTC) (envelope-from jamie@freebsd.org) Received: from gritton.org (gritton.org [162.220.209.3]) by gritton.org (8.15.2/8.15.2) with ESMTPS id u4LLn7hR037498 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sat, 21 May 2016 15:49:07 -0600 (MDT) (envelope-from jamie@freebsd.org) Received: (from www@localhost) by gritton.org (8.15.2/8.15.2/Submit) id u4LLn6GS037497; Sat, 21 May 2016 15:49:06 -0600 (MDT) (envelope-from jamie@freebsd.org) X-Authentication-Warning: gritton.org: www set sender to jamie@freebsd.org using -f To: freebsd-jail@freebsd.org Subject: Re: cannot freebsd jail by c X-PHP-Originating-Script: 0:rcube.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Sat, 21 May 2016 15:49:06 -0600 From: James Gritton Cc: =?UTF-8?Q?=E6=A2=85=E5=87=B1?= In-Reply-To: References: Message-ID: <9898baf72b32a2feada28638e09a3c2f@gritton.org> X-Sender: jamie@freebsd.org User-Agent: Roundcube Webmail/1.1.2 X-BeenThere: freebsd-jail@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Discussion about FreeBSD jail\(8\)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 May 2016 21:49:15 -0000 On 2016-05-21 08:52, 梅凱 wrote: > This is my part c code: > > > 11 int main() > 12 { > 13 in_addr_t addr_t=inet_addr("192.168.2.1"); > 14 > 15 struct in_addr in_addr=inet_makeaddr(addr_t,AF_INET); > 16 > 17 > 18 struct jail j={ > 19 .version=JAIL_API_VERSION, > 20 .path="./jail_test", > 21 .hostname="myjail", > 22 .ip4s=addr_t, > 23 .ip6s=0, > 24 .ip4=&in_addr, > 25 .ip6=NULL > 26 }; > 27 > 28 errno=0; > 29 int rs=jail(&j); > 30 if(0==rs){ > 31 printf("create jail ok!!!\r\n"); > 32 return 0; > 33 } > 34 > 35 switch(errno){ > 36 case EPERM: > 37 printf("eperm\r\n"); > 38 break; > 39 case EFAULT: > 40 printf("efault\r\n"); > 41 break; > 42 case EINVAL: > 43 printf("einval\r\n"); > 44 break; > 45 case EAGAIN: > 46 printf("eagain\r\n"); > 47 break; > 48 default: > 49 printf("---------------\r\n"); > 50 break; > 51 } > 52 return 0; > 53 } > > Unfortunately,the errno return EINVAL,it means “The version number of > the argument is not correct.”,why? Actually, jail(2) can give EINVAL not only for the reason listed, but also for some of the reasons mentioned under jail_set. Really, it means just some value was wrong. In this case there were two errors. You passed addr_t in .ip4s, but that's supposed to be the number of addresses and not the address itself - pass 1 instead. Also, the path of "./jail_test" won't work; it needs to be a full pathname instead. Fix those two and the jail will create correctly. - Jamie