Here is a test case that illustrates the current problem (open() always
failing). There are three files: resmgr.cpp, client.cpp, and Makefile;
the names are self-explanatory.
There are two constants defined at the top of resmgr.cpp; you can change
these to reflect the names of the nodes to be used.
To run the test, compile the two programs and place them both in “/tmp/”
(I have the startup path for the client hardcoded to that location).
Start the resource manager. After five seconds, it spawns the client on
a remote node. The client attempts to open the resource manager once
per second for ten seconds. It exits; 18 seconds after starting, the
resource manager also exits.
All output is to the syslog; here’s an example of what I’ve been getting:
Jun 10 20:33:45 nto resmgr[11743269-1]: spawning client
Jun 10 20:27:55 nto client[1691772-1]: making attempt 1 on /net/dev-1/resmgr
Jun 10 20:27:55 nto client[1691772-1]: Unable to open Exec’s file; errno 309
Jun 10 20:27:56 nto client[1691772-1]: making attempt 2 on /net/dev-1/resmgr
Jun 10 20:27:56 nto client[1691772-1]: Unable to open Exec’s file; errno 3
Jun 10 20:27:57 nto client[1691772-1]: making attempt 3 on /net/dev-1/resmgr
Jun 10 20:27:57 nto client[1691772-1]: Unable to open Exec’s file; errno 3
Jun 10 20:27:58 nto client[1691772-1]: making attempt 4 on /net/dev-1/resmgr
Jun 10 20:27:58 nto client[1691772-1]: Unable to open Exec’s file; errno 3
Jun 10 20:27:59 nto client[1691772-1]: making attempt 5 on /net/dev-1/resmgr
Jun 10 20:27:59 nto client[1691772-1]: Unable to open Exec’s file; errno 3
Jun 10 20:28:00 nto client[1691772-1]: making attempt 6 on /net/dev-1/resmgr
Jun 10 20:28:00 nto client[1691772-1]: Unable to open Exec’s file; errno 3
Jun 10 20:28:01 nto client[1691772-1]: making attempt 7 on /net/dev-1/resmgr
Jun 10 20:28:01 nto client[1691772-1]: Unable to open Exec’s file; errno 3
Jun 10 20:28:02 nto client[1691772-1]: making attempt 8 on /net/dev-1/resmgr
Jun 10 20:28:02 nto client[1691772-1]: Unable to open Exec’s file; errno 3
Jun 10 20:28:03 nto client[1691772-1]: making attempt 9 on /net/dev-1/resmgr
Jun 10 20:28:03 nto client[1691772-1]: Unable to open Exec’s file; errno 3
Jun 10 20:28:04 nto client[1691772-1]: making attempt 10 on
/net/dev-1/resmgr
Jun 10 20:28:04 nto client[1691772-1]: Unable to open Exec’s file; errno 3
Jun 10 20:28:05 nto client[1691772-1]: retries exhausted
Jun 10 20:33:58 nto resmgr[11743269-1]: exiting
Thanks for looking at this.
Josh
==================================
Makefile:
all: resmgr client
client: client.cpp
QCC -o $@ client.cpp
resmgr: resmgr.cpp
QCC -o $@ resmgr.cpp
\
resmgr.cpp
#include <errno.h>
#include <fcntl.h>
#include <spawn.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <unix.h>
#include <sys/iofunc.h>
#include <sys/dispatch.h>
#include <sys/netmgr.h>
const char *local_node = “dev-1”;
const char *remote_node = “dev-2”;
static dispatch_t *dpp;
static resmgr_io_funcs_t io_funcs;
int set_up_timing(void);
int timer_handler(message_context_t *ctp, int code, unsigned flags, void
*handle
int main(int argc, char *argv[])
{
iofunc_attr_t attr;
resmgr_connect_funcs_t connect_funcs;
dispatch_context_t *ctp;
resmgr_attr_t resmgr_attr;
// Daemonize ourselves.
switch (fork()) {
case -1:
syslog(LOG_ERR, “fork() failed”);
exit(EXIT_FAILURE);
break;
case 0:
break;
default:
exit(EXIT_SUCCESS);
break;
}
if (setsid() == -1) {
syslog(LOG_ERR, “setsid() failed”);
exit(EXIT_FAILURE);
}
openlog(“resmgr”, LOG_PID, LOG_LOCAL0);
if((dpp = dispatch_create()) == NULL) {
syslog(LOG_ERR, “dispatch_create() failed”);
exit(EXIT_FAILURE);
}
memset(&resmgr_attr, 0, sizeof resmgr_attr);
resmgr_attr.nparts_max = 1;
resmgr_attr.msg_max_size = 2048;
iofunc_func_init(_RESMGR_CONNECT_NFUNCS, &connect_funcs,
_RESMGR_IO_NFUNCS, &
iofunc_attr_init(&attr, S_IFNAM | 0666, 0, 0);
if(resmgr_attach(dpp, &resmgr_attr, “/resmgr”, _FTYPE_ANY, 0,
&connect_funcs,
syslog(LOG_ERR, “resmgr_attach() failed”);
exit(EXIT_FAILURE);
}
ctp = dispatch_context_alloc(dpp);
if (set_up_timing() == -1) {
syslog(LOG_ERR, “set_up_timing() failed”);
exit(EXIT_FAILURE);
}
while (1) {
if ((ctp = dispatch_block(ctp)) == NULL) {
syslog(LOG_ERR, “dispatch_block() failed”);
exit(EXIT_FAILURE);
}
dispatch_handler(ctp);
}
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
int set_up_timing(void)
{
struct _itimer itime;
struct _clockperiod period;
struct sigevent timerEvent;
int timerId;
memset(&period, 0, sizeof(period));
period.nsec = 500000;
if (ClockPeriod(CLOCK_REALTIME, &period, NULL, 0) == -1) {
syslog(LOG_ERR, “ClockPeriod() failed”);
return -1;
}
if ((timerEvent.sigev_code = pulse_attach(dpp, MSG_FLAG_ALLOC_PULSE,
0, &time
syslog(LOG_ERR, “pulse_attach() failed”);
return -1;
}
if ((timerEvent.sigev_coid = message_connect(dpp,
MSG_FLAG_SIDE_CHANNEL)) ==
syslog(LOG_ERR, “message_connect() failed”);
return -1;
}
timerEvent.sigev_notify = SIGEV_PULSE;
timerEvent.sigev_priority = -1;
timerEvent.sigev_value.sival_int = 0;
if ((timerId = TimerCreate(CLOCK_REALTIME, &timerEvent)) == -1) {
syslog(LOG_ERR, “TimerCreate() failed”);
return -1;
}
memset(&itime, 0, sizeof(itime));
itime.nsec = 10000000;
itime.interval_nsec = 10000000;
if (TimerSettime(timerId, 0, &itime, NULL) == -1) {
syslog(LOG_ERR, “TimerSettime() failed”);
return -1;
}
return 0;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
int timer_handler(message_context_t *ctp, int code, unsigned flags, void
*handle
{
static int tickCount = 0;
tickCount++;
if (tickCount == 500) {
char *argv[3];
struct inheritance inherit;
memset(&inherit, 0, sizeof(inherit));
syslog(LOG_INFO, “spawning client”);
inherit.flags |= SPAWN_SETND;
inherit.nd = netmgr_strtond(remote_node, NULL);
argv[0] = strdup(“client”);
argv[1] = strdup(local_node);
argv[2] = NULL;
if (spawn("/tmp/client", 0, NULL, &inherit, argv, NULL) == -1) {
syslog(LOG_ERR, “spawn() failed; errno %d”, errno);
return -1;
}
free(argv[1]);
free(argv[0]);
}
if (tickCount == 1800) {
syslog(LOG_INFO, “exiting”);
exit(EXIT_SUCCESS);
}
return 0;
}
\
client.cpp
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
int main(int argc, char* argv[])
{
char buf[128];
int execfd = -1;
int iii;
openlog(“client”, LOG_PID, LOG_LOCAL0);
sprintf(buf, “/net/%s/resmgr”, argv[1]);
iii = 1;
while ((execfd == -1) && (iii < 11)) {
syslog(LOG_INFO, “making attempt %d on %s”, iii, buf);
if ((execfd = open(buf, O_RDONLY)) == -1) {
syslog(LOG_ERR, “Unable to open Exec’s file; errno %d”, errno);
}
sleep(1);
iii++;
}
if (execfd == -1) {
syslog(LOG_INFO, “retries exhausted”);
exit(EXIT_FAILURE);
}
syslog(LOG_INFO, “reached here, must have opened resource manager”);
return 0;
}