This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Universal "substitution"/"renaming" of open(2)



This is a shameless plug of a technique I came across to _effectively_
"substitute" ("rename", "intercede") an open(2) libc function. This
technique does *not* use any dynamic loading or other LD_PRELOAD
tricks; it does *not* require any modifications to libc or any other
system files; it does *not* require any super-user privileges.

	Yet all the attempts to open files an application makes are
routed to my version of open(), which may call the regular open() in
some cases. In some other cases, of "extended" file names, my open()
can do, well, some other processing.
	
	I have tested this technique under GNU/Linux 2.0.27, gcc 2.7.2
(Slackware distribution). By this virtue, the trick would work with
GNU ld on any other platform. The technique also works on HP-UX
9000/770 B.10.10, using HP's native ld (HP-PA does not permit GNU ld).
	
	The extended file names are the ones that may have "pipes" in them,
like   "gunzip < /tmp/aa.gz |", " | gzip -best > file.gz ", or even 
	"   cat file-name |  tee transcript  |"

	This extension is implemented on the lowest possible level,
right before the request to open a file goes to the OS, through a
system call open(2). A function sys_open() (in a source file
sys_open.c) acts as a "patch": that is, if you call sys_open() instead
of open() to open a file, you get all the open() functionality plus
the extended file names.

	It has to be stressed that with this substitution in place,
*no matter* how one opens a file -- with open(), fopen(), fstream(),
with-input-from-file, etc -- he can submit the extended file names and
enjoy their functionality. You don't need Perl or Expect: the piped
file names may appear really *anywhere* where files are open.

	One can "extend" file names even further, by allowing
"http://" prefix, "||host:port" prefix or "host:port||" suffix (in the
latter case, the open() does listen() first).
	
	This all blends well with the idea "it's the OS that is the
browser" I've been running around recently.
	
	The extended file names and the open() substitution is a part
of a C++ "advanced" i/o and the arithmetic compression classlib. Its
Makefile contains some "black magic" that shows how to effectively
"substitute" the standard open(2) function with sys_open(), without
changing any of the system code. The Makefile runs a verification code
that tests that the substitution really works. The Makefile in the
distribution archive is set to work under HP-UX. To use it under
GNU/Linux, one needs to comment two lines and uncomment other two, as
explained in the Makefile itself.

References:
        http://pobox.com/~oleg/ftp/c++advio.README.txt
        http://pobox.com/~oleg/ftp/packages/c++advio.tar.gz
The latest version is 2.4.

"Announce: HTTP file system. Browser := OS; Midnight Commanding remote files"
	http://pobox.com/~oleg/ftp/HTTP-VFS.html
and also
	http://pobox.com/~oleg/ftp/Communications.html#http-vfs


	Thank you!
	
			Oleg


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]