Mercurial > prosody-hg
annotate util/gc.lua @ 14016:1df1782ccdfe
prosodyctl shell: Improve process exit codes
This fixes a bug introduced in 3326c8a29a86 where prosodyctl shell would
always exit with non-zero error codes, even on success. Now it will exit with
0 for success, or 1 if any errors were printed.
It also updates the other exit codes in the shell command to help distinguish
between different error cases. These are based on the sysexits.h codes,
although it is not recommended to rely on that interface.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 19 Dec 2025 15:32:26 +0000 |
| parents | c9cc84bee17b |
| children |
| rev | line source |
|---|---|
|
12975
d10957394a3c
util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
11431
diff
changeset
|
1 local set = require "prosody.util.set"; |
|
10933
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local known_options = { |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 incremental = set.new { "mode", "threshold", "speed", "step_size" }; |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 generational = set.new { "mode", "minor_threshold", "major_threshold" }; |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 }; |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 |
|
13928
c9cc84bee17b
util.gc: Handle Lua 5.5 way of passing parameters
Kim Alvefur <zash@zash.se>
parents:
12975
diff
changeset
|
8 if _VERSION == "Lua 5.5" then |
|
c9cc84bee17b
util.gc: Handle Lua 5.5 way of passing parameters
Kim Alvefur <zash@zash.se>
parents:
12975
diff
changeset
|
9 known_options.generational = set.new { "mode", "minor_multiplier", "minor_major_threshold", "major_minor_threshold" }; |
|
c9cc84bee17b
util.gc: Handle Lua 5.5 way of passing parameters
Kim Alvefur <zash@zash.se>
parents:
12975
diff
changeset
|
10 elseif _VERSION ~= "Lua 5.4" then |
|
10933
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 known_options.generational = nil; |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 known_options.incremental:remove("step_size"); |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 end |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 local function configure(user, defaults) |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 local mode = user.mode or defaults.mode or "incremental"; |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 if not known_options[mode] then |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 return nil, "GC mode not supported on ".._VERSION..": "..mode; |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 end |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 for k, v in pairs(user) do |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 if not known_options[mode]:contains(k) then |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 return nil, "Unknown GC parameter: "..k; |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 elseif k ~= "mode" and type(v) ~= "number" then |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 return nil, "parameter '"..k.."' should be a number"; |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 end |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 end |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 if mode == "incremental" then |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 if _VERSION == "Lua 5.4" then |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 collectgarbage(mode, |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 user.threshold or defaults.threshold, |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 user.speed or defaults.speed, |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 user.step_size or defaults.step_size |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 ); |
|
13928
c9cc84bee17b
util.gc: Handle Lua 5.5 way of passing parameters
Kim Alvefur <zash@zash.se>
parents:
12975
diff
changeset
|
36 elseif _VERSION == "Lua 5.5" then |
|
c9cc84bee17b
util.gc: Handle Lua 5.5 way of passing parameters
Kim Alvefur <zash@zash.se>
parents:
12975
diff
changeset
|
37 collectgarbage(mode); |
|
c9cc84bee17b
util.gc: Handle Lua 5.5 way of passing parameters
Kim Alvefur <zash@zash.se>
parents:
12975
diff
changeset
|
38 collectgarbage("param", "pause", user.threshold or defaults.threshold); |
|
c9cc84bee17b
util.gc: Handle Lua 5.5 way of passing parameters
Kim Alvefur <zash@zash.se>
parents:
12975
diff
changeset
|
39 collectgarbage("param", "stepmul", user.speed or defaults.speed); |
|
c9cc84bee17b
util.gc: Handle Lua 5.5 way of passing parameters
Kim Alvefur <zash@zash.se>
parents:
12975
diff
changeset
|
40 collectgarbage("param", "stepsize", user.step_size or defaults.step_size); |
|
10933
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 else |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 collectgarbage("setpause", user.threshold or defaults.threshold); |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 collectgarbage("setstepmul", user.speed or defaults.speed); |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 end |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 elseif mode == "generational" then |
|
13928
c9cc84bee17b
util.gc: Handle Lua 5.5 way of passing parameters
Kim Alvefur <zash@zash.se>
parents:
12975
diff
changeset
|
46 if _VERSION == "Lua 5.4" then |
|
c9cc84bee17b
util.gc: Handle Lua 5.5 way of passing parameters
Kim Alvefur <zash@zash.se>
parents:
12975
diff
changeset
|
47 collectgarbage(mode, |
|
c9cc84bee17b
util.gc: Handle Lua 5.5 way of passing parameters
Kim Alvefur <zash@zash.se>
parents:
12975
diff
changeset
|
48 user.minor_threshold or defaults.minor_threshold, |
|
c9cc84bee17b
util.gc: Handle Lua 5.5 way of passing parameters
Kim Alvefur <zash@zash.se>
parents:
12975
diff
changeset
|
49 user.major_threshold or defaults.major_threshold |
|
c9cc84bee17b
util.gc: Handle Lua 5.5 way of passing parameters
Kim Alvefur <zash@zash.se>
parents:
12975
diff
changeset
|
50 ); |
|
c9cc84bee17b
util.gc: Handle Lua 5.5 way of passing parameters
Kim Alvefur <zash@zash.se>
parents:
12975
diff
changeset
|
51 elseif _VERSION == "Lua 5.5" then |
|
c9cc84bee17b
util.gc: Handle Lua 5.5 way of passing parameters
Kim Alvefur <zash@zash.se>
parents:
12975
diff
changeset
|
52 collectgarbage(mode); |
|
c9cc84bee17b
util.gc: Handle Lua 5.5 way of passing parameters
Kim Alvefur <zash@zash.se>
parents:
12975
diff
changeset
|
53 collectgarbage("param", "minormul", user.minor_multiplier or defaults.minor_multiplier); |
|
c9cc84bee17b
util.gc: Handle Lua 5.5 way of passing parameters
Kim Alvefur <zash@zash.se>
parents:
12975
diff
changeset
|
54 collectgarbage("param", "majorminor", user.major_minor_threshold or defaults.major_minor_threshold); |
|
c9cc84bee17b
util.gc: Handle Lua 5.5 way of passing parameters
Kim Alvefur <zash@zash.se>
parents:
12975
diff
changeset
|
55 collectgarbage("param", "minormajor", user.minor_major_threshold or defaults.minor_major_threshold); |
|
c9cc84bee17b
util.gc: Handle Lua 5.5 way of passing parameters
Kim Alvefur <zash@zash.se>
parents:
12975
diff
changeset
|
56 end |
|
10935
2d57c49bfa12
util.gc: Linter fixes [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
10933
diff
changeset
|
57 end |
|
10933
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 return true; |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 end |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 return { |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 configure = configure; |
|
f59bc81245b3
util.gc: New module for configuring the Lua garbage collector
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 }; |
