Re: Get the full path of the current process?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

> I want to get the full path of the current process (using current

Does this work?

/*
 * Get realpath() of current process.
 * This function uses kmalloc(), so caller must kfree() if this function didn't return NULL.
 */
const char *GetEXE(void)
{
	if (current->mm) {
		struct vm_area_struct *vma = current->mm->mmap;
		while (vma) {
			if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file) {
				char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
				char *p;
				if (buf == NULL) return NULL;
				memset(buf, 0, PAGE_SIZE);
				p = d_path(vma->vm_file->f_dentry, vma->vm_file->f_vfsmnt, buf, PAGE_SIZE);
				if (!IS_ERR(p)) {
					memmove(buf, p, strlen(p) + 1);
					return (const char *) buf;
				}
				kfree(buf); return NULL;
			}
			vma = vma->vm_next;
		}
	}
	return NULL;
}

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux