Friday, November 11, 2011

Compile NS-2.34 and 2.35 with GCC-4.6

I stumbled into the compilation issue after upgrading to Ubuntu Oneiric 11.10. The error occurs in "mac-802_11Ext.h" saying something like the following:
mac/mac-802_11Ext.h: In member function 'u_int32_t PHY_MIBExt::getHdrLen11()':mac/mac-802_11Ext.h:175:19: error: expected primary-expression before 'struct'mac/mac-802_11Ext.h:175:41: error: 'dh_body' was not declared in this scopemac/mac-802_11Ext.h:175:51: error: 'offsetof' was not declared in this scope
I found the solution in Ubuntu's patched version of NS-2.35-RC6. The direct link to the patch is here: http://launchpadlibrarian.net/74445224/ns2_2.35~RC6-4_2.35~RC6-4ubuntu1.diff.gz

It's really simple. All you have to do is to add #include cstddef as shown below:
#ifndef ns_mac_80211Ext_h
#define ns_mac_80211Ext_h
#include cstddef
#include "marshall.h"
#include "timer-handler.h"
 Now, NS-2.34 should compile fine with GCC-4.6. Enjoy your simulation!

P.S. BlogSpot is simply terrible for posting code snippets. For clarity, here's a screenshot of what the code should look like.

 

Friday, October 21, 2011

Google Chrome (Chromium) font anti-aliasing is wrong on LXDE (L)Ubuntu Oneiric (11.10)

The solution was to add the following in the ~/.fonts.conf 

xml version="1.0"?>DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
 <match target="font">
  <edit mode="assign" name="rgba">
   <const>noneconst>
  edit>
 match>
 <match target="font">
  <edit mode="assign" name="hinting">
   <bool>truebool>
  edit>
 match>
 <match target="font">
  <edit mode="assign" name="hintstyle">
   <const>hintslightconst>
  edit>
 match>
 <match target="font">
  <edit mode="assign" name="antialias">
   <bool>truebool>
  edit>
 match>
 <match target="font">
   <edit mode="assign" name="lcdfilter">
    <const>lcddefaultconst>
   <edit>
 <match>
</fontconfig>

One may have to play around with the "hintstyle" to get it right. The available options are:
  • hintslight
  • hintmedium
  • hintfull
  • none

Wednesday, October 19, 2011

Ubuntu Oneiric (11.10) DPKG error removing old Linux kernel

I stumbled into another trouble removing my obsolete packages after upgrading into Ubuntu Oneiric 11.10 with Linux kernel 3.00-12. The problem is with removing the old 64bit kernel 2.6.35-24. The Debian package name is 2.6.35-24. The error I got is following:
[13:41:34] user@machin:[/var/lib/dpkg/info]$ sudo apt-get -f install
Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following packages will be REMOVED:
  linux-image-2.6.35-24-generic
0 upgraded, 0 newly installed, 1 to remove and 31 not upgraded.
1 not fully installed or removed.
After this operation, 139 MB disk space will be freed.
Do you want to continue [Y/n]?
(Reading database ... 248250 files and directories currently installed.)
Removing linux-image-2.6.35-24-generic ...
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 2.6.35-24-generic /boot/vmlinuz-2.6.35-24-generic
update-initramfs: Deleting /boot/initrd.img-2.6.35-24-generic
run-parts: executing /etc/kernel/postrm.d/zz-extlinux 2.6.35-24-generic /boot/vmlinuz-2.6.35-24-generic
P: Checking for EXTLINUX directory... found.
P: Writing config for /boot/vmlinuz-3.0.0-12-generic...
E: /usr/share/syslinux/debian/extlinux: No such file or directory
run-parts: /etc/kernel/postrm.d/zz-extlinux exited with return code 1
Failed to process /etc/kernel/postrm.d at /var/lib/dpkg/info/linux-image-2.6.35-24-generic.postrm line 328.
dpkg: error processing linux-image-2.6.35-24-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
Errors were encountered while processing:
 linux-image-2.6.35-24-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)
The highlighted lines told me the error is caused by the postrm script called zz-extlinux located in /etc/kernel/postrm.d/. I don't know how I managed to have extlinux installed on my system. If I am not mistaken booting is still managed by grub-2. So, I decided to remove both extlinux and linux-image-2.6.35-24-generic. But, since my DPKG is already going crazy removing linux-image-2.6.35-24-generic and failing on zz-extlinux, I have to remove the old Linux image first. I quickly patched the zz-extlinux script with an "exit 0" at top followed by an "sudo apt-get -f install". One could also make it non-executable as following as a solution, followe:
sudo chmod -x /etc/kernel/postrm.d/zz-extlinux; sudo apt-get -f install
This solved my problem removing the Linux image. Now, I guess one can also remove extlinux considering Grub-2 is the bootloader.
sudo apt-get remove --purge extlinux

Tuesday, October 18, 2011

Changing Gnome-Screensaver Background on Lubuntu 11.10 (Oneiric)

I had to find a way on Lubuntu flavoured LXDE to lock/unlock the current running desktop session. The obvious easy way is to use xscreensaver and/or gnome-screensaver and do one of the following:
xscreensaver-command -lock
gnome-screensaver-command --lock
I chose to keep with gnome-screensaver since it is prettier. But immediate annoyance was after locking screen, gnome-screensaver would not retain the same background as current Lubuntu session. After trying so many options (gconf, editing files in /etc), finally I figured - the solution is rather easy.

It appears Lubutu session keeps a separate sets of options from LXDE. When gnome-screensaver is launched, it takes the background option of LXDE (not Lubuntu). To match same background both on LXDE and Lubuntu, which also matches gnome-screensaver background inside Lubuntu session, the steps are below:
  1. Set preferred desktop background on running Lubuntu session by right-click > Desktop Preferences > Background.
  2. Log-out from Lubuntu session.
  3. On the log-in prompt, select LXDE as desktop session to log into.
  4. Once inside LXDE, you'll see the desktop background that gnome-screensaver uses as background.
  5. From the right-click menu, change the background to match your preference.
That's all !!! Now, you can log in back into Lubuntu and lock screen by initiating gnome-screensaver (I use a Compiz command shortcut with Ctrl+Alt+L which triggers "gnome-screensaver-command --lock") and desktop background will match.

Ubuntu Oneiric 11.10 - problem with package dictionaries-common

I started getting troubles with dictionaries-common package right from the beginning of upgrading into Ubuntu Oneiric (11.10). The error message looks kind of like the following:


Setting up dictionaries-common (1.11.5ubuntu1) ...
update-default-wordlist: Question empty but elements installed for class "wordlist"
  dictionaries-common/default-wordlist: return code: "0", value: ""
  Choices: , Manual symlink setting
  shared/packages-wordlist: return code: "10" owners/error: "shared/packages-wordlist doesn't exist"
  Installed elements: american (American English)
  Please see "/usr/share/doc/dictionaries-common/README.problems", section
  "Debconf database corruption" for recovery info.
update-default-wordlist: Selected wordlist "" 
does not correspond to any installed package in the system
and no alternative wordlist could be selected.
dpkg: error processing dictionaries-common (--configure):
 subprocess installed post-installation script returned error exit status 255
dpkg: dependency problems prevent configuration of xscreensaver-data-extra:
 xscreensaver-data-extra depends on dictionaries-common; however:
  Package dictionaries-common is not configured yet.
dpkg: error processing xscreensaver-data-extra (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
Errors were encountered while processing:
 dictionaries-common
 xscreensaver-data-extra
E: Sub-process /usr/bin/dpkg returned an error code (1)

May be I was too quick to have skimmed over the error message and did not realize what is missing. It looks like the problem actually is that I do not have any word-list installed (or, somehow uninstalled during the distribution upgrade process) on my machine for the dictionary to point to. The quick solution is to install the preferred word-list as following:
sudo apt-get install wamerican-insane
 This should remove fix the package installation error with dictionaries-common package.


Compiz Config Settings Manager (CCSM) crashes with SIGSEGV on (L)ubuntu Oneiric (11.10)

On my latest Lubuntu 11.10 installation, CCSM stumbles into a segmentation violation (SIGSEGV) if "Desktop Cube" is enabled in Compiz plugins and I try to disable it through CCSM. Since, I managed to convince myself that "Expo" is capable of providing what I really need, I needed a way to disable it without using CCSM. So, for my own future reference and someone who's going through the same kind of nagging crash, the Compiz config file is located here:
/home/$USER/.config/compiz-1/compizconfig/Default.ini
My list of enabled plugins are below:
 [core] 
s0_active_plugins = core;detection;gtkloader;composite;opengl;copytex;decor;mousepoll;commands;imgjpeg;regex;addhelper;annotate;resize;grid;compiztoolbox;place;imgsvg;imgpng;notification;dbus;gnomecompat;resizeinfo;opacify;wobbly;move;text;loginout;scale;animation;kdecompat;thumbnail;workarounds;scaleaddon;scalefilter;animationaddon;expo;ezoom;switcher;
All one has to do is remove "cube" (or whichever is causing trouble) from "s0_active_plugins".

LightDM Fails to Load with (L)ubuntu Oneiric (11.10)

After my migration from default Ubuntu with Unity and Gnome3 to Lubuntu with LXDE and OpenBox, I realized I have managed to sacrifice beautiful LightDM, the new default login manager on 11.10 and instead, running not so pretty LXDM.

After realizing that LightDM is missing the first thing to do was obviously:
sudo apt-get install lightdm
Followed by:
sudo dpkg-reconfigure lightdm
sudo service lxde stop
sudo service lightdm start
Not much to my surprise on 11.10, LightDM didn't start. After a little digging through the log files located at /var/log/lightdm, I came across the following:

"lightdm can not write to /var/lib/lightdm/.Xauthority"

Time to check /var/lib/lightdm directory:

[11:13:26] user@machine:[/var/lib/lightdm]$ sudo ls -alh
total 44K
drwxr-x---  9  109  130 4.0K 2011-10-14 20:08 .
drwxr-xr-x 74 root root 4.0K 2011-10-17 16:56 ..
drwx------  4  119  136 4.0K 2011-10-14 15:28 .cache
drwx------  4  119  136 4.0K 2011-10-14 15:28 .config
drwx------  3  119  136 4.0K 2011-10-14 15:28 .dbus
-rw-------  1  119  136   16 2011-10-14 15:32 .esd_auth
drwx------  2  119  136 4.0K 2011-10-14 18:29 .gconf
-rw-------  1  119  136    0 2011-10-14 19:55 .goutputstream-54JJ3V
drwx------  2  119  136 4.0K 2011-10-14 15:28 .gvfs
drwxrwxr-x  3  119  136 4.0K 2011-10-14 15:32 .local
drwx------  2  119  136 4.0K 2011-10-14 16:22 .pulse
-rw-------  1  119  136  256 2011-10-14 15:32 .pulse-cookie
-rw-------  1  119  136    0 2011-10-14 20:08 .Xauthority


After checking /etc/passwd and /etc/group, it confirmed that somehow user-id 119 and groupd-id 136 has gone missing from my system. So, as a quick roll-back, I did the following:

sudo apt-get remove --purge lightdm
sudo mv /var/lib/lightdm /var/lib/lightdm.bak
sudo apt-get install lightdm
sudo service lxdm stop
sudo apt-get remove --purge lxdm
sudo service lightdm start

Voila, LightDM showed up with a nice log-in prompt. Re-installing LightDM, added a new user and group with ids 109 and 130 respectively. Also, the ls output in /var/lib/lightdm looks correct.

[11:33:08] user@machine:[/var/log/lightdm]$ sudo ls -al /var/lib/lightdm/
total 44
drwxr-x---  9 lightdm lightdm 4096 2011-10-18 11:14 .
drwxr-xr-x 74 root    root    4096 2011-10-18 11:15 ..
drwx------  4 lightdm lightdm 4096 2011-10-18 11:14 .cache
drwx------  3 lightdm lightdm 4096 2011-10-18 11:14 .config
drwx------  3 lightdm lightdm 4096 2011-10-18 11:14 .dbus
-rw-------  1 lightdm lightdm   16 2011-10-18 11:14 .esd_auth
drwx------  5 lightdm lightdm 4096 2011-10-18 11:15 .gconf
d?????????  ? ?       ?          ?                ? .gvfs
drwxrwxr-x  3 lightdm lightdm 4096 2011-10-18 11:14 .local
drwx------  2 lightdm lightdm 4096 2011-10-18 11:14 .pulse
-rw-------  1 lightdm lightdm  256 2011-10-18 11:14 .pulse-cookie
-rw-------  1 lightdm lightdm   49 2011-10-18 11:14 .Xauthority



Edit (20 Jan 2012):
I stumbled into another problem with LightDM after uninstalling gnome-settings-daemon. It looks like the background file to set for LightDM is requested through gnome-settings-daemon for some reason on my system. So, if you have the same problem, a quick apt-get install gnome-settings-daemon will solve the problem.

Tuesday, September 27, 2011

Removing "RC" packages on Debian/Ubuntu

If you do "dpkg -l", sometimes you will get to see a long list of packages with the following details:
  • rc  package-name  0.4-3  package-details
Note the "rc" status at the beginning of the package description. Some packages will show up in the "dpkg -l" output even after removing them. The reason behind this is - packages with "rc" status indicate that the packages have been removed but some configuration files for those packages are left on the system.

To remove these packages, do the following:
  • sudo dpkg --purge package-name
For a list of packages, run the following:
  • dpkg -l | grep ^rc | cut -d ' ' -f3 | xargs sudo dpkg --purge








Friday, September 2, 2011

Forcing Vim's syntax highlighting (for odd file extensions)

I often tend to keep backup copies of my C/C++ source files with odd extensions (i.e. something that does not end with CC or C). If these files are opened with Vim, they wouldn't be recognized as they should, which means my CTAGS extension and colored syntax highlighting would both refrain to work. The quick solution to this problem is to tell Vim explicitly about the file type. Here is how one can do it:
:setfiletype c
More information on it, as always:
:help setfiletype

Wednesday, August 24, 2011

Remove Firefox add-ons installed by 3rd Party Applications

The list of add-ons with pointers to the XPI code is here:

HKEY_CURRENT_USER\Software\Mozilla\Firefox\Extensions.

Just remove the unwanted entry from the list. Cheers :).

Tuesday, August 23, 2011

Multiple Java Console add-on in Firefox

I recently discovered more than one Java console add-on inside my add-ons manager in my Windows 7 machine. Since I only had only one version of JRE (Java Runtime Environment) updated to the latest version, this did not make sense. To make it more of an eye-sore, these add-ons did not have an associated "Remove" button in the add-on manager.

Some Google-ing revealed these are Java update left-overs. They do not have the "Remove" button because they are installed inside the %ProgramFiles(x86)%\Mozilla Firefox and not inside the %AppData%\Mozilla\Firefox profile directory.

In my installation, I had the following directories inside %ProgramFiles(x86)%\Mozilla Firefox\extensions directory:
  • {CAFEEFAC-0016-0000-0026-ABCDEFFEDCBA}
  • {CAFEEFAC-0016-0000-0023-ABCDEFFEDCBA}
  • {CAFEEFAC-0016-0000-0017-ABCDEFFEDCBA}
The blue numbers are indicative to the Java versions. To remove older left-overs, just keep the folder with associated with the latest Java version, which usually is the highest number in the list and delete the others.

Thursday, July 14, 2011

Evince would not start over SSH X-forwarding

Evince, which is the primary PDF and PostScript viewer on Ubuntu, recently stopped working on my Ubuntu/Natty (11.04) over SSH X-forwarding. It works flawlessly inside 'gnome-session'. But, would not run as a regular application (e.g. xpdf or gv) over X-forwarded SSH.

After digging up a little bit, I found a lots of these message in my
dmesg output:

[1305902.871825] type=1400 audit(1310620543.587:75): apparmor="STATUS" operation="profile_remove" name="/usr/bin/evince" pid=20166 comm="apparmor

It was obvious that apparmor [1] was blocking Evince to run outside Gnome session over SSH. A solution to disable the AppArmor block on Evince over SSH connection was suggested here [2]:

#inside the gnome-terminal
sudo ln -s /etc/apparmor.d/usr.bin.evince /etc/apparmor.d/disable
sudo /etc/init.d/apparmor restart


And voila! Now Evince can again be launched over SSH.

[1] http://en.wikipedia.org/wiki/AppArmour
[2] http://ubuntuforums.org/showthread.php?t=1472642

Thursday, January 27, 2011

No need to multi-thread if one dones't have to ...

I like spend time writing, re-writing, reversing and hacking into codes. I consider myself a learner. Regarding multi-threaded codes, I keep a simple belief that almost all of them could be written using a single thread doing effectively the same thing. I realize the world isn't going to change because of what I believe. I wrote the following little piece to demonstrate a friend of mine that a multi-threaded version of one of his little projects which has a functions that blocks and responsible for a few other things (eg. write_db(), on_demand() ) could also have been written using a single-thread. For whatever it is worth, here is my little demo code:


#include < stdio.h >
#include < sys/time.h >
#include < signal.h >
#include < setjmp.h >

typedef void (*sighandler_t) (int);
sigjmp_buf saved_state;

struct data
{
unsigned int count;
unsigned int epoch;
double watt;
} d;

/*
* This value (in seconds) defines how often an
* attempt is made to read the serial port.
*/
unsigned int sleep_time = 10;
unsigned int sleep_start = 0; // in epoch seconds

/*
* Function to write into SQLite/RRD database.
*/
int write_db()
{
printf("[*] write_db()\n");
return 0;
}

/*
* Function to serve on-demand query.
*/
void on_demand()
{
printf("[*] on_demand() :: ");
printf("count %u now %u watt %.2f\n", d.count, d.epoch, d.watt);
fflush(stdout);
siglongjmp(saved_state, 1);
}

/*
* Function to read from serial port.
*/
int blocking_read()
{
struct timeval timeout;

printf("[*] blocking_read() :: ");

/* simulate the read() blocking-time */
timeout.tv_sec = 0;
timeout.tv_usec = 500;

select(0, NULL, NULL, NULL, &timeout);
d.count = d.count + 1;
d.epoch = time(NULL);
d.watt = random();

printf("count %u now %u watt %.2f\n", d.count, d.epoch, d.watt);
fflush(stdout);
return 0;
}

int main()
{
printf("[*] main() -- pid: %u\n\n", getpid());
fflush(stdout);

signal(SIGUSR1, (sighandler_t) on_demand);

while (1)
{
/*
* If we have just came out from a
* signal, perform the pending delay.
*/
sigsetjmp(saved_state, 1);
if ((int)(sleep_start + sleep_time - time(NULL)) > 0) {
printf("[-] pending delay %u secs\n",
(int)(sleep_start + sleep_time - time(NULL)));
fflush(stdout);
sleep((sleep_start + sleep_time) - time(NULL));
}

blocking_read();
write_db();
printf("\n");
fflush(stdout);

/*
* collect serial port data at
* each 'sleep_time' seconds.
*/
sleep_start = time(NULL);
sleep(sleep_time);
}
return 0;
}

Friday, January 14, 2011

Keyboard num-keys not working in VirtualBox Ubuntu guest

The solution that works for me is by disabling 'Mouse Keys'.
  • Go to System > Preferences > Keyboard.
  • In Mouse Keys tab, un-tick 'Pointer can be controlled using keypad'