[−][src]Struct dpdk_unix::daemonize::Daemonize
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 theFILE
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(&self) -> 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]
fn partial_cmp(&self, other: &Daemonize) -> Option<Ordering>
[src]
fn lt(&self, other: &Daemonize) -> bool
[src]
fn le(&self, other: &Daemonize) -> bool
[src]
fn gt(&self, other: &Daemonize) -> bool
[src]
fn ge(&self, other: &Daemonize) -> bool
[src]
impl PartialEq<Daemonize> for Daemonize
[src]
impl Default for Daemonize
[src]
impl Ord for Daemonize
[src]
fn cmp(&self, other: &Daemonize) -> Ordering
[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<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl Debug for Daemonize
[src]
impl Serialize for Daemonize
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl<'de> Deserialize<'de> for Daemonize
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,