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
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
static char *s_criu_image_path = NULL;
static int s_pid = 0;
-typedef enum
+typedef enum
{
CRIU_GCOUNTER_SHM,
CRIU_GCOUNTER_SIG,
#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];
char m_chServiceAddress[SUN_PATH_MAX];
} criu_native_dump_t;
-typedef struct
+typedef struct
{
int m_iDumpResult;
char m_chDumpResponseMessage[1024];
{
void *lib_handle = NULL;
void *pthread_lib_handle = NULL;
- char ch;
-
+
if (s_native)
return 0;
// Numerical signals indicates Apache
// 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());
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.
(((*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;
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);
}
}
int iOldUMask;
int iFd = -1;
char chFile[1024];
-
+
if (!iFatal) {
// LSCRIU_Debugging();
if (!s_criu_debug) {
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) {
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,
sTm.tm_sec,
sTimeb.millitm,
s_pid,
- iFatal ? "FATAL! " : "(debug) ",
+ iFatal ? "FATAL! " : "(debug) ",
buf);
if (n > (int)sizeof(chFullMessage))
n = sizeof(chFullMessage);
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);
}
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);
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) {
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);
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);
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;
}
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
}
(((*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
}
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
++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) {
}
return s_initial_start_reqs > 0;
}
-