From 567bf445bf188ae60056e779927da52dcd7ed35d Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 15 Aug 2015 16:39:52 +0200 Subject: unix/Daemon: move code to ReadPidFile() --- src/unix/PidFile.hxx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/unix/PidFile.hxx') diff --git a/src/unix/PidFile.hxx b/src/unix/PidFile.hxx index 3c3d5ca21..a8af1e890 100644 --- a/src/unix/PidFile.hxx +++ b/src/unix/PidFile.hxx @@ -82,4 +82,20 @@ public: } }; +gcc_pure +static inline pid_t +ReadPidFile(Path path) +{ + FILE *fp = FOpen(path, PATH_LITERAL("r")); + if (fp == nullptr) + return -1; + + int pid; + if (fscanf(fp, "%i", &pid) != 1) + pid = -1; + + fclose(fp); + return pid; +} + #endif -- cgit v1.2.3