Skip to content

Reading iOS logs requires sudo access: "log: Must be admin to run 'stream' command" #18409

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

Closed
ghost opened this issue Jun 12, 2018 · 44 comments · Fixed by #54154
Closed

Reading iOS logs requires sudo access: "log: Must be admin to run 'stream' command" #18409

ghost opened this issue Jun 12, 2018 · 44 comments · Fixed by #54154
Assignees
Labels
c: regression It was better in the past than it is now platform-ios iOS applications specifically tool Affects the "flutter" command-line tool. See also t: labels.

Comments

@ghost
Copy link

ghost commented Jun 12, 2018

@csterritt commented on Jun 12, 2018, 12:07 AM UTC:

Steps to Reproduce

Ran flutter create first_try, cd'd into that directory. flutter run works, comes up fine in the iOS emulator. I can run in IntelliJ with the "Run" command (green triangle), but no hot-reload.

If I run with "Debug" command (green bug), I get the empty white screen on the iOS emulator, and the following output:

Launching lib/main.dart on iPhone X in debug mode...
log: Must be admin to run 'stream' command
Script started, output file is /dev/null

Script done, output file is /dev/null
Starting Xcode build...
Xcode build done.

Version info

$ flutter doctor -v
[✓] Flutter (Channel beta, v0.4.4, on Mac OS X 10.13.5 17F77, locale en-US)
• Flutter version 0.4.4 at /Volumes/Second/Chris/hacks/flutter/flutter
• Framework revision f9bb4289e9 (4 weeks ago), 2018-05-11 21:44:54 -0700
• Engine revision 06afdfe54e
• Dart version 2.0.0-dev.54.0.flutter-46ab040e58

[!] Android toolchain - develop for Android devices (Android SDK 28.0.0)
• Android SDK at /Users/chris/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.0
• Java binary at: /Users/chris/hacks/flutter/jdk-10.0.1.jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 10.0.1+10)
✗ Android license status unknown.

[✓] iOS toolchain - develop for iOS devices (Xcode 9.4)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 9.4, Build version 9F1027a
• ios-deploy 1.9.2
• CocoaPods version 1.5.3

[✗] Android Studio (not installed)
• Android Studio not found; download from [https://developer.android.com/studio/index.html](https://developer.android.com/studio/index.html)
(or visit [https://flutter.io/setup/#android-setup](https://flutter.io/setup/#android-setup) for detailed instructions).

[✓] IntelliJ IDEA Community Edition (version 2018.1.4)
• IntelliJ at /Users/chris/Applications/IntelliJ IDEA CE.app
• Flutter plugin version 25.0.2
• Dart plugin version 181.4892.1

[!] VS Code (version 1.24.0)
• VS Code at /Users/chris/Applications/Visual Studio Code.app/Contents
• Dart Code extension not installed; install from
[https://marketplace.visualstudio.com/items?itemName=Dart-Code.dart-code](https://marketplace.visualstudio.com/items?itemName=Dart-Code.dart-code)

[✓] Connected devices (1 available)
• iPhone X • D34D5096-B3F9-4930-822B-48D3BD71B83D • ios • iOS 11.4 (simulator)

! Doctor found issues in 3 categories.

This issue was moved by devoncarew from flutter/flutter-intellij/issues/2360.

@ghost
Copy link
Author

ghost commented Jun 12, 2018

@devoncarew commented on Jun 12, 2018, 12:34 AM UTC:

@xster, @cbracken, re: the:

log: Must be admin to run 'stream' command

Do you have a sense for where this is coming from?

@ghost
Copy link
Author

ghost commented Jun 12, 2018

@xster commented on Jun 12, 2018, 12:38 AM UTC:

More interesting was for me:
Script started, output file is but that string (or parts of it) don't appear in our repo. Was this on a custom fork branch?

@ghost
Copy link
Author

ghost commented Jun 12, 2018

@csterritt commented on Jun 12, 2018, 1:05 AM UTC:

@xster Not sure if this is useful to your question, but I just downloaded the Mac installer from flutter.io, I didn't build from github or anything like that.

Thanks for the quick responses!

@ghost
Copy link
Author

ghost commented Jun 12, 2018

@devoncarew commented on Jun 12, 2018, 5:57 PM UTC:

I suspect this is coming from a native tool that we're invoking? In anticipation of that, I'm going to route this to the flutter/flutter repo as a flutter_tools issue.

@devoncarew devoncarew added tool Affects the "flutter" command-line tool. See also t: labels. platform-ios iOS applications specifically labels Jun 12, 2018
@jaxondu
Copy link

jaxondu commented Jul 19, 2018

I encounter this same message when running on a friend's Mac where the machine user account I signed in has no admin access. On terminal flutter create myapp, cd to myapp and flutter run. The basic template app can run fine on iOS simulator. Next I try to use Visual Studio Code. No luck only blank white screen on the Simulator.

@zoechi
Copy link
Contributor

zoechi commented Jul 24, 2018

The section from the flutter run -v output

[  +42 ms] Building Runner.app for 114D27CF-C563-4427-AA18-64034F48DE28.
[   +8 ms] /Users/zoechi/flutter/flutter/bin/cache/dart-sdk/bin/dart /Users/zoechi/flutter/flutter/bin/cache/artifacts/engine/darwin-x64/frontend_server.dart.snapshot --sdk-root /Users/zoechi/flutter/flutter/bin/cache/artifacts/engine/common/flutter_patched_sdk/ --strong --target=flutter --no-link-platform --incremental --packages /Users/zoechi/dart/playground/flutter/flutter_19692_tabbar_gridview_2/.packages --output-dill build/app.dill --depfile build/snapshot_blob.bin.d /Users/zoechi/dart/playground/flutter/flutter_19692_tabbar_gridview_2/lib/main.dart
[   +1 ms] script /dev/null /usr/bin/log stream --style syslog --predicate processImagePath CONTAINS "114D27CF-C563-4427-AA18-64034F48DE28"
[  +80 ms] [DEVICE LOG] log: Must be admin to run 'stream' command
[  +11 ms] [DEVICE LOG] Script started, output file is /dev/null
[        ] [DEVICE LOG] 
[        ] [DEVICE LOG] Script done, output file is /dev/null
[        ] log: Must be admin to run 'stream' command
[        ] Script started, output file is /dev/null
[        ] Script done, output file is /dev/null
[+4484 ms] Building bundle
[        ] Writing asset files to build/flutter_assets

@zoechi
Copy link
Contributor

zoechi commented Jul 24, 2018

No luck only blank white screen on the Simulator.

I opened XCode and got asked if I want to install additional components.
After they were installed I could flutter run from terminal, but from IntelliJ it still only showed a white screen

@zoechi zoechi added this to the Stretch Goals milestone Jul 24, 2018
@eugenious
Copy link

I'm getting the same error too, in VS Code. I am running flutter from a non-admin account, using High Sierra 10.13.6.

In VS Code:

  • Debug | Start Debugging will show the flutter application in the iOS simulator with a blank white screen
  • Debug | Start Without Debugging will launch the application properly.

I feel this issue should be raised higher in priority. I encountered it in my first hour of using flutter, I think there's an issues label for that? It blocks the hot reloading functionality for me.

A more accurate title for this issue might be: "Hot reloading broken for iOS simulator when user is not admin".

The exact error is easy to reproduce in terminal:

> /usr/bin/log stream
log: Must be admin to run 'stream' command

If I were to venture a guess at what the problem is, it seems that the "stream" feature of the /usr/bin/log utility can only be used by an admin user. This might be a recent change in MacOS.

I'm not sure how this feature is used by flutter, it's not clear why the log output is being dumped to /dev/null.

At any rate, the current workaround (your developer account needs to be an admin account) is clearly undesirable.

@AskYous
Copy link

AskYous commented Aug 21, 2018

I had this problem too. I solved it (somehow) by adding the following to my ~/.bash_profile:

# Flutter
export PATH=~/flutter/bin:$PATH

Then running flutter run in a terminal window (as opposed to Android Studio). Mines works now. Idk why.

@DanTup
Copy link
Contributor

DanTup commented Aug 22, 2018

The issues seems to be in this code:

/// Launches the device log reader process on the host.
Future<Process> launchDeviceLogTool(IOSSimulator device) async {
// Versions of iOS prior to iOS 11 log to the simulator syslog file.
if (await device.sdkMajorVersion < 11)
return runCommand(<String>['tail', '-n', '0', '-F', device.logFilePath]);
// For iOS 11 and above, use /usr/bin/log to tail process logs.
// Run in interactive mode (via script), otherwise /usr/bin/log buffers in 4k chunks. (radar: 34420207)
return runCommand(<String>[
'script', '/dev/null', '/usr/bin/log', 'stream', '--style', 'syslog', '--predicate', 'processImagePath CONTAINS "${device.id}"',
]);
}

For iOS >= 11 we call /usr/bin/log stream which doesn't work for non-admins. Trying to find answers, I found lots of people complaining that Xcode is broken after this upgrade for non-Admins too (and the fixes all seem hit and miss).

(cc @cbracken - it was a while ago, but you worked on this in #12079 - do you know if there might be any alternatives?)

@cbracken
Copy link
Member

cbracken commented Aug 23, 2018

@DanTup do we know if the /usr/bin/log permission requirements changed in a recent macOS update, or has this been broken since I landed those updates? (I'm guessing the latter?)

Flutter uses syslog (backed by os_log under the hood) for logging, and the mechanism for this changed in iOS 11, which meant we lost the ability to simply tail them out the way we had done in iOS 10 and earlier.

One alternative to this approach would be for us to adopt a custom logging mechanism of our own design and stream those logs over a port exposed in the engine, which we'd then port-forward to the host, similar to what we do with observatory.

@DanTup
Copy link
Contributor

DanTup commented Aug 23, 2018

do we know if the /usr/bin/log permission requirements changed in a recent macOS update, or has this been broken since I landed those updates? (I'm guessing the latter?)

Afraid I don't know (and couldn't find an answer to that when I looked). Both my MacBook's are up-to-date and that's the behaviour I see (I'm a Mac/Xcode newbie, I was looking at this just because it was raised against Dart Code).

One alternative to this approach would be for us to adopt a custom logging mechanism of our own design and stream those logs over a port exposed in the engine, which we'd then port-forward to the host, similar to what we do with observatory.

Sounds like it should work (though I don't know enough about this to have a strong opinion), though I'm wondering Xcode is doing since this update for non-Admin users (presumably it's still showing the user logs)?

@Grenadingue
Copy link

Grenadingue commented Sep 17, 2018

This issue was blocking me to retrieve usable logs for a CI setup

Dirty fix:

sudo su
mkdir -p /foo/bin
cp /usr/bin/log /foo/bin
chmod u+s /foo/bin/log
LANG_SAVE=$LANG
export LANG=C
sed -i -e 's|/usr/bin/log|/foo/bin/log|g' /opt/flutter/bin/cache/flutter_tools.snapshot
export LANG=$LANG_SAVE

Edit: 2019/07:

  • I must admit that I didn't tested the sed part. The idea I wanted to represent was to replace /usr/bin/log by /foo/bin/log in flutter_tools.snapshot. See keng42's answer later in the thread
  • Removed trollface emojji

@bosslee
Copy link

bosslee commented Dec 5, 2018

Hi
Wanted to share that this is also happening to 1.0.0. Getting the same error of “hot reload not working on vs code” and the log message of “must be admin to run stream command”

Like to ask if anyone managed to slove this? Thanks

@DanTup
Copy link
Contributor

DanTup commented Dec 6, 2018

@dnfield Do you know if #23164 will help with this?

@dnfield
Copy link
Contributor

dnfield commented Dec 6, 2018

Yes, it should

@devoncarew
Copy link
Member

Chiming in to say that I hit this issue myself. This was on a macbook where the account I was signed in as was not the primary account. Here's the verbose logs:

[  +31 ms] Building Runner.app for D28AB018-CDFE-40E9-8F62-052C23EB4A99.
[  +32 ms] executing: script /dev/null /usr/bin/log stream --style syslog --predicate processImagePath CONTAINS "D28AB018-CDFE-40E9-8F62-052C23EB4A99"
[ +110 ms] [DEVICE LOG] log: Must be admin to run 'stream' command
[  +13 ms] [DEVICE LOG] Script started, output file is /dev/null
[        ] [DEVICE LOG] 
[        ] [DEVICE LOG] Script done, output file is /dev/null
[   +1 ms] log: Must be admin to run 'stream' command
[        ] Script started, output file is /dev/null
[        ] Script done, output file is /dev/null

The app did launch with this issue, but we were never able to establish a connection to it, so we couldn't do thing like issue hot reload calls.

@DanTup
Copy link
Contributor

DanTup commented Dec 12, 2018

The app did launch with this issue, but we were never able to establish a connection to it, so we couldn't do thing like issue hot reload calls.

I guess you launched in a "non debug" mode, so the VM wasn't paused at startup? (in VS Code, the default is to launch with the debugger, so I think this ends up with the user looking at a white screen because the VM is paused).

@brutalimp
Copy link

Anyone give a solution to this issue?

@zoechi
Copy link
Contributor

zoechi commented Jan 17, 2019

My workaround

Change

return runCommand(<String>[
'script', '/dev/null', '/usr/bin/log', 'stream', '--style', 'syslog', '--predicate', 'processImagePath CONTAINS "${device.id}"',
]);

to

  return runCommand(<String>[
    'script', '/dev/null', 'sudo', '/usr/bin/log', 'stream', '--style', 'syslog', '--predicate', 'processImagePath CONTAINS "${device.id}"',
  ]);

(add 'sudo',)

And add this rule to /etc/sudoers

myuser          ALL = (root) NOPASSWD: /usr/bin/log

and delete flutter/bin/cache so it gets rebuilt

@ParryGao
Copy link

Anyone give a solution to this issue?

@Chojecki
Copy link

@kentny ReactNative debbuger is an external tool, so I guess you havent installed it if you are not sure. Open a task manager on your device and check if its running

@ricardobrg
Copy link

If you don't have root access, you can debug the app in Xcode. At least you can check the debug messages and rebuild the app to check the changes, since hot reload won't work.

@zhihuilong
Copy link

Same issue. Any solutions?

@fuerst
Copy link

fuerst commented Jul 4, 2019

Workaround from @zoechi above works - thanks!

@keng42
Copy link

keng42 commented Jul 5, 2019

thanks to @zoechi and @Grenadingue
I got some new error with sed -i -e 's|/usr/bin/log|/foo/bin/log|g' ...
and I don't want to edit /etc/sudoers,
so this is my workround

0. my environment

[✓] Flutter (Channel beta, v1.7.8+hotfix.2, on Mac OS X 10.14.5 18F132, locale en-CN) 
[✓] Xcode - develop for iOS and macOS (Xcode 10.2.1)
[✓] VS Code (version 1.36.0)

1. fix log: Must be admin to run 'stream' command

make a copy of /usr/bin/log with an admin account,
then you can run /foo/bin/log stream with a standard account.

sudo mkdir -p /foo/bin
sudo cp /usr/bin/log /foo/bin
sudo chmod u+s /foo/bin/log

2. rebuilt flutter tool

Change

return runCommand(<String>[
'script', '/dev/null', '/usr/bin/log', 'stream', '--style', 'syslog', '--predicate', 'processImagePath CONTAINS "${device.id}"',
]);

to

  return runCommand(<String>[
    'script', '/dev/null', '/foo/bin/log', 'stream', '--style', 'syslog', '--predicate', 'processImagePath CONTAINS "${device.id}"',
  ]);

(use '/foo/bin/log')

and delete flutter/bin/cache so it gets rebuilt

@ryanheise
Copy link

I'm getting this error because I'm working on a MacInCloud managed server plan which does not give you admin access. Besides this, everything else required for Flutter development seems to work in this environment, just except for the logging.

@ryanheise
Copy link

@DanTup @dnfield

Now that #23164 has landed, can this avenue be explored as a solution?

(I'm unable to use any workarounds that involve "sudo")

@DanTup
Copy link
Contributor

DanTup commented Aug 5, 2019

I don't know the details of the mDNS changes so I'll have to defer to @dnfield... Should it replace the need for reading the logs with the stream command?

@dnfield
Copy link
Contributor

dnfield commented Aug 5, 2019

No, that's only used for device finding. /Cc @jonahwilliams @zanderso

@cander0815
Copy link

How can I fix it?

@markrocks
Copy link

I am having this same issue and cannot run the simulator. Like ryanheise above< I am on a dev mac where I do not have admin access -- so I cannot try the fix zoechi suggested. Has there been any update on this? +1

@waniwang
Copy link

waniwang commented Oct 1, 2019

Facing the same issue when running driver tests on CI 😞

@mhrst
Copy link

mhrst commented Nov 19, 2019

Thanks, @keng42 -- your fix worked for me!

@Hixie Hixie modified the milestones: Stretch Goals, New Stretch Goals Jan 7, 2020
@jmagman jmagman changed the title Odd logging error message with IntelliJ, "log: Must be admin to run 'stream' command" Reading iOS logs requires sudo access: "log: Must be admin to run 'stream' command" Jan 23, 2020
@leogny
Copy link

leogny commented Jan 23, 2020

Struggled with this problem for a good two weeks.

Deleting flutter/bin/cache solved the issue.

@zanderso zanderso added the c: regression It was better in the past than it is now label Jan 23, 2020
@preetjdp
Copy link

preetjdp commented Feb 6, 2020

Hi are there any updates to this.
As is @ryanheise I'm trying to get this working with MacInCloud.
And the solution that @keng42 suggested will not work as MacInCloud does not give "sudo" access.

@cfanatic
Copy link

cfanatic commented Apr 4, 2020

My workaround

Change

return runCommand(<String>[
'script', '/dev/null', '/usr/bin/log', 'stream', '--style', 'syslog', '--predicate', 'processImagePath CONTAINS "${device.id}"',
]);

to

  return runCommand(<String>[
    'script', '/dev/null', 'sudo', '/usr/bin/log', 'stream', '--style', 'syslog', '--predicate', 'processImagePath CONTAINS "${device.id}"',
  ]);

(add 'sudo',)

And add this rule to /etc/sudoers

myuser          ALL = (root) NOPASSWD: /usr/bin/log

and delete flutter/bin/cache so it gets rebuilt

God, I am so glad I stumbled over this advice after half a day of troubleshooting while trying to proceed on https://flutter.dev/docs/get-started/test-drive?tab=vscode. I was always getting a white screen on my simulated iOS device. After making sure that log runs with sudo, I was able to get the app to run and test hot reload.

My setup:
[✓] Flutter (Channel stable, v1.12.13+hotfix.9, on Mac OS X 10.15.4 19E266, locale en-DE)
[✓] Xcode - develop for iOS and macOS (Xcode 11.4)
[✓] VS Code (version 1.43.2)
[✓] Connected device (1 available)

@zanderso
Copy link
Member

zanderso commented Apr 6, 2020

@christopherfujino @jmagman any advice on this issue?

@jmagman
Copy link
Member

jmagman commented Apr 6, 2020

This doesn't work for real devices anyway. I wonder if there are permission issues with switching this to xcrun simctl spawn <device-id> log stream for simulators?

@lock
Copy link

lock bot commented Apr 25, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@lock lock bot locked and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
c: regression It was better in the past than it is now platform-ios iOS applications specifically tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging a pull request may close this issue.