Path: utzoo!attcan!uunet!mcvax!hp4nl!4gl!honzo From: honzo@4gl.UUCP (Honzo Svasek) Newsgroups: comp.unix.wizards Subject: name of current dir in kernel Keywords: kernel device driver Message-ID: <558@4gl.UUCP> Date: 23 Nov 88 23:24:51 GMT Organization: 4GL Consultants b.v., the Netherlands Lines: 84 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 #include #include #include #include #include #include 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 --------------------------------------------------- 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.