Librenix
Headlines | Linux | Apps | Coding | BSD | Admin | News
Information for Linux System Administration 

How to customize your Linux system

Up
vote
Down

Ubuntu, Arch, Suse, and Linux from Scratch are covered in this multi-page article...
You can install and remove packages as and when you want to, and you can choose whether to install free or non-free software on your system. Why should you have to live with community decisions when you can make Linux work your way?

However, the distribution you install will likely contain drivers and components that you don't really want or need on your system.
read more...
permapage | score:9299 | -Ray, December 4, 2009

Missing the point of the Mac Mini

Up
vote
Down

I've read several articles and numerous comments over the past week detailing just how overpriced Apple's new Mac Mini is. Reviewers seem to conclude that because they can assemble a PC of similar performance to the Mini for less money, that the new Mac simply costs too much.

What they have not done, however, is duplicate the Mac Mini in any important way. The closest comparison I've seen pitted the Mini against a machine 2.5 times its size. At least that reviewer understood that size matters. I'm a fan of small systems. I own 2 Biostar iDEQ cubes, one Shuttle, and three Book PC's. The Book PC's are the oldest and most obsolete, of course, with the fastest one containing a Pentium III 667. I've gotten rid of several systems over the past two years that were faster than the Book PC's. Why keep the slower computers while getting rid of systems up to twice as fast, you might ask.

I've kept the Book PC's because they are so small that keeping them around isn't a burden. They take about as much space on a bookshelf as an unabridged dictionary. I have one, currently disconnected, functioning only as a monitor stand for the system I'm using right now. A book PC will fit in my briefcase; I've hauled them around with me as if they were laptops. With a dozen computers around the house, space is precious and small is beautiful.

The Book PC's are 3.2" x 10.5" x 11.9". That's 4.8 times the volume of a Mac Mini. The Mac is truly tiny. I've worked to build fast, small, quiet Linux systems for years now. The iDEQ 200V is the cheapest system I've made that is fast, quiet, and runs Linux without complaint. Without software and with only the on-board graphics chip, it cost about the same amount as the Mac Mini. At 12.5" x 7" x 8", however, it is much larger than the Mini and weighs several times as much.

I challenge the anti-Mini crowd to build a PC of any shape that displaces approximately the same volume as the Mini plus power supply. Then, compare prices again. The SFF computer fans are clearly going to notice this machine and are going to buy a few truckloads of them. In the small form factor (SFF) computer market, even ignoring the software, this machine is clearly a bargain.

SFF computer fans who are committed to Windows will still covet this system; a few of them might even make the switch to OS X just to get one. I even expect some SFF Linux geeks to buy them because they're tiny, cheap, and can run Linux. Conclusion: the anti-Mini reviewers and posters are not SFF people.

Next, the Mini is an affordable and typically stylish Mac. A smallish PC does not run OS X. The Mini comes with OS X and will make a great second (or third) computer for many Mac users. I use Linux as my primary desktop OS (SuSE 9.2 Professional for the last three weeks, Fedora Core 2 the previous year) and FreeBSD and Linux (Fedora, Slackware) for my servers. I'm hardly a Mac guy but, as a Unix geek, I'm perfectly fine with OS X. I used a Mac as my primary desktop for a couple of weeks after a recent move.

Many Mac users -- at least those who need a second system -- will find the price -- and the size -- of this system quite appealing. Clearly, the negative reviewers and posters are not OS X users.

Therefore, I've come to the conclusion that these anti-Mac Mini arguments are coming from people who appreciate neither of the core characteristics of the machine. They don't understand the appeal of the SFF systems market, nor are they OS X / Mac users.

Apple, on the other hand, appreciates both and they have produced an impressively priced small form factor OS X system.

I wish for Apple responsive suppliers with scalable production facilities. They will surely need them in order to satisfy the demand for the Mac Mini.
mail this link | permapage | score:9283 | -Ray, January 21, 2005

Top BSD distributions

Up
vote
Down

Here are the top five BSD's...
As some of you may know, Linux is not the only Unix-like operating system available. There are other UNIX derivatives, and one of the most popular among them is called BSD. If you have been to Distrowatch, you will see different BSD distributions listed in there.
read more...
permapage | score:9247 | -Ray, April 5, 2009

Benchmarks: FreeBSD 8.0 vs. Solaris vs. Linux

Up
vote
Down

FreeBSD 8.0 takes on Fedora 12 and Ubuntu 9.10 as well as OpenSolaris 2010.02 b127 in a performance free-for-all..
The hardware we are using for benchmarking this time was a Lenovo ThinkPad T61 notebook with an Intel Core 2 Duo T9300 processor, 2GB of system memory, a 100GB Hitachi HTS72201 7200RPM SATA HDD, and a NVIDIA Quadro NVS 140M graphics processor powering a 1680 x 1050 LVDS panel.
read more...
permapage | score:9241 | -Ray, December 1, 2009

Ubuntu 11.04 Preview

Up
vote
Down

An early look at the next release of Ubuntu Linux...
Ubuntu 11.04 (Natty Narwhal) Beta 1 is powered by Linux kernel 2.6.38, GNOME 2.32.1 and X.Org 7.5. It will included applications such as LibreOffice 3.3.2 as the default office suite, Banshee 1.9.4 as the default audio player/organizer and Mozilla Firefox 4.0 as the default web browser.

A set of seventeen new and beautiful wallpapers will also be present in the Beta release, to please every Ubuntu user out there. And now, the features we've promised...
read more...
mail this link | permapage | score:9224 | -Ray, April 1, 2011

The best lightweight Linux

Up
vote
Down

A subjective assessment of several leading small-footprint Linux distributions...
In selecting our shortlist, we've left out some contenders either because they didn't support older processors, they wouldn't install in 4GB or less of space, they simply didn't work on our hardware or they're no longer being maintained (as is the case for both RULE and U-Lite). The one exception to this is Damn Small Linux - although it has been over a year since the last release, and the homepage is as quiet as the LXF office at 9.30 on a Monday morning, this is still such a widely used and influential project that it was considered worthy of inclusion.
read more...
mail this link | permapage | score:9223 | -Ray, April 11, 2010

How to install Ubuntu Linux on the decTOP SFF computer

Up
vote
Down

I recently bought a decTOP small form factor (SFF) computer. My goal was to build a cheap, fanless, quiet, and low power consumption Linux server. For $99 plus the cheapest available shipping, $40, my machine arrived 11 days after I placed the order.

This is a tiny computer, about the size of a Mac Mini. But, because it has no fan, it runs a bit quieter and, with the help of a 1-watt, 366 MHz CPU, consumes only 8 watts. For comparison, the G4 Mac Mini consumes about 20-30 watts, depending on load.

The decTOP comes with 128 MB of RAM in its sole SO-DIMM slot and a 10 GB 3.5 inch hard drive. I understand that it's a simple matter to replace the drive and to upgrade the memory to a maximum of 512MB.

It also comes with no operating system and the ability to boot only from a USB drive. This article details the steps I used to build the USB boot/installation drive and install Ubuntu 6.06 on the decTOP.

There is another article -- with additional decTOP links -- here on installing Ubuntu 6.06 on the decTOP with the aid of a Windows system. Fortunately ;), I run Mac OS X and Linux (Ubuntu 7.04), so that article didn't work for me. I did the installation of the Ubuntu 6.06 LTS Server Edition using my Ubuntu Linux box and a 1 GB USB flash drive -- although a 512 MB USB drive should work as well.

  1. Download the Ubuntu 6.06 server ISO image from the Ubuntu download page. Depending on your plans for the decTOP, you might want to choose the desktop version. Unless you have already upgraded your decTOP's memory, however, you'll want to stick with the 6.06 releases.

  2. Install the mbr, mtools, and syslinux packages on the Linux system you'll be using to prepare the USB drive. If you run Ubuntu or some other Debian-derived system, the following commands may do the work for you.
    apt-get install mbr
    apt-get install mtools
    apt-get install syslinux
  3. Partition the USB drive with a single FAT-16 partition. I used the fdisk 'n' command to make the new primary partition 1. The fdisk 't' command can be used to change the partition type to FAT-16. My device name was /dev/sda.
    fdisk /dev/sda
  4. Make the FAT-16 partition the active partition. I used the fdisk 'a' command.

  5. Install a master boot record on the USB drive.
    install-mbr /dev/sda
  6. Install syslinux on the USB drive. Note that the USB drive should not be mounted when you do this.
    syslinux -s /dev/sda1
  7. Create a mountpoint and mount the ubuntu ISO image using the loopback device.
    mkdir /iso
    mount -o loop -t iso9660 ubuntu.iso /iso
  8. Create a mountpoint and mount the USB flash drive.
    mkdir /usb
    mount /dev/sda1 /usb
  9. Copy the contents of the ISO image to the USB drive. This will take some time.
    cd /iso
    cp -r . /usb/
  10. Copy the /usb/dists/dapper directory into a new /usb/dists/stable directory.
    cd /usb/dists/
    cp -r dapper/* stable
  11. Copy several files from /usb/install to the /usb root directory.
    cp /usb/install/vmlinuz /usb/
    cp /usb/install/mt86plus /usb/
    cp /usb/install/initrd.gz /usb/
  12. Install the following text into a file named syslinux.cfg in the /usb root directory.
    default vmlinuz
    append initrd=initrd.gz ramdisk_size=24000 root=/dev/ram rw
  13. Flush all writes, unmount, and remove the USB drive. After the sync step, wait for all of the data to be written to the USB drive.
    sync;sync
    umount /usb
  14. Connect the ethernet adapter to the decTOP and connect it to your network to allow automatic configuration of the network interface.

  15. Insert the USB drive into the decTOP and power it up. The decTOP should automatically boot from the USB drive and start the Ubuntu installation.

  16. Answer only the first two questions concerning language selection and go to the next step, below.

  17. Press Alt-F2 (hold down the Alt key and press the F2 function key) to open a shell. Then press enter to start the shell.

  18. Create a /cdrom and a /dev/cdroms directory in the installation ramdisk
    mkdir /cdrom /dev/cdroms
  19. Go to the /dev/cdroms directory and build a symlink from /dev/sda1 (that is likely the device name of your USB boot partition) to /dev/cdroms/cdrom0.
    cd /dev/cdroms
    ln -s ../sda1/cdrom0
  20. While still in the shell, mount the USB drive to mimic an installation CD-ROM.
    mount -t vfat /dev/cdroms/cdrom0 /cdrom
  21. Return to the installation program with Alt-F1 and continue the installation.

From this point, the process should be identical to a routine CD-ROM installation.

For a grand total of $140 and 8 watts of power consumption, I now have a near-silent Linux server running 24/7. You can telnet to it here and marvel at its blinding speed running a 250,000-sector Space Tyrant game.

mail this link | permapage | score:9221 | -Ray, August 16, 2007 (Updated: April 26, 2011)

perl1line.txt: A handy Perl script collection

Up
vote
Down

The ultimate goal of the Perl One-Liners Explained article series was to release the perl1line.txt file. Last week I finished the series and now I am happy to announce perl1line.txt - a collection of handy Perl one-liner scripts.

The perl1line.txt file contains over a hundred short Perl one-line scripts for various text processing tasks. The file processing tasks include: changing file spacing, numbering lines, doing calculations, creating strings and arrays, converting and substituting text, selective printing and deleting of certain lines and text filtering and modifications through regular expressions.

The latest version of perl1line.txt is always at:
http://www.catonmat.net/download/perl1line.txt
Enjoy! It took me over 3 years to write all the one-liners down. read more...
mail this link | permapage | score:9219 | -pkrumins, November 21, 2011

Python for Kids

Up
vote
Down

A series of Python tutorials for children (or programming newbies) in a blog format. The article linked below implements a stand-alone Python program.
In the last tutorial we created a file using our text editor and saved a function to it. This file was called trivia.py and in it was the module “trivia”. We then started Python in a console and import()ed the trivia module. Once imported, it created a “namespace” and we could access the askQuestion() function from within the trivia namespace by using a dot – trivia.askQuestion(). In order for the module to work properly we had to include an import statement within the module itself so that everything that the module relied upon was imported within the module. We then manually loaded our data from a pickle file we created and, manually, ran the askQuestion() function on the first question in our data store. Finally we added docstrings to the function and the module.

In this tutorial we’re going to try to do much the same thing again, but without using the Python interpreter. That is, we will need to take the things we did in the interpreter and implement them in our trivia.py file. We will have a functioning (although still quite simple) stand alone Python program.
read more...
mail this link | permapage | score:9214 | -Ray, May 19, 2011

MiniLesson: An introduction to Linux in ten commands

Up
vote
Down

This tutorial is the first in a series of introductory Linux lessons. This first article will cover navigating around a Linux filesystem along with a brief passage -- with examples -- on using ten of the most essential GNU/Linux commands.

You should have access to a Linux system in order to perform the example commands as we progress through the tutorial. If you don't have a dedicated Linux box, you can use a Live Linux CD-ROM-based distribution such as Knoppix. Knoppix will let you run Linux directly from the CD without modifying anything on your hard drive.

Once you're logged in to a Linux system, open a terminal session. Each of the commands covered here will be typed directly into a command line terminal window. Under Red Hat Linux, terminal is found in the 'system tools' section of the menu. (Your system may, alternatively, have a terminal program called 'konsole', 'xterm', or 'shell'. Look around your system for a menu with 'tools' or 'utilities' in the name if necessary.)

pwd
The first command we will use is 'pwd' -- which stands for 'print working directory'. The pwd command shows you your current position within the Linux filesystem. The position is known as your 'current working directory'. Type pwd now. The example below shows my command prompt and the pwd command followed by the output from the pwd command:
 [rayy@barton0 rayy]$ pwd
/home/rayy
[rayy@barton0 rayy]$
From the output (/home/rayy) we can tell that I am in my 'home directory' -- the directory where I keep my personal files and the directory where I always start out in a new session.

ls
The ls command lets you list files. For example, here is the (shortened) output of an ls command on my system:
 [rayy@barton0 code]$ ls
artdir countdir machine
tsardir sortdir
[rayy@barton0 code]$
Alternatively, you can get a 'long listing' that shows file sizes, timestamp, ownership, and permissions as follows:
 [rayy@barton0 code]$ ls -l
drwxr-xr-x 2 rayy rayy 4096 Feb 3 2002 artdir
drwxr-xr-x 2 rayy rayy 4096 Feb 3 2002 countdir
drwxr-xr-x 2 rayy rayy 4096 Feb 3 2002 machine
drwxr-xr-x 2 rayy rayy 4096 Feb 3 2002 sortdir
drwxr-xr-x 2 rayy rayy 4096 Feb 3 2002 tsardir
[rayy@barton0 code]$
You can also supply a target directory to the ls command. For example, to view the contents of the /tmp directory, I enter the following:
 [rayy@barton0 code]$ ls /tmp
flp kde-rayy mcop-rayy
[rayy@barton0 code]$
For more information on the ls command you can reference the manual page for ls with the following command:
 [rayy@barton0 code]$ man ls
cd
This next command, 'cd', lets you change your current working directory. for example, you can change your current working directory to /usr/bin by entering the following command:
 [rayy@barton0 rayy]$ cd /usr/bin
[rayy@barton0 bin]$
Note that after I entered the cd command, my command prompt changed to reflect the change in the last node of my current working directory. Your command prompt may not be configured to do that.

Change your current working directory to /usr/bin now and enter the ls command.
 [rayy@barton0 code]$ cd /usr/bin
[rayy@barton0 bin]$ ls
addr2line mcheck
addr2name.awk mcomp
addresses mcookie
.
.
.
[rayy@barton0 bin]$
The preceding is a partial listing. There are many, many files in the /usr/bin directory on most Linux systems.

file
If you have a background in Windows or are familiar with DOS, you are used to file extensions that signify the file type. Linux (and Unix) have no such requirement. That is, an executable program can be named anything. Therefore, a handy command is supplied with Linux named 'file'. For example, I have a file named 'sample.c' in my code directory. I can learn a bit about that file by entering the following command:
 [rayy@barton0 code]$ file sample.c
sample.c: C++ program text
[rayy@barton0 code]$
Alternatively, I can use the '*' wildcard -- which represents all filenames -- to examine all of my code files at once. The following is a shortened example:
 [rayy@barton0 code]$ file *
bbsdir: directory
code.tar: GNU tar archive
genart.c: ASCII C program text
sample.c: C++ program text
xor: ELF 32-bit LSB executable
[rayy@barton0 code]$
The file command can be very useful to avoid minor annoyances -- such as when using one of the following three commands.

cat
The cat command is useful for concatenating multiple files -- or just for dumping a single text file to the screen. Before you use the cat command to dump a file to the screen, use the file command to make sure it's some variety of text file such as ascii text, commands/text, C source code, html/text, etc. The following is a shortened example of using file and cat to identify and dump a text file:
 [rayy@barton0 code]$ file xor.c
xor.c: ASCII C program text
[rayy@barton0 code]$ cat xor.c
main()
{
int x;
unsigned char buff[128],
.
.
.
[rayy@barton0 code]$
more
The more command is useful when a text file is larger than a single screen. The following is a shortened example of using more to view a large C program:
 [rayy@barton0 code]$ more xor.c
main()
{
int x;
unsigned char buff[128],
.
.
.
printf("n%sn",buff1);
printf("n%sn",buff2);
}
--More--(29%)
Note the '--More--(29%)' at the end of the screen. That means that 29% of the file is above that line, implying that another 71% of the file is below. Press the space bar to page through the file, a screenful at a time. Press the b key to back up. If you finish looking before reaching the end of the file, press the q key to quit.

grep
The grep command, short for 'get regular expression and print', is useful for finding occurances of a particular string in a text file. To find the 'printf' statements in the example C program above, enter the following command:
 [rayy@barton0 code]$ grep printf xor.c
printf("n%sn",buff1);
printf("n%sn",buff2);
[rayy@barton0 code]$
The grep command has far more capability than I describe here and, as usual, enter
 [rayy@barton0 code]$ man grep
for more information.

cp
The cp command will let you copy files. Unlike the commands used above, this one includes a hazard; if you copy filename1 to filename2 and filename2 already exists, you will destroy the original filename2 file. Use cp with caution!

To make a duplicate copy of my xor.c file I could enter the following command:
 [rayy@barton0 code]$ cp xor.c xor.c.bak
[rayy@barton0 code]$ ls xor.c*
xor.c xor.c.bak
[rayy@barton0 code]$
Note that the cp command returned no output -- I had to enter an ls command to see the results of the copy. [By adding the * wildcard to the original filename, I asked for a listing of all files that started with xor.c -- including those with no additional characters in the name.]

rm
The rm command is used for removing files. To remove the duplicate file I created in the cp command example, I would enter the following:
 [rayy@barton0 code]$ rm xor.c.bak
[rayy@barton0 code]$ ls xor.c*
xor.c
[rayy@barton0 code]$
Again, note the absense of any feedback from the rm command. I had to enter an ls command to verify that the xor.c.bak file had really been removed.

As with other commands, rm can remove multiple files at once when used with wildcards or with the -r (recursive) option. See the man page for more information on rm.

mkdir/rmdir
Ok, this is really two commands, but they are complementary. Use the mkdir command to make a new directory and use the rmdir command to remove an empty directory. For example:
 [rayy@barton0 tmp]$ mkdir testdir
[rayy@barton0 tmp]$ ls
testdir
[rayy@barton0 tmp]$ rmdir testdir
[rayy@barton0 tmp]$ ls
[rayy@barton0 tmp]$
In the preceding series of commands I first created a new directory named 'testdir'. I then used the ls command to verify its presence. Then, I removed 'testdir' and verified that it was gone by using ls again.

For more information on the commands covered in this article, take a look at the general commands man pages over at the LinuxQuestions.org website.
mail this link | permapage | score:9207 | -Ray, February 19, 2004 (Updated: April 18, 2007)

Space Tyrant Index Page: Linux game server development project

Up
vote
Down

This page links to the various articles that have been published about Space Tyrant, a multithreaded, network socket programming Linux game server project in C.

[Update: 07Jun2014 You can play a development version of an upcoming MMORPG in text mode at telnet://textMMOde.com:2323
or, on a command line, enter:
telnet textmmode.com 2323
to log in and play. This game is based on Space Tyrant and the scenario is based on a modified Starship Traders.]

[Update: 03Jun2014 Starshiptraders, the parent of Space Tyrant, and the descendant of Czarwars, Lives Again]

Read below for the history and overview or just click these links for the articles:Space Tyrant is a C language Linux game server development project. It started out in February, 2005 as a humble echo server with high ambitions. On March 18, ST had its design and intentions announced to the world.
Today we kick off a new multithreaded, network socket programming project which we will call Space Tyrant. Our mission is to write an open source, multiplayer, networked, strategy game in the C programming language. The goal of this project is to make a solid code base which implements a simple space trading game upon which other games can then be built. The game will be a subset of The Last Resort (TLR) that currently runs at Ioresort.com. This project will be a learning exercise for me as well as for any interested readers. The current state of the source code will be released with each article update.
Source code to ST, then just an echo server, was not released.

Then, on March 27, 2005, ST was promoted to a crude chatserver.
This is the first code release of Space Tyrant. This is an early stage of development and, at this point, only implements the listening thread, the two IO threads for each player connection, and a skeletal game logic thread that does little beyond proof-of-concept code.
Next, on May 30, 2005, ST started to resemble some sort of incomplete text game.
It’s now possible to connect to the game via telnet and to create an account, log in, and be issued a ship. Once you’re logged in, there is a universe to explore filled with ports for buying and selling goods and planets for scooping free goods. From those trading activities you can earn money, called microbots. Other than trading to earn more money, you only use your microbots to buy fighters -- which you can use to attack other players or the neutral fighters that guard some sectors.
As of this release, the source code was placed under the GPL, version 2.

On June 26, 2005, Space Tyrant was released with many shiny new abilities. Players can now deploy fighters to guard sectors, navigate with the aid of an autopilot, rank the various players in the universe, and sleep peacefully knowing their alternate universe is being backed up constantly by a sporty new backup thread. Yes, good times are surely upon us.
If you’re looking for a planet, type the ‘L’ command that you would normally use to land on a planet in your sector. In the absence of a planet, the L key will engage the autopilot which will search for the nearest planet and give you a ‘/’ command to autowarp to it.
There is normally a copy of the development version of the server running on my decTOP on port 23. To access it, type (or click, if it works for you) the following command:

(telnet to my ST server)

The current development version of the code is usually at http://librenix.com/st/st.c but the individual articles link to the specific versions discussed in each article.

You can mail me about the project at spacetyrant [at] librenix.com -- or you can just telnet into Space Tyrant, as listed above, and send me a radio message. I'm likely to get that faster. ;)


The Space Tyrant project has a new website, SpaceTyrant.com, where the latest source code is always available. Also, new articles about ST programming and about ST gameplay will be posted there as they come available.


Information on The Last Resort follows. TLR is one of the two games that Space Tyrant is intended to replace someday. Space Tyrant has a long way to go before it replicates TLR's 25,000 lines of C code. So far, it has reused only about 40 lines of TLR code, a handy 'bit-plane' sort dating back to 1998.

  • TLR Survival Manual
  • Is this game for you? read more...
  • mail this link | permapage | score:9205 | -Ray, June 25, 2005 (Updated: June 7, 2014)

    Tutorial: UDP socket based client server C programs

    Up
    vote
    Down

    This short and sweet tutorial has the example C source code for both a UDP client and server.
    This article explains how to write a simple UDP client/server system in C for the Linux or Unix platform. Writing client-server applications using UDP sockets is considered very easy, yet we sometimes miss some essential steps, which results in spending more time in intense debugging sessions. I went through one such experience. It is quite hard to remember all the socket API details quickly without having to wade through tons of man pages, so this page lists the standard code for UDP Client Server program. I hope it will be useful for others, too.
    [The original article has gone offline and the link has been replaced by a working page. -Ed.] read more...
    mail this link | permapage | score:9177 | -Ray, February 23, 2004 (Updated: August 24, 2008)

    Currency Traders on Raspberry Pi

    Up
    vote
    Down

    You can now run Currency Traders on your Raspberry Pi. It is extremely efficient and takes only about 2.2% of the memory of a 512MB RPi and less than 0.5% of the CPU. More CPU will be consumed when players are online, of course, but it should support up to a hundred or so concurrent players on a normally clocked Pi.

    The installation is four quick steps, described in the readme.txt file. The entire system is a single binary, available either dynamically linked or statically linked. The static version should work on most any Pi running most any Linux. The dynamically-linked version was compiled and tested on Raspbian Wheezy and may work without library fiddling on other Pi Linuxes. [links removed]
    read more...
    mail this link | permapage | score:9170 | -Ray, March 3, 2013 (Updated: May 13, 2014)

    Space Tyrant: Multithreading lessons learned on SMP hardware

    Up
    vote
    Down

    There is much to report in this update of Space Tyrant. Before getting into the new features and functions, I’ll dispense with the crisis of The Bug.

    For a couple of weeks, we had been noticing odd anomalies with Space Tyrant (ST) running on the virtual server at Ioresort.com (now offline -Ed.). We never saw the problem on any other box -- and it was tested on at least four other Linux boxes and a Mac OS X system. We did all manner of stress testing, locally and over the Internet, script based and even feeding the game the output of /dev/random. Nothing caused the anomaly on any other box.

    At first, I suspected that it might just be an obscure problem with the virtual server itself; after all, I had been forced to modify the TLR code to get it to run properly there. That problem turned out to be merely a limitation of NFS, not a bug with the virtual server software. However, the environment was clearly different from any other system I had used which raised my suspicions -- and reduced my urgency about looking for the bug.

    While the bug wasn’t frequent, it was persistent. The bug appeared to be related to corrupted buffers or corrupted buffer indexes. Out of idle curiosity, I lowered the number of buffers used by ST to see if that affected the bug. Somewhat counter-intuitively, it substantially raised the frequency of the problem.

    Brian Estabrooks (the hero of this release) and I spent more and more of our efforts hunting this incredibly elusive bug until that was all we were doing. I implemented various diagnostic routines hunting for clues. The all seemed to point to buffer indexes being changed incorrectly. Both Brian and I audited the code. It seemed impossible for the indexes to be changed improperly. Brian even went so far as to replace the ring buffer scheme with a high watermark approach but to no avail.

    While I continued to suspect it to be a simple logic error in the code, Brian turned his efforts elsewhere. What he came up with was quite interesting. It seems that on many hardware architectures (most? all?), modifying a bit field can temporarily modify other bit fields in the same word! Now, this isn’t a problem on a single-CPU system; it repairs the damage in the same operation, making it, effectively, atomic. On an SMP machine, however, two different CPU’s working on different bit fields of the same word simultaneously create havoc. The operation isn’t really atomic and it doesn’t work.

    Did I mention that the virtual server is a 4-way Xeon system?

    The ring buffer indexing in ST relies on unsigned integer bit fields to automate wrapping back around to the first buffer after using the last one. My parsimonious programming, of course, packed all the bit fields together, several to a word. Brian’s test version of ST added a pad after each buffer index to round it out so that each bit field lived alone in its own complete word. We abused the new version for nearly an hour before either of us would dare say it. The bug was gone.

    Yay!

    So, the moral of this story is: Operations on sub-word fields affect other bits in that word (at least on many hardware architectures). Tread very carefully if multiple threads are accessing different bits in shared words. It may appear to work perfectly, only to crumble into a pile of smoldering rubble the first time it's loaded on a multiple CPU system!

    Other than the primary lesson, some other good things came out of (the search for) the bug. Several other latent bugs were found and fixed and Brian and I are both much more intimate with the code.

    And, on to the enhancements. ST is starting to look like an actual playable game. The following functions implement the new major features.

    players(): We now have player rankings. It works by adding all the players’ ship resources to an integer array. Then it scans the universe looking for deployed fighters and adds those to the array as well. Currently, those two items comprise the total strength of a player.

    It then sorts the array with a recursive bit-plane sort that I wrote for Starship Traders in 1998. The qsort() function in the C library was plenty fast, but took too much memory for my taste. Memory was a bit scarcer in those days and, worse, the SST software model gave each player his own copy of the server.

    The sort reorders the array in place as follows. It scans the high-order bit in each element of the array. It then moves all elements starting with ‘1’ bits to the top and all starting with ‘0’ bits to the bottom. Next, it calls itself twice to reorder the first and second chunks of the array on the second bit. Each of those two instances of the sort then call the sort twice again, now giving 4 new sorts for the third bit, and so on. When all 32 bits are accounted for, the array is in the correct order with the top player on top, etc.

    Scanning the entire universe can be expensive with a large map. Therefore, the player rankings function keeps the result and time stamps it. If another player asks for a player ranking within five seconds, the system just gives them the old one. After five seconds, however, any new request triggers a fresh listing.

    autopilot(): We’ve added an autopilot to let a player find a specific sector -- or to locate the nearest planet. If you type a ‘0’ (zero), you’ll be prompted for a sector number within 1000 of the sector you’re currently in. You then will have the option of pressing ‘/’ to automatically warp to the destination sector.

    If you’re looking for a planet, type the ‘L’ command that you would normally use to land on a planet in your sector. In the absence of a planet, the L key will engage the autopilot which will search for the nearest planet and give you a ‘/’ command to autowarp to it.

    The new autopilot function consists of two other functions in addition to autopilot(), which is merely a control function. I had intended to use the old shortest path algorithm function from TLR but it was big and complicated. I decided to try to write a simpler, recursive shortest path algorithm instead. The new recursive function is much simpler but not quite as efficient as the giant for loop in TLR.

    The actual algorithm is implemented in two functions called pathdepth() and pathcalc(). The pathdepth() function repeatedly calls pathcalc() with an increasing ‘depth’ parameter. ‘Depth’ tells pathcalc() how many levels deep to search before giving up.

    The pathcalc() function simply looks to see if the sector it is looking at is the target sector. If not, it calls itself for each new sector that the current sector connects to. If the current sector is the target sector, it starts filling in an array for the autowarp() function to follow to reach the target sector. As the previous recursive calls to the pathcalc() function exit, they fill in the remainder of the path array.

    And, yes, I seem to like reinventing the wheel. ;-)

    The other interesting addition to the code is the backup thread. It is implemented by a function called backupdata() and works as follows: It scans the player data, the map data, and the history data looking for ‘dirty’ flags. (Whenever any persistent data is changed anywhere in the game, a dirty flag is set to tell the backup thread to write it out to disk.) This process is quite fast for a small game, but for a game with millions of sectors, it’s a significant waste of resources to scan the dirty flag array frequently.

    Therefore, for the map and history data, I’ve implemented a ‘dirty block’ scheme as well. When a dirty flag is set, its corresponding dirty block flag is set too. Then, the backup thread need only scan the dirty block arrays, typically only about one percent the size of the arrays it represents. When a dirty block is found, only the hundred or so records it points to are scanned to find the actual dirty records for backup.

    The backup file, named ‘st.9999.dat’ -- where ‘9999’ varies with the port number you run the game on -- goes into the current working directory from where you start the daemon. If the file doesn’t exist, a new game is started. Also, if you’ve modified the game in a way that changes the size of the data -- by increasing the map size, for example -- it will start a new game upon startup.

    The game can be shut down from the command line by sending a signal 15 (kill -15 pid) or by the admin with the ^ command. Note that the first player to create an account in a new game automatically becomes the admin of the game!

    makehistory(): The storing of historical data is new as well. Whenever another player attacks your ship while you’re logged off, you’ll get a report of the action and any losses when you next log on. Also, for remote deployed fighters, you never get immediate notification, so that information is stored in the history log even if you're logged on when it happens. You can view any accumulated event information since your login time by pressing the ‘e’ key.

    deploy(): This simple function allows a player to deploy, or retrieve, guard fighters in a sector. Those fighters will not let another player pass through or view any of the contents of that sector. Any ships parked under the fighters are automatically protected against all attacks except for an attack by the fighters’ owner. Once the fighters are destroyed, of course, all ships there are visible and can be attacked.

    There is also a newly implemented time limit in the game to limit the total online time of a day’s sessions to 4 hours. Like most other parameters, it can be changed by modifying a #define statement near the top of the code.

    command(): The help page, a menu of available commands that a player can perform, has been redesigned and rewritten. This menu is attached to the '?' key.

    The old debugger thread is gone, replaced by an in-game command function called showdata(). Press the ‘z’ key to see information on buffers, buffer indexes, and the backup thread’s state and history. Only if you’re serious about modifying the code will this information be useful.

    The section of the gameloop thread that broadcasts radio and news messages has been modified to show only one of each type of message per pass. That way, replaying a long radio history won’t flood the output buffers and longer radio and news histories can therefore be retained.

    The old jumprtn() movement function has been consolidated into the warprtn() function. It’s only slightly more complicated than having them separate.

    The current source code can be downloaded from http://librenix.com/st/st.158.c. and the original article in this series is here. As usual, the compile script is embedded in the comments at the top of the source file. You’ll have to rename the source st.c for the script to work unchanged.

    [A Space Tyrant home page has been created as a central index to the various ST articles, links, and files.]
    mail this link | permapage | score:9163 | -Ray, June 26, 2005 (Updated: July 26, 2008)

    Tutorial: Linux Dialog Boxes

    Up
    vote
    Down

    Dialog lets you create dialog boxes from Unix/Linux shell scripts...
    'dialog' is a utility for building console-based 'front ends' in UNIX like operating systems.

    In this brief tutorial I am mentioning the usage of few important basic controls available with this 'dialog' utility and later I have created a very simple front end application in UNIX bash scripting using dialog.
    read more...
    permapage | score:9145 | -Ray, January 1, 2010

    Trace network packet paths with traceroute

    Up
    vote
    Down

    An introduction and short guide to the traceroute networking utility...
    The tool traceroute is available in all Unix and Linux distributions and is used to find out the potential bottlenecks in between your computer and a remote computer across the net. The usage of this tool is quite simple and is as follows:
    read more...
    permapage | score:9116 | -Ray, January 21, 2007

    Scripting: Put a clock in your bash terminal

    Up
    vote
    Down

    In the original version, the cursor positioning didn't work on my Mac OS X system. If that happens to you, try this simplified variant:
      #!/bin/bash
    while true
    do
    tput sc
    tput cup 0 60
    echo -en `date +"%H:%M:%S %F"`
    tput rc
    sleep 1
    done
    Also, note that you'll need to run either script in the background to use your terminal.
    The script saves the current cursor position with an ANSI escape sequence instruction. Then, using the tput command, the cursor is sent to row 0 (the top of the screen) and the last column minus 19 characters (19 is the length of HH:MM:SS YYYY-MM-DD). The formatted date command is displayed in green inverted color. The cursor is then sent back to its original position with another ANSI sequence that restores the original saved position.
    read more...
    mail this link | permapage | score:9116 | -Ray, January 22, 2008

    Protect SSH from dictionary attacks with pam_abl

    Up
    vote
    Down

    Use pam_abl module to stop brute force attacks against your SSH server...
    Practically all Unix and Linux servers run an SSH service to let administrators connect securely from remote locations. Unfortunately for security administrators, attacks on SSH services are popular today. In this article I'll show you how can you protect machines running SSH services from brute force attacks using the pam_abl plugin for SSH pluggable authentication modules (PAM).
    read more...
    permapage | score:9104 | -Ray, March 28, 2007

    The Virtual Private Nightmare: VPN

    Up
    vote
    Down

    Maybe the 'P' really stands for Public...
    Here's a question: What's the number 1 vector for security outbreaks today? Given the title of the article we hope you answered Virtual Private Networks (VPNs). Today's convenient world of mobile access to critical applications and information has come with a hefty burden for the world's already overburdened security teams.
    (and here are some nightmare prints) read more...
    mail this link | permapage | score:9092 | -Ray, August 4, 2004 (Updated: April 24, 2012)

    perl dispatch table examples

    Up
    vote
    Down

    Dispatch Table: The fancy name for a hash of code-refs...
    In perl, code is a first class data type... you can talk about it in the same way you would talk about arrays or hashes, you can take references to them (giving you a code-ref ) and you can de-reference them (which runs the code);

    Code-references are just scalars that refers to something, and you get them by using the reference-to operator:
    read more...
    permapage | score:9087 | -f00li5h, December 17, 2010
    More articles...
    Fine Art Online Gallery

    Selected articles

    Linux dominates Windows

    The Network Computer: An opportunity for Linux

    Apple DIY Repair

    Mono-culture and the .NETwork effect

    Graffiti Server Download Page

    Shadow.sh: A simple directory shadowing script for Linux

    Why Programmers are not Software Engineers

    Tutorial: Introduction to Linux files

    VPS: Xen vs. OpenVZ

    No, RMS, Linux is not GNU/Linux

    The Supreme Court is wrong on Copyright Case

    Space Tyrant: Multithreading lessons learned on SMP hardware

    Microsoft to push unlicensed users to Linux

    Programming Language Tradeoffs: 3GL vs 4GL

    Apple to Intel move no threat to Linux

    MiniLesson: An introduction to Linux in ten commands

    Beneficial Computer Viruses

    Linux vs. Windows: Why Linux will win

    Space Tyrant: A threaded game server project in C

    Scripting: A parallel Linux backup script

    Space Tyrant: A multiplayer network game for Linux

    Librenix T-Shirts and Coffee Mugs!

    The short life and hard times of a Linux virus

    Download: Linux 3D Client for Starship Traders

    Closed Source Linux Distribution Launched

    The Real Microsoft Monopoly

    Testing the Digital Ocean $5 Cloud Servers with an MMORPG

    Why software sucks

    Missing the point of the Mac Mini

    Space Tyrant: A threaded C game project: First Code

    The life cycle of a programmer

    How to install Ubuntu Linux on the decTOP SFF computer

    Hacker Haiku

     

    Firefox sidebar

    Site map

    Site info

    News feed

    Features

    Login
    (to post)

    Search

     
    Articles are owned by their authors.   © 2000-2012 Ray Yeargin