Browse Source

ncd/modules/net_backend_wpa_supplicant.c: Don't hardcode
/usr/bin/stdbuf, use badvpn_find_program().

ambrop7 12 năm trước cách đây
mục cha
commit
83bd6c1da3
2 tập tin đã thay đổi với 15 bổ sung6 xóa
  1. 4 5
      misc/stdbuf_cmdline.h
  2. 11 1
      ncd/modules/net_backend_wpa_supplicant.c

+ 4 - 5
misc/stdbuf_cmdline.h

@@ -40,25 +40,24 @@
 #include <misc/cmdline.h>
 #include <misc/balloc.h>
 
-#define STDBUF_EXEC "/usr/bin/stdbuf"
-
 /**
  * Builds the initial part of command line for calling a program via stdbuf
  * with standard output buffering set to line-buffered.
  * 
  * @param out {@link CmdLine} to append the result to. Note than on failure, only
  *            some part of the cmdline may have been appended.
+ * @param stdbuf_exec full path to stdbuf executable
  * @param exec path to the executable. Must not contain nulls. 
  * @param exec_len number of characters in exec
  * @return 1 on success, 0 on failure
  */
-static int build_stdbuf_cmdline (CmdLine *out, const char *exec, size_t exec_len) WARN_UNUSED;
+static int build_stdbuf_cmdline (CmdLine *out, const char *stdbuf_exec, const char *exec, size_t exec_len) WARN_UNUSED;
 
-int build_stdbuf_cmdline (CmdLine *out, const char *exec, size_t exec_len)
+int build_stdbuf_cmdline (CmdLine *out, const char *stdbuf_exec, const char *exec, size_t exec_len)
 {
     ASSERT(!memchr(exec, '\0', exec_len))
     
-    if (!CmdLine_AppendMulti(out, 3, STDBUF_EXEC, "-o", "L")) {
+    if (!CmdLine_AppendMulti(out, 3, stdbuf_exec, "-o", "L")) {
         goto fail1;
     }
     

+ 11 - 1
ncd/modules/net_backend_wpa_supplicant.c

@@ -54,6 +54,7 @@
 #include <misc/string_begins_with.h>
 #include <misc/stdbuf_cmdline.h>
 #include <misc/balloc.h>
+#include <misc/find_program.h>
 #include <flow/LineBuffer.h>
 #include <system/BInputProcess.h>
 #include <ncd/NCDModule.h>
@@ -213,8 +214,17 @@ int build_cmdline (struct instance *o, CmdLine *c)
         goto fail0;
     }
     
+    // find stdbuf executable
+    char *stdbuf_exec = badvpn_find_program("stdbuf");
+    if (!stdbuf_exec) {
+        ModuleLog(o->i, BLOG_ERROR, "cannot find stdbuf executable");
+        goto fail1;
+    }
+    
     // append stdbuf part
-    if (!build_stdbuf_cmdline(c, o->exec, o->exec_len)) {
+    int res = build_stdbuf_cmdline(c, stdbuf_exec, o->exec, o->exec_len);
+    free(stdbuf_exec);
+    if (!res) {
         goto fail1;
     }