}
-void kill_file(const std::string &filename)
+pid_t kill_file(const std::string &filename)
{
+ pid_t ret= -1;
FILE *fp;
if (filename.empty())
- return;
+ return ret;
if ((fp= fopen(filename.c_str(), "r")))
{
}
}
}
+
+ return ret;
+}
+
+pid_t get_pid_from_file(const std::string &filename)
+{
+ pid_t ret= -1;
+ FILE *fp;
+
+ if (filename.empty())
+ {
+ Error << "empty pid file";
+ return ret;
+ }
+
+ if ((fp= fopen(filename.c_str(), "r")))
+ {
+ char pid_buffer[1024];
+
+ char *ptr= fgets(pid_buffer, sizeof(pid_buffer), fp);
+ fclose(fp);
+
+ if (ptr)
+ {
+ ret= (pid_t)atoi(pid_buffer);
+ if (ret <= 0)
+ {
+ return ret;
+ }
+ }
+ }
+
+ return ret;
}