[erlang-bugs] disksup:get_disk_data() is returning the wrong data on my system (OS X 10.8 -- Darwin 12)

John Bard john.ryan.bard@REDACTED
Tue Apr 23 01:16:44 CEST 2013


disksup:get_disk_data() is returning garbage in OS X 10.8 (on my system)


[I have verified this in R15B02, R15B03 & 16B]


1> ok = application:start(sasl).

<snip>

2> ok = application:start(os_mon).

<snip>

3> disksup:get_disk_data().

[{"18704735",244277768,31}]

4>


The expectation is: [{"/",244277768,31}]


The problem is that the format of the df command changed in OS X 10.8 for
some reason (at least it is different on my machine... I checked and I
don't appear to have any bash functions or aliases getting in the way).


In OS X 10.7.? (a colleague's mac mini: hdd):

$ df -k -t ufs,hfs

Filesystem   1024-blocks      Used Available Capacity  Mounted on

/dev/disk0s2   487546976 156364392 330926584    33%    /

$


The 6th column is "Mounted on".


In OS X 10.8.3 (my mac book pro: ssd):

$ df -k -t ufs,hfs

Filesystem   1024-blocks     Used Available Capacity  iused    ifree %iused
 Mounted on

/dev/disk0s2   244277768 74564136 169457632    31% 18705032 42364408   31%
  /

$


The 6th column is "iused" instead of "Mounted on".



If this is a simply difference in 10.8 [darwin 12] and isn't a more complex
situation than that (macs pre-installed with ssds vs. hdds? some
configuration somewhere?), a fix could be:

[I toyed around in R16B, but the code is pretty much the same in R15B03 and
I assume the same in R15B02]


in os_mon's disksup.erl:


add a guard for the specific darwin in init's case statement:


Port = case OS of

    {unix, Flavor} when Flavor==sunos4;

            Flavor==solaris;

            Flavor==freebsd;

            Flavor==dragonfly;

            Flavor==darwin;

            Flavor==darwin_12;

            Flavor==linux;

            Flavor==openbsd;

            Flavor==netbsd;

            Flavor==irix64;

            Flavor==irix ->

        start_portprogram();

    {win32, _OSname} ->

        not_used;

    _ ->

        exit({unsupported_os, OS})

    end,


add a clause to the case statement in the get_os() function:


get_os() ->

    case os:type() of

        {unix, sunos} ->

            case os:version() of

                {5,_,_} -> {unix, solaris};

                {4,_,_} -> {unix, sunos4};

                V -> exit({unknown_os_version, V})

            end;

        {unix, irix64} ->

            {unix, irix};

        {unix, darwin} ->

            case os:version() of

                {12,_,_} -> {unix, darwin_12};

                _ -> {unix, darwin}

            end;

        OS ->

            OS

    end.



add a function that will pattern match on the new darwin_12 atom specified
in the other places and will call into a function to parse the df command
differently:


check_disk_space({unix, darwin_12}, Port, Threshold) ->

    Result = my_cmd("/bin/df -k -t ufs,hfs", Port),

    check_disks_darwin_12(skip_to_eol(Result), Threshold);



and add that new function to parse the df command:


%% Special cases like this annoy me...

check_disks_darwin_12("", _Threshold) ->

    [];

check_disks_darwin_12("\n", _Threshold) ->

    [];

check_disks_darwin_12(Str, Threshold) ->

    case io_lib:fread("~s~d~d~d~d%~d~d~d%~s", Str) of

        {ok, [_FS, KB, _Used, _Avail, Cap, _IUsed, _IFree, _ICap, MntOn],
RestStr} ->

            if

                Cap >= Threshold ->

                    set_alarm({disk_almost_full, MntOn}, []);

                true ->

                    clear_alarm({disk_almost_full, MntOn})

            end,

            [{MntOn, KB, Cap} | check_disks_darwin_12(RestStr, Threshold)];

        _Other ->

            check_disks_darwin_12(skip_to_eol(Str),Threshold)

    end.


Sorry if I butchered the whitespace (gmail ate the tabs, so I had to
manually fix the whitespace with consistent spaces).

-- 
Ryan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20130422/28786fab/attachment.htm>


More information about the erlang-bugs mailing list