diff options
Diffstat (limited to 'lib/libutil/pidfile.c')
-rw-r--r-- | lib/libutil/pidfile.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/libutil/pidfile.c b/lib/libutil/pidfile.c index e002d65..983d103 100644 --- a/lib/libutil/pidfile.c +++ b/lib/libutil/pidfile.c @@ -88,19 +88,19 @@ pidfile_open(const char *path, mode_t mode, pid_t *pidptr) { struct pidfh *pfh; struct stat sb; - int error, fd; + int error, fd, len; pfh = malloc(sizeof(*pfh)); if (pfh == NULL) return (NULL); - if (path == NULL) { - snprintf(pfh->pf_path, sizeof(pfh->pf_path), "/var/run/%s.pid", - getprogname()); - } else { - strlcpy(pfh->pf_path, path, sizeof(pfh->pf_path)); - } - if (strlen(pfh->pf_path) == sizeof(pfh->pf_path) - 1) { + if (path == NULL) + len = snprintf(pfh->pf_path, sizeof(pfh->pf_path), + "/var/run/%s.pid", getprogname()); + else + len = snprintf(pfh->pf_path, sizeof(pfh->pf_path), + "%s", path); + if (len >= (int)sizeof(pfh->pf_path)) { free(pfh); errno = ENAMETOOLONG; return (NULL); |