BlogJamun – Thinks Aloud

thinking feverishly for a tagline..

Code Runner – a Dbus service to execute code

Code Runner is an idea that spawned off from another open-source project codechecker that I am part of. In the codechecker project, we have a command line utility called setuid_helper, that runs a user’s submission program in a restricted environment. The program is restricted accesses to resources like CPU time, memory, number of files it can open, number of bytes it can write onto the filesystem etc. On top of this the program can be run as a unprivileged user. The setuid_helper utility also provides that option of running the user’s program in a chroot’ed environment. If you think about it, all malicious submissions can be ‘safely handled’ using the setuid_helper program. The Code Runner project provides a Dbus service that wraps the functionality of the setuid_helper. The advantages of the Dbus service is that, almost all high level programming languages have Dbus bindings and this service becomes immediately accessible to all those developers. It also abstracts away the details of setuid_helper. Currently, the Code Runner project is available here. The gitorious repo has a README that helps in getting started. Depending on the no. of consumers for the Dbus service, I would spend time on writing an installer for the same. If you find this idea cool, feel free to drop a comment 🙂

Advertisements

September 6, 2010 Posted by | open source | , , | Leave a comment

Inversions problem – haskell way

Given an array of numbers A, we need to find the number of distinct pairs such that,
i < j,  A[i] > A[j]
The naive algorithm would be to make ‘n’ choose 2 comparisons and determine the number of inversions in them. This has a worst case complexity of O(n^2).
We can do better than that by modifying merge sort algorithm, which has a worst case complexity of O(nlogn). That takes care of introduction to the problem and the solution.
I learned haskell but never really used it. It was fading away like high school math did. This problem provided the opportunity to dust some manuals and read some bookmarked sites on programming in haskell. The fun I get out of writing small programs in haskell is that, it allows me to think of a problem without knowing how a computer works. All imperative programming languages need you to understand that you manipulate system’s memory to get the desired result.
The following is an implementation of the solution in haskell:
‘imerge’ takes two sorted lists and returns a tuple containing number of inversions present in the merged list and the merged list.

‘imsort’ takes a list and it’s length and returns a tuple containing number of inversions present in the initial list and the sorted list.

imerge :: (Ord a) => [a] -> [a] -> (Int, [a])
imerge [] bs = (0, bs)
imerge as [] = (0, as)
imerge (a:as) (b:bs)
	| a == b = (fst (imerge as bs), a:b:snd (imerge as bs))
	| a < b = (fst (imerge as (b:bs)), a:snd (imerge as (b:bs)))
	| otherwise = (length (a:as) + (fst (imerge (a:as) bs)), b:snd (imerge (a:as) bs))

imsort :: (Ord a) => [a] -> Int -> (Int, [a])
imsort [a] 1 = (0, [a])
imsort a n = ((fst algo) + (fst (imsort (drop r a) (n-r))) + (fst (imsort (take r a) r)), snd algo )
	where r = n `div` 2
              algo = imerge (snd (imsort (take r a) r)) (snd (imsort (drop r a) (n-r)))

sort :: (Ord a) => [a] -> [a]
sort a = snd (imsort a (length a))

inversions :: (Ord a) => [a] -> Int
inversions a = fst (imsort a (length a))

I hope to see some haskell experts come by and comment on the code.

September 6, 2010 Posted by | haskell | , | 3 Comments

Quality Check on literature – A Software based approach

A quick python hack on to prove a point. To ‘just’ show how low people can stoop in the name of literature. Copy paste any boring text onto a file. Now run the following python script on the file.

import sys
import pprint

if len(sys.argv) < 2:
exit(1)

fd = file(sys.argv[1], ‘r’)

pp = pprint.PrettyPrinter()
lines = fd.readlines()
count = {}
for line in lines:
words = line.split(” “)
for word in words:
if not count.has_key(word):
count[word] = 1
else:
count[word] = count[word] + 1
pp.pprint(count)

The script returns a dictionary of words and word count. This python script is limited in its prowess, It can’t catch ’em all. But don’t lose heart. Open source saves the day, and i give it with CYL (choose your license) license.

December 8, 2009 Posted by | Uncategorized | , , | 1 Comment

Sneak Preview – My Talk @ OSDevCon

The following are things that I am currently working on for the Opensolaris Developer Conference this year, to be held during Oct 28-30 at Dresden. I will update the documentation part of it later when I get time to breathe 🙂

krish@trantor:~# dtrace -n ‘glib_prov785:::gslice-alloc { @[execname] = quantize(arg0); }’
dtrace: description ‘glib_prov785:::gslice-alloc ‘ matched 1 probe
^C

nautilus
value  ————- Distribution ————- count
2 |                                         0
4 |                                         10
8 |@@@@@@@@@@@@@@@@@@@@@@@                  69999
16 |@@@@@@@@@@@@                             37287
32 |@@@@                                     11007
64 |@                                        2793
128 |                                         540
256 |                                         666
512 |                                         0
1024 |                                         12
2048 |                                         0

krish@trantor:~# pgrep gnome-panel
784
krish@trantor:~# dtrace -n ‘glib_prov784:::gslice-alloc { @[execname] = quantize(arg0); }’
dtrace: description ‘glib_prov784:::gslice-alloc ‘ matched 1 probe
^C

gnome-panel
value  ————- Distribution ————- count
4 |                                         0
8 |@@@@@@@@@@@@@@@@@@@                      1743
16 |@@@@@@@@@@@@                             1091
32 |@@@@@@                                   603
64 |@@@                                      280
128 |                                         21
256 |                                         0

krish@trantor:~# dtrace -l | grep glib
65027 glib_prov785 libglib-2.0.so.0.2105.0                            g_free g-free
65028 glib_prov785 libglib-2.0.so.0.2105.0                          g_malloc g-malloc
65029 glib_prov785 libglib-2.0.so.0.2105.0                     g_slice_alloc gslice-alloc
65030 glib_prov785 libglib-2.0.so.0.2105.0                     g_slice_free1 gslice-free
65109 glib_prov784 libglib-2.0.so.0.2105.0                            g_free g-free
65110 glib_prov784 libglib-2.0.so.0.2105.0                          g_malloc g-malloc
65111 glib_prov784 libglib-2.0.so.0.2105.0                     g_slice_alloc gslice-alloc
65112 glib_prov784 libglib-2.0.so.0.2105.0                     g_slice_free1 gslice-free

krish@trantor:~# dtrace -n ‘gio_prov785::: {  }’
dtrace: description ‘gio_prov785::: ‘ matched 1 probe
CPU     ID                    FUNCTION:NAME
0  65026 g_file_get_uri_scheme:gio-get-uri
0  65026 g_file_get_uri_scheme:gio-get-uri
0  65026 g_file_get_uri_scheme:gio-get-uri
1  65026 g_file_get_uri_scheme:gio-get-uri
1  65026 g_file_get_uri_scheme:gio-get-uri
^C
0  65026 g_file_get_uri_scheme:gio-get-uri
0  65026 g_file_get_uri_scheme:gio-get-uri

September 16, 2009 Posted by | dtrace, open source | , , , | 1 Comment

Bowled By BSNL.

I could not take it anymore. This is the limit. I had not particularly planned a speech, but I was sure about the decibel levels I was going to target. I mentally did a pulling-the-cuffs-of-a-full-arm-shirt thing to get a feel for the situation. All set to attack, I cleared my throat to seek attention of the BSNL employee. I was pretty impressed with my beginning. Lke Sehwag, like Hayden and the guy who said, “Well begun is half done”, I too believed in the adage. The lady, after getting the gist of my problem, started to look busy. Not sure if she was trying to solve my problem. Suddenly, like in a discontinuous cartoon strip, a very responsible, tax paying citizen of my beloved land appeared. I was appalled, and quite understandably so. He was almost like a Twitterfox popup when you are chatting with a girl who is remotely interested in your conversation. I think this is what is called the sore thumb in the medical jargon. He broke the queue and made me feel invisible and went onto question the lady behind the glass. I was now puzzled by the turn of events and managed to make a croak when I was given a chance to tell why I was there. Quickly I recovered, just like all my people have known me would have guessed. Went on to explain the situation, not in the elegant and concise way the people around me then, would have preferred. Now, the lady looked like a Russian GM in chess, very thoughtfully collecting in her head, all what I had verbosely put across, and replied almost instantly saying “The Server was down all these days, your issue will be sorted out soon.”. I don’t think I was quite ready for any reply at the point of time. I was always in a opinion that, BSNL chaps are going to apologise for the delay. But wait, what has the server got to do with installation of my broadband connection? I was stumped by the reply and yet to recover…

May 16, 2009 Posted by | Uncategorized | , | 1 Comment

Jhbuild Issue in Intrepid Ibex

Update: The error in jhbuild discussed below is a consequence of me trying to merge the jhbuild checkout folder and the gnome components’ checkout folder. It may not apply for those building with default directory structures as prescribed in the jhbuild gnome live wiki.

I recently downloaded the jhbuild sources from the git repository. I was able to compile and install it without many hiccups, thanks to the elaborate distro-specific Jhbuild Issues wiki in gnome.org.
To my shock, ‘jhbuild’ command returned the following error,

Traceback (most recent call last):
File “/home/pk/bin/jhbuild”, line 5, in
import jhbuild.main
ImportError: No module named jhbuild.main

I am not sure if this is consistently reproducible by others. But the solution here is pretty straight forward. Open the ~/bin/jhbuild file. Don’t pay heed to your graphical editors conservative warnings. It is just a python script. Check if the second argument of the sys.path.insert points to the directory which contains the jhbuild sources. Change it suitably and the problem is fixed. In my case the second argument was pointing to “~/svn/gnome2/jhbuild”. I had to modify it to “~/checkout/gnome2”.
Happy building 😉

May 2, 2009 Posted by | Uncategorized | , , , | 3 Comments

Dtrace for timepass

I was trying to copy large amount of files from removable media onto my hard disk. It was taking forever to finish copying. I was curious whether both the processor cores were used equally. I ran the following dtrace one-liner to verify,

pk@opensolaris:~/progs$ pfexec dtrace -n ‘syscall::write:entry /execname == “cp”/ {trace(fds[arg0].fi_pathname); @writes[execname, cpu] = count()}’

<snip>

^C

cp                                                        1             3324
cp                                                        0             3385

</snip>

I must also warn those who are itching to interpret the above result, I ran dtrace after a considerable elapse of time after starting the copy command. I am planning to come up with more such dtrace one-liners. They are really addictive 😉

March 8, 2009 Posted by | dtrace | , , | 1 Comment

I am free to do anything, but….

I have been hitting contradictions to my subconscious belief that I am free to do anything I want. I have managed to convince myself with this belief, right from days at college. Thats were all the philosophical enquiries  about life and self begin. I convinced myself with the ‘I am free’ belief by doing stuff which people around me dint do, because they were asked not to. This gave me a sort of illusion I should say, that I am unrestrained in my actions. All this are at the surface. To add to this, there have been some day-to-day encounters that have found themselves highlighted in my mind. These highlighted moments bring new perceptions to what I used to believe freedom was. To quote some, One evening, when I was returning from my office, I was caught amidst a religious procession. I managed to evade it, but my luck disappears there. I find that the religious procession got the better of me. They stole power from our area to light up the Almighty! At this point I decided to go to a nearby mall to hang around, satiate my visual desires and return once I got tired. I had forgotten my plan and went to a bookstore in the mall. Very unlike me. Moment of truth, if I ever filmed my life. I went to the philosophy section. I must say that was to be expected. It was almost like a depiction of my inner mind. I think about philosophy, whenever I am lost, without a clue of what I should do next. At that very moment, when I was aimless, if you can say that, went to the philosophy section of all the places. Without any clue on famous titles or authors of works of philosophy, I picked a book on Freedom by Osho. After reading the digest at the back of the book, I could not help letting out a low chuckle in agreement to the author’s ideas. From the digest I infer that Osho believes that Freedom is three types. One is Freedom from, other being Freedom for and the third being Ultimate Freedom. Freedom from is to free yourself from all conditionings we have been through. Freedom for is freedom to express yourself as is. And ultimate freedom or just freedom is an unexplainable state of bliss. That is the best I can do about Osho. Nevertheless, this snippet on Freedom is etched in my mind.

This apart, I bumped into this movie called Vicky Christina Barcelona. The whole movie is about two friends of contrasting personalities. Christina, is (best)described as a person who does not know what she wants, but only knows what she does’nt want. However queer or irrational it may sound, it is possible watch the movie. For a better understanding, watch yourself! The other character, Vicky is  a totally practical person. In reality, she is as romantic as her friend Christina, but only she lacks the courage to be herself. I think to read ahead, watching the movie becomes a must. Anyway, the two characters are portrayed in a compelling manner that you would want to associate yourself to one of them. I personally believe, we are both Vicky and Christina. Most of us are not sure what we want. We may come up with a long list of excuses for not trying to figure it out. We kind of know what we don’t want. Mind you mathematicians, the English is tricking you. The statements before may give an impression we are talking about some mutually exclusive and exhaustive stuff, Sorry this is not a place for you. Coming back, the Vicky in us is also very obviously seen. Most of us, lack the courage to do what we want to do, we fear courage, opinions that may float around if  we did, people we know etc. This movie kept reminding me how freedom is only felt when exercised and not when talked about. It is ironical that we don’t utilise or experience the freedom of choice that we know we have. It reminds me of our constitutional freedom. It is well-documented, seldom practised in true spirit.

All this and some more subtle encounters have only left me thinking, am I willing to be free…

February 3, 2009 Posted by | Uncategorized | 10 Comments

Thiruvannamalai – A Perarasu film

To do some justice to this blog, I have to give some historical background. Boring as the following paragraph may seem,  that was how things were in my life.

From the time I became a software engineer,  I have been facing this serious social behaviour related disorder. I am yet to coin a name for this. I am not even sure if this is unique to me. In short, I have nothing to do in weekends and to vent this out on somebody, I ping every “green” soul on gmail chat and bore him/her to death. That is only till the disorder has controllable effects on me. Once it goes beyond me, I go to the level of catching some hidden “invisible” people on the chat. I sometimes can  even hear them telling to themselves “What the heck, how the <you-know-what> caught me man!? When I was almost sucked into this disorder, I drew all my mental strength and came up with the idea of going to a movie. I was so hell-bent on getting over this disease, this cursed disorder, I chose to watch Thiruvannamalai.

Thiruvannamalai, is not any other Tamil movie. It is an action thriller with guaranteed quantities of sister and mother sentiment. Yes, it is full of punch dialogues and comedy with great scope for improvement. Ok, no points for this sitter, Perarasu has delivered yet another stomach upsetting block-buster with actors who are eye-sores. The story still has its own elements of unpredictability. Perarasu, has once again proved a point. Gautham, you can’t make original movies like Perarasu! Originality has always been Perarasu’s unique point. He goes to extreme lengths that even Srikanth Deva has scored ORIGINAL music. Please you must give this to the music composer. I don’t think anyone in his right minds will claim ownership for the tracks (read as drags).

Ok, Ok. I know there is no point in me rambling about this without telling the story. Here goes the story, with screen details only where you may not be able to picture the torture I went through.

Action King Arjun, as he is belovedly known by his fans, is a well-built village boy (of age 20- anybody’s guess). His name is Eshwar, the main deity in Thiruvannamalai temple. He is a social activist who runs a non-profit cable TV channel. He can’t have no enemies. The MLA for the area in which Eshwar is, (not- at-all) surprisingly is corrupt to say the least and an untried convict to sum it all. Eshwar, cannot stand corruption. Kudos, to upbringing! He screens some videos he shoots of the MLA’s usual loud-mouthing of his own criminal record in public. Taken aback by such a screening just before the elections, the MLA sends a parade of Tata SUMOs. Rumour has it that Ratan Tata has promised to present Perarasu a golden Tata SUMO model in acknowledgement to his extensive use of SUMO’s in his movie. Of course Tata has refused to comment on this. Coming back to the parade of SUMO’s, imagine how many goondas can be packed into it. Eshwar just goes DAMAAL, DOMEEL, DISHUM on all the goondas. The powerful hits of Eshwar are undoubted, but the last remaining goonda could not stop pissing in his pants. Now that is a temporary renal failure for you. NO surprises there, Eshwar comes out unhurt. Meanwhile his mom is terribly upset. She is deeply worried that her son may get hurt and decides to flee to her brother’s house in Banglore. Now gimme a break! Does she get to see the script, or atleast does she know she is the hero’s mom! This is just one thread of the plot.

Eshwar who has this compulsive disorder of getting into troubles, which without fail results in a lot of SUMO’s, unbearable noise, and flying men and objects. Yes, he gets involved in marrying two lovers. COINCIDENTALLY, the girl who gets married is the daughter of a convicted murderer, more commonly known as Area DADA. Now, he gives all blood shot glares to Eshwar and threatens that he would kill him for sure.

Eshwar’s mom has had enough. She decides to take him to a Swamiji’s ashram in Thiruvannamalai. TITLE JUSTIFIED. Audience whistle to glory! Now, think of the most arbit thing that can happen in the next shot of the movie. You would not have guessed it! Now don’t give me I already knew that shit! The Swamiji is none other than Arjun himself. THats it! I quit continuing with the story! I have conscience..  Don’t watch this in theatre, and please don’t ever do this at home! I am against watching movies in CD,

a) It is waste of a CD. CD is made out of some kind of plastic. Plastic is a non-bio-degradable material. You are doing to the environment what Perarasu is doing to us!!

b) Come on man, wasn’t a) enough for you.

Now I feel really happy about this blog. Though I don’t believe in self-praise, I must say this. This blog will affect every readers’ life in one way or the other. Some have themselves to blame if they watch Thiruvannamalai despite my blog. The others, I am sure are going to keep praising me for such an early warning and the sacrifice I have done. With a heavy heart and upset stomach I leave you here!

December 22, 2008 Posted by | Humour, Kollywood, movie | , , | 18 Comments

My maiden foss.in

foss.in is a annual (un)conference where people who believe in free and open source philosophy and mostly write code for a living, gather.
The event has a broad agenda to ensure that some tangible contributions is made. This time the organisers went a step ahead and gave the message more code less talk to put it more subtley.

I was manning the SUN microsystems stall and gave demonstrations on Virtual Box, the latest realease of OpenSolaris, ZFS and Dtrace. Virtualization being the buzz word in recent days, people wanted to see what Virtual Box could do. Most of them were excited to see that multiboot is going to become less painful with desktop virtualization products.

OpenSolaris with its new and shining look did catch some attention. The glassy nimbus theme and compiz just mesmerised people who were looking at it. It even caught a KDE fan gaping at it! To experience this and other cool features of OpenSolaris, see here.

Though ZFS and Dtrace are no longer the new kids on the block, they still fascinate, surprise, bother, disturb the software fraternity like they have always done.
It is never easy to convince people that Dtrace is different from other tracing utilities that are around and that it has zero probe effect. Its even harder to convince those who think it is a marketing gimmick. But all this only meant that people simply could not take the fact that Dtrace can get any data you may need as a part of tracing and with no effect. In my opinion, Dtrace is only as powerful as the user!

ZFS has had a make-over only to become more noticable. Some times great things are taken for granted. With the new time slider integrated with nautilus, zfs snapshots have reached ‘Aam Aadmi’. The time slider is a graphical front end to the already existing snapshot feature. It gives a straight forward intuitive interface. Command line enthusiasts may be upset about this, but what is the fun if people can’t use it or for that matter notice it. I personally feel that intuitive GUI saves tons of documentation and man pages. Time slider has options where you can set the period of backing up, for eg. hourly, daily, weekly, monthly and so on. You can also choose what filesystems you want to backup. These are implemented as SMF services. We had a screencast of time slider demo created by Hemantha, my colleague and partner in crime in almost everything. This demo was done using recordmysolaris. This was a port of the recordmylinux. The highlight of the screencast is that it was in ogv format. Lame as it may sound, not many times do we see a video or audio in the open format. This in turn keeps us locked with some of the private formats.

On the 3rd day we had a work-out/hackathon on adding Dtrace probe to GNOME proposed by Partha. The motivation to this being that GNOME has had no foolproof way of measuring its performance. The problem with existing tools that are available is they have a probe effect. This affects the results obtained in a unquantifiable way, that on most occasions no new information is elicited. Now for all Dtrace users and followers, it is quite apparent that why search/design tools when Dtrace exactly fits the bill. Yes, that is exactly what we thought too. Along with people from GNOME community and some people with experience in Dtrace, we began the proceedings. In three hours of the workout, we chose some probe sites that can prove handy. We added one probe on that session. Now that we have found some interesting probe sites and some people interested in this project, we plan to take off from here and continue the good work. I cant wait for the release of GNOME 2.2x with Dtrace probes. KDE cannot lack this feature thought some of the KDE users/enthusiasts. There was a workout on the subsequent day for adding probes into KDE. I am not sure what the progress is, since I was not present on that day. But workouts were meant to be starting point to some great projects. In fact the 3-hour restriction was only for the hall that was alloted. People could continue the workout anywhere they please during foss. This is only a microscopic view of what hapened at this version foss.in. There were so many cool things going around like KDE4 on Solaris, Porting Linux onto embedded devices and so on and so on.
All in all, this was not just another foss!

December 1, 2008 Posted by | dtrace, open source | , , , , , | 2 Comments