Exemplo n.º 1
0
void quit_program(int rc)
{
	set_process_permissions(0, 0, xstrtoo(VBOX_ROOT_UMASK, 0));

	modem_hangup(&vboxmodem);

	log_line(LOG_D, "Closing modem device (%d)...\n", vboxmodem.fd);

	if (vboxmodem_close(&vboxmodem) != 0)
	{
		log_line(LOG_E, "%s (%s)\n", vboxmodem_error(), strerror(errno));
	}

	if (isdnttyname)
	{
		printstring(temppathname, "%s/LCK..%s", LOCKDIR, isdnttyname);

		lock_remove(temppathname);

		printstring(temppathname, "%s/vboxgetty-%s.pid", PIDDIR, isdnttyname);

		pid_remove(temppathname);
	}

	scr_remove_interpreter();
	rc_free(rc_getty_c);
	breaklist_clear();
	log_close();

	exit(rc);
}
Exemplo n.º 2
0
void transfer_abort(void)
{
    worker_block();
    pthread_mutex_lock(&m_transfer);

    if (t_state.active)
    {
        lock_remove(t_state.job->path, LOCK_TRANSFER);
        unlink(t_state.write_path);

        pthread_mutex_unlock(&m_transfer);
        transfer_reset_state();
    }

    worker_unblock();
    pthread_mutex_unlock(&m_transfer);
}
Exemplo n.º 3
0
void transfer_rename(const char *to)
{
    size_t to_len;

    pthread_mutex_lock(&m_transfer);

    if (!t_state.active)
    {
        pthread_mutex_unlock(&m_transfer);
        return;
    }

    DEBUG("transfer_rename to %s", to);

    to_len = strlen(to);

    worker_block();

    lock_remove(t_state.job->path, LOCK_TRANSFER);
    free(t_state.job->path);
    t_state.job->path = strdup(to);
    lock_set(t_state.job->path, LOCK_TRANSFER);

    free(t_state.read_path);
    free(t_state.write_path);
    if (t_state.job->op == JOB_PUSH)
    {
        t_state.read_path = cache_path2(to, to_len);
        t_state.write_path = remote_path2(to, to_len);
    }
    else
    {
        t_state.read_path = remote_path2(to, to_len);
        t_state.write_path = cache_path2(to, to_len);
    }

    pthread_mutex_unlock(&m_transfer);
    worker_unblock();
}
Exemplo n.º 4
0
int transfer(const char *from, const char *to)
{
#define CLOSE(fd) { if (close(fd)) PERROR("error closing fd"); }
    int fdread, fdwrite;
    ssize_t readbytes;
    char buf[TRANSFER_SIZE];
    int w_flags;

    pthread_mutex_lock(&m_transfer);

    if (from && to)
    {
        lock_set(t_state.job->path, LOCK_TRANSFER);
        VERBOSE("beginning transfer: '%s' -> '%s'", from, to);
        t_state.read_path = strdup(from);
        t_state.write_path = strdup(to);

        w_flags = O_WRONLY | O_CREAT | O_TRUNC;
    }
    else if (!t_state.active)
    {
        pthread_mutex_unlock(&m_transfer);
        return TRANSFER_FINISH;
    }
    else
    {
        VERBOSE("resuming transfer: '%s' -> '%s' at %ld",
                t_state.read_path, t_state.write_path, t_state.offset);

        w_flags = O_WRONLY | O_APPEND;
    }


    if (!t_state.read_path || !t_state.write_path)
    {
        ERROR("t_state.read_path or t_state.write_path is NULL");
        lock_remove(t_state.job->path, LOCK_TRANSFER);
        goto failure;
    }

    /* open files */
    if ((fdread = open(t_state.read_path, O_RDONLY)) == -1
            || lseek(fdread, t_state.offset, SEEK_SET) == -1) {
        PERROR(t_state.read_path);
        goto failure;
    }

    if ((fdwrite = open(t_state.write_path, w_flags, 0666)) == -1
            || lseek(fdwrite, t_state.offset, SEEK_SET) == -1) {
        PERROR(t_state.write_path);
        goto failure;
    }

    while (ONLINE && !worker_blocked())
    {
        readbytes = read(fdread, buf, sizeof buf);
        if (readbytes && (readbytes < 0 || write(fdwrite, buf, readbytes) < readbytes || fsync(fdwrite)))
        {

            if (readbytes < 0)
                ERROR("failed to read from file");
            else
                ERROR("failed or incomplete write");

            goto failure;
        }

        /* copy completed, set mode and ownership */
        if (readbytes < sizeof buf)
        {
            CLOSE(fdread);
            CLOSE(fdwrite);

            copy_attrs(t_state.read_path, t_state.write_path);

            VERBOSE("transfer finished: '%s' -> '%s'", t_state.read_path, t_state.write_path);

            lock_remove(t_state.job->path, LOCK_TRANSFER);
            pthread_mutex_unlock(&m_transfer);
            transfer_reset_state();

            return TRANSFER_FINISH;
        }
    }

    t_state.offset = lseek(fdread, 0, SEEK_CUR);

    CLOSE(fdread);
    CLOSE(fdwrite);

    pthread_mutex_unlock(&m_transfer);
    return TRANSFER_OK;

failure:
    pthread_mutex_unlock(&m_transfer);
    transfer_abort();
    return TRANSFER_FAIL;
#undef CLOSE
}