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

Put restored Java process on foreground instead of restorewait #133

Closed
wants to merge 3 commits into from
Closed
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
32 changes: 31 additions & 1 deletion src/java.base/unix/native/criuengine/criuengine.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@
#include <libgen.h>
#include <limits.h>
#include <stdlib.h>
#include <dirent.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <getopt.h>
#include <signal.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/types.h>

#define RESTORE_SIGNAL (SIGRTMIN + 2)

Expand All @@ -48,6 +50,7 @@
#define SUPPRESS_ERROR_IN_PARENT 77

static int g_pid;
static int g_tty_fd = -1;

static char *verbosity = NULL; // default differs for checkpoint and restore
static char *log_file = NULL;
Expand Down Expand Up @@ -281,12 +284,39 @@ static int post_resume(void) {
}

static void sighandler(int sig, siginfo_t *info, void *uc) {
// criuengine restorewait should not have foreground; pass it to the java process
if (g_tty_fd >= 0) {
pid_t current;
while ((current = tcgetpgrp(g_tty_fd)) < 0 && errno == EINTR);
if (current == getpid()) {
while (tcsetpgrp(g_tty_fd, g_pid) && errno == EINTR);
}
}
if (0 <= g_pid) {
kill(g_pid, sig);
if (sig != SIGCHLD) {
kill(g_pid, sig);
}
}
}

static int restorewait(void) {
// standard input and outputs go to /dev/null but
// some open FDs can still tell which tty are we part of.
DIR *dir = opendir("/proc/self/fd");
int dfd = dirfd(dir);
struct dirent *dp;
while ((dp = readdir(dir))) {
if (dp->d_name[0] == '.') {
continue; // skip "." and ".."
}
int fd = atoi(dp->d_name);
if (isatty(fd)) {
g_tty_fd = fd;
rvansa marked this conversation as resolved.
Show resolved Hide resolved
break;
}
}
closedir(dir);

char *pidstr = getenv("CRTOOLS_INIT_PID");
if (!pidstr) {
fprintf(stderr, MSGPREFIX "no CRTOOLS_INIT_PID: signals may not be delivered\n");
Expand Down