home / blog

Installing adobe-reader on Ubuntu 12.10 – 64bit

wget http://ardownload.adobe.com/pub/adobe/reader/unix/9.x/9.5.3/enu/AdbeRdr9.5.3-1_i386linux_enu.deb
dpkg -i --force-all AdbeRdr9.5.3-1_i386linux_enu.deb
sudo apt-get -f install
Posted in geek | Tagged , | Leave a comment

Theme park cursor freeze [solved]

Eventually tracked this down a solution to this on a forum by someone exceedingly clever. Turns out to be an issue in the original game, but happens more often using emulators such as DOSBox.

vogons.zetafleet.com/viewtopic.php?t=31983&sid=6a3a397399f9c7837e222a265b195f4a

I tracked down the mouse pointer freeze problem some time ago thinking it might be a DOSBox issue, but AFAICT it’s a game bug. The mouse handler has a non-reentrancy flag that isn’t cleared in a specific condition that appears to be related to the mouse IRQ firing while switching between hi-res and lo-res video modes. When you play in hi-res some of the subscreens are in lo-res and switching is inevitable, but if you are careful not to move the mouse at all during the switching then the freeze can be avoided.

You can patch MAIN.EXE to fix the pointer freeze bug, but the exact offset varies between versions:
Code:
search: 0F 84 4D 05 00 00
modify: 43

There may be another problem with the mouse pointer related to hi-res/lo-res switching, but it is considerably more complicated and it can take some time before it occurs. This other problem causes the mouse pointer to disappear, and unlike the freeze problem it can’t be avoided by not moving the mouse. Actually, I would be interested in reports of pointer disappearance in Theme Park on real systems, because the complexity of what is going on makes it difficult to be certain if there is a game bug or a DOSBox issue.

Posted in geek | Tagged , | Leave a comment

Command line perl

I find this much more useful than sed.

Example 1: Filter/regex. Print numbers from matching lines.

foo 12 
bar 23
other
baz 34

-e is script mode. -n loops over your input automatically.

# -n option does the while loop for you
horse:~ adam$ perl -ne 'print "$1\n" if /(\d+)/' foo.txt
12
23
34

Without the -n option you’d have to add your own while loop.

perl -e 'while(<>) { print "$1\n" if /(\d+)/ }' foo.txt
12
23
34

Example 2: Modify. Wrap all numbers. -p loops around and prints the value of the substitution – much like sed

perl -pe 's/(\d+)/#$1#/' foo.txt
foo #12# 
bar #23#
other
baz #34#
Posted in geek | Tagged , | Leave a comment

Mythweb broken in Ubuntu 12.10 [solved]

HTTP 500s when trying to visit mythweb after upgrade to 12.10.

Cause, removal of allow-call-time-pass-reference option in PHP 5.4

adam@brimstone$ tail -f /var/log/apache2/error.log

[Sun Dec 02 16:59:29 2012] [error] [client 10.5.1.63] PHP Fatal error:  Call-time pass-by-reference has been removed in /usr/share/mythtv/bindings/php/MythBase.php on line 50

[Sun Dec 02 17:03:53 2012] [error] [client 10.5.1.63] PHP Fatal error:  Call-time pass-by-reference has been removed in /usr/share/mythtv/mythweb/includes/sorting.php on line 122

Fix:

// before MythBase.php: line 50
Cache::setObject($this->cacheKey, &$this, $this->cacheLifetime);
// after
Cache::setObject($this->cacheKey, $this, $this->cacheLifetime);
// before sorting.php on line 122
$response = $function(&$a, &$b);
// after
$response = $function($a, $b);
Posted in geek | Tagged , | Leave a comment

JNI helloworld

JNI is easy to use when you know how and frustrating when you don’t. I hope to demystify it and provide some pointers to when it goes wrong.

Define your native methods using the native modifier. In this example we’ll add two numbers together.

public class HelloWorld {
    public native int add(int a, int b);
}

Now generate your .h header files from the Java.

javac HelloWorld.java
javah -jni -classpath . HelloWorld

Implement your methods in a .c file

#include <jni.h>
#include "HelloWorld.h"
JNIEXPORT jint JNICALL Java_HelloWorld_add
(JNIEnv * env, jobject obj, jint a, jint b) {
  return (jint)(a + b);
}

Build your native library. This will vary between platforms.

# Linux
gcc -shared HelloWorld.c -I/usr/lib/jvm/java-6-openjdk/include -o libhelloworld.so 
# MacOS 10.6 - uses .dylib extension
gcc -shared HelloWorld.c -I-I/System/Library/Frameworks/JavaVM.framework/Headers -o libhelloworld.dylib 
# MacOS - older extension name "jnilib"
gcc -shared HelloWorld.c -I-I/System/Library/Frameworks/JavaVM.framework/Headers -o libhelloworld.jnilib 

Loading your library. This is traditionally done in a static block. The value you pass to loadLibrary() is the “base” library name – no lib prefix or .so, .dylib, .jnilib or .dll extensions.

public class HelloWorld {
    static {
	System.loadLibrary("helloworld");
    }
    public native int add(int a, int b);
    public static void main(String [] args) {
	System.out.println(new HelloWorld().add(12,34));
    }
}

Running. The most important thing here is to let the VM know where your library is. There are several methods for this.

  • Put the library in a known search path:
    # MacOS
    cp libhelloworld.dylib /Library/Java//Extensions
    # Linux
    cp libhelloworld.so /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext/
    
    # run as normal
    java -cp . HelloWorld
    46
    
  • Alter the VM arg java.library.path
    java -Djava.library.path=. -cp . HelloWorld
    46
    
  • Alter the OS library loader
    export LD_LIBRARY_PATH="."
    java -cp . HelloWorld
    46
    

When things go wrong: can’t see library

java -cp . HelloWorld
Exception in thread "main" java.lang.UnsatisfiedLinkError: no helloworld in java.library.path
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860)
	at java.lang.Runtime.loadLibrary0(Runtime.java:845)
	at java.lang.System.loadLibrary(System.java:1084)
	at HelloWorld.<:clinit>(HelloWorld.java:6)

When things go wrong: incorrectly named library

mv libhelloworld.dylib libhelloworld.dylib2
java -Djava.library.path=. -cp . HelloWorld
Exception in thread "main" java.lang.UnsatisfiedLinkError: no helloworld in java.library.path
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860)
	at java.lang.Runtime.loadLibrary0(Runtime.java:845)
	at java.lang.System.loadLibrary(System.java:1084)
	at HelloWorld.<:clinit>(HelloWorld.java:6)

When things go wrong: Method name mismatch.

JNIEXPORT jint JNICALL Java_HelloWorld2_add   <==== name changed to not match classname.
(JNIEnv * env, jobject obj, jint a, jint b) {
  return (jint)(a + b);
}
java -Djava.library.path=. -cp . HelloWorld
Exception in thread "main" java.lang.UnsatisfiedLinkError: HelloWorld.add(II)I
	at HelloWorld.add(Native Method)
	at HelloWorld.main(HelloWorld.java:11)

When things go wrong: library depends on another library that can’t be found.

# My library now depends on libftd2xx
ldd libhelloworld.so 
	linux-vdso.so.1 =>  (0x00007fff5f9ff000)
	libftd2xx.so => /usr/lib/libftd2xx.so (0x00007f4338c68000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f43388a9000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f433868b000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f4338487000)
	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f433827f000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f43390af000)
# I make it unavailable
sudo mv /usr/lib/libftd2xx.so /usr/lib/libftd2xx.so.hidden

java -Djava.library.path=. -cp . HelloWorld
Exception in thread "main" java.lang.UnsatisfiedLinkError: /data3/development/local/java/jni/libhelloworld.so: libftd2xx.so: cannot open shared object file: No such file or directory
	at java.lang.ClassLoader$NativeLibrary.load(Native Method)
	at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1935)
	at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1860)
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1850)
	at java.lang.Runtime.loadLibrary0(Runtime.java:845)
	at java.lang.System.loadLibrary(System.java:1084)
	at HelloWorld.<:clinit>(HelloWorld.java:4)

When things go wrong: library without execute permissions – windows only issue

Also useful for debugging there is also a System.load() call which takes an absolute path to the library.

static {
  System.load("/Users/adam/development/java/jni/libhelloworld.dylib");
}
Posted in geek | Tagged , | Leave a comment

Filtered copy and preserve directory structure

Say you had a massive, slow clearcase VOB with many filetypes, but you just wanted to copy the java files to /tmp for fast searching, and preserve the directory structure.

find . -name "*.java" | cpio --pass-through --verbose /tmp/horsecopy
Posted in geek | Tagged , | Leave a comment

SQLite with Hibernate/JPA LIMIT not working [solved]

Couldn’t get setMaxResults() / setFirstResult() to work properly in SQLite with Hibernate / JPA2. These ultimately boil down to SQL LIMIT/OFFSET. After much debug I found there is a problem in the widely distributed SQLiteDialect.java source.

The following needed adding, checkout the method name, code smell!

@Override
public boolean bindLimitParametersInReverseOrder() {
    return true;
}
Posted in geek | Tagged , , , | Leave a comment

Brasero cannot find DVD [solved]

Needed to use my DVD burner under Linux for the first time in 5 years, it’s still painful. The latest and greatest GUI is brasero which is default in Ubuntu 12.10. Still didn’t work “out of the box” though as it can’t find my DVDR drive.

brasero --brasero-media-debug
BraseroMedia: (at brasero-media.c:533) Initializing Brasero-media 3.4.1
BraseroMedia: (at brasero-medium-monitor.c:654) Probing drives and media
BraseroMedia: (at brasero-medium-monitor.c:659) Found 0 drives
BraseroMedia: (at brasero-medium-monitor.c:675) Found 0 volumes

Turns out I needed the following line in my /etc/fstab.

/dev/dvd               /media/dvd  auto    ro,user,noauto,unhide   0      0
Posted in geek | Tagged , | 1 Comment

Dreamhost php-cgi use different php.ini per directory

The popular gallery webapp still uses dated short PHP open tags <?, this makes it difficult to deploy in a subdirectory of a site that uses XHTML which requires short_open_tag=off to use &lt?xml… headers, leading to the following error.

Parse error: syntax error, unexpected T_STRING in /home/foo/example.com/index.php on line 3

This problem is further complicated by PHP CGI which means that php_value directives in .htaccess files cannot be used as they are with mod_php.

The solution: Per directory .htaccess calling php-cgi with a different php.ini directory.

/
/cgi-bin/
/cgi-bin/php.ini                   < contains short_open_tag=off to support XHTML
/cgi-bin/php-wrapper.fcgi          < calls /dh/cgi-system/php5.cgi
/cgi-bin/php-wrapper-gallery.fcgi  < call /dh/cgi-system/php5.cgi -c /home/foo/example.com/gallery
/gallery/.htaccess                 < Points at php-wrapper.fcgi
/gallery/php.ini                   < contains short_open_tag=on
/gallery/.htaccess                 < Points at php-wrapper-gallery.fcgi

What it looks like in terms of processes…

ps afx | grep php5.cgi
33603 ?        R      0:00 /dh/cgi-system/php5.cgi -c /home/foo/example.com/gallery
32621 ?        S      0:03 /dh/cgi-system/php5.cgi
Posted in geek | Tagged , , , | Leave a comment

Minimal jenkins, git, gradle setup on Ubuntu 12.04

Minimal jenkins, git, gradle setup on Ubuntu 12.04

Although gradle is available via app-get, the current version is broken

Manual install of jenkins

apt-get remove gradle
wget http://repo.gradle.org/gradle/distributions/gradle-1.0-milestone-8-bin.zip
sudo mv gradle-1.0-milestone-8 /usr/share/
sudo ln -s /usr/share/gradle-1.0-milestone-8/bin/gradle /usr/bin/

Normal install of jenkins.

sudo apt-get install jenkins

Setup of jenkins.

  • Add plugin : git
  • Add plugin : gradle
  • Create new project
    • set repository URL /data/development/repo
    • set poll SCM * * * * *
    • Select git advanced options – skip internal tag
    • Add build step – gradle
    • Set gradle root directory java/TestProject
Posted in geek | Tagged , , , | Leave a comment