--with-param=ARG use the given parameter source, default is "tcl"
--with-hardware=ARG use the given readout code, default is "soft",
possible values are rich, mdc, show, trig, soft
+\
+ --with-epics=ARG indicates the epics base directory, take
+ default from enviroment EPICS_BASE \
+
Some influential environment variables:
CC C compiler command
with_hardware="soft"
fi;
+# Check whether --with-epics or --without-epics was given.
+if test "${with_epics+set}" = set; then
+ withval="$with_epics"
+
+else
+ with_epics="$EPICS_BASE"
+fi;
+
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
fi
-if test x$with_param = xfile
+if test x$with_param = xca
+then
+if test -x "$with_epics/startup/HostArch"
+then
+ epics_version="3_13"
+ HOST_ARCH=$($with_epics/startup/HostArch)
+elif test -x "$with_epics/startup/EpicsHostArch"
+then
+ epics_version="3_14"
+ HOST_ARCH=$($with_epics/startup/EpicsHostArch)
+else
+ { { echo "$as_me:$LINENO: error: Missing valid EPICS version" >&5
+echo "$as_me: error: Missing valid EPICS version" >&2;}
+ { (exit 1); exit 1; }; }
+fi
+if test "x$epics_version" = "x3_13"
+then
+ LIBS="-L$with_epics/lib/$HOST_ARCH $LIBS"
+elif test "x$epics_version" = "x3_14"
+then
+ LIBS="-L$with_epics/lib/$EPICS_HOST_ARCH $LIBS"
+fi
+echo "$as_me:$LINENO: checking for library containing Tcl_CreateInterp" >&5
+echo $ECHO_N "checking for library containing Tcl_CreateInterp... $ECHO_C" >&6
+if test "${ac_cv_search_Tcl_CreateInterp+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ ac_func_search_save_LIBS=$LIBS
+ac_cv_search_Tcl_CreateInterp=no
+cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+
+/* Override any gcc2 internal prototype to avoid an error. */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+ builtin and then its argument prototype would still apply. */
+char Tcl_CreateInterp ();
+#ifdef F77_DUMMY_MAIN
+# ifdef __cplusplus
+ extern "C"
+# endif
+ int F77_DUMMY_MAIN() { return 1; }
+#endif
+int
+main ()
+{
+Tcl_CreateInterp ();
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+ (eval $ac_link) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -s conftest$ac_exeext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_search_Tcl_CreateInterp="none required"
+else
+ echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+fi
+rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
+if test "$ac_cv_search_Tcl_CreateInterp" = no; then
+ for ac_lib in tcl; do
+ LIBS="-l$ac_lib $ac_func_search_save_LIBS"
+ cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+
+/* Override any gcc2 internal prototype to avoid an error. */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+ builtin and then its argument prototype would still apply. */
+char Tcl_CreateInterp ();
+#ifdef F77_DUMMY_MAIN
+# ifdef __cplusplus
+ extern "C"
+# endif
+ int F77_DUMMY_MAIN() { return 1; }
+#endif
+int
+main ()
+{
+Tcl_CreateInterp ();
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+ (eval $ac_link) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -s conftest$ac_exeext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_search_Tcl_CreateInterp="-l$ac_lib"
+break
+else
+ echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+fi
+rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
+ done
+fi
+LIBS=$ac_func_search_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_search_Tcl_CreateInterp" >&5
+echo "${ECHO_T}$ac_cv_search_Tcl_CreateInterp" >&6
+if test "$ac_cv_search_Tcl_CreateInterp" != no; then
+ test "$ac_cv_search_Tcl_CreateInterp" = "none required" || LIBS="$ac_cv_search_Tcl_CreateInterp $LIBS"
+
+fi
+
+echo "$as_me:$LINENO: checking for library containing conParam" >&5
+echo $ECHO_N "checking for library containing conParam... $ECHO_C" >&6
+if test "${ac_cv_search_conParam+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ ac_func_search_save_LIBS=$LIBS
+ac_cv_search_conParam=no
+cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+
+/* Override any gcc2 internal prototype to avoid an error. */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+ builtin and then its argument prototype would still apply. */
+char conParam ();
+#ifdef F77_DUMMY_MAIN
+# ifdef __cplusplus
+ extern "C"
+# endif
+ int F77_DUMMY_MAIN() { return 1; }
+#endif
+int
+main ()
+{
+conParam ();
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+ (eval $ac_link) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -s conftest$ac_exeext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_search_conParam="none required"
+else
+ echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+fi
+rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
+if test "$ac_cv_search_conParam" = no; then
+ for ac_lib in caParam; do
+ LIBS="-l$ac_lib -lca -lCom $ac_func_search_save_LIBS"
+ cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+
+/* Override any gcc2 internal prototype to avoid an error. */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+ builtin and then its argument prototype would still apply. */
+char conParam ();
+#ifdef F77_DUMMY_MAIN
+# ifdef __cplusplus
+ extern "C"
+# endif
+ int F77_DUMMY_MAIN() { return 1; }
+#endif
+int
+main ()
+{
+conParam ();
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+ (eval $ac_link) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -s conftest$ac_exeext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_search_conParam="-l$ac_lib"
+break
+else
+ echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+fi
+rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
+ done
+fi
+LIBS=$ac_func_search_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_search_conParam" >&5
+echo "${ECHO_T}$ac_cv_search_conParam" >&6
+if test "$ac_cv_search_conParam" != no; then
+ test "$ac_cv_search_conParam" = "none required" || LIBS="$ac_cv_search_conParam $LIBS"
+ LIBS="-lcaParam -lca -lCom $LIBS"
+fi
+
+elif test x$with_param = xfile
then
echo "$as_me:$LINENO: checking for library containing conParam" >&5
echo $ECHO_N "checking for library containing conParam... $ECHO_C" >&6
echo "$as_me: error: Unknown parameter source $with_param" >&2;}
{ (exit 1); exit 1; }; }
fi
+if test x$ac_cv_search_conParam = xno
+then
+{ { echo "$as_me:$LINENO: error: Parameter library not found" >&5
+echo "$as_me: error: Parameter library not found" >&2;}
+ { (exit 1); exit 1; }; }
+fi
if test x$enable_manage = xyes
then
AC_ARG_WITH(param, [ --with-param[=ARG] use the given parameter source, default is "tcl"],,with_param="tcl")
AC_ARG_WITH(hardware, [ --with-hardware[=ARG] use the given readout code, default is "soft",
possible values are rich, mdc, show, trig, soft],,with_hardware="soft")
+AC_ARG_WITH(epics, \
+[ --with-epics[=ARG] indicates the epics base directory, take
+ default from enviroment EPICS_BASE] \
+,,with_epics="$EPICS_BASE")
dnl Checks for programs.
AC_PROG_CC
AC_SEARCH_LIBS(syslog, netinet)
-if test x$with_param = xfile
+if test x$with_param = xca
+then
+if test -x "$with_epics/startup/HostArch"
+then
+ epics_version="3_13"
+ HOST_ARCH=$($with_epics/startup/HostArch)
+elif test -x "$with_epics/startup/EpicsHostArch"
+then
+ epics_version="3_14"
+ HOST_ARCH=$($with_epics/startup/EpicsHostArch)
+else
+ AC_ERROR([Missing valid EPICS version])
+fi
+if test "x$epics_version" = "x3_13"
+then
+ LIBS="-L$with_epics/lib/$HOST_ARCH $LIBS"
+elif test "x$epics_version" = "x3_14"
+then
+ LIBS="-L$with_epics/lib/$EPICS_HOST_ARCH $LIBS"
+fi
+AC_SEARCH_LIBS(Tcl_CreateInterp, tcl)
+AC_SEARCH_LIBS(conParam, caParam, LIBS="-lcaParam -lca -lCom $LIBS",, -lca -lCom)
+elif test x$with_param = xfile
then
AC_SEARCH_LIBS(conParam, fileParam)
elif test x$with_param = xtcl
else
AC_ERROR([Unknown parameter source $with_param])
fi
+if test x$ac_cv_search_conParam = xno
+then
+AC_ERROR([Parameter library not found])
+fi
if test x$enable_manage = xyes
then
-static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/worker.c,v 6.14 2002-11-07 12:48:49 hadaq Exp $";
+static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/worker.c,v 6.15 2003-02-07 11:42:28 hadaq Exp $";
+#undef WORKER_NEW_PROTOCOL
#define _POSIX_C_SOURCE 199309L
#include <unistd.h>
syslog(LOG_DEBUG, "%s:%d: %s", __FILE__, __LINE__, strerror(errno));
retVal = -1;
} else {
- my->shm = PsxShm_open(ipcName, O_CREAT | O_RDWR, S_IRWXU, WORKER_MAX_NUM_STATS * sizeof(Statistic));
+ my->shm =
+ PsxShm_open(ipcName, O_CREAT | O_RDWR, S_IRWXU,
+ WORKER_MAX_NUM_STATS * sizeof(Statistic));
if (NULL == my->shm) {
syslog(LOG_DEBUG, "%s:%d: %s", __FILE__, __LINE__, strerror(errno));
retVal = -1;
ipcName = basename(ipcNameS);
strcat(ipcName, ".shm");
- my->shm = PsxShm_open(ipcName, O_RDWR, 0, WORKER_MAX_NUM_STATS * sizeof(Statistic));
+ my->shm =
+ PsxShm_open(ipcName, O_RDWR, 0,
+ WORKER_MAX_NUM_STATS * sizeof(Statistic));
if (NULL == my->shm) {
- syslog(LOG_DEBUG, "%s:%d: %s", __FILE__, __LINE__, strerror(errno));
retVal = -1;
} else {
my->statistics = my->shm->addr;
return PsxShm_close(my->shm);
}
-static int removeSigHandlers(Worker *my) {
+static int removeSigHandlers(Worker *my)
+{
return sigaction(my->signal0, my->oldSigAction0, NULL)
| sigaction(my->signal1, my->oldSigAction1, NULL);
}
-static int installSigHandlers(Worker *my, int s0, int s1, void (*sigHandler) (int)) {
+static int installSigHandlers(Worker *my, int s0, int s1,
+ void (*sigHandler) (int))
+{
int retVal;
struct sigaction actS, *act = &actS;
syslog(LOG_DEBUG, "%s:%d: %s", __FILE__, __LINE__, strerror(errno));
my->oldSigAction1 = NULL;
}
-
+
if (my->oldSigAction0 == NULL || my->oldSigAction1 == NULL) {
removeSigHandlers(my);
retVal = -1;
retVal = 0;
}
- return retVal;
+ return retVal;
}
-Worker *Worker_initBegin(const char *name, void (*sigHandler) (int), int priority, int isStandalone)
+Worker *Worker_initBegin(const char *name, void (*sigHandler) (int),
+ int priority, int isStandalone)
{
Worker *retVal;
Worker *my;
Worker_fini(my);
retVal = NULL;
} else {
+#ifndef WORKER_NEW_PROTOCOL
unsigned long *pidP;
pidP = Worker_addStatistic(my, "pid");
*pidP = my->pid;
+#else
+ /* pid must always be first statistic */
+ Worker_addStatistic(my, "pid");
+ my->statistics[0].value = 0;
+#endif
if (0 > changePriority(priority)) {
syslog(LOG_WARNING, "changeing priority: %s", strerror(errno));
void Worker_initEnd(Worker *my)
{
+#ifndef WORKER_NEW_PROTOCOL
if (!my->isStandalone) {
if (0 > kill(getppid(), SIGUSR1)) {
- syslog(LOG_DEBUG,
- "%s:%d: %s", __FILE__, __LINE__, strerror(errno));
+ syslog(LOG_DEBUG, "%s:%d: %s", __FILE__, __LINE__, strerror(errno));
}
}
+#else
+ my->statistics[0].value = my->pid;
+#endif
}
void Worker_fini(Worker *my)
Worker myS, *my = &myS;
strcpy(my->name, argv[0]);
+#ifndef WORKER_NEW_PROTOCOL
installSigHandlers(my, SIGCHLD, SIGUSR1, noopHandler);
+#endif
my->pid = fork();
if (0 > my->pid) {
syslog(LOG_DEBUG, "%s:%d: %s", __FILE__, __LINE__, strerror(errno));
retVal = -1;
} else {
- if (my->pid == 0) { /* This is the child, we can not get out of */
- /* this block */
+ if (my->pid == 0) { /* This is the child, we can not get out of */
+ /* this block */
if (0 > execvp(path, argv)) {
syslog(LOG_DEBUG,
"%s:%d: %s", __FILE__, __LINE__, strerror(errno));
abort();
}
} else {
+#ifndef WORKER_NEW_PROTOCOL
sigset_t sigMaskS, *sigMask = &sigMaskS;
/* BUGBUG there should be a timeout here */
} else {
retVal = 0;
}
+#else
+ /* wait until worker opens statShm and reports pid */
+ const int timeout = 15;
+ int workerIsStarted = 0;
+ int i;
+
+ for (i = 0; !workerIsStarted && i < timeout; i++) {
+ if (0 == openStatShm(my)) {
+ if (my->pid == my->statistics[0].value) {
+ workerIsStarted = 1;
+ }
+ closeStatShm(my);
+ }
+ sleep(1);
+ }
+ if (i == timeout) {
+ retVal = -1;
+ } else {
+ retVal = 0;
+ }
+#endif
}
}
+#ifndef WORKER_NEW_PROTOCOL
removeSigHandlers(my);
+#endif
return retVal;
}
retVal = NULL;
} else {
strcpy(buf, "{}");
- for (
- i = 0, p = buf;
- i < WORKER_MAX_NUM_STATS && strcmp(my->statistics[i].name, "") != 0;
- i++) {
- p += sprintf(p,
- "{ %s %lu } ", my->statistics[i].name, my->statistics[i].value);
+ for (i = 0, p = buf;
+ i < WORKER_MAX_NUM_STATS
+ && strcmp(my->statistics[i].name, "") != 0; i++) {
+ p += sprintf(p, "{ %s %lu } ", my->statistics[i].name,
+ my->statistics[i].value);
}
closeStatShm(my);
retVal = buf;
my->pid = my->statistics[0].value;
if (my->pid > 0) {
if (0 == kill(my->pid, SIGTERM)) {
- sleep(1);
- wait(NULL);
+ sleep(1); /* LynxOS had problem without this */
+ waitpid(my->pid, NULL, 0);
}
}
+ closeStatShm(my);
}
}
unsigned long *retVal;
int i;
- for (i = 0; i < WORKER_MAX_NUM_STATS && strcmp(my->statistics[i].name, "") != 0; i++) {
+ for (i = 0;
+ i < WORKER_MAX_NUM_STATS && strcmp(my->statistics[i].name, "") != 0;
+ i++) {
}
if (i == WORKER_MAX_NUM_STATS) {
- syslog(LOG_ERR, "%s:%d: %s", __FILE__, __LINE__, "Too many statistic counters");
+ syslog(LOG_ERR, "%s:%d: %s", __FILE__, __LINE__,
+ "Too many statistic counters");
retVal = NULL;
} else {
strcpy(my->statistics[i].name, name);
}
}
-int Worker_getStatistic(const char *name, const char *stat, unsigned long int *value) {
+int Worker_getStatistic(const char *name, const char *stat,
+ unsigned long int *value)
+{
int retVal = -1;
int i;
Worker myS, *my = &myS;
if (-1 == openStatShm(my)) {
*value = 0;
} else {
- for (i = 0; i < WORKER_MAX_NUM_STATS && strcmp(my->statistics[i].name, "") != 0; i++) {
+ for (i = 0;
+ i < WORKER_MAX_NUM_STATS
+ && strcmp(my->statistics[i].name, "") != 0; i++) {
if (strcmp(stat, my->statistics[i].name) == 0) {
*value = my->statistics[i].value;
retVal = 0;
}
return retVal;
}
-