|
a/src/pathut.cpp |
|
b/src/pathut.cpp |
|
... |
|
... |
349 |
(path[2] == '/' || path[2] == '\\')) {
|
349 |
(path[2] == '/' || path[2] == '\\')) {
|
350 |
return true;
|
350 |
return true;
|
351 |
}
|
351 |
}
|
352 |
#endif
|
352 |
#endif
|
353 |
return false;
|
353 |
return false;
|
|
|
354 |
}
|
|
|
355 |
|
|
|
356 |
bool path_isdesc(const string& _top, const string& _sub)
|
|
|
357 |
{
|
|
|
358 |
string top = path_canon(_top);
|
|
|
359 |
string sub = path_canon(_sub);
|
|
|
360 |
path_catslash(top);
|
|
|
361 |
path_catslash(sub);
|
|
|
362 |
for (;;) {
|
|
|
363 |
if (sub == top) {
|
|
|
364 |
return true;
|
|
|
365 |
}
|
|
|
366 |
string::size_type l = sub.size();
|
|
|
367 |
sub = path_getfather(sub);
|
|
|
368 |
if (sub.size() == l || sub.size() < top.size()) {
|
|
|
369 |
// At root or sub shorter than top: done
|
|
|
370 |
if (sub == top) {
|
|
|
371 |
return true;
|
|
|
372 |
} else {
|
|
|
373 |
return false;
|
|
|
374 |
}
|
|
|
375 |
}
|
|
|
376 |
}
|
354 |
}
|
377 |
}
|
355 |
|
378 |
|
356 |
bool path_isabsolute(const string& path)
|
379 |
bool path_isabsolute(const string& path)
|
357 |
{
|
380 |
{
|
358 |
if (!path.empty() && (path[0] == '/'
|
381 |
if (!path.empty() && (path[0] == '/'
|
|
... |
|
... |
788 |
// as we'd like to reset the pid inside the file when we're done, it
|
811 |
// as we'd like to reset the pid inside the file when we're done, it
|
789 |
// would be very difficult to do it right and it's probably best left
|
812 |
// would be very difficult to do it right and it's probably best left
|
790 |
// alone.
|
813 |
// alone.
|
791 |
Pidfile::~Pidfile()
|
814 |
Pidfile::~Pidfile()
|
792 |
{
|
815 |
{
|
793 |
if (m_fd >= 0) {
|
816 |
this->close();
|
794 |
::close(m_fd);
|
|
|
795 |
}
|
|
|
796 |
m_fd = -1;
|
|
|
797 |
}
|
817 |
}
|
798 |
|
818 |
|
799 |
pid_t Pidfile::read_pid()
|
819 |
pid_t Pidfile::read_pid()
|
800 |
{
|
820 |
{
|
801 |
int fd = ::open(m_path.c_str(), O_RDONLY);
|
821 |
int fd = ::open(m_path.c_str(), O_RDONLY);
|
|
... |
|
... |
832 |
lockdata.l_len = 0;
|
852 |
lockdata.l_len = 0;
|
833 |
lockdata.l_type = F_WRLCK;
|
853 |
lockdata.l_type = F_WRLCK;
|
834 |
lockdata.l_whence = SEEK_SET;
|
854 |
lockdata.l_whence = SEEK_SET;
|
835 |
if (fcntl(m_fd, F_SETLK, &lockdata) != 0) {
|
855 |
if (fcntl(m_fd, F_SETLK, &lockdata) != 0) {
|
836 |
int serrno = errno;
|
856 |
int serrno = errno;
|
837 |
(void)::close(m_fd);
|
857 |
this->close()
|
838 |
errno = serrno;
|
858 |
errno = serrno;
|
839 |
m_reason = "fcntl lock failed";
|
859 |
m_reason = "fcntl lock failed";
|
840 |
return -1;
|
860 |
return -1;
|
841 |
}
|
861 |
}
|
842 |
#else
|
862 |
#else
|
|
... |
|
... |
844 |
return 0;
|
864 |
return 0;
|
845 |
#else
|
865 |
#else
|
846 |
int operation = LOCK_EX | LOCK_NB;
|
866 |
int operation = LOCK_EX | LOCK_NB;
|
847 |
if (flock(m_fd, operation) == -1) {
|
867 |
if (flock(m_fd, operation) == -1) {
|
848 |
int serrno = errno;
|
868 |
int serrno = errno;
|
849 |
(void)::close(m_fd);
|
869 |
this->close();
|
850 |
errno = serrno;
|
870 |
errno = serrno;
|
851 |
m_reason = "flock failed";
|
871 |
m_reason = "flock failed";
|
852 |
return -1;
|
872 |
return -1;
|
853 |
}
|
873 |
}
|
854 |
#endif // ! win32
|
874 |
#endif // ! win32
|
855 |
#endif // ! sun
|
875 |
#endif // ! sun
|
856 |
|
876 |
|
857 |
if (ftruncate(m_fd, 0) != 0) {
|
877 |
if (ftruncate(m_fd, 0) != 0) {
|
858 |
/* can't happen [tm] */
|
878 |
/* can't happen [tm] */
|
859 |
int serrno = errno;
|
879 |
int serrno = errno;
|
860 |
(void)::close(m_fd);
|
880 |
this->close();
|
861 |
errno = serrno;
|
881 |
errno = serrno;
|
862 |
m_reason = "ftruncate failed";
|
882 |
m_reason = "ftruncate failed";
|
863 |
return -1;
|
883 |
return -1;
|
864 |
}
|
884 |
}
|
865 |
return 0;
|
885 |
return 0;
|
|
... |
|
... |
890 |
return 0;
|
910 |
return 0;
|
891 |
}
|
911 |
}
|
892 |
|
912 |
|
893 |
int Pidfile::close()
|
913 |
int Pidfile::close()
|
894 |
{
|
914 |
{
|
|
|
915 |
int ret = -1;
|
|
|
916 |
if (m_fd >= 0) {
|
895 |
return ::close(m_fd);
|
917 |
ret = ::close(m_fd);
|
|
|
918 |
m_fd = -1;
|
|
|
919 |
}
|
|
|
920 |
return ret;
|
896 |
}
|
921 |
}
|
897 |
|
922 |
|
898 |
int Pidfile::remove()
|
923 |
int Pidfile::remove()
|
899 |
{
|
924 |
{
|
900 |
return unlink(m_path.c_str());
|
925 |
return unlink(m_path.c_str());
|