Monday, November 20, 2006

Firefox speedup

I have a cable modem with the screaming download rate. My machine is also have 2Gig of RAM for the firefox to hog. Still I found the pages taking their own time to load. With some help from google I changed some of the configuration in firefox. Type about:config in the address bar. I change the following setting and the changed values are shown.

network.http.pipelining true
network.http.proxy.pipelining true
network.http.max-connections 64
network.http.max-connections-per-server 32
network.http.max-persistent-connections-per-proxy 12
network.http.max-persistent-connections-per-server 6



After this most of the pages load in a flash. Ofcourse these settings are not for everybody. I have the CPU and memory to live with this setting. It may or may not work for you. So use it with caution.

Tuesday, September 26, 2006

Is it a 'char' or 'unsigned char' or 'signed char'?

I inherited a overly-loaded code something like this...

void func(boost::int8_t p)
{
std::cout << "boost::int8_t" << std::endl;
}
void func(boost::uint8_t p)
{
std::cout << "boost::uint8_t" << std::endl;
}
void f1(boost::int16_t s)
{
std::cout << "boost::int16_t" << std::endl;
}
void f1(boost::uint16_t s)
{
std::cout << "boost::uint16_t" << std::endl;
}
main()
{
short sh;
char c;
f1(sh);
func(c);
}


I tried to compile the above code but the compiler is refusing to proceed balking at "func(c)", while it is completely happy with f1(sh). For the uninitiated boost types are typedef-ed to the appropriate platform types like int8_t -> signed char uint8_t -> unsigned char.

It turned out that the language does not specify whether variables of type char are signed or unsigned quantities. So the compiler complains about the func(c) call because it is ambiguous. Whereas f1(sh) succeeds.

Changind the "char c" to "unsigned char" or "signed char" resolves the ambiguity and calms down the compiler. Curiously even forcing the compiler with -funsigned-char didn't help in this case.

Well my philosophy of solving any problem by an extra level of indirection also didn't work. I tried something like this...


template
void func_char_resolver(T c);

template<>
void func_char_resolver(boost::int8_t c) { /// dealing with singed char....
}

template<>
void func_char_resolver(boost::uint8_t c) { /// dealing with unsinged char....
}
void func(char c)
{
func_char_resolver(c);
}


I don't know may be because `char' is a distinct type (of undefined sign) hence none of the specializations matched. Oh well!

Friday, September 22, 2006

ssh error in locking authority file!

While ssh-ing to one of my remote machines I got this error and X forwarding kept failing because of thsi.

/usr/bin/X11/xauth: error in locking authority file

Who would have guessed the problem? I'm running out of my disk quota! It is a weird way of warning about quota over run! 'quota -v' did confirm the theory and after killing few MB's the problem indeed go away!

Wednesday, September 20, 2006

Problems with X11 Composite Extension

When I enabled trancelucency in my KDE the composite manager crashed with the
message asking to insert the following lines in xorg.conf.

Section "Extensions"
Option "Composite" "Enable"
EndSection

And so I did and forgot about it for a week. Last week when I tried to launch
gnucash it wouldn't . It cried something like this.

-------
Gdk-CRITICAL **: file gdkwindow.c: line 1406 (gdk_window_get_visual):
assertion `window != NULL' failed.

Gdk-CRITICAL **: file gdkcolor.c: line 57 (gdk_colormap_new): assertion
`visual != NULL' failed.
SESSION_MANAGER=tcp/pdm1:53739

Gdk-CRITICAL **: file gdkwindow.c: line 1406 (gdk_window_get_visual):
assertion `window != NULL' failed.

Gdk-CRITICAL **: file gdkcolor.c: line 57 (gdk_colormap_new): assertion
`visual != NULL' failed.
Gdk-ERROR **: BadDrawable (invalid Pixmap or Window parameter)
serial 47 error_code 9 request_code 132 minor_code 5
Gdk-ERROR **: BadDrawable (invalid Pixmap or Window parameter)
serial 48 error_code 9 request_code 55 minor_code 0
--------

I thought one of yum update screwed it up. So I looked through the recent
update logs and couldn't find anything remotely connected to gnucash , X11,
gdk or my window manager. Frustrated like hell I stopped thinking about this
problem. I couldn't do my accounting for a week!

It wasn't until I tried to launch one more app which failed with the same
exception. I then started digging deep and found that the culprit was the
Composite extension option. So I disabled the following from xorg.conf

#Section "Extensions"
#Option "Composite" "Enable"
#EndSection

and yes I did my accounts immediately!

Friday, September 08, 2006

Kerberos on 64bit Linux with gcc 4.0

I was trying to compile kerberos on a 64 bit linux (CentOS). First I was getting configure errors about res_search(). Then I downloaded the latest and the greatest v5-1.5.1 from mit and tried to compile with gcc version 4.0. First the configure script was using the old compiler. So I need to teach it to use the gcc4. So I did...


export CC=gcc4
export CXX=g++4


After this configure script went fine. But the compilation was producing some errors like the following in the kadmin/test directory.

tcl_ovsec_kadm.c:85: `Tcl_HashEntry' undeclared (first use in this function)
tcl_ovsec_kadm.c:85: (Each undeclared identifier is reported only once
tcl_ovsec_kadm.c:85: for each function it appears in.)
tcl_ovsec_kadm.c:85: `entry' undeclared (first use in this function)
tcl_ovsec_kadm.c:93: warning: implicit declaration of function `Tcl_InitHashTable'
tcl_ovsec_kadm.c:93: `TCL_STRING_KEYS' undeclared (first use in this function)
tcl_ovsec_kadm.c:105: warning: implicit declaration of function`Tcl_CreateHashEntry'
tcl_ovsec_kadm.c:109: warning: implicit declaration of function `Tcl_SetHashValue'



Looks like I'm not alone -> http://mailman.mit.edu/pipermail/kerberos/2004-September/006391.html
So I followed it faitfully like this and everything went fine.

./configure --prefix=/home/test/krb5 --without-tcl

Tuesday, August 22, 2006

Getting the gcc/g++ compiler #define-s

I was doing 64 bit migration and wanted to know more about gcc/g++ compiler #define-s. One of my friend Homolka Richard gave me a very nice tip. Alias the whole thing!


alias whatg++='echo "main(){}" | g++ -E -x c++ -dM - '
alias whatgcc='echo "main(){}" | gcc -E -x c -dM - '


So running whatg++ from now on will list all the compiler #define-s something like this...


#define __HAVE_BUILTIN_SETJMP__ 1
#define __unix__ 1
#define unix 1
#define __i386__ 1
#define __SIZE_TYPE__ unsigned int
#define __ELF__ 1
#define __GNUC_PATCHLEVEL__ 3
#define __linux 1
#define __unix 1
#define __linux__ 1
#define __USER_LABEL_PREFIX__
#define linux 1
#define __STDC_HOSTED__ 1
#define __EXCEPTIONS 1
#define __GXX_WEAK__ 1
#define __WCHAR_TYPE__ long int
#define __gnu_linux__ 1
#define __WINT_TYPE__ unsigned int
#define __GNUC__ 3
#define __cplusplus 1
#define __DEPRECATED 1
#define __GNUG__ 3
#define __GXX_ABI_VERSION 102
#define i386 1
#define __GNUC_MINOR__ 2
#define __STDC__ 1
#define __PTRDIFF_TYPE__ int
#define __tune_i386__ 1
#define __REGISTER_PREFIX__
#define __NO_INLINE__ 1
#define _GNU_SOURCE 1
#define __i386 1
#define __VERSION__ "3.2.3 20030502 (Red Hat Linux 3.2.3-47.3)"

Wednesday, August 16, 2006

IMAP through SSL using pine

I have a unix/mail account on a external BSD server. Being a great fan of text mode I use fetchmail to retrieve the mails to my local linux machine and run elm or pine depending on my mood. But my mail server being too restictive on the smtp side, I couldn't hit reply on my local machine and send a reply or send a new mail. Relaying was denied. I could have used a different smtp server of course. But I wanted a simple solution.

So I setup pine on my local machine to do IMAP to my server and things are suddenly rosier. My local copy of pine works on the IMAP folders on my server. I only do fetchmail once in a week for archiving purposes.

The pine configuration is really simple...
Goto "Setup"->"Configuration"
Set 'inbox-path' to
'{mail.foo.com/ssl}INBOX'. Since my server requires a ssl connection todo IMAP.

If your server doesn't support ssl you can replace "ssl" with "notls". I also set the smtp-server to
mail.foo.com

Sunday, August 13, 2006

Making firefox java plug-in work on AMD64

It is frustrating not have the firefox java plugin for AMD64. So living with that handicap for almost a year...finaly I decided to put a end to it.

With little browsing I found the black-down java distribution supports the 64 bit java plugin. I downloaded the distribution from here.

After downloading I executed the installer

sh j2re-1.4.2-03-linux-amd64.bin

This creates a subdirectory "j2re1.4.2". Move this to /usr/java

sudo mv j2re1.4.2 /usr/java/

Now create a softlink to the java plugin from firefox plugins directory...

ln -s /usr/java/j2re1.4.2/plugin/amd64/mozilla/libjavaplugin_oji.so /usr/lib64/mozilla/plugins/

Restart firefox and type "about:plugins" to confirm proper installation.

Thursday, July 20, 2006

bc and awk

I had to calculate sum of a particular column from a huge data file. So I wrote a small bc script like this

----sum.bc-----
sum = 0
while(1)
{
c = read()
if ( c == q )
{
break
}
sum += c
}
sum
quit
----sum.bc-----

and invoked it like this

cat data.dat | awk -F '"' '{print $24}END{print "q"}' | bc -q -l sum.bc

This worked perfectly on my home system which is a linux. But when I did the same in Solaris which had a older bc that dude didn't understand my modern lingo. So I had to abandon the bc script.

So I thought I will just produce the entire sum string with numbers and "+" signs and pump it to bc, like this.

cat data.dat | awk -F '"' '{print $24}' | awk '{printf "%s+",$1}END{print "0"}' | bc -l

Again this worked with my small sample file but bc ran out of internal space when I fed a huge data file. Finally I had to abandon the specialized tool for calculation and fall back on my usual file processor awk to take over the job of the calculator.

cat data.dat | awk -F '"' '{print $24}' | awk '{s += $1}END{print s}'

Well..well ...I fed more than a Gig of data to this small wonder in that old dinky Solaris machine and it worked like a charm.

Tuesday, July 18, 2006

Sendmail and its aversion to upper case

I know lower case rules the Unix world. But at my home for some weird issue with samba shares I had to create a user with upper case "Bob". And I created my fetchmailrc with a very simple no nonsense configuration.

poll mail.X.org proto pop3
user bobnap is Bob here
options keep ssl

When I asked fetchmail to do its job, it did everything correctly and handed over the fetched mail to my local sendmail. Which puked on everything with the following message...

1 message for at mail.X.org (774 octets).
reading message bobnap@mail.X.org:1 of 1 (774 octets) fetchmail: SMTP error: 550 5.1.1 ... User unknown
fetchmail: mail from MAILER-DAEMON@localhost bounced to bobnap@X.org
fetchmail: can't even send to Bob!
not flushed

Intrigued by this I tried to mail myself. The mail ended dead in the "dead.letter".

$ mailx -s "Tot" Bob < /dev/null
Null message body; hope that's ok
$ /home/Bob/dead.letter... Saved message in /home/Bob/dead.letter

I checked and rechecked my sendmail configuration, its aliases etc. Everything seemed alright. Then I logged in as a another user "naper" in my system and tried mailx. Magically everything worked great. Then only I realized the fact that sendmail didn't like the upper case in "Bob" and to confirm that I just edited the passwd files to make it all lower case and sure enough...bob is getting his mails now!

What a strange ugly little devil!

Tuesday, June 27, 2006

SIGCHLD

While I was trying to write a Process Monitoring "Process" for my current employer ( well actually it is Process Monitoring Daemon ) I was breaking my head for almost 1 hour before figuring out what is really going on. I knew SIGCHLD is ignored by default. But I was under impression since I block the signal and wait on that signal specifically I should get the signal. Well it turns out that I won't. You won't either...! You need to specifically install a signal handler before sigwaiting on SIGCHLD. If you remove the sigaction from the below program the while(1) loop will never get to see the SIGCHLD when a child terminates.


#include
#include
#include

static void handle_signal(int signum)
{
printf("got signal %d", signum);
}


main()
{
sigset_t sig_set;
struct sigaction sa;
int signum;
int status;
int pid;
pthread_t tsig;


sa.sa_handler=handle_signal;
sa.sa_flags=0;
sigemptyset(&sa.sa_mask);
sigaction(SIGCHLD, &sa, NULL);

pthread_sigmask(SIG_BLOCK, &sig_set, NULL);

pid = fork();
if ( pid == 0 ) {
if (execve( "test.sh",
NULL,NULL ) < 0) {
perror("execve");
}
} else {
while (1) {
sigwait(&sig_set,&signum);
if ( signum == SIGCHLD ) {
int pid = wait(&status);
}
}
}
}

Wednesday, June 21, 2006

C# Documentation using Doxygen

C# has its own document generator which generates XML documentation from source code comments. But I'm a C++ guy for the most part
of my life and grew up with Doxygen. So I tried Doxygen on a small C# project.

Here is the configuration file I started with

csdoxy.conf
-----------
PROJECT_NAME = "GA C# Port"
OUTPUT_DIRECTORY = html
WARNINGS = YES
INPUT = mysuperprojectdir
FILE_PATTERNS = *.cs
PERL_PATH = /tp/bin/perl
SEARCHENGINE = NO

And I invoked doxygen just giving the above configuration file.

doxygen csdoxy.conf
The C# project had the M$ recommended way of source documentation. It was OK for the most part. But still the result was not what I
expected. Then I came across this C# input filter.
I downloaded it and saved in the same place where I had the configuration file and added these two lines to the configuration
file

INPUT_FILTER = "python doxyfilter.py"
FILTER_SOURCE_FILES = YES

and the world is a much better place now!