static void
setup(char *argv0, bool live_check)
{
	char		exec_path[MAXPGPATH];	/* full path to my executable */

	/*
	 * make sure the user has a clean environment, otherwise, we may confuse
	 * libpq when we connect to one (or both) of the servers.
	 */
	check_pghost_envvar();

	verify_directories();

	/* no postmasters should be running */
	if (!live_check && is_server_running(old_cluster.pgdata))
		pg_log(PG_FATAL, "There seems to be a postmaster servicing the old cluster.\n"
			   "Please shutdown that postmaster and try again.\n");

	/* same goes for the new postmaster */
	if (is_server_running(new_cluster.pgdata))
		pg_log(PG_FATAL, "There seems to be a postmaster servicing the new cluster.\n"
			   "Please shutdown that postmaster and try again.\n");

	/* get path to pg_upgrade executable */
	if (find_my_exec(argv0, exec_path) < 0)
		pg_log(PG_FATAL, "Could not get pathname to pg_upgrade: %s\n", getErrorText(errno));

	/* Trim off program name and keep just path */
	*last_dir_separator(exec_path) = '\0';
	canonicalize_path(exec_path);
	os_info.exec_path = pg_strdup(exec_path);
}
/**************************************************************** 
handle response (by the server) if the client has got hack or not.
*****************************************************************/ 
void handle_single_want_hack_reply(bool you_have_hack)
{
  /* remove challenge file */
  if (challenge_fullname[0] != '\0') {
    if (remove(challenge_fullname) == -1) {
      freelog(LOG_ERROR, "Couldn't remove temporary file: %s",
	      challenge_fullname);
    }
    challenge_fullname[0] = '\0';
  }

  if (you_have_hack) {
    output_window_append(FTC_CLIENT_INFO, NULL,
                         _("Established control over the server. "
                           "You have command access level 'hack'."));
    client_has_hack = TRUE;
  } else if (is_server_running()) {
    /* only output this if we started the server and we NEED hack */
    output_window_append(FTC_CLIENT_INFO, NULL,
                         _("Failed to obtain the required access "
                           "level to take control of the server. "
                           "The server will now be shutdown."));
    client_kill_server(TRUE);
  }
}
void Daemon_Record::stop(void) {
	if (is_server_running()) {
		Block_Buffer buf;
		buf.make_message(SERVER_INNER_SELF_CLOSE);
		buf.finish_message();
		RECORD_MONITOR->push_async_buff(buf);
	}
}
Beispiel #4
0
/**************************************************************************
  ...
**************************************************************************/
static int start_new_game_callback(struct widget *pWidget)
{
    if (Main.event.button.button == SDL_BUTTON_LEFT) {
        popdown_start_menu();
        if (is_server_running() || client_start_server()) {
            /* saved settings are sent in client/options.c load_settable_options() */
        }
    }
    return -1;
}
Beispiel #5
0
void
output_check_banner(bool *live_check)
{
	if (user_opts.check && is_server_running(old_cluster.pgdata))
	{
		*live_check = true;
		pg_log(PG_REPORT, "Performing Consistency Checks on Old Live Server\n");
		pg_log(PG_REPORT, "------------------------------------------------\n");
	}
	else
	{
		pg_log(PG_REPORT, "Performing Consistency Checks\n");
		pg_log(PG_REPORT, "-----------------------------\n");
	}
}
Beispiel #6
0
void
output_check_banner(bool *live_check)
{
	if (user_opts.check && is_server_running(old_cluster.pgdata))
	{
		*live_check = true;
		if (old_cluster.port == new_cluster.port)
			pg_log(PG_FATAL, "When checking a live server, "
				   "the old and new port numbers must be different.\n");
		pg_log(PG_REPORT, "Performing Consistency Checks on Old Live Server\n");
		pg_log(PG_REPORT, "------------------------------------------------\n");
	}
	else
	{
		pg_log(PG_REPORT, "Performing Consistency Checks\n");
		pg_log(PG_REPORT, "-----------------------------\n");
	}
}
Beispiel #7
0
/****************************************************************************
  Kills the server if the client has started it.

  If the 'force' parameter is unset, we just do a /quit.  If it's set, then
  we'll send a signal to the server to kill it (use this when the socket
  is disconnected already).
****************************************************************************/
void client_kill_server(bool force)
{
  if (is_server_running()) {
    if (client.conn.used && client_has_hack) {
      /* This does a "soft" shutdown of the server by sending a /quit.
       *
       * This is useful when closing the client or disconnecting because it
       * doesn't kill the server prematurely.  In particular, killing the
       * server in the middle of a save can have disastrous results.  This
       * method tells the server to quit on its own.  This is safer from a
       * game perspective, but more dangerous because if the kill fails the
       * server will be left running.
       *
       * Another potential problem is because this function is called atexit
       * it could potentially be called when we're connected to an unowned
       * server.  In this case we don't want to kill it. */
      send_chat("/quit");
#ifdef WIN32_NATIVE
      server_process = INVALID_HANDLE_VALUE;
      loghandle = INVALID_HANDLE_VALUE;
#else
      server_pid = -1;
#endif
    } else if (force) {
      /* Either we already disconnected, or we didn't get control of the
       * server. In either case, the only thing to do is a "hard" kill of
       * the server. */
#ifdef WIN32_NATIVE
      TerminateProcess(server_process, 0);
      CloseHandle(server_process);
      if (loghandle != INVALID_HANDLE_VALUE) {
	CloseHandle(loghandle);
      }
      server_process = INVALID_HANDLE_VALUE;
      loghandle = INVALID_HANDLE_VALUE;
#elif HAVE_WORKING_FORK
      kill(server_pid, SIGTERM);
      waitpid(server_pid, NULL, WUNTRACED);
      server_pid = -1;
#endif /* WIN32_NATIVE || HAVE_WORKING_FORK */
    }
  }
  client_has_hack = FALSE;
}   
Beispiel #8
0
/**************************************************************** 
handle response (by the server) if the client has got hack or not.
*****************************************************************/ 
void handle_single_want_hack_reply(bool you_have_hack)
{
  /* remove challenge file */
  if (challenge_fullname[0] != '\0') {
    if (fc_remove(challenge_fullname) == -1) {
      log_error("Couldn't remove temporary file: %s", challenge_fullname);
    }
    challenge_fullname[0] = '\0';
  }

  if (you_have_hack) {
    output_window_append(ftc_client,
                         _("Established control over the server. "
                           "You have command access level 'hack'."));
    client_has_hack = TRUE;
  } else if (is_server_running()) {
    /* only output this if we started the server and we NEED hack */
    output_window_append(ftc_client,
                         _("Failed to obtain the required access "
                           "level to take control of the server. "
                           "Attempting to shut down server."));
    client_kill_server(TRUE);
  }
}
Beispiel #9
0
smedia_handle_t
get_handle_from_fd(int32_t fd)
{
	rmedia_handle_t	*handle;
	void	*lib_handle;
	int	door_fd, door_server;
	int	ret_val;
	door_arg_t	door_args;
	smedia_reqopen_t	reqopen;
	smedia_reterror_t	*reterror;
	door_desc_t	ddesc[2];
	char	rbuf[sizeof (smedia_services_t) + sizeof (door_desc_t)];
	struct stat	stat;

	DPRINTF("smedia_get_handle called\n");
	handle = (rmedia_handle_t *)malloc(sizeof (rmedia_handle_t));
	if (handle == NULL) {
		DPRINTF("Could not allocate memory for handle\n");
		return (NULL);
	}
	(void) memset((void *) handle, 0, sizeof (rmedia_handle_t));
	handle->sm_fd = -1;
	handle->sm_door = -1;
	handle->sm_death_door = -1;
	handle->sm_buffd = -1;
	handle->sm_buf = NULL;
	handle->sm_bufsize = 0;

	if (ioctl(fd, DKIOCINFO, &handle->sm_dkinfo) == -1) {
		free(handle);
		PERROR("DKIOCINFO failed");
		return (NULL);
	}
	lib_handle = get_dev_library_handle(fd);
	if (lib_handle == NULL) {
		free(handle);
		DPRINTF("lib_Handle is NULL\n");
		errno = ENOTSUP;
		return (NULL);
	}
	DPRINTF("Handle initialised successfully.\n");
	/* Initialise the handle elements */
	handle->sm_lib_handle = lib_handle;
	handle->sm_signature = LIBSMEDIA_SIGNATURE;
	DPRINTF2("fd=%d signature=0x%x\n", handle->sm_fd, handle->sm_signature);

	if ((handle->sm_dkinfo.dki_ctype == DKC_SCSI_CCS) ||
	    (handle->sm_dkinfo.dki_ctype == DKC_MD21) ||
	    (handle->sm_dkinfo.dki_ctype == DKC_CDROM)) {

		ret_val = is_server_running(handle);
		if (ret_val == 0) {
			(void) dlclose(handle->sm_lib_handle);
			free(handle);
			return (NULL);
		}
		door_fd = open(smedia_service, O_RDONLY, 0644);
		if (door_fd < 0) {
			(void) dlclose(handle->sm_lib_handle);
			free(handle);
			if (handle->sm_clnt)
				clnt_destroy(handle->sm_clnt);
			DPRINTF1("Error in opening %s\n", smedia_service);
			PERROR(smedia_service);
			return (NULL);
		}

		DPRINTF1("rbuf address=%p\n", rbuf);
		ddesc[0].d_data.d_desc.d_descriptor = fd;
		ddesc[0].d_attributes = DOOR_DESCRIPTOR;
		reqopen.cnum = SMEDIA_CNUM_OPEN_FD;
		door_args.data_ptr = (char *)&reqopen;
		door_args.data_size = sizeof (smedia_services_t);
		door_args.desc_ptr = &ddesc[0];
		door_args.desc_num = 1;
		door_args.rbuf = rbuf;
		door_args.rsize = sizeof (rbuf);

		ret_val = door_call(door_fd, &door_args);
		(void) close(door_fd);
		if (ret_val < 0) {
			(void) dlclose(handle->sm_lib_handle);
			free(handle);
			if (handle->sm_clnt)
				clnt_destroy(handle->sm_clnt);
			PERROR("door_call");
			return (NULL);
		}
		DPRINTF3("rsize = %d data_size = %d data_ptr = %p \n",
		    door_args.rsize, door_args.data_size,
		    door_args.data_ptr);
		reterror = (smedia_reterror_t *)((void *)door_args.data_ptr);
		if (reterror->cnum != SMEDIA_CNUM_OPEN_FD) {
			(void) dlclose(handle->sm_lib_handle);
			free(handle);
			if (handle->sm_clnt)
				clnt_destroy(handle->sm_clnt);
			DPRINTF1(
	"*** door call failed *** cnum returned = 0x%x\n", reterror->cnum);
			errno = reterror->errnum;
			return (NULL);
		}
		/*
		 * 2 door descriptors are returned after the above door call.
		 * The first door descriptor is the one that will be used
		 * in subsequent smedia calls. A dedicated thread is
		 * associated with this door to handle client calls.
		 * The second door descriptor is needed to signal unexpected
		 * death of the client to the server. This will help the server
		 * to do the necessary cleanup.
		 */
		if (door_args.desc_num != 2) {
			(void) dlclose(handle->sm_lib_handle);
			free(handle);
			if (handle->sm_clnt)
				clnt_destroy(handle->sm_clnt);
			DPRINTF("Num of door descriptors returned by "
			    "server is not 2");
			if (door_args.desc_num)
				(void) close(door_args.desc_ptr->\
				    d_data.d_desc.d_descriptor);
			return (NULL);
		}
		door_server = door_args.desc_ptr->d_data.d_desc.d_descriptor;
		/* Check if the descriptor returned is S_IFDOOR */
		if (fstat(door_server, &stat) < 0) {
			PERROR("fstat");
			(void) dlclose(handle->sm_lib_handle);
			free(handle);
			if (handle->sm_clnt)
				clnt_destroy(handle->sm_clnt);
			return (NULL);
		}
		if (!S_ISDOOR(stat.st_mode)) {
			DPRINTF(
		"Descriptor returned by door_call is not of type DOOR\n");
			(void) dlclose(handle->sm_lib_handle);
			free(handle);
			if (handle->sm_clnt)
				clnt_destroy(handle->sm_clnt);
			return (NULL);
		}
		handle->sm_door = door_server;
		handle->sm_fd = fd;
		door_args.desc_ptr++;
		handle->sm_death_door =
		    door_args.desc_ptr->d_data.d_desc.d_descriptor;
		DPRINTF("door call succeeded.\n");
		return ((smedia_handle_t)handle);

	} else {
		handle->sm_fd = fd;
		return ((smedia_handle_t)handle);
	}

}