Code Snipplets
reading multiple eventinterfaces with select
/*
sample by Eric Weiss eric@eric-weiss.de
*/
#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/input.h>
int
main(void) {
fd_set rfds;
struct timeval tv;
int retval;
struct input_event evt;
struct input_event evt1;
int file,file1;
int a;
/* Watch stdin (fd 0) to see when it has input. */
file=open("/dev/input/event7",O_NONBLOCK +O_ASYNC+O_RDONLY);
file1=open("/dev/input/event1",O_NONBLOCK +O_ASYNC+O_RDONLY);
printf( "fds %i , %i \n",file,file1);
/* Wait up to five seconds. */
while(1)
{
tv.tv_sec = 1;
tv.tv_usec = 0;
FD_ZERO(&rfds);
FD_SET(file, &rfds);
FD_SET(file1, &rfds);
retval = select(5, &rfds, NULL, NULL, &tv);
printf("retval %i\n",retval);
if( FD_ISSET(file, &rfds))
{
read(file,&evt, sizeof(struct input_event));
printf("event: %i %i %i %i\n", evt.code,evt.value,evt.type,retval);
}
if( FD_ISSET(file1, &rfds))
{
read(file1,&evt1, sizeof(struct input_event));
printf("event1: %i %i %i %i\n", evt1.code,evt1.value,evt1.type,retval);
}
if ( evt.type == EV_KEY)
{
printf ("%i %i %i\n",evt.type,evt.value,evt.code);
}
}
/* Don't rely on the value of tv now! */
if (retval == -1)
perror("select()");
else if (retval)
printf("Data is available now.\n");
/* FD_ISSET(0, &rfds) will be true. */
else
printf("No data within five seconds.\n");
return 0;
}
Virtualbox Networking
/etc/network/interfaces
auto br0 iface br0 inet static address 172.16.0.1 netmask 255.255.255.0 broadcast 172.16.0.255 bridge_ports vbox0 vbox1 vbox2 post-up VBoxAddIF vbox1 ew br0 post-up VBoxAddIF vbox2 ew br0
~./Virtualbox/bridge_setup
#!/bin/sh
set -e
BRIDGE="br0"
case "${1}" in
"up" )
# Get the last vbox interface that was created or "" if none
TAP=$(cat /proc/net/dev | grep vbox | tail -n 1 | cut -d":" -f1 | sed 's/\s*vbox\(\.*\)/\1/')
# If there was no previous interface then set to -1 (this is sothe += works)
[ "${TAP}" = "" ] && TAP=-1
# Increment TAP
let "TAP+=1"
# prepend vbox onto the TAP no
TAP="vbox${TAP}"
# Create the new TAP device
sudo VBoxTunctl -b -u $(whoami) -t ${TAP}
# Bring up the TAP (without an ip)
sudo ifconfig ${TAP} up
# Add the TAP to the Bridge
sudo brctl addif ${BRIDGE} ${TAP}
# Echo the name of the TAP so VirtualBox knows which one to use
# on lenny the echo must be commented for virtuabox to work correctly
echo ${TAP}
;;
"down" )
# VirtualBox tells us which TAP it used
TAP=${3}
# Bring the TAP down
sudo ifconfig ${TAP} down
# Remove the TAP
sudo VBoxTunctl -d ${TAP} > /dev/null 2>&1
;;
esac
Bacula
shitty SQL_ACII <> UTF-8 problem
psql -U bacula --password -h localhost postgres alter database bacula rename to baculaold; pg_dump -h localhost -U bacula baculaold > bacula.sql createdb -E SQL_ASCII -O bacula bacula -T template0 psql -U bacula --password -h localhost postgres < bacula.sql
create initrd
find . | cpio --create --format='newc' | gzip > /tmp/newinitrd
