1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
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.
@@ -1106,6 +1107,11 @@
return;
}
+ else if (!strcmp(name, "state"))
+ {
+ setStatePath(value);
+ return;
+ }
else if (!strcmp(name, "fullscreen"))
{
if (nxagentReconnectTrap == True)
@@ -1385,6 +1391,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);
--- a/nxcomp/Loop.cpp
+++ b/nxcomp/Loop.cpp
@@ -8898,7 +8898,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
|