summaryrefslogtreecommitdiffabout
path: root/src/util.cc
Side-by-side diff
Diffstat (limited to 'src/util.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--src/util.cc21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/util.cc b/src/util.cc
new file mode 100644
index 0000000..afb2641
--- a/dev/null
+++ b/src/util.cc
@@ -0,0 +1,21 @@
+#include <unistd.h>
+#include <fstream>
+#include <stdexcept>
+using namespace std;
+#include "util.h"
+
+void pid_file::set(const string& f,bool u) {
+ ofstream of(f.c_str(),ios::trunc);
+ if(!of)
+ throw runtime_error(string(__PRETTY_FUNCTION__)+": failed to open file for writing pid");
+ of << getpid() << endl;
+ of.close();
+ file_name = f;
+ unlink_pid = u;
+}
+void pid_file::unlink() {
+ if(!unlink_pid)
+ return;
+ ::unlink(file_name.c_str());
+}
+