Skip to content

Commit

Permalink
Merge pull request dmtcp#719 from karya0/exit_fix
Browse files Browse the repository at this point in the history
Simplified dmtcp_initialize and exit handling
  • Loading branch information
karya0 committed Dec 5, 2018
2 parents 65ab55d + d808fbc commit 7fcf278
Show file tree
Hide file tree
Showing 28 changed files with 323 additions and 678 deletions.
240 changes: 139 additions & 101 deletions include/dmtcp.h

Large diffs are not rendered by default.

129 changes: 0 additions & 129 deletions include/dmtcp_dlsym.h

This file was deleted.

1 change: 0 additions & 1 deletion include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ void initializeLogFile(const char *tmpDir,
const char *procname = "",
const char *preLogPath = "");

void prepareDlsymWrapper();
void adjustRlimitStack();
void runMtcpRestore(int is32bitElf,
const char *path,
Expand Down
8 changes: 0 additions & 8 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,6 @@
#define ENV_VAR_SCREENDIR "SCREENDIR"
#define ENV_VAR_DISABLE_STRICT_CHECKING "DMTCP_DISABLE_STRICT_CHECKING"

#define GLIBC_BASE_FUNC isalnum

#define LIBDL_BASE_FUNC dlinfo
#define LIBDL_BASE_FUNC_STR "dlinfo"
#define ENV_VAR_DLSYM_OFFSET "DMTCP_DLSYM_OFFSET"
#define ENV_VAR_DLSYM_OFFSET_M32 "DMTCP_DLSYM_OFFSET_M32"
#define ENV_VAR_REMOTE_SHELL_CMD "DMTCP_REMOTE_SHELL_CMD"

// this list should be kept up to date with all "protected" environment vars
Expand All @@ -144,8 +138,6 @@
ENV_VAR_DL_PLUGIN, \
ENV_VAR_SIGCKPT, \
ENV_VAR_SCREENDIR, \
ENV_VAR_DLSYM_OFFSET, \
ENV_VAR_DLSYM_OFFSET_M32, \
ENV_VAR_VIRTUAL_PID, \
ENV_VAR_SKIP_WRITING_TEXT_SEGMENTS, \
ENV_DELTACOMPRESSION
Expand Down
42 changes: 24 additions & 18 deletions src/coordinatorapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ eventHook(DmtcpEvent_t event, DmtcpEventData_t *data)
init();
break;

case DMTCP_EVENT_EXIT:
JTRACE("exit() in progress, disconnecting from dmtcp coordinator");
closeConnection();
break;

default:
break;
}
Expand Down Expand Up @@ -371,20 +366,38 @@ recvMsgFromCoordinatorRaw(int fd, DmtcpMessage *msg, void **extraData)
sem_launch_first_time = false;
}

if (Util::readAll(fd, msg, sizeof(*msg)) != sizeof(*msg)) {
// Read into a temporary buffer in case the process exits after reading the
// message but before receiving the extradata.
DmtcpMessage tmpMsg;
if (Util::readAll(fd, &tmpMsg, sizeof(tmpMsg)) != sizeof(tmpMsg)) {
// Perhaps the process is exit()'ing.
return;
}

if (msg->extraBytes > 0) {
if (tmpMsg.extraBytes > 0) {
JASSERT(extraData != NULL);

// Caller must free this buffer
void *buf = JALLOC_HELPER_MALLOC(msg->extraBytes);
JASSERT(Util::readAll(fd, (char*) buf, msg->extraBytes) == msg->extraBytes);
JASSERT(extraData != NULL);
void *buf = JALLOC_HELPER_MALLOC(tmpMsg.extraBytes);
if (Util::readAll(fd, buf, tmpMsg.extraBytes) != tmpMsg.extraBytes) {
JALLOC_HELPER_FREE(buf);
return;
}

*extraData = buf;
}

// All is well, return the received message.
*msg = tmpMsg;

// TODO(Kapil): Distinguish between DMT_KILL_PEER that arrives during
// checkpoint-phase (potentially due to a stuck computation that the user
// wants to kill) vs. normal runtime.
// TODO(Kapil): Consider generating an EXIT event for plugins.
if (msg->isValid() && msg->type == DMT_KILL_PEER) {
JTRACE("Received KILL message from coordinator, exiting");
_exit(0);
}
}

void sendMsgToCoordinator(DmtcpMessage msg, const void *extraData, size_t len)
Expand Down Expand Up @@ -414,10 +427,6 @@ void waitForBarrier(const string& barrierId)
recvMsgFromCoordinator(&msg, (void**)&extraData);

msg.assertValid();
if (msg.type == DMT_KILL_PEER) {
JTRACE("Received KILL message from coordinator, exiting");
_exit(0);
}

JASSERT(msg.type == DMT_BARRIER_RELEASED) (msg.type);
JASSERT(extraData != NULL);
Expand Down Expand Up @@ -549,10 +558,7 @@ sendRecvHandshake(int fd,

recvMsgFromCoordinatorRaw(fd, &msg);
msg.assertValid();
if (msg.type == DMT_KILL_PEER) {
JTRACE("Received KILL message from coordinator, exiting");
_real_exit(0);
}

if (msg.type == DMT_REJECT_NOT_RUNNING) {
JASSERT(false)
.Text("Connection rejected by the coordinator.\n"
Expand Down
2 changes: 1 addition & 1 deletion src/dmtcp_dlsym.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
#endif
#include <dlfcn.h>

#include "dmtcp_dlsym.h"
#include "dmtcp.h"
#include "jassert.h"
#include "config.h"

Expand Down
3 changes: 0 additions & 3 deletions src/dmtcp_launch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,9 +606,6 @@ main(int argc, char **argv)
&coordInfo,
&localIPAddr);

// Set DLSYM_OFFSET env var(s).
Util::prepareDlsymWrapper();

setLDPreloadLibs(is32bitElf);

// run the user program
Expand Down
4 changes: 1 addition & 3 deletions src/dmtcp_restart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "../jalib/jfilesystem.h"
#include "constants.h"
#include "coordinatorapi.h"
#include "dmtcp_dlsym.h"
#include "processinfo.h"
#include "shareddata.h"
#include "uniquepid.h"
Expand Down Expand Up @@ -312,11 +311,10 @@ class RestoreTarget
&compId,
&coordInfo,
&localIPAddr);

Util::initializeLogFile(SharedData::getTmpDir().c_str(),
_pInfo.procname().c_str(),
NULL);

Util::prepareDlsymWrapper();
}

JTRACE("Creating process during restart") (upid()) (_pInfo.procname());
Expand Down
33 changes: 0 additions & 33 deletions src/dmtcpplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,39 +427,6 @@ dmtcp_get_ptrace_fd(void)
return PROTECTED_PTRACE_FD;
}

LIB_PRIVATE int32_t dmtcp_dlsym_offset = -1;
typedef void * (*dlsym_fnptr_t) (void *handle, const char *symbol);
EXTERNC void *
dmtcp_get_libc_dlsym_addr(void)
{
static dlsym_fnptr_t _libc_dlsym_fnptr = NULL;

#ifndef CONFIG_M32
const char *evar = ENV_VAR_DLSYM_OFFSET;
#else // ifndef CONFIG_M32
const char *evar = ENV_VAR_DLSYM_OFFSET_M32;
#endif // ifndef CONFIG_M32

if (_libc_dlsym_fnptr == NULL) {
if (getenv(evar) == NULL) {
fprintf(stderr,
"%s:%d DMTCP Internal Error: Env var DMTCP_DLSYM_OFFSET not"
" set.\n"
" Aborting.\n\n",
__FILE__,
__LINE__);
abort();
}

dmtcp_dlsym_offset = (int32_t)strtol(getenv(evar), NULL, 10);

_libc_dlsym_fnptr = (dlsym_fnptr_t)((char *)&LIBDL_BASE_FUNC +
dmtcp_dlsym_offset);
}

return (void *)_libc_dlsym_fnptr;
}

EXTERNC void
dmtcp_block_ckpt_signal(void)
{
Expand Down
Loading

0 comments on commit 7fcf278

Please sign in to comment.