LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-29-2010, 09:54 AM   #1
kauuttt
Member
 
Registered: Dec 2008
Location: Atlanta, GA, USA
Distribution: Ubuntu
Posts: 135

Rep: Reputation: 26
rpmlib C programming APIs


Hi Experts,

I am new user using RPM libraries and C programming APIs for my project. I am using rpmlib 5.1.6. but I am not getting any proper documentation on this. Whatever document I can get by googling are of the version 4 of RPMlib and most of them are out-dated. I mean the functions/APIs and headers file (like dbindex.h, header.h etc) mentioned over there are no longer existing!!

My action items will be mainly:
1) Fresh Install.
2) Upgrade.
3) Downgrade.
4) Uninstall.
5) Abort of any actions.
6) To get the action status of any ongoing actions.
7) To get all package information. Identify what are they..??
8) Signature of the packages.
9) Package dependencies.
10) Search package by attributes (like name, version)
11) Checksum of a package.
12) Pre/post-install handling.
13) RPM DB connections:
a) To list all the installed packages.
b) To list downgradable packages
c) To list non-downgradable packages
d) List of the packages in sub-tree
e) To get all package information.

I have checked rpm.org and rpm5.org documentations but no help from those…By googling, I have found some APIs (from rpmlib version 4) such as :
1) int rpmReadPackageInfo(int fd,
Header * signatures,
Header * hdr);
2) int rpmInstallPackage(char * rootdir,
rpmdb db,
int fd,
char * prefix,
int flags,
rpmNotifyFunction notify,
char * labelFormat,
char * netsharedPath);

but there are no longer supported in v5.1.6.

When I tried to compile a cpp file with the following command:
g++ -I/usr/include/rpm package-info.cpp -L/MM_BASE/host-tools/lib/rpm/ -L/usr/lib/rpm -lrpmbuild -lrpm -lrpmdb -lrpmio
/usr/bin/ld: cannot find -lrpmbuild
collect2: ld returned 1 exit status


Please help me out. Please let me know which APIs I should concentrate for the above tasks.

Thanks,
Kaushik
 
Old 12-29-2010, 10:47 AM   #2
lazlow
Senior Member
 
Registered: Jan 2006
Posts: 4,362

Rep: Reputation: 172Reputation: 172
Just making sure you know this before you get too far down the line. Most distros (certain RH based) are sticking with RPM4 rather than RPM5. Even in their most current releases(Fedora, RHEL, Centos, etc) are sticking with RPM4. There is a short description of what is going on here:

 
1 members found this post helpful.
Old 12-29-2010, 02:22 PM   #3
kauuttt
Member
 
Registered: Dec 2008
Location: Atlanta, GA, USA
Distribution: Ubuntu
Posts: 135

Original Poster
Rep: Reputation: 26
The target architecture that I will be using is compatible with RPM5...I am using Ubuntu 10.04 as my OS.
Pls help me out..
 
Old 12-29-2010, 03:20 PM   #4
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2016, Slack14.1 Deb Jessie, + 50+ other Linux OS, for test only.
Posts: 16,276

Rep: Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156
Quote:
/usr/bin/ld: cannot find -lrpmbuild
'/usr/lib/librpmbuild.so' is provided by the Ubuntu package librpm-dev.

But that is of course rpm-4.
If you want an rpm-5 build / development environment, you will have to
build that yourself from an rpm-5 source package.

Alternatively install Alt Linux or ArkLinux, they use rpm-5,
ref. the above link, @lazlow.

..
 
Old 12-30-2010, 02:09 AM   #5
kauuttt
Member
 
Registered: Dec 2008
Location: Atlanta, GA, USA
Distribution: Ubuntu
Posts: 135

Original Poster
Rep: Reputation: 26
I have checked the sites, i,e rpm.org and rpm5.org, but I have not got any useful documents. The documents mentioned in these sites are all old (dated back to 2003-04), and the functions, headers, libraries mentioned over there are no longer existing (in both RPM4 and RPM5) in the latest versions.

http://docs.fedoraproject.org/en-US/...ramming-c.html
http://rpm5.org/docs/max-rpm.html
http://rpm5.org/docs/rpm-guide.html#id3061479

All the above links (mentioned in rpm.org and rpm5.org) are not of any help. They are all outdated.

So if based on the experience or work done, can you please let me know which APIs I should concentrate for the below tasks (for either RPM4 and RPM5), it will really help me out. I am quite new on this.

1) Fresh Install.
2) Upgrade.
3) Downgrade.
4) Uninstall.
5) Abort of any actions.
6) To get the action status of any ongoing actions.
7) To get all package information. Identify what are they..??
8) Signature of the packages.
9) Package dependencies.
10) Search package by attributes (like name, version)
11) Checksum of a package.
12) Pre/post-install handling.
13) RPM DB connections:
a) To list all the installed packages.
b) To list downgradable packages
c) To list non-downgradable packages
d) List of the packages in sub-tree
e) To get all package information.

Thanks,
Kaushik
 
Old 12-30-2010, 02:27 AM   #6
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

I think you're looking at this from the wrong perspective:

1. Q: are you sure you even WANT to use rpmlib?
If your target is Ubuntu 10.04 (which uses aptitude and dpkg, vs. yum and rpm), that might not be the best choice.

2. Q: are you sure you want to write in C/C++?
Perhaps a script that runs existing command line tools (like apt-get or dpkg) might be a better choice.

3. Assuming you NEED to write a C/C++ program, and assuming you WANT to use rpmlib ... then are you sure your target will be RPM5? Perhaps RPM4 might be the better choice.

4. IF you choose rpmlib and C/C++, and REGARDLESS of whether you select the RPM4 or RPM5 version, then need to dig in and START CODING. You tried this above, and you got the "librpmbuild" link error. This should be easily resolved (as noted above, librpmbuild.so should be part of the package). Perhaps all you needed to do in order to get a clean link was set "-L" (library search path) switch.

Take one step at a time.

That's the best way to reach your destination
 
Old 12-30-2010, 06:49 AM   #7
kauuttt
Member
 
Registered: Dec 2008
Location: Atlanta, GA, USA
Distribution: Ubuntu
Posts: 135

Original Poster
Rep: Reputation: 26
Hi Paulsm4 -

Due to certain requirements I have to use rpmlib and C/C++. Though I have the RPM5 in my system, but if really required I can switch to RPM4.

I was looking at some links/documents for RPM 4.8.0 at:
http://rpm.org/api/4.8.0/modules.html

But due to lack of proper clarity in it, I'm not able to locate the necessary/required APIs. It's totally ambiguous. I have located the probable APIs for:
- Install
- Upgrade
- Un-install
- Downgrade
- Progress information
- DB open, create and close. But not the manipulation and fetching data from it!

In short, I need to map the APIs for the below mentioned tasks.
1) Fresh Install.
2) Upgrade.
3) Downgrade.
4) Uninstall.
5) Abort of any actions.
6) To get the action status of any ongoing actions.
7) To get all package information. Identify what are they..??
8) Signature of the packages.
9) Package dependencies.
10) Search package by attributes (like name, version)
11) Checksum/Size of a package.
12) Pre/post-install handling.
13) Progress information of any action.
14) RPM DB connections:
a) To list all the installed packages.
b) To list downgradable packages
c) To list non-downgradable packages
d) List of the packages in sub-tree
e) To get all package information.

So any form of help is really appreciated. I am in a soup.
 
Old 12-30-2010, 03:23 PM   #8
redhatstand
Member
 
Registered: Jul 2006
Location: Oxford, UK
Distribution: CentOS, Ubuntu
Posts: 37

Rep: Reputation: 7
@Paulsm4 - awesome response.

Hey kauuttt,

Even granted that you need the:

information you gather for your application AND the changes your application is asked to make MUST be via a C/C++ API, are you totally certain that every single bit of your application needs to be coded by you?

Unless you are inspecting a vast number of hosts, and assuming there are no security threats on the network, you could simply use the classic:

get stdin / stdout setup to be shared by parent and child
fork
exec (package manager command line we all know)
send command to stdin to be actioned by package manager
parse response from stdout

Does this sound feasible within your constraints?

Andy T

Last edited by redhatstand; 12-30-2010 at 03:28 PM. Reason: Correcting poor explanation
 
Old 01-03-2011, 07:20 AM   #9
kauuttt
Member
 
Registered: Dec 2008
Location: Atlanta, GA, USA
Distribution: Ubuntu
Posts: 135

Original Poster
Rep: Reputation: 26
@redhatstand
Can you provide the pseudo code of what you are explaining...so that I can understand the scenario better..
Infact I thought of calling scripts (containing rpm commands) from my C/C++ files...But looks like all these I can't do..

Because the target on which my application will be running...may not have the rpm tool binaries (maybe because of space constraints on the target)..but will have only the shared libraries..
So I think I may need to use the rpmlib APIS through my C/C++ files for serving my purpose...and there I am confused because of lack of proper documentation..and hence I need the help of you experts..

But still whatever the idea you are proving..pls provide a pseudo code so that I can understand it fully..

Thanks.

Last edited by kauuttt; 01-03-2011 at 08:10 AM.
 
Old 01-03-2011, 02:44 PM   #10
redhatstand
Member
 
Registered: Jul 2006
Location: Oxford, UK
Distribution: CentOS, Ubuntu
Posts: 37

Rep: Reputation: 7
Put together quickly so there could be errors - your homework ;-)

You'll probably want to create two versions of this file: one with the comments and one with them stripped out for code clarity

You'll need to check the command line options to ensure STDERR only gets written to by the chosen command on a real error since they don't want to pollute their output to STDOUT, verbose commands write informative data to STDERR you'll find that many binaries offer a -q option (or similar) to tell them to be as quiet as possible.

Also some commands (typically those which generate huge output files) don't default output on STDOUT. In these cases you would typically specify a single hyphen where the man page indicates you should supply a pathname.

Code:
int someFunction(int iInputFile, int iOutputFile, int iErrorFile) {
	pid_t pid;
	int iChildStatus;
	// always catch every error a command can return - see it's man page
	int iErrNo;
	int iSignalNumber;
	
	pid = fork();
	if (pid < (pid_t)0) {
		iErrNo = errno;
		// fork didn't work - look up the problem using 'man fork' 
		// and find the error code in errno.h in the includes dir
		// execution is still within parent, so code as for normal errors
		return iErrNo;
	}
	// fork did work, and it returns twice - in the parent process:
	// pid == new pid, in the new child process: pid == 0, we need to fork,
	// because we have to exec the binary, and this will totally overwrite
	// our new child's memory space. However, one thing which does not get 
	// overwritten is the open file handles including our parent process'
	// STDIN, STDOUT, STDERR
	if (pid == (pid_t)0) {
		// CHILD return
		// Child gets our open files, we map them to the child process' STDIN, STDOUT and STDERR
		// this means parent can still use them normally, but our custom file numbers act as STDIN/OUT/ERR
		// to the child
		dup2(iInputFile, STDIN_FILENO);
		dup2(iOutputFile, STDOUT_FILENO);
		// You can use iErrorFile to find out what the binary didn't like about the command line above
		dup2(iErrorFile, STDERR_FILENO);
		execl("/abspath2/binary", "/abspath2/binary", "--some-option", "--option-with-value", "value", (char*)NULL);
		iErrNo = errno;
		_exit(iErrNo);
		// will only return on fatal error - no permission to execute the binary, or path not found
		// tricky, as we are in child copy of original process - probably best to call _exit(iErrNo)
		// only exits the child, parent continues - to catch this you need to catch SIGCHLD in parent
		// see 'man sigaction'
	} else {
		// Parent - simplest case it to wait until child exits - then we can use iOutFile
		// the default use of waitpid will not return until child exits
		waitpid(pid, &iChildStatus, 0);
		// important to check how the child exited
		if (WIFEXITED(iChildStatus)) {
			iErrNo = WEXITSTATUS(iChildStatus); // 0 if no error
			if (iErrNo != 0) {
				// child returned non-zero - not good
				return iErrNo;
			}
		}
		if (WIFSIGNALED(iChildStatus)) {
			// even worse, child process exited by signal: maybe SIGSEGV, SIGABRT - check 'man 7 signal' for more details
			iSignalNumber = WTERMSIG(iChildStatus);
			// over to you, find a way of differentiating this from an iErrNo return - prob an extra int* arg to 'someFunction'
			return iSignalNumber;
		}
		if (0 != lseek(iErrorFile, 0, SEEK_END)) {
			// could be bad news, binary wrote somthing to STDERR - they often do this, but if you have
			// asked the binary to be a quiet as possible, you may want to check the output...
			// tho' you need to lseek(iErrFile, 0, SEEK_SET) first
		}
	}
	return 0;
}

Last edited by redhatstand; 01-03-2011 at 02:48 PM.
 
Old 01-03-2011, 03:03 PM   #11
redhatstand
Member
 
Registered: Jul 2006
Location: Oxford, UK
Distribution: CentOS, Ubuntu
Posts: 37

Rep: Reputation: 7
Oh yes, and another thing: if you are lucky enough to be coding for an open-source project you could just confirm that the license is compatible then use entire chunks of the existing command's source code in your open-source project.

Clearly don't do this is the project is closed-source as at some point your sponsors _will_ have to release the entire thing under the GPL or other similar. They may not be too happy with you...

A lot of command-line package managers are actually scripted-calling-compiled rather than pure compiled, so you might want to dig around to minimise the number of extra packages you have to install.

Finally, if the libraries you plan to link to are GPL and not LGPL you are going to _have_ to use the fork/exec approach: as I understand it: (I am not a lawyer etc.) to link to a GPL library makes your executable GPL too, whereas fork/exec avoids the 'substantial understanding of internal data structures' requirement - STDIN, STDOUT, STDERR not being library-specific.

If anyone from FSF or linux.org or GNU project can let me know that I'm wrong on this one, then I am totally borked...

Regards,

Andy T
 
Old 01-04-2011, 08:56 AM   #12
kauuttt
Member
 
Registered: Dec 2008
Location: Atlanta, GA, USA
Distribution: Ubuntu
Posts: 135

Original Poster
Rep: Reputation: 26
thanks redhandstand..now ur idea is clear to me. But as I said earlier I am not sure whether rpm tool will be there on the 'target' where my application will be running..

@all - So still my original question is open! I want to get/know the various rpmlib APIs which I can use for my C/C++ programming...any documents..??
For the documents or APIs list..I have searched a lot..infact in the official rpm4 and rpm5 sites...but no help!!

Please provide your kind help.
 
Old 01-04-2011, 06:55 PM   #13
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Certainly ... have a search for

rpm-apidocs



centos provides an rpm.
 
Old 01-06-2011, 07:27 AM   #14
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2016, Slack14.1 Deb Jessie, + 50+ other Linux OS, for test only.
Posts: 16,276

Rep: Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156
Quote:
.. documents or APIs list..I have searched a lot..sites.. .. .. but no help!!
Google .. librpm api
http://www.google.com/webhp?hl=all#s...4ee6e4e8056c32

The first hits ( 4 ) says : " rpm: librpm API Documentation. "

..
 
Old 01-07-2011, 12:41 AM   #15
kauuttt
Member
 
Registered: Dec 2008
Location: Atlanta, GA, USA
Distribution: Ubuntu
Posts: 135

Original Poster
Rep: Reputation: 26
Quote:
Originally Posted by knudfl View Post
Google .. librpm api
http://www.google.com/webhp?hl=all#s...4ee6e4e8056c32

The first hits ( 4 ) says : " rpm: librpm API Documentation. "

..
@knudfl, if you please read the entire thread you will notice, that I am looking for rpm5, the link what you have mentioned are about rpm4.8, and there is some major differences between them.

Anyway, still I had already looked into the urls what you mentioned a week back...and its getting quite difficult for me to fetch the required information from them (mightbe because I am very new to RPM). Presently in RPM4.8, I have got the API only for the below tasks:

- Install
- Upgrade
- Un-install
- Downgrade
- Progress information
- DB open, create and close. But not the manipulation and fetching data from it!

But, still I am able to find the APIs for the below mentioned tasks.

Abort of any actions.
To get the action status of any ongoing actions.
To get all package information. Identify what are they..??
Signature of the packages.
Package dependencies.
Search package by attributes (like name, version)
Checksum/Size of a package.
Pre/post-install handling.
Progress information of any action.
RPM DB connections:
a) To list all the installed packages.
b) To list downgradable packages
c) To list non-downgradable packages
d) List of the packages in sub-tree
e) To get all package information.

Your kind help will be highly appreciated!.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
rpmlib upgradation syedshabihhasan Linux - Software 3 10-05-2009 08:53 AM
rpmlib(PayloadIsLzma) vduvvuru Linux - General 2 08-29-2008 10:41 AM
where to get rpmlib ? mahesh_chavan Linux - Newbie 1 02-08-2008 01:23 PM
LXer: DSP Video Processing Without DSP Programming via Open Source APIs LXer Syndicated Linux News 0 11-07-2006 06:21 PM
rpmlib ras123 Linux - Newbie 1 05-13-2004 03:27 PM


All times are GMT -5. The time now is 11:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration