Skip to content

Commit 8254e70

Browse files
committed
Ensure pid file ends with line separator
1 parent f7be28e commit 8254e70

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

daemonize-tests/tests/tests.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ fn pid() {
3838
.pid_file(&path)
3939
.sleep(std::time::Duration::from_secs(5))
4040
.run();
41-
let pid = std::fs::read_to_string(&path).unwrap().parse().unwrap();
41+
let pid_content = std::fs::read_to_string(&path).unwrap();
42+
assert!(pid_content.ends_with('\n'));
43+
let pid = pid_content[..pid_content.len() - 1].parse().unwrap();
4244
assert_eq!(result.unwrap().pid, pid);
4345

4446
let result = Tester::new().pid_file(&path).run();

daemonize/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ unsafe fn chown_pid_file(
537537

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

0 commit comments

Comments
 (0)