BigSmoke

Smokes your problems, coughs fresh air.

Page 33 of 52

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs is on-line free MIT text-book that uses Scheme in an attempt to give the reader a general and practical understanding of programming.

Not having read the book myself, I’m not sure if the goal of its authors was successful but it is neatly summarized in the Preface:

Our design of this introductory computer-science subject reflects two major concerns. First, we want to establish the idea that a computer language is not just a way of getting a computer to perform operations but rather that it is a novel formal medium for expressing ideas about methodology. Thus, programs must be written for people to read, and only incidentally for machines to execute. Second, we believe that the essential material to be addressed by a subject at this level is not the syntax of particular programming-language constructs, nor clever algorithms for computing particular functions efficiently, nor even the mathematical analysis of algorithms and the foundations of computing, but rather the techniques used to control the intellectual complexity of large software systems.

Our goal is that students who complete this subject should have a good feel for the elements of style and the aesthetics of programming. They should have command of the major techniques for controlling complexity in a large system. They should be capable of reading a 50-page-long program, if it is written in an exemplary style. They should know what not to read, and what they need not understand at any moment. They should feel secure about modifying a program, retaining the spirit and style of the original author.

Maybe this is worth a read?

Matriux, a penetration testing and security analysis LiveCD

Last December, someone pointed me to Matriux. In their own words:

It is a fully featured security distribution consisting of a bunch of powerful, open source and free tools that can be used for various purposes including, but not limited to, penetration testing, ethical hacking, system and network administration, cyber forensics investigations, security testing, vulnerability analysis, and much more. It is a distribution designed for security enthusiasts and professionals, although it can be used normally as your default desktop system.

It comes with a wide arsenal of free software tools to do naughty things to your network. I think I should give it a swing and download it some time.

Monitor the progress of Unix commands with Pipe Viewer (pv)

I just stumbled across the following post while trying to find out how to copy text from VIM using XSel without losing the selected text. It introduces Pipe Viewer, a Unix utility which is a kind of cat with a progress bar.

I emerged it (it’s in Gentoo (Debian too)) and it works very simple, but allows you to do cooler, more complicated things.

# pv emerge.log |gzip >emerge.log.gz
1.24MB 0:00:00 [1.76MB/s] [================>] 100%  
$ pv -cN source access_log | gzip | pv -cN gzip > access_log.gz
   source: 28.7MB 0:00:00 [32.2MB/s] [=====>] 100%            
     gzip: 2.27MB 0:00:00 [2.54MB/s] [ <=>  ]

The first example is easy enough to understand when you mentally substitute pv with cat. The second example is much cooler. It uses the -N flag to make named groups and the -c flag to make sure that the output for these groups doesn’t get garbled.

Read Peteris Krumins’ article for more cool uses of Pipe Viewer.

Installing Windows on Xen

Just a a kind of bookmark, I used this blog post as a base to find out how to install Windows as a DomU on Xen. I might at some point reconstruct my steps, but for now this link is all… (judging by the URL the blog won’t exist much longer, but oh well…)

XSel, for command-line operations on X selections

Since I first learned that Windowmaker installs two command-line tools, wxcopy and wxpaste, to play around with X selections, I have wanted to be able to make and use X selections from my Bash shell. wxcopy and wxpaste never did what I expected them to do, so I gave up until recently I learned about all the different X selections.

By default, wxcopy and wxpaste operate on the CUT_BUFFER[n] selections. These are deprecated. That’s why I could never make it work, because modern applications use only CLIPBOARD and SELECTION. So, wxcopy is pretty useless (unless its used to copy something to paste with wxpaste). With this knowledge wxcopy does seem useful thanks to its -selection [selection-name] flag, but this doesn’t seem to work; I only get the contents of CUT_BUFFER. This is not how the feature is advertised:

-selection [selection-name]
The data will be copied from the named selection. If cutting from the selection fails, the cutbuffer will be used. The default value for the selection name is PRIMARY.

Enter XSel

Fortunately, there’s XSel by Conrad Parker, a program which made him passionately hate the ICCCM.

XSel does exactly what it advertises. I’m actually surprised that I never heard of it before. It’s available in Gentoo, Debian and Ubuntu, so it’s a breeze to install.

Among its features are: --append, --follow, --clear, --delete (very weird, but logical if you understand X IPC), --primary, --secondary, --clipboard, --keep, and --exchange. Read the man page for more. It’s an excellent read.

One of the places where I’m going to use this tool is when copy-pasting to and from VIM. I really like how this compares to using :insert or :r!cat</dev/tty and then using the pointer to paste (or (Shift+)Insert with my custom XTerm config). Now, to paste something in VIM, I can simply type:

:r!xsel

I use the following to copy any amount of text from VIM. This works much better than fooling around with the mouse:

:'>,'> !tee >(xsel -i)

The '>,'> range is entered automatically if you press : while in visual (selection) mode. You could enter any range there, or even % to select the whole file. To copy to the CLIPBOARD instead of the PRIMARY, use xsel -i -b in the above example.

If someone know of a way to make VIM pipe something to a program without replacing the given range with that program’s output, I could simplify this…

Installing Xen with Lenny guest on a Debian machine

This is supersceeded by my install on Debian Squeeze). On Lenny, everything is just too outdated.

This will explain how to install the paravirtualization software Xen on Debian. It is more involved than KVM, but more elegant if you can setup up a dedicated machine to run virtual machines (in fact, KVM on Debian seems quite clunky). I use this Debian wiki page as base.

First some terminology. On Xen, everything runs virtualised, including what in KVM would be called the “Host OS”. This is because every OS instance shares some kernel space. Xen has a primary virtual machine with which you configure the other virtual machines. This is called Domain-0, or Dom0. The guests are DomU’s.

Begin by installing xen-linux-system-2.6.26-2-xen-686 and xen-tools. It will install all necessary dependencies:

aptitude -P install xen-hypervisor-3.2-1-i386 linux-image-2.6-xen-686 xen-tools

(The wiki page suggests to install linux-image-2.6.26-2-xen-686, but that confuses me. See my forum post. I will update this blogpost if my insights change).

A new kernel is installed and is configured in Grub as primary kernel. (As a sidenote, I wonder what will happen if the standard kernel is upgraded at some point in the future; will that be installed as primary again? Should the standard kernel be uninstalled?)

Before you reboot, add “xenblktap” to /etc/modules. This module is needed to be able to use tap:xxx (like tap:aio) storage back-ends. These are preferred over “file:”, especially when using NFS to store images (although that link also states that ENBD is preferred over NFS. (I was having problems with tap:aio and then I discovered the module problem. It still doesn’t work for me, but the problem lies elsewhere now.)

If you boot into the new kernel you can do “xm list” and you will see that your Domain-0 is active.

You want to setup an ethernet bridge configuration next, because that way, you can plug your virtual machines into your existing ethernet network. You can do this by configuring this in the config file /etc/xend-config.xsp (The network-script option is already defined, so all you have to do is change it):

(network-script network-bridge)

Configuring “vnc-listen” might also be a good idea (although not really needed for linux, since you’ll be using the xen console). Setting it to localhost and then tunnling through SSH would be the safest, obviously.

Now it’s time to add DomU’s. Because the guests need to have DomU support, the OS cannot be installed with the normal installer (although I’m not sure this is still the case for Lenny, because the Wiki says: “In Lenny the distinction between the Xen and non-Xen flavours of the kernel (with respect to domU support) is no longer present.”).

First edit /etc/xen-tools/xen-tools.conf to set some good defaults. You can remove the noatime mount options for ext2 and ext3, for example. I can also set the default mirror to “http://ftp.nl.debian.org/debian/”.

xen-create-image --hostname=virtualnode --size=2Gb --dist=lenny --memory=256M --dhcp --dir /root/xen-images/ --swap 256Mb

You have to mount the image to make some corrections. In my case, the image was still mounted somewhere in /tmp. I assume this is bug. Begin by editing /etc/inittab. Comment out the existing “1:…” tty and add the line :

1:2345:respawn:/sbin/getty 38400 hvc0

to /etc/inittab, otherwise your console won’t work.

Start the virtual machine and attach a console (the -c option) like this:

xm create -c virtualnode.cfg

One of the first things you want to install is udev, because you can’t even ssh to the box without it.

The resulting Debian installation is very bare; it doesn’t even have a mail infrastructure.

On the Dom0, you can mkdir /etc/xen/auto and symlink the config file for this virtual host there to have it auto started by the xendomains bootscript.

Copy-pasting to and from XTerms

By default, XTerms only supports the PRIMARY selection for copy and paste. The PRIMARY selection is the one that is used by most ‘modern’ X application when you select text. This text can then usually be pasted by clicking the middle/second mouse button. Because this selection is set whenever you select, it’s easily overwritten, often accidentally. That’s why most newer X apps offer a parallel copy/paste mechanism where the selection is only explicitly set by choosing “Cut” or “Copy” from the application’s “Edit” menu or from its context menu (or with the Control-X/C/V keyboard shortcuts). In X, this selection is called CLIPBOARD, just like in Windows where it’s the only selection.

X also has these selections called Cut Buffers, but these are considered obsolete. Maybe that’s just too bad, because they appear to be the only selections with persistence; the other selections, PRIMARY and CLIPBOARD, disappear when the application is quit. Apparently, this is a feature, because it enables content negotiation.

Anyway, XTerm can be configured to do anything and I want it to be CLIPBOARD aware, for two reasons: one is that I often copy things from applications that can only set the CLIPBOARD selection; another is that I want to be able to really copy something from the XTerm, without losing it as soon as I select something else (especially if that something else is something I want to replace with the selection).

So, I added the following to my VT100.Translations #override in .Xdefaults.XTerm:

XTerm*VT100.Translations: #override \
    ShiftInsert: insert-selection(CLIPBOARD) \n\
    Insert: insert-selection(PRIMARY) \n\
    Shift: insert-selection(CLIPBOARD) \n\
    Shift: select-start() \n\
    Shift: select-extend() \n\
    Shift: select-end(CLIPBOARD)

What this does:

  • This gives me an XTerm that pastes the content of the CLIPBOARD when I hold down Shift during my two-finger tab (I’m using a touchpad, so that works as a Btn2).
  • Because I don’t like moving my hands, I can do the same by pressing Shift+Insert.
  • I can use my Insert key without Shift to paste the PRIMARY selection.
  • To copy something to the clipboard, I hold down the Shift key while making the selection.

That’s how you can make use of the CLIPBOARD from your XTerm.

Sources

If you want to learn more.

Xen console

To get the console of your Linux guests on a Xen machine, type “xm console “. Then to exit, press “ctrl-]”. When in screen, do “ctrl-a, a, ctrl-]”.

Configuring a static IP address on Debian

This is a simple netconfig for a static IP address on a Debian machine. In /etc/network/interfaces, replace your eth0 (or whatever) with this:

auto eth0
iface eth0 inet static
    address 192.168.1.65    
    netmask 255.255.255.0
    gateway 192.168.1.251

Edit: I removed the network and broadcast statements because they are superfluous.

Debian volatile: keep fast moving packages working on Debian stable

The concept of Debian stable is kind of nice, since you don’t have to be affraid of upgrade breakages all the time, but it can also be annoying, because things like spamfilters and virusscanners are fast-moving and you often end up with old versions of those. That is why the Debian volatile project exists.

On new installs, the packages sources will already be in /etc/apt/sources.list, but the sources.list doesn’t seem to be upgraded on old systems, so you may need to add them by hand. These are the sources:

deb http://volatile.debian.org/debian-volatile lenny/volatile main
deb-src http://volatile.debian.org/debian-volatile lenny/volatile main 

It’s speaks for itself that you have to change lenny to whatever the release will be…

« Older posts Newer posts »

© 2024 BigSmoke

Theme by Anders NorenUp ↑