Check the return value of fscanf() when reading a PID file.

This commit is contained in:
Guus Sliepen 2009-09-08 18:18:16 +02:00
parent 5e0efd53e7
commit 3e55dc77f4

View file

@ -37,11 +37,12 @@
pid_t read_pid (char *pidfile) pid_t read_pid (char *pidfile)
{ {
FILE *f; FILE *f;
long pid = 0; long pid;
if (!(f=fopen(pidfile,"r"))) if (!(f=fopen(pidfile,"r")))
return 0; return 0;
fscanf(f,"%ld", &pid); if(fscanf(f,"%ld", &pid) != 1)
pid = 0;
fclose(f); fclose(f);
return pid; return pid;
} }