Changeset - 161b220ee132
[Not reviewed]
0 1 0
HanzZ - 14 years ago 2011-11-07 19:25:43
hanzz.k@gmail.com
Create working_dir after setuid/setgid
1 file changed with 9 insertions and 7 deletions:
0 comments (0 inline, 0 general)
spectrum/src/main.cpp
Show inline comments
 
@@ -179,31 +179,24 @@ int main(int argc, char **argv)
 
		std::cout << desc << "\n";
 
		return 1;
 
	}
 

	
 
	if (!config.load(vm["config"].as<std::string>(), jid)) {
 
		std::cerr << "Can't load configuration file.\n";
 
		return 1;
 
	}
 

	
 
#ifndef WIN32
 
	if (!no_daemon) {
 
		// create directories
 
		try {
 
			boost::filesystem::create_directories(CONFIG_STRING(&config, "service.working_dir"));
 
		}
 
		catch (...) {
 
			std::cerr << "Can't create service.working_dir directory " << CONFIG_STRING(&config, "service.working_dir") << ".\n";
 
			return 1;
 
		}
 
		try {
 
			boost::filesystem::create_directories(
 
				boost::filesystem::path(CONFIG_STRING(&config, "service.pidfile")).parent_path().string()
 
			);
 
		}
 
		catch (...) {
 
			std::cerr << "Can't create service.pidfile directory " << boost::filesystem::path(CONFIG_STRING(&config, "service.pidfile")).parent_path().string() << ".\n";
 
			return 1;
 
		}
 

	
 
		// daemonize
 
		daemonize(CONFIG_STRING(&config, "service.working_dir").c_str(), CONFIG_STRING(&config, "service.pidfile").c_str());
 
@@ -265,24 +258,33 @@ int main(int argc, char **argv)
 
			if ((setuid(pw->pw_uid)) != 0) {
 
				LOG4CXX_ERROR(logger, "Failed to set service.user name " << CONFIG_STRING(&config, "service.user") << " - " << pw->pw_uid << ":" << strerror(errno));
 
				return 1;
 
			}
 
		}
 
		setrlimit(RLIMIT_CORE, &limit);
 
	}
 

	
 
	struct rlimit limit;
 
	limit.rlim_max = RLIM_INFINITY;
 
	limit.rlim_cur = RLIM_INFINITY;
 
	setrlimit(RLIMIT_CORE, &limit);
 

	
 
	// create directories
 
	try {
 
		boost::filesystem::create_directories(CONFIG_STRING(&config, "service.working_dir"));
 
	}
 
	catch (...) {
 
		std::cerr << "Can't create service.working_dir directory " << CONFIG_STRING(&config, "service.working_dir") << ".\n";
 
		return 1;
 
	}
 
#endif
 

	
 
	Swift::SimpleEventLoop eventLoop;
 

	
 
	Swift::BoostNetworkFactories *factories = new Swift::BoostNetworkFactories(&eventLoop);
 
	UserRegistry userRegistry(&config, factories);
 

	
 
	Component transport(&eventLoop, factories, &config, NULL, &userRegistry);
 
	component_ = &transport;
 
// 	Logger logger(&transport);
 

	
 
	StorageBackend *storageBackend = NULL;
0 comments (0 inline, 0 general)