name of current dir in kernel

Honzo Svasek honzo at 4gl.UUCP
Thu Nov 24 09:24:51 AEST 1988


On a system V release 2 system I want to 'catch' all open and close
calls. I have no source, so I patched the symbol table of the link kit
library and make _open into Xopen.

With the following piece of code I am able to diplay the file that
has been opened. (read on after the code)


#include <sys/param.h>
#include <sys/types.h>
#include <sys/dir.h>
#include <sys/signal.h>
#include <sys/user.h>
#include <sys/reg.h>
#include <sys/sysarg.h>


extern struct user u;

/* The assembler code is 80286 assembler.
***************************************/

asm("	.text");
asm("	.globl	_open");
asm("_open:");
/* save u.u_dirp on the stack
****************************/
asm("	push _u+336");
asm("	push _u+334");
asm("	push ax");
asm("	call Xopen");
asm("	call _Owedge");
asm("   pop  ax");
asm("   pop  ax");
asm("   pop  ax");
asm("   ret");

Owedge(dirp)
uaddr_t dirp;
{
	static char name[65];
	char *cp = name;
	int c;

	/* if some error occured, no sense in going on
	*********************************************/
	if (u.u_error)
		return;

	/* copy the filename from user space
	***********************************/
	while ((c = fubyte(dirp++)) > 0) {
		*cp++ = (char) c;
	}
	*cp = '\0';

	printf("%d %s %s\n", u.u_uid, u.u_comm, name);
}

This works quite well and is interesting to look at! However if the open call
did not use the full path name, i still do not know which file we are
talking about.

What i am looking for is an EASY and FAST way to get the name of the
current directory of the program that is running. i spent the whole day
with M.J. Bach, a very faded copy of the Lions book and my /usr/include/sys/*
files, but have not seen the light yet.

As getcwd uses popen, i fear there might not be a simple solution.

Maybe one of you wizards can do some magic, and show me the light?


I_I(           _  
I I ) honzo svasek  <honzo at 4gl.nl>
---------------------------------------------------
Svasek Software Consultants
IJsselkade 24, 3401 RC IJsselstein, the Netherlands
---------------------------------------------------

PS for the curious: I want to be able to process some files when they are
opened, before the are given to the user program. These file contain data
from a database on another machine, and have to be updated just before
they are used on this machine.



More information about the Comp.unix.wizards mailing list