mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-23 06:05:39 +08:00
drop check for old running fishd instances
Closes #3669.
Reverts commit d1a56139e1
.
This commit is contained in:
parent
12ea04580a
commit
5eaccf91e2
|
@ -11,6 +11,7 @@
|
|||
- `command` now accepts "-q"/"--quiet" for `command -sq $command` (#3591).
|
||||
- Selection mode (used with "begin-selection") no longer selects a character the cursor does not move over (#3684).
|
||||
- The `help` command now reads the $fish_help_browser variable (#3131).
|
||||
- fish no longer prints a warning when it identifies a running instance of an old version (2.1.0 and earlier). Changes to universal variables may not propagate between these old versions and 2.5b1.
|
||||
|
||||
## Notable fixes and improvements
|
||||
- `complete` accepts empty strings as descriptions (#3557).
|
||||
|
|
80
src/fish.cpp
80
src/fish.cpp
|
@ -22,14 +22,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|||
#include <getopt.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#include <pwd.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h> // IWYU pragma: keep
|
||||
#include <sys/stat.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
#include <memory>
|
||||
|
@ -199,82 +196,6 @@ static void source_config_in_directory(const wcstring &dir) {
|
|||
parser.set_is_within_fish_initialization(false);
|
||||
}
|
||||
|
||||
static int try_connect_socket(std::string &name) {
|
||||
int s, r, ret = -1;
|
||||
|
||||
/// Connect to a DGRAM socket rather than the expected STREAM. This avoids any notification to a
|
||||
/// remote socket that we have connected, preventing any surprising behaviour. If the connection
|
||||
/// fails with EPROTOTYPE, the connection is probably a STREAM; if it succeeds or fails any
|
||||
/// other way, there is no cause for alarm. With thanks to Andrew Lutomirski <github.com/amluto>
|
||||
if ((s = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) {
|
||||
wperror(L"socket");
|
||||
return -1;
|
||||
}
|
||||
|
||||
debug(3, L"Connect to socket %s at fd %d", name.c_str(), s);
|
||||
|
||||
struct sockaddr_un local = {};
|
||||
local.sun_family = AF_UNIX;
|
||||
strncpy(local.sun_path, name.c_str(), (sizeof local.sun_path) - 1);
|
||||
|
||||
r = connect(s, (struct sockaddr *)&local, sizeof local);
|
||||
|
||||
if (r == -1 && errno == EPROTOTYPE) {
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
close(s);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// Check for a running fishd from old versions and warn about not being able to share variables.
|
||||
/// https://github.com/fish-shell/fish-shell/issues/1730
|
||||
static void check_running_fishd() {
|
||||
// There are two paths to check:
|
||||
// $FISHD_SOCKET_DIR/fishd.socket.$USER or /tmp/fishd.socket.$USER
|
||||
// - referred to as the "old socket"
|
||||
// $XDG_RUNTIME_DIR/fishd.socket or /tmp/fish.$USER/fishd.socket
|
||||
// - referred to as the "new socket"
|
||||
// All existing versions of fish attempt to create the old socket, but
|
||||
// failure in newer versions is not treated as critical, so both need
|
||||
// to be checked.
|
||||
const char *uname = getenv("USER");
|
||||
if (uname == NULL) {
|
||||
const struct passwd *pw = getpwuid(getuid());
|
||||
uname = pw->pw_name;
|
||||
}
|
||||
|
||||
const char *dir_old_socket = getenv("FISHD_SOCKET_DIR");
|
||||
std::string path_old_socket;
|
||||
|
||||
if (dir_old_socket == NULL) {
|
||||
path_old_socket = "/tmp/";
|
||||
} else {
|
||||
path_old_socket.append(dir_old_socket);
|
||||
}
|
||||
|
||||
path_old_socket.append("fishd.socket.");
|
||||
path_old_socket.append(uname);
|
||||
|
||||
const char *dir_new_socket = getenv("XDG_RUNTIME_DIR");
|
||||
std::string path_new_socket;
|
||||
if (dir_new_socket == NULL) {
|
||||
path_new_socket = "/tmp/fish.";
|
||||
path_new_socket.append(uname);
|
||||
path_new_socket.push_back('/');
|
||||
} else {
|
||||
path_new_socket.append(dir_new_socket);
|
||||
}
|
||||
|
||||
path_new_socket.append("fishd.socket");
|
||||
|
||||
if (try_connect_socket(path_old_socket) == 0 || try_connect_socket(path_new_socket) == 0) {
|
||||
debug(1, _(L"Old versions of fish appear to be running. You will not be able to share "
|
||||
L"variable values between old and new fish sessions. For best results, restart "
|
||||
L"all running instances of fish."));
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse init files. exec_path is the path of fish executable as determined by argv[0].
|
||||
static int read_init(const struct config_paths_t &paths) {
|
||||
source_config_in_directory(paths.data);
|
||||
|
@ -487,7 +408,6 @@ int main(int argc, char **argv) {
|
|||
reader_exit(0, 0);
|
||||
} else if (my_optind == argc) {
|
||||
// Interactive mode
|
||||
check_running_fishd();
|
||||
res = reader_read(STDIN_FILENO, empty_ios);
|
||||
} else {
|
||||
char *file = *(argv + (my_optind++));
|
||||
|
|
Loading…
Reference in New Issue
Block a user