author | Michael Krelin <hacker@klever.net> | 2004-07-09 16:48:52 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2004-07-09 16:48:52 (UTC) |
commit | 9148dac885c0325636c2d33715ba248371706d0d (patch) (side-by-side diff) | |
tree | fd95d60f6fd051c3ad46a966882e2be48440452f /src/util.cc | |
download | dudki-9148dac885c0325636c2d33715ba248371706d0d.zip dudki-9148dac885c0325636c2d33715ba248371706d0d.tar.gz dudki-9148dac885c0325636c2d33715ba248371706d0d.tar.bz2 |
dudki: initial import into svn repository
-rw-r--r-- | src/util.cc | 21 |
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()); +} + |