summaryrefslogtreecommitdiff
path: root/src/remote.cc
AgeCommit message (Collapse)Author
2025-07-08Replace on_scope_end with CTAD with OnScopeEnd directlyMaxime Coste
2025-07-08Replace std::unique_ptr with a custom implementationMaxime Coste
<memory> is a costly header we can avoid by just implementing UniquePtr ourselves, which is a pretty straightforward in modern C++, this saves around 10% of the compilation time here.
2024-11-28Add back option to scroll in stdin buffersJohannes Altmanninger
Commit 582c3c56b (Do not add trailing newline to non-scrolling fifo buffers, 2024-01-28) completely forgot about stdin buffers, breaking the ability to make them scrolling via "ge". For example while sleep 1; do seq $LINES date done | kak Let's fix that by adding the trailing newline back for stdin buffers. Unlike "edit -scroll", don't scroll until the user explicitly moves the cursor.
2024-11-12Fail rename-session instead of creating overlong socket pathsJohannes Altmanninger
Commit 9cf8a3ccd (Check for buffer overflow when constructing the socket path., 2022-04-07) made $ kak -s $(printf %0100d) fail but forgot to do the same for $ kak -e "rename-session $(printf %0100d)" which silently succeeds, only to fail at the next $ echo nop | kak -p $(printf %0100d) Fatal error: socket path too long: '/run/user/1000/kakoune/0000...' Let's fail earlier. While at it, don't validate "m_session" redundantly. I'm not sure if we should validate the socket names in "kak -clear"; I guess it doesn't matter.
2024-08-12Move debug utils to debug.hh/debug.ccMaxime Coste
Lots of code includes buffer_utils.hh just for write_to_debug_buffer which pulls many unnecessary dependencies. Reorganise to reduce compile times.
2023-11-04Do not poll command sockets while shell command is runningJohannes Altmanninger
Accepter is a wrapper around a socket watcher. It always uses EventMode::Urgent, so it will be included in pselect(2) (via EventManager::handle_next_events()) even while we are waiting for a (blocking) shell command. However we will not execute the command received on this socket until after the shell command is done. This is implemented with an early return: void handle_available_input(EventMode mode) { while (not m_reader.ready() and fd_readable(sock)) m_reader.read_available(sock); if (mode != EventMode::Normal or not m_reader.ready()) return; so we read available data but don't close the socket. When using this reproducer { sleep 1 && echo 'nop' | kak -p session } & kak -n -s session -e '%sh{sleep 7}' the first "m_reader.read_available(sock);" will read "nop". Then "m_reader.ready()" is true but the socket is still readable. This means that pselect(2) will return it every time, without blocking. This means that the shell manager runs a hot loop between pselect(2) and waitpid(2). Fix this problem demoting command socket watchers from EventMode::Urgent. This means that we won't pselect(2) it when handling only urgent events. Control-C still works, I'm not sure why. Alternative fix: we could read the commands but then disable the socket. I tried this but it seems too complex. Closes #5014
2023-03-11Implement bracketed pasteJohannes Altmanninger
Text pasted into Kakoune's normal mode is interpreted as command sequence, which is probably never what the user wants. Text pasted during insert mode will be inserted fine but may trigger auto-indentation hooks which is likely not what users want. Bracketed paste is pair of escape codes sent by terminals that allow applications to distinguish between pasted text and typed text. Let's use this feature to always insert pasted text verbatim, skipping keymap lookup and the InsertChar hook. In future, we could add a dedicated Paste hook. We need to make a decision on whether to paste before or after the selection. I chose "before" because that's what I'm used to. TerminalUI::set_on_key has EventManager::instance().force_signal(0); I'm not sure if we want the same for TerminalUI::set_on_paste? I assume it doesn't matter because they are always called in tandem. Closes #2465
2022-12-06Load buffer in command line orderMaxime Coste
Pass the first buffer on the the command line explicitely to client creation. This ensure the buffer list matches the command line, which makes buffer-next/buffer-previous a bit more useful. Fixes #2705
2022-11-29Use some template magic to automatically deserialize UI messagesMaxime Coste
We always deserialize arguments in order, and we can extract argument types from the type of the pointer to method.
2022-04-07Check for buffer overflow when constructing the socket path.Tim Allen
2022-04-07Do all session name validation in session_path().Tim Allen
2022-01-18When reporting an invalid session name, report the correct name.Tim Allen
At this point, the session name has already been moved from the `session_name` parameter to the `m_session` member variable.
2021-05-01Rework session directory logicMaxime Coste
Do not use a shared kakoune/ directory for all users to avoid the complexity of having to set the sticky bit on that dir, resolve the session directoy only once by using a static variable and an immediately evaluated lambda. This fixes an annoyance whenver using `su` and having Kakoune refuse to start due to XDG_RUNTIME_DIR still being set.
2021-03-11Do not select on non-urgent fd when handling only urgent eventsMaxime Coste
This avoids 100% CPU usage when we have pending fifo input while running a shell process, as we will not end-up busy looping in pselect but not reading the available data due to being only processing urgent events.
2021-01-26Check XDG_RUNTIME_DIR owner before creating session directoryMaxime Coste
This avoids an issue when using `su` and running Kakoune which creates a session directory owned by root and prevents the user from creating more sessions.
2020-10-19Allow quiting last client with unsaved buffer in daemon modeMaxime Coste
Because the server will out-live that client's disconnection it is still ok to have modified buffers, the server will complain on `kill`. Fixes #3801
2020-05-17Fix use of unportable MSG_CMSG_CLOEXECMaxime Coste
2020-05-10Support piping data to client stdinMaxime Coste
Pass the client stdin fd to the server and open a fifo buffer from it. Fixes #3394
2020-05-02Add support for alpha channel in colorsMaxime Coste
This makes it easier to define faces that lighten/darken whatever they apply on.
2019-11-22Add support for markup in info boxesMaxime Coste
Fixes #2552
2019-08-20Fix kak -l when $XDG_RUNTIME_DIR is setJason Felice
2019-08-05Use $XDG_RUNTIME_DIRJason Felice
Falls back on old mechanism if `XDG_RUNTIME_DIR` is not set. The ability to specify a session as "<user>/<name>" was removed, since it isn't possible to compute the value of `XDG_RUNTIME_DIR` for another user, we wouldn't have access to it if we could, and it would be awkward to support this feature only when `XDG_RUNTIME_DIR` is unset. Also, `rename-session` did not work when another user's session was specified. Closes #3019
2019-07-06Fix build on FreeBSDTobias Kortkamp
file.cc:390:21: error: use of undeclared identifier 'rename'; did you mean 'devname'? if (replace and rename(temp_filename, zfilename) != 0) ^~~~~~ devname /usr/include/stdlib.h:277:7: note: 'devname' declared here char *devname(__dev_t, __mode_t); ^ file.cc:390:28: error: cannot initialize a parameter of type '__dev_t' (aka 'unsigned long') with an lvalue of type 'char [1024]' if (replace and rename(temp_filename, zfilename) != 0) ^~~~~~~~~~~~~ /usr/include/stdlib.h:277:22: note: passing argument to parameter here char *devname(__dev_t, __mode_t); ^ 2 errors generated. --- highlighters.cc:1110:13: error: use of undeclared identifier 'snprintf'; did you mean 'vswprintf'? snprintf(buffer, 16, format, std::abs(line_to_format)); ^~~~~~~~ vswprintf /usr/include/wchar.h:139:5: note: 'vswprintf' declared here int vswprintf(wchar_t * __restrict, size_t n, const wchar_t * __restrict, ^ highlighters.cc:1110:22: error: cannot initialize a parameter of type 'wchar_t *' with an lvalue of type 'char [16]' snprintf(buffer, 16, format, std::abs(line_to_format)); ^~~~~~ /usr/include/wchar.h:139:35: note: passing argument to parameter here int vswprintf(wchar_t * __restrict, size_t n, const wchar_t * __restrict, ^ 2 errors generated. --- json_ui.cc:60:13: error: use of undeclared identifier 'sprintf'; did you mean 'swprintf'? sprintf(buf, "\\u%04x", *next); ^~~~~~~ swprintf /usr/include/wchar.h:133:5: note: 'swprintf' declared here int swprintf(wchar_t * __restrict, size_t n, const wchar_t * __restrict, ^ json_ui.cc:60:21: error: cannot initialize a parameter of type 'wchar_t *' with an lvalue of type 'char [7]' sprintf(buf, "\\u%04x", *next); ^~~ /usr/include/wchar.h:133:34: note: passing argument to parameter here int swprintf(wchar_t * __restrict, size_t n, const wchar_t * __restrict, ^ json_ui.cc:74:9: error: use of undeclared identifier 'sprintf' sprintf(buffer, R"("#%02x%02x%02x")", color.r, color.g, color.b); ^ 3 errors generated. --- regex_impl.cc:1039:9: error: use of undeclared identifier 'sprintf'; did you mean 'swprintf'? sprintf(buf, " %03d ", count++); ^~~~~~~ swprintf /usr/include/wchar.h:133:5: note: 'swprintf' declared here int swprintf(wchar_t * __restrict, size_t n, const wchar_t * __restrict, ^ regex_impl.cc:1039:17: error: cannot initialize a parameter of type 'wchar_t *' with an lvalue of type 'char [20]' sprintf(buf, " %03d ", count++); ^~~ /usr/include/wchar.h:133:34: note: passing argument to parameter here int swprintf(wchar_t * __restrict, size_t n, const wchar_t * __restrict, ^ regex_impl.cc:1197:17: error: use of undeclared identifier 'puts' { if (dump) puts(dump_regex(*this).c_str()); } ^ regex_impl.cc:1208:18: note: in instantiation of member function 'Kakoune::(anonymous namespace)::TestVM<Kakoune::RegexMode::Forward>::TestVM' requested here TestVM<> vm{R"(a*b)"}; ^ regex_impl.cc:1197:17: error: use of undeclared identifier 'puts' { if (dump) puts(dump_regex(*this).c_str()); } ^ regex_impl.cc:1283:56: note: in instantiation of member function 'Kakoune::(anonymous namespace)::TestVM<5>::TestVM' requested here TestVM<RegexMode::Forward | RegexMode::Search> vm{R"(f.*a(.*o))"}; ^ regex_impl.cc:1197:17: error: use of undeclared identifier 'puts' { if (dump) puts(dump_regex(*this).c_str()); } ^ regex_impl.cc:1423:57: note: in instantiation of member function 'Kakoune::(anonymous namespace)::TestVM<6>::TestVM' requested here TestVM<RegexMode::Backward | RegexMode::Search> vm{R"(fo{1,})"}; ^ 5 errors generated. --- remote.cc:829:9: error: use of undeclared identifier 'rename'; did you mean 'devname'? if (rename(old_socket_file.c_str(), new_socket_file.c_str()) != 0) ^~~~~~ devname /usr/include/stdlib.h:277:7: note: 'devname' declared here char *devname(__dev_t, __mode_t); ^ remote.cc:829:16: error: cannot initialize a parameter of type '__dev_t' (aka 'unsigned long') with an rvalue of type 'const char *' if (rename(old_socket_file.c_str(), new_socket_file.c_str()) != 0) ^~~~~~~~~~~~~~~~~~~~~~~ /usr/include/stdlib.h:277:22: note: passing argument to parameter here char *devname(__dev_t, __mode_t); ^ 2 errors generated. --- string_utils.cc:126:20: error: use of undeclared identifier 'sprintf'; did you mean 'swprintf'? res.m_length = sprintf(res.m_data, "%i", val); ^~~~~~~ swprintf /usr/include/wchar.h:133:5: note: 'swprintf' declared here int swprintf(wchar_t * __restrict, size_t n, const wchar_t * __restrict, ^ string_utils.cc:126:28: error: cannot initialize a parameter of type 'wchar_t *' with an lvalue of type 'char [15]' res.m_length = sprintf(res.m_data, "%i", val); ^~~~~~~~~~ /usr/include/wchar.h:133:34: note: passing argument to parameter here int swprintf(wchar_t * __restrict, size_t n, const wchar_t * __restrict, ^ string_utils.cc:133:20: error: use of undeclared identifier 'sprintf'; did you mean 'swprintf'? res.m_length = sprintf(res.m_data, "%u", val); ^~~~~~~ swprintf [...]
2019-06-11Refuse to overwrite an existing session socketMaxime Coste
2019-06-04Merge remote-tracking branch 'eraserhd/minor-remote-fixes'Maxime Coste
2019-05-29Refactor message writingJason Felice
2019-05-23Do not try to send remaining data on a closed socketMaxime Coste
Fixes #2906
2019-04-22Use helper template struct in MsgReaderJason Felice
This makes reads for all types, including String, Vector, and Optional, use the same interface in MsgReader.
2019-01-24Fix missing errno includeMaxime Coste
2018-11-26Read initial remote message in Urgent EventModeMaxime Coste
Fixes #2497
2018-09-07Fix use after delete in RemoteClient FDWatcher callbackMaxime Coste
Fixes #2357
2018-08-24Use $USER if getpwuid failsMatt Peterson
2018-05-23Fix Kakoune client busy looping on SIGHUPMaxime Coste
Pure clients never quitted when they got SIGHUP after recent changes to add is_ok to UserInterface. run_client now tracks the UI state as well and quits if the UI gets killed.
2018-05-17Small code cleanupsMaxime Coste
2018-05-05Remove out of date noexcept(false) on MessageWriter destructorMaxime Coste
This made sense when the writer was trying to send the message in its destructor, but this is not the case anymore.
2018-04-29Rework the way UI can trigger a client quittingMaxime Coste
Add a UserInterface::is_ok method and return false on SIGHUP/stdin closing/socket dropping This should be cleaner and more robust than the previous SIGHUP handling code. Fixes #1594
2018-04-29Remove implicit conversion from String to DisplayAtom/DisplayLineMaxime Coste
2018-04-07Merge remote-tracking branch 'Delapouite/no-such'Maxime Coste
2018-04-07Add some safety static_asserts to remote read/write functionsMaxime Coste
2018-04-06Make error messages more consistentDelapouite
2018-04-05Fix some trailing spaces and a tab that sneaked into the code baseMaxime Coste
2018-03-25Unify code that validates identifiers in KakouneMaxime Coste
Session/Client/User modes names are now requiered to be "identifiers" they must be in [a-zA-Z0-9_-]. Option names are the same except they do not allow '-' as they need to be made available through the env vars and '-' is not supported there. Fixes #1946
2018-03-23Restore client name after converting to clientMaxime Coste
When Kakoune forked the sever to background, the newly converted to client process (the original client/server process) was not preserving its previous client name.
2017-12-15Go back to getpwuid call to get user name from user idMaxime Coste
Unfortunately, reading /etc/passwd is not enough.
2017-12-09Go back to getpwuid call on OSXMaxime Coste
Reading /etc/passwd on OSX does not give us the full list of users. Fixes #1758
2017-12-04Replace uses of getpwuid which is incompatible with static linkingMaxime Coste
Introduce a get_user_name function which parses '/etc/passwd' to find the username associated with a user id.
2017-11-06Add missing include in remote.ccMaxime Coste
strerror is defined in <string.h>
2017-11-06Do not allow rename-session to introduce '/' in session namesMaxime Coste
2017-11-04Remote: stricter validation of the session namesMaxime Coste
Creating a session will not accept any slashes in the session path, connecting to an existing session will accept at most one slash to allow for specifying the session of a different user. Fixes #1635
2017-09-07Tolerate unwritable socket when trying to send the disconnection messageMaxime Coste
Fixes #1552