예제 #1
0
파일: mds-colour.c 프로젝트: maandree/mds
/**
 * Perform the server's mission
 * 
 * @return  Non-zero on error
 */
int
master_loop(void)
{
	int rc = 1, r;

	while (!reexecing && !terminating) {
		if (danger) {
			danger = 0;
			free(send_buffer);
			send_buffer = NULL;
			send_buffer_size = 0;
			colour_list_pack(&colours);
			free(colour_list_buffer_without_values);
			colour_list_buffer_without_values = NULL;
			free(colour_list_buffer_with_values);
			colour_list_buffer_with_values = NULL;
		}

		if (!(r = mds_message_read(&received, socket_fd)))
			if (!(r = handle_message()))
				continue;

		if (r == -2) {
			eprint("corrupt message received, aborting.");
			goto done;
		} else if (errno == EINTR) {
			continue;
		} else {
			fail_if (errno != ECONNRESET);
		}

		eprint("lost connection to server.");
		mds_message_destroy(&received);
		mds_message_initialise(&received);
		connected = 0;
		fail_if (reconnect_to_display());
		connected = 1;
	}

	rc = 0;
	goto done;
fail:
	xperror(*argv);
done:
	if (rc || !reexecing) {
		mds_message_destroy(&received);
		colour_list_destroy(&colours);
	}
	free(send_buffer);
	free(colour_list_buffer_without_values);
	free(colour_list_buffer_with_values);
	return rc;
}
예제 #2
0
파일: mds-vt.c 프로젝트: jiteshpandey93/mds
/**
 * 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;
}
예제 #3
0
파일: mds-vt.c 프로젝트: jiteshpandey93/mds
/**
 * Wait for confirmation that we may switch virtual terminal
 * 
 * @param   data  Thread input parameter, will always be `NULL`
 * @return        Thread return value, will always be `NULL`
 */
void* secondary_loop(void* data)
{
  mds_message_t secondary_received;
  int r;
  (void) data;
  
  secondary_thread_started = 1;
  fail_if (mds_message_initialise(&secondary_received) < 0);
  
  while (!reexecing && !terminating)
    {
      if (r = mds_message_read(&secondary_received, secondary_socket_fd), r == 0)
	r = vt_accept_switch(display_tty_fd);
      if (r == 0)
	continue;
      
      if (r == -2)
	{
	  eprint("corrupt message received, aborting.");
	  secondary_thread_failed = 1;
	  goto done;
	}
      else if (errno == EINTR)
	continue;
      else
	fail_if (errno != ECONNRESET);
      
      eprint("lost secondary connection to server.");
      mds_message_destroy(&secondary_received);
      mds_message_initialise(&secondary_received);
      fail_if (reconnect_fd_to_display(&secondary_socket_fd) < 0);
    }
  
  goto done;
 fail:
  xperror(*argv);
  secondary_thread_failed = 1;
 done:
  secondary_thread_started = 0;
  mds_message_destroy(&secondary_received);
  if (!reexecing && !terminating)
    pthread_kill(master_thread, SIGTERM);
  return NULL;
}
예제 #4
0
파일: mds-echo.c 프로젝트: maandree/mds
/**
 * Perform the server's mission
 * 
 * @return  Non-zero on error
 */
int
master_loop(void)
{
	int rc = 1, r;

	while (!reexecing && !terminating) {
		if (!(r = mds_message_read(&received, socket_fd)))
			if (!(r = echo_message()))
				continue;

		if (r == -2) {
			eprint("corrupt message received, aborting.");
			goto done;
		} else if (errno == EINTR) {
			continue;
		} else {
			fail_if (errno != ECONNRESET);
		}

		eprint("lost connection to server.");
		mds_message_destroy(&received);
		mds_message_initialise(&received);
		connected = 0;
		fail_if (reconnect_to_display());
		connected = 1;
	}

	rc = 0;
	goto done;
fail:
	xperror(*argv);
done:
	if (rc || !reexecing)
		mds_message_destroy(&received);
	free(echo_buffer);
	return rc;
}