Check-in [ec17efd4bb]
Overview
Comment:Made an optional exit path and removed decrementing of reference counters
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ec17efd4bba67c581b333613e214255e8a662c2e
User & Date: rkeene on 2014-11-14 17:25:03
Other Links: manifest | tags
Context
2014-11-14
17:25
Enabled exit path by default in debug mode check-in: 76965f13c9 user: rkeene tags: trunk
17:25
Made an optional exit path and removed decrementing of reference counters check-in: ec17efd4bb user: rkeene tags: trunk
06:13
Updated to decrement reference count for objects as we are done with them check-in: 651fd8051a user: rkeene tags: trunk
Changes

Modified appfsd.c from [4a8cebc0f0] to [3133466dff].

305
306
307
308
309
310
311






312
313
314
315
316
317
318

		Tcl_DeleteInterp(interp);

		interp = NULL;

		pthread_ret = pthread_setspecific(interpKey, interp);
	}







	thread_interp_reset_key = global_interp_reset_key;

	if (interp == NULL) {
		interp = appfs_create_TclInterp(NULL);

		if (interp == NULL) {







>
>
>
>
>
>







305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324

		Tcl_DeleteInterp(interp);

		interp = NULL;

		pthread_ret = pthread_setspecific(interpKey, interp);
	}

	if (global_interp_reset_key == -1) {
		APPFS_DEBUG("Not creating a new interpreter since we are terminating.");

		return(NULL);
	}

	thread_interp_reset_key = global_interp_reset_key;

	if (interp == NULL) {
		interp = appfs_create_TclInterp(NULL);

		if (interp == NULL) {
344
345
346
347
348
349
350

351

352
353
354
355
356

357

358
359
360
361
362
363
364
	int i;

	if (interp == NULL) {
		return(TCL_ERROR);
	}

	objv = (void *) ckalloc(sizeof(*objv) * objc);

	objv[0] = Tcl_NewStringObj(cmd, -1);

	Tcl_IncrRefCount(objv[0]);

	va_start(argp, cmd);
	for (i = 1; i < objc; i++) {
		arg = va_arg(argp, const char *);

		objv[i] = Tcl_NewStringObj(arg, -1);

		Tcl_IncrRefCount(objv[i]);
	}
	va_end(argp);

	retval = Tcl_EvalObjv(interp, objc, objv, 0);

	for (i = 0; i < objc; i++) {







>

>





>

>







350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
	int i;

	if (interp == NULL) {
		return(TCL_ERROR);
	}

	objv = (void *) ckalloc(sizeof(*objv) * objc);

	objv[0] = Tcl_NewStringObj(cmd, -1);

	Tcl_IncrRefCount(objv[0]);

	va_start(argp, cmd);
	for (i = 1; i < objc; i++) {
		arg = va_arg(argp, const char *);

		objv[i] = Tcl_NewStringObj(arg, -1);

		Tcl_IncrRefCount(objv[i]);
	}
	va_end(argp);

	retval = Tcl_EvalObjv(interp, objc, objv, 0);

	for (i = 0; i < objc; i++) {
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
	}

	pathinfo->packaged = 0;
	pathinfo->inode = appfs_get_path_inode(path);

	attr_value_str = Tcl_GetString(attr_value);

	Tcl_DecrRefCount(attr_value);

	switch (attr_value_str[0]) {
		case 'd': /* directory */
			pathinfo->type = APPFS_PATHTYPE_DIRECTORY;
			pathinfo->typeinfo.dir.childcount = 0;

			Tcl_DictObjGet(interp, attrs_dict, attr_key_childcount, &attr_value);
			if (attr_value != NULL) {
				tcl_ret = Tcl_GetWideIntFromObj(NULL, attr_value, &attr_value_wide);
				if (tcl_ret == TCL_OK) {
					pathinfo->typeinfo.dir.childcount = attr_value_wide;
				}

				Tcl_DecrRefCount(attr_value);
			}

			break;
		case 'f': /* file */
			pathinfo->type = APPFS_PATHTYPE_FILE;
			pathinfo->typeinfo.file.size = 0;
			pathinfo->typeinfo.file.executable = 0;

			Tcl_DictObjGet(interp, attrs_dict, attr_key_size, &attr_value);
			if (attr_value != NULL) {
				tcl_ret = Tcl_GetWideIntFromObj(NULL, attr_value, &attr_value_wide);
				if (tcl_ret == TCL_OK) {
					pathinfo->typeinfo.file.size = attr_value_wide;
				}

				Tcl_DecrRefCount(attr_value);
			}

			Tcl_DictObjGet(interp, attrs_dict, attr_key_perms, &attr_value);
			if (attr_value != NULL) {
				attr_value_str = Tcl_GetString(attr_value);
				if (attr_value_str[0] == 'x') {
					pathinfo->typeinfo.file.executable = 1;
				}

				Tcl_DecrRefCount(attr_value);
			}
			break;
		case 's': /* symlink */
			pathinfo->type = APPFS_PATHTYPE_SYMLINK;
			pathinfo->typeinfo.symlink.size = 0;
			pathinfo->typeinfo.symlink.source[0] = '\0';

			Tcl_DictObjGet(interp, attrs_dict, attr_key_source, &attr_value);
			if (attr_value != NULL) {
				attr_value_str = Tcl_GetStringFromObj(attr_value, &attr_value_int); 

				if ((attr_value_int + 1) <= sizeof(pathinfo->typeinfo.symlink.source)) {
					pathinfo->typeinfo.symlink.size = attr_value_int;
					pathinfo->typeinfo.symlink.source[attr_value_int] = '\0';

					memcpy(pathinfo->typeinfo.symlink.source, attr_value_str, attr_value_int);
				}

				Tcl_DecrRefCount(attr_value);
			}
			break;
		case 'F': /* pipe/fifo */
			pathinfo->type = APPFS_PATHTYPE_FIFO;
			break;
		case 'S': /* UNIX domain socket */
			pathinfo->type = APPFS_PATHTYPE_SOCKET;
			break;
		default:
			Tcl_DecrRefCount(attrs_dict);

			Tcl_Release(interp);

			return(-EIO);
	}

	Tcl_DictObjGet(interp, attrs_dict, attr_key_packaged, &attr_value);
	if (attr_value != NULL) {
		pathinfo->packaged = 1;

		Tcl_DecrRefCount(attr_value);
	}

	Tcl_DictObjGet(interp, attrs_dict, attr_key_time, &attr_value);
	if (attr_value != NULL) {
		tcl_ret = Tcl_GetWideIntFromObj(NULL, attr_value, &attr_value_wide);
		if (tcl_ret == TCL_OK) {
			pathinfo->time = attr_value_wide;
		}

		Tcl_DecrRefCount(attr_value);
	} else {
		pathinfo->time = 0;
	}

	Tcl_Release(interp);

	appfs_get_path_info_cache_add(path, fsuid, pathinfo);







<
<











<
<














<
<








<
<

















<
<









<
<








<
<








<
<







766
767
768
769
770
771
772


773
774
775
776
777
778
779
780
781
782
783


784
785
786
787
788
789
790
791
792
793
794
795
796
797


798
799
800
801
802
803
804
805


806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822


823
824
825
826
827
828
829
830
831


832
833
834
835
836
837
838
839


840
841
842
843
844
845
846
847


848
849
850
851
852
853
854
	}

	pathinfo->packaged = 0;
	pathinfo->inode = appfs_get_path_inode(path);

	attr_value_str = Tcl_GetString(attr_value);



	switch (attr_value_str[0]) {
		case 'd': /* directory */
			pathinfo->type = APPFS_PATHTYPE_DIRECTORY;
			pathinfo->typeinfo.dir.childcount = 0;

			Tcl_DictObjGet(interp, attrs_dict, attr_key_childcount, &attr_value);
			if (attr_value != NULL) {
				tcl_ret = Tcl_GetWideIntFromObj(NULL, attr_value, &attr_value_wide);
				if (tcl_ret == TCL_OK) {
					pathinfo->typeinfo.dir.childcount = attr_value_wide;
				}


			}

			break;
		case 'f': /* file */
			pathinfo->type = APPFS_PATHTYPE_FILE;
			pathinfo->typeinfo.file.size = 0;
			pathinfo->typeinfo.file.executable = 0;

			Tcl_DictObjGet(interp, attrs_dict, attr_key_size, &attr_value);
			if (attr_value != NULL) {
				tcl_ret = Tcl_GetWideIntFromObj(NULL, attr_value, &attr_value_wide);
				if (tcl_ret == TCL_OK) {
					pathinfo->typeinfo.file.size = attr_value_wide;
				}


			}

			Tcl_DictObjGet(interp, attrs_dict, attr_key_perms, &attr_value);
			if (attr_value != NULL) {
				attr_value_str = Tcl_GetString(attr_value);
				if (attr_value_str[0] == 'x') {
					pathinfo->typeinfo.file.executable = 1;
				}


			}
			break;
		case 's': /* symlink */
			pathinfo->type = APPFS_PATHTYPE_SYMLINK;
			pathinfo->typeinfo.symlink.size = 0;
			pathinfo->typeinfo.symlink.source[0] = '\0';

			Tcl_DictObjGet(interp, attrs_dict, attr_key_source, &attr_value);
			if (attr_value != NULL) {
				attr_value_str = Tcl_GetStringFromObj(attr_value, &attr_value_int); 

				if ((attr_value_int + 1) <= sizeof(pathinfo->typeinfo.symlink.source)) {
					pathinfo->typeinfo.symlink.size = attr_value_int;
					pathinfo->typeinfo.symlink.source[attr_value_int] = '\0';

					memcpy(pathinfo->typeinfo.symlink.source, attr_value_str, attr_value_int);
				}


			}
			break;
		case 'F': /* pipe/fifo */
			pathinfo->type = APPFS_PATHTYPE_FIFO;
			break;
		case 'S': /* UNIX domain socket */
			pathinfo->type = APPFS_PATHTYPE_SOCKET;
			break;
		default:


			Tcl_Release(interp);

			return(-EIO);
	}

	Tcl_DictObjGet(interp, attrs_dict, attr_key_packaged, &attr_value);
	if (attr_value != NULL) {
		pathinfo->packaged = 1;


	}

	Tcl_DictObjGet(interp, attrs_dict, attr_key_time, &attr_value);
	if (attr_value != NULL) {
		tcl_ret = Tcl_GetWideIntFromObj(NULL, attr_value, &attr_value_wide);
		if (tcl_ret == TCL_OK) {
			pathinfo->time = attr_value_wide;
		}


	} else {
		pathinfo->time = 0;
	}

	Tcl_Release(interp);

	appfs_get_path_info_cache_add(path, fsuid, pathinfo);
923
924
925
926
927
928
929
























930
931
932
933
934
935
936

	if (real_path == NULL) {
		return(NULL);
	}

	return(strdup(real_path));
}

























static int appfs_fuse_readlink(const char *path, char *buf, size_t size) {
	struct appfs_pathinfo pathinfo;
	int retval = 0;

	APPFS_DEBUG("Enter (path = %s, ...)", path);








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954

	if (real_path == NULL) {
		return(NULL);
	}

	return(strdup(real_path));
}

#ifdef APPFS_EXIT_PATH
static void appfs_exit(void) {
	int global_interp_reset_key;

	global_interp_reset_key = __sync_fetch_and_add(&interp_reset_key, 0);
	__sync_fetch_and_sub(&interp_reset_key, global_interp_reset_key);

	while (__sync_sub_and_fetch(&interp_reset_key, 1) >= 0) {
		/* Busy Loop */
	}

	global_interp_reset_key = __sync_fetch_and_add(&interp_reset_key, 0);
	if (global_interp_reset_key != -1) {
		APPFS_DEBUG("Error sending kill signal to all threads, aborting anyway.");
	}

	fuse_exit(fuse_get_context()->fuse);

	appfs_get_path_info_cache_flush(-1, -1);

	return;
}
#endif

static int appfs_fuse_readlink(const char *path, char *buf, size_t size) {
	struct appfs_pathinfo pathinfo;
	int retval = 0;

	APPFS_DEBUG("Enter (path = %s, ...)", path);

957
958
959
960
961
962
963











964
965
966
967
968
969
970
static int appfs_fuse_getattr(const char *path, struct stat *stbuf) {
	struct appfs_pathinfo pathinfo;
	int retval;

	retval = 0;

	APPFS_DEBUG("Enter (path = %s, ...)", path);












	pathinfo.type = APPFS_PATHTYPE_INVALID;

	retval = appfs_get_path_info(path, &pathinfo);
	if (retval != 0) {
		return(retval);
	}







>
>
>
>
>
>
>
>
>
>
>







975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
static int appfs_fuse_getattr(const char *path, struct stat *stbuf) {
	struct appfs_pathinfo pathinfo;
	int retval;

	retval = 0;

	APPFS_DEBUG("Enter (path = %s, ...)", path);

#if (defined(DEBUG) && defined(APPFS_EXIT_PATH)) || defined(APPFS_EXIT_PATH_ENABLE_MAJOR_SECURITY_HOLE)
	/*
	 * This is a major security issue so we cannot let it be compiled into
	 * any release
	 */

	if (strcmp(path, "/exit") == 0) {
		appfs_exit();
	}
#endif

	pathinfo.type = APPFS_PATHTYPE_INVALID;

	retval = appfs_get_path_info(path, &pathinfo);
	if (retval != 0) {
		return(retval);
	}
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
		return(0);
	}

	for (idx = 0; idx < children_count; idx++) {
		filler(buf, Tcl_GetString(children[idx]), NULL, 0);
	}

	Tcl_DecrRefCount(children);

	Tcl_Release(interp);

	return(0);
}

static int appfs_fuse_open(const char *path, struct fuse_file_info *fi) {
	Tcl_Interp *interp;







<
<







1093
1094
1095
1096
1097
1098
1099


1100
1101
1102
1103
1104
1105
1106
		return(0);
	}

	for (idx = 0; idx < children_count; idx++) {
		filler(buf, Tcl_GetString(children[idx]), NULL, 0);
	}



	Tcl_Release(interp);

	return(0);
}

static int appfs_fuse_open(const char *path, struct fuse_file_info *fi) {
	Tcl_Interp *interp;