Commit 8c1b852a authored by Oleksandr Shneyder's avatar Oleksandr Shneyder Committed by Mike Gabriel

Save session state in file.

210_nxagent_save_session_state.full.patch 210_nxcomp_save_session_state.full+lite.patch This patch adds a "state" option to NX (agent) which allows one to specify a file where nxagent will write its session state into.
parent 4a6ccd50
Description: Save session state in file
Author: Oleksandr Shneyder <o.shneyder@phoca-gmbh.de>
--- a/nx-X11/programs/Xserver/hw/nxagent/Args.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Args.c
@@ -60,6 +60,7 @@
#endif
#include "Handlers.h"
#include "Error.h"
+#include "Reconnect.h"
/*
* NX includes and definitions.
@@ -1090,6 +1091,11 @@
return;
}
+ else if (!strcmp(name, "state"))
+ {
+ setStatePath(value);
+ return;
+ }
else if (!strcmp(name, "fullscreen"))
{
if (nxagentReconnectTrap == True)
@@ -1369,6 +1375,11 @@
validateString(nxagentOptionFile));
#endif
+ /*
+ * Init statePath
+ */
+ setStatePath("");
+
if (nxagentOptionFile == NULL)
{
return;
--- a/nx-X11/programs/Xserver/hw/nxagent/Init.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Init.c
@@ -63,7 +63,7 @@
#include "NX.h"
#include "NXlib.h"
-
+#include "Reconnect.h"
/*
* Set here the required log level.
*/
@@ -233,6 +233,7 @@
fprintf(stderr, "Info: Agent running with pid '%d'.\n", getpid());
fprintf(stderr, "Session: Starting session at '%s'.\n", GetTimeAsString());
+ saveAgentState("STARTING");
}
/*
--- a/nx-X11/programs/Xserver/hw/nxagent/Reconnect.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Reconnect.c
@@ -118,6 +118,33 @@
static enum RECONNECTION_STEP failedStep;
+#include <limits.h>
+
+/*
+ * Path of state File
+ */
+char stateFile[PATH_MAX];
+
+
+void setStatePath(char* path)
+{
+ strncpy(stateFile, path, PATH_MAX-1);
+}
+
+void saveAgentState(char* state)
+{
+ FILE* fptr;
+ if(strlen(stateFile))
+ {
+ fptr=fopen(stateFile, "w");
+ if(!fptr)
+ return;
+ fprintf(fptr,"%s", state);
+ fclose(fptr);
+ }
+}
+
+
int nxagentHandleConnectionStates(void)
{
#ifdef TEST
@@ -211,6 +238,7 @@
fprintf(stderr, "Session: Display failure detected at '%s'.\n", GetTimeAsString());
fprintf(stderr, "Session: Suspending session at '%s'.\n", GetTimeAsString());
+ saveAgentState("SUSPENDING");
}
nxagentDisconnectSession();
@@ -265,6 +293,7 @@
fprintf(stderr, "Session: Session suspended at '%s'.\n", GetTimeAsString());
#endif
}
+ saveAgentState("SUSPENDED");
nxagentResetDisplayHandlers();
@@ -622,6 +651,7 @@
#else
fprintf(stderr, "Session: Session resumed at '%s'.\n", GetTimeAsString());
#endif
+ saveAgentState("RUNNING");
nxagentRemoveSplashWindow(NULL);
@@ -785,12 +815,14 @@
if (nxagentSessionState == SESSION_GOING_DOWN)
{
fprintf(stderr, "Session: Suspending session at '%s'.\n", GetTimeAsString());
+ saveAgentState("SUSPENDING");
nxagentDisconnectSession();
}
else if (nxagentSessionState == SESSION_GOING_UP)
{
fprintf(stderr, "Session: Resuming session at '%s'.\n", GetTimeAsString());
+ saveAgentState("RESUMING");
if (nxagentReconnectSession())
{
@@ -803,6 +835,7 @@
fprintf(stderr, "Session: Display failure detected at '%s'.\n", GetTimeAsString());
fprintf(stderr, "Session: Suspending session at '%s'.\n", GetTimeAsString());
+ saveAgentState("SUSPENDING");
nxagentDisconnectSession();
}
--- a/nx-X11/programs/Xserver/hw/nxagent/Reconnect.h
+++ b/nx-X11/programs/Xserver/hw/nxagent/Reconnect.h
@@ -34,6 +34,8 @@
Bool nxagentReconnectSession(void);
int nxagentHandleConnectionStates(void);
void nxagentHandleConnectionChanges(void);
+void setStatePath(char*);
+void saveAgentState(char*);
enum SESSION_STATE
{
--- a/nx-X11/programs/Xserver/hw/nxagent/X/NXdispatch.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/X/NXdispatch.c
@@ -609,6 +609,7 @@
#endif
nxagentSessionState = SESSION_UP;
+ saveAgentState("RUNNING");
}
#ifdef BLOCKS
@@ -823,6 +824,7 @@
*/
fprintf(stderr, "Session: Terminating session at '%s'.\n", GetTimeAsString());
+ saveAgentState("TERMINATING");
nxagentWaitDisplay();
@@ -833,6 +835,7 @@
{
NXShadowDestroy();
}
+ saveAgentState("TERMINATED");
KillAllClients();
DEALLOCATE_LOCAL(clientReady);
Description: Ignore state=<statefile> option in nxproxy/nxcomp
Author: Oleksandr Shneyder <o.shneyder@phoca-gmbh.de>
--- a/nxcomp/Loop.cpp
+++ b/nxcomp/Loop.cpp
@@ -8872,7 +8872,8 @@
}
else if (strcasecmp(name, "defer") == 0 ||
strcasecmp(name, "tile") == 0 ||
- strcasecmp(name, "menu") == 0)
+ strcasecmp(name, "menu") == 0 ||
+ strcasecmp(name, "state") == 0 )
{
#ifdef DEBUG
*logofs << "Loop: Ignoring agent option '" << name
210_nxagent_save_session_state.full.patch
210_nxcomp_save_session_state.full+lite.patch
211_nxcomp_set_default_options.full+lite.patch 211_nxcomp_set_default_options.full+lite.patch
212_nxcomp_build-on-Android.full+lite.patch 212_nxcomp_build-on-Android.full+lite.patch
220_nxproxy_bind-loopback-only.full+lite.patch 220_nxproxy_bind-loopback-only.full+lite.patch
......
...@@ -60,6 +60,7 @@ is" without express or implied warranty. ...@@ -60,6 +60,7 @@ is" without express or implied warranty.
#endif #endif
#include "Handlers.h" #include "Handlers.h"
#include "Error.h" #include "Error.h"
#include "Reconnect.h"
/* /*
* NX includes and definitions. * NX includes and definitions.
...@@ -1090,6 +1091,11 @@ static void nxagentParseOptions(char *name, char *value) ...@@ -1090,6 +1091,11 @@ static void nxagentParseOptions(char *name, char *value)
return; return;
} }
else if (!strcmp(name, "state"))
{
setStatePath(value);
return;
}
else if (!strcmp(name, "fullscreen")) else if (!strcmp(name, "fullscreen"))
{ {
if (nxagentReconnectTrap == True) if (nxagentReconnectTrap == True)
...@@ -1369,6 +1375,11 @@ void nxagentProcessOptionsFile() ...@@ -1369,6 +1375,11 @@ void nxagentProcessOptionsFile()
validateString(nxagentOptionFile)); validateString(nxagentOptionFile));
#endif #endif
/*
* Init statePath
*/
setStatePath("");
if (nxagentOptionFile == NULL) if (nxagentOptionFile == NULL)
{ {
return; return;
......
...@@ -63,7 +63,7 @@ is" without express or implied warranty. ...@@ -63,7 +63,7 @@ is" without express or implied warranty.
#include "NX.h" #include "NX.h"
#include "NXlib.h" #include "NXlib.h"
#include "Reconnect.h"
/* /*
* Set here the required log level. * Set here the required log level.
*/ */
...@@ -233,6 +233,7 @@ void InitOutput(ScreenInfo *screenInfo, int argc, char *argv[]) ...@@ -233,6 +233,7 @@ void InitOutput(ScreenInfo *screenInfo, int argc, char *argv[])
fprintf(stderr, "Info: Agent running with pid '%d'.\n", getpid()); fprintf(stderr, "Info: Agent running with pid '%d'.\n", getpid());
fprintf(stderr, "Session: Starting session at '%s'.\n", GetTimeAsString()); fprintf(stderr, "Session: Starting session at '%s'.\n", GetTimeAsString());
saveAgentState("STARTING");
} }
/* /*
......
...@@ -118,6 +118,33 @@ void *reconnectLossyLevel[STEP_NONE]; ...@@ -118,6 +118,33 @@ void *reconnectLossyLevel[STEP_NONE];
static enum RECONNECTION_STEP failedStep; static enum RECONNECTION_STEP failedStep;
#include <limits.h>
/*
* Path of state File
*/
char stateFile[PATH_MAX];
void setStatePath(char* path)
{
strncpy(stateFile, path, PATH_MAX-1);
}
void saveAgentState(char* state)
{
FILE* fptr;
if(strlen(stateFile))
{
fptr=fopen(stateFile, "w");
if(!fptr)
return;
fprintf(fptr,"%s", state);
fclose(fptr);
}
}
int nxagentHandleConnectionStates(void) int nxagentHandleConnectionStates(void)
{ {
#ifdef TEST #ifdef TEST
...@@ -211,6 +238,7 @@ TODO: This should be reset only when ...@@ -211,6 +238,7 @@ TODO: This should be reset only when
fprintf(stderr, "Session: Display failure detected at '%s'.\n", GetTimeAsString()); fprintf(stderr, "Session: Display failure detected at '%s'.\n", GetTimeAsString());
fprintf(stderr, "Session: Suspending session at '%s'.\n", GetTimeAsString()); fprintf(stderr, "Session: Suspending session at '%s'.\n", GetTimeAsString());
saveAgentState("SUSPENDING");
} }
nxagentDisconnectSession(); nxagentDisconnectSession();
...@@ -265,6 +293,7 @@ TODO: This should be reset only when ...@@ -265,6 +293,7 @@ TODO: This should be reset only when
fprintf(stderr, "Session: Session suspended at '%s'.\n", GetTimeAsString()); fprintf(stderr, "Session: Session suspended at '%s'.\n", GetTimeAsString());
#endif #endif
} }
saveAgentState("SUSPENDED");
nxagentResetDisplayHandlers(); nxagentResetDisplayHandlers();
...@@ -622,6 +651,7 @@ Bool nxagentReconnectSession(void) ...@@ -622,6 +651,7 @@ Bool nxagentReconnectSession(void)
#else #else
fprintf(stderr, "Session: Session resumed at '%s'.\n", GetTimeAsString()); fprintf(stderr, "Session: Session resumed at '%s'.\n", GetTimeAsString());
#endif #endif
saveAgentState("RUNNING");
nxagentRemoveSplashWindow(NULL); nxagentRemoveSplashWindow(NULL);
...@@ -785,12 +815,14 @@ void nxagentHandleConnectionChanges() ...@@ -785,12 +815,14 @@ void nxagentHandleConnectionChanges()
if (nxagentSessionState == SESSION_GOING_DOWN) if (nxagentSessionState == SESSION_GOING_DOWN)
{ {
fprintf(stderr, "Session: Suspending session at '%s'.\n", GetTimeAsString()); fprintf(stderr, "Session: Suspending session at '%s'.\n", GetTimeAsString());
saveAgentState("SUSPENDING");
nxagentDisconnectSession(); nxagentDisconnectSession();
} }
else if (nxagentSessionState == SESSION_GOING_UP) else if (nxagentSessionState == SESSION_GOING_UP)
{ {
fprintf(stderr, "Session: Resuming session at '%s'.\n", GetTimeAsString()); fprintf(stderr, "Session: Resuming session at '%s'.\n", GetTimeAsString());
saveAgentState("RESUMING");
if (nxagentReconnectSession()) if (nxagentReconnectSession())
{ {
...@@ -803,6 +835,7 @@ void nxagentHandleConnectionChanges() ...@@ -803,6 +835,7 @@ void nxagentHandleConnectionChanges()
fprintf(stderr, "Session: Display failure detected at '%s'.\n", GetTimeAsString()); fprintf(stderr, "Session: Display failure detected at '%s'.\n", GetTimeAsString());
fprintf(stderr, "Session: Suspending session at '%s'.\n", GetTimeAsString()); fprintf(stderr, "Session: Suspending session at '%s'.\n", GetTimeAsString());
saveAgentState("SUSPENDING");
nxagentDisconnectSession(); nxagentDisconnectSession();
} }
......
...@@ -34,6 +34,8 @@ void nxagentInitReconnector(void); ...@@ -34,6 +34,8 @@ void nxagentInitReconnector(void);
Bool nxagentReconnectSession(void); Bool nxagentReconnectSession(void);
int nxagentHandleConnectionStates(void); int nxagentHandleConnectionStates(void);
void nxagentHandleConnectionChanges(void); void nxagentHandleConnectionChanges(void);
void setStatePath(char*);
void saveAgentState(char*);
enum SESSION_STATE enum SESSION_STATE
{ {
......
...@@ -609,6 +609,7 @@ Reply Total Cached Bits In Bits Out Bits/Reply Ratio ...@@ -609,6 +609,7 @@ Reply Total Cached Bits In Bits Out Bits/Reply Ratio
#endif #endif
nxagentSessionState = SESSION_UP; nxagentSessionState = SESSION_UP;
saveAgentState("RUNNING");
} }
#ifdef BLOCKS #ifdef BLOCKS
...@@ -823,6 +824,7 @@ Reply Total Cached Bits In Bits Out Bits/Reply Ratio ...@@ -823,6 +824,7 @@ Reply Total Cached Bits In Bits Out Bits/Reply Ratio
*/ */
fprintf(stderr, "Session: Terminating session at '%s'.\n", GetTimeAsString()); fprintf(stderr, "Session: Terminating session at '%s'.\n", GetTimeAsString());
saveAgentState("TERMINATING");
nxagentWaitDisplay(); nxagentWaitDisplay();
...@@ -833,6 +835,7 @@ Reply Total Cached Bits In Bits Out Bits/Reply Ratio ...@@ -833,6 +835,7 @@ Reply Total Cached Bits In Bits Out Bits/Reply Ratio
{ {
NXShadowDestroy(); NXShadowDestroy();
} }
saveAgentState("TERMINATED");
KillAllClients(); KillAllClients();
DEALLOCATE_LOCAL(clientReady); DEALLOCATE_LOCAL(clientReady);
......
...@@ -8872,7 +8872,8 @@ int ParseEnvironmentOptions(const char *env, int force) ...@@ -8872,7 +8872,8 @@ int ParseEnvironmentOptions(const char *env, int force)
} }
else if (strcasecmp(name, "defer") == 0 || else if (strcasecmp(name, "defer") == 0 ||
strcasecmp(name, "tile") == 0 || strcasecmp(name, "tile") == 0 ||
strcasecmp(name, "menu") == 0) strcasecmp(name, "menu") == 0 ||
strcasecmp(name, "state") == 0 )
{ {
#ifdef DEBUG #ifdef DEBUG
*logofs << "Loop: Ignoring agent option '" << name *logofs << "Loop: Ignoring agent option '" << name
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment