+
+ return ret;
+ }
+ }
+ }
+
+ return false;
+}
+
+#define STRINGIFY(x) #x
+#define TOSTRING(x) STRINGIFY(x)
+#define LIBTEST_AT __FILE__ ":" TOSTRING(__LINE__)
+
+pid_t get_pid_from_file(const std::string &filename, std::stringstream& error_message)
+{
+ pid_t ret= -1;
+ FILE *fp;
+
+ if (filename.empty())
+ {
+ error_message << LIBTEST_AT << " 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 < 1)
+ {
+ error_message << LIBTEST_AT << " Invalid pid was read from file " << filename;