diff --git a/SCinter.c b/SCinter.c index f640258e..dcec3d12 100644 --- a/SCinter.c +++ b/SCinter.c @@ -450,12 +450,11 @@ void DeleteInterp(SicsInterp * self) if (tail) { pCurrent = tail; while (pCurrent) { - /* the line below fixes problems with kill functions - * traversing the command list - */ - pCurrent->pNext = NULL; + pCurrent->pNext = NULL; /* inhibit access to killed commands by FindCommandData */ if (pCurrent->KFunc) { - pCurrent->KFunc(pCurrent->pData); + void *data = pCurrent->pData; + pCurrent->pData = NULL; /* make data unreachable by FindCommandData before killing */ + pCurrent->KFunc(data); } if (pCurrent->pName) { /* printf("Deleting %s\n",pCurrent->pName); */ diff --git a/devser.c b/devser.c index 4cbf4bd6..b76e41b0 100644 --- a/devser.c +++ b/devser.c @@ -27,7 +27,6 @@ struct DevSer { DevAction *toKill; /* list of actions to be killed */ SchedHeader *headers; int steps; - int stopTask; }; static char *devPrio[NumberOfPRIO] = { @@ -58,23 +57,14 @@ static void DevFreeActionList(DevAction * actions) while (actions != NULL) { victim = actions; actions = victim->next; + assert(victim->data != NULL); if (victim->kill != NULL) victim->kill(victim->data); + victim->data=NULL; free(victim); } } -static void DevKillTask(void *ds) -{ - DevSer *devser = ds; - - if (devser->stopTask) { - free(devser); - } else { - devser->stopTask = 1; - } -} - DevAction *DevNextAction(DevSer * devser) { DevPrio prio; @@ -130,9 +120,6 @@ int DevQueueTask(void *ds) if (devser->steps == 0) return 1; - if (devser->stopTask) { - return 0; - } /* deferred deallocation of removed actions */ DevFreeActionList(devser->toKill); @@ -188,10 +175,9 @@ DevSer *DevMake(SConnection * con, int argc, char *argv[]) devser->killCurrent = 0; devser->actions = NULL; devser->headers = NULL; - devser->stopTask = 0; devser->toKill = NULL; devser->steps = -1; /* no debugging by default */ - TaskRegister(pServ->pTasker, DevQueueTask, NULL, DevKillTask, devser, 0); + TaskRegister(pServ->pTasker, DevQueueTask, NULL, NULL, devser, 0); return devser; } @@ -235,11 +221,8 @@ void DevKill(DevSer * devser) devser->killCurrent = 0; free(devser->current); } - if (devser->stopTask) { - free(devser); - } else { - devser->stopTask = 1; - } + TaskRemove(pServ->pTasker, DevQueueTask, devser); + free(devser); } void DevDisconnect(DevSer * devser) diff --git a/hipadaba.c b/hipadaba.c index e9878872..786940b3 100644 --- a/hipadaba.c +++ b/hipadaba.c @@ -113,7 +113,7 @@ void RecurseCallbackChains(pHdb node, pHdbMessage message) /*-----------------------------------------------------------------------*/ void DeleteNodeData(pHdb node) { - pHdb tmp = NULL; + pHdb tmp = NULL, next = NULL; if (node == NULL) { return; @@ -132,8 +132,9 @@ void DeleteNodeData(pHdb node) while (node->child != NULL) { tmp = node->child; - node->child = node->child->next; + next = node->child->next; DeleteNodeData(tmp); + node->child = next; } free(node); } diff --git a/obdes.c b/obdes.c index 63f48e06..ce0b9bb6 100644 --- a/obdes.c +++ b/obdes.c @@ -84,7 +84,7 @@ void DeleteDescriptor(pObjectDescriptor self) if (self->pKeys) IFDeleteOptions(self->pKeys); /* - * delate a parameter node only when not linked elsewhere + * delete a parameter node only when not linked elsewhere */ if (self->parNode != NULL) { if (self->parNode->mama == NULL) { diff --git a/scriptcontext.c b/scriptcontext.c index ede6c54c..4c1641f0 100644 --- a/scriptcontext.c +++ b/scriptcontext.c @@ -43,6 +43,7 @@ typedef struct SctData { SctController *controller; SConnection *conCtx; int answered; + int inMacro; Hdb *node; } SctData; @@ -151,7 +152,8 @@ int SctCommand(SConnection * con, SicsInterp * sics, void *object, Hdb *cNode = NULL; hdbValue v; double dtime; - + int iMacro; + assert(sct == object); if (sct->nodes != NULL) { node = sct->nodes->node; @@ -188,11 +190,14 @@ int SctCommand(SConnection * con, SicsInterp * sics, void *object, * print */ if (strcmp(argv[1], "print") == 0) { + iMacro = con->iMacro; if (queueData != NULL) { queueData->answered = 1; + con->iMacro = queueData->inMacro; /* take macro flag stored at set callback */ } Arg2Text(argc - 2, argv + 2, value, sizeof value); - SCWrite(con, value, eLog); + SCWrite(con, value, eWarning); + con->iMacro = iMacro; return 1; } @@ -205,7 +210,7 @@ int SctCommand(SConnection * con, SicsInterp * sics, void *object, } /* - * time stamping (obsolete ? -> see SctActionHandler: timeKey, timeVal) + * time stamping */ if (strcmp(argv[1], "utime") == 0) { if (argc < 3) { @@ -334,13 +339,13 @@ static char *SctActionHandler(void *actionData, char *lastReply, commError = 0; } script = strdup(script); - if (!SctCallInContext(con, script, node, data->controller, &result)) { + if (!SctCallInContext(con, script, node, controller, &result)) { snprintf(eprop, sizeof eprop, "error_during_%s", data->name); if (strncmp(result, "ERROR: ", 7) == 0) { result += 7; } emsg = GetHdbProp(node, eprop); - if (emsg == NULL) { + if (emsg == NULL || con != controller->conn) { GetHdbPath(node, path, sizeof path); SCPrintf(con, eError, "ERROR: action <%s> in {%s} node %s:\nERROR: %s", @@ -364,6 +369,7 @@ static char *SctActionHandler(void *actionData, char *lastReply, snprintf(msg, sizeof msg, "%dx {%s} %s", cnt, origScript, result); SetHdbProperty(node, eprop, msg); send = NULL; + free(script); goto finish; } state = result; @@ -384,6 +390,7 @@ static char *SctActionHandler(void *actionData, char *lastReply, snprintf(timeVal, sizeof timeVal, "%.3f", DoubleTime()); SetHdbProperty(node, timeKey, timeVal); send = NULL; + free(script); goto finish; } SetProp(node, controller->node, "state", state); @@ -568,13 +575,15 @@ static hdbCallbackReturn SctActionCallback(Hdb * node, void *userData, if (data->conCtx != NULL) { GetHdbPath(node, path, sizeof path); - SCPrintf(data->conCtx, eLog, + SCPrintf(data->conCtx, eWarning, "%s target changed to %s before completion", path, GetCharArray(text)); + SCDeleteConnection(data->conCtx); } DeleteDynString(text); data->conCtx = SCCopyConnection(con); data->answered = 0; + data->inMacro = con->iMacro; DevQueue(data->controller->devser, data, prio, SctWriteHandler, SctMatch, NULL); /* no kill function in DevQueue: data is owned by the node (callback list) */ @@ -585,13 +594,11 @@ static hdbCallbackReturn SctActionCallback(Hdb * node, void *userData, if (mm != NULL) { if (queueData != NULL && queueData->conCtx != NULL && !data->answered) { /* update called from a write action */ - /* data->answered = 1; GetHdbPath(node, path, sizeof path); text = formatValue(*(mm->v), node); SCPrintf(queueData->conCtx, eWarning, "OK: %s set to: %s", path, GetCharArray(text)); DeleteDynString(text); - */ } return hdbContinue; } @@ -1050,9 +1057,14 @@ static hdbCallbackReturn SctDebugCallback(Hdb * node, void *userData, return hdbContinue; } -static int SctDeferredFree(void *data) +static void SctDeferredFree(void *data) { free(data); + return; +} + +static int SctDeferredTask(void *data) +{ return 0; } @@ -1069,8 +1081,8 @@ static void SctKillController(void *c) DevKill(controller->devser); controller->devser = NULL; if (pServ->pTasker) { - TaskRegister(pServ->pTasker, SctDeferredFree, NULL, NULL, controller, - 0); + TaskRegister(pServ->pTasker, SctDeferredTask, NULL, SctDeferredFree, + controller, 0); } else { free(controller); } @@ -1124,6 +1136,8 @@ static int SctMakeController(SConnection * con, SicsInterp * sics, if (!controller->devser) return 0; + SetHdbProperty(controller->node, "controllerName", objName); + AddCommand(pServ->pSics, objName, InterInvokeSICSOBJ, KillSICSOBJ, ccmd); RegisterSICSOBJKillCmd(ccmd, objName); SetDescriptorKey(ccmd->pDes, "creationCommand", "0"); diff --git a/sicsobj.c b/sicsobj.c index 6878202f..6a3a5a4a 100644 --- a/sicsobj.c +++ b/sicsobj.c @@ -84,11 +84,13 @@ static void KillSICSOBJfromNode(void *userData) NameClass *nameClass = userData; SICSOBJ *sicsobj; - sicsobj = FindCommandData(pServ->pSics, nameClass->name, nameClass->class); - if (sicsobj) { - sicsobj->objectNode = NULL; /* do not call RemoveHdbNodeFromParent in KillSICSOBJ */ - sicsobj->pDes->parNode = NULL; /* do not free the node twice in KillSICSOBJ/DeleteDescriptor */ - RemoveCommand(pServ->pSics, nameClass->name); + if (pServ->pSics != NULL) { + sicsobj = FindCommandData(pServ->pSics, nameClass->name, nameClass->class); + if (sicsobj) { + sicsobj->objectNode = NULL; /* do not call RemoveHdbNodeFromParent in KillSICSOBJ */ + sicsobj->pDes->parNode = NULL; /* do not free the node twice in KillSICSOBJ/DeleteDescriptor */ + RemoveCommand(pServ->pSics, nameClass->name); + } } free(nameClass->name); free(nameClass->class); @@ -159,7 +161,7 @@ void KillSICSOBJ(void *data) if (self->KillPrivate != NULL && self->pPrivate != NULL) { self->KillPrivate(self->pPrivate); } - if (self->objectNode != NULL) { + if (self->objectNode != NULL && pServ->pTasker != NULL) { /* not on rundown */ RemoveHdbNodeFromParent(self->objectNode, pServ->dummyCon); } if (self->pDes != NULL) { diff --git a/task.c b/task.c index a2cd4da1..85b0f2f9 100644 --- a/task.c +++ b/task.c @@ -351,7 +351,7 @@ void TaskRemove(pTaskMan self, TaskFunc pTaskRun, void *pData) int iRet; pTaskHead pCurrent, pNext; - assert(self); + if (self == NULL) return; assert(self->iID == TASKERID); pNext = self->pHead->pNext; /* skip dummy task */