Thursday, December 15, 2005
Windows gaming on Linux
Wednesday, November 16, 2005
FreeBSD Wallpaper
Tuesday, November 15, 2005
Sharing Linux swap space
Friday, November 11, 2005
FreeBSD 6.0!
PC-BSD 1.0, rc1
Tuesday, November 1, 2005
New logo for FreeBSD
It's pretty. Mind you, they've gone to great lengths to assure everyone that they have not dropped their mascot:
FAQ: What is the little guy's name?
History of the BSD Daemon
Friday, October 28, 2005
A Programmer's Cautionary Tale
I've been writing code since 1979 (doh!) and writing C (and, later, C++) code since the early 80s. I've seen and written, nearly every possible way you can write bad code. But I'm pretty good about learning from my mistakes, and I like to think I don't make the same mistake twice, once the errors of my ways are pointed out.
But some programming mistakes are just hard to avoid. And that's why we have compilers as our first line of defense. There's lots and lots of code that they just won't allow through, and lots of code they will at least complain about.
Yes, you can use other tools to check your source code. The most common tool that reads C and C++ source code to warn you about dubious constructs is called lint. The problem is, it is a beast to use and a bear to configure, especially if you are trying to run it on already written code. As it is supposed to, lint complains about everything, no matter how trivial a problem it may or may not be. So you spend a lot of time getting its settings so that it reflects how aggressive you want it to be, and you keep doing this. This means it generally isn't used, often to the detriment of better code.
There are many other tools that do lint-like things, and even more. I've used Parasoft's tools and have found them to be very nice. While we were at a local Linux show, we talked to a company that sold a very comprehensive source code analsysis tool.
Each of these commercial tools has a big drawback - cost. At US$1000 and up, they are not minor investments. Now, admittedly, US$1000 is not that much to a company. I get paid a pretty penny to code, as do my co-workers and a US$1000 tool that saved 10 hours of work would begin paying for itself. But it still is a hard thing to justify, as Jack Ganssle talks about. And each takes time to begin using, and to continue to use in order to be most effective.
So the front line of code analysis remains the compiler. It is, after all, the final arbiter of what your code can look like. So we've come to expect some small level of meta-analysis, warning us of dubious code, like unpredicitable side effects, unused variables, using an assignment in an if statement, etc. And, unfortunately, I got bit by a couple of GCC's pecadillos.
GCC is the standard compiler in the Linux, *BSD and Unix world. Freely available, incredibly powerful, it is really just a front end to a whole suite of compilation and linking tools. It has dozens and dozens of options, but the one we're concerned about here is the -Wall, which turns on all warnings, so it will be persnickety about your code. So I gave it some code that looked something like this:
#include <stdlib.h>
const int OK=0;
const int ERROR=1;
const int MAX_RETRIES=3;
int main( int /*argc*/, char* /*argv[]*/ )
{
int rv = CheckSomething();
if ( rv == ERROR )
{ // error return, try to work around it
// ... do some recovery stuff, give up if it doesn't work
}
// ... everything's okay, so carry on
return 0;
}
Everything is fine, and going according to plan. A little later, it turned out that CheckSOmething should be tried a few times before it is assumed there is a problem. So I quickly (ahh, the key word) changed it to be:
#include <stdlib.h>
const int OK=0;
const int ERROR=1;
const int MAX_RETRIES=3;
int main( int /*argc*/, char* /*argv[]*/ )
{
int rv;
for ( int rcnt=0; rcnt < MAX_RETRIES && rv != OK; ++rcnt )
rv = ();
if ( rv == ERROR )
{ // error return, try to work around it
// ... do some recovery stuff, give up if it doesn't work
}
// ... everything's okay, so carry on
return 0;
}
Do you see the problem? At first glance, it looked okay, so off it went. No complaints from GCC, the code worked perfectly and everyone was happy.
Then, months later, I got a complaint that the code wasn't working any more. It wasn't recovering fromthe error correctly. A quick re-scan of the code and sure enough, the problem is pretty evident. But my question then became, why didn't GCC complain about the error? It's a pretty common error, and one that compilers have been warning about for decades. Turns out there are two intertwined reasons that this bug remained hidden under a rock for so long, only rearing its ugly head when the error case cropped up.
- GCC zero initializes automatic variables when built in 'debug' mode, by using the -g flag. Normally, automatic variables (ie., ones that are declared inside the program and are not globals) are not initialized to any predictable value by the compiler; the programmer needs to do it specifically. But GCC sets them to zero, but only when built for debugging, not when you use the optimizer (the -O flag).
- The -Wall flag doesn't warn about using unitialized variables unless the -O flag is used. The man page says:
These warnings are possible only in optimizing compilation, because they require data flow information that is computed only when optimizing. If you don't specify -O, you simply won't get these warnings.
So I got nailed by probably the oldest programming bugaboo in the book - using an "uninitialized" variable. It worked in the normal case, because I was using the -g flag, which set rv to be 0, which, you'll remember is the OK status. So the loop never got executed, CheckSomething is never called, and things continued along their merry way, which is okay unless there is a problem and you want to try to fix it. You'll never know about it.
So the obvious fix is:
#include <stdlib.h>
const int OK=0;
const int ERROR=1;
const int MAX_RETRIES=3;
int main( int /*argc*/, char* /*argv[]*/ )
{
int rv=ERROR;
for ( int rcnt=0; rcnt < MAX_RETRIES && rv != OK; ++rcnt )
rv = CheckSomething();
if ( rv == ERROR )
{ // error return, try to work around it
// ... do some recovery stuff, give up if it doesn't work
}
// ... everything's okay, so carry on
return 0;
}
And now we're golden. We're going to call CheckSomething at least once, and now we'll correctly get the return value for checking later. So the moral of the story is to use -Wall but to be sure to compile the final version with -O to get all the warnings. And to look into getting a C++ code analyzer!
Thursday, October 27, 2005
fortune and fame
Well, it's pretty easy to add your own quote file, but I can never remember how to do it, so I'm documenting it here.
fortune generally reads its data files from /usr/share/games/fortune - all the files that have a '-o' appended are "offensive" ones. You can pass a quote file (soon I'll tell you how to make one) on its command line and it will use that one. The special file name "all" will use all the ones in the "standard" places. Other useful options are -a, to include "offensive" quotes, -e, to consider them all to have equal sizes (otherwise it chooses which file based upon the size of the file), and the -l/-s flags to show only long or short ones.
To build your own fortune file, create a simple text file that has no extension and is a list of strings, separated by a line that has just a '%' on it. It would look something like this:
It's amazing how many people in this world are born at third base,
and think they've hit a triple.
Albert L. Lilly III
%
Eagles may soar, but weasels don't get sucked into jet engines.
Todd C. Somers
%
There is no psychiatrist in the world like a puppy licking your face.
Ben Williams
%
Then run the strfile command on it, which generates a .dat file with indices into this quote file for fortune to use:
$ strfile quotes
So now you can run fortune on this file:
$ fortune quotes
The easiest way to integrate this into the normal fortune lookup is to put it into the /usr/share/fortune directory, but that isn't usually writable by normal folks. This means you need to create an alias to do it:
$ alias fortune="fortune -ae all ~/quotes"
The -a says to include the "offensive" ones, the -e says to chose equally among the files, the 'all' says to include all the standard ones and then I add my own file at the end.
Again, don't forget about the freebsd-tips fortune file:
$ \fortune freebsd-tips
gives you a fortune from the tip file. I used the backslash to avoid the fortune command getting replaced by my alias (all of this discussion assumes you are using bash for a shell). To see if it is working correctly add in the -f flag, which displays the files it will use:
$ \fortune -fae all ~/quotes
___% /usr/share/games/fortune
___% fortunes
___% fortunes2
___% freebsd-tips
___% murphy
___% startrek
___% zippy
___% fortunes2-o
___% limerick
___% murphy-o
___% fortunes-o
Again, note the backslash to "quote" the f, so that alias expansion doesn't happen. It's a nice little shortcut if you think an alias is getting in the way.
For some reason, the FreeBSD.org man pages on the web, found at FreeBSD Hypertext Man Pages don't have the 'fortune' - probably a bug.
strfile
Tuesday, October 25, 2005
New PC-BSD release
PC-BSD - Personal Computing, served up BSD Style!
Tuesday, October 18, 2005
portaudit
FreshPorts -- security/portaudit
Wednesday, October 12, 2005
grep help
- a better directory recall
- The '...' (and beyond) facility for changing directories upwards an arbitrary number of parents
- a directory database
- A much easier to use "FOR" facility from the command line
- The FFIND /S command, which recursively searches for text in files
I knew about grep's -R flag, but found it hard to use and couldn't figure out how to recursively search just .h files, for instance. I finally broke down and read the man page, and here's what I found out.
To recursively search for something, you can use the -R flag to grep:
$ fgrep -R BIGENDIAN .
To recursively check just .h files:
$ fgrep -R --include="*.h" BIGENDIAN .
Where:
fgrep - "fast" grep. You can use this if you don't use any regexps in the search pattern
-R - recursively search folders, starting with this one (.)
--include="*.h" - just include *.h files. You need to put the quotes around the wildcard, or the shell will try to expand it and it won't work like you think. That's why you can't just do:
$ fgrep -R BIGENDIAN *.h
It will still just search local .h files, because the shell expands the wildcard before fgrep gets it. So if there are two .h files in the current directory, the command looks like this after the shell gets done with it:
$ fgrep -R BIGENDIAN foo.h bar.h
You can add multiple --includes, and there's even a --exclude you can add to exclude files of that pattern from the search.
grep man page
Tuesday, October 11, 2005
/dev/random
Thursday, October 6, 2005
New Freebsd.org home page
Still, it's a pretty clean looking layout, and maybe my original shock will give way to a grudging acceptance.
Drupal
drupal.org | Community plumbing
Port description for www/drupal
Monday, September 26, 2005
*BSD vs. Linux
GTK Theme selector
Fancy GTK+ apps
Fancy nicer looking GTK+ apps? Apps that fall into this category include Firefox and Thunderbird. Simply run the following command from a console (as root) and restart your x session:
# pkg_add -r gtk-qt-engine
Of course, if you're like me, you'll probably want to make it from the source:
# cd /usr/ports/x11-themes/gtk-qt-engine
# make && make install && make clean
According to the FreeBSD ports page:
GTK-QT Theme Engine allows GTK2 apps to use QT (KDE) themes
More PC-BSD
Anyway, a little update on my BSD follies. I still have my KVM mouse problems (sigh), but I've gone and plugged in another mouse to this box in order to get around them. My PC-BSD install went pretty smoothly, but then I ran into the above mentioned 'mountroot' problem. It seems to be trying to get the OS from the wrong slice (partition). Luckily, I barely remembered both where I installed it and the nomenclature for specifying it. I think they are having a problem with it defaulting to one (ad1s1a) no matter where you actually installed it (in my case, ad6s1a). It's 'ad6' because this is such an old box, it has a funky "fast" controller, back in the days when a UDMA 66 was fast, that isn't part of the normal 4 IDE controllers.
Anyway, I get the following error when I boot PC-BSD:
Mounting root from ufs:/dev/ad1s1a
setrootbyname failed
ffs_mountroot: can't find rootvp
Root mount failed: 6
Then it gives me a little info on how to use the manual input portion of mountroot (whatever that is - it isn't documented in the handbook as far as I can tell). By using the '?' command, I get a list of the possible boot devices, and there I can see 'ad6s1a', which is the 'a' (root file system) partition (in BSD speak) of the first slice (s1) of the 7th IDE device (like I said, it gets put way past the normal 0-3 due to the funky controller). So, if I type in:
mountroot> ufs:ad6s1a
I'm off and running.
But I'm also downloading this 0.8.2 version. I will start again from scratch. I have a big hard drive (120gb) empty, so I can play there. I will probably continue to try out PC-BSD, so as to keep my hand in the BSD game, despite the wickedly annoying KVM problem.
Development Release: PC-BSD 0.8.2 (Beta)
Thursday, September 22, 2005
Blob meme - report on an old post
Rules:
- Go into your archive.
- Find your 23rd post (or closest to).
That would be from June 2003, FreeBSD Splash Screens - Find the fifth sentence (or closest to).
- Post the text of the sentence in your blog along with these instructions.
This page has lots more splash and desktop screens, including some vaguely erotic and futuristic BSD Daemons:
Tuesday, September 20, 2005
DesktopBSD - Yet Another BSD Distro
I still haven't had much luck with my KVM switch. PC-BSD just doesn't seem to recognize the mouse, and DragonFly BSD seems to rudimentary to play with. It's a long-standing problem with FreeBSD for some reason - it just doesn't see a mouse when it is hooked up via a KVM switch. Looking back through my notes here, I see where I once got FreeSBIE to work by jiggling when X start up, but I can't seem to even get that to work any more :-(
Anyway, here's Yet Another BSD distro, called DesktopBSD. I'll give it a shot...
DesktopBSD: Home
Monday, September 19, 2005
New PC-BSD release
Anyway, they just came out with version 0.8 of PC-BSD, so that's the one I'm going to go with. I downloaded the ISO and I'm ready to burn!
PC-BSD - Personal Computing, served up BSD Style!
Updated: : As a quick followup, there is now a 0.8.1 release.
Friday, September 16, 2005
FreeBSD Boot process
This is a description of the boot process in the man pages. Start here, read it and check out the "See Also" links: boot
Here's how to tell the boot loader the options to use and even the kernal to load the next time you restart the system: nextboot
The final stage of the "bootstrap", is the loader(8)
If you use the builtin boot manager, you can use this program to configure it: boot0cfg(8)
Thursday, September 15, 2005
Server Monitoring
Anyway, I guess I should search my own archives, as I already have a post that describes two of them (Nagios and Big Brother):
Monitoring Programs
There are two others I should look into:
Wednesday, September 14, 2005
FreeBSD Snapshots
Postfix help
Automounting
One thing I'd be wary of is that this is a file that is 3 years old at this point. I haven't used amd all that much, and I haven't read this file over carefully, but you need to make sure the information isn't obsolete. I've added links to the handbook and man pages for the appropriate tools, so you might want to start there and only use this file if you have additional questions.
Fun With Automounting on FreeBSD
Here are the appropriate FreeBSD Handbook (the first place to go when you have questions) and man page entries:
Network File System (NFS) - 24.3.4 Automatic Mounts with amd
amd(8)
amq
amd.conf(5)
Monday, September 12, 2005
Ultimate Boot CD
Thursday, August 25, 2005
Seeing all processes
alias ps='ps -afuxww'
This shows all (-a) processes, swapped (-f, but only as root) processes, lots of information (-u), include "headless" apps, like daemons and the like (-x), and do it as wide as you can get (-w says 132 columns, -ww says use it as wide as you need).
Turns out, there are a couple of sysctl options that make ps more secure by not allowing "normal" users to show everything that is running. One of them is mentioned in the man page, security.bsd.see_other_uids (see the entry for the -a option). Kevin on the freebsd questions mailing list gives a cool little demo for setting and unsetting it from the commandline:
# sysctl -a | grep other_uid
security.bsd.see_other_uids: 1
# sudo sysctl security.bsd.see_other_uids=0
security.bsd.see_other_uids: 1 -> 0
# sysctl -a | grep other_uid
security.bsd.see_other_uids: 0
# sudo sysctl security.bsd.see_other_uids=1
security.bsd.see_other_uids: 0 -> 1
# sysctl -a | grep other_uid
security.bsd.see_other_uids: 1
But that's a 5.x option. The 4.x option is kern.ps_showallprocs - pretty straight forward name there. And to set this so that it gets correctly set every boot time, you put it in the /etc/sysctl.conf file:
kern.ps_showallprocs=1
ps (5.x)
ps (4.x)
Wednesday, August 24, 2005
Yet Another Boot Manager
This is different than an emulator like Virtual PC or, even better, VMWare. Emulators run like just another program, and can bring the buffest hardware to its knees.
By using a boot manager, you can get a truly pristine setup. FreeBSD has its own boot manager - most non-Windows OSes will install their own, allowing you to choose between the dark side and the side of light and goodness. But the native ones are generally pretty basic, and don't give you things like partition managers, wizards, graphical interfaces, etc.
I've used a couple in my time. I used to be a huge fan of System Commander. I used it from version 1 up until last year, and was very happy with it. Easy to use, very smart, a great product.
But last year I started running into plenty of problems with it. The display would be garbled, and it just wouldn't work. I got less than satisfactory help from the VCom folks, so I started looking around.
Now I use BootIt NG from Terrabyte Unlimited. A shareware product that has worked very well for me. It's a little less easy to use, but has proven to be very powerful. While you're at the site, be sure to check out other, Windows, freeware utilities like BurnCDCC, which is a very easy to use ISO burner.
There are some freeware ones out there too. Grub is a standard one in the Linux world.
Here is GAG, a freeware one. I'll give it a shot on my test machine and see how it does:
The home page of GAG - main
Emacs delete key
It's not quite as important now for me, because I use a terminal program to connect to my remotely hosted box now, and it does the remapping for me.
Anyway, there's a function that plays some serious games with this and does it in a simpler way than mucking about with the translate table. Check out 'normal-erase-is-backspace-mode' - very interesting routine.
Man, Emacs has almost as many nooks and crannies as FreeBSD!
Monday, July 18, 2005
Cable modem tricks
However, the cost was pretty steep (US$200 per month), even if my company was paying for it. Now that cable modems are up to 768kpbs upload speeds (and 6mb down!), for about $50 a month, the switch was pretty much a no brainer. I've always told folks that asked that cable is, in general, a much more economically feasible broadband alternative than DSL. For the same speeds, DSL is generally twice as much. Plus you have to deal with two or three different folks (Speakeasy was my provider, Covad did the work and it was actually Verizons "copper" wire in the end).
But I miss Speakeasy. I got some cool perks (free download service, game server time, etc), as well as 4 static IP addresses. For reasons unknown to me and even to folks who know a million times more than me, cable companies have always gone with a dynamic IP address. While it almost never seems to change, they are free to give you a different IP address at any time. So running servers and the like is a little more difficult. You can go with a dynamic dhs host (I used to use TZO), it's still much more of a pain. Speakeasy was very server friendly. Instead, I relocated my servers to my friend's ISP (MV.COM if you're interested), and solved all kinds of problems that way!
Anyway, here's a cool page with lots of cable modem tips. I recently found out that the IP address 192.168.100.1 connects to my cable modem and shows some basic info about it. That's easy and this page shows even more stuff like that.
Monday, July 11, 2005
Practice Healthy Computing
Script for setting up internet sharing
IPFilter "automagic' script for FreeBSD / Roq.com
Sunday, July 10, 2005
More on upgrading perl
Friday, July 8, 2005
Playing A Little Night Music
$ chmod 666 /dev/acdo
To make this a more permanent change, add this to /etc/devfs.conf:
perm acd0 0666
so it will set the correct permissions at boot.
Reinstall boot manager
1) Do as root "sysctl kern.geom.debugflags=16"
2) Start sysinstall
3) Go Configure->FDISK-> "OK" -> Q
4) It will ask if you wish boot manager
5) Select BootMgr
Thursday, July 7, 2005
Don't fsck me
Wednesday, July 6, 2005
I can hear your heartbeat
Thursday, June 30, 2005
What are "Load Averages"?
Upgrading Perl
20050624:
AFFECTS: users of lang/perl5.8
lang/perl5.8 has been updated to 5.8.7. You should update
everything depending on perl. The easiest way to do that is
to use perl-after-upgrade script supplied with lang/perl5.8.
Please see its manual page for details.
In other words:
run "perl-after-upgrade" (note the remarks)
run "perl-after-upgrade -f" (to make the changes)
Tuesday, June 28, 2005
Syncing /usr/ports
- Use rsync for /usr/ports from the fast machine to the slower machine.
- Use pkg_create's -b option, then use those packages on the other machine(s).
Stop package from upgrading
Answer:
- Use the '-x' option
- Long term solution - HOLD_PKGS in /usr/local/etc/pkgtools.conf
Thursday, June 16, 2005
Keeping FreeBSD up to date
TaoSecurity: Keeping FreeBSD Up-To-Date
Friday, April 29, 2005
Tuesday, April 5, 2005
HZ Value
On Mon, Apr 04, 2005 at 11:17:19AM +0200, Dick Hoogendijk wrote:
>> I read about polling and HZ=1000. The latter is not high enough for
>> vmware3 (it complains..). I read 'man polling' and learn something about
>> this, but I really want to know more about 'hz=1000'
>>
>> The GENERIC has hz=100 as I recall (fbsd-4.11). Can somebody explain I
>> "human language" what happens if you raise this HZ? Is there a processor
>> related issue here? What exectly happens if you have 'hz=1000' or is it
>> maybe better to have 'hz=2000' ? I can't decide now because I don't
>> understand what happens.. So, anybody?
This is the frequency of the heart beat. Superficially, every 1/HZ second,
a clock tick happens and the kernel is invoked. Then stuff like cleanup and
scheduling a new thread happens (this is not the only time when threads
get scheduled though).
HZ=100 is good enough for most purposes. If the kernel needs to poll
some data faster and more frequently, you can crank up HZ to 1000 or
even higher. A system with higher HZ is usually also more responsive,
but this comes at a price:
* The overhead is higher (you need more time to do internal housekeeping,
and there's less time available for userland threads)
* Processor caches are flushed more frequently, resulting in slower
RAM access.
A high value for HZ is also not a good idea for slow(er) hardware
either.
Interestingly, HZ=100 has remained constant for decades (!), despite
CPUs getting faster all the time. This is an excellent value for most
typical usage patterns. Cranking it up should only be required for
special cases. Anyway, the HZ knob is there. Experiment with it until
you get optimal performance.
Tuning your FreeBSD installation
Friday, April 1, 2005
Yet Another FreeBSD page
Tuesday, March 29, 2005
Installing 5.3
Here's what I've found so far:
- Of course, you need to start here : Installing FreeBSD, which is the installation guide from the FreeBSD.org handbook.
- Installing FreeBSD 5.3-RELEASE
from the Colorado State engineering department's very useful looking FreeBSD Guide.
FreeBSD Stable Release Install Guide : It is a 4.9/4.10 install guide, but it is very well done.
I'll add any more links I come across to this entry.
FreeBSD Guide page
Live CD list
Trying 5.3 again
Sunday, March 27, 2005
Wiki overview
Saturday, March 12, 2005
More IPFiltter help
Firewalling with FreeBSD and IPF
Of course, don't forget the handbook page:
Firewalls
And your local examples found at:
/usr/share/examples/ipfilter/
Friday, February 18, 2005
The Fish - an rc.conf editor
The Fish for FreeBSD
Cool Hacks post
ONLamp.com: FreeBSD Tips and Tricks for 2005