Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check return value of fscanf() #222

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions services/rc_battery_monitor/src/rc_battery_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void shutdown_signal_handler(int signo)
int kill_existing_instance()
{
FILE* fd;
int old_pid, i;
int old_pid, r, i;

// attempt to open PID file
fd = fopen(BATTPIDFILE, "r");
Expand All @@ -308,12 +308,12 @@ int kill_existing_instance()
}

// otherwise try to read the current process ID
fscanf(fd,"%d", &old_pid);
r = fscanf(fd,"%d", &old_pid);
fclose(fd);

// if the file didn't contain a PID number, remove it and
// return -1 indicating weird behavior
if(old_pid == 0){
if(r != 1){
remove(BATTPIDFILE);
return 1;
}
Expand Down