156
162
void DJRestartIfRunning(PCSTR daemon, LWException **exc)
159
PSTR initPath = NULL;
160
PSTR daemonPath = NULL;
163
LW_CLEANUP_CTERR(exc, CTFindFileInPath(daemon, "/etc/init.d:/etc/rc.d/init.d", &initPath));
164
DJ_LOG_INFO("Found '%s' at '%s'", daemon, initPath);
166
LW_TRY(exc, DJGetDaemonStatus(initPath, &running, &LW_EXC));
165
LWException *inner = NULL;
167
DJGetDaemonStatus(daemon, &running, &inner);
168
if(!LW_IS_OK(inner) && inner->code == CENTERROR_DOMAINJOIN_MISSING_DAEMON)
170
//The daemon isn't installed
174
LW_CLEANUP(exc, inner);
169
//The nscd init script on Solaris does not support the query option,
170
//so it looks like the daemon is never running. So we'll run a ps
171
//command and HUP the daemon if it is running
174
LW_CLEANUP_CTERR(exc, CTFindFileInPath(daemon, "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", &daemonPath));
175
ceError = CTGetPidOfCmdLine(NULL, daemonPath, NULL, 0, &daemonPid, NULL);
176
if(ceError == CENTERROR_NO_SUCH_PROCESS || ceError == CENTERROR_NOT_IMPLEMENTED)
178
//Nope, couldn't find the daemon running
181
LW_CLEANUP_CTERR(exc, ceError);
183
DJ_LOG_INFO("Sending HUP to '%s' binary, pid '%d'.", daemonPath, daemonPid);
185
LW_CLEANUP_CTERR(exc, CTSendSignal(daemonPid, SIGHUP));
189
DJ_LOG_INFO("Restarting '%s'", initPath);
190
LW_TRY(exc, DJStartStopDaemon(initPath, FALSE, NULL, &LW_EXC));
191
LW_TRY(exc, DJStartStopDaemon(initPath, TRUE, NULL, &LW_EXC));
194
CT_SAFE_FREE_STRING(initPath);
195
CT_SAFE_FREE_STRING(daemonPath);
178
DJ_LOG_INFO("Restarting '%s'", daemon);
179
LW_TRY(exc, DJStartStopDaemon(daemon, FALSE, NULL, &LW_EXC));
180
DJ_LOG_INFO("Starting '%s'", daemon);
181
LW_TRY(exc, DJStartStopDaemon(daemon, TRUE, NULL, &LW_EXC));
194
PSTR pszDomainNameAllUpper = NULL;
195
BOOLEAN bFileExists = TRUE;
197
PSTR pszErrFilePath = "/var/cache/centeris/grouppolicy/gpagentd.err";
199
DWORD dwGPErrCode = 0;
200
LWException *innerExc = NULL;
204
#define PWGRD "/etc/rc.config.d/pwgr"
205
LW_CLEANUP_CTERR(exc, CTCheckFileExists(PWGRD, &bFileExists));
208
//Shutdown pwgr (a nscd-like daemon) on HP-UX because it only handles
209
//usernames up to 8 characters in length.
210
LW_TRY(exc, DJStartStopDaemon("pwgr", FALSE, NULL, &LW_EXC));
211
LW_CLEANUP_CTERR(exc, CTRunSedOnFile(PWGRD, PWGRD, FALSE, "s/=1/=0/"));
214
//Figure out how many daemons there are
215
for(daemonCount = 0; daemonList[daemonCount].primaryName != NULL; daemonCount++);
219
CHAR szStartPriority[32];
220
CHAR szStopPriority[32];
222
//Start the daemons in ascending order
223
for(i = 0; i < daemonCount; i++)
225
sprintf(szStartPriority, "%d", daemonList[i].startPriority);
226
sprintf(szStopPriority, "%d", daemonList[i].stopPriority);
228
DJManageDaemon(daemonList[i].primaryName,
235
//Try the alternate daemon name if there is one
236
if (!LW_IS_OK(innerExc) &&
237
innerExc->code == CENTERROR_DOMAINJOIN_MISSING_DAEMON &&
238
daemonList[i].alternativeName != NULL)
240
LW_HANDLE(&innerExc);
241
DJManageDaemon(daemonList[i].alternativeName,
248
if (!LW_IS_OK(innerExc) &&
249
innerExc->code == CENTERROR_DOMAINJOIN_MISSING_DAEMON &&
250
!daemonList[i].required)
252
LW_HANDLE(&innerExc);
254
if (LW_IS_OK(innerExc) && !strcmp(daemonList[i].primaryName, "centeris.com-gpagentd"))
256
LW_CLEANUP_CTERR(exc, CTCheckFileExists(pszErrFilePath, &bFileExists));
260
LW_HANDLE(&innerExc);
261
fp = fopen(pszErrFilePath, "r");
264
if (fgets(szBuf, 256, fp) != NULL) {
266
CTStripWhitespace(szBuf);
268
dwGPErrCode = atoi(szBuf);
270
if (dwGPErrCode == GPAGENT_LICENSE_ERROR ||
271
dwGPErrCode == GPAGENT_LICENSE_EXPIRED_ERROR) {
273
LW_RAISE(exc, CENTERROR_DOMAINJOIN_LICENSE_ERROR);
281
DJ_LOG_ERROR("Failed to open file [%s]", pszErrFilePath);
286
LW_CLEANUP(exc, innerExc);
291
CHAR szStartPriority[32];
292
CHAR szStopPriority[32];
294
//Stop the daemons in descending order
295
for(i = daemonCount - 1; i >= 0; i--)
297
sprintf(szStartPriority, "%d", daemonList[i].startPriority);
298
sprintf(szStopPriority, "%d", daemonList[i].stopPriority);
300
DJManageDaemon(daemonList[i].primaryName,
307
//Try the alternate daemon name if there is one
308
if (!LW_IS_OK(innerExc) &&
309
innerExc->code == CENTERROR_DOMAINJOIN_MISSING_DAEMON &&
310
daemonList[i].alternativeName != NULL)
312
LW_HANDLE(&innerExc);
313
DJManageDaemon(daemonList[i].alternativeName,
320
if (!LW_IS_OK(innerExc) &&
321
innerExc->code == CENTERROR_DOMAINJOIN_MISSING_DAEMON &&
322
!daemonList[i].required)
324
LW_HANDLE(&innerExc);
326
LW_CLEANUP(exc, innerExc);
331
CTSafeCloseFile(&fp);
333
if (pszDomainNameAllUpper)
334
CTFreeString(pszDomainNameAllUpper);
336
LW_HANDLE(&innerExc);