Skip to content

Instantly share code, notes, and snippets.

@erickt
Created December 16, 2010 20:11
Show Gist options
  • Select an option

  • Save erickt/743934 to your computer and use it in GitHub Desktop.

Select an option

Save erickt/743934 to your computer and use it in GitHub Desktop.
function pid_file_handle_path:string(pid:long, fd:long) %{
struct task_struct *task = NULL;
struct pid *pid;
struct file *file;
struct path *path;
char buf[256];
char *p;
pid = find_get_pid((pid_t)(long)THIS->pid);
task = pid_task(pid, PIDTYPE_PID);
put_pid(pid);
if (task) {
task_lock(task);
/*
* We are not taking a ref to the file structure, so we must hold
* ->file_lock.
*/
spin_lock(&task->files->file_lock);
file = fcheck_files(task->files, (long)THIS->fd);
if (file) {
path = &file->f_path;
p = d_path(path, buf, sizeof(buf));
if (!IS_ERR(p)) {
memmove(THIS->__retvalue, p, strlen(p) + 1);
}
}
spin_unlock(&task->files->file_lock);
task_unlock(task);
}
%}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment