I don't see much documentation about what we call 'elauncher' here, so I'm thinking it might be something site specific? In any case, It's what we use to add PVs that trigger python scripts to our IOCs. I've attached the source code we add to our src/ folder.
We also have an elaunchSupport.dbd file that simply contains two lines 'device(bo, INST_IO, devLauncher, "Launcher")'' and 'variable(launcherVerbose, int)'.
I'm getting an error when attempting to start the IOC, and I'm wondering if someone here could enlighten me as to the problem:
```
A call to 'assert(prec->out.type == INST_IO)' by thread '_main_' failed in ../launcher.c line 80.
Dumping a stack trace of thread '_main_':
[ 0x7f95a3285283]: /lib/x86_64-linux-gnu/libCom.so.3.15.8(epicsStackTrace+0x73)
[ 0x7f95a327e7af]: /lib/x86_64-linux-gnu/libCom.so.3.15.8(epicsAssert+0x4f)
[ 0x5604d5f29b2f]: ../../bin/linux-x86_64/hlc_s800(add_record+0x4f)
[ 0x7f95a3309ea7]: /lib/x86_64-linux-gnu/libdbCore.so.3.15.8(coreRelease+0x837)
[ 0x7f95a330a10a]: /lib/x86_64-linux-gnu/libdbCore.so.3.15.8(iocBuild+0x1a)
[ 0x7f95a330a299]: /lib/x86_64-linux-gnu/libdbCore.so.3.15.8(iocInit+0x9)
[ 0x7f95a32700fb]: /lib/x86_64-linux-gnu/libCom.so.3.15.8(gphDump+0x125b)
[ 0x5604d5f1fea2]: ../../bin/linux-x86_64/hlc_s800(main+0x12)
[ 0x7f95a309e09b]: /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xeb)
[ 0x5604d5f1fefa]: ../../bin/linux-x86_64/hlc_s800(_start+0x2a)
EPICS Release EPICS R3.15.8-2+0~20201111173402.6+debian10~1.gbp133abb.
Local time is 2021-12-04 14:33:29.880008830 EST
Please E-mail this message to the author or to tech-talk at aps.anl.govCalling epicsThreadSuspendSelf()
```
|
#include <stdlib.h>
#include <string.h>
#include <epicsString.h>
#include <epicsAssert.h>
#include <cantProceed.h>
#include <epicsThread.h>
#include <epicsMutex.h>
#include <epicsEvent.h>
#include <callback.h>
#include <epicsExit.h>
#include <errlog.h>
#include <dbStaticLib.h>
#include <alarm.h>
#include <dbEvent.h>
#include <dbAccess.h>
#include <recSup.h>
#include <devSup.h>
#include <alarm.h>
#include <boRecord.h>
#include <recGbl.h>
int launcherVerbose = 0;
typedef struct {
epicsMutexId lock;
epicsThreadId thread;
epicsEventId start;
boRecord *prec;
unsigned int running:1;
unsigned int done:1;
char *cmd;
int ret;
} work;
static void worker(void*);
static void cleanup(void*);
static long init_record(boRecord* prec)
{
return 2;
}
static long add_record(dbCommon* pcom)
{
DBENTRY entry;
boRecord *prec=(boRecord*)pcom;
work *priv=prec->dpvt;
if(!priv) {
priv=mallocMustSucceed(sizeof(*priv), "elauncher malloc");
prec->dpvt = priv;
priv->lock = epicsMutexMustCreate();
priv->start = epicsEventMustCreate(epicsEventEmpty);
priv->prec = prec;
priv->cmd = NULL;
priv->ret = -1;
priv->running = 0;
priv->done = 0;
priv->thread = epicsThreadMustCreate("launcher",
epicsThreadPriorityMedium,
epicsThreadGetStackSize(epicsThreadStackSmall),
&worker, priv);
epicsAtExit(&cleanup, priv);
}
assert(prec->out.type == INST_IO);
dbInitEntry(pdbbase, &entry);
dbFindRecord(&entry, prec->name); /* can't fail */
if(dbFindInfo(&entry, "cmd")==0) {
priv->cmd = epicsStrDup(dbGetInfoString(&entry));
} else {
priv->cmd = epicsStrDup(prec->out.value.instio.string);
}
if(launcherVerbose || !priv->cmd || strlen(priv->cmd)==0)
errlogPrintf("%s: cmd '%s'\n", prec->name, priv->cmd);
assert(priv->cmd);
dbFinishEntry(&entry);
return 0;
}
static long del_record(dbCommon* pcom)
{
boRecord *prec=(boRecord*)pcom;
work *priv=prec->dpvt;
if(!priv)
return -1;
assert(prec->out.type == INST_IO);
if(priv->running)
return -1;
free(priv->cmd);
priv->cmd = NULL;
return 0;
}
static long write(boRecord* prec)
{
work *priv=prec->dpvt;
if(!priv || !priv->cmd)
return -1;
prec->udf = 0;
if(!prec->pact) {
/* ensure 1-> 0 transition on completion */
prec->mlst = prec->val;
prec->val = 1;
db_post_events(prec, &prec->val, DBE_VALUE|DBE_LOG);
priv->running = 1;
epicsEventSignal(priv->start);
prec->pact = TRUE;
if(launcherVerbose)
errlogPrintf("%s: start\n", prec->name);
return 0;
} else {
prec->pact = FALSE;
if(WIFSIGNALED(priv->ret)) {
recGblSetSevr(prec, WRITE_ALARM, INVALID_ALARM);
} else if(WEXITSTATUS(priv->ret)) {
recGblSetSevr(prec, WRITE_ALARM, MAJOR_ALARM);
}
prec->mlst = prec->val;
prec->val = 0;
if(launcherVerbose)
errlogPrintf("%s: done\n", prec->name);
}
return 0;
}
static void worker(void *raw)
{
work *priv=raw;
while(1) {
char *cmd;
int ret;
epicsEventMustWait(priv->start);
if(priv->done) {
priv->done = 0;
return;
}
dbScanLock((dbCommon*)priv->prec);
if(launcherVerbose)
errlogPrintf("%s: run\n", priv->prec->name);
cmd = epicsStrDup(priv->cmd);
dbScanUnlock((dbCommon*)priv->prec);
ret = system(cmd);
dbScanLock((dbCommon*)priv->prec);
if(launcherVerbose)
errlogPrintf("%s: complete\n", priv->prec->name);
if(WIFSIGNALED(priv->ret)) {
unsigned int d=WTERMSIG(ret);
errlogPrintf("%s: command terminated with signal %u\n '%s'\n",
priv->prec->name, d, cmd);
}
free(cmd);
priv->ret = ret;
priv->running = 0;
(*priv->prec->rset->process)(priv->prec);
dbScanUnlock((dbCommon*)priv->prec);
}
}
static void cleanup(void *raw)
{
work *priv=raw;
priv->done = 1;
while(priv->done)
epicsEventSignal(priv->start);
if(launcherVerbose)
errlogPrintf("%s: worker stopped\n", priv->prec->name);
}
static
dsxt extLauncher =
{
&add_record, &del_record
};
static long init(int pass)
{
if(pass==0)
devExtend(&extLauncher);
return 0;
}
static
struct {
dset com;
DEVSUPFUN write;
} devLauncher =
{
{5, NULL,
(DEVSUPFUN) &init,
(DEVSUPFUN) &init_record,
NULL
},
(DEVSUPFUN) &write
};
#include <epicsExport.h>
epicsExportAddress(dset, devLauncher);
epicsExportAddress(int, launcherVerbose);
- Replies:
- Re: Trying to use elauncher: _main_ thread failed Johnson, Andrew N. via Tech-talk
- Re: Trying to use elauncher: _main_ thread failed Hu, Yong via Tech-talk
- Navigate by Date:
- Prev:
Infinite FLNK loop Daykin, Evan via Tech-talk
- Next:
Re: Infinite FLNK loop Johnson, Andrew N. via Tech-talk
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
<2021>
2022
2023
2024
- Navigate by Thread:
- Prev:
Re: Infinite FLNK loop Johnson, Andrew N. via Tech-talk
- Next:
Re: Trying to use elauncher: _main_ thread failed Johnson, Andrew N. via Tech-talk
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
<2021>
2022
2023
2024
|