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. v0.9.2-266


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. v0.9.2-266-g019962b
Date: Wed, 23 Jun 2010 10:37:38 +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  019962be8f4376abffeb724b242b4f6e31f0b8a1 (commit)
      from  a125bce0bbb9a4c98a729ae53386e46be1e56423 (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 019962be8f4376abffeb724b242b4f6e31f0b8a1
Author: Giuseppe Scrivano <address@hidden>
Date:   Wed Jun 23 12:31:25 2010 +0200

    Use `mkostemp' to open temporary files.
    
    Now FilesUtility::temporaryFileName generates a mask for `mkstemp' hence 
remove
    the members `inputDataPath' and 'outputDataPath' from struct 
HttpThreadContext,
    they are path masks not real file names.

diff --git a/myserver/bootstrap.conf b/myserver/bootstrap.conf
index 3bb098f..5b2f306 100644
--- a/myserver/bootstrap.conf
+++ b/myserver/bootstrap.conf
@@ -47,6 +47,7 @@ git-version-gen
 ioctl
 listen
 malloc
+mkostemp
 mktime
 nproc
 open
diff --git a/myserver/include/base/file/file.h 
b/myserver/include/base/file/file.h
index fe38dfd..5a8b3a9 100644
--- a/myserver/include/base/file/file.h
+++ b/myserver/include/base/file/file.h
@@ -52,7 +52,7 @@ public:
 
   virtual Handle getHandle ();
   virtual int setHandle (Handle);
-  virtual int writeToFile (const char *, u_long , u_long *);
+  virtual int writeToFile (const char *, u_long, u_long *);
   virtual int createTemporaryFile (const char *, bool unlink = true);
 
   virtual int openFile (const char *, u_long, mode_t mask = 00700);
diff --git a/myserver/include/base/files_cache/cached_file.h 
b/myserver/include/base/files_cache/cached_file.h
index bf5a189..bf6b1af 100644
--- a/myserver/include/base/files_cache/cached_file.h
+++ b/myserver/include/base/files_cache/cached_file.h
@@ -35,7 +35,7 @@ public:
   virtual int setHandle (Handle);
   virtual int read (char* ,u_long ,u_long* );
   virtual int writeToFile (const char* ,u_long ,u_long* );
-  virtual int createTemporaryFile (const char* );
+  virtual int createTemporaryFile (const char *, bool unlink = true);
 
   virtual int openFile (const char*, u_long );
   virtual int openFile (string const &file, u_long opt)
diff --git a/myserver/include/protocol/http/http_thread_context.h 
b/myserver/include/protocol/http/http_thread_context.h
index 25bf3b2..1f4788f 100644
--- a/myserver/include/protocol/http/http_thread_context.h
+++ b/myserver/include/protocol/http/http_thread_context.h
@@ -78,8 +78,6 @@ struct HttpThreadContext
   string scriptPath;
   string scriptDir;
   string scriptFile;
-  string inputDataPath;
-  string outputDataPath;
   string vhostDir;
   string vhostSys;
   HashMap<string,string*> other;
diff --git a/myserver/src/base/file/file.cpp b/myserver/src/base/file/file.cpp
index 789e01d..6244655 100644
--- a/myserver/src/base/file/file.cpp
+++ b/myserver/src/base/file/file.cpp
@@ -47,6 +47,7 @@
 
 #include <string>
 #include <sstream>
+#include <memory>
 
 using namespace std;
 
@@ -129,7 +130,8 @@ void File::fstat (struct stat *fstat)
 /*!
   Open (or create if not exists) a file, but must explicitly use read and/or
   write flags and open flag.
-  \param nfilename Filename to open.
+  \param nfilename Filename to open.    If TEMPORARY or TEMPORARY_DELAYED is
+  used, then this parameter specifies the mask to use for mkostemp(3).
   \param opt Specify how open the file.
   \param mask Creation mode when a new file is created.
   openFile returns 0 if the call was successful, any other value on errors.
@@ -138,8 +140,6 @@ int File::openFile (const char* nfilename, u_long opt, 
mode_t mask)
 {
   int flags;
 
-  filename.assign (nfilename);
-
   if ((opt & File::READ) && (opt & File::WRITE))
     flags = O_RDWR;
   else if (opt & File::READ)
@@ -153,18 +153,32 @@ int File::openFile (const char* nfilename, u_long opt, 
mode_t mask)
   if (opt & File::APPEND)
     flags |= O_APPEND;
 
-  handle = gnulib::open (filename.c_str (), flags);
-  if (handle < 0)
+
+  if (opt & (File::TEMPORARY_DELAYED | File::TEMPORARY))
     {
-      if (! ((errno == ENOENT) && (opt & File::FILE_OPEN_ALWAYS)))
+      auto_ptr <char> templatefn (checked::strdup (nfilename));
+      handle = mkostemp (templatefn.get (), flags);
+      if (handle < 0)
         checked::raiseException ();
 
-      flags |= O_CREAT;
-      handle = checked::open (filename.c_str (), flags, S_IRUSR | S_IWUSR);
+      setFilename (templatefn.get ());
+
+      if (opt & File::TEMPORARY)
+        checked::unlink (getFilename ());
     }
+  else
+    {
+      setFilename (nfilename);
+      handle = gnulib::open (filename.c_str (), flags);
+      if (handle < 0)
+        {
+          if (! ((errno == ENOENT) && (opt & File::FILE_OPEN_ALWAYS)))
+            checked::raiseException ();
 
-  if (opt & File::TEMPORARY)
-    checked::unlink (filename.c_str ());
+          flags |= O_CREAT;
+          handle = checked::open (filename.c_str (), flags, S_IRUSR | S_IWUSR);
+        }
+    }
 
   this->opt = opt;
   return handle < 0;
@@ -244,8 +258,8 @@ int File::close ()
   if (handle != -1)
     {
       if (opt & File::TEMPORARY_DELAYED)
-        checked::unlink (filename.c_str ());
-      ret = checked::fsync (handle);
+        gnulib::unlink (filename.c_str ());
+
       ret |= checked::close (handle);
     }
 
diff --git a/myserver/src/base/file/files_utility.cpp 
b/myserver/src/base/file/files_utility.cpp
index fac0ddf..802a50d 100644
--- a/myserver/src/base/file/files_utility.cpp
+++ b/myserver/src/base/file/files_utility.cpp
@@ -673,20 +673,15 @@ void FilesUtility::resetTmpPath ()
 
 
 /*!
-  Create an unique temporary file name.  This function doesn't create
-  or open the file but generates only its name.
+  Create an unique temporary file name mask that can be used by mkstemp.
   \param tid Caller thread id.
   \param out Output string.
  */
 void FilesUtility::temporaryFileName (u_long tid, string &out)
 {
-  ostringstream stream;
-  static u_long counter = 1;
-  counter++;
-
   if (tmpPath.length () == 0)
     tmpPath.assign (getdefaultwd (0, 0));
 
-  stream << tmpPath << "/myserver_" << counter  << "_" << tid << ".tmp";
-  out.assign (stream.str ());
+  out.assign (tmpPath);
+  out.append ("/myserver_XXXXXX");
 }
diff --git a/myserver/src/base/files_cache/cached_file.cpp 
b/myserver/src/base/files_cache/cached_file.cpp
index d03b56b..1291e4f 100644
--- a/myserver/src/base/files_cache/cached_file.cpp
+++ b/myserver/src/base/files_cache/cached_file.cpp
@@ -136,9 +136,9 @@ int CachedFile::read (char* buffer, u_long buffersize, 
u_long* nbr)
 /*!
   A CachedFile can't be temporary.
   Create a temporary file.
-  \param filename The new temporary file name.
+  \see File#createTemporaryFile.
  */
-int CachedFile::createTemporaryFile (const char* filename)
+int CachedFile::createTemporaryFile (const char *, bool)
 {
   return -1;
 }
diff --git a/myserver/src/http_handler/cgi/cgi.cpp 
b/myserver/src/http_handler/cgi/cgi.cpp
index d94a15e..d355a21 100644
--- a/myserver/src/http_handler/cgi/cgi.cpp
+++ b/myserver/src/http_handler/cgi/cgi.cpp
@@ -76,7 +76,6 @@ int Cgi::send (HttpThreadContext* td, const char* scriptpath,
     to get other params like in a POST request.
   */
   Pipe stdOutFile;
-  File stdInFile;
   int len = strlen (cgipath);
   int i;
 
@@ -213,10 +212,6 @@ int Cgi::send (HttpThreadContext* td, const char* 
scriptpath,
       */
       stdOutFile.create ();
 
-      /* Open the stdin file for the new CGI process.  */
-      stdInFile.openFile (td->inputDataPath,
-                          File::READ | File::FILE_OPEN_ALWAYS);
-
       /*
         Build the environment string used by the CGI process.
         Use the td->auxiliaryBuffer to build the environment string.
@@ -241,12 +236,11 @@ int Cgi::send (HttpThreadContext* td, const char* 
scriptpath,
                                                     MYSERVER_SERVER_CONF, ""));
 
       spi.stdError = (FileHandle) stdOutFile.getWriteHandle ();
-      spi.stdIn = (FileHandle) stdInFile.getHandle ();
+      spi.stdIn = (FileHandle) td->inputData.getHandle ();
       spi.stdOut = (FileHandle) stdOutFile.getWriteHandle ();
       spi.envString = td->auxiliaryBuffer->getBuffer ();
 
       if (spi.stdError == (FileHandle) -1 ||
-          spi.stdIn == (FileHandle) -1 ||
           spi.stdOut == (FileHandle) -1)
         {
           td->connection->host->warningsLogWrite (_("Cgi: internal error"));
@@ -274,15 +268,10 @@ int Cgi::send (HttpThreadContext* td, const char* 
scriptpath,
       sendData (td, stdOutFile, chain, cgiProc, onlyHeader, nph);
 
       stdOutFile.close ();
-      stdInFile.close ();
       cgiProc.terminateProcess ();
       chain.clearAllFilters ();
 
       cgiProc.terminateProcess ();
-
-      /* Delete the file only if it was created by the CGI module.  */
-      if (td->inputData.getHandle () >= 0)
-        FilesUtility::deleteFile (td->inputDataPath.c_str ());
     }
   catch (exception & e)
     {
diff --git a/myserver/src/http_handler/fastcgi/fastcgi.cpp 
b/myserver/src/http_handler/fastcgi/fastcgi.cpp
index 37b41a8..3dbbdb0 100644
--- a/myserver/src/http_handler/fastcgi/fastcgi.cpp
+++ b/myserver/src/http_handler/fastcgi/fastcgi.cpp
@@ -181,11 +181,6 @@ int FastCgi::send (HttpThreadContext* td, const char* 
scriptpath,
 #endif
         }
 
-      td->inputData.close ();
-      td->inputData.openFile (td->inputDataPath, File::READ
-                              | File::FILE_OPEN_ALWAYS
-                              | File::NO_INHERIT);
-
       server = connect (&con, cmdLine.str ().c_str ());
       if (server == NULL)
         {
diff --git a/myserver/src/http_handler/scgi/scgi.cpp 
b/myserver/src/http_handler/scgi/scgi.cpp
index d3033ad..224b6cc 100644
--- a/myserver/src/http_handler/scgi/scgi.cpp
+++ b/myserver/src/http_handler/scgi/scgi.cpp
@@ -169,9 +169,6 @@ int Scgi::send (HttpThreadContext* td, const char* 
scriptpath,
           chain.clearAllFilters ();
           return td->http->raiseHTTPError (500);
         }
-      td->inputData.close ();
-      td->inputData.openFile (td->inputDataPath, File::READ
-                              | File::FILE_OPEN_ALWAYS | File::NO_INHERIT);
 
       try
         {
diff --git a/myserver/src/protocol/http/http.cpp 
b/myserver/src/protocol/http/http.cpp
index 29603c2..7d980dc 100644
--- a/myserver/src/protocol/http/http.cpp
+++ b/myserver/src/protocol/http/http.cpp
@@ -847,8 +847,6 @@ int Http::controlConnection (ConnectionPtr a, char*, char*, 
u_long, u_long,
       td->appendOutputs = false;
       td->onlyHeader = false;
       td->filenamePath.assign ("");
-      td->outputDataPath.assign ("");
-      td->inputDataPath.assign ("");
       td->mime = NULL;
       td->headerSent = false;
       td->sentData = 0;
@@ -918,13 +916,6 @@ int Http::controlConnection (ConnectionPtr a, char*, 
char*, u_long, u_long,
 
       td->response.ver.assign (td->request.ver.c_str ());
 
-      /*
-        For methods that accept data after the HTTP header set the correct
-        pointer and create a file containing the informations after the header.
-       */
-      FilesUtility::temporaryFileName (td->id, td->inputDataPath);
-      FilesUtility::temporaryFileName (td->id, td->outputDataPath);
-
       dynamicCommand =
         staticData->getDynCmdManager ()->getHttpCommand (td->request.cmd);
 
@@ -1141,19 +1132,8 @@ int Http::controlConnection (ConnectionPtr a, char*, 
char*, u_long, u_long,
 
       try
         {
-          /* If the inputData file was not closed close it.  */
-          if (td->inputData.getHandle () >= 0)
-            {
-              td->inputData.close ();
-              FilesUtility::deleteFile (td->inputDataPath);
-            }
-
-          /* If the outputData file was not closed close it.  */
-          if (td->outputData.getHandle () >= 0)
-            {
-              td->outputData.close ();
-              FilesUtility::deleteFile (td->outputDataPath);
-            }
+          td->inputData.close ();
+          td->outputData.close ();
         }
       catch (GenericFileException & e)
         {
@@ -1737,8 +1717,6 @@ Http::Http (HttpProtocol *staticData)
   td->scriptPath.assign ("");
   td->scriptDir.assign ("");
   td->scriptFile.assign ("");
-  td->inputDataPath.assign ("");
-  td->outputDataPath.assign ("");
 }
 
 /*!
@@ -1762,7 +1740,5 @@ void Http::clean ()
   td->scriptPath.assign ("");
   td->scriptDir.assign ("");
   td->scriptFile.assign ("");
-  td->inputDataPath.assign ("");
-  td->outputDataPath.assign ("");
   delete td;
 }
diff --git a/myserver/src/protocol/http/http_data_read.cpp 
b/myserver/src/protocol/http/http_data_read.cpp
index 6aedc5c..242baf2 100644
--- a/myserver/src/protocol/http/http_data_read.cpp
+++ b/myserver/src/protocol/http/http_data_read.cpp
@@ -241,6 +241,10 @@ int HttpDataRead::readPostData (HttpThreadContext* td, 
int* httpRetCode)
   u_long inPos = 0;
   u_long nbr;
   u_long length;
+  string inputDataPath;
+
+  FilesUtility::temporaryFileName (td->id, inputDataPath);
+
 
   HttpRequestHeader::Entry *contentType =
     td->request.other.get ("content-type");
@@ -296,8 +300,8 @@ int HttpDataRead::readPostData (HttpThreadContext* td, int* 
httpRetCode)
     Create the file that contains the posted data.
     This data is the stdin file in the CGI.
   */
-  if (td->inputData.openFile (td->inputDataPath, File::READ
-                              | File::WRITE))
+  if (td->inputData.createTemporaryFile (inputDataPath.c_str (), File::READ
+                                         | File::WRITE))
     {
       *httpRetCode = 500;
       return 1;
@@ -327,8 +331,6 @@ int HttpDataRead::readPostData (HttpThreadContext* td, int* 
httpRetCode)
 
           if (ret == -1)
             {
-              td->inputDataPath.assign ("");
-              td->outputDataPath.assign ("");
               td->inputData.close ();
               return -1;
             }
@@ -364,7 +366,6 @@ int HttpDataRead::readPostData (HttpThreadContext* td, int* 
httpRetCode)
                                                timeout))
             {
               td->inputData.close ();
-              FilesUtility::deleteFile (td->inputDataPath);
               *httpRetCode = 400;
               return 1;
             }
@@ -374,7 +375,6 @@ int HttpDataRead::readPostData (HttpThreadContext* td, int* 
httpRetCode)
           else
             {
               td->inputData.close ();
-              FilesUtility::deleteFile (td->inputDataPath);
               *httpRetCode = 400;
               return 1;
             }
@@ -384,8 +384,6 @@ int HttpDataRead::readPostData (HttpThreadContext* td, int* 
httpRetCode)
           if (nbr && td->inputData.writeToFile (td->auxiliaryBuffer->getBuffer 
(),
                                                 nbr, &nbw))
             {
-              td->inputDataPath.assign ("");
-              td->outputDataPath.assign ("");
               td->inputData.close ();
               return -1;
             }
diff --git a/myserver/tests/test_file.cpp b/myserver/tests/test_file.cpp
index c650cdb..0e50697 100644
--- a/myserver/tests/test_file.cpp
+++ b/myserver/tests/test_file.cpp
@@ -64,14 +64,14 @@ public:
 
   void tearDown ()
   {
-    delete tfile;
     try
       {
-        FilesUtility::deleteFile (fname);
+        FilesUtility::deleteFile (tfile->getFilename ());
       }
     catch (...)
       {
       }
+    delete tfile;
   }
 
   void testCreateTemporaryDelayedFile ()
@@ -80,13 +80,13 @@ public:
     CPPUNIT_ASSERT_EQUAL (ret, 0);
 
     /* The unlink is done just before the close, the file can be stat'ed. */
-    ret = FilesUtility::nodeExists (fname.c_str ());
+    ret = FilesUtility::nodeExists (tfile->getFilename ());
     CPPUNIT_ASSERT (ret);
 
     ret = tfile->close ();
     CPPUNIT_ASSERT_EQUAL (ret, 0);
 
-    ret = FilesUtility::nodeExists (fname.c_str ());
+    ret = FilesUtility::nodeExists (tfile->getFilename ());
     CPPUNIT_ASSERT_EQUAL (ret, 0);
   }
 
@@ -96,13 +96,13 @@ public:
     CPPUNIT_ASSERT_EQUAL (ret, 0);
 
     /* Using unlink the file can't be stat'ed at this point.  */
-    ret = FilesUtility::nodeExists (fname.c_str ());
+    ret = FilesUtility::nodeExists (tfile->getFilename ());
     CPPUNIT_ASSERT_EQUAL (ret, 0);
 
     ret = tfile->close ();
     CPPUNIT_ASSERT_EQUAL (ret, 0);
 
-    ret = FilesUtility::nodeExists (fname.c_str ());
+    ret = FilesUtility::nodeExists (tfile->getFilename ());
     CPPUNIT_ASSERT_EQUAL (ret, 0);
   }
 

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

Summary of changes:
 myserver/bootstrap.conf                            |    1 +
 myserver/include/base/file/file.h                  |    2 +-
 myserver/include/base/files_cache/cached_file.h    |    2 +-
 .../include/protocol/http/http_thread_context.h    |    2 -
 myserver/src/base/file/file.cpp                    |   40 +++++++++++++------
 myserver/src/base/file/files_utility.cpp           |   11 +----
 myserver/src/base/files_cache/cached_file.cpp      |    4 +-
 myserver/src/http_handler/cgi/cgi.cpp              |   13 +------
 myserver/src/http_handler/fastcgi/fastcgi.cpp      |    5 --
 myserver/src/http_handler/scgi/scgi.cpp            |    3 -
 myserver/src/protocol/http/http.cpp                |   28 +-------------
 myserver/src/protocol/http/http_data_read.cpp      |   14 +++----
 myserver/tests/test_file.cpp                       |   12 +++---
 13 files changed, 50 insertions(+), 87 deletions(-)


hooks/post-receive
-- 
GNU MyServer



reply via email to

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