Check the return value of fscanf() when reading a PID file.
This commit is contained in:
parent
5e0efd53e7
commit
3e55dc77f4
1 changed files with 3 additions and 2 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue