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

running vscode with gksudo or sudo permission #3068

Closed
ayanb1991 opened this issue Feb 17, 2016 · 13 comments
Closed

running vscode with gksudo or sudo permission #3068

ayanb1991 opened this issue Feb 17, 2016 · 13 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug linux Issues with VS Code on Linux verified Verification succeeded
Milestone

Comments

@ayanb1991
Copy link

visual studio not starting up when running it with gksudo or sudo permission on my Arch Linux. The window just got hanged every time. Starting normally works.

Can not save a file whose owner is root, Gives EACCESS_PERMISSION error. In case of other editors, saving the same file invoking gksudo automatically.

@Tyriar
Copy link
Member

Tyriar commented Feb 17, 2016

Repros on Ubuntu. Setup:

touch test
sudo chown root test
sudo ~/tools/VSCode-linux-x64/Code .

hang

Output:

~/temp
❯ sudo ~/tools/VSCode-linux-x64/Code .
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
[VS Code]: detected unresponsive

Process stats:

❯ ps aux | grep VSCode
root      2485  0.0  0.0  58860  3976 pts/0    S+   07:03   0:00 sudo /home/daniel/tools/VSCode-linux-x64/Code .
root      2486 15.6  0.6 1353480 113552 pts/0  Sl+  07:03   0:22 /home/daniel/tools/VSCode-linux-x64/Code .
root      2488  0.0  0.1 320284 28052 pts/0    S+   07:03   0:00 /home/daniel/tools/VSCode-linux-x64/Code --type=zygote --no-sandbox
root      2504  0.5  0.6 459360 105128 pts/0   Sl+  07:03   0:00 /home/daniel/tools/VSCode-linux-x64/Code --type=gpu-process --channel=2486.0.602618759 --no-sandbox --supports-dual-gpus=false --gpu-driver-bug-workarounds=2,27,30,45,55,57 --disable-accelerated-video-decode --gpu-vendor-id=0x10de --gpu-device-id=0x1187 --gpu-driver-vendor=NVIDIA --gpu-driver-version=352.63 --v8-natives-passed-by-fd --v8-snapshot-passed-by-fd
root      2550  0.1  0.2 916508 46500 pts/0    Sl+  07:03   0:00 /home/daniel/tools/VSCode-linux-x64/Code /home/daniel/tools/VSCode-linux-x64/resources/app/out/bootstrap --type=SharedProcess
root      2562  105  2.9 2609236 485880 pts/0  Rl+  07:03   2:32 /home/daniel/tools/VSCode-linux-x64/Code --type=renderer --no-sandbox --lang=en-US --node-integration=true --enable-delegated-renderer --num-raster-threads=2 --gpu-rasterization-msaa-sample-count=8 --content-image-texture-target=3553 --video-image-texture-target=3553 --disable-accelerated-video-decode --channel=2486.1.575172126 --v8-natives-passed-by-fd --v8-snapshot-passed-by-fd
root      2586 58.2  0.5 959572 93820 pts/0    Sl+  07:03   1:23 /home/daniel/tools/VSCode-linux-x64/Code /home/daniel/tools/VSCode-linux-x64/resources/app/out/bootstrap --type=pluginHost
root      2587  0.1  0.3 912380 49384 pts/0    Sl+  07:03   0:00 /home/daniel/tools/VSCode-linux-x64/Code /home/daniel/tools/VSCode-linux-x64/resources/app/out/bootstrap --type=watcherService
daniel    2824  0.0  0.0  13692  2220 pts/11   R+   07:06   0:00 grep --color=auto VSCode

@Tyriar
Copy link
Member

Tyriar commented Feb 18, 2016

@Tyriar Tyriar added bug Issue identified by VS Code Team member as probable bug linux Issues with VS Code on Linux labels Feb 18, 2016
@egamma egamma added this to the April 2016 milestone Apr 4, 2016
@egamma egamma mentioned this issue Apr 4, 2016
68 tasks
@Tyriar
Copy link
Member

Tyriar commented Apr 6, 2016

A system error occured (EACCES: permission denied, mkdir '/home/daniel/.config/Code/User/snippets'): Error: EACCES: permission denied, mkdir '/home/daniel/.config/Code/User/snippets'
    at Error (native)
    at Object.fs.mkdirSync (fs.js:799:18)
    at new SnippetsTracker (file:////home/daniel/dev/Microsoft/vscode/out/vs/workbench/parts/snippets/electron-browser/snippetsTracker.js:25:20)
    at create (file:////home/daniel/dev/Microsoft/vscode/out/vs/base/common/types.js:150:14)
    at file:////home/daniel/dev/Microsoft/vscode/out/vs/platform/instantiation/common/instantiationService.js:193:45
    at AccessLock.runUnlocked (file:////home/daniel/dev/Microsoft/vscode/out/vs/platform/instantiation/common/instantiationService.js:31:24)
    at ServicesMap.createInstance (file:////home/daniel/dev/Microsoft/vscode/out/vs/platform/instantiation/common/instantiationService.js:192:31)
    at InstantiationService.createInstance (file:////home/daniel/dev/Microsoft/vscode/out/vs/platform/instantiation/common/instantiationService.js:243:42)
    at WorkbenchContributionsRegistry.BaseRegistry.instantiate (file:////home/daniel/dev/Microsoft/vscode/out/vs/platform/platform.js:42:54)
    at WorkbenchContributionsRegistry.BaseRegistry.setInstantiationService (file:////home/daniel/dev/Microsoft/vscode/out/vs/platform/platform.js:38:22)Workbench.startup @ //home/daniel/dev/Microsoft/vscode/out/vs/workbench/browser/workbench.js:145
index.html:26 [uncaught exception]: Error: EACCES: permission denied, mkdir '/home/daniel/.config/Code/User/snippets'onError @ index.html:26
index.html:29 Error: EACCES: permission denied, mkdir '/home/daniel/.config/Code/User/snippets'
    at Error (native)
    at Object.fs.mkdirSync (fs.js:799:18)
    at new SnippetsTracker (file:////home/daniel/dev/Microsoft/vscode/out/vs/workbench/parts/snippets/electron-browser/snippetsTracker.js:25:20)
    at create (file:////home/daniel/dev/Microsoft/vscode/out/vs/base/common/types.js:150:14)
    at file:////home/daniel/dev/Microsoft/vscode/out/vs/platform/instantiation/common/instantiationService.js:193:45
    at AccessLock.runUnlocked (file:////home/daniel/dev/Microsoft/vscode/out/vs/platform/instantiation/common/instantiationService.js:31:24)
    at ServicesMap.createInstance (file:////home/daniel/dev/Microsoft/vscode/out/vs/platform/instantiation/common/instantiationService.js:192:31)
    at InstantiationService.createInstance (file:////home/daniel/dev/Microsoft/vscode/out/vs/platform/instantiation/common/instantiationService.js:243:42)
    at WorkbenchContributionsRegistry.BaseRegistry.instantiate (file:////home/daniel/dev/Microsoft/vscode/out/vs/platform/platform.js:42:54)
    at WorkbenchContributionsRegistry.BaseRegistry.setInstantiationService (file:////home/daniel/dev/Microsoft/vscode/out/vs/platform/platform.js:38:22)

@Tyriar
Copy link
Member

Tyriar commented Apr 6, 2016

The EACCES errors can be fixed by tweaking permissions since .config is normally only 700: chmod 775 .config/

Once that's passed, vscode load and, gives a warning about how you shouldn't run as root. Only files owned by root can be modified in this instance of vscode.

@Tyriar
Copy link
Member

Tyriar commented Apr 6, 2016

When gksudo google-chrome is run this is presented:

image

@Tyriar
Copy link
Member

Tyriar commented Apr 6, 2016

This works with Chrome:

sudo mkdir /home/data/chrome-data
gksudo "google-chrome --user-data-dir=/home/daniel/chrome-data"

@Tyriar
Copy link
Member

Tyriar commented Apr 6, 2016

The whole thing is pretty messy after understanding it, it would be better to request sudo acces when a file is saved. Something like this might work? https://www.npmjs.com/package/electron-sudo

@Tyriar
Copy link
Member

Tyriar commented Apr 6, 2016

I've managed to get it working fairly nicely being run with sudo using a custom user data dir, however it hangs unless run as the normal user at least once.

This is how it I can get around it currently:

# First launch, code will create the data dir then hang with no errors in console
sudo ../VSCode-linux-x64/code-oss --user-data-dir=/home/daniel/data-dir .
# Give daniel access to ~/data-dir
sudo chmod -R 777 /home/daniel/data-dir/
# Launches fine as regular user now
../VSCode-linux-x64/code-oss --user-data-dir=/home/daniel/data-dir .
# Remove daniel access
sudo chmod -R 700 /home/daniel/data-dir/
# Launches fine as root user now
sudo ../VSCode-linux-x64/code-oss --user-data-dir=/home/daniel/data-dir .

@Tyriar
Copy link
Member

Tyriar commented Apr 6, 2016

All files seem to be created correctly.

$ sudo tree ~/data-dir/
/home/daniel/data-dir/
├── DevTools Extensions
├── GPUCache
│   ├── data_0
│   ├── data_1
│   ├── data_2
│   ├── data_3
│   └── index
├── Local Storage
│   ├── file__0.localstorage
│   └── file__0.localstorage-journal
├── storage.json
└── User
    └── snippets

The welcome page never comes up though, and the menu bar hangs when I try to open the license.

@Tyriar
Copy link
Member

Tyriar commented Apr 6, 2016

@Tyriar
Copy link
Member

Tyriar commented Apr 6, 2016

The issue is with xdg-open, notice how the non-sudo call exits with 0 but the sudo call errors and hangs.

~
❯ xdg-open http://www.google.com

~
❯ Created new window in existing browser session.
echo $?
0

~
❯ sudo xdg-open http://www.google.com
[0406/161820:ERROR:nss_util.cc(98)] Failed to create /home/daniel/.pki/nssdb directory.

@Tyriar
Copy link
Member

Tyriar commented Apr 6, 2016

http://linux.die.net/man/1/xdg-open

xdg-open is for use inside a desktop session only. It is not recommended to use xdg-open as root.

Tyriar added a commit that referenced this issue Apr 7, 2016
This commit adds the --user-data-dir argument which allows a custom data dir
for Chromium's user data. This is useful when running as root on Linux since
the root user does not have read or write permissions for the ~/.config/Code
dir.

Part of #3068
@Tyriar Tyriar closed this as completed in ad7e861 Apr 7, 2016
Tyriar added a commit that referenced this issue Apr 8, 2016
Ideally this is a temporary fix for gettingStarted and can be removed once the
freeze is fixed in electron.

Fixes #3068
Fixes #5067
@aeschli aeschli added the verified Verification succeeded label May 2, 2016
@ricardomaleixo
Copy link

this is the solution to me.

access terminal with root and ...

code --user-data-dir="./vscode-root"

ubuntu 16.04

flw.vlw

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug linux Issues with VS Code on Linux verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

5 participants