@samitouri / QOSAMI-WSL / commits / 8c61f09e

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

Lightyears committed Feb 11, 2025 at 11:59 UTC 8c61f09e4d28995a3827f71e03332b5257e16418
1 file changed +8 -4
diagnostics/collect-networking-logs.ps1
+8 -4
@@ -127,6 +127,10 @@ mkdir -p $folder
127 $logProfile = "$folder/wsl_networking.wprp"
128 $networkingBashScript = "$folder/networking.sh"
129
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 +
134 # Copy/Download supporting files
135 if (Test-Path "$PSScriptRoot/wsl_networking.wprp")
136 {
@@ -158,7 +162,7 @@ if (Test-Path $wslconfig)
162 }
163
164 # 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
166
167 Collect-WindowsNetworkState "before_repro"
168
@@ -202,7 +206,7 @@ netsh wfp capture start file="$folder/wfpdiag.cab"
206 $tcpdumpProcess = $null
207 try
208 {
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
210 }
211 catch {}
212
@@ -258,7 +262,7 @@ finally
262 {
263 try
264 {
261 - wsl.exe -u root killall tcpdump
265 + wsl.exe -u $superUser killall tcpdump
266 if ($tcpdumpProcess -ne $null)
267 {
268 Wait-Process -InputObject $tcpdumpProcess -Timeout 10
@@ -272,7 +276,7 @@ finally
276 }
277
278 # 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
280
281 Collect-WindowsNetworkState "after_repro"
282