[][src]Struct dpdk_unix::daemonize::Daemonize

pub struct Daemonize {
    pub working_folder_path: PathBuf,
    pub pid_folder_path: PathBuf,
    pub user_name: CString,
}

An object that can be used with a configuration file (eg via Serde) to configure a daemon.

The following are done:-

  • umask is set to just the current user
  • Checks are made to check the program is not running with the set uid bit set ('setuid' or 'suid').
  • A PID file is created
  • standard in is redirected to /dev/null.
  • standard out and error are redirected to /dev/null.
  • fprintf and friends using the FILE API are redirected to syslog on Linux (this is probably also possible to implement for FreeBSD - see https://mischasan.wordpress.com/2011/05/25/redirecting-stderr-to-syslog/).
  • Double forking and a new session are created.
  • Real and effective user and group ids are changed.
  • Additional groups from /etc/group, if any, are assigned.
  • Environment variables are populated if missing (IFS, PATH)
  • User environment variables are overwritten (HOME, LOGNAME, USER).

Fields

working_folder_path: PathBuf

The folder path to use as the 'current working directory' (CWD).

Equivalent functionality to the shell command chdir.

Defaults to /.

pid_folder_path: PathBuf

A folder path in which to put a PID file.

This uses the processes' name for the actual file base name.

Defaults to /var/run.

user_name: CString

An user name that must exist in /etc/passwd (or the local equivalent).

Use to discover runtime user and groups to change to and the home folder of the running user.

Methods

impl Daemonize[src]

pub fn daemonize(self, dev_path: &DevPath) -> DaemonizeCleanUpOnExit[src]

Daemonizes the current process.

Returns an object that needs to have clean_up() called on it just before process exit.

Does the following:-

  • Verifies we are not running setuid.
  • Sets an initial sane umask (0000).
  • Switches user to self.user_name.
  • Sets up a PID file in self.pid_folder_path.
  • Changes the current working directory to self.working_folder_path.
  • Redirects standard in, standard out and standard error to /dev/null before (only on Linux) trying to redirect FILE stream handles to syslog.
  • Forks.
  • Creates a process group, and detaches from the session's controlling terminal.
  • Forks.
  • Populates the PID file.
  • Makes sure the IFS environment variable is sane (\t\n).
  • Makes sure the PATH environment variable is /usr/local/bin:/usr/bin.
  • Returns an object that needs to have clean_up() called on it just before process exit.

Trait Implementations

impl Eq for Daemonize[src]

impl Clone for Daemonize[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl PartialOrd<Daemonize> for Daemonize[src]

impl PartialEq<Daemonize> for Daemonize[src]

impl Default for Daemonize[src]

impl Ord for Daemonize[src]

fn max(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the minimum of two values. Read more

impl Hash for Daemonize[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl Debug for Daemonize[src]

impl Serialize for Daemonize[src]

impl<'de> Deserialize<'de> for Daemonize[src]

Auto Trait Implementations

impl Send for Daemonize

impl Sync for Daemonize

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]