예제 #1
0
int main(int argc, char* argv[])
{
	schd = create_scheduler();
	initialize_scheduler(schd, NULL);

	session_1 = create_session();
	initialize_session(session_1, "222.214.218.237", 6601, "1299880", 0);
	set_session_index(session_1, 0);
	add_session(schd, session_1);

	session_2 = create_session();
	initialize_session(session_2, "222.214.218.237", 6601, "1299880", 1);
	set_session_index(session_2, 1);
	add_session(schd, session_2);

	set_surface_mode(schd->surface, mode_2);

	scheduler_start(schd);
	session_start(session_1);
	session_start(session_2);

	scheduler_wait(schd);

	session_stop(session_1);
	session_stop(session_2);
	destroy_session(session_1);
	destroy_session(session_2);

	return 0;
}
예제 #2
0
파일: session_mgr.c 프로젝트: rocflyhi/glow
int session_mgr_remove(session_mgr_t *mgr, int id)
{
	if (mgr == NULL || id < 0) {
		LOG_ERROR("Invalid session mgr or id");
		return ZISS_ERROR;
	}

	if (mgr->session_list == NULL) {
		LOG_ERROR("Invalid session list");
		return ZISS_ERROR;
	}

	if (mgr->session_list->id == id) {
		session_t *session_del = mgr->session_list;
		mgr->session_list = mgr->session_list->next;

		session_stop(session_del);
		session_delete(session_del);
		session_del = NULL;
		return ZISS_OK;
	}

	session_t *s = mgr->session_list;
	while (s->next != NULL) {
		if (s->next->id == id) {
			session_t *session_del = s->next;
			s->next = s->next->next;

			session_stop(session_del);
			session_delete(session_del);
			session_del = NULL;
			return ZISS_OK;
		} else {
			s = s->next;
		}
	}

	LOG_WARN("Session id not found");
	return ZISS_OK;
}
예제 #3
0
파일: session_mgr.c 프로젝트: rocflyhi/glow
int session_mgr_check(session_mgr_t *mgr)
{
	if (mgr == NULL) {
		LOG_ERROR("Invalid session mgr");
		return ZISS_ERROR;
	}

	if (mgr->session_list == NULL)
		return ZISS_OK;

	if (mgr->session_list->is_to_exit) {	// TODO: lock here
		session_t *session_del = mgr->session_list;
		mgr->session_list = mgr->session_list->next;

		session_stop(session_del);
		session_delete(session_del);
		session_del = NULL;
		return ZISS_OK;
	}

	session_t *s = mgr->session_list;
	while (s->next != NULL) {
		if (s->next->is_to_exit) {	// TODO: lock here
			session_t *session_del = s->next;
			s->next = s->next->next;

			session_stop(session_del);
			session_delete(session_del);
			session_del = NULL;
			return ZISS_OK;
		} else {
			s = s->next;
		}
	}

	return ZISS_OK;
}
예제 #4
0
파일: session_mgr.c 프로젝트: rocflyhi/glow
int session_mgr_clear(session_mgr_t *mgr)
{
	if (mgr == NULL) {
		LOG_ERROR("Invalid session mgr");
		return ZISS_ERROR;
	}

	while (mgr->session_list != NULL) {
		session_t *temp = mgr->session_list;
		mgr->session_list = mgr->session_list->next;
		
		session_stop(temp);
		session_delete(temp);
		temp = NULL;
	}

	return ZISS_OK;
}
static DBusHandlerResult session_message_dispatch(
                Session *s,
                DBusConnection *connection,
                DBusMessage *message) {

        const BusProperty properties[] = {
                { "org.freedesktop.login1.Session", "Id",                 bus_property_append_string,   "s",    s->id                   },
                { "org.freedesktop.login1.Session", "User",               bus_session_append_user,      "(uo)", s                       },
                { "org.freedesktop.login1.Session", "Name",               bus_property_append_string,   "s",    s->user->name           },
                { "org.freedesktop.login1.Session", "Timestamp",          bus_property_append_usec,     "t",    &s->timestamp.realtime  },
                { "org.freedesktop.login1.Session", "TimestampMonotonic", bus_property_append_usec,     "t",    &s->timestamp.monotonic },
                { "org.freedesktop.login1.Session", "ControlGroupPath",   bus_property_append_string,   "s",    s->cgroup_path          },
                { "org.freedesktop.login1.Session", "VTNr",               bus_property_append_uint32,   "u",    &s->vtnr                },
                { "org.freedesktop.login1.Session", "Seat",               bus_session_append_seat,      "(so)", s                       },
                { "org.freedesktop.login1.Session", "TTY",                bus_property_append_string,   "s",    s->tty                  },
                { "org.freedesktop.login1.Session", "Display",            bus_property_append_string,   "s",    s->display              },
                { "org.freedesktop.login1.Session", "Remote",             bus_property_append_bool,     "b",    &s->remote              },
                { "org.freedesktop.login1.Session", "RemoteUser",         bus_property_append_string,   "s",    s->remote_user          },
                { "org.freedesktop.login1.Session", "RemoteHost",         bus_property_append_string,   "s",    s->remote_host          },
                { "org.freedesktop.login1.Session", "Service",            bus_property_append_string,   "s",    s->service              },
                { "org.freedesktop.login1.Session", "Leader",             bus_property_append_pid,      "u",    &s->leader              },
                { "org.freedesktop.login1.Session", "Audit",              bus_property_append_uint32,   "u",    &s->audit_id            },
                { "org.freedesktop.login1.Session", "Type",               bus_session_append_type,      "s",    &s->type                },
                { "org.freedesktop.login1.Session", "Active",             bus_session_append_active,    "b",    s                       },
                { "org.freedesktop.login1.Session", "Controllers",        bus_property_append_strv,     "as",   s->controllers          },
                { "org.freedesktop.login1.Session", "ResetControllers",   bus_property_append_strv,     "as",   s->reset_controllers    },
                { "org.freedesktop.login1.Session", "KillProcesses",      bus_property_append_bool,     "b",    &s->kill_processes      },
                { "org.freedesktop.login1.Session", "IdleHint",           bus_session_append_idle_hint, "b",    s                       },
                { "org.freedesktop.login1.Session", "IdleSinceHint",          bus_session_append_idle_hint_since, "t", s                },
                { "org.freedesktop.login1.Session", "IdleSinceHintMonotonic", bus_session_append_idle_hint_since, "t", s                },
                { NULL, NULL, NULL, NULL, NULL }
        };

        DBusError error;
        DBusMessage *reply = NULL;
        int r;

        assert(s);
        assert(connection);
        assert(message);

        dbus_error_init(&error);

        if (dbus_message_is_method_call(message, "org.freedesktop.login1.Session", "Terminate")) {

                r = session_stop(s);
                if (r < 0)
                        return bus_send_error_reply(connection, message, NULL, r);

                reply = dbus_message_new_method_return(message);
                if (!reply)
                        goto oom;

        } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Session", "Activate")) {

                r = session_activate(s);
                if (r < 0)
                        return bus_send_error_reply(connection, message, NULL, r);

                reply = dbus_message_new_method_return(message);
                if (!reply)
                        goto oom;

        } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Session", "Lock") ||
                   dbus_message_is_method_call(message, "org.freedesktop.login1.Session", "Unlock")) {

                if (session_send_signal(s, streq(dbus_message_get_member(message), "Lock")) < 0)
                        goto oom;

                reply = dbus_message_new_method_return(message);
                if (!reply)
                        goto oom;

        } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Session", "SetIdleHint")) {
                dbus_bool_t b;
                unsigned long ul;

                if (!dbus_message_get_args(
                                    message,
                                    &error,
                                    DBUS_TYPE_BOOLEAN, &b,
                                    DBUS_TYPE_INVALID))
                        return bus_send_error_reply(connection, message, &error, -EINVAL);

                ul = dbus_bus_get_unix_user(connection, dbus_message_get_sender(message), &error);
                if (ul == (unsigned long) -1)
                        return bus_send_error_reply(connection, message, &error, -EIO);

                if (ul != 0 && ul != s->user->uid)
                        return bus_send_error_reply(connection, message, NULL, -EPERM);

                session_set_idle_hint(s, b);

                reply = dbus_message_new_method_return(message);
                if (!reply)
                        goto oom;

        } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Session", "Kill")) {
                const char *swho;
                int32_t signo;
                KillWho who;

                if (!dbus_message_get_args(
                                    message,
                                    &error,
                                    DBUS_TYPE_STRING, &swho,
                                    DBUS_TYPE_INT32, &signo,
                                    DBUS_TYPE_INVALID))
                        return bus_send_error_reply(connection, message, &error, -EINVAL);

                if (isempty(swho))
                        who = KILL_ALL;
                else {
                        who = kill_who_from_string(swho);
                        if (who < 0)
                                return bus_send_error_reply(connection, message, &error, -EINVAL);
                }

                if (signo <= 0 || signo >= _NSIG)
                        return bus_send_error_reply(connection, message, &error, -EINVAL);

                r = session_kill(s, who, signo);
                if (r < 0)
                        return bus_send_error_reply(connection, message, NULL, r);

                reply = dbus_message_new_method_return(message);
                if (!reply)
                        goto oom;

        } else
                return bus_default_message_handler(connection, message, INTROSPECTION, INTERFACES_LIST, properties);

        if (reply) {
                if (!dbus_connection_send(connection, reply, NULL))
                        goto oom;

                dbus_message_unref(reply);
        }

        return DBUS_HANDLER_RESULT_HANDLED;

oom:
        if (reply)
                dbus_message_unref(reply);

        dbus_error_free(&error);

        return DBUS_HANDLER_RESULT_NEED_MEMORY;
}