Diff

Differences From Artifact [b204b9e307]:

To Artifact [9e818b560b]:


   722    722   	.getattr   = appfs_fuse_getattr,
   723    723   	.readdir   = appfs_fuse_readdir,
   724    724   	.readlink  = appfs_fuse_readlink,
   725    725   	.open      = appfs_fuse_open,
   726    726   	.release   = appfs_fuse_close,
   727    727   	.read      = appfs_fuse_read
   728    728   };
          729  +
          730  +/*
          731  + * FUSE option parsing callback
          732  + */
          733  +static int appfs_fuse_opt_cb(void *data, const char *arg, int key, struct fuse_args *outargs) {
          734  +	static seen_cachedir = 0;
          735  +
          736  +	if (key == FUSE_OPT_KEY_NONOPT && seen_cachedir == 0) {
          737  +		seen_cachedir = 1;
          738  +
          739  +		globalThread.cachedir = strdup(arg);
          740  +
          741  +		return(0);
          742  +	}
          743  +
          744  +	return(1);
          745  +}
   729    746   
   730    747   /*
   731    748    * Entry point into this program.
   732    749    */
   733    750   int main(int argc, char **argv) {
   734    751   	struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
   735         -	const char *cachedir = APPFS_CACHEDIR;
   736    752   	int pthread_ret;
   737    753   
          754  +	/*
          755  +	 * Skip passed program name
          756  +	 */
          757  +	if (argc == 0 || argv == NULL) {
          758  +		return(1);
          759  +	}
          760  +	argc--;
          761  +	argv++;
          762  +
   738    763   	/*
   739    764   	 * Set global variables, these should be configuration options.
   740    765   	 */
   741         -	globalThread.cachedir = cachedir;
          766  +	globalThread.cachedir = APPFS_CACHEDIR;
   742    767   	globalThread.options.writable = 1;
   743    768   
   744    769   	/*
   745    770   	 * Set global variable for "boot time" to set a time on directories
   746    771   	 * that we fake.
   747    772   	 */
   748    773   	globalThread.boottime = time(NULL);
................................................................................
   762    787   	 */
   763    788   	pthread_ret = pthread_key_create(&interpKey, NULL);
   764    789   	if (pthread_ret != 0) {
   765    790   		fprintf(stderr, "Unable to create TSD key for Tcl.  Aborting.\n");
   766    791   
   767    792   		return(1);
   768    793   	}
          794  +
          795  +	/*
          796  +	 * Manually specify cache directory, without FUSE callback
          797  +	 */
          798  +	if (argc >= 2) {
          799  +		if (strcmp(argv[0], "--cachedir") == 0) {
          800  +			globalThread.cachedir = strdup(argv[1]);
          801  +
          802  +			argc -= 2;
          803  +			argv += 2;
          804  +		}
          805  +	}
   769    806   
   770    807   	/*
   771    808   	 * SQLite3 mode, for running raw SQL against the cache database
   772    809   	 */
   773         -	if (argc == 3 && strcmp(argv[1], "-sqlite3") == 0) {
   774         -		return(appfs_sqlite3(argv[2]));
          810  +	if (argc == 2 && strcmp(argv[0], "--sqlite3") == 0) {
          811  +		return(appfs_sqlite3(argv[1]));
   775    812   	}
   776    813   
   777    814   	/*
   778    815   	 * Tcl mode, for running raw Tcl in the same environment AppFSd would
   779    816   	 * run code.
   780    817   	 */
   781         -	if (argc == 3 && strcmp(argv[1], "-tcl") == 0) {
   782         -		return(appfs_tcl(argv[2]));
          818  +	if (argc == 2 && strcmp(argv[0], "--tcl") == 0) {
          819  +		return(appfs_tcl(argv[1]));
   783    820   	}
   784    821   
   785    822   	/*
   786    823   	 * Add FUSE arguments which we always supply
   787    824   	 */
   788         -	fuse_opt_parse(&args, NULL, NULL, NULL);
          825  +	fuse_opt_parse(&args, NULL, NULL, appfs_fuse_opt_cb);
   789    826   	fuse_opt_add_arg(&args, "-odefault_permissions,fsname=appfs,subtype=appfsd,use_ino,kernel_cache,entry_timeout=60,attr_timeout=3600,intr,big_writes");
   790    827   
   791    828   	if (getuid() == 0) {
   792    829   		fuse_opt_parse(&args, NULL, NULL, NULL);
   793    830   		fuse_opt_add_arg(&args, "-oallow_other");
   794    831   	}
   795    832