PDA

View Full Version : Detecting Package Management Tools



thomasaaron
October 10th, 2007, 05:36 PM
Hey, folks.

I need to write a program that will detect if any package management tools are running (apt-get, aptitude, synaptic, etc...).

I know I could look at running processes and grep out key words. But is there a more sophisticated way to do this?

If you try to run two package management tools at the same time, it throws this error...

E: Could not get lock /var/lib/dpkg/lock - open (11 Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

...but I'm having a little difficulty understanding how to take advantage of this built-in mechanism in my own program.

As always, thanks much for your insight.

Best,
Tom

thomasaaron
October 12th, 2007, 09:39 PM
*bump*

No ideas?

moma
October 13th, 2007, 01:50 PM
Can you check the Synaptic's source code. Get the source

$ apt-get source synaptic

$ cd synaptic*

Open the "gtk/gsynaptic.cc" file and search for function names check_and_aquire_lock() and TestLock() or just search for the dpkg word.
$ gedit gtk/gsynaptic.cc

Note: apt-get source needs "dpkg-dev" package. and the deb-src... (source code) repositories must be activated in /etc/apt/sources.list

thomasaaron
October 13th, 2007, 03:59 PM
Sweet. Thank you.

I'll do that. I'm pretty good with java and python. Never messed with C/C++. I will probably take you up on help analyzing the code.

Best,
Tom