Skip to content

Commit

Permalink
Merge pull request #45 from sndyuk/invalid_pid_format
Browse files Browse the repository at this point in the history
Ensure pid file ends with line separator
  • Loading branch information
knsd authored Feb 19, 2023
2 parents 6415684 + 8254e70 commit 7e3a615
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion daemonize-tests/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ fn pid() {
.pid_file(&path)
.sleep(std::time::Duration::from_secs(5))
.run();
let pid = std::fs::read_to_string(&path).unwrap().parse().unwrap();
let pid_content = std::fs::read_to_string(&path).unwrap();
assert!(pid_content.ends_with('\n'));
let pid = pid_content[..pid_content.len() - 1].parse().unwrap();
assert_eq!(result.unwrap().pid, pid);

let result = Tester::new().pid_file(&path).run();
Expand Down
2 changes: 1 addition & 1 deletion daemonize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ unsafe fn chown_pid_file(

unsafe fn write_pid_file(fd: libc::c_int) -> Result<(), ErrorKind> {
let pid = libc::getpid();
let pid_buf = format!("{}", pid).into_bytes();
let pid_buf = format!("{}\n", pid).into_bytes();
let pid_length = pid_buf.len();
let pid_c = CString::new(pid_buf).unwrap();
check_err(libc::ftruncate(fd, 0), ErrorKind::TruncatePidfile)?;
Expand Down

0 comments on commit 7e3a615

Please sign in to comment.