Skip to content

Commit 8c61f09

Browse files
authored
Add superuser detection in networking logs script (#12520)
* Add super user detection; a powershell approach is used * use the 'id' command * avoid stderr warning & wsl alias
1 parent ae780d1 commit 8c61f09

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

diagnostics/collect-networking-logs.ps1

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ mkdir -p $folder
127127
$logProfile = "$folder/wsl_networking.wprp"
128128
$networkingBashScript = "$folder/networking.sh"
129129

130+
# Detect the super user first.
131+
# Actually it's not definite that the super user is named "root". Instead, a user with uid=0 is what we are looking for. See #11693.
132+
$superUser = & wsl.exe -- id -nu 0 # user name of the super user.
133+
130134
# Copy/Download supporting files
131135
if (Test-Path "$PSScriptRoot/wsl_networking.wprp")
132136
{
@@ -158,7 +162,7 @@ if (Test-Path $wslconfig)
158162
}
159163

160164
# Collect Linux & Windows network state before the repro
161-
& wsl.exe -u root -e $networkingBashScript 2>&1 > $folder/linux_network_configuration_before.log
165+
& wsl.exe -u $superUser -e $networkingBashScript 2>&1 > $folder/linux_network_configuration_before.log
162166

163167
Collect-WindowsNetworkState "before_repro"
164168

@@ -202,7 +206,7 @@ netsh wfp capture start file="$folder/wfpdiag.cab"
202206
$tcpdumpProcess = $null
203207
try
204208
{
205-
$tcpdumpProcess = Start-Process wsl.exe -ArgumentList "-u root tcpdump -n -i any -e -vvv > $folder/tcpdump.log" -PassThru
209+
$tcpdumpProcess = Start-Process wsl.exe -ArgumentList "-u $superUser tcpdump -n -i any -e -vvv > $folder/tcpdump.log" -PassThru
206210
}
207211
catch {}
208212

@@ -258,7 +262,7 @@ finally
258262
{
259263
try
260264
{
261-
wsl.exe -u root killall tcpdump
265+
wsl.exe -u $superUser killall tcpdump
262266
if ($tcpdumpProcess -ne $null)
263267
{
264268
Wait-Process -InputObject $tcpdumpProcess -Timeout 10
@@ -272,7 +276,7 @@ finally
272276
}
273277

274278
# Collect Linux & Windows network state after the repro
275-
& wsl.exe -u root -e $networkingBashScript 2>&1 > $folder/linux_network_configuration_after.log
279+
& wsl.exe -u $superUser -e $networkingBashScript 2>&1 > $folder/linux_network_configuration_after.log
276280

277281
Collect-WindowsNetworkState "after_repro"
278282

0 commit comments

Comments
 (0)