[][src]Function librelic::prelude::sys::exe

pub fn exe() -> Result<PathBuf, Error>

Returns the full filesystem path of the current running executable. Wraps std::env::current_exec

Platform-specific behavior

If the executable was invoked through a symbolic link, some platforms will return the path of the symbolic link and other platforms will return the path of the symbolic link’s target.

Errors

Acquiring the path of the current executable is a platform-specific operation that can fail for a good number of reasons. Some errors can include, but not be limited to, filesystem operations failing or general syscall failures.

On Linux systems, if this is compiled as foo:

$ rustc foo.rs
$ ./foo
Ok("/home/alex/foo")

And you make a hard link of the program:

$ ln foo bar

When you run it, you won’t get the path of the original executable, you’ll get the path of the hard link:

$ ./bar
Ok("/home/alex/bar")

This sort of behavior has been known to lead to privilege escalation when used incorrectly.

Examples

use fungus::prelude::*;

println!("current executable path: {:?}", sys::exe().unwrap());