scripts: Port some to new style, minor cleanup

Prep for further work.

Closes: #858
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-07-02 08:54:08 -04:00 committed by Atomic Bot
parent 2b547c2d0a
commit 1f33f42c7a

View File

@ -235,43 +235,37 @@ run_known_rpm_script (const KnownRpmScriptKind *rpmscript,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
const char *desc = rpmscript->desc;
rpmTagVal tagval = rpmscript->tag; rpmTagVal tagval = rpmscript->tag;
rpmTagVal progtagval = rpmscript->progtag; rpmTagVal progtagval = rpmscript->progtag;
const char *script;
g_autofree char **args = NULL;
RpmOstreeScriptAction action;
struct rpmtd_s td;
if (!(headerIsEntry (hdr, tagval) || headerIsEntry (hdr, progtagval))) if (!(headerIsEntry (hdr, tagval) || headerIsEntry (hdr, progtagval)))
return TRUE; return TRUE;
script = headerGetString (hdr, tagval); const char *script = headerGetString (hdr, tagval);
if (!script) if (!script)
return TRUE; return TRUE;
struct rpmtd_s td;
g_autofree char **args = NULL;
if (headerGet (hdr, progtagval, &td, (HEADERGET_ALLOC|HEADERGET_ARGV))) if (headerGet (hdr, progtagval, &td, (HEADERGET_ALLOC|HEADERGET_ARGV)))
args = td.data; args = td.data;
action = lookup_script_action (pkg, ignore_scripts, desc); const char *desc = rpmscript->desc;
RpmOstreeScriptAction action = lookup_script_action (pkg, ignore_scripts, desc);
switch (action) switch (action)
{ {
case RPMOSTREE_SCRIPT_ACTION_DEFAULT: case RPMOSTREE_SCRIPT_ACTION_DEFAULT:
{ {
static const char lua[] = "<lua>"; const char *argv0 = args && args[0] ? args[0] : "/bin/sh";
if (args && args[0] && strcmp (args[0], lua) == 0)
{ static const char lua_builtin[] = "<lua>";
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, if (g_strcmp0 (argv0, lua_builtin) == 0)
"Package '%s' has (currently) unsupported %s script in '%s'", return glnx_throw (error, "Package '%s' has (currently) unsupported %s script in '%s'",
dnf_package_get_name (pkg), lua, desc); dnf_package_get_name (pkg), lua_builtin, desc);
return FALSE;
}
if (!run_script_in_bwrap_container (rootfs_fd, dnf_package_get_name (pkg), desc, script, if (!run_script_in_bwrap_container (rootfs_fd, dnf_package_get_name (pkg), desc, script,
cancellable, error)) cancellable, error))
{ return glnx_prefix_error (error, "Running %s for %s", desc, dnf_package_get_name (pkg));
g_prefix_error (error, "Running %s for %s: ", desc, dnf_package_get_name (pkg));
return FALSE;
}
break; break;
} }
case RPMOSTREE_SCRIPT_ACTION_IGNORE: case RPMOSTREE_SCRIPT_ACTION_IGNORE: