direct-io.hg

changeset 833:6d0f37cc9107

bitkeeper revision 1.515 (3f8c05c9ugF0DM7SjnFypZrwVlJ7jQ)

xen_log.c:
Now xen_log really does compile and link.
author kaf24@scramble.cl.cam.ac.uk
date Tue Oct 14 14:18:49 2003 +0000 (2003-10-14)
parents e7184dc0e284
children d44118178696
files tools/misc/xen_log.c
line diff
     1.1 --- a/tools/misc/xen_log.c	Tue Oct 14 14:12:35 2003 +0000
     1.2 +++ b/tools/misc/xen_log.c	Tue Oct 14 14:18:49 2003 +0000
     1.3 @@ -1,3 +1,5 @@
     1.4 +
     1.5 +#include <netinet/in.h>
     1.6  #include <sys/types.h>
     1.7  #include <tcpd.h>
     1.8  #include <sys/socket.h>
     1.9 @@ -23,20 +25,21 @@ int logoutput;
    1.10  
    1.11  void stripit(char *str)
    1.12  {
    1.13 -  register int i;
    1.14 -
    1.15 -  for (i = 0; str[i]; i++) {
    1.16 -      if (str[i] == '\n') str[i] = '\0';
    1.17 -      if (str[i] == '\r') str[i] = '\0';
    1.18 -  }
    1.19 +    int i;
    1.20 +    for ( i = 0; str[i]; i++ )
    1.21 +        if ( (str[i] == '\n') || (str[i] == '\r') ) 
    1.22 +            str[i] = '\0';
    1.23  }
    1.24  
    1.25  void errexit(char *str)
    1.26  {
    1.27 -    if(logoutput == SYSLOG) {
    1.28 +    if ( logoutput == SYSLOG )
    1.29 +    {
    1.30          stripit(str);
    1.31          syslog(LOG_ERR, "%s failed: %d (%m)", str, errno);
    1.32 -    } else {
    1.33 +    } 
    1.34 +    else 
    1.35 +    {
    1.36          printf("%s", str);
    1.37      }
    1.38      exit(1);
    1.39 @@ -44,15 +47,18 @@ void errexit(char *str)
    1.40  
    1.41  void log(char *str)
    1.42  {
    1.43 -    if(logoutput == SYSLOG) {
    1.44 +    if ( logoutput == SYSLOG )
    1.45 +    {
    1.46          stripit(str);
    1.47          syslog(LOG_INFO, "%s", str);
    1.48 -    } else {
    1.49 +    } 
    1.50 +    else 
    1.51 +    {
    1.52          printf("%s", str);
    1.53      }
    1.54  }
    1.55  
    1.56 -void process()
    1.57 +void process(void)
    1.58  {
    1.59      dom0_op_t op;
    1.60      unsigned char buf[208], obuf[224];
    1.61 @@ -75,20 +81,20 @@ void process()
    1.62      op.cmd = DOM0_GETDOMAININFO;
    1.63  
    1.64      while ( (len = recvfrom(fd, buf, sizeof(buf), 0,
    1.65 -            (struct sockaddr *)&from, &fromlen)) >= 0 )
    1.66 +                            (struct sockaddr *)&from, &fromlen)) >= 0 )
    1.67      {
    1.68          curport = ntohs(from.sin_port);
    1.69 -        if(lastport != curport) {
    1.70 -           op.u.getdominfo.domain = (int)curport;
    1.71 -           if ( do_dom0_op(&op) < 0 ) {
    1.72 -              log("Error resolving domain name\n");
    1.73 -           } else {
    1.74 -              lastport = curport;
    1.75 -           }
    1.76 +        if ( lastport != curport )
    1.77 +        {
    1.78 +            op.u.getdominfo.domain = (int)curport;
    1.79 +            if ( do_dom0_op(&op) < 0 )
    1.80 +                log("Error resolving domain name\n");
    1.81 +            else
    1.82 +                lastport = curport;
    1.83          }
    1.84  
    1.85          sprintf(obuf, "[%s] %s", op.u.getdominfo.name, buf);
    1.86 -		log(obuf);
    1.87 +        log(obuf);
    1.88  
    1.89          fromlen = sizeof(from);
    1.90      }
    1.91 @@ -99,30 +105,30 @@ void closeall(int fd)
    1.92      int fdlimit = sysconf(_SC_OPEN_MAX);
    1.93  
    1.94      while (fd < fdlimit)
    1.95 -      close(fd++);
    1.96 +        close(fd++);
    1.97  }
    1.98  
    1.99  int daemon(int nochdir, int noclose)
   1.100  {
   1.101      switch (fork())
   1.102      {
   1.103 -        case 0:  break;
   1.104 -        case -1: return -1;
   1.105 -        default: _exit(0);
   1.106 +    case 0:  break;
   1.107 +    case -1: return -1;
   1.108 +    default: _exit(0);
   1.109      }
   1.110  
   1.111      if (setsid() < 0)
   1.112 -      return -1;
   1.113 +        return -1;
   1.114  
   1.115      switch (fork())
   1.116      {
   1.117 -        case 0:  break;
   1.118 -        case -1: return -1;
   1.119 -        default: _exit(0);
   1.120 +    case 0:  break;
   1.121 +    case -1: return -1;
   1.122 +    default: _exit(0);
   1.123      }
   1.124  
   1.125      if (!nochdir)
   1.126 -      chdir("/");
   1.127 +        chdir("/");
   1.128  
   1.129      if (!noclose)
   1.130      {
   1.131 @@ -145,22 +151,22 @@ int main(int argc, char **argv)
   1.132      {
   1.133          switch(c)
   1.134          {
   1.135 -            case 'd':
   1.136 -                logoutput = SYSLOG;
   1.137 -                if (daemon(0,0) < 0)
   1.138 -                {
   1.139 -                    errno = 2;
   1.140 -                    errexit("daemon");
   1.141 -                } else {
   1.142 -                    openlog("xenolog", LOG_PID, SYSLOGTO);
   1.143 -                }
   1.144 -                break;
   1.145 -            case 'h':
   1.146 -                printf("Usage: xenolog [options]\n");
   1.147 -                printf("Capture and display output of xen domains.\n\n");
   1.148 -                printf("  -d       Daemonize and send output to syslog.\n");
   1.149 -                exit(0);
   1.150 -                break;
   1.151 +        case 'd':
   1.152 +            logoutput = SYSLOG;
   1.153 +            if (daemon(0,0) < 0)
   1.154 +            {
   1.155 +                errno = 2;
   1.156 +                errexit("daemon");
   1.157 +            } else {
   1.158 +                openlog("xenolog", LOG_PID, SYSLOGTO);
   1.159 +            }
   1.160 +            break;
   1.161 +        case 'h':
   1.162 +            printf("Usage: xenolog [options]\n");
   1.163 +            printf("Capture and display output of xen domains.\n\n");
   1.164 +            printf("  -d       Daemonize and send output to syslog.\n");
   1.165 +            exit(0);
   1.166 +            break;
   1.167          }
   1.168      }
   1.169