LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to find the installed version of a rpm package in a system?? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-find-the-installed-version-of-a-rpm-package-in-a-system-903837/)

Arighna 09-19-2011 08:43 AM

How to find the installed version of a rpm package in a system??
 
Hi Experts,

I am a newbie in linux. For my project i need to find out the installed version of a rpm package from the rpmdb. This i need to do with C codes. Can anybody throw some light about this to help me out???

Simon Bridge 09-19-2011 08:47 AM

Looks like a good homework exercize - write a C program to check the installed version of an rpm package.
You understand how to find the version with the rpm command right?

There are actually several ways to do this in C. You can consider how the rpms are stored and where the version information lives, then you will realize how to access it ... or you can see how to execute another program from within C and just get it to run rpm.

Arighna 09-19-2011 09:15 AM

Quote:

Originally Posted by Simon Bridge (Post 4476051)
You understand how to find the version with the rpm command right?

Yes, i know i can check out by the command rpm -qa.

Quote:

Originally Posted by Simon Bridge (Post 4476051)
There are actually several ways to do this in C. You can consider how the rpms are stored and where the version information lives, then you will realize how to access it ... or you can see how to execute another program from within C and just get it to run rpm.

I don't have sufficient knowledge about handling rpmdb. Maybe if i can find out the list of all the installed packages, and then checking with the desired rpm name (say for e.g. libsecurity) if any installed rpm name matches with it, then that will be the desired output.Please confirm me.
If i am correct in my approach then can you plz tell me how to check from the rpmdb, the list of all the installed package?

knudfl 09-19-2011 09:50 AM

List installed packages : rpm -qa | sort > installed-packages.txt
.. Which will save an alphabetic list to the current directory.


rpm -qa --last > last-packages.txt :
Line 1 will show the package with the latest install time.

.

samtoddler 09-19-2011 10:57 AM

Hi,

You can get your problem solved by stdlib library

Code:

#include<stdlib.h>
system("command_name");
....

or you use the following statement in your c programs
Code:

exec("command > file_output.txt");
but this command can have impact on your program.

samtoddler

TobiSGD 09-19-2011 11:05 AM

You should have a look at the rpmlib library, it contains all functions you need. Should be a much better way than to launch external programs.

Simon Bridge 09-20-2011 11:44 AM

Using the rpm lib should give a more elegant solution, and you can always get hints by examining the source code for the rpm utility. You do know you can get the source right? However, the exact solution you choose should be appropriate to your course ... maybe your teacher wants to see if you can figure out how to execute an external program from within your own? You havn't confirmed this is homework but notice that everyone is replying on that assumption. Without the context, it is hard to pick the proper method for you.

John VV 09-20-2011 03:46 PM

--- edited ---

Arighna 09-21-2011 03:31 AM

Hello all,

This is not a school homework. :P Due to some restrictions i can not use rpm binaries in my codes, rather i have to use the rpmlib version 5.6 APIs. So i wud be grateful to you if u can mention here, what are the APIs i can use to find the list of all installed package, which are stored in rpmdb...

John VV 09-21-2011 04:23 AM

Quote:

For my project i need to find out the installed version of a rpm package from the rpmdb
normally this is done calling rpm to do a database search and list the output
Code:

su -
rpm -qa > ~/RpmList 
or
rpm -qa | sort > ~/RpmList

Quote:

This i need to do with C codes.
then write c wrapper to echo the db search

Simon Bridge 09-21-2011 09:22 AM

You have already been given a link to the rpmlib functions and specification - that is all the api anyone usually needs. What? You want us to write the actual code for you? We have already provided example code. Perhaps I should send you a schedule of my fees?

I don't understand what restrictions, other than homework, would prevent you from calling the rpm binary from within a C wrapper. As observed, this would be the usual way and it is one of the things it is designed for. Without the specifics of what you are doing, nobody can produce code any better suited to you than the examples already given to you.

(Note: linux does not, iirc, have a formal api - it does not need one: you have the entire source code.)


All times are GMT -5. The time now is 05:58 AM.