cloudflare / tableflip

Graceful process restarts in Go
BSD 3-Clause "New" or "Revised" License
2.88k stars 147 forks source link

Pidfile: Use work directory if no path given #25

Closed fasmide closed 5 years ago

fasmide commented 5 years ago

Hello

When specifying just a filename e.g. app.pid as PIDFile option (expecting it to appear in the current working directory) - the previous code created a tmp file in /tmp and then tried to os.Rename it back to the current work directory - This results in invalid cross-device link errors from os.Rename if /tmp is on another mount point

This is a proposal to fix the issue, by using the current work directory for the tmp file if no path was given :)

lmb commented 5 years ago

I hadn't considered this case, thanks for the PR!

lmb commented 5 years ago

Ah, and if you have time for a small test, I would also appreciate that!

fasmide commented 5 years ago

Ah, and if you have time for a small test, I would also appreciate that!

Sure - I've added a test case for writing pidfiles without paths e.g. by specifying just tableflip-testpid.pid and while this does increase the coverage - it does not really test the issue at hand where the temp file is written on another mount point... Properly good enough :)

lmb commented 5 years ago

Hi fasmide,

I made the changes myself, and merged #28. I hope you don't mind.

lmb commented 5 years ago

Thanks for contributing!