pathut: pidfile has no real reason to use pid_t, replace with int and make windows life easier

This commit is contained in:
Jean-Francois Dockes 2020-04-03 08:37:36 +02:00
parent 7656d1b2ef
commit 93262e57a6
2 changed files with 9 additions and 9 deletions

View File

@ -1096,24 +1096,24 @@ Pidfile::~Pidfile()
this->close(); this->close();
} }
pid_t Pidfile::read_pid() int Pidfile::read_pid()
{ {
int fd = ::open(m_path.c_str(), O_RDONLY); int fd = ::open(m_path.c_str(), O_RDONLY);
if (fd == -1) { if (fd == -1) {
return (pid_t) -1; return -1;
} }
char buf[16]; char buf[16];
int i = read(fd, buf, sizeof(buf) - 1); int i = read(fd, buf, sizeof(buf) - 1);
::close(fd); ::close(fd);
if (i <= 0) { if (i <= 0) {
return (pid_t) -1; return -1;
} }
buf[i] = '\0'; buf[i] = '\0';
char *endptr; char *endptr;
pid_t pid = strtol(buf, &endptr, 10); int pid = strtol(buf, &endptr, 10);
if (endptr != &buf[i]) { if (endptr != &buf[i]) {
return (pid_t) - 1; return - 1;
} }
return pid; return pid;
} }
@ -1161,12 +1161,12 @@ int Pidfile::flopen()
return 0; return 0;
} }
pid_t Pidfile::open() int Pidfile::open()
{ {
if (flopen() < 0) { if (flopen() < 0) {
return read_pid(); return read_pid();
} }
return (pid_t)0; return 0;
} }
int Pidfile::write_pid() int Pidfile::write_pid()

View File

@ -175,7 +175,7 @@ public:
~Pidfile(); ~Pidfile();
/// Open/create the pid file. /// Open/create the pid file.
/// @return 0 if ok, > 0 for pid of existing process, -1 for other error. /// @return 0 if ok, > 0 for pid of existing process, -1 for other error.
pid_t open(); int open();
/// Write pid into the pid file /// Write pid into the pid file
/// @return 0 ok, -1 error /// @return 0 ok, -1 error
int write_pid(); int write_pid();
@ -190,7 +190,7 @@ private:
std::string m_path; std::string m_path;
int m_fd; int m_fd;
std::string m_reason; std::string m_reason;
pid_t read_pid(); int read_pid();
int flopen(); int flopen();
}; };