示例#1
0
static int ensure_adb_server_and_connect(void)
{
	bool t_continue;
	t_continue = true;
	
	int t_socket;
	while(t_continue)
	{
		// Socket begins undefined
		t_socket = -1;
		
		// Acquire the global lock.
		sys_enter_lock(&s_global_lock);
		
		if (s_tracking_enabled)
		{
			// Make sure there is an adb server running
			sys_execute(s_adb_path, "start-server");
			
			// Now attempt to connect
			t_socket = connect_to_adb_and_start_tracking();
		}
		else
			t_continue = false;
		
		if (t_socket != -1)
		{
			s_tracking_socket = t_socket;
			t_continue = false;
		}
		
		sys_leave_lock(&s_global_lock);
		
		// If there is no socket yet, sleep for 5 seconds before trying again.
		if (t_continue && t_socket == -1)
			sys_sleep(5000);
	}
	
	return t_socket;
}
示例#2
0
文件: tty.c 项目: fdomig/ottos
static int tty_start_process(const char* bin, char* args, BOOLEAN background) {

  char* buffer = NULL;
  //	char** args_test = malloc(sizeof(char*) * 3);
  char** arguments = NULL;
  int argc = 1;
  int i = 0;

  /*
   char arg1[50] = { 0 };
   char arg2[50] = { 0 };
   char arg3[50] = { 0 };
   char* args_stupid[3];
   args_stupid[0] = arg1;
   args_stupid[1] = arg2;
   args_stupid[2] = arg3;

   while (args != NULL) {
   strcpy(args_stupid[argc], args);
   argc++;
   args = strtok(NULL, SPLIT_CHARS);
   }
   */

  // use a linked list to allocate memory for the arguments
  // after reading the arguments, the argv array will be initialised
  // and the argument values will be copied into the argv array

  // TODO this is so ugly - but we have only 2 days left until presentation ;)
  argument_t* head;
  argument_t* argument = malloc(sizeof(argument_t));
  argument->value_length = (strlen(bin) + 1);
  argument->value = malloc(sizeof(char) * argument->value_length);
  strcpy(argument->value, bin);
  argument->next = NULL;

  head = argument;

  // get next argument
  args = strtok(NULL, SPLIT_CHARS);
  while (args != NULL) {

    argument_t* next = malloc(sizeof(argument_t));
    next->value_length = (strlen(args) + 1);
    next->value = malloc(sizeof(char) * next->value_length);
    strcpy(next->value, args);
    next->next = NULL;

    argument->next = next;
    argument = next;

    argc++;

    // get next argument
    args = strtok(NULL, SPLIT_CHARS);
  }

  arguments = (char**) malloc(sizeof(char**) * argc);

  argument = head;
  while (argument != NULL) {
    argument_t* next;

    arguments[i] = malloc(sizeof(char) * argument->value_length);
    strcpy(arguments[i], argument->value);
    i++;

    next = argument->next;

    free(argument->value);
    free(argument);

    argument = next;
  }

  //	// split arguments by space
  //	char* args_ = args;
  //	while (args_ != NULL) {
  //		argc++;
  //		args_ = strtok(NULL, SPLIT_CHARS);
  //	}
  //	if (argc > 0) {
  //		arguments = (char**) malloc(sizeof(char*) * argc);
  //
  //		args_ = args;
  //		i = 0;
  //		while (args_ != NULL) {
  //			print(args_);
  //			print("\r\n");
  //			arguments[i] = (char*) malloc(sizeof(char) * (strlen(args_) + 1));
  //			if (arguments[i] == NULL) {
  //				print("WTF?\r\n");
  //			}
  //			strcpy(arguments[i], args_);
  //			//			arguments[i] = args_;
  //			i++;
  //			args_ = strtok(NULL, SPLIT_CHARS);
  //		}
  //	}

  buffer = malloc(sizeof(char) * MAX_PATH_LENGTH);

  //	args_test[0] = malloc(sizeof(char) * (strlen("arg1") + 1));
  //	args_test[1] = malloc(sizeof(char) * (strlen("arg2") + 1));
  //	args_test[2] = malloc(sizeof(char) * (strlen("arg3") + 1));
  //	strcpy(args_test[0], "arg1");
  //	strcpy(args_test[1], "arg2");
  //	strcpy(args_test[2], "arg3");

  sprintf(buffer, "/bin/%s", bin);

  //print("before starting process\r\n");
  //	sys_execute(1, background, bin, 3, args_test);
  //	sys_execute(1, background, bin, 0, NULL);
  sys_execute(1, background == FALSE, bin, argc, arguments);
  //	sys_execute(1, background, bin, argc, args_stupid);

  if (argc > 0) {
    for (i = 0; i < argc; i++) {
      free(arguments[i]);
    }
    free(arguments);
  }
  //		free(args_test[0]);
  //		free(args_test[1]);
  //		free(args_test[2]);
  //		free(args_test);
  free(buffer);

  // TODO ([email protected]) return the process return state on foreground process
  return 0;
}
示例#3
0
/* change_terminal function
   Function handles switching terminals (ALT + FUNCTION-KEY)
   Input : new_terminal -- terminal to switch into
   Output : None
   Side Effect : Does nothing if the new terminal 
   is the same as the current terminal.
   Else it copies video memory into the correct video buffer
   and the correct video buffer into video memory
*/
void change_terminal(int32_t new_terminal)
{
	/* Check to make sure that the new_terminal is not the same
	   as the terminal displayed now */
	int32_t old_terminal = get_displayed_terminal();
	if(new_terminal == old_terminal){
		LOG("You are already in this terminal! Cannot Switch!\n");
		return;
	}

	/* Case where we try to launch shell with max_num_process already running */
	if(num_progs[TERMINAL_1] + num_progs[TERMINAL_2] + num_progs[TERMINAL_3] >= MAX_NUM_PROCESS && 
	   num_progs[new_terminal] == 0){
	   	printf("Reached maximum number of programs! Can't fire new shell in new terminal!391OS> ");
		return;
	}

	/* Grab the page dir for the old terminal */
	pcb_t* pcb_ptr = top_process[old_terminal]; 
	pde_t* current_pg_dir = pcb_ptr->pg_dir;

	/* Grab the page dir for new terminal */
	pcb_t* top_pcb = top_process[new_terminal];
	pde_t* new_term_pg_dir;
	if(top_pcb == NULL)
		new_term_pg_dir = NULL;
	else
		new_term_pg_dir = top_pcb -> pg_dir;

	/* Copy mem (video->buf) and remap page (USER_VIDEO -> BUF) for the old_terminal*/
	remap_user_video_and_memcpy(get_video_buf_for_terminal(old_terminal), VIDEO, current_pg_dir);
	
	/* Copy mem (buf-> video) and remap page (USER_VIDEO -> VIDEO) for the new_terminal */
	remap_user_video_and_memcpy(VIDEO, get_video_buf_for_terminal(new_terminal), new_term_pg_dir);

	/* Flush TLB */
	set_cr3_reg(get_pcb_ptr() -> pg_dir);

	/* Update the displayed terminal*/
	displayed_terminal = new_terminal;

	/* If the the new terminal is not executing any programs, Execute Shell */
	if(num_progs[new_terminal] == 0){
		key_press = 0;	// Will not return to keyboardhandler, update key_press	

		pcb_t* curr_ptr = get_pcb_ptr();
		uint8_t exec_cmd[15] = "shell";

		/* Save info for scheduling */
		curr_ptr -> esp0 = tss.esp0; 
		asm volatile("movl %%esp, %0;" 
	  		"movl %%ebp, %1;" : 
	  		"=b" (curr_ptr -> esp),
	  		"=c" (curr_ptr -> ebp));

		send_eoi(KEYBOARD_IRQ);		//Send EOI for ALT+FUNCTION-KEY

		/* Execute a Shell */
		if(-1 == sys_execute(exec_cmd)){
			LOG("Executing new shell from new terminal failed!\n");
		}
	}