oscartheduckin’ around

June 1, 2008

Where’s the damn GSOC Code, dude?

Filed under: Uncategorized — Tags: , — oscartheduck @ 11:51 pm

I was talking to my mentor the other day about having committing code because, let’s face it, FreeBSD has some of the world’s greatest coders writing for it. And I’m terrified and nervous. Because I write crappy code, I know I write crappy code, I’m comfortable writing crappy code, because I never distribute my crappy code.

This last part changed with GSOC. I have to have people able to read my code, I have to distribute the code, all that stuff. And the official SCM is Perforce, but I’m not a huge fan so far. I much prefer git.

So this is the git URL for the code:

git://github.com/jamesh/shinybsd.git

It’s called shinybsd; feel free to track it. If you want to actually commit to the repo, let me know and I’ll help you get set up. Be aware that you’ll need an account on github.com

I’ll be syncing this back up semi-regularly with perforce, so no worries if that’s what you want to watch.

May 3, 2008

ca-ca-catching up

Filed under: Uncategorized — Tags: , , — oscartheduck @ 4:39 am

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.
*/

April 30, 2008

Reading code

Filed under: freebsd — oscartheduck @ 1:58 am

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.

April 21, 2008

GSOC

Filed under: Uncategorized — oscartheduck @ 10:28 pm

http://code.google.com/soc/2008/freebsd/appinfo.html?csaid=AB2F0224F1C4AD72

Yeah. That’s me.

Awesome.

April 9, 2008

person.glow(oscar)

Filed under: Uncategorized — oscartheduck @ 2:10 am

I’ve been writing lots of OOP code of late, after a long stint writing functional programming code, and I’m in this weird space.

On the one hand, it’s interesting writing the code and seeing all kinds of magic appear to happen with almost nothing done. On the other hand, I don’t trust objects to keep track of themselves.

What’s a person to do in this situation? It’s especially bad with java; I don’t expect it to be able to do anything as a language because of its uniformly weird implementation. Having default types which override the types that a programmer enters in the code is _just_plain_wrong_. But java’s also where the employment is right now.

I much prefer ruby. Open classes, isThisBoolean?, uniformly object oriented. It’s plain old gorgeousness on stilts.

For those of you out there clustering away, consider this: to reimage a bunch of nodes without too much hassle, unplug your dhcp server from a switch, plug in a freshly configured SystemImager master box and copy of the dhcpd.conf file, bob’s your uncle you’ve got instant reconfiguration of all nodes. Plug the old dhcp server back in and everything’s ready to rock and roll.

October 21, 2007

(failed)

Filed under: Uncategorized — oscartheduck @ 2:49 pm

I didn’t get 24 pages last night. At 6 AM, with 1 hour to go, I was falling asleep in my chair on page 18.

The problem was that I never really saw how my different stories gelled.  Alas.

But I did work out one of the most subtle ways a comic can be a comic. And exploited it maximally.

Had a fun time, folks. See you next year.

late night entertainment

Filed under: Uncategorized — oscartheduck @ 6:46 am

arse

Filed under: Uncategorized — oscartheduck @ 5:17 am

 I now have 12 pages. I have 45 minutes to write another 5.

I’ve never written something like this. Normally, I see the several ideas I have and I trust that they don’t make sense *now*. but in ten pages time they’ll just gel, and I go with that. This time, it’s. It’s weird.

I mean, it’s fucking weird.

I’m spending half my comic so far apologising for writing about boring topics. There’s really no way to write about source control management and make it interesting.
I should start writing about something else.

hee hee

Filed under: Uncategorized — oscartheduck @ 3:40 am

Name that geek (terrible picture, terrible artist, making it hard)

Where am I

Filed under: Uncategorized — oscartheduck @ 12:25 am

I am not just writing a comic here, I’m also maintaining the server for the 24 hour readathon (a parallel event that started this year), and it recently had a crisis.

It’s been having crises a lot of late. It has bad RAM. I need to buy more for it. But it’s limping along reasonably well, so meh. I’ll buy it in a couple of weeks.

I have written these pages so far. Note the liberal use of NIGHT for entire HALF PAGES.

I’m so fucking behind. But I’m having fun. I will have caught up by midnight, I hope. I’m moving right now from the science fiction story of balls coming to earth to the story of distributed development with git.


These snacks are fuelling me. Delicious!

Though my gas is fucking atrocious.

Older Posts »

Blog at WordPress.com.