void POMP_Finalize() { static int pomp_finalize_called = 0; if ( ! pomp_finalize_called ) { pomp_finalize_called = 1; vt_close(); } }
/** * Perform the server's mission * * @return Non-zero on error */ int master_loop(void) { int rc = 1, r; while (!reexecing && !terminating) { if (switching_vt) { int leaving = switching_vt == 1; switching_vt = 0; r = switch_vt(leaving); } else if (r = mds_message_read(&received, socket_fd), r == 0) r = handle_message(); if (r == 0) continue; if (r == -2) { eprint("corrupt message received, aborting."); goto done; } else if (errno == EINTR) continue; else fail_if (errno != ECONNRESET); eprint("lost primary connection to server."); mds_message_destroy(&received); mds_message_initialise(&received); connected = 0; fail_if (reconnect_to_display()); connected = 1; } rc = 0; if (vt_set_exclusive(display_tty_fd, 0) < 0) xperror(*argv); if (vt_set_graphical(display_tty_fd, 0) < 0) xperror(*argv); if (unlink(vtfile_path) < 0) xperror(*argv); vt_close(display_tty_fd, &old_vt_stat); goto done; fail: xperror(*argv); done: rc |= secondary_thread_failed; if (rc || !reexecing) mds_message_destroy(&received); if ((errno = pthread_join(secondary_thread, NULL))) xperror(*argv); return rc; }
int execvp(const char* path, char* const argv[]) { int rc; VT_MEMHOOKS_OFF(); if ( DO_TRACE(execvp) ) { /* mark enter function */ uint64_t time = vt_pform_wtime(); vt_enter(&time, libc_funcs[FUNCIDX(execvp)].rid); } /* close VT for current process */ vt_close(); /* call (real) function */ CALL_FUNC(execvp, rc, (path, argv)); vt_warning("execvp failed: %s", strerror(errno)); return rc; }
int execle(const char* path, const char* arg, ...) { int rc; char* argv[100]; char** envp; char* tmp; int i; va_list ap; VT_MEMHOOKS_OFF(); va_start(ap, arg); i = 0; argv[i++] = (char*)arg; while((tmp = va_arg(ap, char*) )) argv[i++] = tmp; argv[i] = NULL; envp = va_arg(ap, char**); va_end(ap); if ( DO_TRACE(execle) ) { /* mark enter function */ uint64_t time = vt_pform_wtime(); vt_enter(&time, libc_funcs[FUNCIDX(execle)].rid); } /* close VT for current process */ vt_close(); /* call (real) function */ CALL_FUNC(execve, rc, (path, argv, envp)); vt_warning("execle failed: %s", strerror(errno)); return rc; }
/** * This function should initialise the server, * and it not invoked after a re-exec. * * @return Non-zero on error */ int initialise_server(void) { struct vt_mode mode; char* display_env; int primary_socket_fd; int stage = 0; const char* const message = "Command: intercept\n" "Message ID: 0\n" "Length: 38\n" "\n" "Command: get-vt\n" "Command: configure-vt\n"; const char* const secondary_message = "Command: intercept\n" "Message ID: 0\n" "Priority: -4611686018427387904\n" /* −2⁶² */ "Length: 22\n" "\n" "Command: switching-vt\n"; primary_socket_fd = socket_fd; fail_if (connect_to_display()); secondary_socket_fd = socket_fd; socket_fd = primary_socket_fd; display_env = getenv("MDS_DISPLAY"); display_env = display_env ? strchr(display_env, ':') : NULL; if ((display_env == NULL) || (strlen(display_env) < 2)) goto no_display; memset(vtfile_path, 0, sizeof(vtfile_path)); xsnprintf(vtfile_path, "%s/%s.vt", MDS_RUNTIME_ROOT_DIRECTORY, display_env + 1); stage = 1; if (is_respawn == 0) { display_vt = select_vt(); fail_if (display_vt < 0); display_tty_fd = vt_open(display_vt, &old_vt_stat); fail_if (write_vt_file() < 0); fail_if (vt_set_active(display_vt) < 0); } else { fail_if (read_vt_file() < 0); vt_is_active = (display_vt == vt_get_active()); fail_if (vt_is_active < 0); } fail_if (full_send(secondary_socket_fd, secondary_message, strlen(secondary_message))); fail_if (full_send(socket_fd, message, strlen(message))); fail_if (server_initialised() < 0); fail_if (mds_message_initialise(&received)); stage = 2; fail_if (xsigaction(SIGRTMIN + 2, received_switch_vt) < 0); fail_if (xsigaction(SIGRTMIN + 3, received_switch_vt) < 0); vt_construct_mode(1, SIGRTMIN + 2, SIGRTMIN + 3, &mode); fail_if (vt_get_set_mode(display_tty_fd, 1, &mode) < 0); if (vt_set_exclusive(display_tty_fd, 1) < 0) xperror(*argv); return 0; no_display: eprint("no display has been set, how did this happen."); return 1; fail: xperror(*argv); if (stage >= 1) unlink(vtfile_path); if (display_tty_fd >= 0) vt_close(display_tty_fd, &old_vt_stat); if (stage >= 2) mds_message_destroy(&received); return 1; }
void _ftrace_stop2_() { vt_close(); }