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
).
The folder path to use as the 'current working directory' (CWD).
Equivalent functionality to the shell command chdir
.
Defaults to /
.
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
.
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.
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.
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
Returns the "default value" for a type. Read more
This method tests for self
and other
values to be equal, and is used by ==
. Read more
This method tests for !=
.
Performs copy-assignment from source
. Read more
This method returns an Ordering
between self
and other
. Read more
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
Formats the value using the given formatter. Read more
Feeds this value into the given [Hasher
]. Read more
Feeds a slice of this type into the given [Hasher
]. Read more
Serialize this value into the given Serde serializer. Read more
Deserialize this value from the given Serde deserializer. Read more
Creates owned data from borrowed data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static