Issue
I am working on a project in which I need to know the current working directory of the executable which called the system call. I think it would be possible as some system calls like open
would make use of that information.
Could you please tell how I can get the current working directory path in a string?
Solution
You can look at how the getcwd
syscall is implemented to see how to do that.
That syscall is in fs/dcache.c
and calls:
get_fs_root_and_pwd(current->fs, &root, &pwd);
root
and pwd
are struct path
variables,
That function is defined as an inline function in include/linux/fs_struct.h
, which also contains:
static inline void get_fs_pwd(struct fs_struct *fs, struct path *pwd)
and that seems to be what you are after.
Answered By - Mat Answer Checked By - Marilyn (WPSolving Volunteer)