some random old commits before bzr conversion
authortridge <>
Sun, 24 Jun 2007 16:08:20 +0000 (16:08 +0000)
committertridge <>
Sun, 24 Jun 2007 16:08:20 +0000 (16:08 +0000)
33 files changed:
base64.c
enum.c
epoll_fork.c
fnmatch/ms_fnmatch.c
getmntent.c
histogram.awk
idtree/Makefile
iolmaster/iolmaster.c
mail.runner
minimal_includes.pl
mksparse.c
notify.c
nsstest.c
preload_open.c
pthreads/locking.c
pthreads/tls.c
radeontool/radeon_reg.h
radeontool/radeontool.c
readfiles.c
segv_handler/Makefile
segv_handler/segv_handler.c
segv_handler/testprog.c
sizeof.c
sockspy-ntlm2.c
softroot/preload_softroot.c
speed.c
tdd/tdd.c
timelimit.c
tserver/files/index.html
udpproxy.c
web/index.cgi
writefiles.c
zfind.c

index 5892e9c8b7d626413715e757192d30011750ee11..291a317721cd93b784c88a0f18cfde8181602d36 100644 (file)
--- a/base64.c
+++ b/base64.c
@@ -3,18 +3,20 @@
 #include <errno.h>
 #include <stdlib.h>
 
-/***************************************************************************
-encode a buffer using base64 - simple and slow algorithm. null terminates
-the result.
-  ***************************************************************************/
-static void base64_encode(char *buf, int len, char *out)
+/*
+  encode as base64
+  caller frees
+*/
+static char *base64_encode(const char *buf, int len)
 {
-       char *b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+       const char *b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
        int bit_offset, byte_offset, idx, i;
-       unsigned char *d = (unsigned char *)buf;
-       int bytes = (len*8 + 5)/6;
+       const unsigned char *d = (const unsigned char *)buf;
+       int bytes = (len*8 + 5)/6, pad_bytes = (bytes % 4) ? 4 - (bytes % 4) : 0;
+       char *out;
 
-       memset(out, 0, bytes+1);
+       out = calloc(1, bytes+pad_bytes+1);
+       if (!out) return NULL;
 
        for (i=0;i<bytes;i++) {
                byte_offset = (i*6)/8;
@@ -29,6 +31,12 @@ static void base64_encode(char *buf, int len, char *out)
                }
                out[i] = b64[idx];
        }
+
+       for (;i<bytes+pad_bytes;i++)
+               out[i] = '=';
+       out[i] = 0;
+
+       return out;
 }
 
 
@@ -60,13 +68,9 @@ int main(int argc, char *argv[])
 {
        char *s;
        int n;
-       char *out;
 
        n = load_stdin(&s);
 
-       out = malloc(n*2);
-
-       base64_encode(s, n, out);
-       printf("%s\n", out);
+       printf("%s\n", base64_encode(s, n));
        return 0;
 }
diff --git a/enum.c b/enum.c
index 8325b4e702cc8c1ffacd3525cfbca2fa2d733cc4..dcf39ccdce5965802c0e2e8ac010682ed0fbc815 100644 (file)
--- a/enum.c
+++ b/enum.c
@@ -1,7 +1,10 @@
 #include <stdio.h>
 
+enum xxy;
+
 typedef struct { int v; } BOOL;
 typedef enum {NO_PROBLEM=0, BLAH=1} NT_STATUS;
+#define False 0
 
 static BOOL foo1(void)
 {
index 3c0deaa2445cc6337538a065e77ba77d18fd6eb2..06439812e63d2c5059f2dcbc2a05ea59747d2d57 100644 (file)
@@ -6,7 +6,6 @@
 #include <sys/wait.h>
 #include <errno.h>
 
-
 static void run_child(int epoll_fd)
 {
        struct epoll_event event;
@@ -20,7 +19,10 @@ static void run_child(int epoll_fd)
        event.events = EPOLLIN|EPOLLERR;
        event.data.u32 = getpid();
 
-       epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd[0], &event);
+       if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd[0], &event) != 0) {
+               perror("epoll_ctl");
+               abort();
+       }
 
        while (1) {
                char c = 0;
index bd458564db5be26ae13e6588113d8b29d582e3ed..bc2b757a0f22d0782bb036cf4b506252262590ee 100644 (file)
@@ -109,7 +109,7 @@ static int fnmatch_core(const char *p, const char *n, struct max_n *max_n, const
                        if (max_n->predot && max_n->predot <= n) {
                                return null_match(p);
                        }
-                       if (max_n->postdot && max_n->postdot <= n && n < ldot) {
+                       if (max_n->postdot && max_n->postdot <= n && n <= ldot) {
                                return -1;
                        }
                        for (i=0; n[i]; i++) {
index 6f945afc3c431f5f6cd164156037c8ac991dcc78..a04666d3150f8f144d81afd18ea1c19798a6f4da 100644 (file)
@@ -1,5 +1,8 @@
 #include <stdio.h>
 #include <mntent.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
 
 int main(void)
 {
@@ -7,8 +10,13 @@ int main(void)
        struct mntent *m;
 
        while ((m = getmntent(f))) {
-               printf("%s %s %s\n", 
-                      m->mnt_fsname, m->mnt_dir, m->mnt_type);
+               struct stat st;
+               dev_t dev = 0;
+               if (stat(m->mnt_dir, &st) == 0) {
+                       dev = st.st_dev;
+               }
+               printf("%s %s %s 0x%llx\n", 
+                      m->mnt_fsname, m->mnt_dir, m->mnt_type, (unsigned long long)dev);
        }
        
        endmntent(f);
index e1e1ebc9bd8f98d8e3d306590a8d8f255e1d9103..4580ca0b7dad308e1fff1407a89ea8e6a411b990 100644 (file)
@@ -1,6 +1,6 @@
 
 {
-  counts[$1]++;
+  counts[$0]++;
   total++;
 }
 
index b8ba4dacb1453ff3251aa0a456cbd8e044d99648..d3e0bfebb7d2ff5106a2d525528b985cac763d95 100644 (file)
@@ -1,4 +1,4 @@
-CFLAGS=-Wall -O2 -g -I/usr/src/linux/include
+CFLAGS=-Wall -O2 -I/usr/src/linux/include
 
 all: idtree
 
index 768cff86860dade117dc1814e9fce5d9b5018e99..a3229377c268527adef2cb6d587fb543521f40a7 100644 (file)
@@ -35,7 +35,7 @@ static int open_socket_out(const char *host, int port)
        } else {
                hp = gethostbyname(host);
                if (!hp) {
-                       fprintf(stderr,"tseal: unknown host %s\n", host);
+                       fprintf(stderr,"iolmaster: unknown host %s\n", host);
                        return -1;
                }
                memcpy(&sock_out.sin_addr, hp->h_addr, hp->h_length);
@@ -46,7 +46,7 @@ static int open_socket_out(const char *host, int port)
 
        if (connect(res,(struct sockaddr *)&sock_out,sizeof(sock_out)) != 0) {
                close(res);
-               fprintf(stderr,"tseal: failed to connect to %s (%s)\n", 
+               fprintf(stderr,"iolmaster: failed to connect to %s (%s)\n", 
                        host, strerror(errno));
                return -1;
        }
@@ -80,6 +80,15 @@ static int new_file(time_t *t)
 
        do {
                char *name;
+               struct stat st;
+               asprintf(&name, "iol-%u.dat", (unsigned)*t);
+               if (stat(name, &st) == 0) {
+                 fd = -1;
+                       free(name);
+                       (*t)++;
+                       continue;
+               }
+               free(name);
                asprintf(&name, "iol-%u.tmp", (unsigned)*t);
                fd = open(name, O_CREAT|O_EXCL|O_WRONLY, 0644);
                if (fd == -1) {
@@ -106,11 +115,38 @@ static void end_file(time_t t)
        free(name2);
 }
 
+static char nbuf[1024];
+static int nbuflen, nbufofs;
+
+static int next_char(int fd, char *c)
+{
+       if (nbuflen == 0) {
+               nbuflen = read(fd, nbuf, sizeof(nbuf));
+               if (nbuflen <= 0) return 0;
+               nbufofs = 0;
+       }
+       
+       *c = nbuf[nbufofs++];
+       nbuflen--;
+       return 1;
+}
+
 static int check_checksum(const char *line, size_t len)
 {
        unsigned char sum = 0;
        int i;
 
+       if (nbuflen > 0 && 
+           nbuf[nbufofs] != 'B' &&
+           nbuf[nbufofs] != 'E') {
+         return 0;
+       }
+
+       if (nbuflen > 1 && 
+           (!isxdigit(nbuf[nbufofs+1]) || islower(nbuf[nbufofs+1]))) {
+         return 0;
+       }
+
        for (i=0;i<len-3;i++) {
                sum += ((unsigned char *)line)[i];
        }
@@ -145,7 +181,7 @@ static int fetch_line(int fd, char **line)
                        }
                }
 
-               if (read(fd, &c, 1) != 1) {
+               if (next_char(fd, &c) != 1) {
                        return len;
                }
 
index d88c59f2cb5ebb15ed792f28b809bef0210f802e..d4344aeccb35ba9d4ca3aebccef409efe0e1824f 100755 (executable)
@@ -13,7 +13,7 @@ MAIL_DIR="Mail"
 MAIL_INBOX="$HOME/InBox"
 MAIL_RUNNER="mail.runner"
 SENDMAIL="/usr/lib/sendmail"
-SENDMAIL_OPTS="-t"
+SENDMAIL_OPTS="-t -i"
 RSYNC_OPTS="-Pavz"
 MAIL_TIMEOUT=300
 PROCMAIL_COMMAND="formail -s procmail"
index 995f44a63c1b03305274a74311fffb9fc6e3bae5..f9d80e263cbc96ba2dc243170ca70ebf734b8ed7 100755 (executable)
@@ -74,11 +74,14 @@ sub test_include($$$$)
        my $out = test_compile($fname);
        
        if ($out eq $original) {
-           if ($opt_remove) {
-               print "$fname: removing $line";
-               return;
-           }
-           print "$fname: might be able to remove $line";
+               if ($opt_remove) {
+                       print "$fname: removing $line";
+                       return;
+               }
+               print "$fname: might be able to remove $line";
+       } else {
+#              print "OUT:  $out\n";
+#              print "ORIG: $original\n";
        }
 
        $lines->[$i] = $line;
index 4c9dab1294c40e68238d11ec678742927ef035b7..954c8055ef8016a2753aad72d6449e5d08e0620c 100644 (file)
@@ -9,7 +9,7 @@ int main(int argc, char *argv[])
        int fd;
 
        fd = open(fname,O_WRONLY|O_CREAT|O_TRUNC, 0600);
-       lseek(fd, megs * 1024*1024, SEEK_SET);
+       llseek(fd, megs * 1024*1024, SEEK_SET);
        write(fd, fname, strlen(fname));
        close(fd);
        return 0;
index 2088140b62afc2306db452d536914d2fb51722c8..f0d4c3169b2c1450b9176bac11152bf72501cb98 100644 (file)
--- a/notify.c
+++ b/notify.c
@@ -41,4 +41,6 @@ int main(void)
                pause();
                printf("Got event on fd=%d\n", event_fd);
        }
+
+       return 0;
 }
index fb1a906e4a5e89241f10e4efeae1c2fbaccb43f8..59f8dc07d3cc499a9f5c5fce8be6f27adccf8bb1 100644 (file)
--- a/nsstest.c
+++ b/nsstest.c
@@ -257,7 +257,8 @@ static int nss_initgroups(char *user, gid_t group, gid_t **groups, long int *sta
 
        if (!_nss_initgroups) return NSS_STATUS_UNAVAIL;
 
-       status = _nss_initgroups(user, group, start, size, groups, 0, &nss_errno);
+       status = _nss_initgroups(user, group, start, size, groups, 2, &nss_errno);
+       printf("nss_errno=%d *size=%d\n", nss_errno, *size);
        if (status != NSS_STATUS_SUCCESS) {
                report_nss_error("initgroups", status);
        }
index 15e66f5491c172ce6d709486a0c59b3f1c98bf00..eb7d92a56dbed4e101db08842615a42827331439 100644 (file)
@@ -24,7 +24,9 @@ static void do_magic(const char *pathname)
        const char *magic_script;
        char *s = NULL;
        magic_script = getenv("MAGIC_SCRIPT");
-       
+
+       unlink("xxx.dat");
+
        if (!magic_script) {
                return;
        }
@@ -65,6 +67,8 @@ int open64(const char *pathname, int flags, ...)
 
        ret = real_open(pathname, flags, mode);
 
+               do_magic(pathname);
+
        if (ret == -1 && errno == ENOENT) {
                do_magic(pathname);
                ret = real_open(pathname, flags, mode);
@@ -100,6 +104,8 @@ int open(const char *pathname, int flags, ...)
 
        ret = real_open(pathname, flags, mode);
 
+               do_magic(pathname);
+
        if (ret == -1 && errno == ENOENT) {
                do_magic(pathname);
                ret = real_open(pathname, flags, mode);
index 9299bfde3f09c669468f2f10c22a8e0575ede413..f65247248fb7f28b7da6f59eba423b9010778dd1 100644 (file)
@@ -66,6 +66,8 @@ static void *thread_main(void *private)
                }
        }
 
+       printf("tid %d done\n", tid);
+
        return NULL;
 }
 
index 53bbd1063cb4f5d1d9edfabc36d11aeb81e41c4a..29715a5716297b1fa2d95ca159301eb2d25ab865 100644 (file)
@@ -45,6 +45,8 @@ int main(int argc, char *argv[])
        thread_start(thread_main, NULL);
        thread_start(thread_main, NULL);
 
+       usleep(1);
+
        printf("tls=%d non_tls=%d\n", tls, non_tls);
 
        if (tls != 0 || non_tls != 5) {
index eb586a29ef592087a12b1a04f077bcf17bf65a5b..780d2e841ff5878dec36e9cba1ee6b90e86a656e 100644 (file)
 #       define RADEON_DAC_VGA_ADR_EN        (1 << 13)
 #       define RADEON_DAC_PDWN              (1 << 15)
 #       define RADEON_DAC_MASK_ALL          (0xff << 24)
+#define RADEON_DAC_EXT_CNTL                 0x0280
 #define RADEON_DAC_CNTL2                     0x007c
 #       define RADEON_DAC2_DAC_CLK_SEL      (1 <<  0)
 #       define RADEON_DAC2_DAC2_CLK_SEL     (1 <<  1)
index 0d41f05f2194ae58decbb1368a788f6acb12653e..9bc4c2f88ef926bfef720c07b77d6ca26a01fdf6 100644 (file)
@@ -122,6 +122,7 @@ void radeon_cmd_regs(void)
        #define SHOW_REG(r) printf("%s\t%08lx\n", #r, radeon_get(r, #r))
        
        SHOW_REG(RADEON_DAC_CNTL);
+       SHOW_REG(RADEON_DAC_EXT_CNTL);
        SHOW_REG(RADEON_DAC_CNTL2);
        SHOW_REG(RADEON_TV_DAC_CNTL);
        SHOW_REG(RADEON_DISP_OUTPUT_CNTL);
@@ -256,6 +257,7 @@ REGLIST(CUR2_HORZ_VERT_OFF),
 REGLIST(CUR2_HORZ_VERT_POSN),
 REGLIST(CUR2_OFFSET),
 REGLIST(DAC_CNTL),
+REGLIST(DAC_EXT_CNTL),
 REGLIST(DAC_CNTL2),
 REGLIST(TV_DAC_CNTL),
 REGLIST(DISP_OUTPUT_CNTL),
index 681d54c279f484aa4418279d4b11ffb9a753c7ca..46025d7f48aae07653d8802b2955b5267cf97591 100644 (file)
@@ -62,14 +62,14 @@ static void read_file(char *fname)
 
 static void usage(void)
 {
-       printf("
-readfiles - reads from a list of files, showing read throughput
-
-Usage: readfiles [options] <files>
-
-Options:
-    -B size        set the block size in bytes
-");
+       printf("\n" \
+"readfiles - reads from a list of files, showing read throughput\n" \
+"\n" \
+"Usage: readfiles [options] <files>\n" \
+"\n" \
+"Options:\n" \
+"    -B size        set the block size in bytes\n" \
+"");
 }
 
 int main(int argc, char *argv[])
index 8461b3f693f812148605accfdd8153c0512ab582..4a0461fc7977324edfbfd6138200d72bb980aee5 100644 (file)
@@ -10,7 +10,7 @@ testprog: testprog.c
 
 test: all
        -LD_PRELOAD=./segv_handler.so ./testprog
-       ls -l /tmp/segv_testprog.*
+       ls -l /var/log/segv/segv_testprog.*
 
 clean:
        /bin/rm -f *.o *.so *~ testprog /tmp/segv_testprog.*
index bf06ef2d37f3cf8b0a63c863e4f8caeb18050955..eadc61dd0dc8c8128b8076fc3e33373dcdb37357 100644 (file)
@@ -18,7 +18,7 @@ static int segv_handler(int sig)
        p = strrchr(progname, '/');
        *p = 0;
        
-       snprintf(cmd, sizeof(cmd), "backtrace %d > /tmp/segv_%s.%d.out 2>&1", 
+       snprintf(cmd, sizeof(cmd), "backtrace %d > /var/log/segv/segv_%s.%d.out 2>&1", 
                 (int)getpid(), p+1, (int)getpid());
        system(cmd);
        signal(SIGSEGV, SIG_DFL);
@@ -28,4 +28,5 @@ static int segv_handler(int sig)
 void _init(void)
 {
        signal(SIGSEGV, segv_handler);
+       signal(SIGBUS, segv_handler);
 }
index 709fdae080a558a839a38b13ad52c408ed937289..e37d9cd7bbf2c07ac6083b9348c69e9281c38282 100644 (file)
@@ -1,9 +1,17 @@
-void foo(int *x)
+void another_function(int *yy)
 {
        /* add some local variables for "bt full" to see */
        int y = 7;
        double foo = 1.2;
-       *x = 2;
+       *yy = 2;
+}
+
+void foo(int *x)
+{
+       /* add some local variables for "bt full" to see */
+       int foovar = 7;
+       double myval = 1.2;
+       another_function(x);
 }
 
 int main(void)
index 3333fa24b0de6f52783ba6e80478cff8cb79f860..e9bf49c02295d2eb8df7a021915bb7b6d91139e1 100644 (file)
--- a/sizeof.c
+++ b/sizeof.c
@@ -13,4 +13,8 @@ main()
         printf("off_t : %d\n", sizeof(off_t));
         printf("size_t : %d\n", sizeof(size_t));
         printf("uid_t : %d\n", sizeof(uid_t));
+        printf("dev_t : %d\n", sizeof(dev_t));
+        printf("ino_t : %d\n", sizeof(ino_t));
+        printf("float : %d\n", sizeof(float));
+        printf("double : %d\n", sizeof(double));
 }
index f734614eb3a339011c4a4d217cfb91d13ec86980..285164da6f5ace402abcb3d95ff15a74a66584ff 100644 (file)
@@ -77,7 +77,6 @@ void dump_data(int level, const char *buf1,int len)
 static void replace_str(char *buf, int n)
 {
        static int count;
-       char *p;
        printf("Packet %d\n", count++);
        dump_data(0, buf, n);
        if (0 && n == 0x40) {
@@ -227,6 +226,29 @@ static void main_loop(int sock1, int sock2)
        }       
 }
 
+static char *get_socket_addr(int fd)
+{
+       struct sockaddr sa;
+       struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa);
+       socklen_t length = sizeof(sa);
+       static char addr_buf[200];
+
+       strcpy(addr_buf,"0.0.0.0");
+
+       if (fd == -1) {
+               return addr_buf;
+       }
+       
+       if (getsockname(fd, &sa, &length) < 0) {
+               printf("getpeername failed. Error was %s\n", strerror(errno) );
+               return addr_buf;
+       }
+       
+       strcpy(addr_buf,(char *)inet_ntoa(sockin->sin_addr));
+       
+       return addr_buf;
+}
+
 int main(int argc, char *argv[])
 {
        int listen_port, dest_port;
@@ -267,6 +289,8 @@ int main(int argc, char *argv[])
                exit(1);
        }
 
+       printf("Connection from %s\n", get_socket_addr(sock_in));
+
        close(listen_fd);
 
        sock_out = open_socket_out(host, dest_port);
index c52d91b01f2c5dcce94ce9230efdc884d1809c3d..41ac8fc988487e5a6a363c11678db8a124743c00 100644 (file)
@@ -78,13 +78,16 @@ static const char *redirect_name(const char *filename)
 {
        static char buf[1024];
        static int (*access_orig)(const char *, int );
+       static char *(*getenv_orig)(const char *);
        static const char *lroot;
 
        if (filename == NULL) return filename;
 
-       if (hack_disabled == -1) {
-               char *(*getenv_orig)(const char *);
+       if (!getenv_orig) {
                getenv_orig = dlsym(RTLD_NEXT, "getenv");
+       }
+
+       if (hack_disabled == -1) {
                if (getenv_orig("SOFTROOT_DISABLED")) {
                        hack_disabled = 1;
                } else {
@@ -97,7 +100,7 @@ static const char *redirect_name(const char *filename)
        }
 
        if (lroot == NULL) {
-               lroot = getenv("LROOT");
+               lroot = getenv_orig("LROOT");
        }
        if (lroot == NULL) {
                lroot = "/opt/softroot";
@@ -304,6 +307,7 @@ FILE *fopen(const char *filename, const char *mode)
 
        if (!fopen_orig) {
                fopen_orig = dlsym(RTLD_NEXT, "fopen");
+
        }
 
        ret = fopen_orig(redirect_name(filename), mode);
diff --git a/speed.c b/speed.c
index fa1897ff82a910e3b17c80a6ab15e8de2012239e..2743ebd10ef4a8ae201f7b11e2a59b6db6de1458 100644 (file)
--- a/speed.c
+++ b/speed.c
@@ -1,4 +1,9 @@
+#define _GNU_SOURCE
+#include <sys/types.h>
+#include <unistd.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <math.h>
 #include <sys/time.h>
 
@@ -96,7 +101,7 @@ static void memcpy_test(int size)
 }
 
 
-main()
+int main(void)
 {
   int loops = 100000;
   int l;
@@ -147,6 +152,7 @@ main()
     for (i=0;i<l;i++)
       p1[i] = i;
     start_timer();
+
     for (i=0;i<loops/100;i++)
       {
        int j;
@@ -202,4 +208,5 @@ main()
   }
   printf("%g MOPS\n",0.01*(loops*l)/(1.0e6*t));
 
+  return 0;
 }
index 3077cdf2eaa239b0a44cfcc09c680421e94bac8c..739eddb058dc0b753e66be19b8d1d4acb959dc8b 100644 (file)
--- a/tdd/tdd.c
+++ b/tdd/tdd.c
@@ -103,7 +103,7 @@ static void swap_bytes(char *p, int n)
 static int all_zero(const char *buf, size_t count)
 {
        while (count--) {
-               if (*buf != 0) return 0;
+               if (*buf++ != 0) return 0;
        }
        return 1;
 }
@@ -119,7 +119,7 @@ static ssize_t write_sparse(int fd, const void *buf, size_t count)
        if (ftruncate64(fd, ofs) != 0) {
                return -1;
        }
-       llseek(fd, count, SEEK_CUR);
+       llseek(fd, ofs, SEEK_SET);
        return count;
 }
 
index dda8faee5a845dcb7b6e7f8718dd85f7fee8a4d5..cf0ed01727c451276a6d59c41852999f32e1b6af 100644 (file)
@@ -19,6 +19,7 @@ static void usage(void)
 
 static void sig_alrm(int sig)
 {
+       fprintf(stderr, "\nMaximum time expired in timelimit - killing\n");
        kill(0, SIGKILL);
        exit(1);
 }
@@ -32,10 +33,17 @@ int main(int argc, char *argv[])
                exit(1);
        }
 
+#ifdef BSD_SETPGRP
+       if (setpgrp(0,0) == -1) {
+               perror("setpgrp");
+               exit(1);
+       }
+#else
        if (setpgrp() == -1) {
                perror("setpgrp");
                exit(1);
        }
+#endif
 
        maxtime = atoi(argv[1]);
        signal(SIGALRM, sig_alrm);
@@ -43,6 +51,8 @@ int main(int argc, char *argv[])
 
        if (fork() == 0) {
                execvp(argv[2], argv+2);
+               perror(argv[2]);
+               exit(1);
        }
 
        do {
index fce9d964f48cbdc8e29bafe9c34e83848f4d731a..a9d3017f4991c5a7073e37bebe0ea2307cd1e9f8 100644 (file)
@@ -1,34 +1,73 @@
 {{ header.html }}
 
-<form method=POST>
-<table BORDER=0>
-<tr>
-<td COLSPAN="2">
-Please enter the location of the installation archive and a HTTP proxy
-server if you have one
-</td>
-</tr>
-
-<tr>
-<td><b>Archive location:</b></td>
-
-<td><input type=text size=40 name="archive_location"></td>
-</tr>
-
-<tr>
-<td><b>Proxy Server:</b></td>
-
-<td><input type=text size=40 name="proxy_server"></td>
-</tr>
-
-<tr>
- <td>
-  <input type=submit name="action" value="Install">
-  <input type=submit name="action" value="Upgrade">
-  <input type=submit name="action" value="Diagnostics">
- </td>
-</tr>
+<h2>Snapserver Installation Diagnostics</h2>
+
+This page shows some basic hardware information which may be useful in
+diagnosing problems with your Snapserver
+
+
+<h3>The environment</h3>
+<pre>
+{{ ! printenv }}
+</pre>
+
+<h3>PCI Devices</h3>
+
+<small>
+<pre>
+{{ !
+   lspci
+}}
+</pre>
+</small>
+
+<h3>Kernel Version</h3>
+
+<small>
+<pre>
+{{ !
+   cat /proc/version
+}}
+</pre>
+</small>
+
+<h3>Attached Disks</h3>
+
+<table border=1>
+<tr><th>Device</th><th>Model</th><th>Capacity (sectors)</th></tr>
+{{ !
+   cd /proc/ide || exit 1;
+   for d in hd*; do
+cat << EOF
+      <tr align=right>
+      <td>$d</td>
+      <td>`cat $d/model`</td>
+      <td>`cat $d/capacity 2> /dev/null`</td>
+      </tr>
+EOF
+   done
+}}
 </table>
-</form>
 
-{{ footer.html }}
+<h3>Disk Partitions</h3>
+
+<pre>{{ ! cat /proc/partitions }}</pre>
+
+<h3>Network devices</h3>
+
+<pre>
+{{ !
+   ifconfig -a;
+   route -n
+}}
+</pre>
+
+<h3>CPU Info</h3>
+
+<pre>
+{{ !
+   cat /proc/cpuinfo
+}}
+</pre>
+
+{{footer.html}}
index 8a85ed2aba3bad08fa0fc350a34b8f00709e8710..cb97518dd04bf1efdd1f5a1ac10e948f00007aca 100644 (file)
@@ -108,9 +108,8 @@ static void main_loop(int sock1, int sock2)
 {
        unsigned char buf[10240];
        int i=0;
-       struct sockaddr from;
-       socklen_t fromlen = sizeof(from);
-       int connected = 0;
+       static struct sockaddr from;
+       static socklen_t fromlen = sizeof(from);
 
        while (1) {
                fd_set fds;
@@ -128,11 +127,6 @@ static void main_loop(int sock1, int sock2)
                        int n = recvfrom(sock1, buf, sizeof(buf), 0, &from, &fromlen);
                        if (n <= 0) break;
 
-                       if (!connected) {
-                               connect(sock1,&from,sizeof(from));
-                               connected = 1;
-                       }
-
 //                     printf("out %d bytes\n", n);
                        write_all(sock2, buf, n);
                }
@@ -142,7 +136,7 @@ static void main_loop(int sock1, int sock2)
                        if (n <= 0) break;
 
 //                     printf("in %d bytes\n", n);
-                       write_all(sock1, buf, n);
+                       sendto(sock1, buf, n, 0, &from, fromlen);
                }
        }       
 }
index 29115fd02b62d4167b536d0ec290e621dd436095..d582b0ad9ef6c195a6993701d8a6990e9ad55948 100755 (executable)
@@ -103,4 +103,4 @@ EOF
 }}
 
 </body>
-</html>
\ No newline at end of file
+</html>
index e9f0e89c0bdbeb0123f3f4ee288a0cba52d3fd9c..8eb580828ef7e0cf698026f2d4f21a753e64aff0 100644 (file)
@@ -3,11 +3,13 @@
 #include <stdlib.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <time.h>
 #include <sys/time.h>
 
 
 static struct timeval tp1,tp2;
 static size_t block_size = 64 * 1024;
+static int osync;
 
 static void start_timer()
 {
@@ -32,11 +34,11 @@ static void write_file(char *fname)
        buf = malloc(block_size);
 
        if (!buf) {
-               printf("Malloc of %d failed\n", block_size);
+               printf("Malloc of %d failed\n", (int)block_size);
                exit(1);
        }
 
-       fd = open(fname, O_WRONLY|O_SYNC);
+       fd = open(fname, O_WRONLY|(osync?O_SYNC:0));
        if (fd == -1) {
                perror(fname);
                free(buf);
@@ -64,17 +66,18 @@ static void write_file(char *fname)
 
 static void usage(void)
 {
-       printf("
-writefiles - writes to a list of files, showing throughput
-
-Usage: writefiles [options] <files>
-
-Options:
-    -B size        set the block size in bytes
-
-WARNING: writefiles is a destructive test!
-
-");
+       printf("\n" \
+"writefiles - writes to a list of files, showing throughput\n" \
+"\n" \
+"Usage: writefiles [options] <files>\n" \
+"\n" \
+"Options:\n" \
+"    -B size        set the block size in bytes\n" \
+"    -s             sync open\n" \
+"\n" \
+"WARNING: writefiles is a destructive test!\n" \
+"\n" \
+"");
 }
 
 
@@ -85,11 +88,14 @@ int main(int argc, char *argv[])
        extern int optind;
        int c;
 
-       while ((c = getopt(argc, argv, "B:h")) != -1) {
+       while ((c = getopt(argc, argv, "B:hs")) != -1) {
                switch (c) {
                case 'B':
                        block_size = strtol(optarg, NULL, 0);
                        break;
+               case 's':
+                       osync = 1;
+                       break;
                case 'h':
                default:
                        usage();
diff --git a/zfind.c b/zfind.c
index d1810c0077944a10aff4c7de7eb9fe88585599bd..f7375b7b8b8918ea0b9593e7e44966b46e5b2964 100644 (file)
--- a/zfind.c
+++ b/zfind.c
@@ -70,6 +70,20 @@ static void *map_file(const char *fname, size_t *size)
        return p;
 }
 
+static void file_save(const char *fname, const char *p, off_t size)
+{
+       int fd;
+       fd = open(fname, O_CREAT|O_TRUNC|O_WRONLY, 0666);
+       if (fd == -1) {
+               perror(fname);
+               return;
+       }
+       if (write(fd, p, size) != size) {
+               fprintf(stderr, "Failed to save %d bytes to %s\n", (int)size, fname);
+               return;
+       }
+       close(fd);
+}
 
 int main(int argc, const char *argv[])
 {
@@ -99,13 +113,15 @@ int main(int argc, const char *argv[])
                        goto failed;
                }
 
-               while (inflate(&zs, Z_SYNC_FLUSH) == 0 &&
-                      zs.avail_out > 0) ;
+               inflate(&zs, Z_BLOCK);
 
-               if (zs.avail_out != sizeof(outbuf)) {
-                       printf("Inflated %u bytes at offset %u\n", 
-                              sizeof(outbuf)-zs.avail_out, i);
+               if (zs.avail_out != sizeof(outbuf) && sizeof(outbuf)-zs.avail_out > 200) {
+                       printf("Inflated %u bytes at offset %u (consumed %u bytes)\n", 
+                              sizeof(outbuf)-zs.avail_out, i, (size-i) - zs.avail_in);
                        dump_data(0, outbuf, sizeof(outbuf)-zs.avail_out);
+                       if (sizeof(outbuf)-zs.avail_out > 10000) {
+                               file_save("x.dat", outbuf, sizeof(outbuf)-zs.avail_out);
+                       }
                }
 
                inflateEnd(&zs);