brndnmtthws / conky

Light-weight system monitor for X, Wayland (sort of), and other things, too
https://conky.cc
GNU General Public License v3.0
7.17k stars 615 forks source link

LUA API: uptime in the conky_info table appears not to be working #596

Closed ghost closed 6 years ago

ghost commented 6 years ago

This table entry appears to be blank - whereas the update_interval entry works. Apologies if some compile-time option is needed for this (which I have not enabled).

Linux Mint 19 Cinnamon x64.

conky 1.10.9_pre compiled Thu 9 Aug 22:06:55 BST 2018 for Linux 4.17.13-041713-generic x86_64

Compiled in features:

System config file: /etc/conky/conky.conf Package library path: /usr/local/lib/conky

General:

lasers commented 6 years ago

Do you have an example config we can use to test this?

ghost commented 6 years ago

Certainly. Here are gutted but hopefully stil functional - apart from with respect to the problem at issue! - versions of my conky script and the lua script in question. (The originals are a bit large and involved.)

I edited the title of this bug report, to clear up a confusion I had introduced. To be clear: the problem is with the update field in the conky_info table.

lasers commented 6 years ago

Pastebin does not last long. I'm copying the config to here.

--     ______            __
--    / ____/___  ____  / /____  __
--   / /   / __ \/ __ \/ //_/ / / /
--  / /___/ /_/ / / / / ,< / /_/ /
--  \____/\____/_/ /_/_/|_|\__, /
--                        /____/

-- ///////////////////////
-- //   CONFIGURATION   //
-- ///////////////////////

conky.config =
{
        update_interval = 1.1,
        update_interval_on_battery = 1.25,

        total_run_times = 0,

        short_units = true,

        format_human_readable = true,

        own_window_type = "desktop",
        own_window_hints = "undecorated,below,sticky,skip_taskbar,skip_pager",

        own_window_transparent = false,

        own_window_argb_visual = true,
        own_window_argb_value = 3,

        gap_x = 40,
        gap_y = 10,

        minimum_width = 2560,

        maximum_width = 2560,

        alignment = "top_left",

        border_outer_margin = 3,

        draw_graph_borders = true,

        use_xft = true,

        font = "Noto Sans:size=19",

        draw_shades = false,

        use_spacer = "left",

    -- // LUA script(s) //
    lua_load = '~/test.lua',
    -- See inter alia: https://github.com/brndnmtthws/conky/wiki/Lua-API
}

-- ///////////////
-- //   Main    //
-- ///////////////

conky.text = [[
${lua_parse conky_test}\
]]
#!/usr/local/bin/lua

conkyTicks_toRunAtAll = 8

local rtnText = ''

-- MAIN

function conky_test ()
    local ConkyTicks_current

    -- Necessary check
    if conky_window == nil then
        return ''
    end

    -- Abort if system not been up (= time since boot?) for < X seconds.
    -- Broken at present
    if conky_info ['uptime'] < 21 then
        return ''
    end

    ConkyTicks_current = tonumber( conky_parse ( "${updates}" ) )
    if ( ( ConkyTicks_current % conkyTicks_toRunAtAll ) ~= 0 ) then
        return rtnText
    end
    rtnText = 'test'

    return rtnText
end

-- ##### EOF #####
ghost commented 6 years ago

OK. But I set the Pastebin's expiry on both scripts to six months.

lasers commented 6 years ago

Stupid question. Am I missing a second script? I only see one script.

ghost commented 6 years ago

My mistake. Something had gone wrong with the formatting in my post. I've fixed it and here too is a link to that same - previousy missing - lua script.

lasers commented 6 years ago

So far, I see duplicate maximum_width = 2560. I see that it printed 0 for uptime and 1.1 for update_interval because you specified that in your config. Also, you may be interested in trying /usr/bin/env lua so it can find lua well on other machines.

@plikhari Can you see if he's doing Lua correctly? @su8 Can you see if this is correct? It's only two lines in ~/src/lluaa.cc.

./src/llua.cc:539:  llua_set_number("uptime", i->uptime);
./src/llua.cc:555:  llua_set_number("uptime", i->uptime);

EDIT: I hope we can close this issue today. :-)

plikhari commented 6 years ago

uptime has always printed 0 - but is this not the system Uptime - in which case it should match ${uptime} variable. In LUA you can also derive this value using conky_parse('${uptime}')

update_interval has always worked !!!

su8 commented 6 years ago

Here's the initialization of uptime

https://github.com/brndnmtthws/conky/blob/bbaa0e9ac8d8024245c2dde676ed4b6376f8300e/src/llua.cc#L539

Here's the initialization of the above function https://github.com/brndnmtthws/conky/blob/bbaa0e9ac8d8024245c2dde676ed4b6376f8300e/src/conky.cc#L3048

Even if we add this:

diff --git a/src/conky.cc b/src/conky.cc
index 52422ce5..09157b74 100644
--- a/src/conky.cc
+++ b/src/conky.cc
@@ -3045,6 +3045,7 @@ void initialisation(int argc, char **argv) {
 #ifdef BUILD_X11
   X11_create_window();
 #endif /* BUILD_X11 */
+  update_uptime();
   llua_setup_info(&info, active_update_interval());

   /* Set signal handlers */

The uptime information will be updated only once :disappointed:

edit: and it will be the raw /proc/uptime value.

plikhari commented 6 years ago

Ahh so there you have it - if it is only going to update one time - we really have no use for it. I have always seen conky_parse("${uptime}") in use - so we can change the docs and remove the uptime part.

ghost commented 6 years ago

Thanks, all. (What I really need, though, is time in seconds or milliseconds since either boot or resumption from sleep . .)

plikhari commented 6 years ago

For that you can use the cat /proc/uptime or uptime - former gives 2 values - 1st is the uptime in seconds. in LUA you can use as I have suggested above - and convert those to seocnds

ghost commented 6 years ago

Thanks. Also, though, I do not understand the comment above about

/usr/bin/env

lasers commented 6 years ago

I think it'd be good idea to take out the whole conky_info if it's going to require a sole option update_interval to work. Maybe I don't see it, but is there a Lua function to parse conky settings like update_interval, default_bar_width, etc...?

For waking up...

$ journalctl -b  | grep 'ACPI: Waking up' | tail -n1
Aug 14 04:23:29 z420 kernel: ACPI: Waking up from system sleep state S3
lasers commented 6 years ago

Change #!/usr/local/bin/lua to #!/usr/bin/env lua so it know where to find lua.

I have /usr/bin/lua here. Your lua seems to be coming from non-distro installation.

EDIT: https://www.cyberciti.biz/tips/finding-bash-perl-python-portably-using-env.html

plikhari commented 6 years ago

hey that is a very critical option - please leave it as it is - update_interval

plikhari commented 6 years ago

if you are running lua from within conky - then do not use environment statement on the first line !!!

lasers commented 6 years ago

@plikhari Why? #!/usr/local/bin/lua should have higher precedence over #!/usr/bin/lua either way.

plikhari commented 6 years ago

i am not talking about any precedence - this line need not be used as the lua interpreter is triggered by lua_load = filename.lua variable in the config section.

ghost commented 6 years ago

Well, on my computer anyway, conky can run lua files just fine, whether they start with (1)

#!/usr/local/bin/lua

or with what was suggested to me on this thread, viz., (2)

#!/usr/bin/env lua

And I've tested 1 (but not 2) on two other computers (all admittedly running the same Linux distribution, namely, Mint Cinnamon).

su8 commented 6 years ago

#!/usr/bin/env lua will traverse the $PATH to find any lua executables, it will stop the search on first occurrence, and is the preferred way to write portable scripts/programs.

plikhari commented 6 years ago

If you are running lua scripts as stand alone and not within conky - then you need to use the environment shebang - otherwise - it is not the preferred way if the script is being run within conky + lua using lua_load.

This is also not required if you are going to run the script as for example lua ./luascript.lua.

plikhari commented 6 years ago

That line is not even looked at in conky + lua thing.

I just tested with #!/bin/bash in a lua file and it still runs as lua file !

plikhari commented 6 years ago

There is no other way to get update_interval from within LUA other than conky_info - and my lua_startup_hook depends on that !!

su8 commented 6 years ago

lua ./luascript.lua

You are using the interpreter here, that's why it ignores the shebang.


Add #!/bin/bash, chomd +x luascript.lua and try running it by executing ./luascript.lua

plikhari commented 6 years ago

I absolutely agree with your point.

My case only exists for conky and embedded lua - not for stand alone situations.

lasers commented 6 years ago

@lasers Maybe I don't see it, but is there a Lua function to parse conky settings like update_interval, default_bar_width, etc...?

@su8 Is it trivial to implement this? All conky settings, not just update_interval.