]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.2072: Socket server has a few minor issues v9.1.2072
authorFoxe Chen <chen.foxe@gmail.com>
Fri, 9 Jan 2026 17:30:50 +0000 (17:30 +0000)
committerChristian Brabandt <cb@256bit.org>
Fri, 9 Jan 2026 17:30:50 +0000 (17:30 +0000)
Problem:  Socket server has some small issues
Solution: Fix issues (see below)

- don't poll current vim instance when using serverlist()
- list the current vim instance in serverlist() (to match X11
  behaviour)
- don't make X11 feature disable socketserver feature
- refactor CheckSocketServer logic and update tests with remote server
  dependency

closes: #19118

Signed-off-by: Foxe Chen <chen.foxe@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
13 files changed:
Filelist
src/auto/configure
src/config.h.in
src/configure.ac
src/feature.h
src/os_unix.c
src/testdir/test_clientserver.vim
src/testdir/test_remote.vim
src/testdir/test_usercommands.vim
src/testdir/test_vim9_builtin.vim
src/testdir/util/check.vim
src/testdir/util/socketserver.vim [new file with mode: 0644]
src/version.c

index 7c8d1dd9e4b7fb197aab30d96ac02fe7f640858e..4cfba23235271cc89a7521700a24fe9cda027910 100644 (file)
--- a/Filelist
+++ b/Filelist
@@ -248,6 +248,7 @@ SRC_ALL =   \
                src/testdir/util/view_util.vim \
                src/testdir/util/vim9.vim \
                src/testdir/util/window_manager.vim \
+               src/testdir/util/socketserver.vim \
                src/testdir/viewdumps.vim \
                src/proto.h \
                src/protodef.h \
index 7cf35d66deddc7ddc81562a50d4b154ea89bb1a5..67a94928c9705d2966317ba5f455c0672a7eead6 100755 (executable)
@@ -9088,26 +9088,22 @@ then :
 else case e in #(
   e) if test "x$features" = xtiny
 then :
-  enable_socketserver=no_auto
+  enable_socketserver=no_msg
                         { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: cannot use socketserver with tiny features" >&5
 printf "%s\n" "cannot use socketserver with tiny features" >&6; }
 else case e in #(
-  e) enable_socketserver=auto ;;
+  e) enable_socketserver=yes ;;
 esac
 fi ;;
 esac
 fi
 
+
 if test "$enable_socketserver" = "yes"; then
   printf "%s\n" "#define WANT_SOCKETSERVER 1" >>confdefs.h
 
   { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 printf "%s\n" "yes" >&6; }
-elif test "$enable_socketserver" = "auto"; then
-  printf "%s\n" "#define MAYBE_SOCKETSERVER 1" >>confdefs.h
-
-  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: auto" >&5
-printf "%s\n" "auto" >&6; }
 elif test "$enable_socketserver" = "no"; then
   { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
 printf "%s\n" "no" >&6; }
@@ -14538,18 +14534,18 @@ then :
 fi
 if test "$enable_largefile,$enable_year2038" != no,no
 then :
-  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CPPFLAGS option for large files" >&5
-printf %s "checking for $CPPFLAGS option for large files... " >&6; }
+  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable large file support" >&5
+printf %s "checking for $CC option to enable large file support... " >&6; }
 if test ${ac_cv_sys_largefile_opts+y}
 then :
   printf %s "(cached) " >&6
 else case e in #(
-  e) ac_save_CPPFLAGS=$CPPFLAGS
+  e) ac_save_CC="$CC"
   ac_opt_found=no
-  for ac_opt in "none needed" "-D_FILE_OFFSET_BITS=64" "-D_LARGE_FILES=1"; do
+  for ac_opt in "none needed" "-D_FILE_OFFSET_BITS=64" "-D_LARGE_FILES=1" "-n32"; do
     if test x"$ac_opt" != x"none needed"
 then :
-  CPPFLAGS="$ac_save_CPPFLAGS $ac_opt"
+  CC="$ac_save_CC $ac_opt"
 fi
     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
@@ -14578,12 +14574,12 @@ then :
   if test x"$ac_opt" = x"none needed"
 then :
   # GNU/Linux s390x and alpha need _FILE_OFFSET_BITS=64 for wide ino_t.
-        CPPFLAGS="$CPPFLAGS -DFTYPE=ino_t"
+        CC="$CC -DFTYPE=ino_t"
         if ac_fn_c_try_compile "$LINENO"
 then :
 
 else case e in #(
-  e) CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64"
+  e) CC="$CC -D_FILE_OFFSET_BITS=64"
            if ac_fn_c_try_compile "$LINENO"
 then :
   ac_opt='-D_FILE_OFFSET_BITS=64'
@@ -14599,7 +14595,7 @@ fi
 rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
     test $ac_opt_found = no || break
   done
-  CPPFLAGS=$ac_save_CPPFLAGS
+  CC="$ac_save_CC"
 
   test $ac_opt_found = yes || ac_cv_sys_largefile_opts="support not detected" ;;
 esac
@@ -14623,14 +14619,16 @@ printf "%s\n" "#define _FILE_OFFSET_BITS 64" >>confdefs.h
 
 printf "%s\n" "#define _LARGE_FILES 1" >>confdefs.h
  ;; #(
+  "-n32") :
+    CC="$CC -n32" ;; #(
   *) :
     as_fn_error $? "internal error: bad value for \$ac_cv_sys_largefile_opts" "$LINENO" 5 ;;
 esac
 
 if test "$enable_year2038" != no
 then :
-  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CPPFLAGS option for timestamps after 2038" >&5
-printf %s "checking for $CPPFLAGS option for timestamps after 2038... " >&6; }
+  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option for timestamps after 2038" >&5
+printf %s "checking for $CC option for timestamps after 2038... " >&6; }
 if test ${ac_cv_sys_year2038_opts+y}
 then :
   printf %s "(cached) " >&6
index 983f186b8d1d7225dcbeb3ad8721bd495a8038b0..22c4a155dfe8501163cf24b375811ea96d51fd61 100644 (file)
 /* Define if you want to use sockets for clientserver communication. */
 #undef WANT_SOCKETSERVER
 
-/* Define if you want to use sockets for clientserver communication if it makes sense. */
-#undef MAYBE_SOCKETSERVER
-
 /* Define if you want to include fontset support. */
 #undef FEAT_XFONTSET
 
index fa6757d69f0c27a6da345a9ea970a83e6b0aff16..70ffb8eb2576e8891ac5d393669a0bf55f6c03e4 100644 (file)
@@ -2368,15 +2368,13 @@ AC_ARG_ENABLE(socketserver,
        [  --enable-socketserver Use sockets for clientserver communication.],
        [enable_socketserver=$enableval],
        AS_IF([test "x$features" = xtiny],
-                       [enable_socketserver=no_auto
+                       [enable_socketserver=no_msg
                         AC_MSG_RESULT([cannot use socketserver with tiny features])],
-                       [enable_socketserver=auto]))
+                       [enable_socketserver=yes]))
+
 if test "$enable_socketserver" = "yes"; then
   AC_DEFINE(WANT_SOCKETSERVER)
   AC_MSG_RESULT([yes])
-elif test "$enable_socketserver" = "auto"; then
-  AC_DEFINE(MAYBE_SOCKETSERVER)
-  AC_MSG_RESULT([auto])
 elif test "$enable_socketserver" = "no"; then
   AC_MSG_RESULT([no])
 fi
index cbb1875fdde4513aff1cf079de2bc2ade46d2afe..8f53488bd51a61f9da3c9b6d65441545713c6aa0 100644 (file)
 /*
  * +socketserver        Use UNIX domain sockets for clientserver communication
  */
-#if defined(UNIX) && (defined(WANT_SOCKETSERVER) || \
-       (defined(MAYBE_SOCKETSERVER) && !defined(HAVE_X11)))
+#if defined(UNIX) && defined(WANT_SOCKETSERVER)
 #define FEAT_SOCKETSERVER
 #endif
 
index 7798ff7e2443f09e6f0fbc6168fce2617bc86604..31e7fd4f48f4253d4dbb44513f9cbb57cfdcf3ee 100644 (file)
@@ -155,8 +155,8 @@ Display         *x11_display = NULL;
 # define SOCKET_SERVER_MAX_CMD_SIZE 16384
 # define SOCKET_SERVER_MAX_MSG 6
 
-static int socket_server_fd = -1;
-static char_u *socket_server_path = NULL;
+static int     socket_server_fd = -1;
+static char_u  *socket_server_path = NULL;
 
 typedef enum {
     SS_MSG_TYPE_ENCODING    = 'e',  // Encoding of message.
@@ -9416,10 +9416,19 @@ socket_server_list_sockets(void)
            buf.length = vim_snprintf_safelen((char *)buf.string, sizeof(addr.sun_path),
                "%s/%s", path.string, dp->d_name);
 
-           // Try sending an ALIVE command. This is more assuring than a
-           // simple connect, and *also seems to make tests less flaky*.
-           if (!socket_server_check_alive(buf.string))
-               continue;
+           // Don't want to send to ourselves, but we do want to list our
+           // server name (if we are a server).
+           if (socket_server_path == NULL
+                   || STRCMP(socket_server_path, buf.string) != 0)
+           {
+               // Try sending an ALIVE command. This is more assuring than a
+               // simple connect, and *also seems to make tests less flaky*.
+               //
+               // We could also use a lock file which may be better, but this
+               // has worked fine so far... - 64bitman
+               if (!socket_server_check_alive(buf.string))
+                   continue;
+           }
 
            ga_concat_len(&str, (char_u *)dp->d_name, buf.length - (path.length + 1));
            ga_append(&str, '\n');
index 24d91409638f26406412e887ce77d5100f144209..5f2e8870a13590585a8e5e75c466cf8de19949c4 100644 (file)
@@ -12,7 +12,7 @@ source util/shared.vim
 
 " Unlike X11, we need the socket server running if we want to send commands to
 " a server via sockets.
-CheckSocketServer
+RunSocketServer
 
 func Check_X11_Connection()
   if has('x11')
@@ -205,6 +205,7 @@ endfunc
 func Test_client_server_stopinsert()
   " test does not work on MS-Windows
   CheckNotMSWindows
+  CheckNotMac
   let g:test_is_flaky = 1
   let cmd = GetVimCommand()
   if cmd == ''
@@ -229,8 +230,8 @@ func Test_client_server_stopinsert()
 
   call remote_expr(name, 'execute("stopinsert")')
 
-  call assert_equal('n', name->remote_expr("mode(1)"))
-  call assert_equal('13', name->remote_expr("col('.')"))
+  call WaitForAssert({-> assert_equal('n', name->remote_expr("mode(1)"))})
+  cal WaitForAssert({-> assert_equal('13', name->remote_expr("col('.')"))})
 
   eval name->remote_send(":qa!\<CR>")
   try
@@ -283,7 +284,7 @@ func Test_client_server_x11_and_socket_server()
 endfunc
 
 " Test if socket server works in the GUI
-func Test_client_socket_server_server_gui()
+func Test_client_server_socket_server_gui()
   CheckNotMSWindows
   CheckFeature socketserver
   CheckFeature gui_gtk
index af70f2217ebb857538004e13802e2f6fe656efdf..ad959e629cbe552f8a7a6aa69ef60e692366c117 100644 (file)
@@ -131,4 +131,19 @@ func Test_remote_servername_shellslash()
   close
 endfunc
 
+" Test if serverlist() lists itself.
+func Test_remote_servername_itself()
+  let lines =<< trim END
+    call writefile([serverlist()], "XTest")
+  END
+  defer delete("XTest")
+  call writefile(lines, 'XRemote.vim', 'D')
+  let buf = RunVimInTerminal('--servername XVIMTEST -S XRemote.vim', {'rows': 8})
+  call TermWait(buf)
+
+  call WaitForAssert({-> assert_match("XVIMTEST", readfile("XTest")[0])})
+
+  call StopVimInTerminal(buf)
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 2718a24dd31e2fb41c4a8e82224b1b1924f6610c..a327106bc56ad7554b2f3c2f176b0452f532d9ce 100644 (file)
@@ -391,6 +391,7 @@ func Test_CmdCompletion()
     exe 'delcommand ' .. cmd
   endfor
   delcommand MissingFeature
+  delcommand RunSocketServer
 
   command! DoCmd1 :
   command! DoCmd2 :
index 4346c14713b23aff54cac78d2ccebe63c11daf6b..d5521cf879851509b6927cd4cb594d1ab7146474 100644 (file)
@@ -1,11 +1,9 @@
 " Test using builtin functions in the Vim9 script language.
 
 source util/screendump.vim
+source util/socketserver.vim
 import './util/vim9.vim' as v9
 
-" Socket backend for remote functions require the socket server to be running
-CheckSocketServer
-
 " Test for passing too many or too few arguments to builtin functions
 func Test_internalfunc_arg_error()
   let l =<< trim END
@@ -3527,12 +3525,17 @@ enddef
 
 def Test_remote_expr()
   CheckFeature clientserver
-  CheckEnv DISPLAY
+  TrySocketServer
+
+  if !g:socketserver_only
+    CheckEnv DISPLAY
+  endif
   v9.CheckSourceDefAndScriptFailure(['remote_expr(1, "b")'], ['E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1'])
   v9.CheckSourceDefAndScriptFailure(['remote_expr("a", 2)'], ['E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2'])
   v9.CheckSourceDefAndScriptFailure(['remote_expr("a", "b", 3)'], ['E1013: Argument 3: type mismatch, expected string but got number', 'E1174: String required for argument 3'])
   v9.CheckSourceDefAndScriptFailure(['remote_expr("a", "b", "c", "d")'], ['E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4'])
-  v9.CheckSourceDefExecAndScriptFailure(['remote_expr("", "")'], 'E241: Unable to send to ')
+
+    v9.CheckSourceDefExecAndScriptFailure(['remote_expr("", "")'], 'E241: Unable to send to ')
 enddef
 
 def Test_remote_foreground()
@@ -3548,7 +3551,10 @@ enddef
 
 def Test_remote_peek()
   CheckFeature clientserver
-  CheckEnv DISPLAY
+  TrySocketServer
+  if !g:socketserver_only
+    CheckEnv DISPLAY
+  endif
   v9.CheckSourceDefAndScriptFailure(['remote_peek(0z10)'], ['E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1'])
   v9.CheckSourceDefAndScriptFailure(['remote_peek("a5b6c7", [1])'], ['E1013: Argument 2: type mismatch, expected string but got list<number>', 'E1174: String required for argument 2'])
   v9.CheckSourceDefExecAndScriptFailure(['remote_peek("")'], 'E573: Invalid server id used')
@@ -3564,7 +3570,10 @@ enddef
 
 def Test_remote_send()
   CheckFeature clientserver
-  CheckEnv DISPLAY
+  TrySocketServer
+  if !g:socketserver_only
+    CheckEnv DISPLAY
+  endif
   v9.CheckSourceDefAndScriptFailure(['remote_send(1, "b")'], ['E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1'])
   v9.CheckSourceDefAndScriptFailure(['remote_send("a", 2)'], ['E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2'])
   v9.CheckSourceDefAndScriptFailure(['remote_send("a", "b", 3)'], ['E1013: Argument 3: type mismatch, expected string but got number', 'E1174: String required for argument 3'])
@@ -3573,7 +3582,10 @@ enddef
 
 def Test_remote_startserver()
   CheckFeature clientserver
-  CheckEnv DISPLAY
+  TrySocketServer
+  if !g:socketserver_only
+    CheckEnv DISPLAY
+  endif
   v9.CheckSourceDefAndScriptFailure(['remote_startserver({})'], ['E1013: Argument 1: type mismatch, expected string but got dict<any>', 'E1174: String required for argument 1'])
 enddef
 
index f6bf8dfdb68b323b00538d1e23ca4ec8305abf40..8a3a97e4f2198f852b95ec2234627a312156b8ef 100644 (file)
@@ -329,12 +329,12 @@ func CheckGithubActions()
   endif
 endfunc
 
-command CheckSocketServer call CheckSocketServer()
-func CheckSocketServer()
-  if v:servername == ""
+command RunSocketServer call RunSocketServer()
+func RunSocketServer()
+  if has("socketserver") && v:servername == ""
     try
       call remote_startserver('VIMSOCKETSERVERTEST')
-    catch /^Vim\%((\a\+)\)\=:E240:/ " not possible to start a remote server
+    catch " not possible to start a remote server
       throw 'Skipped: Cannot start remote server'
     endtry
   endif
diff --git a/src/testdir/util/socketserver.vim b/src/testdir/util/socketserver.vim
new file mode 100644 (file)
index 0000000..5492db6
--- /dev/null
@@ -0,0 +1,17 @@
+" Check if only the socketserver backend is available for clientserver (only on
+" Unix), and set g:socketserver_only to v:true along with starting the
+" socketserver.
+command TrySocketServer call TrySocketServer()
+func TrySocketServer()
+  if has("socketserver") && !has("x11")
+    let g:socketserver_only = v:true
+
+    if v:servername == ""
+      call remote_startserver('VIMSOCKETSERVERTEST')
+    endif
+  else
+      let g:socketserver_only = v:false
+    endif
+endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
index f24b8c2fc38adb374792534b9a6d4f6d80211295..2d5c065dd3e08e2953ac0ca78fdce254869f6958 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2072,
 /**/
     2071,
 /**/