Esempio n. 1
0
/*interface function
 while handling data it's saving it to buffer provided in obj1 and updating 
 used buffer space (index) in obj3 param*/
void handle_env_record(struct MNvramObserver* observer,
		       struct ParsedRecord* record,
		       void* obj1, void* obj2, void* obj3){
    assert(record);
    /*get param*/
    char* envname = NULL;
    ALLOCA_PARAM_VALUE(record->parsed_params_array[ENV_PARAM_NAME_KEY_INDEX], 
		      &envname);
    /*get param*/
    char* envval = NULL;
    ALLOCA_PARAM_VALUE(record->parsed_params_array[ENV_PARAM_VALUE_KEY_INDEX], 
		      &envval);
    ZRT_LOG(L_INFO, "env record: %s=%s", envname, envval);
    /*unescape value*/
    char* unescaped_value_result = alloca( strlen(envval)+1 );
    int unescaped_value_len =
	unescape_string_copy_to_dest(envval, 
				     record->parsed_params_array[ENV_PARAM_VALUE_KEY_INDEX].vallen, 
				     unescaped_value_result);
    ZRT_LOG(L_SHORT, "env record: %s=%s (escaped) %d", envname, unescaped_value_result, unescaped_value_len);

    /*If handling envs at session start preparing main() arguments,
     it's expected code running at prolog stage*/
    if ( obj1 && obj2 && obj3 ){
	char* buffer = (char*)obj1; /*obj1 - char* */
	int bufsize = *(int*)obj2;  /*obj2 - int*  */
	int* index = (int*)obj3;    /*obj3 - int*  */
	assert(buffer); /*into buffer will be saved results*/

	add_pair_to_temp_buffer(buffer, bufsize, index,
				envname, 
				record->parsed_params_array[ENV_PARAM_NAME_KEY_INDEX].vallen, 
				unescaped_value_result, 
				unescaped_value_len);
    }
    /*Handling envs at forked session, no another input parameters needed */
    else{
	if ( setenv(envname, unescaped_value_result, 1) == 0 ){
	    ZRT_LOG(L_INFO, P_TEXT, "env overwrite success");
	}
	else{
	    ZRT_LOG(L_INFO, P_TEXT, "env overwrite failed");
	}
    }
}
Esempio n. 2
0
void handle_tar_export(){
    struct ParsedRecord* current;
    int i;
    for ( i=0; i < s_export_tarrecords.count; i++ ){
	current = &s_export_tarrecords.records[i];
	/*get param*/
	char* channel_alias = NULL;
	ALLOCA_PARAM_VALUE(current->parsed_params_array[FSTAB_PARAM_CHANNEL_KEY_INDEX], 
			   &channel_alias);
	/*get param*/
	char* mount_path = NULL;
	ALLOCA_PARAM_VALUE(current->parsed_params_array[FSTAB_PARAM_MOUNTPOINT_KEY_INDEX], 
			   &mount_path);
	int res = save_as_tar(mount_path, channel_alias);
	ZRT_LOG(L_SHORT, "save_as_tar res=%d, dirpath=%s, tar_path=%s", 
		res, mount_path, channel_alias);
    }
}
Esempio n. 3
0
void handle_precache_record(struct MNvramObserver* observer,
			 struct ParsedRecord* record,
			 void* obj1, void* obj2, void* obj3){
    assert(record);
    /*get param*/
    char* precache = NULL;
    int* dofork = (int*)obj1;
    ALLOCA_PARAM_VALUE(record->parsed_params_array[PRECACHE_PARAM_PRECACHE_KEY_INDEX], 
		       &precache);
    ZRT_LOG(L_SHORT, "precache record: precache=%s", precache);

    if ( precache ){
	if ( !strcmp("yes", precache) ){
	    *dofork = 1;
	}
	else{
	    *dofork = 0;
	}
    }
}
Esempio n. 4
0
void handle_fstab_record(struct MNvramObserver* observer,
			 struct ParsedRecord* record,
			 void* obj1, void* obj2, void* obj3){
    assert(record);

    /*obj1 - only channels filesystem interface*/
    struct MountsInterface* channels_mount = (struct MountsInterface*)obj1;
    /*obj2 - whole filesystem interface*/
    struct MountsInterface* transparent_mount = (struct MountsInterface*)obj2;
    /*handle record according to removable state*/
    int fstab_mount_stage = (int)obj3;

    /*get param*/
    char* channel_alias = NULL;
    ALLOCA_PARAM_VALUE(record->parsed_params_array[FSTAB_PARAM_CHANNEL_KEY_INDEX], 
		      &channel_alias);
    /*get param*/
    char* mount_path = NULL;
    ALLOCA_PARAM_VALUE(record->parsed_params_array[FSTAB_PARAM_MOUNTPOINT_KEY_INDEX], 
		      &mount_path);
    /*get param check*/
    char* access = NULL;
    ALLOCA_PARAM_VALUE(record->parsed_params_array[FSTAB_PARAM_ACCESS_KEY_INDEX], 
		      &access);
    /*get param check*/
    char* removable = NULL;
    ALLOCA_PARAM_VALUE(record->parsed_params_array[FSTAB_PARAM_REMOVABLE_KEY_INDEX], 
		      &removable);
    int removable_record = !strcasecmp( removable, FSTAB_VAL_REMOVABLE_YES);

    ZRT_LOG(L_SHORT, 
	    "fstab record handle now=%d: channel=%s, mount_path=%s, access=%s, removable=%s",
	    IS_NEED_TO_HANDLE_FSTAB_RECORD(fstab_mount_stage, removable_record),
	    channel_alias, mount_path, access, removable);

    /* In case if we need to inject files into FS.*/
    if ( !strcmp(access, FSTAB_VAL_ACCESS_READ) &&
	 IS_NEED_TO_HANDLE_FSTAB_RECORD(fstab_mount_stage, removable_record) ){
	/*
	 * inject contents into specified folder mount_path of filesystem, from channel name
	 * channel_alias. Content of filesystem is reading from channel that points to 
	 * supported archive, tar currently, read every file dir and add it into MemMount filesystem
	 */
	/*create mounts reader linked to tar archive that contains filesystem image,
	 it call "read" from MountsInterface and don't call "read" function from posix layer*/
	struct MountsReader* mounts_reader =
            alloc_mounts_reader( channels_mount, channel_alias );

	if ( mounts_reader ){
	    /*create image loader, passed 1st param: image alias, 2nd param: Root filesystem;
	     * Root filesystem passed instead MemMount to reject adding of files into /dev folder;
	     * For example if archive contains non empty /dev folder that contents will be ignored*/
	    struct ImageInterface* image_loader =
                alloc_image_loader( transparent_mount );
	    /*create archive unpacker*/
	    struct UnpackInterface* tar_unpacker =
                alloc_unpacker_tar( mounts_reader, image_loader->observer_implementation );

	    /*read archive from linked channel and add all contents into Filesystem*/
	    int count_files = image_loader->deploy_image( mount_path, tar_unpacker );
	    ZRT_LOG( L_SHORT, 
		     "From %s archive readed and injected %d files "
		     "into %s folder of ZRT filesystem",
		     channel_alias, count_files, mount_path );

	    free_unpacker_tar( tar_unpacker );
	    free_image_loader( image_loader );
	    free_mounts_reader( mounts_reader );
	}
    }
#ifdef FSTAB_SAVE_TAR_ENABLE
    /*save files located at mount_path into tar archive*/
    else if ( !strcmp(access, FSTAB_VAL_ACCESS_WRITE) ){
	/*as temp solution, need to do good solution to export tar*/
	memset(&s_export_tarrecords, '\0', sizeof(s_export_tarrecords));

	struct ParsedRecord* record = &s_export_tarrecords.records[s_export_tarrecords.count];
	struct ParsedParam* p1 = &record->parsed_params_array[FSTAB_PARAM_CHANNEL_KEY_INDEX];
	struct ParsedParam* p2 = &record->parsed_params_array[FSTAB_PARAM_MOUNTPOINT_KEY_INDEX];
	p1->key_index = FSTAB_PARAM_CHANNEL_KEY_INDEX;
	p1->val = strdup(channel_alias);
	p1->vallen = strlen(channel_alias);
	p2->key_index = FSTAB_PARAM_MOUNTPOINT_KEY_INDEX;
	p2->val = strdup(mount_path);
	p2->vallen = strlen(mount_path);
	s_export_tarrecords.count++;
	ZRT_LOG( L_SHORT, "Export scheduled on exit from '%s' into channel '%s'", 
		 mount_path, channel_alias);
    }
#endif //FSTAB_SAVE_TAR_ENABLE

    ZRT_LOG_DELIMETER;
}