예제 #1
0
파일: subprocess.cpp 프로젝트: giucam/vault
QByteArray Process::check_output
(QString const &cmd, QStringList const &args, QVariantMap const &error_info)
{
    start(cmd, args);
    wait(-1);
    check_error(error_info);
    return stdout();
}
예제 #2
0
파일: subprocess.cpp 프로젝트: giucam/vault
void Process::check_error(QVariantMap const &error_info)
{
    if (!rc())
        return;
    QVariantMap err = {{"msg", "Process error"}
                       , {"cmd", ps->program()}
                       , {"args", QVariant(ps->arguments())}
                       , {"rc", rc()}
                       , {"stderr", stderr()}
                       , {"stdout", stdout()}
                       , {"info", errorInfo()}};
    err.unite(error_info);
    error::raise(err);
}
예제 #3
0
void NXClientLib::processParseStdout()
{
	QString message = nxsshProcess.readAllStandardOutput().data();
	
	// Message 211 is sent if ssh is asking to continue with an unknown host
	if (session.parseResponse(message) == 211) {
		emit sshRequestConfirmation(message);
	}
	
	cout << message.toStdString();

	emit stdout(message);
	
	QStringList messages = splitString(message);
	QStringList::const_iterator i;

	// On some connections this is sent via stdout instead of stderr?
	if (proxyData.encrypted && isFinished && message.contains("NX> 999 Bye")) {
		QString returnMessage;
		returnMessage = "NX> 299 Switching connection to: ";
		returnMessage += proxyData.proxyIP + ":" + QString::number(proxyData.port) + " cookie: " + proxyData.cookie + "\n";
		write(returnMessage);
	} else if (message.contains("NX> 287 Redirected I/O to channel descriptors"))
		emit callbackWrite(tr("The session has been started successfully"));

	for (i = messages.constBegin(); i != messages.constEnd(); ++i) {
		if ((*i).contains("Password")) {
			emit callbackWrite(tr("Authenticating with NX server"));
			password = true;
		}
		if (!isFinished)
			write(session.parseSSH(*i));
		else
			write(parseSSH(*i));
	}
}
예제 #4
0
int32_t execute(const uint8_t* command)
{

	pcb_t* previous_pcb = curr_process;


	char* cmd = (char*)command;
	uint8_t* fname = (uint8_t*)parse(cmd);
	get_arg((char *)command, (int)strlen(cmd));
	
	/*	Looking for processes	*/
	uint8_t process_mask = MASK;

	// Calculating the process mask, which keeps track of open processes. Here we search for a 0 in the mask
	// and set it to 1, giving the index in the bitmap to process_id
	int i = 0;
	for(i = 0; i < 7; i++)
	{
		if((process_mask & open_processes) == 0)
		{
			open_processes |= process_mask;
			process_id = i;
			break;
		}
		else
			process_mask >>= 1;
	}

	// if(num_processes + 1 > 2)
	// {
	// 	cout("PROCESS LIMIT EXCEEDED. NOT ALLOWED TO EXECUTE\n");
	// 	//num_processes--;
	// 	sti();
	// 	asm volatile("jmp ret_halt");	
	// }

	// Check
	if(i == 7)
	{

		printf("Too many processes!\n");
		return 1;
	}

	/* Executable check */
	uint8_t elf_check[4];

	dentry_t dentry_temp;
	if(-1 == read_dentry_by_name(fname, &dentry_temp))
	{
		 
		return -1;
	}

	if(-1 == read_data(dentry_temp.inode_num, 0, elf_check, 4))
	{
		 
		return -1;
	}

	if(!(elf_check[0] == 0x7f && elf_check[1] == 0x45 && elf_check[2] == 0x4c && elf_check[3] == 0x46))
	{
		 
		return -1;
	}

	/* Find the address of the file's first instruction */
	uint8_t buf_temp[4];

	if(-1 == read_data(dentry_temp.inode_num, 24, buf_temp, 4))
	{
		 
		return -1;
	}
	int k = 0;
	uint32_t entry_addr = 0;
	for(k = 0; k < 4; k++)
		entry_addr |= (buf_temp[k] << 8*k);


	/* Set up paging */
	PDE_t* PD_ptr = task_mem_init(process_id);
	if(PD_ptr == NULL)
	{
		 
		printf("Too many processes!\n");
		return 1;
	}

	// Load program image into memory
	if(-1 == program_load(fname, PGRM_IMG))
	{
		 	
		return -1;
	}

	k_bp = _8MB - (_8KB)*(process_id) - 4;
	curr_process = (pcb_t *) (k_bp & 0xFFFFE000);
	// k_bp = _8MB - (_8KB)*(process_id);
	// curr_process = (pcb_t *) ((k_bp - 1) & 0xFFFFE000);
	curr_process->process_id = process_id;
	curr_process->PD_ptr = PD_ptr;
	curr_process->k_bp = k_bp;
	curr_process->k_sp = k_bp;
	
	// If initial shell, case should be handeled by making parent process the same shell
	if(initial_shell)
	{
		curr_process->parent_process = curr_process;
		curr_process->child_flag = 0;
		curr_process->parent_process->child = -1;
		initial_shell = 0;
	}
	else
	{
		curr_process->parent_process = previous_pcb;
		curr_process->parent_process->child_flag = 1;
		curr_process->parent_process->child = process_id;
	}
	
	// Initialize file descriptors
	for(i = 0; i < 8; i++)
	{
		curr_process->file_fds[i].file_op = NULL;
		curr_process->file_fds[i].inode_ptr = NULL;
		curr_process->file_fds[i].file_pos = 0;
		curr_process->file_fds[i].flags = 0;
	}	

	task_queue[next_available] = process_id;
	next_available = (next_available + 1) % 7;

	stdin(0);									//kernel should automatically open stdin and stdout
	stdout(1);									//which correspond to fd 0 and 1 respectively


	
	task_queue[next_available] = process_id;
	next_available = (next_available + 1) % 7;
	
	// Setting TSS
	tss.esp0 = curr_process->k_sp; 		// This is good code
	tss.ss0 = KERNEL_DS;

	if(previous_pcb != NULL)
	{
		asm volatile("movl %%esp, %0":"=g"(previous_pcb->k_sp));
		asm volatile("movl %%ebp, %0":"=g"(previous_pcb->k_bp));
	}

	// Jump to program and being executions
	jump_to_userspace(entry_addr);

	// Halt jumps here for finishing execute
	asm volatile("ret_halt:\n\t");				
	 
	return retval;
}