summaryrefslogtreecommitdiffabout
path: root/src/util.cc
blob: afb264108b53bbc0d15d69d40e4c03626e0411b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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());
}