8000 keep scan thread for version before high sierra by pmalhaire · Pull Request #728 · hishamhm/htop · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

keep scan thread for version before high sierra - #728

Merged
hishamhm merged 2 commits into
hishamhm:masterfrom
pmalhaire:macos_keep_not_high_sierra_ok
Mar 25, 2018
Merged

hishamhm merged 2 commits into
hishamhm:masterfrom
pmalhaire:macos_keep_not_high_sierra_ok

Conversation

@pmalhaire
Copy link
Copy Markdown
Contributor

@hishamhm As said this should do the trick to keep thread info for those who don't have High Sierra.

Unfortunately I don't know the exact version failling.

@pmalhaire
pmalhaire force-pushed the macos_keep_not_high_sierra_ok branch from d4ce5f2 to 8235a2b Compare February 4, 2018 20:38
@ylluminarious
Copy link
Copy Markdown

You sure you want to turn off this feature for all of High Sierra? Some people are reporting that XNU has been fixed by Apple in 10.13.4.

@pmalhaire
Copy link
Copy Markdown
Contributor Author

@ylluminarious not really, it seems that the issue is for versions 10.13.2 to 10.13.3 is it ?

@moritzreiter
Copy link
Copy Markdown

@pmalhaire For me the issue started with macOS High Sierra 10.13.0 and persisted in all versions until 10.13.3. With the public beta of 10.13.4 that was released recently (and htop 2.0.2) I couldn't reproduce the issue anymore.

@pmalhaire
pmalhaire force-pushed the macos_keep_not_high_sierra_ok branch 2 times, most recently from bba9153 to c100f4e Compare February 5, 2018 22:35
@ilovezfs
ilovezfs commented Feb 6, 2018
Copy link
Copy Markdown

What is the value of sysctl kern.osrelease on 10.13.3 and on 10.13.4?

@ylluminarious
Copy link
Copy Markdown

@ilovezfs On 10.13.3 it's 17.4.0.

@ilovezfs
ilovezfs commented Feb 6, 2018
Copy link
Copy Markdown

@pmalhaire so this PR also needs to exclude 17.4.0

@ilovezfs ilovezfs mentioned this pull request Feb 6, 2018
4 tasks done
@ilovezfs
ilovezfs commented Feb 6, 2018
Copy link
Copy Markdown

@pmalhaire and >= 17.5.0 is safe again.

@pmalhaire
pmalhaire force-pushed the macos_keep_not_high_sierra_ok branch from c100f4e to d9af224 Compare February 6, 2018 07:34
@pmalhaire
pmalhaire commented Feb 6, 2018 •
Copy link
Copy Markdown
Contributor Author

Thx I mixed up. Fixer @ilovezfs @ylluminarious

@pmalhaire
Copy link
Copy Markdown
Contributor Author

Infortunately I don't have version to test the fix

@ylluminarious
Copy link
Copy Markdown

@pmalhaire Thanks! Hopefully someone who is on the beta can try your patch and see if it works. Also @hishamhm should probably review this for merging.

Comment thread darwin/DarwinProcessList.c Outdated
#include <stdbool.h>


void GetKernelVersion(int ** major, int ** minor, int ** internal) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the ** needed here? I may be wrong, but it seems like you only need int *major etc. here if you change the bottom lines to be *major = cMajor; etc. and the variable declarations to be int maj, min, inter;.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I want to use pointers it's needed or the value won't be set.

Since the size of a pointer is the same or bigger than an int, I could use simple pointer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mc10 should be fixed

@pmalhaire
pmalhaire force-pushed the macos_keep_not_high_sierra_ok branch from d9af224 to 5e9c38b Compare February 6, 2018 23:36
@moritzreiter
Copy link
Copy Markdown

I have a VM running High Sierra with one snapshot on 10.13.3 and one snapshot on 10.13.4 public beta. I'd be happy to run tests if it's of any help but I'd need some guidance on how and what exactly to test.

I could build htop from this branch (pmalhaire:macos_keep_not_high_sierra_ok) and test if it runs fine on both High Sierra versions but I wouldn't know how to test if that scan thread feature is actually switched on again on 10.13.4...

@pmalhaire
pmalhaire commented Feb 7, 2018 •
Copy link
Copy Markdown
Contributor Author

@anothernode
Actualy the function is giving thread infos si thread state or thread id are info which should be present when on 10.13.4 but not in 10.13.3

10.13.3 state (S) has ?
capture d ecran 2018-02-07 a 09 05 35

void DarwinProcess_scanThreads(DarwinProcess *dp) {

@moritzreiter
moritzreiter commented Feb 7, 2018 •
Copy link
Copy Markdown

@pmalhaire All right, thanks!

So I compiled htop from pmalhaire:macos_keep_not_high_sierra_ok and let it run once on 10.13.3 and once on 10.13.4 public beta.

As you can see in the attached screenshots, on 10.13.3, the S column shows a ? for the htop process but on 10.13.4 it shows an R. For all other processes though it shows ? on either version (I guess, because I didn't run with sudo?). I hope that helps.

High Sierra 10.13.3:
screenshot-htop-high-sierra-10 13 3

High Sierra 10.13.4 public beta:
screenshot-htop-high-sierra-10 13 4-beta

@pmalhaire
Copy link
Copy Markdown
Contributor Author

Seems fine @anothernode

@hishamhm
Copy link
Copy Markdown
Owner

Hey @pmalhaire! Thank you for this patch! I'm wondering though if it's worth keeping a lot of version detection code around to catch one bug in one specific point release... is 10.13.4 about to be released? I think once that is out, basically all High Sierra users will upgrade to it, right? So at that point, reenabling the feature unconditionally would make sense. What do you think? (I don't have a big understanding of typical macOS user upgrade patterns)

@hishamhm hishamhm added the macOS label Feb 17, 2018
@pmalhaire
pmalhaire commented Feb 17, 2018 •
Copy link
Copy Markdown
Contributor Author

@hishamhm You are right most people will upgrade to a newer version. I didn't find updated upgrade rate but I'd say from past experiences that 30% of users will not upgrade 6 month after the upgrade is released.

Blocking it at package manager level (brew) is an other option what do you think @ilovezfs ?
something like

if version is 10.13.3 
    error "please upgrade you high sierra version to 10.13.4 or upper"   

Unfortunately macOs bug rate is quite high at the time. It may change, but you may need this kind of code again.

I'll compact my code anyway, it's too long for what it does.

@pmalhaire
pmalhaire force-pushed the macos_keep_not_high_sierra_ok branch from e645e37 to 08dbac0 Compare February 18, 2018 10:58
@ylluminarious
Copy link
Copy Markdown

@hishamhm @pmalhaire I know a fair number of people who do not upgrade right when a new release comes out. Even if they're already on the most recent major version. I am not one of those people most of the time, but I don't think that having some extra lines will hurt anything, considering the fact that people often have a good reason not to upgrade to a new minor version right away. Downtime, compatibility, bugs in the new version are all valid concerns and I think it's a bad practice to impose such minor versions on users, when it's not even much of a pain for the developer himself.

@pmalhaire
Copy link
Copy Markdown
Contributor Author

Thanks @ylluminarious for your explaination.

@hishamhm Given what @ylluminarious added I'd suggest merging this code.

@ylluminarious
Copy link
Copy Markdown

@hishamhm Thank you very much for merging this! I'm sure we can all appreciate the solution given by @pmalhaire.

@ylluminarious
Copy link
Copy Markdown

@ilovezfs The homebrew formula for htop should probably be updated now.

@ilovezfs
Copy link
Copy Markdown

@ylluminarious voilà Homebrew/homebrew-core#25751

hishamhm pushed a commit that referenced this pull request Mar 26, 2018
Keep scanning threads for versions before High Sierra 13.0.0 and after 13.3.0.
@ylluminarious
Copy link
Copy Markdown

@ilovezfs @pmalhaire @hishamhm @anothernode Yikes, sorry folks, looks like this patch did not fix the issue. According to my own testing, this bug is still alive and well on High Sierra versions lower than 10.13.4.

@ilovezfs
Copy link
Copy Markdown

I've reverted this patch from 2.1.0 in Homebrew: Homebrew/homebrew-core#25887 until we figure out what went wrong here.

@pmalhaire I think the comparisons are backwards here. Won't CompareKernelVersion(17, 5, 0) be a positive number not a negative number on an affected system?

@ylluminarious
Copy link
Copy Markdown

@ilovezfs @pmalhaire Sounds like a fine situation for good ol' printf and friends to tell us whether or not the comparison is actually working.

@ilovezfs
Copy link
Copy Markdown

@ylluminarious are you suggesting we not guess?

@ylluminarious
Copy link
Copy Markdown

@ilovezfs Heheh, well... yes :)

I've no problem with testing the reverse comparison patch that you made, but it sure wouldn't hurt to test it both ways and write some sort of logging statement indicating whether the main boolean expression is doing what we expect it to. Just as a sanity check, if nothing else.

@Smattr
Smattr commented Mar 29, 2018
Copy link
Copy Markdown

Er, yes, the comparisons are is back-to-front, aren't they? Copy and pasting into an isolated program:

#include <stdbool.h>                                                                                                                          [0/76]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/sysctl.h>

struct kern {
    short int version[3];
};

void GetKernelVersion(struct kern *k) {
   static short int version_[3] = {0};
   if (!version_[0]) {
      // just in case it fails someday
      version_[0] = version_[1] = version_[2] = -1;
      char str[256] = {0};
      size_t size = sizeof(str);
      int ret = sysctlbyname("kern.osrelease", str, &size, NULL, 0);
      if (ret == 0) sscanf(str, "%hd.%hd.%hd", &version_[0], &version_[1], &version_[2]);
    }
    memcpy(k->version, version_, sizeof(version_));
}

int CompareKernelVersion(short int major, short int minor, short int component) {
    struct kern k;
    GetKernelVersion(&k);
    if ( k.version[0] !=  major) return major - k.version[0];
    if ( k.version[1] !=  minor) return minor - k.version[1];
    if ( k.version[2] !=  component) return component - k.version[2];
    return 0;
}

bool foo() {
    bool isScanThreadSupported  = ! ( CompareKernelVersion(17, 0, 0) >= 0 && CompareKernelVersion(17, 5, 0) < 0);
    return isScanThreadSupported;
}


int main(void) {
    puts(foo() ? "true" : "false");
    return EXIT_SUCCESS;
}

This tells me "true" and I'm on macOS 10.13.3 so it should be telling me "false." Should this be the following?

bool isScanThreadSupported  = ! ( CompareKernelVersion(17, 0, 0) < 0 && CompareKernelVersion(17, 5, 0) >= 0);

@ilovezfs
Copy link
Copy Markdown

No, I think it needs to be

    bool isScanThreadSupported  = ! ( CompareKernelVersion(17, 0, 0) <= 0 && CompareKernelVersion(17, 5, 0) > 0);

otherwise 10.13.4 will be disqualified too.

Or we can reverse the subtraction order in CompareKernelVersion.

@ylluminarious
Copy link
Copy Markdown

@ilovezfs @Smattr I know this still sounds elementary and obvious... but this is a place where I would use printf or similar to verify that the conditional is working correctly. We definitely need some assurance as to which conditional is correct since my head is starting to spin after thinking about this logic several times... :P

After some unsuccessful testing in a VM, I'd like to have more confidence before being a guinea pig again. I am sure that others would like the same assurance. I would do it myself, but I have not had time to go and compile htop and apply these patches manually.

@ilovezfs
Copy link
Copy Markdown

@ylluminarious I did, which is how I identified the off-by-one error in @Smattr's suggestion. But please feel free to verify my findings yourself :)

@ylluminarious
Copy link
Copy Markdown

@ilovezfs Oh cool, that's great. I didn't realize you had already done that. Thank you, I have some more confidence to try it out now. I suppose I can try it out at some point tomorrow or the next day unless someone beats me to it :)

@ilovezfs
Copy link
Copy Markdown

@ylluminarious please note that my suggestion above is different from what I said in the other issue, which is what accounts for the failure monouser7dig still saw.

@ylluminarious
Copy link
Copy Markdown

@ilovezfs Right, I noticed that it was different. Thank you for further clarifying that.

@pmalhaire
Copy link
Copy Markdown
Contributor Author

I'll have a look

@pmalhaire
Copy link
Copy Markdown
Contributor Author

I definetly switched the test while compacting my code, I'll fix and send a test executable tonight.

@moritzreiter
Copy link
Copy Markdown

Personally I'm happy with always running htop with sudo until macOS 10.13.4 gets released.

So maybe we could also consider a kind of patch where htop just refuses to start and print some explanatory error message instead, if invoked without sudo on macOS 10.13.0 >= x <= 10.13.3?

It kind of seems to be a bit of a waste of effort to put much more time and energy into this, now that we know that 10.13.4 will fix the actual root cause of the whole mess...

@ilovezfs
Copy link
Copy Markdown

@anothernode It's cool that you have root access on your computer. Many users don't.

@pmalhaire
pmalhaire commented Mar 29, 2018 •
Copy link
Copy Markdown
Contributor Author

test.c.txt
It should be fine now. ^ This is the test with all versions ^

Sorry for the error.

@ilovezfs
Copy link
Copy Markdown

Apple has now released 10.13.4

@ylluminarious
Copy link
Copy Markdown

Ok, so I attempted to test @ilovezfs's fix yesterday, but I had some issues connecting to https://hisham.hm, so I could not get the modified formula to install. Moreover, I noticed that @pmalhaire started a new PR at #772, so which patch should be tested now?

@pmalhaire
Copy link
Copy Markdown
Contributor Author

@ylluminarious @ilovezfs the patch I made just fixes the error I made. It's the same as what @ilovezfs suggested.

@ylluminarious
Copy link
Copy Markdown

@pmalhaire Ok, your solution is slightly different in that it changes the arithmetic in CompareKernelVersion rather than changing the comparison operators. But I see that it is effectively the same by testing out both versions from you and @ilovezfs. I guess I'll try out your patch in #772 and see what happens.

@pmalhaire
pmalhaire commented Apr 1, 2018 •
Copy link
Copy Markdown
Contributor Author

I wrote CompareKernelVersion to work like in #772. Unfortunately I made a mistake when I compacted the code. Currently my fix is broken. It just needs to be fixed one way #772 or the other.

@ylluminarious
Copy link
Copy Markdown

@pmalhaire @ilovezfs @hishamhm Looks like #772 does the job and fixes this problem for good.

@ylluminarious
Copy link
Copy Markdown

@ilovezfs @hishamhm To reiterate a comment I left on #682 and to avoid any confusion: I left htop running for 4 hours on 10.13.3 with @pmalhaire's patch in #772 and I didn't crash. His patch should be merged.

hishamhm pushed a commit that referenced this pull request Apr 6, 2018
Keep scanning threads for versions before High Sierra 13.0.0 and after 13.3.0.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

0