boltblog

Creating .deb-Packages With Checkinstall

Posted on January 4, 2012

If you've exhausted all other options, it might be time to compile from source, even in Debian.

If you're about to do that though, don't abandon the concept of .deb files and the advantages they bring with versioning and easy removal. Use "checkinstall".

Checkinstall is in the standard Debian repositories and encapsulates your install into a nice, easily installable and distributable .deb file. apt-getting it and reading the manual is easy enough, but if you want a howto, falkotimme.com has a nice one, archived here as a PDF.

Filed under: Linux, Reference No Comments

UDP through SSH

Posted on October 5, 2011

http://zarb.org/~gc/html/udp-in-ssh-tunneling.html
Good. Archived for personal reference.

copy here

Filed under: Linux, Reference No Comments

Fixing “shmget() failed: No space left on device”

Posted on September 14, 2011

I had this happen when someone ran a script to kill x11vnc every so often, using kill -9 (don't ask).

Killing x11vnc with SIGTERM (15) allows it to clean up its shared memory segments. SIGKILL (9) will not.

Googling around, I found a script over here (backup copy here).

The problem with that was that it's aimed at being run as the user, and it only supports usernames up to 10 characters, because of how "ipcs -m" prints its entries on Linux.

I wanted a solution that supported any length of username, and that could be run periodically, by root, as a cronjob to clean up after silly users, and that would also give me a report when it cleaned something, so I could see who was causing this.

The result was this script. It only supports Linux, and thus is a bit less portable than the one at karlrunge.com, but it does the job, even with long usernames, and generates such nice reports:

Removed SHM Segments:
___________________________
|   OWNER    |   COUNT    |
|------------|------------|
| bolt       |         42 |
|____________|____________|

Total: 42

Oops...

EDIT:
Updated script, automatically synced with the one I'm actually using available here.

SSH in a while loop – stdin problems

Posted on September 12, 2011

When SSH is used with a line like "while read ....", the while loop will only run once.
This can be seen by running this simple example:

$ seq 1 10 | while read line; do ssh remotehostname "echo x${line}x"; done
x1x

You might expect this to connect to the host with the name "remotehostname" 10 times, and each time print one of the numbers in the sequence from 1 to 10. This will, however, not be the case. The result is a single line, saying "1".

Where did the rest of the numbers go? To the SSH process.
By default, SSH runs off with the stdin file descriptor, preventing "read" from reading anything else from it. You can see this by trying the following example:

$ seq 1 10 | while read line; do ssh remotehostname "echo x${line}x; cat -"; done
x1x
2
3
4
5
6
7
8
9
10

Now all the numbers were printed, but they were all in a single ssh connection. As you can see, only the number "1" got the X'es on both sides, indicating it was printed by the "echo" instruction. The rest of the numbers come from "cat -", which basically takes whatever comes in on SSH's stdin, and dumps it to the stdout (the screen, in this case). So that's where they went!

Now, how do you remedy this?

Answer: SSH's -n switch. From the manual:
-n Redirects stdin from /dev/null (actually, prevents reading from stdin). This must be used when ssh is run in the background. A common trick is to use this to run X11 programs on a remote machine. For example, ssh -n shadows.cs.hut.fi emacs & will start an emacs on shadows.cs.hut.fi, and the X11 connection will be automatically forwarded over an encrypted channel. The ssh program will be put in the background. (This does not work if ssh needs to ask for a password or passphrase; see also the -f option.)

So let's try that with -n, shall we?

$ seq 1 10 | while read line; do ssh -n remotehostname "echo x${line}x; cat -"; done
x1x
x2x
x3x
x4x
x5x
x6x
x7x
x8x
x9x
x10x

There. 10 SSH connections opened, 1 number printed each time. A total waste of time, but a rather simple example to follow :)

Set php.ini values using .htaccess

Posted on September 10, 2011

Did you know that you can set php.ini values right inside the .htaccess file?
You can do so by adding lines like these:
#format
php_value setting_name setting_value

#example
php_value upload_max_filesize 128M

Filed under: Linux, Reference No Comments

GCC stray X in program

Posted on September 10, 2011

Problem:
IEMGD_HEAD_Linux/common/drm/emgd/display/pi/cmn/pi.c:1: error: stray ‘\357’ in program

This is caused by "invalid" characters in the code, specifically I encountered this while trying to compile the Intel EMGD driver for my EEEPC's graphics card.

Thanks to the helpful folks over here, there's a solution:
cd IEMGD_HEAD_Linux/common/drm/emgd/display/pi/cmn
cat -v pi.c | awk '{if(NR>1) print $0}' > tmp # make strange characters on first visible and remove
mv tmp pi.c

That makes the invalid characters visible and removes them.
In this case, it leaves some partial, garbage comments behind, so the file still wont compile.
To resolve this, I opened the file in vim, and quickly searched for and removed the faulty comments (and some I didn't have to remove).
Remember to answer "no" to the question of re-extracting the tarball each time you retry building this.
Attached is the original driver file, and my modified copy of pi.c

Result:
"Completed EMGD Installation"

Lin_EMGD_1_6_RC_1922
modified pi.c

xorg.conf for KVM

Posted on September 3, 2011

Found this somewhere.
Works for me.

Section "ServerLayout"
Identifier "BodhiZazen's KVM xorg.conf"
Screen 0 "Screen0" 0 0
InputDevice "Mouse0" "CorePointer"
InputDevice "Keyboard0" "CoreKeyboard"
EndSection

Section "Module"
Load "record"
Load "dri"
Load "extmod"
Load "glx"
Load "dbe"
Load "dri2"
EndSection

Section "InputDevice"
Identifier "Keyboard0"
Driver "kbd"
EndSection

Section "InputDevice"
Identifier "Mouse0"
Driver "vmmouse"
Option "Protocol" "SysMouse"
Option "Device" "/dev/sysmouse"
Option "ZAxisMapping" "4 5 6 7"
EndSection

Section "Monitor"
Identifier "Monitor0"
VendorName "Monitor Vendor"
ModelName "Monitor Model"
HorizSync 20.0 - 50.0
VertRefresh 40.0 - 80.0
Option "DPMS"

EndSection

Section "Device"
Identifier "Card0"
Driver "vesa"
VendorName "KVM - std"
BoardName "GD 5446"
BusID "PCI:0:2:0"
EndSection

Section "Screen"
Identifier "Screen0"
Device "Card0"
Monitor "Monitor0"
SubSection "Display"
Viewport 0 0
Modes "800x600"
EndSubSection
EndSection

Filed under: Linux, Reference No Comments

bash time limit on commands

Posted on September 1, 2011

Several programs, like "timelimit" and "timeout", exist to prevent a process from running for too long.
However, if you want to do this on a box where neither is installed, there's a way to do so with bash alone.

Based on the original script I found at pixelbeat.org...
#!/bin/sh

# Execute a command with a timeout

# Author:
# http://www.pixelbeat.org/
# Notes:
# If the timeout occurs the exit status is 128.
# There is an asynchronous (and buggy) equivalent of this
# script packaged with bash (under /usr/share/doc/ in my distro),
# which I only noticed after writing this.
# I noticed later again that there is a C equivalent of this packaged
# with satan by Wietse Venema, and copied to forensics by Dan Farmer.
# Changes:
# V1.0, Nov 3 2006, Initial release
# V1.1, Nov 20 2007, Brad Greenlee
# Make more portable by using the 'CHLD'
# signal spec rather than 17.

if [ "$#" -lt "2" ]; then
echo "Usage: `basename $0` timeout_in_seconds command" >&2
echo "Example: `basename $0` 2 sleep 3 || echo timeout" >&2
exit 1
fi

cleanup() {
{ kill %1 2>/dev/null; }& # kill sleep $timeout if running
kill %2 2>/dev/null && exit 128 # kill monitored job if running
}

set -m # enable job control
trap "cleanup" CHLD # cleanup after timeout or command
timeout=$1 && shift # first param is timeout in seconds
sleep $timeout& # start the timeout
"$@" # start the job

I made a new script in bash, which also returns the correct exit status if the command completed before the timeout:
http://www.dhampir.no/stuff/bash/timeout.bash

Works well for me, at least :)

Debian APT Pinning properly explained

Posted on August 26, 2011

Accidentally stumbled across the "Debian Cheat Sheet" at http://carlo17.home.xs4all.nl/howto/debian.html

Finally some documentation on why the heck pinning with "Package: *" and "Package: mypackage" doesn't mix well, and other useful knowledge.

In case the link goes dead, here's a PDF: debian_cheat_sheet.pdf

Filed under: Linux, Reference No Comments

Using LD_PRELOAD to override a function

Posted on July 15, 2011

This was blatantly stolen from technovelty, kept here because I hate it when my bookmarks die.

For some reason, people seem to get this quite wrong a lot of the time. Certainly one should not be playing with symbols that start with __ unless you really know what you're doing with them.

ianw@lime:~/tmp/override$ cat override.c
#define _GNU_SOURCE 1
#include
#include
#include
#include
#include

pid_t getpid(void)
{
pid_t (*orig_getpid)(void) = dlsym(RTLD_NEXT, "getpid");
printf("Calling GETPID\n");

return orig_getpid();
}

ianw@lime:~/tmp/override$ cat test.c
#include
#include
#include

int main(void)
{
printf("%d\n", getpid());
}

ianw@lime:~/tmp/override$ gcc -shared -fPIC -o liboverride.so override.c -ldl
ianw@lime:~/tmp/override$ gcc -o test test.c
ianw@lime:~/tmp/override$ LD_PRELOAD=./liboverride.so ./test
Calling GETPID
15187

Filed under: Linux, Reference No Comments