コード例 #1
0
ファイル: LaunchDaemon.cpp プロジェクト: garodimb/haiku
status_t
LaunchDaemon::_StartSession(const char* login)
{
	// TODO: enable user/group code
	// The launch_daemon currently cannot talk to the registrar, though

	struct passwd* passwd = getpwnam(login);
	if (passwd == NULL)
		return B_NAME_NOT_FOUND;
	if (strcmp(passwd->pw_name, login) != 0)
		return B_NAME_NOT_FOUND;

	// Check if there is a user session running already
	uid_t user = passwd->pw_uid;
	gid_t group = passwd->pw_gid;

	Unlock();

	if (fork() == 0) {
		if (setsid() < 0)
			exit(EXIT_FAILURE);

		if (initgroups(login, group) == -1)
			exit(EXIT_FAILURE);
		if (setgid(group) != 0)
			exit(EXIT_FAILURE);
		if (setuid(user) != 0)
			exit(EXIT_FAILURE);

		if (passwd->pw_dir != NULL && passwd->pw_dir[0] != '\0') {
			setenv("HOME", passwd->pw_dir, true);

			if (chdir(passwd->pw_dir) != 0) {
				debug_printf("Could not switch to home dir %s: %s\n",
					passwd->pw_dir, strerror(errno));
			}
		}

		// TODO: This leaks the parent application
		be_app = NULL;

		// Reinitialize be_roster
		BRoster::Private().DeleteBeRoster();
		BRoster::Private().InitBeRoster();

		// TODO: take over system jobs, and reserve their names (or ask parent)
		status_t status;
		LaunchDaemon* daemon = new LaunchDaemon(true, fEvents, status);
		if (status == B_OK)
			daemon->Run();

		delete daemon;
		exit(EXIT_SUCCESS);
	}
	Lock();
	return B_OK;
}
コード例 #2
0
ファイル: LaunchDaemon.cpp プロジェクト: puckipedia/haiku
int
main()
{
	EventMap events;
	status_t status;
	LaunchDaemon* daemon = new LaunchDaemon(false, events, status);
	if (status == B_OK)
		daemon->Run();

	delete daemon;
	return status == B_OK ? EXIT_SUCCESS : EXIT_FAILURE;
}
コード例 #3
0
ファイル: LaunchDaemon.cpp プロジェクト: puckipedia/haiku
status_t
LaunchDaemon::_StartSession(const char* login)
{
	// TODO: enable user/group code
	// The launch_daemon currently cannot talk to the registrar, though

	struct passwd* passwd = getpwnam(login);
	if (passwd == NULL)
		return B_NAME_NOT_FOUND;
	if (strcmp(passwd->pw_name, login) != 0)
		return B_NAME_NOT_FOUND;

	// Check if there is a user session running already
	uid_t user = passwd->pw_uid;
	gid_t group = passwd->pw_gid;

	Unlock();

	if (fork() == 0) {
		if (setsid() < 0)
			exit(EXIT_FAILURE);

		if (initgroups(login, group) == -1)
			exit(EXIT_FAILURE);
		if (setgid(group) != 0)
			exit(EXIT_FAILURE);
		if (setuid(user) != 0)
			exit(EXIT_FAILURE);

		BString home="HOME=\"";
		home << passwd->pw_dir << "\"";
		putenv(home.String());

		// TODO: This leaks the parent application
		be_app = NULL;

		// TODO: take over system jobs, and reserve their names
		status_t status;
		LaunchDaemon* daemon = new LaunchDaemon(true, fEvents, status);
		if (status == B_OK)
			daemon->Run();

		delete daemon;
		exit(EXIT_SUCCESS);
	}
	Lock();
	return B_OK;
}
コード例 #4
0
ファイル: LaunchDaemon.cpp プロジェクト: garodimb/haiku
int
main()
{
	// Make stdin/out/err available
	open_stdio(STDIN_FILENO, O_RDONLY);
	open_stdio(STDOUT_FILENO, O_WRONLY);
	dup2(STDOUT_FILENO, STDERR_FILENO);

	EventMap events;
	status_t status;
	LaunchDaemon* daemon = new LaunchDaemon(false, events, status);
	if (status == B_OK)
		daemon->Run();

	delete daemon;
	return status == B_OK ? EXIT_SUCCESS : EXIT_FAILURE;
}