From: Michael Welles <mike@bangstate.com>
To: linux-kernel@vger.kernel.org
Subject: Using get_cwd inside a module.
Date: Fri, 21 Nov 2003 19:05:15 -0500 [thread overview]
Message-ID: <3FBEA83B.1060001@bangstate.com> (raw)
Apologies in advance for a lengthy and probably stupid question.
I'm one of the authors of changedfiles (http://changedfiles.org), a
GPL'd application that monitors file operations and allows user
configurable actions to take place in userspace when any defined rules
are matched. Currently we work w/ 2.2.x and 2.4.x kernel series, but
this question mostly concerns 2.4.x.
When doing the initial development of the kernel module component of the
system, I needed getcwd() in kernel space. Being lazy, and frankly
terrified to be working in kernel space, I ended up cutting and pasting
getcwd() from dcache.c and using the locally defined version in the module.
This worked great for a couple of years, but recently when my debian
testing box starting using gcc 3.3 (I think this is the cause -- it's
just about the only thing that changed), I started getting NULL pointer
drefs inside the copied code.
I figured it was high time I stoppied using cut n' paste code. Instead
I thought I'd use sys_call_table[__NR_getcwd] instead -- since I could
run pwd in a shell without any kernel panics, I figured it must be
working OK.
My powers of grep were sorely lacking, though, and I couldn't find
anywhere in the source where the function was assigned. In a bit of
desperation, I guessed that somewhere, somehow, the getcwd() in dcache
was being assigned, so I used that function prototype:
int (*getcwd)(char *buf, unsigned long size);
getcwd = (int (*)(char * , unsigned long
))(sys_call_table[__NR_getcwd]);
and use it as I used to:
len = getcwd(fullnewname, MAX_PATH);
Everything built just fine, but whenever I load the module and the above
statement runs, the function returns -14. This is true on my debian
testing box, and also on my YDL 3.0 machine, where the old version (with
the cut n' paste code) still runs just fine.
I'm not sure what to try next. What am I doing wrong?
Thanks,
Michael Welles
next reply other threads:[~2003-11-22 0:05 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-11-22 0:05 Michael Welles [this message]
2003-11-22 0:32 ` Using get_cwd inside a module Maciej Zenczykowski
2003-11-22 12:30 ` Szymon Acedański
2003-11-22 8:30 ` Christoph Hellwig
2003-11-22 9:33 ` Juergen Hasch
2003-11-22 10:15 ` Christoph Hellwig
2003-11-22 10:45 ` Juergen Hasch
2003-11-22 11:04 ` Christoph Hellwig
2003-11-22 17:22 ` Michael Welles
2003-11-23 19:40 ` Juergen Hasch
2003-11-22 11:48 ` Andreas Dilger
2003-11-23 19:41 ` Juergen Hasch
2003-11-22 17:15 ` Michael Welles
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3FBEA83B.1060001@bangstate.com \
--to=mike@bangstate.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.