12/04/2009
For those who actually read my blog and/or interested (are there any? :P).
You can now follow me on Twitter: twitter://adamhoka
10/31/2009
Bootstraping pkgsrc with pcc
cd /usr/pkgsrc/bootstrap
env CC=pcc ./bootstrap --prefix /usr/pccpkg --varbase /usr/pccpkg/var --pkgdbdir /usr/pccpkg/.pkgdb --compiler pcc
...wait a few minutes...
echo CC=pcc >> /usr/pccpkg/etc/mk.conf
Thats it, start using with /usr/pccpkg/bin/bmake and report any compiler bugs to PCC!
8/04/2009
Make Firefox faster in less time
It's just a simple for loop in shell. But can we do it faster? Of course, we can make it parallel, so it's finishing much sooner!
The script needs ksh, you can install pdksh or mksh, but other versions should work too.
Enjoy!
#!/bin/ksh
#
# Parallel vacuum for Firefox
# Adam Hoka, 2009
set -A pid
npid=0
for i in $HOME/.mozilla/firefox/*/*.sqlite
do
print 'VACUUM;' | sqlite3 "$i" &
pid[$npid]=$!
((npid++))
done
if [[ $npid -eq 0 ]]
then
exit 1
fi
n=0
while [[ $npid -gt $n ]]
do
wait ${pid[$n]}
((n++))
done
4/13/2009
LVM Volume Manager on NetBSD
Let’s see how to use NetBSD’s newborn volume manager. It’s sharing much with Linux LVM, so it may be very familiar. You will need NetBSD current (I’m using 5.99.10) and sources.
# cd /usr/src/external/gpl2/lvm2/
# USETOOLS=no MKLVM=yes make
# USETOOLS=no MKLVM=yes make install
# USETOOLS=no MKLVM=yes make clean
# cd /usr/src/sys/modules/dm/
# USETOOLS=no MKLVM=yes make
# USETOOLS=no MKLVM=yes make install
# USETOOLS=no MKLVM=yes make clean
Let’s load it:
# modload dm
# modstat | grep dm
dm driver filesys 0 18364 -
# lvm pvcreate /dev/rwd1d /dev/rwd2d
Physical volume "/dev/rwd1d" successfully created
Physical volume "/dev/rwd2d" successfully created
# lvm vgcreate volumes /dev/rwd1d /dev/rwd2d
Volume group "volumes" successfully created
# lvm lvcreate -n vol0 -L 400M volumes
Logical volume "vol0" created
# lvm lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
vol0 volumes -wi-a- 400.00M
# newfs -O 2 -F -s 400M /dev/volumes/rvol0
/dev/volumes/rvol0: 400.0MB (819200 sectors) block size 8192, fragment size 1024
using 9 cylinder groups of 44.45MB, 5689 blks, 10720 inodes.
super-block backups (for fsck_ffs -b #) at:
144, 91168, 182192, 273216, 364240, 455264, 546288, 637312, 728336,
# mount /dev/volumes/vol0 /mnt
# mount
/dev/wd0a on / type ffs (log, local)
kernfs on /kern type kernfs (local)
ptyfs on /dev/pts type ptyfs (local)
procfs on /proc type procfs (local)
/dev/mapper/volumes-vol0 on /mnt type ffs (local)
11/15/2008
How to compile PCC?
As it's still in an early stage of developement, obtaining a copy is recommended from the project's CVS.
First, check out the source tree:
$ cvs -d :pserver:anonymous@pcc.ludd.ltu.se:/cvsroot co pcc
After that, we can build it using autoconf:
$ cd pcc
$ ./configure --prefix=/opt/pcc
$ make
$ make install
Now we should have an /opt/pcc/bin/pcc binary, so we can start playing:
$ pcc -v
pcc 0.9.9 for i386--netbsdelf, replaced@grimnismal.regius.local Sat Nov 15 22:54:49 CET 2008
no input files
11/04/2008
A basic proplib example
Proplib is an API/lib to create, handle and store property lists.
It was created by Apple but NetBSD also have a clean room implementation in the system, and it's mostly used for implementing sysctl interfaces. It's a somehow limited implementation to make it faster/smaller (maybe extended in the future as demands grow).
Here's a little example code to show some of the basics:
This will create a dictionary and store it as an xml file on the disk:
int
main()
{
prop_dictionary_t d;
bool r;
d = prop_dictionary_create();
if (d == NULL)
goto error;
r = prop_dictionary_set_cstring(d, "name", "Adam");
if (!r)
goto error;
r = prop_dictionary_set_uint32(d, "year", 1986);
if (!r)
goto error;
r = prop_dictionary_externalize_to_file(d, "test.plist");
if (!r)
goto error;
return EXIT_SUCCESS;
error :
fprintf(stderr, "error\n");
return EXIT_FAILURE;
}
And this will read it and display the values:
int
main()
{
prop_dictionary_t d;
uint32_t year;
char *name;
bool r;
d = prop_dictionary_internalize_from_file("test.plist");
if (d == NULL)
goto error;
r = prop_dictionary_get_cstring(d, "name", &name);
if (!r)
goto error;
r = prop_dictionary_get_uint32(d, "year", &year);
if (!r)
goto error;
printf("name: %s, year: %u\n", name, year);
return EXIT_SUCCESS;
error :
fprintf(stderr, "error\n");
return EXIT_FAILURE;
}
You will need to include prop/proplib.h or a similar header file depending on the implementation you use.
Setting the default uid in gpg
gpg --edit-key adam.hoka
you see something like this now:
Command>
type list and lookup the number next to the ID you want to use as a default and enter it.
Example:
Command> 2
It will list the IDs again (note the asterisk next to the selected ID).
Type primary and then save.
Done.