-static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/tcldaq.c,v 6.9 2002-11-09 10:03:18 hadaq Exp $";
+static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/tcldaq.c,v 6.10 2002-11-09 16:24:03 hadaq Exp $";
#define _GNU_SOURCE
#include <unistd.h>
int SystemCmd(ClientData clientData, Tcl_Interp * interp, int argc, char *argv[])
{
- int SystemCmdR = 0;
+ int SystemCmdR;
CLIENT *cl;
if (argc < 3) {
Tcl_AppendResult(interp, "usage: c_system <agent> command", NULL);
return TCL_ERROR;
}
+
strcpy(agents[nThr++], argv[1]);
if (NULL == (cl = clnt_create(argv[1], DAQAGENTPROG, DAQAGENTVERS, "tcp"))) {
- clnt_pcreateerror("clnt_create");
- SystemCmdR = -1;
+ Tcl_AppendResult(interp, clnt_spcreateerror(argv[1]), NULL);
+ SystemCmdR = TCL_ERROR;
} else {
- static struct timeval TIMEOUT = { 0, 0 };
+ struct timeval TIMEOUT = { 0, 0 };
+ struct rpc_err rpcErr;
+
clnt_control(cl, CLSET_TIMEOUT, (char *)&TIMEOUT);
- if (NULL == rpcsystem_1(&argv[2], cl)) {
- clnt_perror(cl, "rpcsystem_1");
- SystemCmdR = 0;
+ rpcsystem_1(&argv[2], cl); /* will produce a timeout */
+ clnt_geterr(cl, &rpcErr);
+
+ if (rpcErr.re_status != RPC_TIMEDOUT) { /* a real error */
+ Tcl_AppendResult(interp, clnt_sperror(cl, "rpcsystem_1"), NULL);
+ SystemCmdR = TCL_ERROR;
} else {
- SystemCmdR = 0;
+ SystemCmdR = TCL_OK;
}
clnt_destroy(cl);
}
- sprintf(interp->result, "%d", SystemCmdR);
- return SystemCmdR == 0 ? TCL_OK : TCL_ERROR;
+ return SystemCmdR;
}
int JoinAllCmd(ClientData clientData, Tcl_Interp * interp, int argc, char *argv[])
{
int JoinAllCmdR;
CLIENT *cl;
- int res;
+ int dummy;
- JoinAllCmdR = 0;
+ JoinAllCmdR = TCL_OK;
while (nThr > 0) {
--nThr;
if (NULL == (cl = clnt_create(agents[nThr], DAQAGENTPROG, DAQAGENTVERS, "tcp"))) {
- clnt_pcreateerror("clnt_create");
- JoinAllCmdR = -1;
+ Tcl_AppendResult(interp, clnt_spcreateerror(argv[1]), NULL);
+ JoinAllCmdR = TCL_ERROR;
} else {
- static struct timeval TIMEOUT = { 120, 0 };
+ struct timeval TIMEOUT = { 120, 0 };
+
clnt_control(cl, CLSET_TIMEOUT, (char *)&TIMEOUT);
- if (NULL == rpcjoin_1(&res, cl)) {
- clnt_perror(cl, "rpcjoin_1");
- JoinAllCmdR = -1;
- } else {
- JoinAllCmdR = 0;
+ if (NULL == rpcjoin_1(&dummy, cl)) {
+ Tcl_AppendResult(interp, clnt_sperror(cl, "rpcjoin_1"), NULL);
+ JoinAllCmdR = TCL_ERROR;
}
clnt_destroy(cl);
}
}
- sprintf(interp->result, "%d", JoinAllCmdR);
- return JoinAllCmdR == 0 ? TCL_OK : TCL_ERROR;
+ return JoinAllCmdR;
}
int Daq_Init(Tcl_Interp * interp)