From 2b15bc5f70afc46ae04a60988166bee31fe879ba Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Wed, 18 Oct 2017 19:12:50 -0500 Subject: [PATCH] Can't dbUnregisterServer() if stopped & no stop() method Unregistration is allowed if we're still registering though. This allows for cases like rsrv, which doesn't have a stop method. However the semantics of restarting servers after they have been stopped hasn't been defined, and rsrv probably wouldn't work if you tried that anyway, so I'm not convinced this is useful. --- src/ioc/db/dbServer.c | 6 ++++++ src/ioc/db/test/dbServerTest.c | 8 +++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/ioc/db/dbServer.c b/src/ioc/db/dbServer.c index 495156dcf..09917da55 100644 --- a/src/ioc/db/dbServer.c +++ b/src/ioc/db/dbServer.c @@ -76,6 +76,12 @@ int dbUnregisterServer(dbServer *psrv) psrv->name); return -1; } + if (state == stopped && psrv->stop == NULL) { + fprintf(stderr, "dbUnregisterServer: '%s' has no stop() method.\n", + psrv->name); + return -1; + } + ellDelete(&serverList, &psrv->node); return 0; } diff --git a/src/ioc/db/test/dbServerTest.c b/src/ioc/db/test/dbServerTest.c index 5aba92770..325b77644 100644 --- a/src/ioc/db/test/dbServerTest.c +++ b/src/ioc/db/test/dbServerTest.c @@ -123,7 +123,7 @@ MAIN(dbServerTest) char *theName = "The One"; int status; - testPlan(18); + testPlan(20); /* Prove that we handle substring names properly */ epicsEnvSet("EPICS_IOC_IGNORE_SERVERS", "none ones"); @@ -137,6 +137,8 @@ MAIN(dbServerTest) testDiag("Registering dbServer 'no-routines'"); testOk(dbRegisterServer(&no_routines) == 0, "Registered 'no-routines'"); + testOk(dbUnregisterServer(&no_routines) == 0, "'no-routines' unreg'd"); + testOk(dbRegisterServer(&no_routines) == 0, "Re-registered 'no-routines'"); epicsEnvSet("EPICS_IOC_IGNORE_SERVERS", "disabled nonexistent"); testDiag("Registering dbServer 'disabled'"); @@ -156,8 +158,8 @@ MAIN(dbServerTest) dbStopServers(); testOk(oneState == STOP_CALLED, "dbStopServers"); - testOk(dbUnregisterServer(&toolate) != 0, "No unregistration if not reg'ed"); - testOk(dbUnregisterServer(&no_routines) == 0, "Unregistered 'no-routines'"); + testOk(dbUnregisterServer(&toolate) != 0, "No unreg' if not reg'ed"); + testOk(dbUnregisterServer(&no_routines) != 0, "No unreg' of 'no-routines'"); testDiag("Printing server report"); dbsr(0);