#include "trbrpc.h"
-static const char trbnetd_version[] = "$Revision: 1.11 $";
+static const char trbnetd_version[] = "$Revision: 1.12 $";
+
+static int daemon_lock = 0;
int trbnetrpcprog_1_freeresult(SVCXPRT * transp,
xdrproc_t xdr_result, caddr_t result)
int status;
/* allocate buffer memory */
+ retVal->data.Buffer_len = 0;
retVal->data.Buffer_val = (uint32_t *) malloc(sizeof(uint32_t) * dsize);
if (retVal->data.Buffer_val == NULL) {
fprintf(stderr, "register_read: malloc failed\n");
retVal->status.trb_errno = TRB_RPC_ERROR;
return TRUE;
}
-
+
+ if (daemon_lock == 1) {
+ retVal->status.retVal = -128;
+ return TRUE;
+ }
+
status = trb_register_read(trb_address, reg_address,
(uint32_t *) retVal->data.Buffer_val, dsize);
retVal->data.Buffer_len = status == -1 ? 0 : status;
struct svc_req * rqstp)
{
int status;
- /* allocate buffer memory */
+ /* allocate buffer memory */
+ retVal->data.Buffer_len = 0;
retVal->data.Buffer_val = (uint32_t *) malloc(sizeof(uint32_t) * dsize);
if (retVal->data.Buffer_val == NULL) {
fprintf(stderr, "registertime_read: malloc failed\n");
return TRUE;
}
+ if (daemon_lock == 1) {
+ retVal->status.retVal = -128;
+ return TRUE;
+ }
+
status = trb_registertime_read(trb_address, reg_address,
(uint32_t *) retVal->data.Buffer_val, dsize);
retVal->data.Buffer_len = status == -1 ? 0 : status;
int status;
/* allocate buffer memory */
+ retVal->data.Buffer_len = 0;
retVal->data.Buffer_val = (uint32_t *) malloc(sizeof(uint32_t) * dsize);
if (retVal->data.Buffer_val == NULL) {
fprintf(stderr, "register_read_mem: malloc failed\n");
retVal->status.retVal = -1;
return TRUE;
}
+
+ if (daemon_lock == 1) {
+ retVal->status.retVal = -128;
+ return TRUE;
+ }
status = trb_register_read_mem(trb_address, reg_address, option, size,
(uint32_t *) retVal->data.Buffer_val, dsize);
int status;
/* allocate buffer memory */
+ retVal->data.Buffer_len = 0;
retVal->data.Buffer_val = (uint32_t *) malloc(sizeof(uint32_t) * dsize);
if (retVal->data.Buffer_val == NULL) {
fprintf(stderr, "registertime_read_mem: malloc failed\n");
uint32_t value,
Status* retVal,
struct svc_req* rqstp)
-{
+{
+ if (daemon_lock == 1) {
+ retVal->retVal = -128;
+ return TRUE;
+ }
+
retVal->retVal = trb_register_write(trb_address, reg_address, value);
copyStatus(retVal);
Status* retVal,
struct svc_req* rqstp)
{
+ if (daemon_lock == 1) {
+ retVal->retVal = -128;
+ return TRUE;
+ }
+
retVal->retVal =
trb_register_write_mem(trb_address, reg_address, option,
(uint32_t*)data.Buffer_val, data.Buffer_len);
struct svc_req* rqstp)
{
int status;
-
+
/* allocate buffer memory */
- retVal->data.Buffer_val = NULL;
retVal->data.Buffer_len = 0;
retVal->data.Buffer_val = (uint32_t*)malloc(sizeof(uint32_t) * dsize);
retVal->status.retVal = -1;
return TRUE;
}
-
+
+ if (daemon_lock == 1) {
+ retVal->status.retVal = -128;
+ return TRUE;
+ }
+
status = trb_read_uid(trb_address,
(uint32_t*)retVal->data.Buffer_val,
dsize);
Status* retVal,
struct svc_req* rqstp)
{
+ if (daemon_lock == 1) {
+ retVal->retVal = -128;
+ return TRUE;
+ }
+
retVal->retVal = trb_set_address(uid, endpoint, trb_address);
copyStatus(retVal);
bool_t network_reset_1_svc(Status* retVal,
struct svc_req* rqstp)
{
+ if (daemon_lock == 1) {
+ retVal->retVal = -128;
+ return TRUE;
+ }
+
retVal->retVal = network_reset();
copyStatus(retVal);
Status* retVal,
struct svc_req* rqstp)
{
+ if (daemon_lock == 1) {
+ retVal->retVal = -128;
+ return TRUE;
+ }
+
retVal->retVal = trb_send_trigger(type, trg_info, trg_random, trg_number);
copyStatus(retVal);
Status* retVal,
struct svc_req* rqstp)
{
+ if (daemon_lock == 1) {
+ retVal->retVal = -128;
+ return TRUE;
+ }
+
retVal->retVal =
trb_send_trigger_rich(input, type, trg_info, trg_random, trg_number);
copyStatus(retVal);
int status;
/* allocate buffer memory */
+ retVal->data.Buffer_len = 0;
retVal->data.Buffer_val = (uint32_t *) malloc(sizeof(uint32_t) * dsize);
if (retVal->data.Buffer_val == NULL) {
fprintf(stderr, "ipu_data_read: malloc failed\n");
retVal->status.retVal = -1;
return TRUE;
}
-
+
+ if (daemon_lock == 1) {
+ retVal->status.retVal = -128;
+ return TRUE;
+ }
+
status = trb_ipu_data_read(type, trg_info, trg_random, trg_number,
(uint32_t *)retVal->data.Buffer_val, dsize);
int status;
/* allocate buffer memory */
+ retVal->data.Buffer_len = 0;
retVal->data.Buffer_val = (uint32_t *) malloc(sizeof(uint32_t) * 1);
if (retVal->data.Buffer_val == NULL) {
fprintf(stderr, "fpga_register_read: malloc failed\n");
return TRUE;
}
+ if (daemon_lock == 1) {
+ retVal->status.retVal = -128;
+ return TRUE;
+ }
+
status = fpga_register_read(reg_address,
(uint32_t *)retVal->data.Buffer_val);
Status* retVal,
struct svc_req* rqstp)
{
+ if (daemon_lock == 1) {
+ retVal->retVal = -128;
+ return TRUE;
+ }
+
retVal->retVal = fpga_register_write(reg_address, value);
copyStatus(retVal);
Status* retVal,
struct svc_req* rqstp)
{
+ if (daemon_lock == 1) {
+ retVal->retVal = -128;
+ return TRUE;
+ }
+
retVal->retVal = trb_fifo_flush(channel);
copyStatus(retVal);
bool_t com_reset_1_svc(Status* retVal,
struct svc_req* rqstp)
{
+ if (daemon_lock == 1) {
+ retVal->retVal = -128;
+ return TRUE;
+ }
+
retVal->retVal = com_reset();
copyStatus(retVal);
Status* retVal,
struct svc_req* rqstp)
{
+ if (daemon_lock == 1) {
+ retVal->retVal = -128;
+ return TRUE;
+ }
+
retVal->retVal =
trb_register_modify(trb_address, reg_address, mode, bitMask, bitValue);
/* ------ MAIN ---------------------------------------------------------- */
+static void blockDaemon(int sig) {
+ switch (sig) {
+
+ case SIGUSR1:
+ daemon_lock = 1;
+ break;
+
+ case SIGUSR2:
+ daemon_lock = 0;
+ break;
+
+ default:
+ break;
+ }
+}
+
void usage(const char *progName)
{
fprintf(stdout, "Usage: %s [-h] [-f]\n", progName);
fprintf(stdout, " -h give this help\n");
fprintf(stdout, " -f execute as foreground process\n");
fprintf(stdout, " -V version number\n");
+ fprintf(stdout, "\nSignals:\n");
+ fprintf(stdout, " USR1 lock daemon\n");
+ fprintf(stdout, " USR2 unlock daemon\n");
}
static pid_t myPid = -1;
sigemptyset(&blockSet);
sigaddset(&blockSet, SIGPIPE);
sigprocmask(SIG_BLOCK, &blockSet, NULL);
-
+
+ /* Add SIGUSR1 for blocking daemon */
+ if (signal(SIGUSR1, blockDaemon) == SIG_ERR) abort();
+ if (signal(SIGUSR2, blockDaemon) == SIG_ERR) abort();
+
pmap_unset(TRBNETRPCPROG, TRBNETRPCVERS);
transp = svctcp_create(RPC_ANYSOCK, 0, 0);
#include <stdio.h>
#include <rpc/rpc.h> /* always needed */
+#include <unistd.h>
#include "trbrpc.h" /* will be generated by rpcgen */
#include <trberror.h>
#include "trbnet.h"
-const char trbnet_version[] = "$Revision: 1.10 $ RPC";
+const char trbnet_version[] = "$Revision: 1.11 $ RPC";
unsigned int trb_debug = 0;
unsigned int trb_dma = 0;
static CLIENT *trb_client = NULL;
static char trb_server[128] = "";
+static const unsigned int SLEEP_TIME = 2;
static void copyStatus(const Status* status)
{
RetVal retVal;
if (trb_client == NULL) return -1;
+ do {
+ retVal.data.Buffer_val = data;
+ retVal.data.Buffer_len = dsize;
+
+ status =
+ register_read_1(trb_address, reg_address, dsize,
+ &retVal, trb_client);
+
+ if (status != RPC_SUCCESS) {
+ /*
+ * An error occurred while calling the server.
+ * Print error message and stop.
+ */
+ trb_errno = status + 256;
+ return -1;
+ }
+ if (retVal.status.retVal != -128) break;
+ sleep(SLEEP_TIME);
+ } while (1);
- retVal.data.Buffer_val = data;
- retVal.data.Buffer_len = dsize;
-
- status =
- register_read_1(trb_address, reg_address, dsize,
- &retVal, trb_client);
-
- if (status != RPC_SUCCESS) {
- /*
- * An error occurred while calling the server.
- * Print error message and stop.
- */
- trb_errno = status + 256;
- return -1;
- }
-
copyStatus(&retVal.status);
return retVal.status.retVal;
}
RetVal retVal;
if (trb_client == NULL) return -1;
-
- retVal.data.Buffer_val = data;
- retVal.data.Buffer_len = dsize;
+ do {
+ retVal.data.Buffer_val = data;
+ retVal.data.Buffer_len = dsize;
- status =
- registertime_read_1(trb_address, reg_address, dsize,
+ status =
+ registertime_read_1(trb_address, reg_address, dsize,
&retVal, trb_client);
- if (status != RPC_SUCCESS) {
- /*
- * An error occurred while calling the server.
- * Print error message and stop.
- */
- trb_errno = status + 256;
- return -1;
- }
-
+ if (status != RPC_SUCCESS) {
+ /*
+ * An error occurred while calling the server.
+ * Print error message and stop.
+ */
+ trb_errno = status + 256;
+ return -1;
+ }
+ if (retVal.status.retVal != -128) break;
+ sleep(SLEEP_TIME);
+ } while (1);
+
copyStatus(&retVal.status);
return retVal.status.retVal;
}
RetVal retVal;
if (trb_client == NULL) return -1;
-
- retVal.data.Buffer_val = data;
- retVal.data.Buffer_len = dsize;
-
- status =
- register_read_mem_1(trb_address, reg_address, option, size, dsize,
- &retVal, trb_client);
-
- if (status != RPC_SUCCESS) {
- /*
- * An error occurred while calling the server.
- * Print error message and stop.
- */
- trb_errno = status + 256;
- return -1;
- }
+ do {
+ retVal.data.Buffer_val = data;
+ retVal.data.Buffer_len = dsize;
+
+ status =
+ register_read_mem_1(trb_address, reg_address, option, size, dsize,
+ &retVal, trb_client);
+
+ if (status != RPC_SUCCESS) {
+ /*
+ * An error occurred while calling the server.
+ * Print error message and stop.
+ */
+ trb_errno = status + 256;
+ return -1;
+ }
+ if (retVal.status.retVal != -128) break;
+ sleep(SLEEP_TIME);
+ } while (1);
copyStatus(&retVal.status);
return retVal.status.retVal;
{
enum clnt_stat status;
RetVal retVal;
-
+
if (trb_client == NULL) return -1;
+ do {
+ retVal.data.Buffer_val = data;
+ retVal.data.Buffer_len = dsize;
+
+ status =
+ registertime_read_mem_1(trb_address, reg_address, option, size, dsize,
+ &retVal, trb_client);
+
+ if (status != RPC_SUCCESS) {
+ /*
+ * An error occurred while calling the server.
+ * Print error message and stop.
+ */
+ trb_errno = status + 256;
+ return -1;
+ }
+ if (retVal.status.retVal != -128) break;
+ sleep(SLEEP_TIME);
+ } while (1);
- retVal.data.Buffer_val = data;
- retVal.data.Buffer_len = dsize;
-
- status =
- registertime_read_mem_1(trb_address, reg_address, option, size, dsize,
- &retVal, trb_client);
-
- if (status != RPC_SUCCESS) {
- /*
- * An error occurred while calling the server.
- * Print error message and stop.
- */
- trb_errno = status + 256;
- return -1;
- }
-
copyStatus(&retVal.status);
return retVal.status.retVal;
}
RetVal retVal;
if (trb_client == NULL) return -1;
+ do {
+ retVal.data.Buffer_val = data;
+ retVal.data.Buffer_len = dsize;
+
+ status = read_uid_1(trb_address, dsize, &retVal, trb_client);
+
+ if (status != RPC_SUCCESS) {
+ /*
+ * An error occurred while calling the server.
+ * Print error message and stop.
+ */
+ trb_errno = status + 256;
+ return -1;
+ }
- retVal.data.Buffer_val = data;
- retVal.data.Buffer_len = dsize;
-
- status = read_uid_1(trb_address, dsize, &retVal, trb_client);
-
- if (status != RPC_SUCCESS) {
- /*
- * An error occurred while calling the server.
- * Print error message and stop.
- */
- trb_errno = status + 256;
- return -1;
- }
+ if (retVal.status.retVal != -128) break;
+ sleep(SLEEP_TIME);
+ } while (1);
copyStatus(&retVal.status);
return retVal.status.retVal;
Status retVal;
if (trb_client == NULL) return -1;
-
- status = register_write_1(trb_address, reg_address, value,
- &retVal, trb_client);
+ do {
+ status = register_write_1(trb_address, reg_address, value,
+ &retVal, trb_client);
- if (status != RPC_SUCCESS) {
- /*
- * An error occurred while calling the server.
- * Print error message and stop.
- */
- trb_errno = status + 256;
- return -1;
- }
+ if (status != RPC_SUCCESS) {
+ /*
+ * An error occurred while calling the server.
+ * Print error message and stop.
+ */
+ trb_errno = status + 256;
+ return -1;
+ }
+ if (retVal.retVal != -128) break;
+ sleep(SLEEP_TIME);
+ } while (1);
copyStatus(&retVal);
return retVal.retVal;
Buffer buffer;
if (trb_client == NULL) return -1;
+ do {
+ buffer.Buffer_val = (uint32_t*)data;
+ buffer.Buffer_len = size;
- buffer.Buffer_val = (uint32_t*)data;
- buffer.Buffer_len = size;
-
- status = register_write_mem_1(trb_address, reg_address, option, buffer,
- &retVal, trb_client);
-
- if (status != RPC_SUCCESS) {
- /*
- * An error occurred while calling the server.
- * Print error message and stop.
- */
- trb_errno = status + 256;
- return -1;
- }
+ status = register_write_mem_1(trb_address, reg_address, option, buffer,
+ &retVal, trb_client);
+
+ if (status != RPC_SUCCESS) {
+ /*
+ * An error occurred while calling the server.
+ * Print error message and stop.
+ */
+ trb_errno = status + 256;
+ return -1;
+ }
+ if (retVal.retVal != -128) break;
+ sleep(SLEEP_TIME);
+ } while (1);
copyStatus(&retVal);
return retVal.retVal;
Status retVal;
if (trb_client == NULL) return -1;
-
- status = set_address_1(uid, endpoint, trb_address,
- &retVal, trb_client);
-
- if (status != RPC_SUCCESS) {
- /*
- * An error occurred while calling the server.
- * Print error message and stop.
- */
- trb_errno = status + 256;
- return -1;
- }
+ do {
+ status = set_address_1(uid, endpoint, trb_address,
+ &retVal, trb_client);
+
+ if (status != RPC_SUCCESS) {
+ /*
+ * An error occurred while calling the server.
+ * Print error message and stop.
+ */
+ trb_errno = status + 256;
+ return -1;
+ }
+ if (retVal.retVal != -128) break;
+ sleep(SLEEP_TIME);
+ } while (1);
copyStatus(&retVal);
return retVal.retVal;
RetVal retVal;
if (trb_client == NULL) return -1;
+ do {
+ retVal.data.Buffer_val = data;
+ retVal.data.Buffer_len = dsize;
- retVal.data.Buffer_val = data;
- retVal.data.Buffer_len = dsize;
-
- status =
- ipu_data_read_1(type, trg_info, trg_random, trg_number, dsize,
- &retVal, trb_client);
-
- if (status != RPC_SUCCESS) {
- /*
- * An error occurred while calling the server.
- * Print error message and stop.
- */
- trb_errno = status + 256;
- return -1;
- }
+ status =
+ ipu_data_read_1(type, trg_info, trg_random, trg_number, dsize,
+ &retVal, trb_client);
+
+ if (status != RPC_SUCCESS) {
+ /*
+ * An error occurred while calling the server.
+ * Print error message and stop.
+ */
+ trb_errno = status + 256;
+ return -1;
+ }
+ if (retVal.status.retVal != -128) break;
+ sleep(SLEEP_TIME);
+ } while (1);
copyStatus(&retVal.status);
return retVal.status.retVal;
Status retVal;
if (trb_client == NULL) return -1;
-
- status = send_trigger_1(type, info, random, number, &retVal, trb_client);
-
- if (status != RPC_SUCCESS) {
- /*
- * An error occurred while calling the server.
- * Print error message and stop.
- */
- trb_errno = status + 256;
- return -1;
- }
+ do {
+ status = send_trigger_1(type, info, random, number, &retVal, trb_client);
+
+ if (status != RPC_SUCCESS) {
+ /*
+ * An error occurred while calling the server.
+ * Print error message and stop.
+ */
+ trb_errno = status + 256;
+ return -1;
+ }
+ if (retVal.retVal != -128) break;
+ sleep(SLEEP_TIME);
+ } while (1);
copyStatus(&retVal);
return retVal.retVal;
Status retVal;
if (trb_client == NULL) return -1;
+ do {
+ status = send_trigger_rich_1(input, type, info, random, number,
+ &retVal, trb_client);
+
+ if (status != RPC_SUCCESS) {
+ /*
+ * An error occurred while calling the server.
+ * Print error message and stop.
+ */
+ trb_errno = status + 256;
+ return -1;
+ }
+ if (retVal.retVal != -128) break;
+ sleep(SLEEP_TIME);
+ } while (1);
- status = send_trigger_rich_1(input, type, info, random, number,
- &retVal, trb_client);
-
- if (status != RPC_SUCCESS) {
- /*
- * An error occurred while calling the server.
- * Print error message and stop.
- */
- trb_errno = status + 256;
- return -1;
- }
-
copyStatus(&retVal);
return retVal.retVal;
}
RetVal retVal;
if (trb_client == NULL) return -1;
+ do {
+ retVal.data.Buffer_val = value;
+ retVal.data.Buffer_len = 1;
- retVal.data.Buffer_val = value;
- retVal.data.Buffer_len = 1;
-
- status = fpga_register_read_1(reg_address,
- &retVal, trb_client);
-
- if (status != RPC_SUCCESS) {
- /*
- * An error occurred while calling the server.
- * Print error message and stop.
- */
- trb_errno = status + 256;
- return -1;
- }
+ status = fpga_register_read_1(reg_address,
+ &retVal, trb_client);
+
+ if (status != RPC_SUCCESS) {
+ /*
+ * An error occurred while calling the server.
+ * Print error message and stop.
+ */
+ trb_errno = status + 256;
+ return -1;
+ }
+ if (retVal.status.retVal != -128) break;
+ sleep(SLEEP_TIME);
+ } while (1);
copyStatus(&retVal.status);
return retVal.status.retVal;
Status retVal;
if (trb_client == NULL) return -1;
+ do {
+ status = fpga_register_write_1(reg_address, value, &retVal, trb_client);
+
+ if (status != RPC_SUCCESS) {
+ /*
+ * An error occurred while calling the server.
+ * Print error message and stop.
+ */
+ trb_errno = status + 256;
+ return -1;
+ }
+ if (retVal.retVal != -128) break;
+ sleep(SLEEP_TIME);
+ } while (1);
- status = fpga_register_write_1(reg_address, value, &retVal, trb_client);
-
- if (status != RPC_SUCCESS) {
- /*
- * An error occurred while calling the server.
- * Print error message and stop.
- */
- trb_errno = status + 256;
- return -1;
- }
-
copyStatus(&retVal);
return retVal.retVal;
}
Status retVal;
if (trb_client == NULL) return -1;
+ do {
+ status = trb_fifo_flush_1(channel, &retVal, trb_client);
+
+ if (status != RPC_SUCCESS) {
+ /*
+ * An error occurred while calling the server.
+ * Print error message and stop.
+ */
+ trb_errno = status + 256;
+ return -1;
+ }
+ if (retVal.retVal != -128) break;
+ sleep(SLEEP_TIME);
+ } while (1);
- status = trb_fifo_flush_1(channel, &retVal, trb_client);
-
- if (status != RPC_SUCCESS) {
- /*
- * An error occurred while calling the server.
- * Print error message and stop.
- */
- trb_errno = status + 256;
- return -1;
- }
-
copyStatus(&retVal);
return retVal.retVal;
}
Status retVal;
if (trb_client == NULL) return -1;
-
- status = network_reset_1(&retVal, trb_client);
+ do {
+ status = network_reset_1(&retVal, trb_client);
+
+ if (status != RPC_SUCCESS) {
+ /*
+ * An error occurred while calling the server.
+ * Print error message and stop.
+ */
+ trb_errno = status + 256;
+ return -1;
+ }
+ if (retVal.retVal != -128) break;
+ sleep(SLEEP_TIME);
+ } while (1);
- if (status != RPC_SUCCESS) {
- /*
- * An error occurred while calling the server.
- * Print error message and stop.
- */
- trb_errno = status + 256;
- return -1;
- }
-
copyStatus(&retVal);
return retVal.retVal;
}
Status retVal;
if (trb_client == NULL) return -1;
-
- status =
- register_modify_1(trb_address, reg_address, mode, bitMask, bitValue,
- &retVal, trb_client);
-
- if (status != RPC_SUCCESS) {
- /*
- * An error occurred while calling the server.
- * Print error message and stop.
- */
- trb_errno = status + 256;
- return -1;
- }
+ do {
+ status =
+ register_modify_1(trb_address, reg_address, mode, bitMask, bitValue,
+ &retVal, trb_client);
+
+ if (status != RPC_SUCCESS) {
+ /*
+ * An error occurred while calling the server.
+ * Print error message and stop.
+ */
+ trb_errno = status + 256;
+ return -1;
+ }
+ if (retVal.retVal != -128) break;
+ sleep(SLEEP_TIME);
+ } while (1);
copyStatus(&retVal);
return retVal.retVal;