Wink Saville’s Blog

April 19, 2008

linux - Excessive hard disk activity (or how to execute something while booting)

Filed under: linux — wink @ 11:01 am

A common problem encountered with laptop is that there is excessive activity due to the heads being loaded and unloaded frequently as described here. The solution for my HP zv5000 laptop was to use hdparm to disable advanced power management:

hdparm -B 255 /dev/sda

Since this needs to be performed every time the system boots you need to figure out a good place for the code. For Ubuntu I chose to add it to /sbin/setup.sh which is a script exectued by the The solution I used with Ubuntu was to add the above line to /sbin/setup.sh. In my case /sbin/setup.sh didn’t exist so I created it, be sure it’s executable.

When I changed my laptop to use Fedora I found the same problem, but Fedora doesn’t exectue /sbin/setup.sh instead I found the suggested mechanism was to add the code to file /etc/rc.d/rc.local.

March 16, 2008

scm - git svn connect

Filed under: linux, scm — wink @ 9:45 pm

The following allows you to reconnect a local clone of a remote svn repo assuming a git repo exists. In my case I have a backup of the remote svn repo but its a pure git repo without any git-svn meta data. Steven Walter provided the basic instructions here.

lcl ~/ $ git clone git://srv/amc.git amc
lcl ~/ $ cd amc
lcl ~/amc $ git svn init -s http://async-msgcomp.googlecode.com/svn
lcl ~/amc $ rm -rf .git/svn
lcl ~/amc $ cp .git/refs/remotes/origin/master .git/refs/remotes/trunk
lcl ~/amc $ git svn fetch

At this point a git svn rebase should indicated “Current branch mastger is up to date.”

March 14, 2008

git - workflow with remote svn repositories

Filed under: programming, scm — wink @ 11:11 am

I’m going to try a new git-svn workflow. Previously I did a git svn clone and also created a backup on my backup server as a remote. So pictorially something like this:

    local-git-svn-clone
           /       \
          /         \
         /           \
remote-svn            backup-server

This worked OK but I’ve made mistakes in the local-git-svn-clone and have had to start all over because things got out of sync. Most often this would happen if I merged into the master branch pushed to the backup-server than then did a “git svn rebase”. I would end up not being able to do any more pushes to the backup-server.

To try to reduce the possibility of mistakes I’m going to try separate repos. So I first. cloned the svn repo as normal:

<local>$ git svn clone -s svn+ssh://wink@<remote-svn-rep>/<path to repo> <local-git-svn-clone>

Then I made a local clone of local-git-svn-clone:

<local>$ git clone local-git-svn-clone local-clone

Next ssh into my backup-server and create a bare shared repo.

<local>$ ssh wink@<backup-server>
<backup-server>$ cd <git-repos>
<backup-server>$ mkdir <backup-repo>
<backup-server>$ cd <backup-repo>
<backup-server>$ git --bare init --shared
<backup-server>$ exit
<local>$

Now back on my local machine I push the local-git-svn-clone repo to the backup repository.

<local>$ cd <local-clone>
<local>$ git remote add backup git://<backup-server>/<backup-repo>
<local>$ git push --repo=backup --all

So at this point <local-clone> points at <local-git-svn-clone> and <backup-repo> which I don’t want. What I want is <local-clone> to just point at <backup-repo>. There may be a simpler way to do this, but I choose to actually delete <local-clone> and create it anew from <backup-repo>.

<local>$ cd ..
<local>$ rm <local-clone>
<local>$ git clone git://<backup-server>/<backup-repo> <local-clone>

So now I have two separate repos on local. <local-clone> connected to <backup-server>/<backup-repo> and <local-git-svn-clone> connected to the <remote-svn-repo>/<path to repo>.

    local-clone    << git pull >>    local-git-svn-clone
           /                                      \
          /                                        \
         /                                          \
back-repo                                          backup-server

Without the direct connection between , but since they are both based on the svn repo I can easily pull local-clone from local-git-svn-clone.

With this configuration you work on branches in local-clone, don’t work on master, the goal is to keep local-clone master exactly the same as local-git-svn-clone. If you don’t do this it will you’ll see trapezoidal commits and things get confusing.

So the work flow becomes:

local-clone$ git checkout -b x
local-clone$ hack
local-clone$ git commit (or git gui)
local-clone$ test
local-clone$ repeat more hack/commit/test
local-clone$ git push --all

So you’ve been working a while and periodically pushing to your back-repo to backup local-clone. Eventually you’ll want to commit the work you’ve done. To do this you’ll pull the changes from local-clone x branch to local-git-svn-clone, svn rebase, test and svn dcommit.

local-git-svn-clone$ git pull <local-clone> x:master
local-git-svn-clone$ git svn rebase
local-git-svn-clone$ test
local-git-svn-clone$ git svn dcommit

If the git svn rebase pulled in a lot of changes you may want to pull these over to local-clone if there and hack/test/commit then back to the above. Eventually you’ll do the svn dcommit.

The last step is to get the changes in local-git-svn-clone into local-clone and push them to backup-repo.

local-clone$ git pull <local-git-svn-clone>
local-clone$ git branch -D x
local-clone$ git push

Of course you don’t need to delete the branch x but all of those changes are now in the local-clone master so they aren’t needed.

March 10, 2008

Linking - How to link 32bit and 64bit x86 code into one image

Filed under: linux, programming — wink @ 11:05 pm

Learned something new from TJ over at Codegen today, he solved a problem where we needed to have 32bit code linked with 64bit code but the linker wouldn’t do it. Apparently this use to work without doing anything, but with the latest linker (ld) code it doesn’t. TJ figured out all that needed to be done was use objcopy to convert the 32bit format to 64bit format:

objcopy -O elf64-x86_64 32bit.o 64bit.o

One other noteworthy element to determine the output formats that objcopy supports use objcopy –info or objcopy –help

wink@ic2d1:$ objcopy --info
BFD header file version (GNU Binutils for Ubuntu) 2.18
elf64-x86-64
 (header little endian, data little endian)
  i386
elf32-i386
 (header little endian, data little endian)
  i386
a.out-i386-linux
 (header little endian, data little endian)
  i386
efi-app-ia32
 (header little endian, data little endian)
  i386
efi-app-x86_64
 (header little endian, data little endian)
  i386
elf64-little
 (header little endian, data little endian)
  i386
elf64-big
 (header big endian, data big endian)
  i386
elf32-little
 (header little endian, data little endian)
  i386
elf32-big
 (header big endian, data big endian)
  i386
srec
 (header endianness unknown, data endianness unknown)
  i386
symbolsrec
 (header endianness unknown, data endianness unknown)
  i386
tekhex
 (header endianness unknown, data endianness unknown)
  i386
binary
 (header endianness unknown, data endianness unknown)
  i386
ihex
 (header endianness unknown, data endianness unknown)
  i386

               elf64-x86-64 elf32-i386 a.out-i386-linux efi-app-ia32
          i386 elf64-x86-64 elf32-i386 a.out-i386-linux efi-app-ia32
               efi-app-x86_64 elf64-little elf64-big elf32-little elf32-big
          i386 efi-app-x86_64 elf64-little elf64-big elf32-little elf32-big
               srec symbolsrec tekhex binary ihex
          i386 srec symbolsrec tekhex binary ihex

March 7, 2008

make - need VPATH for non-local files if implicit rules are used

Filed under: linux, programming — wink @ 5:31 pm

Ran into a strange problem today, for some reason if a file isn’t in the current directory I need to have VPATH defined so that it points to the directory that contains the file(s) if the rule is implicit. For example, with the following structure where the Makefile is in a subdirectory below the location of the source file:

wink.c
x/Makefile

and the Makefile file is:cat x/Makefile is:

wink@ic2d1:$ cat x/Makefile
#VPATH=../
wink.o: ../wink.c
clean:
      rm *.o

If I now go into x and do a make –debug the we see the following:

wink@ic2d1:$ make --debug
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for x86_64-pc-linux-gnu
Reading makefiles...
Updating goal targets....
 File `wink.o' does not exist.
Must remake target `wink.o'.
Successfully remade target file `wink.o'.
make: Nothing to be done for `wink.o'.

So it knows it needs to”remake target ‘wink.o’” but then says “Successfully remade …” but it didn’t, wink.o isn’t built. If I now enable VPATH and Makefile is:

wink@ic2d1:$ cat x/Makefile
VPATH=../
wink.o: ../wink.c
clean:
      rm *.o

Now make –debug does build wink.o and the output is:

wink@ic2d1:$ make --debug
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for x86_64-pc-linux-gnu
Reading makefiles...
Updating goal targets....
 File `wink.o' does not exist.
Must remake target `wink.o'.
cc    -c -o wink.o ../wink.c
Successfully remade target file `wink.o'.

If you have an explicit rule everything works as expected as well:

wink@ic2d1:$ cat Makefile
#VPATH=../
wink.o: ../wink.c
	$(CC) $(CFLAGS) -c -o $@ $<
clean:
      rm *.o

Now make –debug also builds wink.o and the output is:

wink@ic2d1:$ make --debug
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for x86_64-pc-linux-gnu
Reading makefiles...
Updating goal targets....
 File `wink.o' does not exist.
Must remake target `wink.o'.
cc    -c -o wink.o ../wink.c
Successfully remade target file `wink.o'.

Another solution is don’t use Gnu Make but use pmake. Of course if the makefile isn’t compatible with pmake then this won’t work. On Ubuntu install the bin86 package via synaptic or “apt-get install pmake”.

March 3, 2008

PXE - Booting via network cards

Filed under: linux, programming, pxe — wink @ 2:08 pm

To get PXE there are several resources on the web, here and here. The sources for pxelinux.0 is in syslinux. Anyway, here’s what I did; First, to use PXE you need to have a more capable DHCP server, so I switched to dhcpd3-server on my linux:

wink@saville-server:/etc/dhcp3$ cat my-dhcpd.conf
ddns-update-style interim;
option domain-name "saville.com";
option domain-name-servers 68.87.76.178, 66.240.49.9;
default-lease-time 600;max-lease-time 7200;

log-facility local7;
subnet 192.168.0.0 netmask 255.255.255.0 {
   range 192.168.0.100 192.168.0.149;
   option routers 192.168.0.2;
}

host test1 {
   hardware ethernet 00:1D:7D:00:A3:0B;
   fixed-address 192.168.0.148;
   option host-name "test1";
   filename "pxelinux.0";
   next-server 192.168.0.99;
}

The “host” section is the important part for PXE and in particular “hardware” identifies the card via its ethernet id, “filename” defines the file that will be requested and “next-server” defines the IP address of the server that will server the file to the “test1″ client via tftp.

So the next step was to get tftp working, I did the following but obviously synaptic works also:

apt-get install tftpd-hpa

I the config file for tftpd needs a little doctoring. The defaults is not running as a daemon and the directory is /var/log/tftpboot. You need it to run as a daemon and you may want to change the directory, here is what I have:

#Defaults for tftpd-hpa
RUN_DAEMON="yes"
OPTIONS="-l -s /tftpboot"

To start/test manually run “sudo /etc/init.d/tftpd-hpa start”. You should be able to see tftp using netstat:

wink@ic2d1:$ netstat netstat -apu
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
udp        0      0 *:32769                 *:*                                -
udp        0      0 *:32772                 *:*                                -
udp        0      0 ic2d1.local:netbios-ns  *:*                                -
udp        0      0 *:netbios-ns            *:*                                -
udp        0      0 ic2d1.local:netbios-dgm *:*                                -
udp        0      0 *:netbios-dgm           *:*                                -
udp        0      0 *:946                   *:*                                -
udp        0      0 *:tftp                  *:*                                -       
udp        0      0 *:mdns                  *:*                                -
udp        0      0 *:sunrpc                *:*                                -
udp        0      0 ic2d1.local:ntp         *:*                                -
udp        0      0 localhost:ntp           *:*                                -
udp        0      0 *:ntp                   *:*                                -
udp6       0      0 fe80::217:31ff:fee1:ntp *:*                                -
udp6       0      0 ip6-localhost:ntp       *:*                                -
udp6       0      0 *:ntp                   *:*                                -

You should now be able to add files to the directory /tftpboot such as pxelinux.0.

February 24, 2008

Ajax - responses must have Content-Length

Filed under: Ajax, firefox — wink @ 2:30 pm

When responding to an AJAX request, actually when responding to any HTTP/1.1 request that is going to be kept alive you need to have a Content-Length header field even if the the content length is 0.

February 23, 2008

Java - sources in jar’s

Filed under: java — wink @ 7:33 pm

While debugging Ajax support for AMC I learned that to debug class files that java libraries (aka. jar files) all you need to do is include the java files in the jar files.

February 22, 2008

Firefox/Apache - debug server side php code

Filed under: Apache, firefox — wink @ 11:10 am

To apache debug server-side scripts the typical solution is to usr print statements back to the browser. But that won’t work for AJAX as there isn’t any place to view the output.

The other method is to log to a file

$fp = fopen(’debug.php’, ‘ab’);
fwrite($fp, “debug data …”);
// Then eventually close
fclose($fp);

Filed under: firefox — wink @ 11:03 am

Debugging Firefox:

*) DOM Inspector:

By default on Ubuntu the firefox DOM inspector isn’t enabled and when reading “Programmin Firefox” it is one of the recommended tools

But it isn’t enabled by default, apparently this is the case for Windows also where you need to do a custom install to get it. For Ubuntu I installed it via synaptic as firefox-dom-inspector I also added firefox-dbg and firefox-dev. Interesting, it wasn’t available right away and I needed to reboot the system, although there may be other ways.

*) Java script parsing bugs

At the moment, 20070602, I don’t see parsing errors for java script files I create?

*) Java script runtime debugging:

Method one: run FF from the command line with the -console option: wink@ic2d1:~$ firefox -console & and then use “dump” commands to print strings to the console.

Method two: use Venkman debugger. Again, wasn’t available by default, I used Toos->Add-on and navigated to “Web and developer tools” and searched for debugger, the Venkman debugger was the first choice. Seleting this and the “Install Now” button installed it.

*) Venkman debugger:

To get Venkman to debug my overlay I had to enable browser files: Goto menu item “Debug/Exclude Browser Files” and be sure it is not checked. The list of files will then expand and my script “sl.js” was visible. A break point could then be set.

Newer Posts »

Powered by WordPress