1
0
forked from bip/bip

sanitize: fix pid/pidfile handling

This commit is contained in:
Loïc Gomez 2022-01-09 20:11:01 +01:00 committed by Pierre-Louis Bonicoli
parent af590f83b7
commit b990a071b3
Signed by untrusted user: pilou
GPG Key ID: 06914C4A5EDAA6DD

View File

@ -179,7 +179,7 @@ try_again:
fatal("%s %s", "gethostname", strerror(errno));
hname[511] = 0;
snprintf(longpath, longpath_max - 1, "%s.%s.%ld", conf_pid_file, hname,
(long unsigned int)getpid());
(long)getpid());
longpath[longpath_max] = 0;
if ((fd = open(longpath, O_CREAT|O_WRONLY, S_IWUSR|S_IRUSR)) == -1)
fatal("Cannot write to PID file (%s) %s", longpath,
@ -199,13 +199,13 @@ try_again:
pid_is_there:
{
pid_t pid;
long unsigned int p;
size_t p;
if (fd != -1)
close(fd);
if (f) {
int c = fscanf(f, "%ld", &p);
int c = fscanf(f, "%zu", (size_t *)&p);
fclose(f);
pid = p;
pid = (pid_t)p;
if (c != 1 || p == 0) {
mylog(LOG_INFO, "pid file found but invalid "
"data inside. Continuing...\n");