Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XDG_SESSION_ID and XDG_SESSION_TYPE environment in debugConfig.environment or console's environment are overrided by getConfigureEnvironment #3806

Open
upcliujie opened this issue Jun 1, 2024 · 7 comments
Assignees
Labels
bug a bug in the product Feature: debug/launch
Milestone

Comments

@upcliujie
Copy link
Contributor

Brief Issue Summary

Problem 1:
The workspace vcode settings :
图片

The code to get XDG_SESSION_ID and XDG_SESSION_TYPE environment with c++ :
图片
We can't get the XDG_SESSION_ID and XDG_SESSION_TYPE in debugConfig.environment.

Problem 2:
Delete the worksapce vscode settings. Use tmux connect to another tty.
Run the code in Problem 1:
图片

We can't get the same XDG_SESSION_ID and XDG_SESSION_TYPE environment value with tmux

CMake Tools Diagnostics

No response

Debug Log

No response

Additional Information

No response

@github-actions github-actions bot added the triage label Jun 1, 2024
@v-frankwang v-frankwang added more info needed More info is needed from the community for us to properly triage and investigate. and removed triage labels Jun 5, 2024
@v-frankwang
Copy link
Collaborator

@upcliujie I tried the problem you described on my machine, but I was not able to reproduce the problem you described, can you give me some advice?

image

@upcliujie
Copy link
Contributor Author

upcliujie commented Jun 11, 2024

@v-frankwang The terminal on win don't set XDG_SESSION_* to env so don't have this problem.

Using a win PC to connect a linux PC by ssh-remote can reproduce this problem

@upcliujie
Copy link
Contributor Author

upcliujie commented Jun 11, 2024

@v-frankwang This is a relevant code from the cmakeProject.ts file

    /**
     * Both debugTarget and launchTarget called this funciton, so it's refactored out
     * Array.concat's performance would not beat the Dict.merge a lot.
     * This is also the point to fixing the issue #1987
     */
    async getTargetLaunchEnvironment(drv: CMakeDriver | null, debugEnv?: DebuggerEnvironmentVariable[]): Promise<Environment> {
        const env = util.fromDebuggerEnvironmentVars(debugEnv);

        // Add environment variables from ConfigureEnvironment.
        const configureEnv = await drv?.getConfigureEnvironment();

        if ((drv?.useCMakePresets ?? false) && (checkConfigureOverridesPresent(this.workspaceContext.config) ?? false)) {
            log.info(localize('launch.with.overrides', `NOTE: You are launching a target and there are some environment overrides being applied from your VS Code settings.`));
        }

        return EnvironmentUtils.merge([env, configureEnv]);
    }

XDF_SESSION_* is set in ConfigureEnvironment on linux so it will overwrite the environment we set in debugConfig.environment.

@v-frankwang
Copy link
Collaborator

@upcliujie Thank you very much for your reply, I have retried the problem as you have given advice, does this reproduce the problem you have described?

image

@upcliujie
Copy link
Contributor Author

@v-frankwang Yes,it's the problem I described.

@v-frankwang
Copy link
Collaborator

@gcampbell-msft I reproduced the issue based on the user's prompts and here are the steps I took to reproduce it:

ENV:
VS code version: 1.90.0
CMake Extension version: 1.18.42
Remote-ssh: v0.112.0

  1. Create a folder named Test on the remote linux machine.
  2. Using the Remote-ssh extension to connect to Linux machines in vscode.
  3. Open the folder named Test.
  4. Add the CMakeLists.txt file and add the following code:
cmake_minimum_required(VERSION 3.8)
project(test)
add_executable(test main.cpp) 
  1. Add the main.cpp file and add the following code:
#include <iostream>
#include <cstdlib>

int main() {
    char *xdgSessionId = getenv("XXDG_SESSION_ID");
    if (xdgSessionId != nullptr) {
        std::cout << "XXDG_SESSION_ID: " << xdgSessionId << std::endl;
    } else {
        std::cout << "XXDG_SESSION_ID not set" << std::endl;
    }
    char *xdgSessionType = getenv("XDG_SESSION_TYPE");
    if (xdgSessionType != nullptr) {
        std::cout << "XDG_SESSION_TYPE: " << xdgSessionType << std::endl;
    } else {
        std::cout << "XDG_SESSION_TYPE not set" << std::endl;
    }

    return 0;
}
  1. Search for Cmake:debug Config in settings, then click Edit in settings.json and add the following code:
{
    "cmake.debugConfig": {
        "environment": [
            {
                "name": "XXDG_SESSION_ID",
                "value": "2"
            },
            {
                "name": "XDG_SESSION_TYPE",
                "value": "wayland"
            }
        ]
    }
}
  1. Click on "Launch the selected target in the terminal window" in the navigation bar below.

Actual result:
image

@v-frankwang
Copy link
Collaborator

@upcliujie @gcampbell-msft If I manually set the value of XDG_SESSION_TYPE to "wayland" in the terminal using the command: export XDG_SESSION_TYPE=wayland, and then click the "Launch the selected target in the terminal window" in the navigation bar below, the correct result is displayed.
image

@v-frankwang v-frankwang added bug a bug in the product and removed more info needed More info is needed from the community for us to properly triage and investigate. labels Jun 19, 2024
@gcampbell-msft gcampbell-msft added this to the 1.19 milestone Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug a bug in the product Feature: debug/launch
Projects
Status: Ready to be Assigned
Development

No branches or pull requests

4 participants