ia64/xen-unstable

changeset 17803:caa2b155a42d

stubdom: permit compilation without lwip

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Jun 09 09:46:32 2008 +0100 (2008-06-09)
parents 07ba9aeee347
children 124367e10376
files extras/mini-os/lib/sys.c extras/mini-os/main.c
line diff
     1.1 --- a/extras/mini-os/lib/sys.c	Mon Jun 09 09:46:16 2008 +0100
     1.2 +++ b/extras/mini-os/lib/sys.c	Mon Jun 09 09:46:32 2008 +0100
     1.3 @@ -43,7 +43,9 @@
     1.4  #include <stdlib.h>
     1.5  #include <math.h>
     1.6  
     1.7 +#ifdef HAVE_LWIP
     1.8  #include <lwip/sockets.h>
     1.9 +#endif
    1.10  #include <fs.h>
    1.11  
    1.12  #define debug(fmt, ...) \
    1.13 @@ -240,8 +242,10 @@ int read(int fd, void *buf, size_t nbyte
    1.14  	    }
    1.15  	    return 0;
    1.16  	}
    1.17 +#ifdef HAVE_LWIP
    1.18  	case FTYPE_SOCKET:
    1.19  	    return lwip_read(files[fd].socket.fd, buf, nbytes);
    1.20 +#endif
    1.21  	case FTYPE_TAP: {
    1.22  	    ssize_t ret;
    1.23  	    ret = netfront_receive(files[fd].tap.dev, buf, nbytes);
    1.24 @@ -299,8 +303,10 @@ int write(int fd, const void *buf, size_
    1.25  	    }
    1.26  	    return 0;
    1.27  	}
    1.28 +#ifdef HAVE_LWIP
    1.29  	case FTYPE_SOCKET:
    1.30  	    return lwip_write(files[fd].socket.fd, (void*) buf, nbytes);
    1.31 +#endif
    1.32  	case FTYPE_TAP:
    1.33  	    netfront_xmit(files[fd].tap.dev, (void*) buf, nbytes);
    1.34  	    return nbytes;
    1.35 @@ -367,7 +373,7 @@ int close(int fd)
    1.36  {
    1.37      printk("close(%d)\n", fd);
    1.38      switch (files[fd].type) {
    1.39 -	case FTYPE_CONSOLE:
    1.40 +        default:
    1.41  	    files[fd].type = FTYPE_NONE;
    1.42  	    return 0;
    1.43  	case FTYPE_FILE: {
    1.44 @@ -382,11 +388,13 @@ int close(int fd)
    1.45  	case FTYPE_XENBUS:
    1.46              xs_daemon_close((void*)(intptr_t) fd);
    1.47              return 0;
    1.48 +#ifdef HAVE_LWIP
    1.49  	case FTYPE_SOCKET: {
    1.50  	    int res = lwip_close(files[fd].socket.fd);
    1.51  	    files[fd].type = FTYPE_NONE;
    1.52  	    return res;
    1.53  	}
    1.54 +#endif
    1.55  	case FTYPE_XC:
    1.56  	    xc_interface_close(fd);
    1.57  	    return 0;
    1.58 @@ -555,6 +563,7 @@ int fcntl(int fd, int cmd, ...)
    1.59      va_end(ap);
    1.60  
    1.61      switch (cmd) {
    1.62 +#ifdef HAVE_LWIP
    1.63  	case F_SETFL:
    1.64  	    if (files[fd].type == FTYPE_SOCKET && !(arg & ~O_NONBLOCK)) {
    1.65  		/* Only flag supported: non-blocking mode */
    1.66 @@ -562,6 +571,7 @@ int fcntl(int fd, int cmd, ...)
    1.67  		return lwip_ioctl(files[fd].socket.fd, FIONBIO, &nblock);
    1.68  	    }
    1.69  	    /* Fallthrough */
    1.70 +#endif
    1.71  	default:
    1.72  	    printk("fcntl(%d, %d, %lx/%lo)\n", fd, cmd, arg, arg);
    1.73  	    errno = ENOSYS;
    1.74 @@ -666,9 +676,12 @@ static void dump_set(int nfds, fd_set *r
    1.75  /* Just poll without blocking */
    1.76  static int select_poll(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds)
    1.77  {
    1.78 -    int i, n = 0, sock_n, sock_nfds = 0;
    1.79 +    int i, n = 0;
    1.80 +#ifdef HAVE_LWIP
    1.81 +    int sock_n, sock_nfds = 0;
    1.82      fd_set sock_readfds, sock_writefds, sock_exceptfds;
    1.83      struct timeval timeout = { .tv_sec = 0, .tv_usec = 0};
    1.84 +#endif
    1.85  
    1.86  #ifdef LIBC_VERBOSE
    1.87      static int nb;
    1.88 @@ -678,6 +691,7 @@ static int select_poll(int nfds, fd_set 
    1.89      nb++;
    1.90  #endif
    1.91  
    1.92 +#ifdef HAVE_LWIP
    1.93      /* first poll network */
    1.94      FD_ZERO(&sock_readfds);
    1.95      FD_ZERO(&sock_writefds);
    1.96 @@ -704,6 +718,7 @@ static int select_poll(int nfds, fd_set 
    1.97      sock_n = lwip_select(sock_nfds, &sock_readfds, &sock_writefds, &sock_exceptfds, &timeout);
    1.98      dump_set(nfds, &sock_readfds, &sock_writefds, &sock_exceptfds, &timeout);
    1.99      DEBUG("\n");
   1.100 +#endif
   1.101  
   1.102      /* Then see others as well. */
   1.103      for (i = 0; i < nfds; i++) {
   1.104 @@ -752,6 +767,7 @@ static int select_poll(int nfds, fd_set 
   1.105  	    FD_CLR(i, writefds);
   1.106  	    FD_CLR(i, exceptfds);
   1.107  	    break;
   1.108 +#ifdef HAVE_LWIP
   1.109  	case FTYPE_SOCKET:
   1.110  	    if (FD_ISSET(i, readfds)) {
   1.111  	        /* Optimize no-network-packet case.  */
   1.112 @@ -773,6 +789,7 @@ static int select_poll(int nfds, fd_set 
   1.113  		    FD_CLR(i, exceptfds);
   1.114              }
   1.115  	    break;
   1.116 +#endif
   1.117  	}
   1.118  #ifdef LIBC_VERBOSE
   1.119  	if (FD_ISSET(i, readfds))
   1.120 @@ -938,6 +955,7 @@ out:
   1.121      return ret;
   1.122  }
   1.123  
   1.124 +#ifdef HAVE_LWIP
   1.125  int socket(int domain, int type, int protocol)
   1.126  {
   1.127      int fd, res;
   1.128 @@ -989,6 +1007,7 @@ LWIP_STUB(ssize_t, recvfrom, (int s, voi
   1.129  LWIP_STUB(ssize_t, send, (int s, void *buf, size_t len, int flags), (s, buf, len, flags))
   1.130  LWIP_STUB(ssize_t, sendto, (int s, void *buf, size_t len, int flags, struct sockaddr *to, socklen_t tolen), (s, buf, len, flags, to, tolen))
   1.131  LWIP_STUB(int, getsockname, (int s, struct sockaddr *name, socklen_t *namelen), (s, name, namelen))
   1.132 +#endif
   1.133  
   1.134  int nanosleep(const struct timespec *req, struct timespec *rem)
   1.135  {
     2.1 --- a/extras/mini-os/main.c	Mon Jun 09 09:46:16 2008 +0100
     2.2 +++ b/extras/mini-os/main.c	Mon Jun 09 09:46:32 2008 +0100
     2.3 @@ -57,7 +57,9 @@ static void call_main(void *p)
     2.4      //sleep(1);
     2.5  
     2.6      sparse((unsigned long) &__app_bss_start, &__app_bss_end - &__app_bss_start);
     2.7 +#ifdef HAVE_LWIP
     2.8      start_networking();
     2.9 +#endif
    2.10      init_fs_frontend();
    2.11  
    2.12  #ifdef CONFIG_QEMU
    2.13 @@ -162,6 +164,9 @@ void _exit(int ret)
    2.14      close_all_files();
    2.15      __libc_fini_array();
    2.16      printk("main returned %d\n", ret);
    2.17 +#ifdef HAVE_LWIP
    2.18 +    stop_networking();
    2.19 +#endif
    2.20      unbind_all_ports();
    2.21      if (!ret) {
    2.22  	/* No problem, just shutdown.  */