]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: Add set_socket_path() to sockopt.c to override the path element of a (vty) socke...
authorMartin Winter <mwinter@opensourcerouting.org>
Tue, 24 Jan 2017 15:42:11 +0000 (22:42 +0700)
committerMartin Winter <mwinter@opensourcerouting.org>
Wed, 25 Jan 2017 17:40:55 +0000 (00:40 +0700)
Signed-off-by: Martin Winter <mwinter@opensourcerouting.org>
lib/sockopt.c
lib/sockopt.h

index 461e1f7f5469d8dfc2c1390ec9eccfff0aced3d5..570b575a7ae8ec3fe4e34d756fac78e32af0c30a 100644 (file)
 #include "sockopt.h"
 #include "sockunion.h"
 
+/* Replace the path of given defaultpath with newpath, but keep filename */
+void
+set_socket_path (char *path, char *defaultpath, char *newpath, int maxsize)
+{
+  char *sock_name;
+
+  sock_name = strrchr(defaultpath, '/');
+  if (sock_name)
+    /* skip '/' */
+    sock_name++;
+  else
+    /*
+     * VTYSH_PATH configured as relative path
+     * during config? Should really never happen for
+     * sensible config
+     */
+    sock_name = defaultpath;
+
+  strlcpy (path, newpath, maxsize);
+  strlcat (path, "/", maxsize);
+  strlcat (path, sock_name, maxsize);
+}
+
 void
 setsockopt_so_recvbuf (int sock, int size)
 {
index b3ab57ab716c7ad8499b0ec213845efcff5c76eb..8e7895dd6f8c909520481f0d5c6558bf4e4907d3 100644 (file)
@@ -24,6 +24,9 @@
 
 #include "sockunion.h"
 
+/* Override (vty) socket paths, but keep the filename */
+extern void set_socket_path (char *path, char *defaultpath, char *newpath, int maxsize);
+
 extern void setsockopt_so_recvbuf (int sock, int size);
 extern void setsockopt_so_sendbuf (const int sock, int size);
 extern int getsockopt_so_sendbuf (const int sock);