Minor PID string length fix

Changed PID string length to 7 to accomodate an ending newline and NULL
char when writing to the fwknopd .pid file.  Without this fix, with a
5 digit PID the trailing newline would be truncated (no room for the
ending NULL char).
This commit is contained in:
Michael Rash 2011-10-18 21:28:38 -04:00
parent 0e7a0e9a37
commit b8571bcc05
2 changed files with 10 additions and 5 deletions

View File

@ -590,7 +590,7 @@ write_pid_file(fko_srv_options_t *opts)
{
pid_t old_pid, my_pid;
int op_fd, lck_res, num_bytes;
char buf[6] = {0};
char buf[PID_BUFLEN] = {0};
/* Reset errno (just in case)
*/
@ -640,7 +640,7 @@ write_pid_file(fko_srv_options_t *opts)
/* Write our PID to the file
*/
my_pid = getpid();
snprintf(buf, 6, "%i\n", my_pid);
snprintf(buf, PID_BUFLEN, "%i\n", my_pid);
if(opts->verbose > 1)
log_msg(LOG_INFO, "[+] Writing my PID (%i) to the lock file: %s\n",
@ -667,15 +667,18 @@ static pid_t
get_running_pid(fko_srv_options_t *opts)
{
int op_fd;
char buf[6] = {0};
pid_t rpid = 0;
char buf[PID_BUFLEN] = {0};
pid_t rpid = 0;
op_fd = open(opts->config[CONF_FWKNOP_PID_FILE], O_RDONLY);
if(op_fd > 0)
{
if (read(op_fd, buf, 6) > 0)
if (read(op_fd, buf, PID_BUFLEN) > 0)
{
buf[PID_BUFLEN-1] = '\0';
rpid = (pid_t)atoi(buf);
}
close(op_fd);
}

View File

@ -62,4 +62,6 @@
#define CRYPT_OP_ENCRYPT 1
#define CRYPT_OP_DECRYPT 2
#define PID_BUFLEN 7
#endif /* FWKNOPD_H */