[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [Nbd] [PATCH] nbd-server: fix server socket initialization



Thanks, all three are applied.

On Fri, Dec 28, 2012 at 12:22:41AM +0200, =?UTF-8?q?Tuomas=20Jorma=20Juhani=20R=C3=A4s=C3=A4nen?= wrote:
> Change the value for undefined descriptor from 0 to -1 because any value
> greater or equal to 0 can be a valid file descriptor.
> 
> Signed-off-by: Tuomas Jorma Juhani Räsänen <tuomasjjrasanen@...1261...>
> ---
>  nbd-server.c |   18 +++++++++++++++++-
>  1 file changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/nbd-server.c b/nbd-server.c
> index f5aa6ca..ec617a9 100644
> --- a/nbd-server.c
> +++ b/nbd-server.c
> @@ -2268,7 +2268,7 @@ int serveloop(GArray* servers) {
>  	max=0;
>  	FD_ZERO(&mset);
>  	for(i=0;i<servers->len;i++) {
> -		if((sock=(g_array_index(servers, SERVER, i)).socket)) {
> +		if((sock=(g_array_index(servers, SERVER, i)).socket) >= 0) {
>  			FD_SET(sock, &mset);
>  			max=sock>max?sock:max;
>  		}
> @@ -2358,6 +2358,22 @@ int setup_serve(SERVER *serve) {
>  	gchar *port = NULL;
>  	int e;
>  
> +        /* Without this, it's possible that socket == 0, even if it's
> +         * not initialized at all. And that would be wrong because 0 is
> +         * totally legal value for properly initialized descriptor. This
> +         * line is required to ensure that unused/uninitialized
> +         * descriptors are marked as such (new style configuration
> +         * case). Currently, servers are being initialized in multiple
> +         * places, and some of the them do the socket initialization
> +         * incorrectly. This is the only point common to all code paths,
> +         * and therefore setting -1 is put here. However, the whole
> +         * server initialization procedure should be extracted to its
> +         * own function and all code paths wanting to mess with servers
> +         * should initialize servers with that function.
> +         * 
> +         * TODO: fix server initialization */
> +        serve->socket = -1;
> +
>  	if(!(glob_flags & F_OLDSTYLE)) {
>  		return serve->servename ? 1 : 0;
>  	}
> -- 
> 1.7.10.4
> 
> 
> ------------------------------------------------------------------------------
> Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
> MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
> with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
> MVPs and experts. ON SALE this month only -- learn more at:
> http://p.sf.net/sfu/learnmore_122712
> _______________________________________________
> Nbd-general mailing list
> Nbd-general@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/nbd-general
> 

-- 
Copyshops should do vouchers. So that next time some bureaucracy requires you
to mail a form in triplicate, you can mail it just once, add a voucher, and
save on postage.



Reply to: