Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: dispatching any action causes actmon/actlog to crash with SIGSEGV #2835

Open
wants to merge 3 commits into
base: alpha
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion actions/actlogp.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ static void MessageAst(void *dummy __attribute__((unused)), char *reply)
}
free(event->msg);
free(event);
CheckIn(0);
}

inline static void _EventUpdate(LinkedEvent *event)
Expand Down
1 change: 0 additions & 1 deletion actions/actmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <ctype.h>
#include <mdsplus/mdsplus.h>
static void Exit(Widget w, int *tag, XtPointer callback_data);
static void MessageAst();
static void EventUpdate();
static void Phase(LinkedEvent *event);
static void Dispatched(LinkedEvent *event);
Expand Down
16 changes: 16 additions & 0 deletions actions/testing/ServerShrTest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

export distest_path=/tmp/$USER/distest

mkdir -p $distest_path

mdsip -p 9997 -s > server_9997.log 2> server_9997.err & # Monitor server
mdsip -p 9998 -s > server_9998.log 2> server_9998.err & # Action server
mdsip -p 9999 -s > server_9999.log 2> server_9999.err & # Dispatch server
actlog -monitor localhost:9997 > actlog.log 2> actlog.err &

mdstcl @build_tree

mdstcl @test_action

pkill -P $$
7 changes: 7 additions & 0 deletions actions/testing/build_tree.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
edit distest /shot=1 /new
add node act01 /usage=action
write
put/extend ACT01
Build_Action(Build_Dispatch(2,"localhost:9998","INIT",10,*),BUILD_FUNCTION(BUILTIN_OPCODE("COMMA"),BUILD_FUNCTION(BUILTIN_OPCODE("WRITE"),*,"Test action"),1))

close
6 changes: 6 additions & 0 deletions actions/testing/test_action.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dispatch /command /server=localhost:9999 set tree distest /shot=1
wait 1
dispatch /command /server=localhost:9999 dispatch/build/monitor=localhost:9997
wait 1
dispatch /command /server=localhost:9999 dispatch/phase/monitor=localhost:9997 init
wait 1
8 changes: 4 additions & 4 deletions include/servershr.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ EXPORT extern int ServerBuildDispatchTable(char *wildcard, char *monitor_name,
void **table);
EXPORT extern int ServerCloseTrees(char *server);
EXPORT extern int ServerCreatePulse(int *id, char *server, char *tree, int shot,
void (*ast)(), void *astprm, int *retstatus,
void (*ast)(void *, char *), void *astprm, int *retstatus,
pthread_rwlock_t *lock,
void (*before_ast)());
EXPORT extern int ServerDispatchAction(int *id, char *server, char *tree,
int shot, int nid, void (*ast)(),
int shot, int nid, void (*ast)(void *, char *),
void *astprm, int *retstatus,
pthread_rwlock_t *lock, int *socket,
void (*before_ast)());
EXPORT extern int ServerDispatchClose(void *vtable);
EXPORT extern int ServerDispatchCommand(int *id, char *server, char *cli,
char *command, void (*ast)(),
char *command, void (*ast)(void *, char *),
void *astprm, int *retstatus,
pthread_rwlock_t *lock,
void (*before_ast)());
Expand All @@ -51,7 +51,7 @@ EXPORT extern int ServerDispatchPhase(int *id, void *vtable, char *phasenam,
const char *monitor);
EXPORT extern int ServerFailedEssential(void *vtable, int reset);
EXPORT extern char *ServerFindServers(void **ctx, char *wild_match);
EXPORT extern int ServerMonitorCheckin(char *server, void (*ast)(),
EXPORT extern int ServerMonitorCheckin(char *server, void (*ast)(void *, char *),
void *astparam);
EXPORT extern int ServerSetLogging(char *server, char logging_mode);
EXPORT extern int ServerStartServer(char *server);
Expand Down
4 changes: 2 additions & 2 deletions servershr/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static void Client_cleanup_jobs(Client *c, fd_set *fdactive)
Job *j = Job_pop_by_conid(conid);
if (j)
{
Job_callback_done(j, ServerPATH_DOWN, FALSE);
Job_callback_done(j, ServerPATH_DOWN, NULL, FALSE);
free(j);
}
else
Expand Down Expand Up @@ -198,7 +198,7 @@ static void Client_do_message(Client *c, fd_set *fdactive)
j = Job_get_by_jobid(MonJob);
if (j)
{
Job_callback_done(j, status, TRUE);
Job_callback_done(j, status, msg, TRUE);
}
else
{
Expand Down
14 changes: 7 additions & 7 deletions servershr/Job.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ typedef struct job
int conid;
int *retstatus;
pthread_rwlock_t *lock;
void (*callback_done)();
void (*callback_done)(void *, char*);
void (*callback_before)();
void *callback_param;
pthread_cond_t *cond;
Expand All @@ -30,7 +30,7 @@ static Job *Jobs = NULL;
static int MonJob = -1;

static Job *newJob(int conid, int *retstatus, pthread_rwlock_t *lock,
void (*callback_done)(void *),
void (*callback_done)(void *, char *),
void *callback_param,
void (*callback_before)(void *))
{
Expand Down Expand Up @@ -71,7 +71,7 @@ static void Job_pop(Job *job)
static int Job_register(int *msgid,
int conid, int *retstatus, pthread_rwlock_t *lock,
void *callback_param,
void (*callback_done)(void *),
void (*callback_done)(void *, char *),
void (*callback_before)(void *))
{
Job *j = newJob(conid, retstatus, lock, callback_param, callback_done, callback_before);
Expand Down Expand Up @@ -107,10 +107,10 @@ static void Job_callback_before(Job *job)
}

/// returns true if job was popped
static int Job_callback_done(Job *j, int status, int remove)
static int Job_callback_done(Job *j, int status, char *msg, int remove)
{
MDSDBG(JOB_PRI " status=%d, remove=%d", JOB_VAR(j), status, remove);
void (*callback_done)(void *);
void (*callback_done)(void *, char *);
const int is_mon = j->jobid == MonJob;
if (j->lock)
pthread_rwlock_wrlock(j->lock);
Expand All @@ -122,7 +122,7 @@ static int Job_callback_done(Job *j, int status, int remove)
if (j->lock)
pthread_rwlock_unlock(j->lock);
if (callback_done)
callback_done(j->callback_param);
callback_done(j->callback_param, msg);
/**** If job has a condition, RemoveJob will not remove it. ***/
if (remove && !is_mon)
{
Expand Down Expand Up @@ -258,7 +258,7 @@ static void Job_cleanup(int status, int jobid)
do
{
MDSDBG(JOB_PRI " done", JOB_VAR(j));
Job_callback_done(j, status, FALSE);
Job_callback_done(j, status, NULL, FALSE);
free(j);
j = Job_pop_by_conid(conid);
} while (j);
Expand Down
2 changes: 1 addition & 1 deletion servershr/ServerCreatePulse.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ dsc$descriptor *tree, int *shot, void (*ast)(), int astprm, int *netid, void
#include "servershrp.h"

EXPORT int ServerCreatePulse(int *id, char *server, char *tree, int shot,
void (*ast)(), void *astprm, int *retstatus,
void (*ast)(void *, char *), void *astprm, int *retstatus,
pthread_rwlock_t *lock, void (*before_ast)())
{
struct descrip p1, p2;
Expand Down
2 changes: 1 addition & 1 deletion servershr/ServerDispatchAction.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ dsc$descriptor *tree, int *shot, int *nid, void (*ast)(), int astprm, int
#include "servershrp.h"

EXPORT int ServerDispatchAction(int *id, char *server, char *tree, int shot,
int nid, void (*ast)(), void *astprm,
int nid, void (*ast)(void *, char*), void *astprm,
int *retstatus, pthread_rwlock_t *lock,
int *socket, void (*before_ast)())
{
Expand Down
2 changes: 1 addition & 1 deletion servershr/ServerDispatchCommand.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ int *netid, void (*link_down)(), void (*before_ast)())
#include "servershrp.h"

EXPORT int ServerDispatchCommand(int *id, char *server, char *cli,
char *command, void (*ast)(), void *astprm,
char *command, void (*ast)(void *, char *), void *astprm,
int *retstatus, pthread_rwlock_t *lock,
void (*before_ast)())
{
Expand Down
8 changes: 4 additions & 4 deletions servershr/ServerDispatchPhase.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ extern int ProgLoc;

static void dispatch(int idx);
static void send_monitor(int mode, int idx);
static void action_done(intptr_t idx);
static void action_done();
static void action_done_action_locked(int idx);
static void action_done_action_unlocked(int idx);
static void before(int idx);
Expand Down Expand Up @@ -723,7 +723,7 @@ static void action_done_action_unlocked(int idx)
UNLOCK_ACTION(cidx, ad_fte);
WRLOCK_ACTION(cidx, ad_fte);
actions[cidx].status = ServerINVALID_DEPENDENCY;
action_done(cidx);
action_done(cidx, NULL);
UNLOCK_ACTION(cidx, ad_fte);
action_done_action_unlocked(cidx);
}
Expand Down Expand Up @@ -836,7 +836,7 @@ static void action_done_thread()
pthread_cleanup_pop(1);
}

static void action_done(intptr_t i)
static void action_done(intptr_t i, char *dummy __attribute__((unused)))
{
INIT_STATUS;
static pthread_t thread;
Expand All @@ -846,7 +846,7 @@ static void action_done(intptr_t i)
perror("action_done: pthread creation failed");
}
#else
static inline void action_done(intptr_t i)
static inline void action_done(intptr_t i, char *dummy __attribute__((unused)))
{
return action_done_do(i);
}
Expand Down
2 changes: 1 addition & 1 deletion servershr/ServerMonitorCheckin.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static inline int using_events(char *server, void (*ast)(), void *astprm)
return yesno;
}

EXPORT int ServerMonitorCheckin(char *server, void (*ast)(), void *astprm)
EXPORT int ServerMonitorCheckin(char *server, void (*ast)(void *, char *), void *astprm)
{
if (using_events(server, ast, astprm))
return MDSplusSUCCESS;
Expand Down
32 changes: 16 additions & 16 deletions servershr/ServerQAction.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@ EXPORT int ServerQAction(uint32_t *addrp, uint16_t *portp, int *op, int *flags,
job.nid = *(int *)p3;
if (job.h.addr)
{
MDSDBG(SVRACTIONJOB_PRI, SVRACTIONJOB_VAR(&job));
MDSDBG(SRVACTIONJOB_PRI, SRVACTIONJOB_VAR(&job));
status = QJob((SrvJob *)&job);
}
else
{
MDSWRN(SVRACTIONJOB_PRI " No Addr", SVRACTIONJOB_VAR(&job));
MDSWRN(SRVACTIONJOB_PRI " No Addr", SRVACTIONJOB_VAR(&job));
status = DoSrvAction((SrvJob *)&job);
}
break;
Expand All @@ -217,12 +217,12 @@ EXPORT int ServerQAction(uint32_t *addrp, uint16_t *portp, int *op, int *flags,
job.h.jobid = *jobid;
if (job.h.addr)
{
MDSDBG(SVRCLOSEJOB_PRI, SVRCLOSEJOB_VAR(&job));
MDSDBG(SRVCLOSEJOB_PRI, SRVCLOSEJOB_VAR(&job));
status = QJob((SrvJob *)&job);
}
else
{
MDSWRN(SVRCLOSEJOB_PRI " No Addr", SVRCLOSEJOB_VAR(&job));
MDSWRN(SRVCLOSEJOB_PRI " No Addr", SRVCLOSEJOB_VAR(&job));
status = DoSrvClose((SrvJob *)&job);
}
break;
Expand All @@ -240,12 +240,12 @@ EXPORT int ServerQAction(uint32_t *addrp, uint16_t *portp, int *op, int *flags,
job.shot = *(int *)p2;
if (job.h.addr)
{
MDSDBG(SVRCREATEPULSEJOB_PRI, SVRCREATEPULSEJOB_VAR(&job));
MDSDBG(SRVCREATEPULSEJOB_PRI, SRVCREATEPULSEJOB_VAR(&job));
status = QJob((SrvJob *)&job);
}
else
{
MDSWRN(SVRCREATEPULSEJOB_PRI " No Addr", SVRCREATEPULSEJOB_VAR(&job));
MDSWRN(SRVCREATEPULSEJOB_PRI " No Addr", SRVCREATEPULSEJOB_VAR(&job));
status = DoSrvCreatePulse((SrvJob *)&job);
}
break;
Expand All @@ -271,12 +271,12 @@ EXPORT int ServerQAction(uint32_t *addrp, uint16_t *portp, int *op, int *flags,
job.command = strdup((char *)p2);
if (job.h.addr)
{
MDSDBG(SVRCOMMANDJOB_PRI, SVRCOMMANDJOB_VAR(&job));
MDSDBG(SRVCOMMANDJOB_PRI, SRVCOMMANDJOB_VAR(&job));
status = QJob((SrvJob *)&job);
}
else
{
MDSWRN(SVRCOMMANDJOB_PRI " No Addr", SVRCOMMANDJOB_VAR(&job));
MDSWRN(SRVCOMMANDJOB_PRI " No Addr", SRVCOMMANDJOB_VAR(&job));
status = DoSrvCommand((SrvJob *)&job);
}
break;
Expand All @@ -300,12 +300,12 @@ EXPORT int ServerQAction(uint32_t *addrp, uint16_t *portp, int *op, int *flags,
job.status = *(int *)p8;
if (job.h.addr)
{
MDSDBG(SVRMONITORJOB_PRI, SVRMONITORJOB_VAR(&job));
MDSDBG(SRVMONITORJOB_PRI, SRVMONITORJOB_VAR(&job));
status = QJob((SrvJob *)&job);
}
else
{
MDSWRN(SVRMONITORJOB_PRI " No Addr", SVRMONITORJOB_VAR(&job));
MDSWRN(SRVMONITORJOB_PRI " No Addr", SRVMONITORJOB_VAR(&job));
status = MDSplusERROR;
}
break;
Expand Down Expand Up @@ -429,7 +429,7 @@ static int RemoveLast()
JobQueueNext->h.next = 0;
else
JobQueue = 0;
MDSMSG(SVRJOB_PRI "Removed pending action", SVRJOB_VAR(job));
MDSMSG(SRVJOB_PRI "Removed pending action", SRVJOB_VAR(job));
FreeJob(job);
status = MDSplusSUCCESS;
}
Expand Down Expand Up @@ -948,7 +948,7 @@ static SOCKET setup_client(SrvJob *job)
if (sock != INVALID_SOCKET)
{
add_client(addr, port, sock);
MDSMSG("setup connection %" PRI_SOCKET " " SVRJOB_PRI, sock, SVRJOB_VAR(job));
MDSMSG("setup connection %" PRI_SOCKET " " SRVJOB_PRI, sock, SRVJOB_VAR(job));
}
}
return sock;
Expand All @@ -961,11 +961,11 @@ static void cleanup_client(SrvJob *job)
close_socket(sock);
if (STATIC_Debug)
{
MDSMSG("cleanup connection %" PRI_SOCKET " " SVRJOB_PRI, sock, SVRJOB_VAR(job));
MDSMSG("cleanup connection %" PRI_SOCKET " " SRVJOB_PRI, sock, SRVJOB_VAR(job));
}
else
{
MDSDBG("cleanup connection %" PRI_SOCKET " " SVRJOB_PRI, sock, SVRJOB_VAR(job));
MDSDBG("cleanup connection %" PRI_SOCKET " " SRVJOB_PRI, sock, SRVJOB_VAR(job));
}
}

Expand All @@ -992,7 +992,7 @@ static int send_all(SOCKET sock, char *msg, int len)

static int send_reply(SrvJob *job, int replyType, int status_in, int length, char *msg)
{
MDSDBG(SVRJOB_PRI " %d", SVRJOB_VAR(job), replyType);
MDSDBG(SRVJOB_PRI " %d", SRVJOB_VAR(job), replyType);
int status = MDSplusERROR;
long msg_len = msg ? (long)strlen(msg) : 0;
int try_again = FALSE;
Expand All @@ -1005,7 +1005,7 @@ static int send_reply(SrvJob *job, int replyType, int status_in, int length, cha
SOCKET sock = setup_client(job);
if (sock == INVALID_SOCKET)
{
MDSMSG(SVRJOB_PRI " break connection", SVRJOB_VAR(job));
MDSMSG(SRVJOB_PRI " break connection", SRVJOB_VAR(job));
cleanup_client(job);
break;
}
Expand Down
6 changes: 3 additions & 3 deletions servershr/ServerSendMessage.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static SOCKET get_socket_by_conid(int conid)
// Each thread uses a different port, thus a different network connection.
// Connections persist and thus handle all traffic between the endpoints.
int ServerSendMessage(int *msgid, char *server, int op, int *retstatus,
pthread_rwlock_t *lock, int *conid_out, void (*callback_done)(),
pthread_rwlock_t *lock, int *conid_out, void (*callback_done)(void *, char *),
void *callback_param, void (*callback_before)(), int numargs_in,
...)
{
Expand All @@ -125,7 +125,7 @@ int ServerSendMessage(int *msgid, char *server, int op, int *retstatus,
MDSWRN("failed to connect");
}
if (callback_done)
callback_done(callback_param);
callback_done(callback_param, NULL);
return ServerPATH_DOWN;
}
INIT_STATUS;
Expand Down Expand Up @@ -155,7 +155,7 @@ int ServerSendMessage(int *msgid, char *server, int op, int *retstatus,
{
MDSWRN("could not resolve address socket %" PRI_SOCKET " is bound to", sock);
if (callback_done)
callback_done(callback_param);
callback_done(callback_param, NULL);
return ServerSOCKET_ADDR_ERROR;
}
jobid = Job_register(msgid, conid, retstatus, lock, callback_done, callback_param, callback_before);
Expand Down
Loading