Пример #1
0
pid_t
sys_waitpid(pid_t pid, int * status, int options, int *retval){

	int result = valid_pid(pid);
	
	if(result){
		return result;
	}
	//If there is an option attached, FAIL. NO OPTIONS FOR YOU
	else if(options != 0){
		return EINVAL;
	}
	//If pointer is not aligned, throw an error. NO EXIT CODE FOR YOU
	else if((int)status%4 != 0){
		return EFAULT;
	}
	acquire_lock(pid);
	//While the process has not exited yet,  
	while(has_exit_code(pid) == false){
		put_to_sleep(pid);
	}
	
	*status = _MKWAIT_EXIT(get_exit_code(pid));
	release_lock(pid);
	release_pid(pid);
	*retval = pid;
	return 0;
}
Пример #2
0
report_class runner::get_report() {
    report.application_name = get_program();

    report.exception = get_exception();
    report.exit_code = get_exit_code();
    return report;
}
Пример #3
0
process_status_t runner::get_process_status() {
    //renew process status
    if (process_status & process_finished_normal
     || process_status == process_suspended
     || process_status == process_not_started) {
        return process_status;
    }
    unsigned long exitcode = get_exit_code();
    if (process_status == process_spawner_crash) {
        return process_status;
    }
    if (exitcode == exit_code_still_active) {
        process_status = process_still_active;
    } else {
        process_status = process_finished_abnormally;
    }
    if (exitcode == 0) {
        process_status = process_finished_normal;
    }
    return process_status;
}
Пример #4
0
static int			/* O - 0 = success, non-0 = failure */
smb_print(struct cli_state * cli,	/* I - SMB connection */
	  char *title,		/* I - Title/job name */
	  FILE * fp)
{				/* I - File to print */
	uint16_t             fnum;	/* File number */
	int             nbytes,	/* Number of bytes read */
	                tbytes;	/* Total bytes read */
	char            buffer[8192],	/* Buffer for copy */
	               *ptr;	/* Pointer into title */
	NTSTATUS nt_status;


	/*
         * Sanitize the title...
         */

	for (ptr = title; *ptr; ptr++) {
		if (!isalnum((int) *ptr) && !isspace((int) *ptr)) {
			*ptr = '_';
		}
	}

	/*
         * Open the printer device...
         */

	nt_status = cli_open(cli, title, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE,
			  &fnum);
	if (!NT_STATUS_IS_OK(nt_status)) {
		fprintf(stderr, "ERROR: %s opening remote spool %s\n",
			nt_errstr(nt_status), title);
		return get_exit_code(cli, nt_status);
	}

	/*
         * Copy the file to the printer...
         */

	if (fp != stdin)
		rewind(fp);

	tbytes = 0;

	while ((nbytes = fread(buffer, 1, sizeof(buffer), fp)) > 0) {
		NTSTATUS status;

		status = cli_writeall(cli, fnum, 0, (uint8_t *)buffer,
				      tbytes, nbytes, NULL);
		if (!NT_STATUS_IS_OK(status)) {
			int ret = get_exit_code(cli, status);
			fprintf(stderr, "ERROR: Error writing spool: %s\n",
				nt_errstr(status));
			fprintf(stderr, "DEBUG: Returning status %d...\n",
				ret);
			cli_close(cli, fnum);

			return (ret);
		}
		tbytes += nbytes;
	}

	nt_status = cli_close(cli, fnum);
	if (!NT_STATUS_IS_OK(nt_status)) {
		fprintf(stderr, "ERROR: %s closing remote spool %s\n",
			nt_errstr(nt_status), title);
		return get_exit_code(cli, nt_status);
	} else {
		return (0);
	}
}
Пример #5
0
static struct cli_state *
smb_complete_connection(const char *myname,
			const char *server,
			int port,
			const char *username,
			const char *password,
			const char *workgroup,
			const char *share,
			int flags,
			bool *need_auth)
{
	struct cli_state *cli;	/* New connection */
	NTSTATUS        nt_status;

	/* Start the SMB connection */
	*need_auth = false;
	nt_status = cli_start_connection(&cli, myname, server, NULL, port,
					 Undefined, flags);
	if (!NT_STATUS_IS_OK(nt_status)) {
		fprintf(stderr, "ERROR: Connection failed: %s\n", nt_errstr(nt_status));
		return NULL;
	}

	/*
	 * We pretty much guarantee password must be valid or a pointer to a
	 * 0 char.
	 */
	if (!password) {
		*need_auth = true;
		return NULL;
	}

	nt_status = cli_session_setup(cli, username,
				      password, strlen(password) + 1,
				      password, strlen(password) + 1,
				      workgroup);
	if (!NT_STATUS_IS_OK(nt_status)) {
		fprintf(stderr, "ERROR: Session setup failed: %s\n", nt_errstr(nt_status));

		if (get_exit_code(cli, nt_status) == 2) {
			*need_auth = true;
		}

		cli_shutdown(cli);

		return NULL;
	}

	nt_status = cli_tcon_andx(cli, share, "?????", password,
				  strlen(password) + 1);
	if (!NT_STATUS_IS_OK(nt_status)) {
		fprintf(stderr, "ERROR: Tree connect failed (%s)\n",
			nt_errstr(nt_status));

		if (get_exit_code(cli, nt_status) == 2) {
			*need_auth = true;
		}

		cli_shutdown(cli);

		return NULL;
	}
#if 0
	/* Need to work out how to specify this on the URL. */
	if (smb_encrypt) {
		if (!cli_cm_force_encryption(cli,
					     username,
					     password,
					     workgroup,
					     share)) {
			fprintf(stderr, "ERROR: encryption setup failed\n");
			cli_shutdown(cli);
			return NULL;
		}
	}
#endif

	return cli;
}
Пример #6
0
exception_t runner::get_exception() {
    if (get_process_status() == process_finished_abnormally) {
        return (exception_t)get_exit_code();
    }
    else return exception_exception_no;
}