[BRLTTY] Waiting for policykit startup

Samuel Thibault samuel.thibault at ens-lyon.org
Sat Oct 8 20:04:31 EDT 2016


Hello,

When BRLTTY is started very early, policykit is not running yet. BrlAPI
would then be disabled.  This makes the policykit initialization detect
the case when policykit it not started yet (G_IO_ERROR_NOT_FOUND), and
moves the initialization of authentication to inside the BrlAPI thread,
to avoid delaying the BRLTTY startup.

Samuel
-------------- next part --------------
diff --git a/Programs/auth.c b/Programs/auth.c
index f93afad..0dceef1 100644
--- a/Programs/auth.c
+++ b/Programs/auth.c
@@ -448,19 +448,29 @@ typedef struct {
 static void *
 authPolkit_initialize (const char *parameter) {
   MethodDescriptor_polkit *polkit;
+  GQuark domain;
+  gint code;
 
   if ((polkit = malloc(sizeof(*polkit)))) {
     memset(polkit, 0, sizeof(*polkit));
 
-    GError *error_local = NULL;
-    polkit->authority = polkit_authority_get_sync(NULL, &error_local);
+    while(1) {
+      GError *error_local = NULL;
+      polkit->authority = polkit_authority_get_sync(NULL, &error_local);
 
-    if (polkit->authority) {
-      return polkit;
-    } else {
-      g_error_free(error_local);
-      g_free(polkit);
+      if (polkit->authority) {
+	return polkit;
+      } else {
+	domain = error_local->domain;
+	code = error_local->code;
+	logMessage(LOG_WARNING, "Unable to connect to polkit: %s (%d) %s (%d)", g_quark_to_string(domain), (int) domain, error_local->message, code);
+	g_error_free(error_local);
+	if (domain != G_IO_ERROR && code != G_IO_ERROR_NOT_FOUND)
+	  break;
+      }
+      approximateDelay(1000);
     }
+    g_free(polkit);
   } else {
     logMallocError();
   }
diff --git a/Programs/brlapi_server.c b/Programs/brlapi_server.c
index 3fadda2..acd4c0b 100644
--- a/Programs/brlapi_server.c
+++ b/Programs/brlapi_server.c
@@ -2168,6 +2184,12 @@ THREAD_FUNCTION(runServer) {
   logMessage(LOG_CATEGORY(SERVER_EVENTS), "server thread started");
   if (!prepareThread()) goto finished;
 
+  if (auth && !isAbsolutePath(auth)) 
+    if (!(authDescriptor = authBeginServer(auth))) {
+      logMessage(LOG_WARNING, "Unable to start auth server");
+      goto finished;
+    }
+
   socketHosts = splitString(hosts,'+',&numSockets);
   if (numSockets>MAXSOCKETS) {
     logMessage(LOG_ERR,"too many hosts specified (%d, max %d)",numSockets,MAXSOCKETS);
@@ -3071,10 +3093,6 @@ int api_start(BrailleDisplay *brl, char **parameters)
     if (*operand) auth = operand;
   }
 
-  if (auth && !isAbsolutePath(auth)) 
-    if (!(authDescriptor = authBeginServer(auth)))
-      return 0;
-
   pthread_attr_t attr;
   pthread_mutexattr_t mattr;
 


More information about the BRLTTY mailing list