ia64/xen-unstable

changeset 1347:de3970272f43

bitkeeper revision 1.891.1.1 (409a12c9_7u5WpEokOglsC5WPWr5gQ)

Fix compile warnings.
author kaf24@scramble.cl.cam.ac.uk
date Thu May 06 10:26:17 2004 +0000 (2004-05-06)
parents 2b2dc843edfb
children d7147f016bfd 430798be9fca
files tools/xc/py/Xc.c
line diff
     1.1 --- a/tools/xc/py/Xc.c	Tue May 04 21:57:10 2004 +0000
     1.2 +++ b/tools/xc/py/Xc.c	Thu May 06 10:26:17 2004 +0000
     1.3 @@ -13,6 +13,7 @@
     1.4  #include <sys/types.h>
     1.5  #include <sys/socket.h>
     1.6  #include <netdb.h>
     1.7 +#include <arpa/inet.h>
     1.8  
     1.9  /* Needed for Python versions earlier than 2.3. */
    1.10  #ifndef PyMODINIT_FUNC
    1.11 @@ -199,15 +200,16 @@ static PyObject *pyxc_linux_save(PyObjec
    1.12                                        &dom, &state_file, &progress) )
    1.13          return NULL;
    1.14  
    1.15 -    if (progress) flags |= XCFLAGS_VERBOSE;
    1.16 +    if ( progress )
    1.17 +        flags |= XCFLAGS_VERBOSE;
    1.18  
    1.19 -    if (strncmp(state_file,"tcp:", strlen("tcp:")) == 0)
    1.20 +    if ( strncmp(state_file,"tcp:", strlen("tcp:")) == 0 )
    1.21      {
    1.22  #define max_namelen 64
    1.23  	char server[max_namelen];
    1.24  	char *port_s;
    1.25  	int port=777;
    1.26 -	int sd = 0;
    1.27 +	int sd = -1;
    1.28  	struct hostent *h;
    1.29  	struct sockaddr_in s;
    1.30  	int sockbufsize;
    1.31 @@ -215,19 +217,18 @@ static PyObject *pyxc_linux_save(PyObjec
    1.32  	int writerfn(void *fd, const void *buf, size_t count)
    1.33  	{
    1.34  	    int tot = 0, rc;
    1.35 -	    do 
    1.36 -	    {
    1.37 +	    do {
    1.38  		rc = write( (int) fd, ((char*)buf)+tot, count-tot );
    1.39 -		if (rc<0) { perror("WRITE"); return rc; };
    1.40 +		if ( rc < 0 ) { perror("WRITE"); return rc; };
    1.41  		tot += rc;
    1.42  	    }
    1.43 -	    while(tot<count);
    1.44 +	    while ( tot < count );
    1.45  	    return 0;
    1.46  	}
    1.47  
    1.48  	strncpy( server, state_file+strlen("tcp://"), max_namelen);
    1.49  	server[max_namelen-1]='\0';
    1.50 -	if( port_s = strchr(server,':') )
    1.51 +	if ( (port_s = strchr(server,':')) != NULL )
    1.52  	{
    1.53  	    *port_s = '\0';
    1.54  	    port = atoi(port_s+1);
    1.55 @@ -237,36 +238,36 @@ static PyObject *pyxc_linux_save(PyObjec
    1.56  	
    1.57  	h = gethostbyname(server);
    1.58  	sd = socket (AF_INET,SOCK_STREAM,0);
    1.59 -	if(sd<0) goto serr;
    1.60 +	if ( sd < 0 )
    1.61 +            goto serr;
    1.62  	s.sin_family = AF_INET;
    1.63  	bcopy ( h->h_addr, &(s.sin_addr.s_addr), h->h_length);
    1.64  	s.sin_port = htons(port);
    1.65 -	if( connect(sd, (struct sockaddr *) &s, sizeof(s)) ) 
    1.66 +	if ( connect(sd, (struct sockaddr *) &s, sizeof(s)) ) 
    1.67  	    goto serr;
    1.68  
    1.69  	sockbufsize=128*1024;
    1.70 -	if (setsockopt(sd, SOL_SOCKET, SO_SNDBUF, &sockbufsize, sizeof sockbufsize) < 0) 
    1.71 -	{
    1.72 +	if ( setsockopt(sd, SOL_SOCKET, SO_SNDBUF, 
    1.73 +                        &sockbufsize, sizeof sockbufsize) < 0 ) 
    1.74  	    goto serr;
    1.75 -	}
    1.76  
    1.77 -	if ( xc_linux_save(xc->xc_handle, dom, flags, writerfn, (void*)sd) == 0 )
    1.78 +	if ( xc_linux_save(xc->xc_handle, dom, flags, 
    1.79 +                           writerfn, (void*)sd) == 0 )
    1.80  	{
    1.81  	    close(sd);
    1.82  	    Py_INCREF(zero);
    1.83  	    return zero;
    1.84  	}
    1.85  
    1.86 -	serr:
    1.87 -
    1.88 +    serr:
    1.89  	PyErr_SetFromErrno(xc_error);
    1.90 -	if(sd)close(sd);
    1.91 +	if ( sd >= 0 ) close(sd);
    1.92  	return NULL;
    1.93      }    
    1.94      else
    1.95      {
    1.96 -	int fd;
    1.97 -	gzFile gfd;
    1.98 +	int fd = -1;
    1.99 +	gzFile gfd = NULL;
   1.100  
   1.101  	int writerfn(void *fd, const void *buf, size_t count)
   1.102  	{
   1.103 @@ -310,10 +311,11 @@ static PyObject *pyxc_linux_save(PyObjec
   1.104  
   1.105      err:
   1.106  	PyErr_SetFromErrno(xc_error);
   1.107 -	if(gfd)gzclose(gfd);
   1.108 -	if(fd)close(fd);
   1.109 +	if ( gfd != NULL )
   1.110 +            gzclose(gfd);
   1.111 +	if ( fd >= 0 )
   1.112 +            close(fd);
   1.113  	unlink(state_file);
   1.114 -
   1.115  	return NULL;
   1.116      }
   1.117  
   1.118 @@ -336,15 +338,16 @@ static PyObject *pyxc_linux_restore(PyOb
   1.119                                        &dom, &state_file, &progress) )
   1.120          return NULL;
   1.121  
   1.122 -    if (progress) flags |= XCFLAGS_VERBOSE;
   1.123 +    if ( progress )
   1.124 +        flags |= XCFLAGS_VERBOSE;
   1.125  
   1.126 -    if (strncmp(state_file,"tcp:", strlen("tcp:")) == 0)
   1.127 +    if ( strncmp(state_file,"tcp:", strlen("tcp:")) == 0 )
   1.128      {
   1.129  #define max_namelen 64
   1.130  	char server[max_namelen];
   1.131  	char *port_s;
   1.132  	int port=777;
   1.133 -	int ld = 0, sd = 0;
   1.134 +	int ld = -1, sd = -1;
   1.135  	struct hostent *h;
   1.136  	struct sockaddr_in s, d, p;
   1.137  	socklen_t dlen, plen;
   1.138 @@ -356,20 +359,16 @@ static PyObject *pyxc_linux_restore(PyOb
   1.139  	    int rc, tot = 0;
   1.140  	    do { 
   1.141  		rc = read( (int) fd, ((char*)buf)+tot, count-tot ); 
   1.142 -		if (rc<0)
   1.143 -		    {
   1.144 -			perror("READ");
   1.145 -			return rc;
   1.146 -		    }
   1.147 +		if ( rc < 0 ) { perror("READ"); return rc; }
   1.148  		tot += rc;
   1.149 -	    } while( tot<count );
   1.150 -
   1.151 +	    } 
   1.152 +            while ( tot < count );
   1.153  	    return 0;
   1.154  	}
   1.155  
   1.156  	strncpy( server, state_file+strlen("tcp://"), max_namelen);
   1.157  	server[max_namelen-1]='\0';
   1.158 -	if( port_s = strchr(server,':') )
   1.159 +	if ( (port_s = strchr(server,':')) != NULL )
   1.160  	{
   1.161  	    *port_s = '\0';
   1.162  	    port = atoi(port_s+1);
   1.163 @@ -379,58 +378,55 @@ static PyObject *pyxc_linux_restore(PyOb
   1.164  	
   1.165  	h = gethostbyname(server);
   1.166  	ld = socket (AF_INET,SOCK_STREAM,0);
   1.167 -	if(ld<0) goto serr;
   1.168 +	if ( ld < 0 ) goto serr;
   1.169  	s.sin_family = AF_INET;
   1.170  	//bcopy ( h->h_addr, &(s.sin_addr.s_addr), h->h_length);
   1.171  	s.sin_addr.s_addr = htonl(INADDR_ANY);
   1.172  	s.sin_port = htons(port);
   1.173  
   1.174 -	if (setsockopt(ld, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) < 0)
   1.175 +	if ( setsockopt(ld, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) < 0 )
   1.176  	    goto serr;
   1.177  
   1.178 -	if( bind(ld, (struct sockaddr *) &s, sizeof(s)) ) 
   1.179 +	if ( bind(ld, (struct sockaddr *) &s, sizeof(s)) ) 
   1.180  	    goto serr;
   1.181  
   1.182 -	if( listen(ld, 1) )
   1.183 +	if ( listen(ld, 1) )
   1.184  	    goto serr;
   1.185  
   1.186  	dlen=sizeof(struct sockaddr);
   1.187 -	if( (sd = accept(ld, (struct sockaddr *) &d, &dlen )) < 0 )
   1.188 +	if ( (sd = accept(ld, (struct sockaddr *) &d, &dlen )) < 0 )
   1.189  	    goto serr;
   1.190  
   1.191          plen = sizeof(p);
   1.192 -	if (getpeername(sd, (struct sockaddr_in *) &p, 
   1.193 -			&plen) < 0) {
   1.194 +	if ( getpeername(sd, (struct sockaddr_in *) &p, 
   1.195 +                         &plen) < 0 )
   1.196  	    goto serr;
   1.197 -	}
   1.198  
   1.199 -	printf("Accepted connection from %s\n",
   1.200 -			inet_ntoa(p.sin_addr));
   1.201 +	printf("Accepted connection from %s\n", inet_ntoa(p.sin_addr));
   1.202  	
   1.203  	sockbufsize=128*1024;
   1.204 -	if (setsockopt(sd, SOL_SOCKET, SO_SNDBUF, &sockbufsize, sizeof sockbufsize) < 0) 
   1.205 -	{
   1.206 +	if ( setsockopt(sd, SOL_SOCKET, SO_SNDBUF, &sockbufsize, 
   1.207 +                        sizeof sockbufsize) < 0 ) 
   1.208  	    goto serr;
   1.209 -	}
   1.210  
   1.211 -	if ( xc_linux_restore(xc->xc_handle, dom, flags, readerfn, (void*)sd, &dom) == 0 )
   1.212 +	if ( xc_linux_restore(xc->xc_handle, dom, flags, 
   1.213 +                              readerfn, (void*)sd, &dom) == 0 )
   1.214  	{
   1.215  	    close(sd);
   1.216  	    Py_INCREF(zero);
   1.217  	    return zero;
   1.218  	}
   1.219  
   1.220 -	serr:
   1.221 -
   1.222 +    serr:
   1.223  	PyErr_SetFromErrno(xc_error);
   1.224 -	if(ld)close(ld);
   1.225 -	if(sd)close(sd);
   1.226 +	if ( ld >= 0 ) close(ld);
   1.227 +	if ( sd >= 0 ) close(sd);
   1.228  	return NULL;
   1.229      }    
   1.230      else
   1.231      {
   1.232 -	int fd;
   1.233 -	gzFile gfd;
   1.234 +	int fd = -1;
   1.235 +	gzFile gfd = NULL;
   1.236  
   1.237  	int readerfn(void *fd, void *buf, size_t count)
   1.238  	{
   1.239 @@ -441,7 +437,7 @@ static PyObject *pyxc_linux_restore(PyOb
   1.240  	    return ! (rc == count);
   1.241  	}
   1.242  
   1.243 -	if (strncmp(state_file,"file:",strlen("file:")) == 0)
   1.244 +	if ( strncmp(state_file,"file:",strlen("file:")) == 0 )
   1.245  	    state_file += strlen("file:");
   1.246  
   1.247  	if ( (fd = open(state_file, O_RDONLY)) == -1 )
   1.248 @@ -463,7 +459,8 @@ static PyObject *pyxc_linux_restore(PyOb
   1.249  	}
   1.250  
   1.251  
   1.252 -	if ( xc_linux_restore(xc->xc_handle, dom, flags, readerfn, gfd, &dom) == 0 )
   1.253 +	if ( xc_linux_restore(xc->xc_handle, dom, flags, 
   1.254 +                              readerfn, gfd, &dom) == 0 )
   1.255  	{
   1.256  	    gzclose(gfd);
   1.257  	    close(fd);
   1.258 @@ -474,8 +471,8 @@ static PyObject *pyxc_linux_restore(PyOb
   1.259  
   1.260      err:
   1.261  	PyErr_SetFromErrno(xc_error);
   1.262 -	if(gfd)gzclose(gfd);
   1.263 -	if(fd)close(fd);
   1.264 +	if ( gfd != NULL ) gzclose(gfd);
   1.265 +	if ( fd >= 0 ) close(fd);
   1.266  	return NULL;
   1.267      }
   1.268