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
|
# Package parent directories when not installing under /usr
|
||||||
if test "${prefix}" != "/usr"; then
|
if test "${prefix}" != "/usr"; then
|
||||||
extradirs=`echo ${pp_destdir}${mandir}/[mc]* | sed "s#${pp_destdir}##g"`
|
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`"
|
test "`dirname $exampledir`" != "$docdir" && extradirs="$extradirs `dirname $exampledir`"
|
||||||
for dir in $sbindir $extradirs; do
|
for dir in $sbindir $extradirs; do
|
||||||
while test "$dir" != "/"; 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
|
%endif
|
||||||
$sbindir/sudo_logsrvd 0755 ignore-others
|
$sbindir/sudo_logsrvd 0755 ignore-others
|
||||||
$mandir/man*/*logsrv* 0644 ignore-others
|
$mandir/man*/*logsrv* 0644 ignore-others
|
||||||
|
$rundir/ 0711 root: ignore-others
|
||||||
$docdir/ 0755 ignore-others
|
$docdir/ 0755 ignore-others
|
||||||
$exampledir/ 0755 ignore-others
|
$exampledir/ 0755 ignore-others
|
||||||
$exampledir/*logsrv* 0644 ignore-others
|
$exampledir/*logsrv* 0644 ignore-others
|
||||||
|
@ -1650,6 +1650,36 @@ logsrvd_cleanup(void)
|
|||||||
return;
|
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.
|
* 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);
|
debug_decl(daemonize, SUDO_DEBUG_UTIL);
|
||||||
|
|
||||||
if (!nofork) {
|
if (!nofork) {
|
||||||
FILE *fp;
|
|
||||||
|
|
||||||
switch (fork()) {
|
switch (fork()) {
|
||||||
case -1:
|
case -1:
|
||||||
sudo_fatal("fork");
|
sudo_fatal("fork");
|
||||||
@ -1676,13 +1704,7 @@ daemonize(bool nofork)
|
|||||||
/* detach from terminal and write pid file. */
|
/* detach from terminal and write pid file. */
|
||||||
if (setsid() == -1)
|
if (setsid() == -1)
|
||||||
sudo_fatal("setsid");
|
sudo_fatal("setsid");
|
||||||
fp = fopen(logsrvd_conf_pid_file(), "w");
|
write_pidfile();
|
||||||
if (fp == NULL) {
|
|
||||||
sudo_warn("%s", logsrvd_conf_pid_file());
|
|
||||||
} else {
|
|
||||||
fprintf(fp, "%u\n", (unsigned int)getpid());
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chdir("/") == -1)
|
if (chdir("/") == -1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user