{"id":16724877,"url":"https://github.com/kaworu/lua-sysctl","last_synced_at":"2025-03-21T21:30:59.236Z","repository":{"id":7038033,"uuid":"8314428","full_name":"kaworu/lua-sysctl","owner":"kaworu","description":"FreeBSD's sysctl(3) interface for Lua","archived":false,"fork":false,"pushed_at":"2024-05-22T15:32:51.000Z","size":70,"stargazers_count":7,"open_issues_count":3,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-18T05:12:37.700Z","etag":null,"topics":["freebsd","lua","sysctl"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kaworu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-02-20T14:14:55.000Z","updated_at":"2024-05-22T15:32:54.000Z","dependencies_parsed_at":"2024-10-28T11:34:29.615Z","dependency_job_id":"e8ed64cf-fb27-4854-988d-52a59fd53b63","html_url":"https://github.com/kaworu/lua-sysctl","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaworu%2Flua-sysctl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaworu%2Flua-sysctl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaworu%2Flua-sysctl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaworu%2Flua-sysctl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kaworu","download_url":"https://codeload.github.com/kaworu/lua-sysctl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244874154,"owners_count":20524576,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["freebsd","lua","sysctl"],"created_at":"2024-10-12T22:47:07.405Z","updated_at":"2025-03-21T21:30:58.874Z","avatar_url":"https://github.com/kaworu.png","language":"C","readme":"# sysctl(3) C interface for Lua\n\nlua-sysctl aim provide a simple and complete interface to FreeBSD's `sysctl(3)`\nC function for the [Lua](http://lua.org) scripting language. It allow both\nreading and writing sysctl values (see [limitations](#limitations)).\n\nAlthough the project has been started to display system informations inside the\n[Awesome window manager](http://awesome.naquadah.org/) it has been designed as\na general purpose interface, allowing it to be embedded into bigger project,\nused as library by system administration scripts etc.\n\nMost of the implementation is based on FreeBSD's `sysctl(8)` command line tool.\nFor more informations about sysctl see:\n\n* http://www.freebsd.org/doc/handbook/configtuning-sysctl.html\n* http://www.freebsd.org/cgi/man.cgi?query=sysctl\u0026amp;sektion=8\n* http://www.freebsd.org/cgi/man.cgi?query=sysctl\u0026amp;sektion=3\n\n## Installation\n* Supported Lua versions: 5.2, 5.3, and 5.4\n* Supported FreeBSD versions: 12.x\n\nNote that lua-sysctl might work fine with other version(s), I just don't have\nthe time to test more than what is listed above.\n\n### Using the FreeBSD ports tree\nThanks to garga@FreeBSD and @uzsolt, lua-sysctl is in the FreeBSD ports\ntree under _devel/lua-sysctl_.\n\n### Using RavenPorts\nThanks to @kraileth, lua-sysctl is in\n[Ravenports](https://github.com/jrmarino/Ravenports).\n\n### Build from source\nExample build, usage, and installation with Lua 5.4 (simply replace `LUA_VER`\nand `lua54` by your Lua version).\n\nCompiling:\n```console\n% make LUA_VER=5.4\ninstall -m 755 -d build\ncc -O2 -pipe -Wall -Wextra -fPIC `pkg-config --cflags lua-5.4` -o build/sysctl.so  -shared -Wl,-soname,lua_sysctl src/lua_sysctl.c\n```\n\n`require` from the local build/ directory:\n```console\n% sysctl -Na | LUA_CPATH=\"${PWD}/build/?.so;;\" lua54 ./misc/test-all.lua\n…\n```\n\nInstalling:\n```console\n# make LUA_VER=5.4 DESTDIR=/usr/local/lib/lua/5.4 install\ninstall -m 755 -d /usr/local/lib/lua/5.4\ninstall -m 755 build/sysctl.so /usr/local/lib/lua/5.4\n```\n\nNow we can `require` from the standard Lua path:\n```console\n% sysctl -Na | lua54 ./misc/test-all.lua\n…\n```\n\n## Examples\n\nReading:\n```\n\u003e sysctl = require('sysctl')\n\u003e val, type = sysctl.get('kern.ostype') -- reading a string\n\u003e print(val)\nFreeBSD\n\u003e print(type)\nA\n\u003e val, type = sysctl.get('kern.maxvnodes') -- reading a integer value\n\u003e print(val)\n111376\n\u003e print(type)\nI\n\u003e table, type = sysctl.get('vm.vmtotal') -- reading a special type value (which will be a table in Lua)\n\u003e print(table)\ntable: 0x801415800\n\u003e print(type)\nS,vmtotal\n\u003e for k,v in pairs(table) do print(k,v) end\nsl  20\nrm  81264\navmshr  6884\ndw  0\nfree    1601444\npw  0\narmshr  6252\nvmshr   22048\nrmshr   7204\narm 35104\nrq  1\nvm  1074232888\navm 420396\n```\n\nWritting:\n```\n\u003e sysctl = require('sysctl')\n\u003e sysctl.set('security.bsd.see_other_uids', 0)\n```\n\n## Functions\n\nNOTE: Both `sysctl.get()` and `sysctl.set()` raise an error if any problem\noccur.  If you don't control the key you're passing to these function you might\nwant to use [protected calls](https://www.lua.org/work/doc/manual.html#2.3).\n\n### sysctl.get(key)\nReturns two values: The first returned value is the `sysctl(3)` value, the\nsecond value is the format.\n\n#### formats\nFrom format value to C types:\n- _I_ `int`\n- _UI_ `unsigned int`\n- _IK_ `int`, in (kelv * 10) (used to get temperature)\n- _L_ `long`\n- _UL_ `unsigned long`\n- _A_ `char *`\n- _S,clockinfo_ `struct clockinfo`\n- _S,loadavg_ `struct loadavg`\n- _S,timeval_ `struct timeval`\n- _S,vmtotal_ `struct vmtotal`\n\nIn Lua land, it means that:\n- _I_, _UI_, _IK_, _L_, _UL_, are numbers.\n- _A_ is a string.\n- _S,clockinfo_ is a table of integers\n  `{ hz, tick, profhz, stathz }`\n- _S,loadavg_ is an array of numbers\n  `{ 1, 2, 3 }`\n- _S,timeval_ is a table of integers\n  `{ sec, sec }`\n- _S,vmtotal_ is a table of integers\n  `{ rq, dw, pw, sl, vm, avm, rm, arm, vmshr, avmshr, rmshr, armshr, free }`\n\n### sysctl.set(key, newval)\nSet the sysctl's key to newval. Return nothing and throw Lua error if any\nproblem occur. Note that some sysctl's key are read only or read only tunable\nand can not be set at runtime.\n\n### sysctl.IK2celsius(kelv)\nConvert a sysctl's IK value into Celsius and return it.\n\n### sysctl.IK2farenheit(kelv)\nConvert a sysctl's IK value into Fahrenheit and return it.\n\n## Limitations\n\n* Some sysctl variables cannot be changed while the system is running (they're\n  \"read-only tunable\").\n* You need root privilege to change sysctl variables\n* Some variables cannot be changed from inside a jail (and might depend of the\n  _securelevel_ too).\n\nTheses limitations are not due to the implementation of lua-sysctl but rather\nto `sysctl(3)` and how FreeBSD work. Note that most (if not all) theses\nlimitations are desirables.\n\n* lua-sysctl is unable to handle values for all existing types. More precisely,\n  it can handle about the same subset supported by the `sysctl(8)` command line\n  utility. It should not be an issue since most sysctl key have \"simple\" values\n  (i.e. numeric or string).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaworu%2Flua-sysctl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkaworu%2Flua-sysctl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaworu%2Flua-sysctl/lists"}