May 15, 2008

Philip Paeps (philip) [stats, website]

Devsummit day 1

21:14 EDT

Registration at the Royal Oak last night was fun again. It seems most people managed to fight their way through the Canadian border scrutiny again. As usual, a number of people got stuck in Chicago. ORD almost makes LHR looks good... Almost.

We left the Royal Oak rather earlyish for the hacking lounge. I think I got a number of people somewhat interested in my effort to "architect" syscons. It is going to hurt but it really needs doing. The best description I've come up with for the current state of affairs is "four-dimensional noodles on bad acid". The term layering violation does not even begin to describe it.

Got a bit of code-reading done and then headed upstairs at a fairly civilized hour. My roommates (plural, Tiff seems to have moved in -- cool) were in a somewhat confused state when I got there. It transpires that George was double booked in our room, and a number of other rooms before that and was a bit 'hostile' after the manyeth elevator ride. Confused accomodation receptionists are a required feature at geek conferences.

Started a bit grumpy this morning. I found that carrot at home had crashed. Funny how this sort of thing always happens when there's an ocean separating me from any reasonable debugging interface. A smiling face suggesting coffee and breakfast improved my mood considerably. Thanks, miss!

I appear to have come to terms with the local currency. The locals have not come to terms with my breakfast requirements, however. They are surprisingly resistant to giving me something "random and tasty". I asked for a muffin and the girl asked me which one, when I asked her to give me the one which would give her the most pleasure to part with, she looked a bit confused and suggested about four different kinds, when I then said "yes", she got even more confused. sigh.

The devsummit was off to a good start. Except for the fact that there is no wireless. This is also a conference constant, however, so it didn't bother me much. In fact, the lack of wireless probably boosted the productivity.

Met Ed Schouten who is working on rewriting the TTY layer. This ties in rather nicely with my ideas about syscons. I look forward to working with him some more on this. Tomorrow I am organizing a syscons bof. I hope to get this project off the ground at last.

Highlight of the devsummit was the "greenbsd bof". Poul-Henning and Diane disagreed a bit about how to measure power going through switch-mode power supplies. Everyone agrees that we should come up with ways to save power intelligently and that implementations in other operating systems are suboptimal. This will probably become more interesting over the next few months. I look forward to doing some more power-management work again. It's been a while.

Thai food at the hacking lounge. Yum yum. I need to try to find Peter to figure out where my ISC tshirt went and catch up with email. I'm also cooking up an if_bridge patch for Andrew to look over while we're on the same continent. Feeling productive.

Posted: Thu, 15 May 2008 02:14:00 +0000


May 14, 2008

Murray Stokely (murray) [stats, website]

finstall alpha4 review


finstall is Ivan Voras's installer project for FreeBSD. His goal is to create a more user friendly, extensible, and maintainable replacement for the venerable sysinstall program. Replacing sysinstall is something that has been near and dear to my heart since I was first granted a commit bit to work on sysinstall over 8 years ago.

In the past decade a number of projects (libh, anyone?) have been initiated with the goal of replacing sysinstall and none have succeeded. Ivan began his 2007 Summer of Code project with a survey of the existing BSD/Linux installer landscape and his finstall project aims to provide functionality not possible with the alternatives while avoiding some of the pitfalls.

Today Ivan gave a presentation about finstall at the FreeBSD Developer Summit preceding BSDCan but work is keeping me in San Francisco until Friday. Since I'm missing the in person discussions about finstall and FreeBSD 8.0 I thought I'd at least download the latest ISO and publish my findings here. The latest code for finstall is available on SourceForge but Ivan also provides ISO images on his blog.

The first thing you'll notice is that the installer is LiveCD based. Sysinstall was traditionally installed from boot floppy disks or as floppy images on El-Torrito bootable CDs. This led to the use of crunchgen(1) and other techniques for keeping the size of the installation environment within the confines of 1.44MB disks.

Freed from this anachronism, finstall boots into FreeBSD 7.0 and provides a login prompt where users can login as root to use the disk as a LiveCD / recovery CD, or as install to complete an installation onto local disk.

Immediately after logging in as install, the user is prompted to choose a keymap and timezone using the same text libdialog(3) based tools that sysinstall users are familiar with. There is no back button if you accidentally choose the wrong keymap, and no easy way to intuitively scroll through the long list of options in each menu. Thankfully, these are the only two parts of the system that still rely on libdialog(3).

After the timezone is selected, X Windows starts up and the user is dropped into an XFce desktop with a 'FreeBSD Install' icon. Selecting this icon launches the graphical installer. Only the novice (minimum interaction) menu item is available, but standard and advanced modes which allow for RAID configuration are being worked on.

The novice installation process sets up a default partition layout based on the available space on the drive selected by the user, without allowing the user to change the partitions in any way. On my 4 GB VMWare image it chose 512MB /, 409MB /var, 256MB swap, 2048MB /usr, and 865MB /home. The user is then given a choice of file systems to use (UFS+SU, UFS+GJ, ZFS, ext2). finstall refuses to install on a disk with less than 2.3GB of space. This seems excessive until you realize that the current version isn't going to give you the option of pruning down the installed package set -- everything on the ISO will be installed.

After file system selection, the installation begins with the format/partitioning of the disk, installation of the base system, and installation of all the packages on the LiveCD. During installation a number of helpful system tips are provided to the user beneath the status bar ("BSD stands for ...", pointers to the FreeBSD Handbook, etc..)

After installation is completed the user is asked to enter a root password, create a user account, setup network interfaces, and enable system daemons. These configuration menus are pretty standard but are much more user friendly than the sysinstall equivalents.

After installation, the user is left at the XFce desktop. It would probably be more useful at this point to actually reboot into the newly installed system. Perhaps the last message of the installer could say something like "Click here to reboot into your new FreeBSD 7.0 system."

This post is far longer than I expected so I'll end here, and follow up tomorrow with some specific suggestions that I'd like to see added to finstall. In the mean time, by all means check out the code on SourceForge and send Ivan your patches.

Posted: Wed, 14 May 2008 23:59:25 +0000
Tags: bsdcan, crunchgen, devsummit, finstall, ivan voras, sourceforge, summer of code, sysinstall, xfce


Summer of Code Students in Community Bonding Period


We're over halfway through the community bonding period and in less than 2 weeks it will be time for our Summer of Code students to start coding.

At this point we've created Perforce accounts for our students and over half of them have already started submitting to their project directory. Ten of our students have started wikis about their projects over on wiki.FreeBSD.org and 8 students have setup blogs which are now aggregated on Planet FreeBSD SoC 2008. Many students sent introduction emails to the freebsd-hackers list over the last 3 weeks.

We ended up getting one extra student in the final allocation for a total of 21 Summer of Code students this year. Two of our students are previous summer of code participants (Gábor Kövesdán from SoC 2006, and 2007 and Rui Paulo from SoC 2007). We also have a former student, Attilio Rao (SoC 2007), serving as a mentor this year.

The graphs in this post present a breakdown of the current country of residence/study for the FreeBSD Summer of Code students that have shared this information. The countries with the most participating students are represented by darker shades of red on the world map above. The statistics for the entire Google Summer of Code program are available here. If you haven't already, please take a moment to send a welcome mail to our students in response to one of the introductions on hackers@ or use the forums above to get in contact with any students working in areas you are particularly interested in.

Update 3/14/2008 - We have a student from Portugal who was misclassified on the original graphs.

Posted: Wed, 14 May 2008 20:23:18 +0000
Tags: attilio rao, gabor kovesdan, google, perforce, planet, rui paulo, summer of code, wiki

[ FreeBSD News ]

January - March, 2008 Status Reports

The January - March, 2008 Status Reports are now available with 13 entries.

Posted: Wed, 14 May 2008 09:00:00 +0000


Edwin Groothuis (edwin) [stats, website]

FreeBSD IPv6 Divert socket adventures (3)

Victory! Tonight I managed to get the nat6to4 daemon working. Remember what went wrong yesterday:

IPv6 packet does not go from the nat6to4 daemon into divert. What?!?!?
Yes, that would have worked in one go if I actually had pushed the data in the right IPv6 socket instead of in the wrong IPv4 socket. It happens, specially when you are copying whole functions around.

As a demo:

[~] edwin@freefall>telnet 2001:5c0:8fff:ffff::c3 80
Trying 2001:5c0:8fff:ffff::c3...
Connected to 2001:5c0:8fff:ffff::c3.
Escape character is '^]'.
HEAD / HTTP/1.0 HTTP/1.1 200 OK
Content-Type: text/xml; charset="utf-8"
Date: Tue, 13 May 2008 14:10:23 GMT
Expires: Thu, 26 Oct 1995 00:00:00 GMT
Last-Modified: Tue, 13 May 2008 14:10:23 GMT
Pragma: no-cache
Content-Length: 32
Server: Allegro-Software-RomPager/4.34 Connection closed by foreign host.
That is pretty uninteresting for the naked eye, but the thing is that the Allegro-Software-RomPager doesn't support IPv6, it's mapped via the nat6to4 gateway.

So, my nat6to4 daemon works for mapping the TCP or UDP payload of basic IPv6 packets (single header, nothing fancy) onto IPv4 packets: Now I can make all basic services on my jails (webservers, LDAP servers, DNS servers, POP and IMAP servers) available via IPv6.

Now I have to put netinet6/ip6_divert.c into a shape so that it gets accepted by the FreeBSD project, right now there are too many things commented out because I didn't know what they are for. Yes, I feel like an apprentice magician left alone with a hand full of scrolls and asked to find out if they are interesting.

Patches for FreeBSD 6.3 are available from http://people.freebsd.org/~edwin/freebsd63-ip6divert-20080513.patch.
The nat6to4d is available from http://people.freebsd.org/~edwin/nat6to4d-20080513.c.
And the ipfw rules:

01005 606 245695 divert 8664 ip from any to 192.168.253.2
01006 452 33304 allow ipv6-icmp from any to me6 via tun1
01006 517 51742 divert 8666 ip6 from any to me6 via tun1
65535 79349 20349420 allow ip from any to any

Posted: Wed, 14 May 2008 00:00:00 +0000


May 13, 2008

Vincenzo Iozzo (snagg) [stats, website]

Some news

I’ve just finished to upload the code onto my perforce branch. At the moment the whole code is ready for testing, which means that, now, should be possibile to audit events one-by-one. Specifically I’ve added some functionalities to audit_pipe_ioctl which allow to do the same operation done before but on events list instead of audit classes. Also all the functions needed to manage the events list were made up. The audit_pipe_preselect structure was modified, adding a pid field and a dynamic array of structs which hold the events’ list.  The KPI now has two new prototype for audit_pipe_preselect and audit_pipe_submit in order to allow event matching by pid. As soon as the testing period is finished maybe new features will be added. All the code could be found on my perforce branch. I’d really appreciate if anyone willing to help will test the code and give me some feedback. Also please note that the whole code is in a really alpha-stage.That’s all folks,Snagg 

Posted: Tue, 13 May 2008 00:59:56 +0000
Tags: project
Comments


May 12, 2008

Remko Lodder (remko) [stats, website]

Just back from Tunisia , flying out to Canada

So, I just returned from Tunesia with Denise and we both will be flying out to Canada within 2 days to visit BSDCan. We will be joining Ed Schouten (mpsafetty, facilitated by Snow BV) and Poul-Henning Kamp and Robert Watson in the plane towards Canada. Denise, Ed and myself will be flying under the Snow BV waiver, to show a bit of presence there :-)

Ed will also be doing a talk, and I am sure that will go just fine.

BSDCan updates to follow when possible :)

Posted: Mon, 12 May 2008 13:22:56 +0000
Tags: freebsd, news
Comments


Edwin Groothuis (edwin) [stats, website]

FreeBSD IPv6 Divert socket adventures (2)

A small update:

  • Dr. Goto has replied. It seems that I contacted him at the beginning on the Golden Week, a week in Japan with a lot of free days so that was the reason it took longer. His patches are against 5.2.1 and applied without problems but didn't compile. But it gave me some good hints.
  • Three kernel panics later I was told by Bruce M Simpson to use Qemu for kernel development work. Two days later I have it up and running. Works nice, I have it booting via PXE and the disks are mounted via NFS. I can boot in several FreeBSD versions but not into 5.2.1 because it hangs just before starting the userland. So far for my reference platform...
  • I have copied sys/src/netinet/ip_divert.c to sys/src/netinet/ip6_divert.c and modified all IPv4 functions into their IPv6 equivalents. Also added IP_PROTO_SPACERS to in6_proto.h. And finally when I open a socket with PF_INET6 and SOCK_RAW and IPPROTO_DIVERT, I get a proper socket:
    nat6to4d 2578 root 3u IPv6 0xc1df8ec4 0t0 DIVERT *:8666
    nat6to4d 2578 root 4u IPv4 0xc1dfaec4 0t0 DIVERT *:8664
    sockstat still doesn't show it though...
  • Internally in ip6_divert.c, instead of abusing the sin_zero[] fields in struct sockaddr_in I have created the new sockaddr type struct sockaddr_div:
    struct sockaddr_div { uint8_t div_len; sa_family_t div_family; /* AF_INET / AF_INET6 */ in_port_t div_cookie; /* was: sin_port */ char div_iface[8]; struct in6_addr div6_addr; /* IPv6 address */ struct in_addr div4_addr; /* IPv4 address */
    };
    This could / should be also used in the normal ip_divert code.

So what works and what doesn't?

  • IPv6 packet goes from divert to the nat6to4 daemon. Yay!
    (TCP SYN packet from IPv6 host to the IPv6 address of the machine with the nat6to4 daemon)
  • IPv4 packet goes from the nat6to4 daemon to divert. Yay!
    (TCP SYN packet from the IPv4 address of the machine with the nat6to4 daemon to the IPv4 host. Trivia: Why do you need to recalculate the TCP checksum when you haven't changed the TCP header and TCP payload?)
  • IPv4 packet goes from divert to the nat6to4 daemon. Yay!
    (TCP SYN-ACK packet from IPv4 host to the IPv4 address of the machine with the nat6to4 daemon)
  • IPv6 packet does not go from the nat6to4 daemon into divert. What?!?!?
I'm not sure what goes wrong here: sendto() says that it is accepted, but the packet is expected to end up on the div6_send() function but it doesn't end up there. For some reason. Which is kind of annoying. Robert Watson suggested to check the GDB debugger what happens in the sendto() call.

But that is an adventure for later when I have some spare time again... work and two kids, that doesn't leave much time adventures like this (except between 22:00 and 01:00 which is very bad for everybody)

Posted: Mon, 12 May 2008 11:00:00 +0000


May 11, 2008

[ FreeBSD Upcoming Events ]

LinuxTag 2008

LinuxTag 2008 (http://www.linuxtag.org/2008/en/), Messe Berlin, Berlin, Germany 28 - 31 May, 2008. LinuxTag is Europe's largest event about Free Software, Linux and Open Source. This year there will be the traditional FreeBSD booth and several BSD talks. It will also be possible to take the BSDA certification exam there on Friday May 30.

Posted: Sun, 11 May 2008 06:55:11 +0000


9th Libre Software Meeting

9th Libre Software Meeting (http://2008.rmll.info/?lang=en), Multiple Locations, Mont-de-Marsan, France 1 - 5 July, 2008. The Libre Software Meeting has occurred each year since July 2000. This year there will again be a FreeBSD boot camp to introduce new users to the Operating System.

Posted: Sun, 11 May 2008 06:55:11 +0000

May 9, 2008

James Harrison (jamesh) [stats, website]

oscartheduck


I’m on my way out right now, but I’m going to write up a script tonight called code2pdf, and wanted to write down the history of it before it leaves my head.

I have been taking a CS class this semester, and have been writing code as a consequence. The requirements for submitting this code are twofold:

1. pop all code and a scriptfile proving the code works on a USB stick

2. print out copies of all code and the scriptfile and submit with above.

Now, most of the folks are using some kind of windows kludge to write their code, so they were taking screenshots of command windows and handing that in as a script file. I just used script, because I figured that’s what it’s there for. The problems were twofold:

1. I don’t have a printer in my house.

2. The printers at school are all connected to windows boxes.

So when I come in with a nice raw text file and attempt to print it, it looks _awful_. Same goes for code; my text files looked horrible.

But my instructor is a unix geek, so she didn’t mind at first. However, the driver being used to run the printer has a quirk in it; it has its own definition of what a tab is. I couldn’t believe it; my nice sensible “two spaces to a tab” code was running and running and running over line after line of blank space. Which didn’t worry me, but it made trying to read the code a horrible task for the instructor. True to her form, she mildly pointed this out to me and asked me to work on the issue, no fuss just a pleasant request. Which is the best way to get results.

So, I started thinking about it. First things first, I stopped using tabs and started using spaces. The printouts looked a lot better from that alone.

But I decided not to stop there; my instructor had been polite, and I have the power of FreeBSD available. I installed OpenOffice from the port (which took ages), after which my hard drive killed itself. So I installed anew and installed OpenOffice again, which took forever again. And I copied my code into OpenOffice and output it as a .pdf.

.pdf rules. I format things nicely, go through the file and make sure everything’s pretty and I’m happy as a clam at high tide. The script file was more difficult than the code, funnily enough, as openoffice is smart enough to read the .txt extension, scan the interior and then kindly offer to format everything as a spreadsheet.

Remove the extension and open the file again, and a different preprocessor asks for advice. I told it to use luxi mono as the font, and everything looks pretty. From there to .pdf is as simple as using the filter.

But why stop there? With the ports system at my fingertips, I can do anything! And I don’t want to start up openoffice just to spew out a .pdf file, more importantly. After a couple of creative searches, I found  a beautiful program called highlight, which takes code in and spews out one of several forms, HTML, rtf, TeX, LaTeX, XML, a few others.

I export everything to .rtf and then open it in openoffice, just to take a look. It looks great; colour code highlighting, the works. Export to pdf, to make sure I have it in time for my deadline, and then get back to work.

I export everything as TeX, then use pdftex and it comes out as a gorgeous looking pdf, but only in greyscale. I wanted to hand in colour, so I didn’t worry about this and instead used openoffice, but tonight I’ll be looking for a .rtf to .pdf filter on the command line so I can deal with everything and get colour output.

Whether I find it or not, I’ll write up a quick script to take in code and output a greyscale pdf file. Then I’ll investigate script files, which I imagine will be as simple as txt2pdf or something named similarly. Then I’ll submit it as a port; it’ll be a front end to other tools, but I think the ability to ensure my code looked gorgeous from any operating system and printed out correctly was sufficiently useful that other students would like the same thing. And lo! It will be called something witty.

I’m thinking it should be a simple thing that offers flags to output colour or greyscale pdfs (eventually), and also can handle script files. Pretty code all day long.

Posted: Fri, 9 May 2008 15:59:42 +0000
Tags: code, how to, programming
Comments


May 6, 2008

Edwin Groothuis (edwin) [stats, website]

FreeBSD IPv6 Divert socket adventures

This whole IPv6 Divert idea seems to be a little bit optimistic now. As all new technology (I wouldn't call IPv6 new technology, but still) not everything you have available now is supported in it.

So, how far did we get?

  • FreeBSD's ipfw2 supports diverting of IPv6 packets. Yay!
  • A simple program which listens on the divert socket (IPPROTO_DIVERT) for IPv4 (PF_INET) and prints some information about the packets received works. Yay!
  • That same program for IPv6 (PF_INET6) doesn't work, lsof says that it is listening for protocol 0 (the catch all) instead of protocol IPPROTO_DIVERT.
  • Looking through ip_divert() in src/netinet/ip_divert.c shows about the registration of protocols (thanks to bms@ for hints): pf_proto_register(PF_INET, ÷_protosw), but when I do this for PF_INET6 it returns an error which is related to the absence of a free IPPROTO_SPACER. And these are (thanks to rwatson@ for hints) not available for IPv6.

So, this is getting trickier and trickier for an userland guy like me to experiment with on a sunday afternoon... But I'm not going to give up! (yet)

On the other hand, an interesting paper by Dr. Goto (I'm not kidding) and friends available at IPV4/V6 NETWORK EMULATOR USING DIVERT SOCKET says:

[...]
We have ported divert socket to IPv6 by adding about 1000
lines of C program code either on FreeBSD and Linux kernel
for this research.
[...]
I have asked him if he wanted to share his code but haven't heard anything back from him.

Posted: Tue, 6 May 2008 11:00:00 +0000


May 5, 2008

Matteo Riondato (matteo) [stats, website]

Laptop Status

I’m pretty happy of the status of the FreeBSD installation on my laptop: I’m running HEAD and have skype-devel, jdk15, eclipse, and OpenOffice.org-2.4. Eventually, last night I moved my home to a new slice with GELI+Gjournal.

Still to do: Tor configuration…and flash: gnash doesn’t seem to be so stable ATM on my laptop..It may be X.org’s, drm’s, or gnash’s fault, or who knows…

Posted: Mon, 5 May 2008 18:55:37 +0000
Tags: freebsd
Comments


May 4, 2008

Philip Paeps (philip) [stats, website]

Playing with zsh

Ever since ... well, forever, people have been telling me to try zsh. I have been a happy tcsh user since the beginning of time, and have never seen a reason to switch.

According to the documentation, zsh is a hybrid shell that combines all the useful features of tcsh and ksh, has somehow managed to find good features in bash to include as well (I wonder how that works, I've never managed to find any good features in bash, only annoyances) and adds some interesting new stuff on top.

The implied bloat of this alone has kept me away from zsh for a while. In fact, the binary is about the same size as bash. Which isn't bad, considering that bash takes all this space without offering any functionality and zsh offers heaps.

Being bored over the long weekend, I took a closer look at zsh and tried to teach it about the things I have grown to like in tcsh. This turned out to be surprisingly easy. In fact, the only mildly tricky bit was teaching zsh about the addictive run-fg-editor command, which I bind to ^Z and which is very addictive.

Six lines in my .zshrc do the trick, however:

# Emulate tcsh's run-fg-editor
run-fg-editor() {
    zle push-input
    BUFFER="fg %$EDITOR:t"
    zle accept-line
}
zle -N run-fg-editor

Another annoyance is the way the backward-delete-word function likes to eat whole paths. As far as I know, only tcsh gets this right by default. That is, if I've got something like cd /usr/local/tools/xchains/arm/arm9 in my buffer and press ^W, I only want the arm9 to go away, not the whole path. You'd think that would count as sensible default. Like the run-fg-editor bit, this was also fairly easy to fix:

# Emulate tcsh's backward-delete-word
tcsh-backward-delete-word () {
    local WORDCHARS="${WORDCHARS:s#/#}"
    zle backward-delete-word
}
zle -N tcsh-backward-delete-word

After I got zsh behaving like tcsh, I checked to make sure that some of the constructions I use all the time still worked:

[204] (philip@carrot)~/tmp% touch foo
[205] (philip@carrot)~/tmp% cp foo !#:1.orig
cp foo foo.orig
[206] (philip@carrot)~/tmp%

[206] (philip@carrot)~/tmp% !204:s/foo/bar/
touch bar
[207] (philip@carrot)~/tmp% !205:gs/foo/bar/
cp bar bar.orig
[208] (philip@carrot)~/tmp%

[208] (philip@carrot)~/tmp% !to
touch bar
[209] (philip@carrot)~/tmp% !cp
cp bar bar.orig
[210] (philip@carrot)~/tmp%

Yes - I'm a great fan of history substitution. And of the foreach loop and modifiers:

[210] (philip@carrot)~/tmp% mkdir foreach
[211] (philip@carrot)~/tmp% cd !$
cd foreach
[212] (philip@carrot)~/tmp/foreach% touch alpha beta gamma
[213] (philip@carrot)~/tmp/foreach% foreach file (*)
foreach> mv $file $file:u
foreach> end
[214] (philip@carrot)~/tmp/foreach% ll
total 0
-rw-rw-r--  1 philip  philip  0 May  4 13:49 ALPHA
-rw-rw-r--  1 philip  philip  0 May  4 13:49 BETA
-rw-rw-r--  1 philip  philip  0 May  4 13:49 GAMMA
[215] (philip@carrot)~/tmp/foreach%

I also make the occasional typo:

[215] (philip@carrot)~/tmp/foreach% iv GAMMA
zsh: correct 'iv' to 'vi' [nyae]?

Excellent. :-)

I'll be playing with this some more... I'm particularly interested in learning about the "fully programmable completion". If I read the documentation right, it's like tcsh completion on acid. Sounds like fun.

My only worry is that zsh is the "shell of choice" in the build system at work. So who knows what kind of horrible voodoo rites I'll need to perform to have both a sensible interactive environment (which the default isn't) and be able to create bootable builds (which a sensible interactive environment surely can't).

It seems zsh offers the possibility to be started with a different set of dotfiles. I think together with modules (thanks again for that tip, Jan, I think I already told you I'm addicted), I should be able to hack something together.

Fun fun fun!

Posted: Sun, 4 May 2008 13:02:00 +0000


Playing with zsh

Ever since ... well, forever, people have been telling me to try zsh. I have been a happy tcsh user since the beginning of time, and have never seen a reason to switch.

According to the documentation, zsh is a hybrid shell that combines all the useful features of tcsh and ksh, has somehow managed to find good features in bash to include as well (I wonder how that works, I've never managed to find any good features in bash, only annoyances) and adds some interesting new stuff on top.

The implied bloat of this alone has kept me away from zsh for a while. In fact, the binary is about the same size as bash. Which isn't bad, considering that bash takes all this space without offering any functionality and zsh offers heaps.

Being bored over the long weekend, I took a closer look at zsh and tried to teach it about the things I have grown to like in tcsh. This turned out to be surprisingly easy. In fact, the only mildly tricky bit was teaching zsh about the addictive run-fg-editor command, which I bind to ^Z and which is very addictive.

Six lines in my .zshrc do the trick, however:

# Emulate tcsh's run-fg-editor
run-fg-editor() {
    zle push-input
    BUFFER="fg %$EDITOR:t"
    zle accept-line
}
zle -N run-fg-editor

Another annoyance is the way the backward-delete-word function likes to eat whole paths. As far as I know, only tcsh gets this right by default. That is, if I've got something like cd /usr/local/tools/xchains/arm/arm9 in my buffer and press ^W, I only want the arm9 to go away, not the whole path. You'd think that would count as sensible default. Like the run-fg-editor bit, this was also fairly easy to fix:

# Emulate tcsh's backward-delete-word
tcsh-backward-delete-word () {
    local WORDCHARS="${WORDCHARS:s#/#}"
    zle backward-delete-word
}
zle -N tcsh-backward-delete-word

After I got zsh behaving like tcsh, I checked to make sure that some of the constructions I use all the time still worked:

[204] (philip@carrot)~/tmp% touch foo
[205] (philip@carrot)~/tmp% cp foo !#:1.orig
cp foo foo.orig
[206] (philip@carrot)~/tmp%

[206] (philip@carrot)~/tmp% !204:s/foo/bar/
touch bar
[207] (philip@carrot)~/tmp% !205:gs/foo/bar/
cp bar bar.orig
[208] (philip@carrot)~/tmp%

[208] (philip@carrot)~/tmp% !to
touch bar
[209] (philip@carrot)~/tmp% !cp
cp bar bar.orig
[210] (philip@carrot)~/tmp%

Yes - I'm a great fan of history substitution. And of the foreach loop and modifiers:

[210] (philip@carrot)~/tmp% mkdir foreach
[211] (philip@carrot)~/tmp% cd !$
cd foreach
[212] (philip@carrot)~/tmp/foreach% touch alpha beta gamma
[213] (philip@carrot)~/tmp/foreach% foreach file (*)
foreach> mv $file $file:u
foreach> end
[214] (philip@carrot)~/tmp/foreach% ll
total 0
-rw-rw-r--  1 philip  philip  0 May  4 13:49 ALPHA
-rw-rw-r--  1 philip  philip  0 May  4 13:49 BETA
-rw-rw-r--  1 philip  philip  0 May  4 13:49 GAMMA
[215] (philip@carrot)~/tmp/foreach%

I also make the occasional typo:

[215] (philip@carrot)~/tmp/foreach% iv GAMMA
zsh: correct 'iv' to 'vi' [nyae]?

Excellent. :-)

I'll be playing with this some more... I'm particularly interested in learning about the "fully programmable completion". If I read the documentation right, it's like tcsh completion on acid. Sounds like fun.

My only worry is that zsh is the "shell of choice" in the build system at work. So who knows what kind of horrible voodoo rites I'll need to perform to have both a sensible interactive environment (which the default isn't) and be able to create bootable builds (which a sensible interactive environment surely can't).

It seems zsh offers the possibility to be started with a different set of dotfiles. I think together with modules (thanks again for that tip, Jan, I think I already told you I'm addicted), I should be able to hack something together.

Fun fun fun!

Posted: Sun, 4 May 2008 13:02:00 +0000

May 3, 2008

James Harrison (jamesh) [stats, website]

oscartheduck


I did something today that I’ve never done before. I decided that I was going to see how far that FreeBSD and gnome integrate with each other. Whenever I install FreeBSD, I usually run it as a CLI os. I install a window manager, but it’s not there as anything really other than support for multiple terminals. I use ubuntu for a nice pretty OS with integration between all the disparate elements, and FreeBSD for real work.

So I started following the instructions from the FreeBSD Gnome folks for auto-mounting this and pleasant integration that. In the process, amazing things happened. Screensavers started working brilliantly, icons that were missing showed up out of nowhere, and I started to see the truth of a friend of mine’s observation to me two years ago that FreeBSD and Gnome are exceptionally well integrated with each other.

I almost feel like writing a port that’s just a shell script to execute the relevant bits and pieces to make FreeBSD shine with Gnome; it’s amazing that all this time I could have had this on the desktop and instead was using linux.

I privately noted an interesting thing today. I started using the _excellent_ portmaster tool to solve ports issues instead of portupgrade recently, and out of nowhere the amount of circular dependencies registered in pkgb skyrocketed. It’s probably merely a coincidence, but still.

trap just became my new best friend: http://docs.hp.com/en/B2355-90046/ch23s07.html

I’ve been following the code for NanoBSD of late; it’s extremely clearly written and provides excellent examples of shell code. Well worth a look.

I’ve also been following my interests down the path to the source code of common utilities. What’s neat is the little things I hadn’t thought of. For example, from boot0cfg, in the case statement that reads argv, Robert Nordier sets a variable to equal 1:

case ‘f’:
fpath = optarg;
break;

Then,

/* save the existing MBR if we are asked to do so */
if (fpath)
write_mbr(fpath, O_CREAT | O_TRUNC, mbr, mbr_size);

Robert directly tests for truth on the fpath variable. I’ve always called my variables something like fpath_test to remind myself that they’re essentially booleans; however, looking at this I’m suddenly hit by the “Oh, there’s no real need to do what I do, and it might sacrifice a little clarity”.

This suddenly makes me wonder: would there be any performance impact of using boolean types here? I can’t imagine there would be, as I assume the boole types are little more than static constants.

I noticed this little gem in the code for boot0cfg, too:

opttbl[] = {
{”packet”, 0},
{”update”, 1},
{”setdrv”, 0}
};

Is it just me, or is that sucker a dictionary/hash?

I need to include the following to satisfy the license:

/*
* Copyright (c) 1999 Robert Nordier
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS“AS IS” AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

Posted: Sat, 3 May 2008 05:39:46 +0000
Tags: desktop, freebsd, ubuntu, uncategorized
Comments


May 2, 2008

Gábor Kövesdán (gabor) [stats, website]

SoC 2008: Porting BSD-licensed Text-Processing Tools from OpenBSD

This year, I’m working on porting grep, sort and diff from OpenBSD. You can read more about my project in the original proposal. If you wanto to see the progress, you can look at my wiki page, although I’m going to post the most important milestones here.

Posted: Fri, 2 May 2008 17:18:28 +0000
Tags: freebsd
Comments


May 1, 2008

Vincenzo Iozzo (snagg) [stats, website]

First post, me and my project

Hi all,I’m Vincenzo Iozzo, currently I’m studying computer engineering at the Politecnico di Milano. I also work for Secure Network srl. And in the spare time I do some research for my university. I’m mainly involved in IT Security.   Now, after this brief presentation, I’d like to spend a few words on my project for this Summer Of Code.  I will modify the FreeBSD auditpipe support in order to provide more granularity while auditing syscalls. In fact, at the present time, your choice on what to audit is limited to default classes. With my patch it would be possible to select every syscall by its own. The second half of the project will consist of creating a framework for testing the correct behavior of the auditing system and, if needed, patching it.Finally the whole auditing system will be checked in order to see whether or not is vulnerable at some anti-forensics techiniques.  Here you can find a detailed description of the first part of the project.Snagg

Posted: Thu, 1 May 2008 17:59:43 +0000
Tags: project
Comments


Edwin Groothuis (edwin) [stats, website]

Three Mobile roaming 3G network

Thanks to my job, or cursed by my job sometimes, I have access to a 3G modem of Three Mobile. It works fine in areas where there is Three Mobile coverage, outside these areas were we are roaming (and probably on the Telstra 3G network) there are interesting issues with the IPCP phase (IP Confirguration Protocol) of PPP which make the PPP setup fail.

So what works and what doesn't? According to the PPP manual, this is what we should see:

ppp ON awfulhak> # No link has been established
Ppp ON awfulhak> # We've connected & finished LCP
PPp ON awfulhak> # We've authenticated
PPP ON awfulhak> # We've agreed IP numbers
The first two Ps become capitals, but the third one doesn't when we are roaming.

What do the logs say? The short version of a successful handshake is:

IPCP: FSM: Using "deflink" as a transport
IPCP: deflink: State change Initial --> Closed
IPCP: deflink: LayerStart.
IPCP: deflink: SendConfigReq(1) state = Closed
IPCP: deflink: State change Closed --> Req-Sent
IPCP: deflink: RecvConfigNak(1) state = Req-Sent
IPCP: deflink: SendConfigReq(2) state = Req-Sent
IPCP: deflink: RecvConfigNak(2) state = Req-Sent
IPCP: deflink: SendConfigReq(3) state = Req-Sent
IPCP: deflink: RecvConfigReq(0) state = Req-Sent
IPCP: deflink: SendConfigNak(0) state = Req-Sent
IPCP: deflink: RecvConfigRej(3) state = Req-Sent
IPCP: deflink: SendConfigReq(4) state = Req-Sent
IPCP: deflink: RecvConfigReq(1) state = Req-Sent
IPCP: deflink: SendConfigAck(1) state = Req-Sent
IPCP: deflink: State change Req-Sent --> Ack-Sent
IPCP: deflink: RecvConfigNak(4) state = Ack-Sent
IPCP: deflink: SendConfigReq(5) state = Ack-Sent
IPCP: deflink: RecvConfigAck(5) state = Ack-Sent
IPCP: deflink: State change Ack-Sent --> Opened
The full log is at the end of this writeup.
The discussion goes like this: I propose something three times (SendConfigReq) and they reject it (RecvConfigNak), but at the third time they say "Let's try it with this" (RecvConfigReq) and we come up with a common ground. And everybody is happy!

The short version of an unsuccessful handshake is:

IPCP: FSM: Using "deflink" as a transport
IPCP: deflink: State change Initial --> Closed
IPCP: deflink: LayerStart.
IPCP: deflink: SendConfigReq(1) state = Closed
IPCP: deflink: State change Closed --> Req-Sent
IPCP: deflink: RecvConfigNak(1) state = Req-Sent
IPCP: deflink: SendConfigReq(2) state = Req-Sent
IPCP: deflink: RecvConfigNak(2) state = Req-Sent
IPCP: deflink: SendConfigReq(3) state = Req-Sent
IPCP: deflink: RecvConfigNak(3) state = Req-Sent
IPCP: deflink: SendConfigReq(4) state = Req-Sent
IPCP: deflink: RecvConfigNak(4) state = Req-Sent
IPCP: deflink: SendConfigReq(5) state = Req-Sent
IPCP: deflink: RecvConfigNak(5) state = Req-Sent
IPCP: deflink: SendConfigReq(6) state = Req-Sent
IPCP: deflink: RecvConfigNak(6) state = Req-Sent
IPCP: deflink: SendConfigReq(7) state = Req-Sent
IPCP: deflink: RecvConfigNak(7) state = Req-Sent
IPCP: deflink: SendConfigReq(8) state = Req-Sent
IPCP: deflink: RecvConfigNak(8) state = Req-Sent
IPCP: deflink: SendConfigReq(9) state = Req-Sent
IPCP: deflink: RecvConfigNak(9) state = Req-Sent
IPCP: deflink: SendConfigReq(10) state = Req-Sent
IPCP: deflink: RecvConfigNak(10) state = Req-Sent
IPCP: deflink: SendConfigReq(11) state = Req-Sent
IPCP: deflink: SendTerminateReq(11) state = Req-Sent
IPCP: deflink: State change Req-Sent --> Closing
IPCP: deflink: RecvTerminateAck(11) state = Closing
IPCP: deflink: LayerFinish.
IPCP: deflink: State change Closing --> Closed
IPCP: deflink: RecvConfigNak(11), dropped (expected 12)
The full log is at the end of this writeup.
Here there are only SendConfigReq and RecvConfigNak, there is no RecvConfigReq coming from them!

If anybody has managed to setup a successful PPP connection on the 3G network of anybody but Three Mobile can send me some logs, I would be very happy to see if I can fix things.

Here are the full logs:

This is the IPCP part of a successful handshake

ppp[1098]: tun0: Phase: bundle: Network
ppp[1098]: tun0: IPCP: FSM: Using "deflink" as a transport
ppp[1098]: tun0: IPCP: deflink: State change Initial --> Closed
ppp[1098]: tun0: IPCP: deflink: LayerStart.
ppp[1098]: tun0: IPCP: deflink: SendConfigReq(1) state = Closed
ppp[1098]: tun0: IPCP: IPADDR[6] 0.0.0.0
ppp[1098]: tun0: IPCP: COMPPROTO[6] 16 VJ slots without slot compression
ppp[1098]: tun0: IPCP: PRIDNS[6] 202.124.76.66
ppp[1098]: tun0: IPCP: SECDNS[6] 255.255.255.255
ppp[1098]: tun0: IPCP: deflink: State change Closed --> Req-Sent
ppp[1098]: tun0: LCP: deflink: RecvProtocolRej(2) state = Opened
ppp[1098]: tun0: LCP: deflink: -- Protocol 0x80fd (Compression Control Protocol) was rejected!
ppp[1098]: tun0: CCP: deflink: State change Req-Sent --> Stopped
ppp[1098]: tun0: IPCP: deflink: RecvConfigNak(1) state = Req-Sent
ppp[1098]: tun0: IPCP: PRIDNS[6] 10.11.12.13
ppp[1098]: tun0: IPCP: SECDNS[6] 10.11.12.14
ppp[1098]: tun0: IPCP: PRINBNS[6] 10.11.12.13
ppp[1098]: tun0: IPCP: MS NBNS req 130 - NAK??
ppp[1098]: tun0: IPCP: SECNBNS[6] 10.11.12.14
ppp[1098]: tun0: IPCP: MS NBNS req 132 - NAK??
ppp[1098]: tun0: IPCP: Primary nameserver set to 10.11.12.13
ppp[1098]: tun0: IPCP: Secondary nameserver set to 10.11.12.14
ppp[1098]: tun0: IPCP: deflink: SendConfigReq(2) state = Req-Sent
ppp[1098]: tun0: IPCP: IPADDR[6] 0.0.0.0
ppp[1098]: tun0: IPCP: COMPPROTO[6] 16 VJ slots without slot compression
ppp[1098]: tun0: IPCP: PRIDNS[6] 10.11.12.13
ppp[1098]: tun0: IPCP: SECDNS[6] 10.11.12.14
ppp[1098]: tun0: IPCP: deflink: RecvConfigNak(2) state = Req-Sent
ppp[1098]: tun0: IPCP: PRIDNS[6] 10.11.12.13
ppp[1098]: tun0: IPCP: SECDNS[6] 10.11.12.14
ppp[1098]: tun0: IPCP: PRINBNS[6] 10.11.12.13
ppp[1098]: tun0: IPCP: MS NBNS req 130 - NAK??
ppp[1098]: tun0: IPCP: SECNBNS[6] 10.11.12.14
ppp[1098]: tun0: IPCP: MS NBNS req 132 - NAK??
ppp[1098]: tun0: IPCP: Primary nameserver set to 10.11.12.13
ppp[1098]: tun0: IPCP: Secondary nameserver set to 10.11.12.14
ppp[1098]: tun0: IPCP: deflink: SendConfigReq(3) state = Req-Sent
ppp[1098]: tun0: IPCP: IPADDR[6] 0.0.0.0
ppp[1098]: tun0: IPCP: COMPPROTO[6] 16 VJ slots without slot compression
ppp[1098]: tun0: IPCP: PRIDNS[6] 10.11.12.13
ppp[1098]: tun0: IPCP: SECDNS[6] 10.11.12.14
ppp[1098]: tun0: IPCP: deflink: RecvConfigReq(0) state = Req-Sent
ppp[1098]: tun0: IPCP: [EMPTY]
ppp[1098]: tun0: IPCP: deflink: SendConfigNak(0) state = Req-Sent
ppp[1098]: tun0: IPCP: IPADDR[6] 10.0.0.2
ppp[1098]: tun0: IPCP: deflink: RecvConfigRej(3) state = Req-Sent
ppp[1098]: tun0: IPCP: COMPPROTO[6] 16 VJ slots without slot compression
ppp[1098]: tun0: IPCP: deflink: SendConfigReq(4) state = Req-Sent
ppp[1098]: tun0: IPCP: IPADDR[6] 0.0.0.0
ppp[1098]: tun0: IPCP: PRIDNS[6] 10.11.12.13
ppp[1098]: tun0: IPCP: SECDNS[6] 10.11.12.14
ppp[1098]: tun0: IPCP: deflink: RecvConfigReq(1) state = Req-Sent
ppp[1098]: tun0: IPCP: [EMPTY]
ppp[1098]: tun0: IPCP: deflink: SendConfigAck(1) state = Req-Sent
ppp[1098]: tun0: IPCP: [EMPTY]
ppp[1098]: tun0: IPCP: deflink: State change Req-Sent --> Ack-Sent
ppp[1098]: tun0: IPCP: deflink: RecvConfigNak(4) state = Ack-Sent
ppp[1098]: tun0: IPCP: IPADDR[6] 119.11.8.120
ppp[1098]: tun0: IPCP: IPADDR[6] changing address: 0.0.0.0 --> 119.11.8.120
ppp[1098]: tun0: IPCP: PRIDNS[6] 202.124.68.130
ppp[1098]: tun0: IPCP: SECDNS[6] 202.124.76.66
ppp[1098]: tun0: IPCP: Primary nameserver set to 202.124.68.130
ppp[1098]: tun0: IPCP: Secondary nameserver set to 202.124.76.66
ppp[1098]: tun0: IPCP: deflink: SendConfigReq(5) state = Ack-Sent
ppp[1098]: tun0: IPCP: IPADDR[6] 119.11.8.120
ppp[1098]: tun0: IPCP: PRIDNS[6] 202.124.68.130
ppp[1098]: tun0: IPCP: SECDNS[6] 202.124.76.66
ppp[1098]: tun0: IPCP: deflink: RecvConfigAck(5) state = Ack-Sent
ppp[1098]: tun0: IPCP: IPADDR[6] 119.11.8.120
ppp[1098]: tun0: IPCP: PRIDNS[6] 202.124.68.130
ppp[1098]: tun0: IPCP: SECDNS[6] 202.124.76.66
ppp[1098]: tun0: IPCP: deflink: State change Ack-Sent --> Opened
ppp[1098]: tun0: IPCP: deflink: LayerUp.

This is the IPCP part of a unsuccessful handshake

ppp[1661]: tun0: Phase: bundle: Network
ppp[1661]: tun0: IPCP: FSM: Using "deflink" as a transport
ppp[1661]: tun0: IPCP: deflink: State change Initial --> Closed
ppp[1661]: tun0: IPCP: deflink: LayerStart.
ppp[1661]: tun0: IPCP: deflink: SendConfigReq(1) state = Closed
ppp[1661]: tun0: IPCP: IPADDR[6] 0.0.0.0
ppp[1661]: tun0: IPCP: COMPPROTO[6] 16 VJ slots with slot compression
ppp[1661]: tun0: IPCP: PRIDNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: SECDNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: deflink: State change Closed --> Req-Sent
ppp[1661]: tun0: LCP: deflink: RecvProtocolRej(2) state = Opened
ppp[1661]: tun0: LCP: deflink: -- Protocol 0x80fd (Compression Control Protocol) was rejected!
ppp[1661]: tun0: CCP: deflink: State change Req-Sent --> Stopped
ppp[1661]: tun0: IPCP: deflink: RecvConfigNak(1) state = Req-Sent
ppp[1661]: tun0: IPCP: PRIDNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: SECDNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: PRINBNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: MS NBNS req 130 - NAK??
ppp[1661]: tun0: IPCP: SECNBNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: MS NBNS req 132 - NAK??
ppp[1661]: tun0: IPCP: Primary nameserver set to 10.11.12.13
ppp[1661]: tun0: IPCP: Secondary nameserver set to 10.11.12.14
ppp[1661]: tun0: IPCP: deflink: SendConfigReq(2) state = Req-Sent
ppp[1661]: tun0: IPCP: IPADDR[6] 0.0.0.0
ppp[1661]: tun0: IPCP: COMPPROTO[6] 16 VJ slots with slot compression
ppp[1661]: tun0: IPCP: PRIDNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: SECDNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: deflink: RecvConfigNak(2) state = Req-Sent
ppp[1661]: tun0: IPCP: PRIDNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: SECDNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: PRINBNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: MS NBNS req 130 - NAK??
ppp[1661]: tun0: IPCP: SECNBNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: MS NBNS req 132 - NAK??
ppp[1661]: tun0: IPCP: Primary nameserver set to 10.11.12.13
ppp[1661]: tun0: IPCP: Secondary nameserver set to 10.11.12.14
ppp[1661]: tun0: IPCP: deflink: SendConfigReq(3) state = Req-Sent
ppp[1661]: tun0: IPCP: IPADDR[6] 0.0.0.0
ppp[1661]: tun0: IPCP: COMPPROTO[6] 16 VJ slots with slot compression
ppp[1661]: tun0: IPCP: PRIDNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: SECDNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: deflink: RecvConfigNak(3) state = Req-Sent
ppp[1661]: tun0: IPCP: PRIDNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: SECDNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: PRINBNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: MS NBNS req 130 - NAK??
ppp[1661]: tun0: IPCP: SECNBNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: MS NBNS req 132 - NAK??
ppp[1661]: tun0: IPCP: Primary nameserver set to 10.11.12.13
ppp[1661]: tun0: IPCP: Secondary nameserver set to 10.11.12.14
ppp[1661]: tun0: IPCP: deflink: SendConfigReq(4) state = Req-Sent
ppp[1661]: tun0: IPCP: IPADDR[6] 0.0.0.0
ppp[1661]: tun0: IPCP: COMPPROTO[6] 16 VJ slots with slot compression
ppp[1661]: tun0: IPCP: PRIDNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: SECDNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: deflink: RecvConfigNak(4) state = Req-Sent
ppp[1661]: tun0: IPCP: PRIDNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: SECDNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: PRINBNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: MS NBNS req 130 - NAK??
ppp[1661]: tun0: IPCP: SECNBNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: MS NBNS req 132 - NAK??
ppp[1661]: tun0: IPCP: Primary nameserver set to 10.11.12.13
ppp[1661]: tun0: IPCP: Secondary nameserver set to 10.11.12.14
ppp[1661]: tun0: IPCP: deflink: SendConfigReq(5) state = Req-Sent
ppp[1661]: tun0: IPCP: IPADDR[6] 0.0.0.0
ppp[1661]: tun0: IPCP: COMPPROTO[6] 16 VJ slots with slot compression
ppp[1661]: tun0: IPCP: PRIDNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: SECDNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: deflink: RecvConfigNak(5) state = Req-Sent
ppp[1661]: tun0: IPCP: PRIDNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: SECDNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: PRINBNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: MS NBNS req 130 - NAK??
ppp[1661]: tun0: IPCP: SECNBNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: MS NBNS req 132 - NAK??
ppp[1661]: tun0: IPCP: Primary nameserver set to 10.11.12.13
ppp[1661]: tun0: IPCP: Secondary nameserver set to 10.11.12.14
ppp[1661]: tun0: IPCP: deflink: SendConfigReq(6) state = Req-Sent
ppp[1661]: tun0: IPCP: IPADDR[6] 0.0.0.0
ppp[1661]: tun0: IPCP: COMPPROTO[6] 16 VJ slots with slot compression
ppp[1661]: tun0: IPCP: PRIDNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: SECDNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: deflink: RecvConfigNak(6) state = Req-Sent
ppp[1661]: tun0: IPCP: PRIDNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: SECDNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: PRINBNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: MS NBNS req 130 - NAK??
ppp[1661]: tun0: IPCP: SECNBNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: MS NBNS req 132 - NAK??
ppp[1661]: tun0: IPCP: Primary nameserver set to 10.11.12.13
ppp[1661]: tun0: IPCP: Secondary nameserver set to 10.11.12.14
ppp[1661]: tun0: IPCP: deflink: SendConfigReq(7) state = Req-Sent
ppp[1661]: tun0: IPCP: IPADDR[6] 0.0.0.0
ppp[1661]: tun0: IPCP: COMPPROTO[6] 16 VJ slots with slot compression
ppp[1661]: tun0: IPCP: PRIDNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: SECDNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: deflink: RecvConfigNak(7) state = Req-Sent
ppp[1661]: tun0: IPCP: PRIDNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: SECDNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: PRINBNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: MS NBNS req 130 - NAK??
ppp[1661]: tun0: IPCP: SECNBNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: MS NBNS req 132 - NAK??
ppp[1661]: tun0: IPCP: Primary nameserver set to 10.11.12.13
ppp[1661]: tun0: IPCP: Secondary nameserver set to 10.11.12.14
ppp[1661]: tun0: IPCP: deflink: SendConfigReq(8) state = Req-Sent
ppp[1661]: tun0: IPCP: IPADDR[6] 0.0.0.0
ppp[1661]: tun0: IPCP: COMPPROTO[6] 16 VJ slots with slot compression
ppp[1661]: tun0: IPCP: PRIDNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: SECDNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: deflink: RecvConfigNak(8) state = Req-Sent
ppp[1661]: tun0: IPCP: PRIDNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: SECDNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: PRINBNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: MS NBNS req 130 - NAK??
ppp[1661]: tun0: IPCP: SECNBNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: MS NBNS req 132 - NAK??
ppp[1661]: tun0: IPCP: Primary nameserver set to 10.11.12.13
ppp[1661]: tun0: IPCP: Secondary nameserver set to 10.11.12.14
ppp[1661]: tun0: IPCP: deflink: SendConfigReq(9) state = Req-Sent
ppp[1661]: tun0: IPCP: IPADDR[6] 0.0.0.0
ppp[1661]: tun0: IPCP: COMPPROTO[6] 16 VJ slots with slot compression
ppp[1661]: tun0: IPCP: PRIDNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: SECDNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: deflink: RecvConfigNak(9) state = Req-Sent
ppp[1661]: tun0: IPCP: PRIDNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: SECDNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: PRINBNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: MS NBNS req 130 - NAK??
ppp[1661]: tun0: IPCP: SECNBNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: MS NBNS req 132 - NAK??
ppp[1661]: tun0: IPCP: Primary nameserver set to 10.11.12.13
ppp[1661]: tun0: IPCP: Secondary nameserver set to 10.11.12.14
ppp[1661]: tun0: IPCP: deflink: SendConfigReq(10) state = Req-Sent
ppp[1661]: tun0: IPCP: IPADDR[6] 0.0.0.0
ppp[1661]: tun0: IPCP: COMPPROTO[6] 16 VJ slots with slot compression
ppp[1661]: tun0: IPCP: PRIDNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: SECDNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: deflink: RecvConfigNak(10) state = Req-Sent
ppp[1661]: tun0: IPCP: PRIDNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: SECDNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: PRINBNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: MS NBNS req 130 - NAK??
ppp[1661]: tun0: IPCP: SECNBNS[6] 10.11.12.14
ppp[1661]: tun0: IPCP: MS NBNS req 132 - NAK??
ppp[1661]: tun0: IPCP: Primary nameserver set to 10.11.12.13
ppp[1661]: tun0: IPCP: Secondary nameserver set to 10.11.12.14
ppp[1661]: tun0: IPCP: deflink: SendConfigReq(11) state = Req-Sent
ppp[1661]: tun0: IPCP: IPADDR[6] 0.0.0.0
ppp[1661]: tun0: IPCP: COMPPROTO[6] 16 VJ slots with slot compression
ppp[1661]: tun0: IPCP: PRIDNS[6] 10.11.12.13
ppp[1661]: tun0: IPCP: SECDNS[6] 10.11.12.14
ppp[1661]: tun0: Command: /dev/ttyp1: quit
ppp[1661]: tun0: IPCP: deflink: SendTerminateReq(11) state = Req-Sent
ppp[1661]: tun0: IPCP: deflink: State change Req-Sent --> Closing
ppp[1661]: tun0: IPCP: deflink: RecvTerminateAck(11) state = Closing
ppp[1661]: tun0: IPCP: deflink: LayerFinish.
ppp[1661]: tun0: IPCP: Connect time: 11 secs: 0 octets in, 0 octets out
ppp[1661]: tun0: IPCP: 0 packets in, 0 packets out
ppp[1661]: tun0: IPCP: total 0 bytes/sec, peak 0 bytes/sec on Thu Apr 24 13:39:49 2008
ppp[1661]: tun0: IPCP: deflink: State change Closing --> Closed
ppp[1661]: tun0: IPCP: deflink: RecvConfigNak(11), dropped (expected 12)
ppp[1661]: tun0: Phase: bundle: Terminate

Posted: Thu, 1 May 2008 09:00:00 +0000


April 30, 2008

James Harrison (jamesh) [stats, website]

oscartheduck


Today, I finally got to really start a beginning on my embedded BSD proposal; I started reading NanoBSD and TinyBSD, to see what they’re doing.

I love reading other coders’ code, because it’s always a learning experience. Poul-Henning Kamp, for example, writes very nice shell script. Very nice indeed.

As I am about to redistribute his code a little, let me include this :

<—-snip—->

# Copyright (c) 2005 Poul-Henning Kamp.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS “AS IS” AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $FreeBSD: src/tools/tools/nanobsd/nanobsd.sh,v 1.30 2008/01/12 22:58:06 simon Exp $

<—-/snip—->

Now that that’s over with, a little code is in order:

<—-snip—->

# Name of this NanoBSD build. (Used to construct workdir names)
NANO_NAME=full

# Source tree directory
NANO_SRC=/usr/src

# Where nanobsd additional files live under the source tree
NANO_TOOLS=tools/tools/nanobsd

# Where cust_pkg() finds packages to install
NANO_PACKAGE_DIR=${NANO_SRC}/${NANO_TOOLS}/Pkg

# Object tree directory
# default is subdir of /usr/obj
# XXX: MAKEOBJDIRPREFIX handling… ?
#NANO_OBJ=”"

# The directory to put the final images
# default is ${NANO_OBJ}
#NANO_DISKIMGDIR=”"

<—-/snip—->

See what he did there? He’s declaring variables. Every one of them is prefixed with a comment that says “This next variable means this”. I swear, I started reading this and admired the time put in simply to make the code easier to follow.

I was a little worried, though. It looks wordy. But I got down to the code:

<—-snip—->
###########################################
#
# The functions which do the real work.
# Can be overridden from the config file(s)
#
#######################################################################

clean_build ( ) (
echo “## Clean and create object directory (${MAKEOBJDIRPREFIX})”

if rm -rf ${MAKEOBJDIRPREFIX} > /dev/null 2>&1 ; then
true
else
chflags -R noschg ${MAKEOBJDIRPREFIX}
rm -rf ${MAKEOBJDIRPREFIX}
fi
mkdir -p ${MAKEOBJDIRPREFIX}
printenv > ${MAKEOBJDIRPREFIX}/_.env
)
make_conf_build ( ) (
echo “## Construct build make.conf ($NANO_MAKE_CONF)”

echo “${CONF_WORLD}” > ${NANO_MAKE_CONF}
echo “${CONF_BUILD}” >> ${NANO_MAKE_CONF}
)

build_world ( ) (
echo “## run buildworld”
echo “### log: ${MAKEOBJDIRPREFIX}/_.bw”

cd ${NANO_SRC}
${NANO_PMAKE} __MAKE_CONF=${NANO_MAKE_CONF} buildworld \
> ${MAKEOBJDIRPREFIX}/_.bw 2>&1
)
<—-/snip—->

A note which tells us “variables are over now, busters”, then straight into code.

It’s a good example of how to write a shell script. There’s enough information to get one oriented, but after that you’re on your own. And let’s face it, if you can’t work this stuff out reading it then no number of comments are going to help.

In reading it, I ran across a couple of programs I’ve never used. I figured, though, what better time to get familiar with them than by also reading their source code? So I gleefully started wandering through my source tree, discovering what there is to discover there. And as ever, I was impressed by how simple a lot of programs are.

chflags, for example, is basically two case statements.

I love usage statements. This code is covered under the same copyright as above, though I cannot see its author listed in the file. Author, please let me know who you are!

void
usage(void)
{
(void)fprintf(stderr,
“usage: chflags [-h] [-R [-H | -L | -P]] flags file …\n”);
exit(1);
}

My favourite program in the source tree right now is hostname; I remember the first time I saw it being struck by how well the various pieces of the operating system fall together to form a cohesive whole. It features a case statement that becomes a cascading case statement. The logic of the program is tiny: In substance it reads:

if (*argv) {
if (sethostname(*argv, (int)strlen(*argv)))
err(1, “sethostname”);
} else {
if (gethostname(hostname, (int)sizeof(hostname)))
err(1, “gethostname”);
if (sflag) {
p = strchr(hostname, ‘.’);
if (p != NULL)
*p = ”;
}
(void)printf(”%s\n”, hostname);
}
I love it for several reasons. It’s simple, it taught me a lot about unix, it’s just plain awesome.

For example, sethostname? Where is that function? Well, it’s declared as: extern int sethostname(char *, int);

Where? Well, use unix to tell you! cd /usr/src && grep -R sethostname *. /usr/src/contrib/gcc/sys-protos.h

Ach, what’m I talkin’ about, anyway. I just like greppin’ code and seeing what there is to be found.

Posted: Wed, 30 Apr 2008 02:58:06 +0000
Tags: freebsd, uncategorized
Comments