Changeset - 2f46d9f7a3ab
[Not reviewed]
0 3 0
Jan Kaluza - 12 years ago 2013-01-22 09:07:10
hanzz.k@gmail.com
Working spectrum2_manager restart and hopefully working backend logging directory creation under unprivileged user
3 files changed with 37 insertions and 30 deletions:
0 comments (0 inline, 0 general)
spectrum/src/sample.cfg
Show inline comments
 
@@ -13,15 +13,15 @@ admin_password=test
 
#cert=server.pfx #patch to PKCS#12 certificate
 
#cert_password=test #password to that certificate if any
 
users_per_backend=10
 
backend=../..//backends/swiften/spectrum2_swiften_backend
 
#backend=../..//backends/swiften/spectrum2_swiften_backend
 
#backend=../../backends/twitter/spectrum2_twitter_backend
 
#backend=/home/hanzz/code/libtransport/backends/libcommuni/spectrum2_libcommuni_backend
 
backend=/home/hanzz/code/libtransport/backends/libcommuni/spectrum2_libcommuni_backend
 
protocol=prpl-jabber
 
#protocol=prpl-msn
 
#protocol=any
 
#protocol=prpl-icq
 
working_dir=./
 
portfile=$jid.port
 
portfile=./$jid.port
 
irc_server=irc.freenode.org
 

	
 
[backend]
spectrum_manager/src/main.cpp
Show inline comments
 
@@ -138,6 +138,9 @@ int main(int argc, char **argv)
 
	else if (command[0] == "list") {
 
		std::vector<std::string> list = show_list(&config);
 
	}
 
	else if (command[0] == "restart") {
 
		return restart_instances(&config);
 
	}
 
	else if (command[0] == "server") {
 
		Server server(&config);
 
		if (server.start() == false) {
src/logging.cpp
Show inline comments
 
@@ -136,30 +136,38 @@ static void initLogging(Config *config, std::string key, bool only_create_dir =
 
		p.setProperty("id", id);
 
#endif
 

	
 
		std::string dir;
 
		std::vector<std::string> dirs;
 
		BOOST_FOREACH(const log4cxx::LogString &prop, p.propertyNames()) {
 
// 			if (boost::ends_with(prop, ".File")) {
 
			if (boost::ends_with(prop, ".File")) {
 
				std::string dir;
 
				log4cxx::helpers::Transcoder::encode(p.get(prop), dir);
 
				boost::replace_all(dir, "${jid}", jid);
 
				boost::replace_all(dir, "${pid}", pid);
 
				boost::replace_all(dir, "${id}", id);
 
				break;
 
// 			}
 
				dirs.push_back(dir);
 
			}
 
		}
 
		mode_t old_cmask;
 
		if (!dir.empty()) {
 
			// create directories
 
		// create directories
 
#ifndef WIN32
 
			old_cmask = umask(0007);
 
		old_cmask = umask(0007);
 
#endif
 
			try {
 
				Transport::Util::createDirectories(config, boost::filesystem::path(dir).parent_path());
 
			}
 
			catch (const boost::filesystem::filesystem_error &e) {
 
				std::cerr << "Can't create logging directory directory " << boost::filesystem::path(dir).parent_path().string() << ": " << e.what() << ".\n";
 

	
 
		BOOST_FOREACH(std::string &dir, dirs) {
 
			if (!dir.empty()) {
 
				try {
 
					Transport::Util::createDirectories(config, boost::filesystem::path(dir).parent_path());
 
				}
 
				catch (const boost::filesystem::filesystem_error &e) {
 
					std::cerr << "Can't create logging directory directory " << boost::filesystem::path(dir).parent_path().string() << ": " << e.what() << ".\n";
 
				}
 
			}
 
		}
 

	
 
#ifndef WIN32
 
		umask(old_cmask);
 
#endif
 

	
 
		if (only_create_dir) {
 
			return;
 
		}
 
@@ -168,24 +176,20 @@ static void initLogging(Config *config, std::string key, bool only_create_dir =
 

	
 
		// Change owner of main log file
 
#ifndef WIN32
 
	if (!CONFIG_STRING(config, "service.group").empty() && !CONFIG_STRING(config, "service.user").empty()) {
 
		struct group *gr;
 
		if ((gr = getgrnam(CONFIG_STRING(config, "service.group").c_str())) == NULL) {
 
			std::cerr << "Invalid service.group name " << CONFIG_STRING(config, "service.group") << "\n";
 
		}
 
		struct passwd *pw;
 
		if ((pw = getpwnam(CONFIG_STRING(config, "service.user").c_str())) == NULL) {
 
			std::cerr << "Invalid service.user name " << CONFIG_STRING(config, "service.user") << "\n";
 
	BOOST_FOREACH(std::string &dir, dirs) {
 
		if (!CONFIG_STRING(config, "service.group").empty() && !CONFIG_STRING(config, "service.user").empty()) {
 
			struct group *gr;
 
			if ((gr = getgrnam(CONFIG_STRING(config, "service.group").c_str())) == NULL) {
 
				std::cerr << "Invalid service.group name " << CONFIG_STRING(config, "service.group") << "\n";
 
			}
 
			struct passwd *pw;
 
			if ((pw = getpwnam(CONFIG_STRING(config, "service.user").c_str())) == NULL) {
 
				std::cerr << "Invalid service.user name " << CONFIG_STRING(config, "service.user") << "\n";
 
			}
 
			chown(dir.c_str(), pw->pw_uid, gr->gr_gid);
 
		}
 
		chown(dir.c_str(), pw->pw_uid, gr->gr_gid);
 
	}
 
#endif
 

	
 
#ifndef WIN32
 
		if (!dir.empty()) {
 
			umask(old_cmask);
 
		}
 
#endif
 
	}
 
}
 

	
0 comments (0 inline, 0 general)