Even if macrofiles is NULL we (may) have other initialization tasks
to do, always grab the context lock and mind segfaulting when loading
files if macrofiles is NULL.
Compacts things a bit and allows for more flexibility later on,
unfortunately at the price of losing type safety. No functinal changes,
just paving way for next steps.
Add a mbInit() function that allocates the buffer, increases the
expansion depth and stashes some values into a MacroExpansionData area.
Add a mbFini() function that decreases the depth again,
restores the values and optionally prints the expansion result.
find-debuginfo is multi-threaded and rpm runs
scripts usually with "-e" to abort on error.
If the debug-splitting tool fails, that job will abort.
But if you have X files that are problematic in the tree,
and you have X or less jobs, find-debuginfo will abort
as no single res.$number has been written.
But if you have more than X jobs, the build will succeed,
which makes the whole process random.
This commit remove this randomness.
Remove long since obsoleted tags and such, at least mention all
spec sections by name. Obviously mountains of information is missing,
and what is there is totally chaotic and inconsistent, but at least
there's a place to add more now.
As of Doxygen >= 1.8.20 it started complaining about anything marked
as @retval being undocumented. As this is widely used in rpm...
Mass-replace all @retval uses with @param[out] to silence. Some of
these are actually in/out parameters but combing through all of them
is a bit too much...
Also escape <CR><LF> in rpmpgp.h to shut up yet another new warning.
In libselinux >= 3.1 these cause deprecation warnings on build.
security_context_t always was nothing but typedef to plain old "char *"
so just using that is entirely backwards compatible too.
Fixes compilation on musl, otherwise it fails with undefined references
to various O_* symbols as mentioned here:
https://www.man7.org/linux/man-pages/man0/fcntl.h.0p.html
Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
If there was a \ at the end of the buffer, the code would
return a pointer after the trailing \0 leading to unallocated
memory access and weird results in some cases.
See commit 817959609b.
macro.c: In function ‘mbopt’:
macro.c:895:19: warning: unused variable ‘me’ [-Wunused-variable]
895 | rpmMacroEntry me = mb->me;
| ^~
rpmlua.c: In function ‘fd_seek’:
rpmlua.c:985:22: warning: unused variable ‘mode’ [-Wunused-variable]
985 | static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
| ^~~~
The former is actually unused, the latter should be used.
Macros might want to pass along options meant for others while perhaps
modifying some of them, without exposing it all to users.
Have "-" as the parametric macro opts string disable all options processing
in rpm, allowing the macro to handle the raw argument list as they place.
Fixes: #547
Avoids code duplication (glibc quirks and whatnot) between macro and lua
option parsing, isolate the global opt* variable accesses to one spot.
Makes it easier to ensure identical behavior between the users if/when
something changes.
No behavior changes intended.
This whole lot has been barely used at all since its addition in 2004,
is totally undocumented and instead of being helpful, it only ends up
being more code using some strange add-on API. It also quite effectively
prevents anybody from doing anything fancy with Lua because you'd have to
wrap it up somewhere in this intermediate API.
People are better off using native Lua API for data manipulation, byebye.
Not much changes here in practise, although this does patch_nums and
source_nums "leaking" after a spec parse as we forgot to update
*that* code when adding them. More visible when consolidated...
Also store the Lua context in the spec struct. This doesn't make much
of a difference as it is, but it'll be needed someday when we create
a new Lua environment for each spec parse, and at any rate this is
gives us a single, easy place to check whether it was initialized or not.
This seems to be the intention of the code but it did
not work because macro parsing was resumed at the wrong
point of the input string. Without this commit, "%{}"
expanded to "%" instead of "%{}".
Since Lua can easily return multiple values, combine test for definition
and parametric into one rpm.isdefined() API, always returning two booleans.
This also kinda ensures correct API usage as both are needed to positively
identify a defined, non-parametric macro.
We already have the macro arguments in an ARGV that's suitable for
passing to Lua, just store it in the macro buffer for passing around.
As macros can nest arbitrarily, we need to store and restore the mb
args which is a bit hacky, but much less trouble than changing all the
related functions to pass argound an argv which only one function
ever uses. Ditto with the macro entry itself, which is needed to pass
around the options (and name, and maybe something else too later).
Besides all the normal rpm defined macros for arguments and options,
parametric Lua macros now get pre-processed options and arguments
in native local tables "opt" and "arg" for much more pleasant access.
"opt" and "arg" tables are always there even if no options or arguments
were passed, this avoids having to deal with multiple cases and test
for nil's all over the place.
Fixes: #1092
The code is more obvious and there's a whole lot less of it, we get
rid of a klunky global table, allow Lua scriptlets to process arguments
using native facilities for variadic functions, all in a backwards
compatible manner. What's not to like?
As a side-effect, the package count arguments now appear as integers
instead of floats, which is much saner in the context. Lua will
automatically convert numbers as necessary so this should not break
anything.
Add support for passing getopt options and arguments to natively to Lua
scriptlets via the internal API. The processed opts and args are stored
in two chunk local two tables, options keyed by the letter and arguments
by their numeric index.
Update call sites accordingly, but no actual functionality changes here,
just pre-requisites for next steps.
This code eliminates a false positive failure when the destination
position is > 2GiB. This is done by changing the contract for `Fseek`.
Now it returns `0` on success instead of an `int` offset.
Care should be used to interpret the result as there is a difference in
semantics between the POSIX `fseek(2)`. Existing code is correct: negative
results are still failures.