[Opalvoip-svn] SF.net SVN: opalvoip:[34926] ptlib/trunk
Brought to you by:
csoutheren,
rjongbloed
|
From: <rjo...@us...> - 2016-08-22 16:32:03
|
Revision: 34926
http://sourceforge.net/p/opalvoip/code/34926
Author: rjongbloed
Date: 2016-08-22 16:32:00 +0000 (Mon, 22 Aug 2016)
Log Message:
-----------
Merged revision(s) 34920-34925 from ptlib/branches/v2_16:
---------------------
r34924
Fixed various functions for PFilePath, in particular the Unix SetType(), while normalising behaviour for Unix/windows platforms.
---------------------
r34923
Tweaked the factories to deal with static destructors being called twice with certain combinations of debug/static/plugin shared library nightmare that is glibc.
---------------------
r34922
Print PTrace options in hex
---------------------
r34921
Fixed GNU warning and added error message if can/cannot set file handles in service process.
Revision Links:
--------------
http://sourceforge.net/p/opalvoip/code/34924
http://sourceforge.net/p/opalvoip/code/34923
http://sourceforge.net/p/opalvoip/code/34922
http://sourceforge.net/p/opalvoip/code/34921
Modified Paths:
--------------
ptlib/trunk/include/ptlib/filepath.h
ptlib/trunk/include/ptlib/msos/ptlib/pdirect.h
ptlib/trunk/include/ptlib/pfactory.h
ptlib/trunk/include/ptlib/unix/ptlib/ptlib.inl
ptlib/trunk/src/ptlib/common/osutils.cxx
ptlib/trunk/src/ptlib/msos/ptlib.cxx
ptlib/trunk/src/ptlib/msos/win32.cxx
ptlib/trunk/src/ptlib/unix/osutil.cxx
ptlib/trunk/src/ptlib/unix/svcproc.cxx
Property Changed:
----------------
ptlib/trunk/
Index: ptlib/trunk
===================================================================
--- ptlib/trunk 2016-08-22 16:17:34 UTC (rev 34925)
+++ ptlib/trunk 2016-08-22 16:32:00 UTC (rev 34926)
Property changes on: ptlib/trunk
___________________________________________________________________
Modified: svn:mergeinfo
## -6,7 +6,7 ##
/ptlib/branches/v2_10:25177-29189,32921,32947
/ptlib/branches/v2_12:28485-31603
/ptlib/branches/v2_14:31501-33720
-/ptlib/branches/v2_16:34085-34919
+/ptlib/branches/v2_16:34085-34925
/ptlib/branches/v2_2:20746,20791,20827,22014,22942
/ptlib/branches/v2_4:21086,21094,21147,21160,21185,21281,21296,21305,21322,21337,21363,21467,21471-21472,21506,21508,21623,21695,21744,21746,21763,22241,22958,23045-23046,23061,23066,23712
/ptlib/branches/v2_6:22195,22243,22295,22304,22311,22317,22320,22356,22458,22509,22587,22601-22602,22611,22629,22633,22673,22681,22729,22731-22732,22736,22742,22848,22960,22992,23161,23163,23167,23169,23177,23239,23291,23298,23336,23429,23595,23823,23827,23873,24816
\ No newline at end of property
Modified: ptlib/trunk/include/ptlib/filepath.h
===================================================================
--- ptlib/trunk/include/ptlib/filepath.h 2016-08-22 16:17:34 UTC (rev 34925)
+++ ptlib/trunk/include/ptlib/filepath.h 2016-08-22 16:32:00 UTC (rev 34926)
@@ -291,6 +291,8 @@
);
//@}
+ // Internal function to take partial path and make a full canonoical path form it.
+ static PFilePathString Canonicalise(const PFilePathString & path, bool isDirectory);
protected:
virtual void AssignContents(const PContainer & cont);
Modified: ptlib/trunk/include/ptlib/msos/ptlib/pdirect.h
===================================================================
--- ptlib/trunk/include/ptlib/msos/ptlib/pdirect.h 2016-08-22 16:17:34 UTC (rev 34925)
+++ ptlib/trunk/include/ptlib/msos/ptlib/pdirect.h 2016-08-22 16:32:00 UTC (rev 34926)
@@ -39,7 +39,4 @@
WIN32_FIND_DATA fileinfo;
bool InternalEntryCheck();
- public:
- static PString CreateFullPath(const PString & path, PBoolean isDirectory);
-
// End Of File ///////////////////////////////////////////////////////////////
Modified: ptlib/trunk/include/ptlib/pfactory.h
===================================================================
--- ptlib/trunk/include/ptlib/pfactory.h 2016-08-22 16:17:34 UTC (rev 34925)
+++ ptlib/trunk/include/ptlib/pfactory.h 2016-08-22 16:32:00 UTC (rev 34926)
@@ -408,21 +408,25 @@
class Worker : protected WorkerBase_T
{
private:
- Key_T m_key;
+ Key_T * m_key;
public:
Worker(const Key_T & key, bool singleton = false)
: WorkerBase_T(singleton)
- , m_key(key)
+ , m_key(new Key_T(key))
{
PAssert(Register(key, this), "Factory Worker already registered");
}
~Worker()
{
- Unregister(m_key);
+ if (m_key == NULL)
+ return;
+ Unregister(*m_key);
+ delete m_key;
+ m_key = NULL;
}
- const Key_T & GetKey() const { return m_key; }
+ const Key_T & GetKey() const { return *m_key; }
protected:
virtual Abstract_T * Create(Param_T) const
@@ -469,21 +473,25 @@
class Worker : protected WorkerBase_T
{
private:
- Key_T m_key;
+ Key_T * m_key;
public:
Worker(const Key_T & key, bool singleton = false)
: WorkerBase_T(singleton)
- , m_key(key)
+ , m_key(new Key_T(key))
{
PAssert(Register(key, this), "Factory Worker already registered");
}
~Worker()
{
- Unregister(m_key);
+ if (m_key == NULL)
+ return;
+ Unregister(*m_key);
+ delete m_key;
+ m_key = NULL;
}
- const Key_T & GetKey() const { return m_key; }
+ const Key_T & GetKey() const { return *m_key; }
protected:
virtual Abstract_T * Create(Param_T param) const
Modified: ptlib/trunk/include/ptlib/unix/ptlib/ptlib.inl
===================================================================
--- ptlib/trunk/include/ptlib/unix/ptlib/ptlib.inl 2016-08-22 16:17:34 UTC (rev 34925)
+++ ptlib/trunk/include/ptlib/unix/ptlib/ptlib.inl 2016-08-22 16:32:00 UTC (rev 34926)
@@ -79,6 +79,9 @@
PINLINE PString PFilePath::GetVolume() const
{ return PString::Empty(); }
+PINLINE PString PFilePath::GetPath() const
+ { return GetDirectory(); }
+
///////////////////////////////////////////////////////////////////////////////
PINLINE bool PFile::Remove(const PFilePath & name, bool)
Modified: ptlib/trunk/src/ptlib/common/osutils.cxx
===================================================================
--- ptlib/trunk/src/ptlib/common/osutils.cxx 2016-08-22 16:17:34 UTC (rev 34925)
+++ ptlib/trunk/src/ptlib/common/osutils.cxx 2016-08-22 16:32:00 UTC (rev 34926)
@@ -659,7 +659,7 @@
{
PTraceInfo & info = PTraceInfo::Instance();
if (info.AdjustOptions(options, 0)) {
- PTRACE(2, "Trace options set to " << info.m_options);
+ PTRACE(2, "Trace options 0x" << hex << options << " added, now 0x" << info.m_options);
}
}
@@ -668,7 +668,7 @@
{
PTraceInfo & info = PTraceInfo::Instance();
if (info.AdjustOptions(0, options)) {
- PTRACE(2, "Trace options set to " << info.m_options);
+ PTRACE(2, "Trace options 0x" << hex << options << " removed, now 0x" << info.m_options);
}
}
@@ -3667,4 +3667,72 @@
return m_inUse.find(id) != m_inUse.end();
}
+
+///////////////////////////////////////////////////////////////////////
+
+PFilePath::PFilePath(const PString & str)
+ : PFilePathString(Canonicalise(str, false))
+{
+}
+
+
+PFilePath::PFilePath(const char * cstr)
+ : PFilePathString(Canonicalise(cstr, false))
+{
+}
+
+
+void PFilePath::AssignContents(const PContainer & cont)
+{
+ PFilePathString::AssignContents(cont);
+ PFilePathString::AssignContents(Canonicalise(*this, false));
+}
+
+
+PDirectory PFilePath::GetDirectory() const
+{
+ if (!IsEmpty()) {
+ PINDEX sep = FindLast(PDIR_SEPARATOR);
+ if (PAssert(sep != P_MAX_INDEX, "Bad file path"))
+ return Left(sep);
+ }
+ return PString::Empty();
+}
+
+
+PFilePathString PFilePath::GetFileName() const
+{
+ if (!IsEmpty()) {
+ PINDEX sep = FindLast(PDIR_SEPARATOR);
+ if (PAssert(sep != P_MAX_INDEX, "Bad file path"))
+ return Mid(sep+1);
+ }
+ return PString::Empty();
+}
+
+
+PFilePathString PFilePath::GetTitle() const
+{
+ PFilePathString filename = GetFileName();
+ return filename.Left(filename.FindLast('.'));
+}
+
+
+PFilePathString PFilePath::GetType() const
+{
+ PFilePathString filename = GetFileName();
+ return filename.Mid(filename.FindLast('.'));
+}
+
+
+void PFilePath::SetType(const PFilePathString & newType)
+{
+ PFilePathString oldType = GetType();
+ if (oldType.IsEmpty())
+ *this += newType;
+ else
+ Splice(newType, GetLength() - oldType.GetLength(), oldType.GetLength());
+}
+
+
// End Of File ///////////////////////////////////////////////////////////////
Modified: ptlib/trunk/src/ptlib/msos/ptlib.cxx
===================================================================
--- ptlib/trunk/src/ptlib/msos/ptlib.cxx 2016-08-22 16:17:34 UTC (rev 34925)
+++ ptlib/trunk/src/ptlib/msos/ptlib.cxx 2016-08-22 16:32:00 UTC (rev 34926)
@@ -359,18 +359,6 @@
///////////////////////////////////////////////////////////////////////////////
// File Path
-PFilePath::PFilePath(const PString & str)
- : PCaselessString(PDirectory::CreateFullPath(str, false))
-{
-}
-
-
-PFilePath::PFilePath(const char * cstr)
- : PCaselessString(PDirectory::CreateFullPath(cstr, false))
-{
-}
-
-
PFilePath::PFilePath(const char * prefix, const char * dir)
{
if (dir != NULL) {
@@ -397,13 +385,6 @@
}
-void PFilePath::AssignContents(const PContainer & cont)
-{
- PCaselessString::AssignContents(cont);
- PCaselessString::AssignContents(PDirectory::CreateFullPath(*this, false));
-}
-
-
static PINDEX GetVolumeSubStringLength(const PString & path)
{
if (path[1] == ':')
@@ -432,72 +413,12 @@
}
-PDirectory PFilePath::GetDirectory() const
-{
- PINDEX backslash = FindLast('\\');
- if (backslash != P_MAX_INDEX)
- return Left(backslash+1);
-
- return PCaselessString();
-}
-
-
PCaselessString PFilePath::GetPath() const
{
return operator()(GetVolumeSubStringLength(*this), FindLast('\\', GetLength()-2));
}
-PCaselessString PFilePath::GetFileName() const
-{
- PINDEX backslash = FindLast('\\', GetLength()-2);
- if (backslash == P_MAX_INDEX)
- backslash = 0;
- else
- backslash++;
-
- return Mid(backslash);
-}
-
-
-PCaselessString PFilePath::GetTitle() const
-{
- PINDEX backslash = FindLast('\\', GetLength()-2);
- if (backslash == P_MAX_INDEX)
- backslash = 0;
- else
- backslash++;
-
- PINDEX last_dot = FindLast('.');
- if (last_dot < backslash)
- last_dot = P_MAX_INDEX;
-
- return operator()(backslash, last_dot-1);
-}
-
-
-PCaselessString PFilePath::GetType() const
-{
- PINDEX slash = FindLast('\\');
- if (slash == P_MAX_INDEX)
- slash = 0;
- PINDEX dot = FindLast('.');
- if (dot < slash)
- return PCaselessString();
- return operator()(dot, P_MAX_INDEX);
-}
-
-
-void PFilePath::SetType(const PCaselessString & type)
-{
- PINDEX dot = Find('.', FindLast('\\'));
- if (dot != P_MAX_INDEX)
- Splice(type, dot, GetLength()-dot);
- else
- *this += type;
-}
-
-
///////////////////////////////////////////////////////////////////////////////
// PFile
Modified: ptlib/trunk/src/ptlib/msos/win32.cxx
===================================================================
--- ptlib/trunk/src/ptlib/msos/win32.cxx 2016-08-22 16:17:34 UTC (rev 34925)
+++ ptlib/trunk/src/ptlib/msos/win32.cxx 2016-08-22 16:32:00 UTC (rev 34926)
@@ -273,7 +273,7 @@
{
hFindFile = INVALID_HANDLE_VALUE;
fileinfo.cFileName[0] = '\0';
- PCaselessString::AssignContents(CreateFullPath(*this, true));
+ PCaselessString::AssignContents(PFilePath::Canonicalise(*this, true));
}
@@ -348,7 +348,7 @@
}
-PString PDirectory::CreateFullPath(const PString & path, PBoolean isDirectory)
+PFilePathString PFilePath::Canonicalise(const PFilePathString & path, bool isDirectory)
{
if (path.IsEmpty())
return path;
Modified: ptlib/trunk/src/ptlib/unix/osutil.cxx
===================================================================
--- ptlib/trunk/src/ptlib/unix/osutil.cxx 2016-08-22 16:17:34 UTC (rev 34925)
+++ ptlib/trunk/src/ptlib/unix/osutil.cxx 2016-08-22 16:32:00 UTC (rev 34926)
@@ -329,23 +329,27 @@
}
-static PString CanonicaliseFilename(const PString & filename)
+PFilePathString PFilePath::Canonicalise(const PFilePathString & path, bool isDirectory)
{
- if (filename.IsEmpty())
- return filename;
+ if (path.IsEmpty())
+ return path;
- PINDEX p;
+ if (isDirectory)
+ return CanonicaliseDirectory(path);
+
+ PINDEX pos;
PString dirname;
// if there is a slash in the string, extract the dirname
- if ((p = filename.FindLast('/')) != P_MAX_INDEX) {
- dirname = filename(0,p);
- while (filename[p] == '/')
- p++;
- } else
- p = 0;
+ if ((pos = path.FindLast('/')) == P_MAX_INDEX)
+ pos = 0;
+ else {
+ dirname = path(0, pos);
+ while (path[pos] == '/')
+ pos++;
+ }
- return CanonicaliseDirectory(dirname) + filename(p, P_MAX_INDEX);
+ return CanonicaliseDirectory(dirname) + path(pos, P_MAX_INDEX);
}
@@ -987,20 +991,7 @@
///////////////////////////////////////////////////////////////////////////////
// PFilePath
-PFilePath::PFilePath(const PString & str)
- : PString(CanonicaliseFilename(str))
-{
-}
-
-
-PFilePath::PFilePath(const char * cstr)
- : PString(CanonicaliseFilename(cstr))
-{
-}
-
-
PFilePath::PFilePath(const char * prefix, const char * dir)
- : PString()
{
if (prefix == NULL)
prefix = "tmp";
@@ -1028,60 +1019,6 @@
}
-void PFilePath::AssignContents(const PContainer & cont)
-{
- PString::AssignContents(cont);
- PString::AssignContents(CanonicaliseFilename(*this));
-}
-
-
-PString PFilePath::GetPath() const
-{
- PINDEX pos = FindLast('/');
- PAssert(pos != P_MAX_INDEX, PInvalidArrayIndex);
- return Left(pos+1);
-}
-
-
-PString PFilePath::GetTitle() const
-{
- PString fn(GetFileName());
- return fn(0, fn.FindLast('.')-1);
-}
-
-
-PString PFilePath::GetType() const
-{
- PINDEX pos = FindLast('.');
- return pos == P_MAX_INDEX || (GetLength()-pos) < 2 ? PString::Empty() : Mid(pos);
-}
-
-
-void PFilePath::SetType(const PString & type)
-{
- PINDEX dot = Find('.', FindLast('/'));
- if (dot != P_MAX_INDEX)
- Splice(type, dot, GetLength()-dot);
- else
- *this += type;
-}
-
-
-PString PFilePath::GetFileName() const
-
-{
- PINDEX pos = FindLast('/');
- return pos == P_MAX_INDEX ? static_cast<PString>(*this) : Mid(pos+1);
-}
-
-
-PDirectory PFilePath::GetDirectory() const
-{
- PINDEX pos = FindLast('/');
- return pos == P_MAX_INDEX ? PString("./") : Left(pos);
-}
-
-
PBoolean PFilePath::IsValid(char c)
{
return c != '/';
Modified: ptlib/trunk/src/ptlib/unix/svcproc.cxx
===================================================================
--- ptlib/trunk/src/ptlib/unix/svcproc.cxx 2016-08-22 16:17:34 UTC (rev 34925)
+++ ptlib/trunk/src/ptlib/unix/svcproc.cxx 2016-08-22 16:32:00 UTC (rev 34926)
@@ -405,9 +405,13 @@
if (args.HasOption('H')) {
int uid = geteuid();
- PIGNORE_RETURN(int,seteuid(getuid())); // Switch back to starting uid for next call
- SetMaxHandles(args.GetOptionString('H').AsInteger());
- PIGNORE_RETURN(int,seteuid(uid));
+ PAssertOS(seteuid(getuid()) == 0); // Switch back to starting uid for next call
+ unsigned maxHandles = args.GetOptionString('H').AsUnsigned();
+ if (SetMaxHandles(maxHandles))
+ cout << "Maximum handles set to " << maxHandles << endl;
+ else
+ cout << "Could not set maximum handles to " << maxHandles << endl;
+ PAssertOS(seteuid(uid) == 0);
}
#ifdef P_LINUX
@@ -418,7 +422,7 @@
cout << "Could not get current core file size : error = " << errno << endl;
else {
int uid = geteuid();
- PIGNORE_RETURN(int,seteuid(getuid())); // Switch back to starting uid for next call
+ PAssertOS(seteuid(getuid()) == 0); // Switch back to starting uid for next call
int v = args.GetOptionString('C').AsInteger();
rlim.rlim_cur = v;
if (setrlimit(RLIMIT_CORE, &rlim) != 0)
@@ -427,7 +431,7 @@
getrlimit(RLIMIT_CORE, &rlim);
cout << "Core file size set to " << rlim.rlim_cur << "/" << rlim.rlim_max << endl;
}
- PIGNORE_RETURN(int,seteuid(uid));
+ PAssertOS(seteuid(uid) == 0);
}
}
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|