Exemplo n.º 1
0
/*
 * Main loop
 */
int main(void)
{
    /* Initialize all peripherals */
    open_board();

    /* Configure stdout/stderr to be keyboard input to the host */
    open_streams();

    led_set(3, 1, 1);
    for (;;) {
        poll_matrix();
        update_matrix();
            
        // Handle USB HID reporting
        // Generic USB tasks take place in interrupt
        USB_USBTask();
        USB_HIDTask();

        if (GFLAGS & GF_BOOTLOADER)
            break;

        maybe_sleep();
    }

    /* Disable stdout/stderr. We can't use it if usb is down */
    close_streams();

    /* Teardown everything we setup. Nothing can be active before the jump */
    close_board();

    jump_to_bootloader();
}
Exemplo n.º 2
0
unsigned int get_ea_size(char *name)
{
 #if TARGET==OS2
  #ifdef __32BIT__
   FILESTATUS4 fs;
  #else
   FILESTATUS2 fs;
  #endif
  unsigned int rc;

  #ifdef __32BIT__
   DosQueryPathInfo(name, FIL_QUERYEASIZE, (PVOID)&fs, sizeof(fs));
  #else
   DosQPathInfo(name, FIL_QUERYEASIZE, (PVOID)&fs, sizeof(fs), 0L);
  #endif
  rc=(fs.cbList>=4)?fs.cbList-4:fs.cbList;
  #ifdef __32BIT__
   rc>>=1;                             /* BUGBUG? */
  #endif
  return(rc);
 #elif TARGET==WIN32
  struct nt_sid *sid;
  unsigned long rc;

  if(!ea_supported||(sid=open_streams(name, 0))==NULL)
   return(0);
  rc=seek_stream_id(BACKUP_EA_DATA, sid);
  close_streams(sid);
  return((rc>0xFFFF)?0:rc);
 #else
  return(0);
 #endif
}
Exemplo n.º 3
0
Arquivo: exit.c Projeto: Nakrez/zOS
void exit(int status)
{
    int ret;

    close_streams();

    SYSCALL1(SYS_EXIT, status, ret);

    while (1)
        ;
}
Exemplo n.º 4
0
void prepare_to_execute(char* args[], char* envp[], int in, int out)
{
	int pid = fork();
	switch(pid)
	{
		case -1: 
			shell_error("fork()");
			break;
		case 0:
			open_streams(in, out);
			execute(args, envp);
			break;
		default:
			close_streams(in, out);
			if (wait(0) == -1)
				shell_error("wait()");
	}
}
Exemplo n.º 5
0
int send_app_msgs(int sock)
{
	struct ustcomm_ust_msg lum;
	struct ustcomm_ust_reply lur;
	int ret, i, j, k;

	for (i = 0; i < NR_SESSIONS; i++) {
		/* Create session */
		memset(&lum, 0, sizeof(lum));
		lum.handle = LTTNG_UST_ROOT_HANDLE;
		lum.cmd = LTTNG_UST_SESSION;
		ret = ustcomm_send_app_cmd(sock, &lum, &lur);
		if (ret)
			return ret;
		session_handle[i] = lur.ret_val;
		printf("received session handle %u\n", session_handle[i]);

		/* Create metadata channel */
		memset(&lum, 0, sizeof(lum));
		lum.handle = session_handle[i];
		lum.cmd = LTTNG_UST_METADATA;
		lum.u.channel.overwrite = 0;
		lum.u.channel.subbuf_size = 32768;
		lum.u.channel.num_subbuf = 4;
		lum.u.channel.switch_timer_interval = 0;
		lum.u.channel.read_timer_interval = 0;
		lum.u.channel.output = LTTNG_UST_MMAP;
		ret = ustcomm_send_app_cmd(sock, &lum, &lur);
		if (ret)
			return ret;
		metadata_data[i].handle = lur.ret_val;
		printf("received metadata handle %u\n", metadata_data[i].handle);
		if (lur.ret_code == LTTNG_UST_OK) {
			ssize_t len;

			metadata_data[i].memory_map_size = lur.u.channel.memory_map_size;
			/* get shm fd */
			len = ustcomm_recv_fd(sock);
			if (len < 0)
				return -EINVAL;
			metadata_data[i].shm_fd = len;
			/* get wait fd */
			len = ustcomm_recv_fd(sock);
			if (len < 0)
				return -EINVAL;
			metadata_data[i].wait_fd = len;
		}

		ret = open_streams(sock, metadata_data[i].handle,
				&metadata_stream_data[i], 1);
		if (ret) {
			printf("Error in open_streams\n");
			return ret;
		}

		/* Create channels */
		for (j = 0; j < NR_CHANNELS; j++) {
			memset(&lum, 0, sizeof(lum));
			lum.handle = session_handle[i];
			lum.cmd = LTTNG_UST_CHANNEL;
			//lum.u.channel.overwrite = 0;
			lum.u.channel.overwrite = 1;
			lum.u.channel.subbuf_size = 32768;
			lum.u.channel.num_subbuf = 8;
			//lum.u.channel.num_subbuf = 4;
			//lum.u.channel.num_subbuf = 2;
			lum.u.channel.switch_timer_interval = 0;
			lum.u.channel.read_timer_interval = 0;
			lum.u.channel.output = LTTNG_UST_MMAP;
			ret = ustcomm_send_app_cmd(sock, &lum, &lur);
			if (ret)
				return ret;
			channel_data[i][j].handle = lur.ret_val;
			printf("received channel handle %u\n", channel_data[i][j].handle);
			if (lur.ret_code == LTTNG_UST_OK) {
				ssize_t len;

				channel_data[i][j].memory_map_size = lur.u.channel.memory_map_size;
				/* get shm fd */
				len = ustcomm_recv_fd(sock);
				if (len < 0)
					return -EINVAL;
				channel_data[i][j].shm_fd = len;
				/* get wait fd */
				len = ustcomm_recv_fd(sock);
				if (len < 0)
					return -EINVAL;
				channel_data[i][j].wait_fd = len;
			}

			/* Create events */
			for (k = 0; k < NR_EVENTS; k++) {
				memset(&lum, 0, sizeof(lum));
				lum.handle = channel_data[i][j].handle;
				lum.cmd = LTTNG_UST_EVENT;
				strncpy(lum.u.event.name, evname[k],
					LTTNG_UST_SYM_NAME_LEN);
				lum.u.event.instrumentation = LTTNG_UST_TRACEPOINT;
				ret = ustcomm_send_app_cmd(sock, &lum, &lur);
				if (ret)
					return ret;
				event_handle[i][j][k] = lur.ret_val;
				printf("received event handle %u\n", event_handle[i][j][k]);
			}

			/* Get references to channel streams */
			ret = open_streams(sock, channel_data[i][j].handle,
					stream_data[i][j], MAX_NR_STREAMS);
			if (ret) {
				printf("Error in open_streams\n");
				return ret;
			}
		}

		memset(&lum, 0, sizeof(lum));
		lum.handle = session_handle[i];
		lum.cmd = LTTNG_UST_SESSION_START;
		ret = ustcomm_send_app_cmd(sock, &lum, &lur);
		if (ret)
			return ret;
		printf("Session handle %u started.\n", session_handle[i]);
	}

	/* Tell application registration is done */
	memset(&lum, 0, sizeof(lum));
	lum.handle = LTTNG_UST_ROOT_HANDLE;
	lum.cmd = LTTNG_UST_REGISTER_DONE;
	ret = ustcomm_send_app_cmd(sock, &lum, &lur);
	if (ret)
		return ret;
	printf("Registration done acknowledged.\n");

	sleep(4);

	ret = consume_buffers();
	if (ret) {
		printf("Error in consume_buffers\n");
		return ret;
	}

	for (i = 0; i < NR_SESSIONS; i++) {
		/* Release channels */
		for (j = 0; j < NR_CHANNELS; j++) {
			/* Release streams */
			ret = close_streams(sock, stream_data[i][j],
					MAX_NR_STREAMS);
			if (ret)
				return ret;

			/* Release events */
			for (k = 0; k < NR_EVENTS; k++) {
				memset(&lum, 0, sizeof(lum));
				lum.handle = event_handle[i][j][k];
				lum.cmd = LTTNG_UST_RELEASE;
				ret = ustcomm_send_app_cmd(sock, &lum, &lur);
				if (ret)
					return ret;
			}
			memset(&lum, 0, sizeof(lum));
			lum.handle = channel_data[i][j].handle;
			lum.cmd = LTTNG_UST_RELEASE;
			ret = ustcomm_send_app_cmd(sock, &lum, &lur);
			if (ret)
				return ret;
			if (channel_data[i][j].shm_fd >= 0) {
				ret = close(channel_data[i][j].shm_fd);
				if (ret)
					return ret;
			}
			if (channel_data[i][j].wait_fd >= 0) {
				ret = close(channel_data[i][j].wait_fd);
				if (ret)
					return ret;
			}
		}

		/* Release metadata channel */
		ret = close_streams(sock, &metadata_stream_data[i], 1);
		if (ret)
			return ret;

		memset(&lum, 0, sizeof(lum));
		lum.handle = metadata_data[i].handle;
		lum.cmd = LTTNG_UST_RELEASE;
		ret = ustcomm_send_app_cmd(sock, &lum, &lur);
		if (ret)
			return ret;
		if (metadata_data[i].shm_fd >= 0) {
			ret = close(metadata_data[i].shm_fd);
			if (ret)
				return ret;
		}
		if (metadata_data[i].wait_fd >= 0) {
			ret = close(metadata_data[i].wait_fd);
			if (ret)
				return ret;
		}

		/* Release session */
		memset(&lum, 0, sizeof(lum));
		lum.handle = session_handle[i];
		lum.cmd = LTTNG_UST_RELEASE;
		ret = ustcomm_send_app_cmd(sock, &lum, &lur);
		if (ret)
			return ret;
	}

	return 0;
}
Exemplo n.º 6
0
int exec_wait()
{
    int         i;
    int         ret;
    int         fd_max;
    int         pid;
    int         status;
    int         finished;
    int         rstat;
    timing_info time_info;
    fd_set      fds;
    struct tms  new_time;

    /* Handle naive make1() which does not know if commands are running. */
    if ( !cmdsrunning )
        return 0;

    /* Process children that signaled. */
    finished = 0;
    while ( !finished && cmdsrunning )
    {
        /* Compute max read file descriptor for use in select(). */
        populate_file_descriptors( &fd_max, &fds );

        if ( 0 < globs.timeout )
        {
            /* Force select() to timeout so we can terminate expired processes.
             */
            tv.tv_sec = select_timeout;
            tv.tv_usec = 0;

            /* select() will wait until: i/o on a descriptor, a signal, or we
             * time out.
             */
            ret = select( fd_max + 1, &fds, 0, 0, &tv );
        }
        else
        {
            /* select() will wait until i/o on a descriptor or a signal. */
            ret = select( fd_max + 1, &fds, 0, 0, 0 );
        }

        if ( 0 < ret )
        {
            for ( i = 0; i < globs.jobs; ++i )
            {
                int out = 0;
                int err = 0;
                if ( FD_ISSET( cmdtab[ i ].fd[ OUT ], &fds ) )
                    out = read_descriptor( i, OUT );

                if ( ( globs.pipe_action != 0 ) &&
                    ( FD_ISSET( cmdtab[ i ].fd[ ERR ], &fds ) ) )
                    err = read_descriptor( i, ERR );

                /* If feof on either descriptor, then we are done. */
                if ( out || err )
                {
                    /* Close the stream and pipe descriptors. */
                    close_streams( i, OUT );
                    if ( globs.pipe_action != 0 )
                        close_streams( i, ERR );

                    /* Reap the child and release resources. */
                    pid = waitpid( cmdtab[ i ].pid, &status, 0 );

                    if ( pid == cmdtab[ i ].pid )
                    {
                        finished = 1;
                        pid = 0;
                        cmdtab[ i ].pid = 0;

                        /* Set reason for exit if not timed out. */
                        if ( WIFEXITED( status ) )
                        {
                            cmdtab[ i ].exit_reason = 0 == WEXITSTATUS( status )
                                ? EXIT_OK
                                : EXIT_FAIL;
                        }

                        /* Print out the rule and target name. */
                        out_action( cmdtab[ i ].action, cmdtab[ i ].target,
                            cmdtab[ i ].command, cmdtab[ i ].buffer[ OUT ],
                            cmdtab[ i ].buffer[ ERR ], cmdtab[ i ].exit_reason
                        );

                        times( &new_time );

                        time_info.system = (double)( new_time.tms_cstime - old_time.tms_cstime ) / CLOCKS_PER_SEC;
                        time_info.user   = (double)( new_time.tms_cutime - old_time.tms_cutime ) / CLOCKS_PER_SEC;
                        time_info.start  = cmdtab[ i ].start_dt;
                        time_info.end    = time( 0 );

                        old_time = new_time;

                        /* Drive the completion. */
                        --cmdsrunning;

                        if ( intr )
                            rstat = EXEC_CMD_INTR;
                        else if ( status != 0 )
                            rstat = EXEC_CMD_FAIL;
                        else
                            rstat = EXEC_CMD_OK;

                        /* Assume -p0 in effect so only pass buffer[ 0 ]
                         * containing merged output.
                         */
                        (*cmdtab[ i ].func)( cmdtab[ i ].closure, rstat,
                            &time_info, cmdtab[ i ].command,
                            cmdtab[ i ].buffer[ 0 ] );

                        BJAM_FREE( cmdtab[ i ].buffer[ OUT ] );
                        cmdtab[ i ].buffer[ OUT ] = 0;

                        BJAM_FREE( cmdtab[ i ].buffer[ ERR ] );
                        cmdtab[ i ].buffer[ ERR ] = 0;

                        BJAM_FREE( cmdtab[ i ].command );
                        cmdtab[ i ].command = 0;

                        cmdtab[ i ].func = 0;
                        cmdtab[ i ].closure = 0;
                        cmdtab[ i ].start_time = 0;
                    }
                    else
                    {
                        printf( "unknown pid %d with errno = %d\n", pid, errno );
                        exit( EXITBAD );
                    }
                }
            }
        }
    }

    return 1;
}
Exemplo n.º 7
0
int exec_wait()
{
    int         i, j;
    int         ret;
    int         fd_max;
    int         pid;
    int         status;
    int         finished;
    fd_set      fds;

    /* Handle naive make1() which does not know if commands are running. */
    if ( !cmdsrunning )
        return 0;

    /* Process children that signaled. */
    finished = 0;
    while ( !finished && cmdsrunning )
    {
        /* Compute max read file descriptor for use in select(). */
        populate_file_descriptors( &fd_max, &fds );

        if ( 0 < globs.timeout )
        {
            /* Force select() to timeout so we can terminate expired processes.
             */
            tv.tv_sec = select_timeout;
            tv.tv_nsec = 0;

            /* select() will wait until: i/o on a descriptor, a signal, or we
             * time out.
             */
            ret = pselect( fd_max + 1, &fds, 0, 0, &tv, &empty_sigmask );
        }
        else
        {
            /* pselect() will wait until i/o on a descriptor or a signal. */
            ret = pselect( fd_max + 1, &fds, 0, 0, 0, &empty_sigmask );
        }

        if (-1 == ret && errno != EINTR) {
            perror("pselect()");
            exit(-1);
        }

        if (0 < child_events) {
            /* child terminated via SIGCHLD */
            for (i=0; i<MAXJOBS; ++i) {
                if (0 < terminated_children[i].pid) {
                    pid_t pid = terminated_children[i].pid;
                    /* get index of terminated pid */
                    for (j=0; j<globs.jobs; ++j) {
                        if (pid == cmdtab[j].pid) {
                            /* cleanup loose ends for terminated process */
                            close_streams(j, OUT);
                            if ( globs.pipe_action != 0 ) close_streams(j, ERR);
                            cleanup_child(j, terminated_children[i].status);
                            --cmdsrunning;
                            finished = 1;
                            break;
                        }
                    }
                    /* clear entry from list */
                    terminated_children[i].status = 0;
                    terminated_children[i].pid = 0;
                    --child_events;
                }
            }
        }

        if ( 0 < ret )
        {
            for ( i = 0; i < globs.jobs; ++i )
            {
                int out = 0;
                int err = 0;
                if ( FD_ISSET( cmdtab[ i ].fd[ OUT ], &fds ) )
                    out = read_descriptor( i, OUT );

                if ( ( globs.pipe_action != 0 ) &&
                    ( FD_ISSET( cmdtab[ i ].fd[ ERR ], &fds ) ) )
                    err = read_descriptor( i, ERR );

                /* If feof on either descriptor, then we are done. */
                if ( out || err )
                {
                    /* Close the stream and pipe descriptors. */
                    close_streams( i, OUT );
                    if ( globs.pipe_action != 0 )
                        close_streams( i, ERR );

                    /* Reap the child and release resources. */
                    pid = waitpid( cmdtab[ i ].pid, &status, 0 );

                    if ( pid == cmdtab[ i ].pid )
                    {
                        /* move into function so signal handler can also use */
                        finished = 1;
                        cleanup_child(i, status);
                        --cmdsrunning;
                    }
                    else
                    {
                        printf( "unknown pid %d with errno = %d\n", pid, errno );
                        exit( EXITBAD );
                    }
                }
            }
        }
    }
    return 1;
}
Exemplo n.º 8
0
void exec_wait()
{
    int finished = 0;

    /* Process children that signaled. */
    while ( !finished )
    {
        int i;
        struct timeval tv;
        struct timeval * ptv = NULL;
        int select_timeout = globs.timeout;

        /* Check for timeouts:
         *   - kill children that already timed out
         *   - decide how long until the next one times out
         */
        if ( globs.timeout > 0 )
        {
            struct tms buf;
            clock_t const current = times( &buf );
            for ( i = 0; i < globs.jobs; ++i )
                if ( cmdtab[ i ].pid )
                {
                    clock_t const consumed =
                        ( current - cmdtab[ i ].start_time ) / tps;
                    if ( consumed >= globs.timeout )
                    {
                        killpg( cmdtab[ i ].pid, SIGKILL );
                        cmdtab[ i ].exit_reason = EXIT_TIMEOUT;
                    }
                    else if ( globs.timeout - consumed < select_timeout )
                        select_timeout = globs.timeout - consumed;
                }

            /* If nothing else causes our select() call to exit, force it after
             * however long it takes for the next one of our child processes to
             * crossed its alloted processing time so we can terminate it.
             */
            tv.tv_sec = select_timeout;
            tv.tv_usec = 0;
            ptv = &tv;
        }

        /* select() will wait for I/O on a descriptor, a signal, or timeout. */
        {
            /* disable child termination signals while in select */
            int ret;
            sigset_t sigmask;
            sigemptyset(&sigmask);
            sigaddset(&sigmask, SIGCHLD);
            sigprocmask(SIG_BLOCK, &sigmask, NULL);
            while ( ( ret = poll( wait_fds, WAIT_FDS_SIZE, select_timeout * 1000 ) ) == -1 )
                if ( errno != EINTR )
                    break;
            /* restore original signal mask by unblocking sigchld */
            sigprocmask(SIG_UNBLOCK, &sigmask, NULL);
            if ( ret <= 0 )
                continue;
        }

        for ( i = 0; i < globs.jobs; ++i )
        {
            int out_done = 0;
            int err_done = 0;
            if ( GET_WAIT_FD( i )[ OUT ].revents )
                out_done = read_descriptor( i, OUT );

            if ( globs.pipe_action && ( GET_WAIT_FD( i )[ ERR ].revents ) )
                err_done = read_descriptor( i, ERR );

            /* If feof on either descriptor, we are done. */
            if ( out_done || err_done )
            {
                int pid;
                int status;
                int rstat;
                timing_info time_info;
                struct rusage cmd_usage;

                /* We found a terminated child process - our search is done. */
                finished = 1;

                /* Close the stream and pipe descriptors. */
                close_streams( i, OUT );
                if ( globs.pipe_action )
                    close_streams( i, ERR );

                /* Reap the child and release resources. */
                while ( ( pid = wait4( cmdtab[ i ].pid, &status, 0, &cmd_usage ) ) == -1 )
                    if ( errno != EINTR )
                        break;
                if ( pid != cmdtab[ i ].pid )
                {
                    err_printf( "unknown pid %d with errno = %d\n", pid, errno );
                    exit( EXITBAD );
                }

                /* Set reason for exit if not timed out. */
                if ( WIFEXITED( status ) )
                    cmdtab[ i ].exit_reason = WEXITSTATUS( status )
                        ? EXIT_FAIL
                        : EXIT_OK;

                {
                    time_info.system = ((double)(cmd_usage.ru_stime.tv_sec)*1000000.0+(double)(cmd_usage.ru_stime.tv_usec))/1000000.0;
                    time_info.user   = ((double)(cmd_usage.ru_utime.tv_sec)*1000000.0+(double)(cmd_usage.ru_utime.tv_usec))/1000000.0;
                    timestamp_copy( &time_info.start, &cmdtab[ i ].start_dt );
                    timestamp_current( &time_info.end );
                }

                /* Drive the completion. */
                if ( interrupted() )
                    rstat = EXEC_CMD_INTR;
                else if ( status )
                    rstat = EXEC_CMD_FAIL;
                else
                    rstat = EXEC_CMD_OK;

                /* Call the callback, may call back to jam rule land. */
                (*cmdtab[ i ].func)( cmdtab[ i ].closure, rstat, &time_info,
                    cmdtab[ i ].buffer[ OUT ], cmdtab[ i ].buffer[ ERR ],
                    cmdtab[ i ].exit_reason );

                /* Clean up the command's running commands table slot. */
                BJAM_FREE( cmdtab[ i ].buffer[ OUT ] );
                cmdtab[ i ].buffer[ OUT ] = 0;
                cmdtab[ i ].buf_size[ OUT ] = 0;

                BJAM_FREE( cmdtab[ i ].buffer[ ERR ] );
                cmdtab[ i ].buffer[ ERR ] = 0;
                cmdtab[ i ].buf_size[ ERR ] = 0;

                cmdtab[ i ].pid = 0;
                cmdtab[ i ].func = 0;
                cmdtab[ i ].closure = 0;
                cmdtab[ i ].start_time = 0;
            }
        }
    }
}
Exemplo n.º 9
0
void exec_wait()
{
    int finished = 0;

    /* Process children that signaled. */
    while ( !finished )
    {
        int i;
        struct timeval tv;
        struct timeval * ptv = NULL;
        int select_timeout = globs.timeout;

        /* Prepare file descriptor information for use in select(). */
        fd_set fds;
        int const fd_max = populate_file_descriptors( &fds );

        /* Check for timeouts:
         *   - kill children that already timed out
         *   - decide how long until the next one times out
         */
        if ( globs.timeout > 0 )
        {
            struct tms buf;
            clock_t const current = times( &buf );
            for ( i = 0; i < globs.jobs; ++i )
                if ( cmdtab[ i ].pid )
                {
                    clock_t const consumed =
                        ( current - cmdtab[ i ].start_time ) / tps;
                    if ( consumed >= globs.timeout )
                    {
                        killpg( cmdtab[ i ].pid, SIGKILL );
                        cmdtab[ i ].exit_reason = EXIT_TIMEOUT;
                    }
                    else if ( globs.timeout - consumed < select_timeout )
                        select_timeout = globs.timeout - consumed;
                }

            /* If nothing else causes our select() call to exit, force it after
             * however long it takes for the next one of our child processes to
             * crossed its alloted processing time so we can terminate it.
             */
            tv.tv_sec = select_timeout;
            tv.tv_usec = 0;
            ptv = &tv;
        }

        /* select() will wait for I/O on a descriptor, a signal, or timeout. */
        {
            int ret;
            while ( ( ret = select( fd_max + 1, &fds, 0, 0, ptv ) ) == -1 )
                if ( errno != EINTR )
                    break;
            if ( ret <= 0 )
                continue;
        }

        for ( i = 0; i < globs.jobs; ++i )
        {
            int out_done = 0;
            int err_done = 0;
            if ( FD_ISSET( cmdtab[ i ].fd[ OUT ], &fds ) )
                out_done = read_descriptor( i, OUT );

            if ( globs.pipe_action && FD_ISSET( cmdtab[ i ].fd[ ERR ], &fds ) )
                err_done = read_descriptor( i, ERR );

            /* If feof on either descriptor, we are done. */
            if ( out_done || err_done )
            {
                int pid;
                int status;
                int rstat;
                timing_info time_info;

                /* We found a terminated child process - our search is done. */
                finished = 1;

                /* Close the stream and pipe descriptors. */
                close_streams( i, OUT );
                if ( globs.pipe_action )
                    close_streams( i, ERR );

                /* Reap the child and release resources. */
                while ( ( pid = waitpid( cmdtab[ i ].pid, &status, 0 ) ) == -1 )
                    if ( errno != EINTR )
                        break;
                if ( pid != cmdtab[ i ].pid )
                {
                    printf( "unknown pid %d with errno = %d\n", pid, errno );
                    exit( EXITBAD );
                }

                /* Set reason for exit if not timed out. */
                if ( WIFEXITED( status ) )
                    cmdtab[ i ].exit_reason = WEXITSTATUS( status )
                        ? EXIT_FAIL
                        : EXIT_OK;

                {
                    struct tms new_time;
                    times( &new_time );
                    time_info.system = (double)( new_time.tms_cstime -
                        old_time.tms_cstime ) / CLOCKS_PER_SEC;
                    time_info.user   = (double)( new_time.tms_cutime -
                        old_time.tms_cutime ) / CLOCKS_PER_SEC;
                    timestamp_copy( &time_info.start, &cmdtab[ i ].start_dt );
                    timestamp_current( &time_info.end );
                    old_time = new_time;
                }

                /* Drive the completion. */
                if ( interrupted() )
                    rstat = EXEC_CMD_INTR;
                else if ( status )
                    rstat = EXEC_CMD_FAIL;
                else
                    rstat = EXEC_CMD_OK;

                /* Call the callback, may call back to jam rule land. */
                (*cmdtab[ i ].func)( cmdtab[ i ].closure, rstat, &time_info,
                    cmdtab[ i ].buffer[ OUT ], cmdtab[ i ].buffer[ ERR ],
                    cmdtab[ i ].exit_reason );

                /* Clean up the command's running commands table slot. */
                BJAM_FREE( cmdtab[ i ].buffer[ OUT ] );
                cmdtab[ i ].buffer[ OUT ] = 0;
                cmdtab[ i ].buf_size[ OUT ] = 0;

                BJAM_FREE( cmdtab[ i ].buffer[ ERR ] );
                cmdtab[ i ].buffer[ ERR ] = 0;
                cmdtab[ i ].buf_size[ ERR ] = 0;

                cmdtab[ i ].pid = 0;
                cmdtab[ i ].func = 0;
                cmdtab[ i ].closure = 0;
                cmdtab[ i ].start_time = 0;
            }
        }
    }
}
Exemplo n.º 10
0
int resolve_longname(char *dest, char *name)
{
 #ifdef HAVE_EAS
  unsigned char *tmp_name;
  int entry, l_sel, rc;
  #if TARGET==OS2
   #ifdef __32BIT__
    EAOP2 eaop;
    PGEA2LIST pgeal;
    PFEA2LIST pfeal;
   #else
    EAOP eaop;
    PGEALIST pgeal;
    PFEALIST pfeal;
   #endif
  #elif TARGET==WIN32
   struct nt_sid *sid=NULL;
   unsigned char *streambuf=NULL;
   unsigned long stream_len, rem_len, fetch;
   FEALIST feal;
   PFEALIST pfeal;
  #endif
  char FAR *valptr;
  unsigned int st_len;

  if(name[0]=='\0'||name[0]==PATHSEP_DEFAULT&&name[1]=='\0'||name[1]==':'&&name[2]=='\0')
  {
   strcpy(dest, name);
   return(0);
  }
  tmp_name=(char *)malloc_msg(FILENAME_MAX);
  l_sel=entry=split_name(name, tmp_name, NULL);
  if(entry>0)
  {
   tmp_name[entry-1]='\0';
   resolve_longname(dest, tmp_name);
   entry=strlen(dest);
   dest[entry]=PATHSEP_DEFAULT;
   dest[entry+1]='\0';
  }
  else
   dest[0]='\0';
  #if TARGET==OS2
   #ifdef __32BIT__
    pgeal=(PGEA2LIST)farmalloc_msg(sizeof(GEA2LIST)+sizeof(longname_ea));
    pfeal=(PFEA2LIST)farmalloc_msg(sizeof(FEA2LIST)+sizeof(longname_ea)+FILENAME_MAX);
   #else
    pgeal=(PGEALIST)farmalloc_msg(sizeof(GEALIST)+sizeof(longname_ea));
    pfeal=(PFEALIST)farmalloc_msg(sizeof(FEALIST)+sizeof(longname_ea)+FILENAME_MAX);
   #endif
   far_strcpy(pgeal->list[0].szName, (char FAR *)longname_ea);
  #elif TARGET==WIN32
   pfeal=(PFEALIST)farmalloc_msg(sizeof(FEALIST)+sizeof(longname_ea)+FILENAME_MAX);
  #endif
  #if TARGET==OS2
   #ifdef __32BIT__
    pgeal->list[0].oNextEntryOffset=0;
   #endif
   pgeal->list[0].cbName=sizeof(longname_ea)-1;
   #ifdef __32BIT__
    pgeal->cbList=sizeof(GEA2LIST)+sizeof(longname_ea)-1;
    pfeal->cbList=sizeof(FEA2LIST)+sizeof(longname_ea)+FILENAME_MAX-1-entry;
    eaop.fpGEA2List=pgeal;
    eaop.fpFEA2List=pfeal;
   #else
    pgeal->cbList=sizeof(GEALIST)+sizeof(longname_ea)-1;
    pfeal->cbList=sizeof(FEALIST)+sizeof(longname_ea)+FILENAME_MAX-1-entry;
    eaop.fpGEAList=pgeal;
    eaop.fpFEAList=pfeal;
   #endif
   #ifdef __32BIT__
    if(DosQueryPathInfo(name, FIL_QUERYEASFROMLIST, (PBYTE)&eaop, sizeof(eaop)))
   #else
    if(DosQPathInfo(name, FIL_QUERYEASFROMLIST, (PBYTE)&eaop, sizeof(eaop), 0L))
   #endif
     rc=0;
   else
   {
    rc=1;
    #ifdef __32BIT__
     valptr=(char FAR *)pfeal+sizeof(FEA2LIST)+pfeal->list[0].cbName;
    #else
     valptr=(char FAR *)pfeal+sizeof(FEALIST)+pfeal->list[0].cbName+1;
    #endif
   }
  #elif TARGET==WIN32
   rc=0;
   if((sid=open_streams(name, 0))!=NULL&&
      (stream_len=seek_stream_id(BACKUP_EA_DATA, sid))>0)
   {
    valptr=streambuf=(char *)farmalloc_msg(256);
    pfeal=(PFEALIST)&feal;
    while(read_stream((char *)pfeal, sizeof(FEALIST), sid)==sizeof(FEALIST)&&
          read_stream(streambuf, pfeal->list[0].cbName+1, sid)==pfeal->list[0].cbName+1)
    {
     rem_len=pfeal->cbList-sizeof(FEALIST)-pfeal->list[0].cbName-1;
     if(!stricmp(streambuf, longname_ea))
     {
      if(pfeal->list[0].cbValue<256)
      {
       read_stream(streambuf, pfeal->list[0].cbValue, sid);
       rc=1;
       break;
      }
     }
     else
     {
      if(pfeal->cbList==0)
       break;
      /* Advance to the next EA entry */
      while(rem_len>0)
      {
       fetch=min(256, rem_len);
       read_stream(streambuf, fetch, sid);
       rem_len-=fetch;
      }
     }
    }
   }
  #endif
  if(rc)
  {
   if((st_len=pfeal->list[0].cbValue)==0)
    rc=0;
   else
   {
    far_memmove((char FAR *)tmp_name, valptr, st_len);
    tmp_name[st_len]='\0';
    if(tmp_name[0]==0xFD&&tmp_name[1]==0xFF)
    {
     strcpy(tmp_name, (char *)tmp_name+4);
     st_len-=4;
    }
    if(st_len==0||st_len+entry>=FILENAME_MAX)
     rc=0;
    else
    {
     while(st_len-->0)
     {
      if(tmp_name[st_len]<' '||strchr(forbidden_chars, tmp_name[st_len])!=NULL)
      {
       rc=0;
       break;
      }
     }
    }
   }
  }
  if(!rc)
  {
   if(strlen(name)+entry+l_sel>=FILENAME_MAX)
    error(M_MAXPATH_EXCEEDED, FILENAME_MAX, name);
   strcat(dest, name+l_sel);
  }
  else
   strcat(dest, (char *)tmp_name);
  #if TARGET==OS2
   farfree(pgeal);
   farfree(pfeal);
  #elif TARGET==WIN32
   if(streambuf!=NULL)
    farfree(streambuf);
   if(sid!=NULL)
    close_streams(sid);
  #endif
  free(tmp_name);
  return(rc);
 #else
  return(0);
 #endif
}
Exemplo n.º 11
0
int set_ea(char FAR *i_eas, char *name)
{
 #ifdef HAVE_EAS
  int rc=0;
  char FAR *eas;
  unsigned int i, total;
  #if TARGET==OS2
   #ifdef __32BIT__
    FILESTATUS4 fs;
    EAOP2 eaop;
    char FAR *real_pfeal;
    PFEA2LIST pfeal;
    PFEA2 pf, opf;
   #else
    EAOP eaop;
    PFEALIST pfeal;
    PFEA pf;
    FILESTATUS2 fs;
    SEL selector;
   #endif
  #elif TARGET==WIN32
   PFEALIST pfeal0, pfeal;
   PFEA pf;
   struct nt_sid *sid;
   unsigned char *pstreambuf, *streambuf;
   WIN32_STREAM_ID w32sid;
   unsigned long stream_len;
  #endif

  eas=i_eas;
  if(discard_ea(name))
   return(-1);
  if((total=mget_word(eas))==0)
   return(0);
  #if TARGET==OS2
   #ifdef __32BIT__
    /* This takes the 4-byte prefixes into account (are the V1.2 EAs still
       valid if they flow beyond 64K when the oNextEntryOffset is applied?).
       Also, we ensure that it is aligned properly. In theory, there may be
       a way to crash this (72K doesn't consider the multitude of EAs) but we
       don't know/care about it -- ASR 17/10/2000 */
    real_pfeal=(char FAR *)farmalloc_msg(73728);
    pfeal=(PFEA2LIST)align_dword(real_pfeal);
    eaop.fpFEA2List=pfeal;
   #else
    if(DosAllocSeg(65535U, &selector, SEG_NONSHARED))
     return(-1);
    pfeal=(PFEALIST)MAKEP(selector, 0);
    eaop.fpFEAList=pfeal;
   #endif
  #elif TARGET==WIN32
   pstreambuf=(char *)farmalloc_msg(65536+260*total);
   pfeal=pfeal0=(PFEALIST)(streambuf=align_dword(pstreambuf));
  #endif
  eas+=2;
  pf=&pfeal->list[0];
  for(i=0; i<total; i++)
  {
   #if TARGET==OS2&&defined(__32BIT__)
    opf=pf;
   #endif
   #if TARGET==WIN32
    pf=&pfeal->list[0];
   #endif
   pf->fEA=mget_byte(eas++);
   pf->cbName=mget_byte(eas++);
   pf->cbValue=mget_word(eas);
   eas+=2;
   #if TARGET==OS2&&defined(__32BIT__)
     far_memmove((char FAR *)pf+sizeof(FEA2)-1, eas, pf->cbName);
     *((char FAR *)pf+sizeof(FEA2)-1+pf->cbName)='\0';
   #else /* Win32 or OS/2-16 */
     far_memmove((char FAR *)pf+sizeof(FEA), eas, pf->cbName);
     *((char FAR *)pf+sizeof(FEA)+pf->cbName)='\0';
   #endif
   eas+=pf->cbName;
   #if TARGET==OS2&&defined(__32BIT__)
    far_memmove((char FAR *)pf+sizeof(FEA2)+pf->cbName, eas, pf->cbValue);
   #else /* Win32 or OS/2-16 */
    far_memmove((char FAR *)pf+sizeof(FEA)+pf->cbName+1, eas, pf->cbValue);
   #endif
   eas+=pf->cbValue;
   #if SFX_LEVEL>=ARJ
    #if TARGET==OS2&&defined(__32BIT__)
     if(ea_filter((char FAR *)pf+sizeof(FEA2), 0)&&((pf->fEA&FEA_NEEDEA)||!crit_eas))
    #else /* Win32 or OS/2-16 */
     if(ea_filter((char FAR *)pf+sizeof(FEA), 0)&&((pf->fEA&FEA_NEEDEA)||!crit_eas))
    #endif
   #endif
   /* Update the offsets */
   #if TARGET==OS2
    #ifdef __32BIT__
     pf=(PFEA2)((char FAR *)pf+sizeof(FEA2)+pf->cbName+pf->cbValue);
    #else
     pf=(PFEA)((char FAR *)pf+sizeof(FEA)+pf->cbName+1+pf->cbValue);
    #endif
    /* Align at DWORD boundary and issue the list fixups */
    #ifdef __32BIT__
     pf=(PFEA2)align_dword((char FAR *)pf);
     opf->oNextEntryOffset=(i+1==total)?0:(char FAR *)pf-(char FAR *)opf;
    #endif
   #elif TARGET==WIN32
    pfeal=(PFEALIST)((char FAR *)pfeal+sizeof(FEALIST)+pf->cbName+1+pf->cbValue);
    if(i<total-1)
     pfeal=(PFEALIST)align_dword((char FAR*)pfeal);
    pfeal0->cbList=(i==total-1)?
                   0:
                   (((char FAR *)pfeal)-((char FAR *)pfeal0));
    pfeal0=pfeal;
   #endif
  }
  #if TARGET==OS2
   pfeal->cbList=(char FAR *)pf-(char FAR *)pfeal;
   #ifdef __32BIT__
    rc=DosSetPathInfo((PSZ)name, FIL_QUERYEASIZE, (PBYTE)&eaop, sizeof(eaop), 0);
    farfree(real_pfeal);
   #else
    rc=DosSetPathInfo((PSZ)name, FIL_QUERYEASIZE, (PBYTE)&eaop, sizeof(eaop), 0, 0L);
    DosFreeSeg(selector);
   #endif
   if(!rc)
   {
    #ifdef __32BIT__
     if(DosQueryPathInfo(name, FIL_QUERYEASIZE, (PVOID)&fs, sizeof(fs)))
    #else
     if(DosQPathInfo(name, FIL_QUERYEASIZE, (PVOID)&fs, sizeof(fs), 0L))
    #endif
     rc=-1;
    else
     if(fs.cbList<=4)
      rc=-1;
   }
  #elif TARGET==WIN32
   if((sid=open_streams(name, 1))==NULL)
    rc=-1;
   else
   {
    memset(&w32sid, 0, sizeof(w32sid));
    w32sid.dwStreamId=BACKUP_EA_DATA;
    w32sid.Size.LowPart=stream_len=(((char FAR *)pfeal)-streambuf);
    if(create_stream(&w32sid, sid)||write_stream(streambuf, stream_len, sid)<stream_len)
     rc=-1;
    close_streams(sid);
   }
   free(pstreambuf);
  #endif
  return(rc);
 #else
  return(-1);
 #endif
}
Exemplo n.º 12
0
int query_ea(char FAR **dest, char *name, int skip_ln)
{
 #ifdef HAVE_EAS
  ULONG count, j;
  #if TARGET==OS2
   #ifdef __32BIT__
    EAOP2 eaop;
    PGEA2LIST pgeal;
    PFEA2LIST pfeal;
    APIRET rc;
    PDENA2 pdena;
    FILESTATUS4 fs;
   #else
    EAOP eaop;
    PGEALIST pgeal;
    PFEALIST pfeal;
    USHORT rc;
    PDENA1 pdena;
    FILESTATUS2 fs;
   #endif
  #elif TARGET==WIN32
   struct nt_sid *sid;
   unsigned char *streambuf;
   unsigned long stream_len;
   PFEALIST pfeal;
  #endif
  int rcode=0;
  char FAR *dptr, FAR *nptr;

  #if TARGET==OS2
   pdena=farmalloc_msg(sizeof(*pdena)+CCHMAXPATHCOMP);
   #ifdef __32BIT__
    pgeal=(PGEA2LIST)farmalloc_msg(sizeof(GEA2LIST)+CCHMAXPATHCOMP);
    if(DosQueryPathInfo(name, FIL_QUERYEASIZE, (PVOID)&fs, sizeof(fs)))
     return(-1);
   #else
    pgeal=(PGEALIST)farmalloc_msg(sizeof(GEALIST)+CCHMAXPATHCOMP);
    if(DosQPathInfo(name, FIL_QUERYEASIZE, (PVOID)&fs, sizeof(fs), 0L))
     return(-1);
   #endif
   if(fs.cbList<4)
    fs.cbList=4;                         /* Fix for Ext2FS */
   /* Allocate enough space to hold EA block */
   #ifdef __32BIT__
    *dest=(char FAR *)farmalloc_msg((int)fs.cbList*2); /* SDK does recommend it */
   #else
    *dest=(char FAR *)farmalloc_msg((int)fs.cbList-2);
   #endif
  #elif TARGET==WIN32
   if((sid=open_streams(name, 0))==NULL)
    return(-1);
   stream_len=seek_stream_id(BACKUP_EA_DATA, sid);
   if(stream_len==0||stream_len>65535)
   {
    close_streams(sid);
    *dest=(char FAR *)farmalloc_msg(2);
    dptr=*dest;
    mput_word(0, dptr);
    return(0);
   }
   /* It's a plain FEALIST, so doesn't require much caution */
   streambuf=(char FAR *)farmalloc_msg((int)stream_len);
   *dest=(char FAR *)farmalloc_msg((int)stream_len);
   if((stream_len=read_stream(streambuf, stream_len, sid))==0)
   {
    close_streams(sid);
    dptr=*dest;
    mput_word(0, dptr);
    free(streambuf);
    return(0);
   }
  #endif
  /* Initialize storage */
  dptr=*dest;
  mput_word(0, dptr);
  dptr+=2;
  j=0L;
  while(1)
  {
   #if TARGET==OS2
    count=1L;
    #ifdef __32BIT__
     if(DosEnumAttribute(ENUMEA_REFTYPE_PATH, (PVOID)name, ++j, (PVOID)pdena,
                         sizeof(*pdena)+CCHMAXPATHCOMP, &count,
                         ENUMEA_LEVEL_NO_VALUE))
      break;
    #else
     if(DosEnumAttribute(ENUMEA_REFTYPE_PATH, (PVOID)name, ++j, (PVOID)pdena,
                         sizeof(*pdena)+CCHMAXPATHCOMP, &count,
                         ENUMEA_LEVEL_NO_VALUE, 0L))
      break;
    #endif
    if(count==0L)
     break;
    /* EA (pdena->szName) consumes (pdena->cbValue) bytes */
    #ifdef __32BIT__
     eaop.fpGEA2List=pgeal;
    #else
     eaop.fpGEAList=pgeal;
    #endif
    far_strcpy(pgeal->list[0].szName, pdena->szName);
    pgeal->list[0].cbName=pdena->cbName;
    #ifdef __32BIT__
     pgeal->list[0].oNextEntryOffset=0;
     pgeal->cbList=sizeof(GEA2LIST)+pdena->cbName;
     eaop.fpGEA2List=pgeal;
     pfeal=(PFEA2LIST)farmalloc_msg(sizeof(FEA2LIST)+pdena->cbName+pdena->cbValue+1);
     pfeal->cbList=sizeof(FEA2LIST)+pdena->cbName+pdena->cbValue+1;
     eaop.fpFEA2List=pfeal;
     if((rc=DosQueryPathInfo(name, FIL_QUERYEASFROMLIST, (PBYTE)&eaop, sizeof(eaop)))!=0)
     {
      farfree(pfeal);
      rcode=-1;
      break;
     }
     nptr=(char FAR *)&(pfeal->list[0])+sizeof(FEA2)-1;
    #else
     pgeal->cbList=sizeof(GEALIST)+pdena->cbName;
     eaop.fpGEAList=pgeal;
     pfeal=(PFEALIST)farmalloc_msg(sizeof(FEALIST)+pdena->cbName+pdena->cbValue+1);
     pfeal->cbList=sizeof(FEALIST)+pdena->cbName+pdena->cbValue+1;
     eaop.fpFEAList=pfeal;
     if((rc=DosQPathInfo(name, FIL_QUERYEASFROMLIST, (PBYTE)&eaop, sizeof(eaop), 0L))!=0)
     {
      farfree(pfeal);
      rcode=-1;
      break;
     }
     nptr=(char FAR *)&(pfeal->list[0])+sizeof(FEA);
    #endif
   #elif TARGET==WIN32
    /* Win32 provides us with a FEALIST at our disposal. */
    pfeal=(PFEALIST)streambuf;
    nptr=(char FAR *)&(pfeal->list[0])+sizeof(FEA);
   #endif
  #if SFX_LEVEL>=ARJ
   if(ea_filter(nptr, skip_ln)&&((pfeal->list[0].fEA&FEA_NEEDEA)||!crit_eas))
  #endif
   {
    mput_word(mget_word(*dest)+1, *dest);
    mput_byte(pfeal->list[0].fEA, dptr++);
    mput_byte(pfeal->list[0].cbName, dptr++);
    mput_word(pfeal->list[0].cbValue, dptr);
    dptr+=2;
    far_memmove(dptr, nptr, (int)pfeal->list[0].cbName);
    dptr+=pfeal->list[0].cbName;
    far_memmove(dptr, nptr+pfeal->list[0].cbName+1, pfeal->list[0].cbValue);
    dptr+=pfeal->list[0].cbValue;
   }
   #if TARGET==OS2
    farfree(pfeal);
   #elif TARGET==WIN32
    if(pfeal->cbList==0)                /* Indicates the last EA */
     break;
    streambuf+=pfeal->cbList;
   #endif
  }
  #if TARGET==OS2
   farfree(pdena);
   farfree(pgeal);
  #endif
  #if TARGET==WIN32
   close_streams(sid);
  #endif
  return(rcode);
 #else
  return(-1);
 #endif
}