Пример #1
0
bool vc_leq_all(VC& vc1, VC& vc2) {
	for (VC::iterator it=vc2.begin() ; it != vc2.end(); it++ ) {
		THREADID t = it->first;
		vctime_t c1 = vc_get(vc1, t);
		vctime_t c2 = it->second;
		if(c1 > c2) {
			return false;
		}
	}
	return true;
}
Пример #2
0
VC vc_cup(VC& vc1, VC& vc2) {
	VC _vc_ = vc1;
	for (VC::iterator it=vc2.begin() ; it != vc2.end(); it++ ) {
		THREADID t = it->first;
		vctime_t c1 = vc_get(_vc_, t);
		vctime_t c2 = it->second;
		if(c2 > c1) {
			_vc_[t] = c2;
		}
	}
	return _vc_;
}
Пример #3
0
int main(int argc, char *argv[])
{
    const unsigned int tout = 1;
    char file[100];
    char string[100];
    int talpa;
    int rc;
    struct TalpaPacket_VettingDetails* details;
    struct TalpaPacketFragment_FileDetails* fdetails;
    char* fname;
    int status;
    int ok = 0;

    if ( argc == 3 )
    {
        strcpy(file, argv[1]);
        strcpy(string, argv[2]);
    }
    else
    {
        strcpy(file, "/bin/true");
        strcpy(string, "/bin/true");
    }

    if ( (talpa = vc_init(0, tout*1000)) < 0 )
    {
        fprintf(stderr, "Failed to initialize!\n");
        return -1;
    }

    rc = fork();

    if ( !rc )
    {
        if ( execl(file, file, NULL) )
        {
            fprintf(stderr, "Failed to exec %s (%d)!\n", file, errno);
            return -1;
        }
    }
    else if ( rc < 0 )
    {
        fprintf(stderr, "Fork failed!\n");
        return -1;
    }

    details = vc_get(talpa);

    if ( !details )
    {
        fprintf(stderr, "Nothing caught!\n");
        vc_exit(talpa);
        wait(NULL);
        return -1;
    }

    if ( vc_respond(talpa, details, TALPA_ALLOW) < 0 )
    {
        fprintf(stderr, "Respond error!\n");
        vc_exit(talpa);
        wait(NULL);
        return -1;
    }

    fdetails = vc_file_frag(details);
    fname = vc_file_name(fdetails);

    if ( !strcmp(fname, string) )
    {
        ok = 1;
    }

    details = vc_get(talpa);

    if ( !details )
    {
        fprintf(stderr, "Nothing caught 2!\n");
        vc_exit(talpa);
        wait(NULL);
        return -1;
    }

    if ( vc_respond(talpa, details, TALPA_ALLOW) < 0 )
    {
        fprintf(stderr, "Respond error 2!\n");
        vc_exit(talpa);
        wait(NULL);
        return -1;
    }

    fdetails = vc_file_frag(details);
    fname = vc_file_name(fdetails);

    /* Wait for one more if we are under 2.6 kernel */
    details = vc_get(talpa);

    if ( details )
    {
        vc_respond(talpa, details, TALPA_ALLOW);
    }

    wait(&status);

    if ( ok )
    {
        vc_exit(talpa);
        return 0;
    }

    if ( strcmp(fname, string) )
    {
        fprintf(stderr, "String mismatch %s != %s!\n", fname, string);
        vc_exit(talpa);
        return -1;
    }

    if ( !WIFEXITED(status) )
    {
        fprintf(stderr, "Child error!\n");
        vc_exit(talpa);
        return -1;
    }

    if ( WEXITSTATUS(status) )
    {
        fprintf(stderr, "Child exec failed!\n");
        vc_exit(talpa);
        return -1;
    }

    vc_exit(talpa);

    return 0;
}
Пример #4
0
bool vc_leq(VC& vc1, VC& vc2, THREADID t) {
	vctime_t c1 = vc_get(vc1, t);
	vctime_t c2 = vc_get(vc2, t);
	return c1 <= c2;
}
Пример #5
0
void vc_inc(VC& vc, THREADID t) {
	VC _vc_ = vc;
	vctime_t c = vc_get(_vc_, t);
	_vc_[t] = c + 1;
}
Пример #6
0
int main(int argc, char *argv[])
{
    const unsigned int tout = 2;
    char dir[100];
    char source[100];
    char target[100];
    char type[100];
    char source_path[100];
    char target_path[100];
    int dirlen;
    int talpa;
    int rc;
    struct TalpaPacket_VettingDetails* details;
    int status;
    struct TalpaPacketFragment_FilesystemDetails* fsdetails;
    char* fsdev;


    if ( argc == 5 )
    {
        strcpy(dir, argv[1]);
        strcpy(source, argv[2]);
        strcpy(target, argv[3]);
        strcpy(type, argv[4]);
    }
    else
    {
        strcpy(dir, "/tmp");
        strcpy(source, "/dev");
        strcpy(target, "/mnt");
        strcpy(type, "ext2");
    }

    strcpy(source_path, dir);
    strcat(source_path, source);

    strcpy(target_path, dir);
    strcat(target_path, target);

    dirlen = strlen(dir);

    if ( mount( source_path, target_path, type, 0, NULL) )
    {
        fprintf(stderr, "Mount failed!\n");
        return -1;
    }


    if ( (talpa = vc_init(0, tout*1000)) < 0 )
    {
        fprintf(stderr, "Failed to initialize!\n");
        return -1;
    }

    rc = fork();

    if ( !rc )
    {
        if ( chdir(dir) != 0 )
        {
            fprintf(stderr, "(child) chdir failed!\n");
            return -1;
        }

        if ( chroot(dir) != 0 )
        {
            fprintf(stderr, "(child) chroot failed!\n");
            return -1;
        }

        if ( umount2(target, 0) )
        {
            fprintf(stderr, "(child) Umount failed!\n");
            return -1;
        }

        return 0;
    }
    else if ( rc < 0 )
    {
        fprintf(stderr, "Fork failed!\n");
        return -1;
    }

    details = vc_get(talpa);

    if ( !details )
    {
        fprintf(stderr, "Nothing caught!\n");
        vc_exit(talpa);
        wait(NULL);
        return -1;
    }

    if ( vc_respond(talpa, details, TALPA_ALLOW) < 0 )
    {
        fprintf(stderr, "Respond error!\n");
        vc_exit(talpa);
        wait(NULL);
        return -1;
    }

    wait(&status);

    if ( details->header.type != TALPA_PKT_FILESYSTEMDETAIL )
    {
        fprintf(stderr, "Didn't get TALPA_PKT_FILESYSTEMDETAIL type: %x != %x!\n",
            details->header.type, TALPA_PKT_FILESYSTEMDETAIL );
        vc_exit(talpa);
        return -1;
    }

    fsdetails = vc_filesystem_frag(details);

    if ( fsdetails->operation != TALPA_UMOUNT )
    {
        fprintf(stderr, "Didn't get TALPA_UMOUNT operation: %d != %d!\n",
            fsdetails->operation, TALPA_UMOUNT );
        vc_exit(talpa);
        return -1;
    }

    fsdev = vc_filesystem_dev(fsdetails);

    if ( strcmp(fsdev, source_path) )
    {
        fprintf(stderr, "String mismatch %s != %s!\n", fsdev, source);
        vc_exit(talpa);
        return -1;
    }

    if ( details->rootdir_len != dirlen )
    {
        fprintf(stderr, "dir_len mismatch %d != %d!\n",  details->rootdir_len, dirlen);
        vc_exit(talpa);
        return -1;
    }

    if ( !WIFEXITED(status) )
    {
        fprintf(stderr, "Child error!\n");
        vc_exit(talpa);
        return -1;
    }

    if ( WEXITSTATUS(status) )
    {
        fprintf(stderr, "Child exec failed!\n");
        vc_exit(talpa);
        return -1;
    }

    vc_exit(talpa);

    return 0;
}