myserver-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myserver-commit] [SCM] GNU MyServer branch, master, updated. 0_9_2-140-


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. 0_9_2-140-g31db1be
Date: Thu, 15 Apr 2010 20:58:26 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU MyServer".

The branch, master has been updated
       via  31db1be72710a7980801f6f364d17efadffe6345 (commit)
       via  cbee09074feaf3dccfb22f14c0862cb03b20e36f (commit)
       via  0570505f9b6d0642ef1fcdc8df3188f39355474c (commit)
      from  ca14a85fac9d465bc770699c98fa162168d7bd54 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------


commit 31db1be72710a7980801f6f364d17efadffe6345
Author: Giuseppe Scrivano <address@hidden>
Date:   Thu Apr 15 22:58:26 2010 +0200

    Ensure locks are not kept on exceptions

diff --git a/myserver/src/base/files_cache/cached_file_factory.cpp 
b/myserver/src/base/files_cache/cached_file_factory.cpp
index 4f408b0..2ea785e 100644
--- a/myserver/src/base/files_cache/cached_file_factory.cpp
+++ b/myserver/src/base/files_cache/cached_file_factory.cpp
@@ -68,8 +68,6 @@ CachedFileFactory::CachedFileFactory (u_long size)
  */
 void CachedFileFactory::clean ()
 {
-  mutex.lock ();
-
   HashMap<char*, CachedFileFactoryRecord*>::Iterator it = buffers.begin ();
   for (; it != buffers.end (); it++)
     {
@@ -77,8 +75,6 @@ void CachedFileFactory::clean ()
       delete (*it);
     }
   buffers.clear ();
-
-  mutex.unlock ();
   mutex.destroy ();
 }
 
@@ -146,95 +142,104 @@ File* CachedFileFactory::open (const char* filename)
 
   mutex.lock ();
 
-  ticks = getTicks ();
-  record = buffers.get (filename);
-  buffer = record ? record->buffer : 0;
+  try
+    {
 
-  used++;
+      ticks = getTicks ();
+      record = buffers.get (filename);
+      buffer = record ? record->buffer : 0;
 
-  /*!
-   * If the file on the file system has a different mtime then don't use
-   * the cache, in this way when opened instance of this file will be closed
-   * the null reference callback can be called and the file reloaded.
-   */
-  if (record)
-    {
-      if (ticks - record->lastModTimeCheck > MYSERVER_SEC (5))
-        {
-          record->invalidCache = FilesUtility::getLastModTime (filename)
-                                 != record->mtime;
-          record->lastModTimeCheck = ticks;
-        }
+      used++;
 
-      if (record->invalidCache)
+      /*!
+       * If the file on the file system has a different mtime then don't use
+       * the cache, in this way when opened instance of this file will be 
closed
+       * the null reference callback can be called and the file reloaded.
+       */
+      if (record)
         {
-          mutex.unlock ();
+          if (ticks - record->lastModTimeCheck > MYSERVER_SEC (5))
+            {
+              record->invalidCache = FilesUtility::getLastModTime (filename)
+                != record->mtime;
+              record->lastModTimeCheck = ticks;
+            }
 
-          File *file = new File ();
-          if (file->openFile (filename, File::OPEN_IF_EXISTS |
-                              File::READ))
+          if (record->invalidCache)
             {
-              delete file;
-              return NULL;
+              mutex.unlock ();
+
+              File *file = new File ();
+              if (file->openFile (filename, File::OPEN_IF_EXISTS |
+                                  File::READ))
+                {
+                  delete file;
+                  return NULL;
+                }
+              return file;
             }
-          return file;
         }
-    }
 
-  if (buffer == NULL)
-    {
-      u_long fileSize;
-      File *file = new File ();
-      if (file->openFile (filename, File::OPEN_IF_EXISTS | File::READ))
+      if (buffer == NULL)
         {
-          mutex.unlock ();
-          delete file;
-          return NULL;
-        }
-      fileSize = file->getFileSize ();
-      purgeRecords ();
-      if ((minSize != 0 && fileSize < minSize) ||
-          (maxSize != 0 && fileSize > maxSize)  ||
-          (fileSize > size - usedSize))
-        {
-          mutex.unlock ();
-          return file;
-        }
-      else
-        {
-          record = new CachedFileFactoryRecord ();
-          if (!record)
+          u_long fileSize;
+          File *file = new File ();
+          if (file->openFile (filename, File::OPEN_IF_EXISTS | File::READ))
             {
-              delete record;
-              file->close ();
-              delete file;
               mutex.unlock ();
-              return 0;
+              delete file;
+              return NULL;
             }
-
-          buffer = new CachedFileBuffer (file);
-          record->mtime = file->getLastModTime ();
-          file->close  ();
-          delete file;
-
-          if (!buffer)
+          fileSize = file->getFileSize ();
+          purgeRecords ();
+          if ((minSize != 0 && fileSize < minSize) ||
+              (maxSize != 0 && fileSize > maxSize)  ||
+              (fileSize > size - usedSize))
             {
-              delete record;
               mutex.unlock ();
-              return 0;
+              return file;
+            }
+          else
+            {
+              record = new CachedFileFactoryRecord ();
+              if (!record)
+                {
+                  delete record;
+                  file->close ();
+                  delete file;
+                  mutex.unlock ();
+                  return 0;
+                }
+
+              buffer = new CachedFileBuffer (file);
+              record->mtime = file->getLastModTime ();
+              file->close  ();
+              delete file;
+
+              if (!buffer)
+                {
+                  delete record;
+                  mutex.unlock ();
+                  return 0;
+                }
+              buffer->setFactoryToNotify (this);
+              record->created = ticks;
+              record->buffer = buffer;
+              buffers.put ((char *)filename, record);
+              usedSize += fileSize;
             }
-          buffer->setFactoryToNotify (this);
-          record->created = ticks;
-          record->buffer = buffer;
-          buffers.put ((char *)filename, record);
-          usedSize += fileSize;
         }
-    }
-  record->used++;
+      record->used++;
 
-  cachedFile = new CachedFile (buffer);
+      cachedFile = new CachedFile (buffer);
 
-  mutex.unlock ();
+      mutex.unlock ();
+    }
+  catch (...)
+    {
+      mutex.unlock ();
+      throw;
+    }
 
   return cachedFile;
 }
@@ -252,29 +257,37 @@ void CachedFileFactory::nullReferences (CachedFileBuffer* 
cfb)
   u_long ticks;
   mutex.lock ();
 
-  ticks = getTicks ();
-  record = buffers.get (cfb->getFilename ());
-  if (!record)
+  try
     {
-      mutex.unlock ();
-      return;
-    }
+      ticks = getTicks ();
+      record = buffers.get (cfb->getFilename ());
+      if (!record)
+        {
+          mutex.unlock ();
+          return;
+        }
 
-  spaceUsage = (float)usedSize / size;
-  averageUsage = (float)used * 1000.0f / (ticks - created);
-  bufferAverageUsage = (float)record->used * 1000.0f /
-    (getTicks () - record->created);
+      spaceUsage = (float)usedSize / size;
+      averageUsage = (float)used * 1000.0f / (ticks - created);
+      bufferAverageUsage = (float)record->used * 1000.0f /
+        (getTicks () - record->created);
 
-  if (((spaceUsage > 0.65f) && (bufferAverageUsage < averageUsage)
-       && ((ticks - record->created) > 10000))
-      || (spaceUsage > 0.9f)
-      || record->invalidCache)
+      if (((spaceUsage > 0.65f) && (bufferAverageUsage < averageUsage)
+           && ((ticks - record->created) > 10000))
+          || (spaceUsage > 0.9f)
+          || record->invalidCache)
+        {
+          record = buffers.remove (cfb->getFilename ());
+          if (record)
+            buffersToRemove.push_back (record);
+        }
+      mutex.unlock ();
+    }
+  catch (...)
     {
-      record = buffers.remove (cfb->getFilename ());
-      if (record)
-        buffersToRemove.push_back (record);
+      mutex.unlock ();
+      throw;
     }
-  mutex.unlock ();
 }
 
 /*!
diff --git a/myserver/src/base/home_dir/home_dir.cpp 
b/myserver/src/base/home_dir/home_dir.cpp
index 4699c00..a2e67bf 100644
--- a/myserver/src/base/home_dir/home_dir.cpp
+++ b/myserver/src/base/home_dir/home_dir.cpp
@@ -109,9 +109,16 @@ int HomeDir::load ()
   int ret;
   loadMutex.lock ();
 
-  ret = loadImpl ();
-
-  loadMutex.unlock ();
+  try
+    {
+      ret = loadImpl ();
+      loadMutex.unlock ();
+    }
+  catch (...)
+    {
+      loadMutex.unlock ();
+      throw;
+    }
   return ret;
 }
 
diff --git a/myserver/src/base/process/process_server_manager.cpp 
b/myserver/src/base/process/process_server_manager.cpp
index 9e55079..b7d49b2 100644
--- a/myserver/src/base/process/process_server_manager.cpp
+++ b/myserver/src/base/process/process_server_manager.cpp
@@ -145,10 +145,18 @@ void ProcessServerManager::load ()
 ProcessServerManager::ServerDomain*
 ProcessServerManager::getDomain (const char* name)
 {
-  ServerDomain* ret;
+  ServerDomain* ret = NULL;
   mutex.lock ();
-  ret = domains.get (name);
-  mutex.unlock ();
+  try
+    {
+      ret = domains.get (name);
+      mutex.unlock ();
+    }
+  catch (...)
+    {
+      mutex.unlock ();
+      throw;
+    }
   return ret;
 }
 
@@ -159,19 +167,26 @@ ProcessServerManager::getDomain (const char* name)
 ProcessServerManager::ServerDomain*
 ProcessServerManager::createDomain (const char* name)
 {
-  ServerDomain* ret;
+  ServerDomain* ret = NULL;
 
   mutex.lock ();
 
-  ret = domains.get (name);
-  if (!ret)
-  {
-    string str (name);
-    ret = new ServerDomain ();
-    domains.put (str, ret);
-  }
-
-  mutex.unlock ();
+  try
+    {
+      ret = domains.get (name);
+      if (!ret)
+        {
+          string str (name);
+          ret = new ServerDomain ();
+          domains.put (str, ret);
+        }
+      mutex.unlock ();
+    }
+  catch (...)
+    {
+      mutex.unlock ();
+      throw;
+    }
 
   return ret;
 }
@@ -184,37 +199,44 @@ void ProcessServerManager::clear ()
   HashMap<string, ServerDomain*>::Iterator it;
 
   mutex.lock ();
-
-  it = domains.begin ();
-
-  for (;it != domains.end (); it++)
+  try
     {
-      ServerDomain *sd = *it;
-      HashMap<string, vector<Server*>*>::Iterator server = sd->servers.begin 
();
+      it = domains.begin ();
 
-      for (; server != sd->servers.end (); server++)
+      for (;it != domains.end (); it++)
         {
-          for (vector<Server*>::iterator it = (*server)->begin ();
-               it != (*server)->end ();
-               it++)
-            {
-              Server *s = *it;
+          ServerDomain *sd = *it;
+          HashMap<string, vector<Server*>*>::Iterator server = 
sd->servers.begin ();
 
-              if (s->isLocal)
-                nServers--;
-
-              if (sd->clear)
-                sd->clear (s);
-
-              s->terminate ();
-              delete s;
+          for (; server != sd->servers.end (); server++)
+            {
+              for (vector<Server*>::iterator it = (*server)->begin ();
+                   it != (*server)->end ();
+                   it++)
+                {
+                  Server *s = *it;
+
+                  if (s->isLocal)
+                    nServers--;
+
+                  if (sd->clear)
+                    sd->clear (s);
+
+                  s->terminate ();
+                  delete s;
+                }
+              delete (*server);
             }
-          delete (*server);
+          delete (*it);
         }
-      delete (*it);
-  }
-  domains.clear ();
-  mutex.unlock ();
+      domains.clear ();
+      mutex.unlock ();
+    }
+  catch (...)
+    {
+      mutex.unlock ();
+      throw;
+    }
 }
 
 /*!
@@ -226,37 +248,45 @@ void ProcessServerManager::clear ()
 ProcessServerManager::Server*
 ProcessServerManager::getServer (const char* domain, const char* name, int 
seed)
 {
-  ServerDomain* sd;
+  ServerDomain* sd = NULL;
   Server* s = NULL;
 
   mutex.lock ();
-  sd = domains.get (domain);
+  try
+    {
+      sd = domains.get (domain);
+      if (sd)
+        {
+          vector<Server*> *slist = sd->servers.get (name);
+          if (slist)
+            s = slist->at (seed % slist->size ());
+        }
+
+      if (s && s->isLocal && !s->process.isProcessAlive ())
+        {
+          s->socket.close ();
+          s->process.terminateProcess ();
+          if (!s->path.length ())
+            s->path.assign (name);
+
+          s->port = 0;
+
+          if (runServer (s, s->path.c_str (), s->port))
+            {
+              sd->servers.remove (name);
+              delete s;
+              s = 0;
+            }
+        }
 
-  if (sd)
+      mutex.unlock ();
+    }
+  catch (...)
     {
-      vector<Server*> *slist = sd->servers.get (name);
-      if (slist)
-        s = slist->at (seed % slist->size ());
+      mutex.unlock ();
+      throw;
     }
 
-  if (s && s->isLocal && !s->process.isProcessAlive ())
-  {
-    s->socket.close ();
-    s->process.terminateProcess ();
-    if (!s->path.length ())
-      s->path.assign (name);
-
-    s->port = 0;
-
-    if (runServer (s, s->path.c_str (), s->port))
-      {
-        sd->servers.remove (name);
-        delete s;
-        s = 0;
-      }
-  }
-
-  mutex.unlock ();
   return s;
 }
 
@@ -273,17 +303,25 @@ void ProcessServerManager::addServer 
(ProcessServerManager::Server* server,
   string strName (name);
 
   mutex.lock ();
-  vector<Server*>* slist = sd->servers.get (strName);
-
-  if (slist == NULL)
+  try
     {
-      slist = new vector<Server*> ();
-      sd->servers.put (strName, slist);
-    }
+      vector<Server*>* slist = sd->servers.get (strName);
+
+      if (slist == NULL)
+        {
+          slist = new vector<Server*> ();
+          sd->servers.put (strName, slist);
+        }
 
-  slist->push_back (server);
+      slist->push_back (server);
 
-  mutex.unlock ();
+      mutex.unlock ();
+    }
+  catch (...)
+    {
+      mutex.unlock ();
+      throw;
+    }
 }
 
 /*!
@@ -317,36 +355,42 @@ void ProcessServerManager::removeDomain (const char* 
domain)
   HashMap<string, Server*>::Iterator server;
 
   mutex.lock ();
-
-  sd = getDomain (domain);
-
-  if (sd)
+  try
     {
-      HashMap<string, vector<Server*>*>::Iterator server = sd->servers.begin 
();
-
-      for (; server != sd->servers.end (); server++)
+      sd = getDomain (domain);
+      if (sd)
         {
-          for (vector<Server*>::iterator it = (*server)->begin ();
-               it != (*server)->end ();
-               it++)
+          HashMap<string, vector<Server*>*>::Iterator server
+            = sd->servers.begin ();
+          for (; server != sd->servers.end (); server++)
             {
-              Server *s = *it;
-
-              if (s->isLocal)
-                nServers--;
-
-              if (sd->clear)
-                sd->clear (s);
-
-              s->terminate ();
-              delete s;
+              for (vector<Server*>::iterator it = (*server)->begin ();
+                   it != (*server)->end ();
+                   it++)
+                {
+                  Server *s = *it;
+
+                  if (s->isLocal)
+                    nServers--;
+
+                  if (sd->clear)
+                    sd->clear (s);
+
+                  s->terminate ();
+                  delete s;
+                }
+              delete (*server);
             }
-          delete (*server);
+          delete sd;
         }
-      delete sd;
-    }
 
-  mutex.unlock ();
+      mutex.unlock ();
+    }
+  catch (...)
+    {
+      mutex.unlock ();
+      throw;
+    }
 }
 
 /*!
@@ -376,10 +420,10 @@ ProcessServerManager::runAndAddServer (const char 
*domain, const char *path,
   Server* server = new Server;
 
   if (runServer (server, path, port, chroot, uid, gid))
-  {
-    delete server;
-    return 0;
-  }
+    {
+      delete server;
+      return 0;
+    }
   addServer (server, domain, path);
   return server;
 }
diff --git a/myserver/src/base/safetime/safetime.cpp 
b/myserver/src/base/safetime/safetime.cpp
index e4ed781..73884f2 100644
--- a/myserver/src/base/safetime/safetime.cpp
+++ b/myserver/src/base/safetime/safetime.cpp
@@ -73,8 +73,16 @@ struct tm *myserver_localtime (const time_t *timep, tm* res)
 #else
 
   mutex.lock ();
-  memcpy (res, localtime (timep), sizeof (tm));
-  mutex.unlock ();
+  try
+    {
+      memcpy (res, localtime (timep), sizeof (tm));
+      mutex.unlock ();
+    }
+  catch (...)
+    {
+      mutex.unlock ();
+      throw;
+    }
 
   return res;
 #endif
diff --git a/myserver/src/connections_scheduler/connections_scheduler.cpp 
b/myserver/src/connections_scheduler/connections_scheduler.cpp
index 2d9c315..0fbb115 100644
--- a/myserver/src/connections_scheduler/connections_scheduler.cpp
+++ b/myserver/src/connections_scheduler/connections_scheduler.cpp
@@ -197,15 +197,8 @@ static void listenerHandler (int fd, short event, void 
*arg)
             }
           while (clientSock);
         }
-      catch (std::exception & e)
-        {
-          s->server->log (MYSERVER_LOG_MSG_ERROR, _("Error listening on socket 
%s"),
-                          e.what ());
-          throw;
-        }
       catch (...)
         {
-          throw;
         }
     }
 
diff --git a/myserver/src/connections_scheduler/listen_threads.cpp 
b/myserver/src/connections_scheduler/listen_threads.cpp
index 4f94a4b..152d75b 100644
--- a/myserver/src/connections_scheduler/listen_threads.cpp
+++ b/myserver/src/connections_scheduler/listen_threads.cpp
@@ -439,10 +439,17 @@ int ListenThreads::terminate ()
             continue;
 
           serverSocket->shutdown (SHUT_RDWR);
-          do
+          for (;;)
             {
-              err = serverSocket->recv (buffer, 256, 0);
-            }while (err != -1);
+              try
+                {
+                  err = serverSocket->recv (buffer, 256, 0);
+                }
+              catch (...)
+                {
+                  break;
+                }
+            }
 
           serverSocket->close ();
           delete serverSocket;
diff --git a/myserver/src/http_handler/http_file/http_file.cpp 
b/myserver/src/http_handler/http_file/http_file.cpp
index 6600076..c23a060 100644
--- a/myserver/src/http_handler/http_file/http_file.cpp
+++ b/myserver/src/http_handler/http_file/http_file.cpp
@@ -55,9 +55,18 @@ int HttpFile::putFile (HttpThreadContext* td, string& 
filename)
     if (FilesUtility::nodeExists (td->filenamePath.c_str ()))
       {
         File file;
-        if (file.openFile (td->filenamePath.c_str (), File::OPEN_IF_EXISTS
-                           | File::WRITE))
-          return td->http->raiseHTTPError (500);
+        try
+          {
+            file.openFile (td->filenamePath.c_str (), File::OPEN_IF_EXISTS
+                           | File::WRITE);
+          }
+        catch (exception & e)
+          {
+            td->connection->host->warningsLogWrite
+              (_("HttpFile: error accessing file %s : %e"),
+               td->filenamePath.c_str (), &e);
+            return td->http->raiseHTTPError (500);
+          }
 
         file.seek (firstByte);
 
@@ -97,10 +106,18 @@ int HttpFile::putFile (HttpThreadContext* td, string& 
filename)
       {
         /* The file doesn't exist.  */
         File file;
-        if (file.openFile (td->filenamePath.c_str (),
-                           File::FILE_CREATE_ALWAYS
-                           | File::WRITE))
-          return td->http->raiseHTTPError (500);
+        try
+          {
+            file.openFile (td->filenamePath.c_str (), File::FILE_CREATE_ALWAYS
+                           | File::WRITE);
+          }
+        catch (exception & e)
+          {
+            td->connection->host->warningsLogWrite
+              (_("HttpFile: error accessing file %s : %e"),
+               td->filenamePath.c_str (), &e);
+            return td->http->raiseHTTPError (500);
+          }
 
         for (;;)
           {
@@ -248,7 +265,18 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
           !ifModifiedSince->value->compare (tmpTime))
         return td->http->sendHTTPNonModified ();
 
-      file = Server::getInstance ()->getCachedFiles ()->open (filenamePath);
+      try
+        {
+          file = Server::getInstance ()->getCachedFiles ()->open 
(filenamePath);
+        }
+      catch (exception & e)
+        {
+          td->connection->host->warningsLogWrite
+            (_("HttpFile: error accessing file %s : %e"),
+             td->filenamePath.c_str (), &e);
+          return td->http->raiseHTTPError (500);
+        }
+
       if (!file)
         return td->http->raiseHTTPError (500);
 
diff --git a/myserver/src/log/stream/log_stream.cpp 
b/myserver/src/log/stream/log_stream.cpp
index e85eb41..5f11eb6 100644
--- a/myserver/src/log/stream/log_stream.cpp
+++ b/myserver/src/log/stream/log_stream.cpp
@@ -49,17 +49,22 @@ LogStream::resetFilters ()
 int
 LogStream::log (const string & message)
 {
-  mutex->lock ();
   int success = 0;
-  if (needToCycle ())
+  mutex->lock ();
+  try
     {
-      success = doCycle () || write (message);
+      if (needToCycle ())
+        success = doCycle () || write (message);
+      else
+        success = write (message);
+
+      mutex->unlock ();
     }
-  else
+  catch (...)
     {
-      success = write (message);
+      mutex->unlock ();
+      throw;
     }
-  mutex->unlock ();
   return success;
 }
 
@@ -111,14 +116,23 @@ LogStream::getFiltersChain ()
 int
 LogStream::close ()
 {
+  int success = 0;
   mutex->lock ();
-  int success = 1;
-  isOpened = fc->flush (&nbw) || out->close ();
-  if (!isOpened)
+  try
     {
-      success = 0;
+      success = 1;
+      isOpened = fc->flush (&nbw) || out->close ();
+      if (! isOpened)
+        success = 0;
+
+      mutex->unlock ();
     }
-  mutex->unlock ();
+  catch (...)
+    {
+      mutex->unlock ();
+      throw;
+    }
+
   return success;
 }
 
@@ -156,18 +170,42 @@ LogStream::update (LogStreamEvent evt, void* message, 
void* reply)
 int
 LogStream::addFilter (Filter* filter)
 {
+  int success = 0;
   mutex->lock ();
-  int success = fc->addFilter (filter, &nbw);
+  try
+  {
+    success = fc->addFilter (filter, &nbw);
+    mutex->unlock ();
+  }
+  catch (...)
+    {
+      mutex->unlock ();
+      throw;
+    }
+
   mutex->unlock ();
+
   return success;
 }
 
 int
 LogStream::removeFilter (Filter* filter)
 {
+  int success = 0;
   mutex->lock ();
-  int success = fc->removeFilter (filter);
+  try
+  {
+    success = fc->removeFilter (filter);
+    mutex->unlock ();
+  }
+  catch (...)
+    {
+      mutex->unlock ();
+      throw;
+    }
+
   mutex->unlock ();
+
   return success;
 }
 
diff --git a/myserver/src/protocol/ftp/ftp.cpp 
b/myserver/src/protocol/ftp/ftp.cpp
index 016f15b..eb0d55e 100644
--- a/myserver/src/protocol/ftp/ftp.cpp
+++ b/myserver/src/protocol/ftp/ftp.cpp
@@ -111,13 +111,6 @@ FtpuserData::FtpuserData ()
 
 bool FtpuserData::allowdelete (bool wait)
 {
-  if (wait)
-    {
-      /* Wait for data connection to finish.  */
-      m_DataConnBusy.lock ();
-      m_DataConnBusy.unlock ();
-
-    }
   if (m_pDataConnection != NULL)
     return !m_pDataConnection->isScheduled ();
   else
@@ -633,6 +626,7 @@ void Ftp::retrstor (bool bretr, bool bappend, const 
std::string & sPath)
 static
 DEFINE_THREAD (SendAsciiFile, pParam)
 {
+  File *file = NULL;
   DataConnectionWorkerThreadData *pWt =
     reinterpret_cast < DataConnectionWorkerThreadData * >(pParam);
   if (pWt == NULL)
@@ -670,27 +664,11 @@ DEFINE_THREAD (SendAsciiFile, pParam)
     }
 
   pFtpuserData->m_DataConnBusy.lock ();
-
-  if (pWt->m_pFtp == NULL)
+  try
     {
-      pFtpuserData->closeDataConnection ();
-      pFtpuserData->m_DataConnBusy.unlock ();
-      delete pWt;
-#ifdef WIN32
-      return 0;
-#elif HAVE_PTHREAD
-      return (void *) 0;
-#endif
-    }
 
-  if (pFtpuserData->m_nFtpstate == FtpuserData::DATA_CONNECTION_UP)
-    ftpReply (pConnection, 125);
-  else
-    {
-      ftpReply (pConnection, 150);
-      if (pWt->m_pFtp->OpenDataConnection () == 0)
+      if (pWt->m_pFtp == NULL)
         {
-          ftpReply (pConnection, 425);
           pFtpuserData->closeDataConnection ();
           pFtpuserData->m_DataConnBusy.unlock ();
           delete pWt;
@@ -700,24 +678,40 @@ DEFINE_THREAD (SendAsciiFile, pParam)
           return (void *) 0;
 #endif
         }
-    }
 
-  if (pFtpuserData->m_pDataConnection == NULL ||
-      pFtpuserData->m_pDataConnection->socket == NULL)
-    {
-      ftpReply (pConnection, 451);
-      pFtpuserData->closeDataConnection ();
-      pFtpuserData->m_DataConnBusy.unlock ();
-      delete pWt;
+      if (pFtpuserData->m_nFtpstate == FtpuserData::DATA_CONNECTION_UP)
+        ftpReply (pConnection, 125);
+      else
+        {
+          ftpReply (pConnection, 150);
+          if (pWt->m_pFtp->OpenDataConnection () == 0)
+            {
+              ftpReply (pConnection, 425);
+              pFtpuserData->closeDataConnection ();
+              pFtpuserData->m_DataConnBusy.unlock ();
+              delete pWt;
 #ifdef WIN32
-      return 0;
+              return 0;
 #elif HAVE_PTHREAD
-      return (void *) 0;
+              return (void *) 0;
 #endif
-    }
-  File *file = NULL;
-  try
-    {
+            }
+        }
+
+      if (pFtpuserData->m_pDataConnection == NULL ||
+          pFtpuserData->m_pDataConnection->socket == NULL)
+        {
+          ftpReply (pConnection, 451);
+          pFtpuserData->closeDataConnection ();
+          pFtpuserData->m_DataConnBusy.unlock ();
+          delete pWt;
+#ifdef WIN32
+          return 0;
+#elif HAVE_PTHREAD
+          return (void *) 0;
+#endif
+        }
+
       file =
         Server::getInstance ()->getCachedFiles ()->open (pWt->m_sFilePath.
                                                          c_str ());
@@ -841,21 +835,23 @@ DEFINE_THREAD (SendAsciiFile, pParam)
         }
       file->close ();
       delete file;
+
+      pFtpuserData->m_sCurrentFileName = "";
+      pFtpuserData->m_nFileSize = 0;
+      pFtpuserData->m_nBytesSent = 0;
+      pFtpuserData->m_nrestartOffset = 0;
+      ftpReply (pConnection, 226);
+      pFtpuserData->closeDataConnection ();
+      pFtpuserData->m_DataConnBusy.unlock ();
     }
   catch (bad_alloc & ba)
     {
       if (file != NULL)
         file->close ();
       delete file;
+      pFtpuserData->m_DataConnBusy.unlock ();
     }
 
-  pFtpuserData->m_sCurrentFileName = "";
-  pFtpuserData->m_nFileSize = 0;
-  pFtpuserData->m_nBytesSent = 0;
-  pFtpuserData->m_nrestartOffset = 0;
-  ftpReply (pConnection, 226);
-  pFtpuserData->closeDataConnection ();
-  pFtpuserData->m_DataConnBusy.unlock ();
   delete pWt;
 #ifdef WIN32
   return 1;
@@ -906,27 +902,11 @@ DEFINE_THREAD (SendImageFile, pParam)
     }
 
   pFtpuserData->m_DataConnBusy.lock ();
-
-  if (pWt->m_pFtp == NULL)
-    {
-      pFtpuserData->closeDataConnection ();
-      pFtpuserData->m_DataConnBusy.unlock ();
-      delete pWt;
-#ifdef WIN32
-      return 0;
-#elif HAVE_PTHREAD
-      return (void *) 0;
-#endif
-    }
-
-  if (pFtpuserData->m_nFtpstate == FtpuserData::DATA_CONNECTION_UP)
-    ftpReply (pConnection, 125);
-  else
+  File *file = NULL;
+  try
     {
-      ftpReply (pConnection, 150);
-      if (pWt->m_pFtp->OpenDataConnection () == 0)
+      if (pWt->m_pFtp == NULL)
         {
-          ftpReply (pConnection, 425);
           pFtpuserData->closeDataConnection ();
           pFtpuserData->m_DataConnBusy.unlock ();
           delete pWt;
@@ -936,25 +916,40 @@ DEFINE_THREAD (SendImageFile, pParam)
           return (void *) 0;
 #endif
         }
-    }
 
-  if (pFtpuserData->m_pDataConnection == NULL ||
-      pFtpuserData->m_pDataConnection->socket == NULL)
-    {
-      ftpReply (pConnection, 451);
-      pFtpuserData->closeDataConnection ();
-      pFtpuserData->m_DataConnBusy.unlock ();
-      delete pWt;
+      if (pFtpuserData->m_nFtpstate == FtpuserData::DATA_CONNECTION_UP)
+        ftpReply (pConnection, 125);
+      else
+        {
+          ftpReply (pConnection, 150);
+          if (pWt->m_pFtp->OpenDataConnection () == 0)
+            {
+              ftpReply (pConnection, 425);
+              pFtpuserData->closeDataConnection ();
+              pFtpuserData->m_DataConnBusy.unlock ();
+              delete pWt;
 #ifdef WIN32
-      return 0;
+              return 0;
 #elif HAVE_PTHREAD
-      return (void *) 0;
+              return (void *) 0;
 #endif
-    }
+            }
+        }
+
+      if (pFtpuserData->m_pDataConnection == NULL ||
+          pFtpuserData->m_pDataConnection->socket == NULL)
+        {
+          ftpReply (pConnection, 451);
+          pFtpuserData->closeDataConnection ();
+          pFtpuserData->m_DataConnBusy.unlock ();
+          delete pWt;
+#ifdef WIN32
+          return 0;
+#elif HAVE_PTHREAD
+          return (void *) 0;
+#endif
+        }
 
-  File *file = NULL;
-  try
-    {
       file =
         Server::getInstance ()->getCachedFiles ()->open (pWt->m_sFilePath.
                                                          c_str ());
@@ -1033,6 +1028,7 @@ DEFINE_THREAD (SendImageFile, pParam)
       if (file != NULL)
         file->close ();
       delete file;
+      pFtpuserData->m_DataConnBusy.unlock ();
     }
 
   pFtpuserData->m_sCurrentFileName = "";
@@ -1042,6 +1038,7 @@ DEFINE_THREAD (SendImageFile, pParam)
   ftpReply (pConnection, 226);
   pFtpuserData->closeDataConnection ();
   pFtpuserData->m_DataConnBusy.unlock ();
+
   delete pWt;
 #ifdef WIN32
   return 1;



commit cbee09074feaf3dccfb22f14c0862cb03b20e36f
Author: Giuseppe Scrivano <address@hidden>
Date:   Thu Apr 15 21:23:42 2010 +0200

    The log manager uses %e as formatter for exceptions

diff --git a/myserver/src/log/log_manager.cpp b/myserver/src/log/log_manager.cpp
index eb142b8..61c714e 100644
--- a/myserver/src/log/log_manager.cpp
+++ b/myserver/src/log/log_manager.cpp
@@ -22,6 +22,8 @@
 #include <include/log/log_manager.h>
 #include <include/server/server.h>
 
+#include <include/base/exceptions/exceptions.h>
+
 #include <cstdarg>
 
 /*!
@@ -667,11 +669,11 @@ LogManager::log (const void* owner, const string & type, 
LoggingLevel level,
               switch (*fmt)
                 {
                 case 's':
-                  oss << static_cast<const char*> (va_arg (args, const char*));
+                  oss << static_cast<const char *> (va_arg (args, const char 
*));
                   break;
 
                 case 'S':
-                  oss << static_cast<string*> (va_arg (args, string*));
+                  oss << static_cast<string *> (va_arg (args, string *));
                   break;
 
                 case '%':
@@ -682,6 +684,11 @@ LogManager::log (const void* owner, const string & type, 
LoggingLevel level,
                   oss << static_cast<int> (va_arg (args, int));
                   break;
 
+                case 'e':
+                  oss << (static_cast<exception *> (va_arg (args,
+                                                     exception *)))->what ();
+                  break;
+
                 default:
                   mutex->unlock ();
                   return 1;



commit 0570505f9b6d0642ef1fcdc8df3188f39355474c
Author: Giuseppe Scrivano <address@hidden>
Date:   Thu Apr 15 20:21:24 2010 +0200

    Test if errno is read correctly

diff --git a/myserver/tests/test_exceptions.cpp 
b/myserver/tests/test_exceptions.cpp
index 4efff3c..a6ad610 100644
--- a/myserver/tests/test_exceptions.cpp
+++ b/myserver/tests/test_exceptions.cpp
@@ -31,8 +31,9 @@ using namespace std;
 class TestExceptions : public CppUnit::TestFixture
 {
   CPPUNIT_TEST_SUITE ( TestExceptions );
-  CPPUNIT_TEST (testCatch1);
-  CPPUNIT_TEST (testCatch2);
+  CPPUNIT_TEST (testWrongCloseDir);
+  CPPUNIT_TEST (testWrongCwd);
+  CPPUNIT_TEST (testErrno);
   CPPUNIT_TEST_SUITE_END ();
 
   DIR *foodir;
@@ -47,12 +48,12 @@ public:
 
   void tearDown () {}
 
-  void testCatch1 ()
+  void testWrongCloseDir ()
   {
     try
       {
         checked::closedir (foodir);
-        CPPUNIT_FAIL ("The exception in testCatch1 wasn't thrown or caught");
+        CPPUNIT_FAIL ("The exception in testWrongCloseDir wasn't thrown or 
caught");
       }
     catch (ArgumentListException& e)
       {
@@ -60,16 +61,32 @@ public:
       }
     catch (...)
       {
-        CPPUNIT_FAIL ("The wrong exception in testCatch1 was thrown");
+        CPPUNIT_FAIL ("The wrong exception in testWrongCloseDir was thrown");
       }
   }
 
-  void testCatch2 ()
+  void testErrno ()
+  {
+    bool success = false;
+    errno = EINVAL;
+    try
+      {
+        checked::raiseException ();
+      }
+    catch (AbstractServerException & ase)
+      {
+        success = ase.getErrno () == EINVAL;
+      }
+
+    CPPUNIT_ASSERT (success);
+  }
+
+  void testWrongCwd ()
   {
     try
       {
         char *p = checked::getcwd (buf, 1);
-        CPPUNIT_FAIL ("The exception in testCatch2 wasn't thrown or caught");
+        CPPUNIT_FAIL ("The exception in testWrongCwd wasn't thrown or caught");
       }
     catch (OverflowException& e)
       {
@@ -77,7 +94,7 @@ public:
       }
     catch (...)
       {
-        CPPUNIT_FAIL ("The wrong exception in testCatch2 was thrown");
+        CPPUNIT_FAIL ("The wrong exception in testWrongCwd was thrown");
       }
   }
 };

-----------------------------------------------------------------------

Summary of changes:
 .../src/base/files_cache/cached_file_factory.cpp   |  197 +++++++++--------
 myserver/src/base/home_dir/home_dir.cpp            |   13 +-
 .../src/base/process/process_server_manager.cpp    |  238 ++++++++++++--------
 myserver/src/base/safetime/safetime.cpp            |   12 +-
 .../connections_scheduler.cpp                      |    7 -
 .../src/connections_scheduler/listen_threads.cpp   |   13 +-
 myserver/src/http_handler/http_file/http_file.cpp  |   44 +++-
 myserver/src/log/log_manager.cpp                   |   11 +-
 myserver/src/log/stream/log_stream.cpp             |   64 +++++-
 myserver/src/protocol/ftp/ftp.cpp                  |  155 +++++++-------
 myserver/tests/test_exceptions.cpp                 |   33 ++-
 11 files changed, 473 insertions(+), 314 deletions(-)


hooks/post-receive
-- 
GNU MyServer




reply via email to

[Prev in Thread] Current Thread [Next in Thread]