Changeset 86495 in vbox
- Timestamp:
- Oct 8, 2020 1:04:26 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/dbus-calls.h
r82968 r86495 45 45 RT_PROXY_STUB(dbus_free_string_array, void, (char **str_array), \ 46 46 (str_array)) \ 47 RT_PROXY_STUB(dbus_connection_ref, DBusConnection *, (DBusConnection *connection), \ 48 (connection)) \ 47 49 RT_PROXY_STUB(dbus_connection_unref, void, (DBusConnection *connection), \ 48 50 (connection)) \ -
trunk/src/VBox/Main/src-server/linux/HostPowerLinux.cpp
r82968 r86495 45 45 HostPowerServiceLinux::HostPowerServiceLinux(VirtualBox *aVirtualBox) 46 46 : HostPowerService(aVirtualBox) 47 , mThread(N ULL)47 , mThread(NIL_RTTHREAD) 48 48 , mpConnection(NULL) 49 49 { … … 76 76 if (checkDBusError(&error, &mpConnection)) 77 77 return; 78 79 /* Grab another reference so that both the destruct and thread each has one: */ 80 DBusConnection *pForAssert = dbus_connection_ref(mpConnection); 81 Assert(pForAssert == mpConnection); RT_NOREF(pForAssert); 82 78 83 /* Create the new worker thread. */ 79 84 rc = RTThreadCreate(&mThread, HostPowerServiceLinux::powerChangeNotificationThread, this, 0 /* cbStack */, 80 85 RTTHREADTYPE_MSG_PUMP, RTTHREADFLAGS_WAITABLE, "MainPower"); 81 86 if (RT_FAILURE(rc)) 87 { 82 88 LogRel(("HostPowerServiceLinux: RTThreadCreate failed with %Rrc\n", rc)); 89 dbus_connection_unref(mpConnection); 90 } 83 91 } 84 92 … … 86 94 HostPowerServiceLinux::~HostPowerServiceLinux() 87 95 { 88 int rc;89 RTMSINTERVAL cMillies = 5000;90 91 96 /* Closing the connection should cause the event loop to exit. */ 92 97 LogFunc((": Stopping thread\n")); 93 98 if (mpConnection) 99 { 94 100 dbus_connection_close(mpConnection); 101 dbus_connection_unref(mpConnection); 102 mpConnection = NULL; 103 } 95 104 96 rc = RTThreadWait(mThread, cMillies, NULL); 97 if (rc != VINF_SUCCESS) 98 LogRelThisFunc(("RTThreadWait() for %u ms failed with %Rrc\n", cMillies, rc)); 99 mThread = NIL_RTTHREAD; 105 if (mThread != NIL_RTTHREAD) 106 { 107 /* HACK ALERT! This poke call should _not_ be necessary as dbus_connection_close() 108 should close the socket and force the poll/dbus_connection_read_write 109 call to return with POLLHUP/FALSE. It does so when stepping it in the 110 debugger, but not in real life (asan build; dbus-1.12.20-1.fc32; linux 5.8). 111 112 Poking the thread is a crude crude way to wake it up from whatever 113 stuff it's actually blocked on and realize that the connection has 114 been dropped. */ 115 116 uint64_t msElapsed = RTTimeMilliTS(); 117 int vrc = RTThreadWait(mThread, 10 /*ms*/, NULL); 118 if (RT_FAILURE(vrc)) 119 { 120 RTThreadPoke(mThread); 121 vrc = RTThreadWait(mThread, RT_MS_5SEC, NULL); 122 } 123 msElapsed = RTTimeMilliTS() - msElapsed; 124 if (vrc != VINF_SUCCESS) 125 LogRelThisFunc(("RTThreadWait() failed after %llu ms: %Rrc\n", msElapsed, vrc)); 126 mThread = NIL_RTTHREAD; 127 } 100 128 } 101 129 … … 114 142 for (;;) 115 143 { 116 DBusMessageIter args;117 dbus_bool_t fSuspend;118 119 144 pMessage = dbus_connection_pop_message(pConnection); 120 145 if (pMessage == NULL) 121 146 break; 147 122 148 /* The systemd-logind interface notification. */ 149 DBusMessageIter args; 123 150 if ( dbus_message_is_signal(pMessage, "org.freedesktop.login1.Manager", "PrepareForSleep") 124 151 && dbus_message_iter_init(pMessage, &args) 125 152 && dbus_message_iter_get_arg_type(&args) == DBUS_TYPE_BOOLEAN) 126 153 { 154 dbus_bool_t fSuspend; 127 155 dbus_message_iter_get_basic(&args, &fSuspend); 156 128 157 /* Trinary operator does not work here as Reason_... is an 129 158 * anonymous enum. */ … … 133 162 pPowerObj->notify(Reason_HostResume); 134 163 } 164 135 165 /* The UPowerd interface notifications. Sleeping is the older one, 136 166 * NotifySleep the newer. This gives us one second grace before the … … 142 172 || dbus_message_is_signal(pMessage, "org.freedesktop.UPower", "NotifyResume")) 143 173 pPowerObj->notify(Reason_HostResume); 174 144 175 /* Free local resources held for the message. */ 145 176 dbus_message_unref(pMessage); 146 177 } 147 178 } 179 148 180 /* Close the socket or whatever underlying the connection. */ 149 181 dbus_connection_close(pConnection); 182 150 183 /* Free in-process resources used for the now-closed connection. */ 151 184 dbus_connection_unref(pConnection); 185 152 186 Log(("HostPowerServiceLinux: Exiting thread\n")); 153 187 return VINF_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.