Esempio n. 1
0
/* ---------------------------------------------- */
int main(int argc, char *argv[])
{
	int c;
	struct Fuse_option fuse_options;

	/* Set up owlib */
	LibSetup(program_type_filesystem);

	/* grab our executable name */
	if (argc > 0) {
		Globals.progname = owstrdup(argv[0]);
	}
	//mtrace() ;
	/* process command line arguments */
	while ((c = getopt_long(argc, argv, OWLIB_OPT, owopts_long, NULL)) != -1) {
		switch (c) {
		case 'V':
			fprintf(stderr, "%s version:\n\t" VERSION "\n", argv[0]);
			break;
		case e_fuse_opt:		/* fuse_mnt_opt */
			if (fuse_mnt_opt) {
				owfree(fuse_mnt_opt);
			}
			fuse_mnt_opt = Fuse_arg(optarg, "FUSE mount options");
			if (fuse_mnt_opt == NULL) {
				ow_exit(0);
			}
			break;
		case e_fuse_open_opt:	/* fuse_open_opt */
			if (fuse_open_opt) {
				owfree(fuse_open_opt);
			}
			fuse_open_opt = Fuse_arg(optarg, "FUSE open options");
			if (fuse_open_opt == NULL) {
				ow_exit(0);
			}
			break;
		}
		if ( BAD( owopt(c, optarg) ) ) {
			ow_exit(0);			/* rest of message */
		}
	}

	/* non-option arguments */
	while (optind < argc - 1) {
		ARG_Generic(argv[optind]);
		++optind;
	}
	while (optind < argc) {
		if (Outbound_Control.active) {
			ARG_Generic(argv[optind]);
		} else {
			ARG_Server(argv[optind]);
		}
		++optind;
	}

	if (Outbound_Control.active == 0) {
		LEVEL_DEFAULT("No mount point specified.\nTry '%s -h' for help.", argv[0]);
		ow_exit(1);
	}
	// FUSE directory mounting
	LEVEL_CONNECT("fuse mount point: %s", Outbound_Control.head->name);

	// Signal handler is set in fuse library
	//set_signal_handlers(exit_handler);

	/* Set up adapters */
	if ( BAD(LibStart()) ) {
		ow_exit(1);
	}

#if FUSE_VERSION >= 14
	/* Set up "command line" for main fuse routines */
	Fuse_setup(&fuse_options);	// command line setup
	Fuse_add(Outbound_Control.head->name, &fuse_options);	// mount point
#if FUSE_VERSION >= 22
	Fuse_add("-o", &fuse_options);	// add "-o direct_io" to prevent buffering
	Fuse_add("direct_io", &fuse_options);
#endif							/* FUSE_VERSION >= 22 */
	if (!Globals.want_background) {
		Fuse_add("-f", &fuse_options);	// foreground for fuse too
		if (Globals.error_level > 2) {
			Fuse_add("-d", &fuse_options);	// debug for fuse too
		}
	}
	Fuse_parse(fuse_mnt_opt, &fuse_options);
	LEVEL_DEBUG("fuse_mnt_opt=[%s]", fuse_mnt_opt);
	Fuse_parse(fuse_open_opt, &fuse_options);
	LEVEL_DEBUG("fuse_open_opt=[%s]", fuse_open_opt);
	if (Globals.allow_other) {
		Fuse_add("-o", &fuse_options);	// add "-o allow_other" to permit other users access
		Fuse_add("allow_other", &fuse_options);
	}
#if OW_MT == 0
	Fuse_add("-s", &fuse_options);	// single threaded
#endif							/* OW_MT */
	Globals.now_background = Globals.want_background;	// tell "error" that we are background
#if 0
	{
		int i;
		for (i = 0; i < fuse_options.argc; i++) {
			LEVEL_DEBUG("fuse_options.argv[%d]=[%s]", i, fuse_options.argv[i]);
		}
	}
#endif
#if FUSE_VERSION > 25
	fuse_main(fuse_options.argc, fuse_options.argv, &owfs_oper, NULL);
#else							/* FUSE_VERSION <= 25 */
	fuse_main(fuse_options.argc, fuse_options.argv, &owfs_oper);
#endif							/* FUSE_VERSION <= 25 */
	Fuse_cleanup(&fuse_options);
#endif

	ow_exit(0);
	return 0;
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
	int c;

	/* Set up owlib */
	LibSetup(program_type_httpd);
	Setup_Systemd() ; // systemd?
	Setup_Launchd() ; // launchd?

	/* grab our executable name */
	ArgCopy( argc, argv ) ;

	while ((c = getopt_long(argc, argv, OWLIB_OPT, owopts_long, NULL)) != -1) {
		switch (c) {
		case 'V':
			fprintf(stderr, "%s version:\n\t" VERSION "\n", argv[0]);
			break;
		default:
			break;
		}
		if ( BAD( owopt(c, optarg) ) ) {
			ow_exit(0);			/* rest of message */
		}
	}

	/* non-option arguments */
	while (optind < argc) {
		ARG_Generic(argv[optind]);
		++optind;
	}

	switch (Globals.daemon_status) {
		case e_daemon_sd:
		case e_daemon_sd_done:
			// systemd done later
			break ;
		default:
			if (Outbound_Control.active == 0) {
				if (Globals.zero == zero_none) {
					LEVEL_DEFAULT("%s would be \"locked in\" so will quit.\nBonjour and Avahi not available.", argv[0]);
					ow_exit(1);
				} else {
					LEVEL_CONNECT("%s will use an ephemeral port", argv[0]) ;
				}
				ARG_Server(NULL);		// make an ephemeral assignment
			}
			break ;
	}

	/* become a daemon if not told otherwise */
	if ( BAD(EnterBackground()) ) {
		ow_exit(1);
	}

	/* Set up adapters and systemd */
	if ( BAD(LibStart(NULL)) ) {
		ow_exit(1);
	}

	set_exit_signal_handlers(exit_handler);
	set_signal_handlers(NULL);

	ServerProcess(Acceptor);

	LEVEL_DEBUG("ServerProcess done");
	ow_exit(0);
	LEVEL_DEBUG("owhttpd done");
	return 0;
}