From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47163) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XQVRT-0007PA-3k for qemu-devel@nongnu.org; Sun, 07 Sep 2014 01:55:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XQVRM-0001l3-VH for qemu-devel@nongnu.org; Sun, 07 Sep 2014 01:55:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58494) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XQVRM-0001jh-Os for qemu-devel@nongnu.org; Sun, 07 Sep 2014 01:55:08 -0400 Date: Sun, 7 Sep 2014 08:58:01 +0300 From: "Michael S. Tsirkin" Message-ID: <20140907055801.GA23907@redhat.com> References: <1409835061-19989-1-git-send-email-david.marchand@6wind.com> <1409835061-19989-2-git-send-email-david.marchand@6wind.com> <20140904155657.GD21203@redhat.com> <5409A79A.8050302@6wind.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5409A79A.8050302@6wind.com> Subject: Re: [Qemu-devel] [PATCH v5 1/3] contrib: add ivshmem client and server List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: David Marchand Cc: Olivier Matz , kvm , Stefan Hajnoczi , Claudio Fontana , Markus Armbruster , "qemu-devel@nongnu.org Developers" , "Gonglei (Arei)" , Martin Kletzander , Paolo Bonzini , Jani Kokkonen , Cam Macdonell On Fri, Sep 05, 2014 at 02:07:54PM +0200, David Marchand wrote: > Hello Michael, > > On 09/04/2014 05:56 PM, Michael S. Tsirkin wrote: > >>+ /* create the unix listening socket */ > >>+ sock_fd = socket(AF_UNIX, SOCK_STREAM, 0); > >>+ if (sock_fd < 0) { > >>+ debug_log(server, "cannot create socket: %s\n", strerror(errno)); > >>+ goto err_close_shm; > >>+ } > >>+ > >>+ sun.sun_family = AF_UNIX; > >>+ snprintf(sun.sun_path, sizeof(sun.sun_path), "%s", server->unix_sock_path); > >>+ unlink(sun.sun_path); > > > >why unlink it? > > Yes, this is wrong, because this means that when starting multiple > servers on the same socket, the last server is the one who wins ... > while I think it should be the opposite (first server wins, as it may > have some connected clients). > > I have been scratching my head about this: when should I unlink ? > > My current fix unlinks from ivshmem_server_close() (which should be the > right place). > I need to call this when exiting, but I can only do this when the server > exits gracefully (when an error occurs on the server socket or when > receiving a SIGTERM). > > If something unexpected happens (like a bug/crash or a SIGKILL), the > socket won't be unlinked and the next server process will refuse to start. > Is this something acceptable ? > > Do you have a better idea ? > > > Thanks. Is the point to prevent multiple servers from opening the same socket? Either leave it up to the user, or try to use some lock - unlink will never be a safe way to do this. I advise for the former. > -- > David Marchand