X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flogin%2Flogind-core.c;h=fe97c1de0e01e1f3db09b1ca998893dfcbee9b62;hb=5c524c1900f85eb098ad525f80f9c61801fd9366;hp=06ca3c1c8b38a88a36af21ddb238110fcabc77c8;hpb=91216a607d510872fe02f82c84558417f26e60c3;p=elogind.git diff --git a/src/login/logind-core.c b/src/login/logind-core.c index 06ca3c1c8..fe97c1de0 100644 --- a/src/login/logind-core.c +++ b/src/login/logind-core.c @@ -279,7 +279,7 @@ int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session) { _cleanup_free_ char *unit = NULL; #else _cleanup_free_ char *session_name = NULL; -#endif +#endif // 0 Session *s; int r; @@ -296,12 +296,15 @@ int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session) { s = hashmap_get(m->session_units, unit); #else + log_debug_elogind("Searching session for PID %u", pid); r = cg_pid_get_session(pid, &session_name); if (r < 0) return 0; s = hashmap_get(m->sessions, session_name); -#endif + log_debug_elogind("Session Name \"%s\" -> Session \"%s\"", + session_name, s && s->id ? s->id : "NULL"); +#endif // 0 if (!s) return 0; @@ -317,7 +320,7 @@ int manager_get_user_by_pid(Manager *m, pid_t pid, User **user) { User *u; #else Session *s; -#endif +#endif // 0 int r; assert(m); @@ -351,7 +354,7 @@ int manager_get_user_by_pid(Manager *m, pid_t pid, User **user) { int manager_get_idle_hint(Manager *m, dual_timestamp *t) { Session *s; bool idle_hint; - dual_timestamp ts = { 0, 0 }; + dual_timestamp ts = DUAL_TIMESTAMP_NULL; Iterator i; assert(m); @@ -471,7 +474,7 @@ int manager_spawn_autovt(Manager *m, unsigned int vtnr) { } #endif // 0 -bool manager_is_docked(Manager *m) { +static bool manager_is_docked(Manager *m) { Iterator i; Button *b; @@ -482,7 +485,7 @@ bool manager_is_docked(Manager *m) { return false; } -int manager_count_displays(Manager *m) { +static int manager_count_external_displays(Manager *m) { _cleanup_udev_enumerate_unref_ struct udev_enumerate *e = NULL; struct udev_list_entry *item = NULL, *first = NULL; int r; @@ -504,7 +507,8 @@ int manager_count_displays(Manager *m) { udev_list_entry_foreach(item, first) { _cleanup_udev_device_unref_ struct udev_device *d = NULL; struct udev_device *p; - const char *status; + const char *status, *enabled, *dash, *nn, *i; + bool external = false; d = udev_device_new_from_syspath(m->udev, udev_list_entry_get_name(item)); if (!d) @@ -520,6 +524,40 @@ int manager_count_displays(Manager *m) { if (!streq_ptr(udev_device_get_subsystem(p), "drm")) continue; + nn = udev_device_get_sysname(d); + if (!nn) + continue; + + /* Ignore internal displays: the type is encoded in + * the sysfs name, as the second dash seperated item + * (the first is the card name, the last the connector + * number). We implement a whitelist of external + * displays here, rather than a whitelist, to ensure + * we don't block suspends too eagerly. */ + dash = strchr(nn, '-'); + if (!dash) + continue; + + dash++; + FOREACH_STRING(i, "VGA-", "DVI-I-", "DVI-D-", "DVI-A-" + "Composite-", "SVIDEO-", "Component-", + "DIN-", "DP-", "HDMI-A-", "HDMI-B-", "TV-") { + + if (startswith(dash, i)) { + external = true; + break; + } + } + if (!external) + continue; + + /* Ignore ports that are not enabled */ + enabled = udev_device_get_sysattr_value(d, "enabled"); + if (!enabled) + continue; + if (!streq_ptr(enabled, "enabled")) + continue; + /* We count any connector which is not explicitly * "disconnected" as connected. */ status = udev_device_get_sysattr_value(d, "status"); @@ -530,7 +568,7 @@ int manager_count_displays(Manager *m) { return n; } -bool manager_is_docked_or_multiple_displays(Manager *m) { +bool manager_is_docked_or_external_displays(Manager *m) { int n; /* If we are docked don't react to lid closing */ @@ -541,11 +579,11 @@ bool manager_is_docked_or_multiple_displays(Manager *m) { /* If we have more than one display connected, * assume that we are docked. */ - n = manager_count_displays(m); + n = manager_count_external_displays(m); if (n < 0) log_warning_errno(n, "Display counting failed: %m"); - else if (n > 1) { - log_debug("Multiple (%i) displays connected.", n); + else if (n >= 1) { + log_debug("External (%i) displays connected.", n); return true; }