Package: brltty / 5.4-7+deb9u1

wait-polkit Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
commit 7c26200d24b73fd4b3eec5e00f8593cf7ba507ff
Author: Dave Mielke <dave@mielke.cc>
Date:   Sat Oct 8 22:27:03 2016 -0400

    Waiting for Polkit initialization shouldn't delay BRLTTY startup. (st)
    
    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.

diff --git a/Programs/auth.c b/Programs/auth.c
index f93afad..9b8bf3b 100644
--- a/Programs/auth.c
+++ b/Programs/auth.c
@@ -54,6 +54,7 @@ typedef unsigned int gid_t;
 #include "strfmt.h"
 #include "parse.h"
 #include "auth.h"
+#include "async_wait.h"
 
 /* peer credentials */
 #undef CAN_CHECK_CREDENTIALS
@@ -452,15 +453,28 @@ authPolkit_initialize (const char *parameter) {
   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 {
+        GQuark domain = error_local->domain;
+        gint 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;
+        }
+      }
+
+      asyncWait(1000);
     }
+
+    g_free(polkit);
   } else {
     logMallocError();
   }
diff --git a/Programs/brlapi_server.c b/Programs/brlapi_server.c
index c3b3c6e..295f169 100644
--- a/Programs/brlapi_server.c
+++ b/Programs/brlapi_server.c
@@ -2183,6 +2183,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);
@@ -3086,10 +3092,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;