[server] better checking for read() return value flagged by Coverity

This commit is contained in:
Michael Rash 2014-01-12 21:40:20 -05:00
parent 05d6e1c4a7
commit cf6a38ea0d

View File

@ -731,7 +731,7 @@ write_pid_file(fko_srv_options_t *opts)
static pid_t
get_running_pid(const fko_srv_options_t *opts)
{
int op_fd, is_err;
int op_fd, is_err, bytes_read = 0;
char buf[PID_BUFLEN] = {0};
pid_t rpid = 0;
@ -751,7 +751,8 @@ get_running_pid(const fko_srv_options_t *opts)
return(rpid);
}
if (read(op_fd, buf, PID_BUFLEN) > 0)
bytes_read = read(op_fd, buf, PID_BUFLEN);
if (bytes_read > 0)
{
buf[PID_BUFLEN-1] = '\0';
/* max pid value is configurable on Linux
@ -761,6 +762,8 @@ get_running_pid(const fko_srv_options_t *opts)
if(is_err != FKO_SUCCESS)
rpid = 0;
}
else if (bytes_read < 0)
perror("Error trying to read() PID file: ");
close(op_fd);