Sunday, May 22, 2011

Problem No. 1: Building MANPATH

I am starting a series of posts to discuss about the interesting problems that I will be facing in my project and my views on how to solve them. For those who don't know about my project for GSoC 2011 for NetBSD please see my project page [1].

The very Ist problem that I need to solve is finding the MANPATH. MANPATH is an environment variable which tells us the directories where man pages are stored. I need it because the very first thing my project needs to do is to parse all the man pages and build an index, but it won't be possible unless it knows the different directories where man pages might be stored.

Very often is the case that MANPATH is not defined in the system. In such scenario I need to fallback on a mechanism which will build the manpath for me. Following is the strategy that I have thought for solving this:

Following is the strategy that I have thought of implementing:

makewhatis: Will be responsible for constructing the database from scratch, parsing each man page using libmandoc. For this it will need to know the locations of the man pages. I propose using /etc/apropos.conf as the default place to look for the manpath.

/etc/apropos.conf: For now, I believe it should store the path where man pages are stored. It might contain other information in future.

manpathbuilder: In case /etc/apropos.conf does not contain a definition for manpath or it has been removed, makewhatis will call manpathbuilder. It will build the manpath by parsing information from /etc/man.conf. Once the manpath is built it will be stored in /etc/apropos.conf and control returned to makewhatis which can recheck /etc/apropos.conf (or maybe manpathbuilder return the manpath to makewhatis directly ?)

Why /etc/apropos.conf ? Well it takes some time to build the path containing all possible directories (/usr/share/man/man1, /usr/share/man/man2, ... , /usr/X11R7/man/man1, ... , etc) and the current code of manpathbuilder is also not very efficient, so it makes sense that once we have built the manpath we make it persistent for future uses and only redo the work when it is actually needed.

I have written most of the code for manpathbuilder, although it is highly inefficient from memory or runtime point of view, but it seems to work. I will improve it as I get some more time (struggling with exams at the moment).

UPDATE: I discussed with Joerg about the outline I have drafted above. We reached to a better alternative. He suggested that rather than writing an additional utility manpathbuilder and an extra config file (/etc/apropos.conf), we could add a new option to man(1) by patching it. This will provide us the complete manpath and also will serve as an easy point of access to let the end user to see if anything is wrong with the path. 

So in the coming days, I will be working on patching man(1) to add a new option which will give the list of directories where man pages are stored (like /usr/share/man/man1:/usr/share/man/man2,...) 

The simplified outline


No comments:

Post a Comment