From: "Luis R. Rodriguez" Subject: Re: [PATCH v4 05/15] oxenstored: add support for systemd active sockets Date: Wed, 30 Apr 2014 19:30:26 +0200 Message-ID: <20140430173026.GF11838@wotan.suse.de> References: <1398820328-15132-1-git-send-email-mcgrof@do-not-panic.com> <1398820328-15132-6-git-send-email-mcgrof@do-not-panic.com> <4CFC3D64-E02D-47D2-B1EF-1F97B435CE26@citrix.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============7924375163442684147==" Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WfYL0-0001FQ-1P for xen-devel@lists.xenproject.org; Wed, 30 Apr 2014 17:30:30 +0000 In-Reply-To: <4CFC3D64-E02D-47D2-B1EF-1F97B435CE26@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Dave Scott Cc: Ian Campbell , "Luis R. Rodriguez" , Vincent Hanquez , Stefano Stabellini , Ian Jackson , "xen-devel@lists.xenproject.org" List-Id: xen-devel@lists.xenproject.org --===============7924375163442684147== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="eJnRUKwClWJh1Khz" Content-Disposition: inline --eJnRUKwClWJh1Khz Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Apr 30, 2014 at 08:35:50AM +0000, Dave Scott wrote: > On 30 Apr 2014, at 02:11, Luis R. Rodriguez wro= te: > > An important different with socket activation is that systemd will set > > FD_CLOEXEC for us on the socket before giving it to us, Ocaml gets > > support for [1] Unix.set_cloexec but only as of 4.00.1+dev which isn't > > yet widely available on distributions. >=20 > I=E2=80=99m not familiar with systemd but I=E2=80=99m curious: if systems= is setting the flag > on the socket before giving it to us, why would we still need the > Unix.set_cloexec function in OCaml? systemd is setting the flag for us, my point was that Unix.set_cloexec is n= ot being set yet for non-systemd cases. This can go in as a separate patch, I for so= me reason couldn't find this on documentation so I just checked out ocaml code= to find the right call, would this be OK as a separate patch: diff --git a/tools/ocaml/xenstored/utils.ml b/tools/ocaml/xenstored/utils.ml index d3d2e31..b206898 100644 --- a/tools/ocaml/xenstored/utils.ml +++ b/tools/ocaml/xenstored/utils.ml @@ -78,13 +78,13 @@ let create_regular_unix_socket name =3D Unixext.mkdir_rec (Filename.dirname name) 0o700; let sockaddr =3D Unix.ADDR_UNIX(name) in let sock =3D Unix.socket Unix.PF_UNIX Unix.SOCK_STREAM 0 in + Unix.set_close_on_exec sock; Unix.bind sock sockaddr; Unix.listen sock 1; sock =20 > ... > > diff --git a/tools/ocaml/xenstored/systemd.ml b/tools/ocaml/xenstored/s= ystemd.ml > > new file mode 100644 > > index 0000000..cace794 > > --- /dev/null > > +++ b/tools/ocaml/xenstored/systemd.ml > > @@ -0,0 +1,16 @@ > > +(* > > + * Copyright (C) 2014 Luis R. Rodriguez > > + * > > + * This program is free software; you can redistribute it and/or modify > > + * it under the terms of the GNU Lesser General Public License as publ= ished > > + * by the Free Software Foundation; version 2.1 only. with the special > > + * exception on linking described in file LICENSE. > > + * > > + * This program is distributed in the hope that it will be useful, > > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > > + * GNU Lesser General Public License for more details. > > + *) > > + > > +external sd_listen_fds: string -> Unix.file_descr =3D "ocaml_sd_listen= _fds" > > +external sd_active_socket_required: unit -> int =3D =E2=80=9Cocaml_sd_= active_socket_required" >=20 > Minor comment: It would be clearer if sd_active_socket_required was unit = -> > bool. In the C code you should use Val_true and Val_false from > . Thanks! Like this? If so then I rolled this in, and can send as part of my = v5. diff --git a/tools/ocaml/xenstored/systemd.ml b/tools/ocaml/xenstored/syste= md.ml index cace794..baa1c00 100644 --- a/tools/ocaml/xenstored/systemd.ml +++ b/tools/ocaml/xenstored/systemd.ml @@ -13,4 +13,4 @@ *) =20 external sd_listen_fds: string -> Unix.file_descr =3D "ocaml_sd_listen_fds" -external sd_active_socket_required: unit -> int =3D "ocaml_sd_active_socke= t_required" +external sd_active_socket_required: unit -> bool =3D "ocaml_sd_active_sock= et_required" diff --git a/tools/ocaml/xenstored/systemd.mli b/tools/ocaml/xenstored/syst= emd.mli index a65ea5e..6f2db9c 100644 --- a/tools/ocaml/xenstored/systemd.mli +++ b/tools/ocaml/xenstored/systemd.mli @@ -18,4 +18,4 @@ val sd_listen_fds: string -> Unix.file_descr =20 (** Tells us whether or not systemd support was compiled in *) -val sd_active_socket_required: unit -> int +val sd_active_socket_required: unit -> bool diff --git a/tools/ocaml/xenstored/systemd_stubs.c b/tools/ocaml/xenstored/= systemd_stubs.c index ded9542..942ae19 100644 --- a/tools/ocaml/xenstored/systemd_stubs.c +++ b/tools/ocaml/xenstored/systemd_stubs.c @@ -13,6 +13,7 @@ */ =20 #include +#include #include #include #include @@ -139,7 +140,7 @@ CAMLprim value ocaml_sd_active_socket_required(void) CAMLparam0(); CAMLlocal1(ret); =20 - ret =3D Val_int(1); + ret =3D Val_true; =20 CAMLreturn(ret); } @@ -159,7 +160,7 @@ CAMLprim value ocaml_sd_active_socket_required(void) CAMLparam0(); CAMLlocal1(ret); =20 - ret =3D Val_int(0); + ret =3D Val_false; =20 CAMLreturn(ret); } diff --git a/tools/ocaml/xenstored/utils.ml b/tools/ocaml/xenstored/utils.ml index d3d2e31..50f05c1 100644 --- a/tools/ocaml/xenstored/utils.ml +++ b/tools/ocaml/xenstored/utils.ml @@ -83,8 +83,7 @@ let create_regular_unix_socket name =3D sock =20 let create_unix_socket name =3D - let active_sockets =3D Systemd.sd_active_socket_required() in - if active_sockets =3D 1 then + if Systemd.sd_active_socket_required() then Systemd.sd_listen_fds name else create_regular_unix_socket name >=20 > Everything else looks good to me! Thanks, can I sprinkle an Acked-by: Dave Scott ? Luis --eJnRUKwClWJh1Khz Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) iQIcBAEBAgAGBQJTYTMyAAoJEPep4JnvMe6zK34P/i7hTgBq/xuq+2ASK1EUMMMG MRhcfJoz+VgIKKUX3jX/9kXRRuDbKJNbKISJdjOPraSsF5uLUtH3kjk7RmE8gq+O S0ETyINYJ0Okndy1OU0oCFSI7ji4DeMHIbOjhj+6KynXZEtVpbEeo4DtfECMxmW7 LDO4Fab8CsbLkX1gBsC8MLD+EeL0jetkAoSDSPho0c9nPnqVl4TmUgcK8HU1EUG5 iMvk18hmJC2oVqE+oKsDw4tDAqN0sXUl4RJLycqd2WHFXxaCNRH1KcpLQMLDnsU8 xWidtlcxE35Bpio7aaPUs5U/dIr3WM5MdRbG+8EHDTyQ76UHnFfCB/LCDgvsS+Ub AbWmFiqRYqTQW+GCUFiKPAYZMsImJiYCppyvdzJQvT7WlvxjAmSb9M9TL5ZkVfD9 1IXNWW9GCJCSGDu4iniz2zpmQ4dl5VMoZ6as+xJZwGQq1S2nJ8X7f0W9JYim1YQr 9qPD8YSin580eiJLmwjqw2zo8Js464dt904UUY583E777cbqAYBo9tG40UKx7fCv FJLsrfWttuIEdZVwMN595rMFlF0Vky3IB7XeLSd9+q5r/8QyW/VSz/OaG+y9OLvi tpwA1hfwU0MIadqSWcYBUj4YkjBN+Bm6TzlXFoj6r5HwEcoWxR5KAdIrhds2IFYR KMAaIjAJdnJvsfmc0pvb =h/PB -----END PGP SIGNATURE----- --eJnRUKwClWJh1Khz-- --===============7924375163442684147== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --===============7924375163442684147==--