mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-22 09:57:41 +00:00
Create the pid file parent directory if it doesn't already exist.
Also package the run directory in the sudo_logsrvd PolyPkg file.
This commit is contained in:
parent
dfd5a88772
commit
e86106f2e1
@ -111,7 +111,7 @@ This makes it possible to have all sudo I/O logs on a central server."
|
||||
# Package parent directories when not installing under /usr
|
||||
if test "${prefix}" != "/usr"; then
|
||||
extradirs=`echo ${pp_destdir}${mandir}/[mc]* | sed "s#${pp_destdir}##g"`
|
||||
extradirs="$extradirs `dirname $docdir`"
|
||||
extradirs="$extradirs `dirname $docdir` `dirname $rundir`"
|
||||
test "`dirname $exampledir`" != "$docdir" && extradirs="$extradirs `dirname $exampledir`"
|
||||
for dir in $sbindir $extradirs; do
|
||||
while test "$dir" != "/"; do
|
||||
@ -148,6 +148,7 @@ This makes it possible to have all sudo I/O logs on a central server."
|
||||
%endif
|
||||
$sbindir/sudo_logsrvd 0755 ignore-others
|
||||
$mandir/man*/*logsrv* 0644 ignore-others
|
||||
$rundir/ 0711 root: ignore-others
|
||||
$docdir/ 0755 ignore-others
|
||||
$exampledir/ 0755 ignore-others
|
||||
$exampledir/*logsrv* 0644 ignore-others
|
||||
|
@ -1650,6 +1650,36 @@ logsrvd_cleanup(void)
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write the process ID into a file, typically /var/run/sudo/sudo_logsrvd.pid.
|
||||
* If the parent directory doesn't exist, it will be created.
|
||||
*/
|
||||
static void
|
||||
write_pidfile(void)
|
||||
{
|
||||
FILE *fp;
|
||||
bool success;
|
||||
char *pid_file = (char *)logsrvd_conf_pid_file();
|
||||
debug_decl(write_pidfile, SUDO_DEBUG_UTIL);
|
||||
|
||||
/* sudo_mkdir_parents() modifies the path but restores it before return. */
|
||||
success = sudo_mkdir_parents(pid_file, ROOT_UID, ROOT_GID,
|
||||
S_IRWXU|S_IXGRP|S_IXOTH, false);
|
||||
if (success) {
|
||||
fp = fopen(logsrvd_conf_pid_file(), "w");
|
||||
if (fp == NULL) {
|
||||
sudo_warn("%s", pid_file);
|
||||
} else {
|
||||
fprintf(fp, "%u\n", (unsigned int)getpid());
|
||||
fflush(fp);
|
||||
if (ferror(fp))
|
||||
sudo_warn("%s", pid_file);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
debug_return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fork, detatch from the terminal and write pid file unless nofork set.
|
||||
*/
|
||||
@ -1660,8 +1690,6 @@ daemonize(bool nofork)
|
||||
debug_decl(daemonize, SUDO_DEBUG_UTIL);
|
||||
|
||||
if (!nofork) {
|
||||
FILE *fp;
|
||||
|
||||
switch (fork()) {
|
||||
case -1:
|
||||
sudo_fatal("fork");
|
||||
@ -1676,13 +1704,7 @@ daemonize(bool nofork)
|
||||
/* detach from terminal and write pid file. */
|
||||
if (setsid() == -1)
|
||||
sudo_fatal("setsid");
|
||||
fp = fopen(logsrvd_conf_pid_file(), "w");
|
||||
if (fp == NULL) {
|
||||
sudo_warn("%s", logsrvd_conf_pid_file());
|
||||
} else {
|
||||
fprintf(fp, "%u\n", (unsigned int)getpid());
|
||||
fclose(fp);
|
||||
}
|
||||
write_pidfile();
|
||||
}
|
||||
|
||||
if (chdir("/") == -1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user