]> granicus.if.org Git - php/commitdiff
Removed and fixed unused variables
authorGabriel Caruso <carusogabriel34@gmail.com>
Mon, 16 Jul 2018 03:19:02 +0000 (00:19 -0300)
committerGabriel Caruso <carusogabriel34@gmail.com>
Fri, 20 Jul 2018 01:51:37 +0000 (22:51 -0300)
sapi/litespeed/lscriu.c

index f767738f1b2acf2c6fe550fdf3a41bc253394340..b8345eb73cd97522335447a8b6977f141ec9b4fb 100644 (file)
@@ -21,18 +21,18 @@ All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are
-met: 
+met:
 
     * Redistributions of source code must retain the above copyright
-      notice, this list of conditions and the following disclaimer. 
+      notice, this list of conditions and the following disclaimer.
     * Redistributions in binary form must reproduce the above
       copyright notice, this list of conditions and the following
       disclaimer in the documentation and/or other materials provided
-      with the distribution. 
+      with the distribution.
     * Neither the name of the Lite Speed Technologies Inc nor the
       names of its contributors may be used to endorse or promote
       products derived from this software without specific prior
-      written permission.  
+      written permission.
 
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@@ -44,7 +44,7 @@ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
 #define HAVE_MSGHDR_MSG_CONTROL
@@ -107,7 +107,7 @@ static int s_fd_native = -1;
 static char *s_criu_image_path = NULL;
 static int s_pid = 0;
 
-typedef enum 
+typedef enum
 {
     CRIU_GCOUNTER_SHM,
     CRIU_GCOUNTER_SIG,
@@ -127,15 +127,15 @@ int LSAPI_Get_ppid();
 #define lscriu_dbg(...) \
     do { if (s_criu_debug) fprintf(stderr, __VA_ARGS__); } while(0)
 #else
-#define lscriu_dbg(...) 
+#define lscriu_dbg(...)
 #endif
-        
+
 #define lscriu_err(...) fprintf(stderr, __VA_ARGS__)
 
-        
+
 #define SUN_PATH_MAX   (sizeof(((struct sockaddr_un *)NULL)->sun_path))
 
-typedef struct 
+typedef struct
 {
     pid_t m_iPidToDump;
     char  m_chImageDirectory[1024];
@@ -143,7 +143,7 @@ typedef struct
     char  m_chServiceAddress[SUN_PATH_MAX];
 } criu_native_dump_t;
 
-typedef struct 
+typedef struct
 {
     int   m_iDumpResult;
     char  m_chDumpResponseMessage[1024];
@@ -258,8 +258,7 @@ static int LSCRIU_load_liblscapi(void)
 {
     void *lib_handle = NULL;
     void *pthread_lib_handle = NULL;
-    char ch;
-    
+
     if (s_native)
         return 0;
     // Numerical signals indicates Apache
@@ -299,10 +298,10 @@ static void LSCRIU_Wink_Server_is_Ready(void)
         // Not used for native
         return;
     }
-    if (getenv("LSAPI_UNIQE")) 
+    if (getenv("LSAPI_UNIQE"))
         snprintf(sem_name, sizeof sem_name - 1, "lsphp[hash=%s].is_ready",
                  getenv("LSAPI_UNIQE"));
-    else 
+    else
         snprintf(sem_name, sizeof sem_name - 1, "lsphp[euid=0x%x].is_ready",
                  geteuid());
 
@@ -314,28 +313,28 @@ static void LSCRIU_Wink_Server_is_Ready(void)
         if (psem_close(is_ready_sem) < 0)
             lsapi_error(sem_name, errno);
     }
-    else if (errno != ENOENT) 
+    else if (errno != ENOENT)
         lsapi_error(sem_name, errno);
 }
 
 
-static char *LSCRIU_Error_File_Name(char *pchFile, int max_len) 
+static char *LSCRIU_Error_File_Name(char *pchFile, int max_len)
 {
     const char *pchDefaultSocketPath = "/tmp/";
     const char *pchDefaultLogFileName = "lsws_error.log";
-    snprintf(pchFile, max_len, "%s%s", pchDefaultSocketPath, 
+    snprintf(pchFile, max_len, "%s%s", pchDefaultSocketPath,
              pchDefaultLogFileName);
     return pchFile;
 }
 
 
-#ifdef LSAPILIB_DEBUG_CRIU    
+#ifdef LSAPILIB_DEBUG_CRIU
 static void LSCRIU_Debugging(void) {
     char *pchCRIUDebug;
     pchCRIUDebug = getenv("LSAPI_CRIU_DEBUG");
-    if (!pchCRIUDebug) 
+    if (!pchCRIUDebug)
         pchCRIUDebug = getenv("LSCAPI_CRIU_DEBUG");
-    //fprintf(stderr,"(%d) LSCRIU: CRIU debug environment variable: %s\n",  
+    //fprintf(stderr,"(%d) LSCRIU: CRIU debug environment variable: %s\n",
     //        s_pid, pchCRIUDebug);
     // I've made it easy to turn on debugging.  CloudLinux Apache sets
     // LSCAPI_CRIU_DEBUG to nothing to indicate it's on.  Sigh.
@@ -347,7 +346,7 @@ static void LSCRIU_Debugging(void) {
          (((*pchCRIUDebug == 'O') ||
             (*pchCRIUDebug == 'o')) &&
            ((*(pchCRIUDebug + 1)) &&
-            ((*(pchCRIUDebug + 1) == 'F') || (*(pchCRIUDebug + 1) == 'f')))))) 
+            ((*(pchCRIUDebug + 1) == 'F') || (*(pchCRIUDebug + 1) == 'f'))))))
     {
         lscriu_dbg("LSCRIU (%d): CRIU Debugging disabled by environment\n", s_pid);
         s_criu_debug = 0;
@@ -355,7 +354,7 @@ static void LSCRIU_Debugging(void) {
     else {
         s_criu_debug = 1;
         lscriu_dbg("LSCRIU (%d): CRIU Debugging enabled by environment\n", s_pid);
-        fprintf(stderr,"LSCRIU (%d): CRIU debug environment variable: %s\n",  
+        fprintf(stderr,"LSCRIU (%d): CRIU debug environment variable: %s\n",
                 s_pid, pchCRIUDebug);
     }
 }
@@ -366,7 +365,7 @@ static void LSCRIU_Restored_Error(int iFatal, char *format, ...) {
     int iOldUMask;
     int iFd = -1;
     char chFile[1024];
-    
+
     if (!iFatal) {
         // LSCRIU_Debugging();
         if (!s_criu_debug) {
@@ -379,7 +378,7 @@ static void LSCRIU_Restored_Error(int iFatal, char *format, ...) {
         return;
     }
     iOldUMask = umask(0);
-    iFd = open( chFile, O_WRONLY | O_APPEND | O_CREAT, 
+    iFd = open( chFile, O_WRONLY | O_APPEND | O_CREAT,
                 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
     umask(iOldUMask);
     if (iFd >= 0) {
@@ -393,9 +392,9 @@ static void LSCRIU_Restored_Error(int iFatal, char *format, ...) {
         char buf[0x1000];
         vsnprintf(buf, sizeof(buf), format, ap);
         va_end(ap);
-        
+
         int n = snprintf(chFullMessage, sizeof(chFullMessage),
-                "%04d-%02d-%02d %02d:%02d:%02d.%03d: LSCRIU (%d): %s %s\n", 
+                "%04d-%02d-%02d %02d:%02d:%02d.%03d: LSCRIU (%d): %s %s\n",
                 sTm.tm_year + 1900,
                 sTm.tm_mon + 1,
                 sTm.tm_mday,
@@ -404,7 +403,7 @@ static void LSCRIU_Restored_Error(int iFatal, char *format, ...) {
                 sTm.tm_sec,
                 sTimeb.millitm,
                 s_pid,
-                iFatal ? "FATAL! " : "(debug) ", 
+                iFatal ? "FATAL! " : "(debug) ",
                 buf);
         if (n > (int)sizeof(chFullMessage))
             n = sizeof(chFullMessage);
@@ -438,7 +437,7 @@ static int LSCRIU_Native_Dump(pid_t iPid,
     if (write(iFdNative,
               &criu_native_dump,
               sizeof(criu_native_dump)) == -1) {
-        lscriu_err("LSCRIU (%d): Error sending dump request to the listener: %s\n", 
+        lscriu_err("LSCRIU (%d): Error sending dump request to the listener: %s\n",
                    s_pid, strerror(errno));
         return(-1);
     }
@@ -461,7 +460,7 @@ static int LSCRIU_Native_Dump(pid_t iPid,
 static void LSCRIU_CloudLinux_Checkpoint(void)
 {
     int iRet;
-    
+
     if ((!s_native) && (!s_lscapi_dump_me)) {
         lscriu_dbg("LSCRIU (%d): Not native and unable to dump - abandon one-time "
                    "dump\n", s_pid);
@@ -470,8 +469,7 @@ static void LSCRIU_CloudLinux_Checkpoint(void)
 
     iRet = s_lscapi_dump_me();
     if (iRet < 0) {
-        char *pchError;
-        lscriu_err("LSCRIU: CloudLinux dump of PID: %d, error: %s\n", 
+        lscriu_err("LSCRIU: CloudLinux dump of PID: %d, error: %s\n",
                    s_pid, strerror(errno));
     }
     if (iRet == 0) {
@@ -482,11 +480,11 @@ static void LSCRIU_CloudLinux_Checkpoint(void)
         s_restored = 1;
         LSAPI_reset_server_state();
         /*
-         Here we have restored the php process, so we should to tell (via 
+         Here we have restored the php process, so we should to tell (via
          semaphore) mod_lsapi that we are started and ready to receive data.
         */
         LSCRIU_Wink_Server_is_Ready();
-        lscriu_err("LSCRIU: Successful CloudLinux restore of PID: %d, parent: %d.\n", 
+        lscriu_err("LSCRIU: Successful CloudLinux restore of PID: %d, parent: %d.\n",
                    getpid(), getppid());
     }
     LSCRIU_Set_Initial_Start_Reqs(0);
@@ -526,31 +524,28 @@ static void LSCRIU_try_checkpoint(int *forked_pid)
 
     if (s_tried_checkpoint) {
         lscriu_dbg("LSCRIU (%d): Already tried checkpoint - one time per customer\n",
-                   getpid());
+                   iPidDump);
         return;
     }
-    lscriu_dbg("LSCRIU (%d): Trying checkpoint\n", getpid());
+    lscriu_dbg("LSCRIU (%d): Trying checkpoint\n", iPidDump);
     s_tried_checkpoint = 1;
     if (!s_native) {
         LSCRIU_CloudLinux_Checkpoint();
         return;
     }
 
-    lscriu_dbg("LSCRIU (%d): fork!\n", getpid());
+    lscriu_dbg("LSCRIU (%d): fork!\n", iPidDump);
     iPid = fork();
     if (iPid < 0) {
         lscriu_err("LSCRIU (%d): Can't checkpoint due to a fork error: %s\n",
-                   getpid(), strerror(errno));
+                   iPidDump, strerror(errno));
         return;
     }
     if (iPid == 0) {
-        int     iResult;
-        pid_t   iPidSender;
         pid_t   iPidParent = getppid();
 
-        s_pid = getpid();
         setsid();
-        iRet = LSCRIU_Native_Dump(s_pid,
+        iRet = LSCRIU_Native_Dump(iPidDump,
                                   s_criu_image_path,
                                   s_fd_native);
         close(s_fd_native);
@@ -603,22 +598,22 @@ static int LSCRIU_Init_Env_Parameters(void)
     int n;
 
     p = getenv("LSAPI_INITIAL_START");
-    if (!p) 
+    if (!p)
         p = getenv("LSAPI_BACKEND_INITIAL_START");
     if (p) {
         n = atoi(p);
 
         if (n > 0) {
-            lscriu_dbg("LSCRIU (%d): Set start requests based on environment (%d)\n", 
+            lscriu_dbg("LSCRIU (%d): Set start requests based on environment (%d)\n",
                        getpid(), n);
             LSCRIU_Set_Initial_Start_Reqs(n);
         } else {
-            lscriu_dbg("LSCRIU (%d): LSAPI_INITIAL_START set to 0 disabled\n", 
+            lscriu_dbg("LSCRIU (%d): LSAPI_INITIAL_START set to 0 disabled\n",
                        getpid());
             return 0;
         }
     } else {
-        lscriu_dbg("LSCRIU (%d): LSAPI_INITIAL_START NOT set - disabled\n", 
+        lscriu_dbg("LSCRIU (%d): LSAPI_INITIAL_START NOT set - disabled\n",
                    getpid());
         return 0;
     }
@@ -627,11 +622,11 @@ static int LSCRIU_Init_Env_Parameters(void)
         GlobalCounterType_t gc_type = CRIU_GCOUNTER_SHM;
         char *env;
         if ((env = getenv("LSAPI_CRIU_USE_SHM"))) {
-            // CloudLinux doc: Off (shared memory) or Signals.  
+            // CloudLinux doc: Off (shared memory) or Signals.
             // Litespeed doc: On (shared memory) or Signals
-            // So just check the first character for an 'S' and if not, then 
+            // So just check the first character for an 'S' and if not, then
             // use shared memory.  Pipe support is lost (sigh).
-            if ((*env == 'S') || (*env == 's')) 
+            if ((*env == 'S') || (*env == 's'))
                 gc_type = CRIU_GCOUNTER_SIG; // Just assume the rest is signals
             // else use the default of shared memory
         }
@@ -644,7 +639,7 @@ static int LSCRIU_Init_Env_Parameters(void)
                 (((*env == 'O') || (*env == 'o')) &&
                  ((*(env + 1) == 'N') || (*(env + 1) == 'n'))))
                 gc_type = CRIU_GCOUNTER_SIG;
-            else if (*env == 2) 
+            else if (*env == 2)
                 gc_type = CRIU_GCOUNTER_PIPE; // The only case for pipe
             //else use the default of shared memory
         }
@@ -657,11 +652,10 @@ static int LSCRIU_Init_Env_Parameters(void)
             lscriu_dbg("LSCRIU (%d): Use shared memory\n", getpid());
         LSCRIU_Set_Global_Counter_Type(gc_type);
     }
-    else 
+    else
         lscriu_dbg("LSCRIU (%d): NOT Listening\n", getpid());
 
     char *criu_mode = NULL;
-    char ch;
     criu_mode = getenv("LSAPI_CRIU");
     // 0 disabled
     // 1 cloudlinux
@@ -691,7 +685,7 @@ void LSCRIU_inc_req_procssed()
         ++s_requests_count;
     }
 
-    lscriu_dbg("LSCRIU (%d): s_requests_count %d counter %d\n", getpid(), 
+    lscriu_dbg("LSCRIU (%d): s_requests_count %d counter %d\n", getpid(),
                s_requests_count, s_initial_start_reqs);
 
     if (s_initial_start_reqs > 0 && s_requests_count <= s_initial_start_reqs) {
@@ -739,4 +733,3 @@ int LSCRIU_Init(void)
     }
     return s_initial_start_reqs > 0;
 }
-