Пример #1
0
Файл: fork.c Проект: VanL/zrt
int main(int argc, char **argv)
{
    int res;
    int datalen, datalen1;
    char testpath[PATH_MAX];
    snprintf(testpath, sizeof(testpath), "/test/%s", FILENAME_WITH_DYNAMIC_CONTENTS );
    fprintf(stderr, "%s\n", testpath);

    /*Read files at mountpoint*/
    char* contents1 = read_file_contents( testpath, &datalen1 );
    CMP_MEM_DATA(MOUNT_CONTENTS, contents1, strlen(MOUNT_CONTENTS) );

    char* contents = read_file_contents( FILENAME_WITH_DYNAMIC_CONTENTS, &datalen );
    CMP_MEM_DATA(MOUNT_CONTENTS, contents, strlen(MOUNT_CONTENTS) );

    TEST_OPERATION_RESULT(strcmp("1", getenv("new")), &res, res==0);

    struct stat st;
    TEST_OPERATION_RESULT( lstat("/dev/read-write", &st), &res, res==0 );
    TEST_OPERATION_RESULT( (st.st_mode&S_IFCHR)==S_IFCHR, &res, res==1 );
    
    res = zfork();
    free(contents);
    free(contents1);
    /*After fork it is expected that this file remains unchanged*/
    contents1 = read_file_contents( testpath, &datalen1 );
    CMP_MEM_DATA(MOUNT_CONTENTS, contents1, strlen(MOUNT_CONTENTS) );

    /*After fork it is expected that this file is changed*/
    contents = read_file_contents( FILENAME_WITH_DYNAMIC_CONTENTS, &datalen );
    CMP_MEM_DATA(REMOUNT_CONTENTS, contents, strlen(REMOUNT_CONTENTS) );

    /*After fork env var changed*/
    TEST_OPERATION_RESULT(strcmp("2", getenv("new")), &res, res==0);

    /*After fork channels mapping is changed*/
    TEST_OPERATION_RESULT( lstat("/dev/read-write", &st), &res, res==0 );
    TEST_OPERATION_RESULT( (st.st_mode&S_IFREG)==S_IFREG, &res, res==1 );

    free(contents);
    free(contents1);
    return 0;
}
Пример #2
0
/*Basic zrt initializer*/
void zrt_zcall_enhanced_zrt_setup(void){
    struct NvramLoaderPublicInterface* nvram = INSTANCE_L(NVRAM_LOADER)();
    zrt_internal_init(MANIFEST);

    if ( NULL != nvram->section_by_name( nvram, MAPPING_SECTION_NAME ) ){
	nvram->handle(nvram, HANDLE_ONLY_MAPPING_SECTION, NULL, NULL, NULL);
    }
    if ( NULL != nvram->section_by_name( nvram, FSTAB_SECTION_NAME ) ){
	nvram->handle(nvram, (struct MNvramObserver*)HANDLE_ONLY_FSTAB_SECTION, 
		      s_channels_mount, s_transparent_mount, NULL );
    }
    /*check nvram section [precache] and call fork if needed*/
    if ( NULL != nvram->section_by_name( nvram, PRECACHE_SECTION_NAME ) ){
	int dofork = 0;
	/*return result via dofork pointer*/
	nvram->handle(nvram, HANDLE_ONLY_PRECACHE_SECTION, &dofork, NULL, NULL);
	if ( dofork ){
	    zfork();
	}
    }
}