Blob Blame History Raw
From 0319176e1d1fa741868d822100d0dde89a585ca3 Mon Sep 17 00:00:00 2001
From: Numan Siddique <numans@ovn.org>
Date: Wed, 8 Apr 2020 20:16:49 +0530
Subject: [PATCH] ovn-nbctl: Create daemon control socket in ovn run dir

ovn-nbctl when run as a daemon is creating the ctl socket in
the ovs rundir. This patch fixes this issue by creating it in
the ovn rundir.

When an ovn service is run with -u option (which specifies the
ctl socket path) and if this path is not absolute, the ovn
ctl socket path is created in the ovs run dir. This patch
also fixes this issue by creating it in the ovn run dir.

Reported-by: Dan Williams <dcbw@redhat.com>
Acked-by: Dumitru Ceara <dceara@redhat.com>
Signed-off-by: Numan Siddique <numans@ovn.org>

(cherry-picked from upstream branch-20.03 commit 29927708242044696a49051c77c3d4b38ba02392)

Change-Id: I17b3ab45f591fa9793ae8d95cf78c2113a1e4d65
---
 controller-vtep/ovn-controller-vtep.c |  5 ++++-
 controller/ovn-controller.c           |  2 +-
 ic/ovn-ic.c                           | 10 +++-------
 lib/ovn-util.c                        |  9 +++++----
 lib/ovn-util.h                        |  2 +-
 northd/ovn-northd.c                   | 10 +++-------
 utilities/ovn-nbctl.c                 |  6 +++++-
 utilities/ovn-trace.c                 |  6 +++++-
 8 files changed, 27 insertions(+), 23 deletions(-)

diff --git a/controller-vtep/ovn-controller-vtep.c b/controller-vtep/ovn-controller-vtep.c
index b30a731d4..253a709ab 100644
--- a/controller-vtep/ovn-controller-vtep.c
+++ b/controller-vtep/ovn-controller-vtep.c
@@ -67,7 +67,10 @@ main(int argc, char *argv[])
 
     daemonize_start(false);
 
-    retval = unixctl_server_create(NULL, &unixctl);
+    char *abs_unixctl_path = get_abs_unix_ctl_path(NULL);
+    retval = unixctl_server_create(abs_unixctl_path, &unixctl);
+    free(abs_unixctl_path);
+
     if (retval) {
         exit(EXIT_FAILURE);
     }
diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c
index 2893eaac1..4d21ba0fd 100644
--- a/controller/ovn-controller.c
+++ b/controller/ovn-controller.c
@@ -1729,7 +1729,7 @@ main(int argc, char *argv[])
 
     daemonize_start(true);
 
-    char *abs_unixctl_path = get_abs_unix_ctl_path();
+    char *abs_unixctl_path = get_abs_unix_ctl_path(NULL);
     retval = unixctl_server_create(abs_unixctl_path, &unixctl);
     free(abs_unixctl_path);
     if (retval) {
diff --git a/ic/ovn-ic.c b/ic/ovn-ic.c
index bf8205de2..d931ca50f 100644
--- a/ic/ovn-ic.c
+++ b/ic/ovn-ic.c
@@ -1575,13 +1575,9 @@ main(int argc, char *argv[])
 
     daemonize_start(false);
 
-    if (!unixctl_path) {
-        char *abs_unixctl_path = get_abs_unix_ctl_path();
-        retval = unixctl_server_create(abs_unixctl_path, &unixctl);
-        free(abs_unixctl_path);
-    } else {
-        retval = unixctl_server_create(unixctl_path, &unixctl);
-    }
+    char *abs_unixctl_path = get_abs_unix_ctl_path(unixctl_path);
+    retval = unixctl_server_create(abs_unixctl_path, &unixctl);
+    free(abs_unixctl_path);
 
     if (retval) {
         exit(EXIT_FAILURE);
diff --git a/lib/ovn-util.c b/lib/ovn-util.c
index df18fda89..514e2489f 100644
--- a/lib/ovn-util.c
+++ b/lib/ovn-util.c
@@ -377,7 +377,7 @@ default_ic_sb_db(void)
 }
 
 char *
-get_abs_unix_ctl_path(void)
+get_abs_unix_ctl_path(const char *path)
 {
 #ifdef _WIN32
     enum { WINDOWS = 1 };
@@ -386,9 +386,10 @@ get_abs_unix_ctl_path(void)
 #endif
 
     long int pid = getpid();
-    char *abs_path =
-        WINDOWS ? xasprintf("%s/%s.ctl", ovn_rundir(), program_name)
-                : xasprintf("%s/%s.%ld.ctl", ovn_rundir(), program_name, pid);
+    char *abs_path
+        = (path ? abs_file_name(ovn_rundir(), path)
+           : WINDOWS ? xasprintf("%s/%s.ctl", ovn_rundir(), program_name)
+           : xasprintf("%s/%s.%ld.ctl", ovn_rundir(), program_name, pid));
     return abs_path;
 }
 
diff --git a/lib/ovn-util.h b/lib/ovn-util.h
index 32c8334b0..11238f61c 100644
--- a/lib/ovn-util.h
+++ b/lib/ovn-util.h
@@ -82,7 +82,7 @@ const char *default_nb_db(void);
 const char *default_sb_db(void);
 const char *default_ic_nb_db(void);
 const char *default_ic_sb_db(void);
-char *get_abs_unix_ctl_path(void);
+char *get_abs_unix_ctl_path(const char *path);
 
 struct ovsdb_idl_table_class;
 const char *db_table_usage(struct ds *tables,
diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
index fd1be5b27..1f1238d23 100644
--- a/northd/ovn-northd.c
+++ b/northd/ovn-northd.c
@@ -11673,13 +11673,9 @@ main(int argc, char *argv[])
 
     daemonize_start(false);
 
-    if (!unixctl_path) {
-        char *abs_unixctl_path = get_abs_unix_ctl_path();
-        retval = unixctl_server_create(abs_unixctl_path, &unixctl);
-        free(abs_unixctl_path);
-    } else {
-        retval = unixctl_server_create(unixctl_path, &unixctl);
-    }
+    char *abs_unixctl_path = get_abs_unix_ctl_path(unixctl_path);
+    retval = unixctl_server_create(abs_unixctl_path, &unixctl);
+    free(abs_unixctl_path);
 
     if (retval) {
         exit(EXIT_FAILURE);
diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c
index 59abe0051..a88c1ddc2 100644
--- a/utilities/ovn-nbctl.c
+++ b/utilities/ovn-nbctl.c
@@ -6436,7 +6436,11 @@ server_loop(struct ovsdb_idl *idl, int argc, char *argv[])
 
     service_start(&argc, &argv);
     daemonize_start(false);
-    int error = unixctl_server_create(unixctl_path, &server);
+
+    char *abs_unixctl_path = get_abs_unix_ctl_path(unixctl_path);
+    int error = unixctl_server_create(abs_unixctl_path, &server);
+    free(abs_unixctl_path);
+
     if (error) {
         ctl_fatal("failed to create unixctl server (%s)",
                   ovs_retval_to_string(error));
diff --git a/utilities/ovn-trace.c b/utilities/ovn-trace.c
index e59698ec4..eae9622d3 100644
--- a/utilities/ovn-trace.c
+++ b/utilities/ovn-trace.c
@@ -125,7 +125,11 @@ main(int argc, char *argv[])
     bool exiting = false;
     if (get_detach()) {
         daemonize_start(false);
-        int error = unixctl_server_create(unixctl_path, &server);
+
+        char *abs_unixctl_path = get_abs_unix_ctl_path(unixctl_path);
+        int error = unixctl_server_create(abs_unixctl_path, &server);
+        free(abs_unixctl_path);
+
         if (error) {
             ovs_fatal(error, "failed to create unixctl server");
         }
-- 
2.25.1