#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;
}
out[i] = b64[idx];
}
+
+ for (;i<bytes+pad_bytes;i++)
+ out[i] = '=';
+ out[i] = 0;
+
+ return out;
}
{
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;
}
#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)
{
#include <sys/wait.h>
#include <errno.h>
-
static void run_child(int epoll_fd)
{
struct epoll_event event;
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;
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++) {
#include <stdio.h>
#include <mntent.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
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);
{
- counts[$1]++;
+ counts[$0]++;
total++;
}
-CFLAGS=-Wall -O2 -g -I/usr/src/linux/include
+CFLAGS=-Wall -O2 -I/usr/src/linux/include
all: idtree
} 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);
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;
}
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) {
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];
}
}
}
- if (read(fd, &c, 1) != 1) {
+ if (next_char(fd, &c) != 1) {
return len;
}
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"
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;
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;
pause();
printf("Got event on fd=%d\n", event_fd);
}
+
+ return 0;
}
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);
}
const char *magic_script;
char *s = NULL;
magic_script = getenv("MAGIC_SCRIPT");
-
+
+ unlink("xxx.dat");
+
if (!magic_script) {
return;
}
ret = real_open(pathname, flags, mode);
+ do_magic(pathname);
+
if (ret == -1 && errno == ENOENT) {
do_magic(pathname);
ret = real_open(pathname, flags, mode);
ret = real_open(pathname, flags, mode);
+ do_magic(pathname);
+
if (ret == -1 && errno == ENOENT) {
do_magic(pathname);
ret = real_open(pathname, flags, mode);
}
}
+ printf("tid %d done\n", tid);
+
return NULL;
}
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) {
# 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)
#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);
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),
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[])
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.*
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);
void _init(void)
{
signal(SIGSEGV, segv_handler);
+ signal(SIGBUS, segv_handler);
}
-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)
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));
}
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) {
}
}
+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;
exit(1);
}
+ printf("Connection from %s\n", get_socket_addr(sock_in));
+
close(listen_fd);
sock_out = open_socket_out(host, dest_port);
{
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 {
}
if (lroot == NULL) {
- lroot = getenv("LROOT");
+ lroot = getenv_orig("LROOT");
}
if (lroot == NULL) {
lroot = "/opt/softroot";
if (!fopen_orig) {
fopen_orig = dlsym(RTLD_NEXT, "fopen");
+
}
ret = fopen_orig(redirect_name(filename), mode);
+#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>
}
-main()
+int main(void)
{
int loops = 100000;
int l;
for (i=0;i<l;i++)
p1[i] = i;
start_timer();
+
for (i=0;i<loops/100;i++)
{
int j;
}
printf("%g MOPS\n",0.01*(loops*l)/(1.0e6*t));
+ return 0;
}
static int all_zero(const char *buf, size_t count)
{
while (count--) {
- if (*buf != 0) return 0;
+ if (*buf++ != 0) return 0;
}
return 1;
}
if (ftruncate64(fd, ofs) != 0) {
return -1;
}
- llseek(fd, count, SEEK_CUR);
+ llseek(fd, ofs, SEEK_SET);
return count;
}
static void sig_alrm(int sig)
{
+ fprintf(stderr, "\nMaximum time expired in timelimit - killing\n");
kill(0, SIGKILL);
exit(1);
}
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);
if (fork() == 0) {
execvp(argv[2], argv+2);
+ perror(argv[2]);
+ exit(1);
}
do {
{{ 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}}
{
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;
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);
}
if (n <= 0) break;
// printf("in %d bytes\n", n);
- write_all(sock1, buf, n);
+ sendto(sock1, buf, n, 0, &from, fromlen);
}
}
}
}}
</body>
-</html>
\ No newline at end of file
+</html>
#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()
{
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);
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" \
+"");
}
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();
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[])
{
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);