Back on track, iPod and OpenBSD meeting

Misc Comments Off

After a vacation week on Olhos de Água, Algarve, I’m back on track. The week was completely off computers and work, being the photos download from the digital camera the only allowed task.

Now I’m in Coimbra, after picking up Marc Balmer at the Lisbon airport for the OpenBSD-PT meeting that will start today.

Bought a 1Gb black iPod nano and I’m using gtkpod for managing it under Linux. It works pretty well till now. I also tryed amarok and its pretty good also.


Humorous comics feeds

Misc Comments Off

Most of my web feeds are on technical issues or from friends that blog about work. That’s ok but sometimes gets really boring. I decided to make reading my feeds more fun and went on search for humorous comics feeds.

Tapestry Comics, a web app built on top of Ruby on Rails, is a directory of web comics with feeds from which I glady pulled out dilbert, Every One Loves Eric Raymond, Sev Wars and Snap-o-Mania for now. They are so many that its difficult to choose :)

I wanted of course a feed for PhD comics and Userfriendly, but couldn’t find any. It’s a pitty, but I understand their bussiness decision, most of these sites earn money from advertisement and page views, a web feed would danger that (or so they seem to think).

If you have more fun stuff let me know. Thanks.

Note: If you don’t know what a ‘feed’ is go to this page and use Bloglines, for example, to track your favorite feeds.


Multiple installations of gcc

Misc Comments Off

Bumped into a problem with multiple gcc installations. I wanted to force the use of gcc-2.95 but I couldn’t use the normal ‘update-alternatives’ script because the package wasn’t being managed by it. I tryed another approach that was to put a copy of the gcc binary I wanted, together with ‘cpp0’ and ‘cc1’, on ~/bin and added it to PATH. I then tryed to compile a minimal C file:

main(){}

But then I was having this error:

ld: crtbegin.o: No such file or directory

GCC searches the PATH for an assembler and a loader, but it only does so after searching a directory list hard-coded in the GCC executables. By issuing ‘gcc –print-search-dirs’ you can check that list. By doing this I found that I needed to include yet another directory and by exporting LIBRARY_PATH to that directory I was able to make it work.

This problem eated most of my day so I hope this saves someone (or me next time) some time.

Note: If after this you have problems with the headers you may need to pass to gcc in the compilation command the directory of the headers you want with the option -I<dir>.


Test Driven Development in C

Misc Comments Off

Since part of my Msc work in being written in C I went digging for Test Driven Development in C. The guys at Object Mentor published an article on this very same topic in Octorer 2002 C/C++ Users Journal. They’ve arranjed a neat scheme for emulating a full testing framework in C.


Linux clone(2) syscall

Misc Comments Off

I’ve been trying out Linux clone(2). What follows is a small example I’ve assembled.

From the man page, “the main use of clone is to implement threads: multiple threads of control in a program that run concurrently in a shared memory space”. Also have in mind clone(2) is Linux-specific.

One example of a real-usage is this short program I wrote for running several prolog engines at the same time.

This is the main file:

cfs.c

#include <stdio.h>
#include <sched.h>

#include <gprolog/gprolog.h>

my_pred() {
  FILE *fd = fopen("./teste", "w");
  fwrite("ola", 1, sizeof("ola"), fd);
  fclose(fd);
  return TRUE;
}

thread() {
  int retval;
  Start_Prolog(0, 0);   /* start prolog engine */
  _exit(0);
}

main() {
  void **child_stack;
  child_stack = (void **) malloc(65536);
  clone(thread, child_stack, CLONE_VM|CLONE_FILES, NULL);
}

In the main routine I just create one process with clone(2) but one could create as many as we would like of course. Unlike fork(2), clone allow the child process to share parts of its execution context with the calling process, such as the memory space, the table of file descriptors, and the table of signal handlers. On this example I choosed to share the file descriptor table with the option CLONE_FILES. The CLONE_VM option will make the calling process and the child process run in the same memory space. This is good to make communication happen between the processes we will create and use.

The child process will begin by executing the function called ‘thread’ in this program. The ‘child_stack’ argument specifies the location of the stack used by the child process. Since the child and calling process may share memory, it is not possible for the child process to execute in the same stack as the calling process.

In the Makefile make sure to link with gprolog libraries. This is the Makefile I used:

Makefile

PLL=/usr/lib/gprolog-iso
LIBS=

all: cfs

cfs.o: cfs.c
	gplc -c cfs.c

%.o: %.pl
	gplc -c $+

cfs: cfs.o prolog.o
	gcc -static -ggdb -Wall -o cfs  \
	 $(PLL)/obj_begin.o 	\
	 $+			\
	 -L$(PLL)		\
	 -lbips_fd		\
	-lengine_fd		\
	 -lbips_pl		\
	 $(PLL)/obj_end.o $(LIBS) -lengine_pl -llinedit -lm

clean:
	rm -f *.o *~ cfs

And the prolog source code I tested this example with:

prolog.pl

:- foreign(my_pred, [fct_name(my_pred)]).
:- initialization(my_pred).

The ‘foreign’ call in prolog declares that a C function with that name exists.

This short example shows how to use clone(2) to create a multi-process program with gprolog. You could of course use it for creating processes that would run anykind of program in Linux.


5 minutes

Uncategorized Comments Off

What if you had only 5 minutes to post a blog entry? What would you write? How many errors would you make? What would you talk about? Life? Tech? Threads? :-)

Portugal won against England: Incredible shit by Ricardo on defending those penalties and by Ricardo Carvalho on defense.

I wanted to write something about the reasons on why buddishm continues to attract so many people but the time is out.. maybe next time.

OpenBSD .PT Meeting

Misc Comments Off

Next July 22 and 23 OpenBSD .PT will be holding its 6th meeting in Coimbra. It’s fantastic how I’ve started this group and it has envolved into something much bigger than I and my ambition to be a
hacker.

Last meeting we had developer Pedro Martelletto joining us and this time its Marc Balmer (covered in Kerneltrap) that will be comming all the way from Basel, Switzerland. I first meet Marc in WTH and if you know him you certainly agree he is a great guy. There will be technical presentations and general slacking. Everyone is welcome to come.

http://www.openbsd-pt.com/eventos/coimbra06/

Grandmother

Misc Comments Off

It’s been a while since I’ve write anything here. A lot has happen since my last post, most significantly my grandmother passed away.

About a year ago, she and my grandfather were preparing to leave to Lisbon for a few weeks. As they were leaving the house, she suddenly lost strength in her legs and fell to the ground. She never walked again since.

She had a treatment for a cancer twenty years ago but it got worse and caused pressure on the medula that didn’t allow the commands from the brain to go through anymore. She did a whole year and a few weeks without leaving the bed, depending on the good faith and love of family, friends and doctors, prior to succumbing to the illness. Her last hours were of agony and pain.

But life isn’t about your last year is it? Everyone who have seen my grandparents together knows they were pretty close. I’m know they lived great moments of happiness and had a wonderful life trip together.

Inevitably, death brings back that life is temporary. Something we know but tend to ignore most of the time. As for me, I tryed as much as I could to be like a lotus flower - in the water but yet untouched by it. Right or wrong, the choice was mine and I take full responsability for it.

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in