ferdnyc left a comment (rpm-software-management/rpm#3661)

So, this is confusing. `rpm -q --scripts glibc` displays ***some*** code with 
backslashes intact, and other code without:

```bash
$ rpm -q --scripts glibc
postinstall scriptlet (using <lua>):
-- 8<---snip---8<
function update_gconv_modules_cache ()
  local iconv_dir = "/usr/lib64/gconv"
  local iconv_cache = iconv_dir .. "/gconv-modules.cache"
  local iconv_modules = iconv_dir .. "/gconv-modules"
  if posix.utime(iconv_modules) == 0 then
    if posix.utime (iconv_cache) == 0 then
      post_exec ("Error: call to /usr/sbin/iconvconfig failed.n",
                 "/usr/sbin/iconvconfig",
                 "-o", iconv_cache,
                 "--nostdlib",
                 iconv_dir)
    else
      io.stdout:write ("Error: Missing " .. iconv_cache .. " file.n")
    end
  end
end
-- (1) Update /etc/ld.so.conf
-- Next we update /etc/ld.so.conf to ensure that it starts with
-- a literal "include ld.so.conf.d/*.conf".

local ldsoconf = "/etc/ld.so.conf"
local ldsoconf_tmp = "/etc/glibc_post_upgrade.ld.so.conf"

if posix.access (ldsoconf) then

  -- We must have a "include ld.so.conf.d/*.conf" line.
  local have_include = false
  for line in io.lines (ldsoconf) do
    -- This must match, and we don't ignore whitespace.
    if string.match (line, "^include ld.so.conf.d/%*%.conf$") ~= nil then
      have_include = true
    end
  end

  if not have_include then
    -- Insert "include ld.so.conf.d/*.conf" line at the start of the
    -- file. We only support one of these post upgrades running at
    -- a time (temporary file name is fixed).
    local tmp_fd = io.open (ldsoconf_tmp, "w")
    if tmp_fd ~= nil then
      tmp_fd:write ("include ld.so.conf.d/*.conf\n")
      for line in io.lines (ldsoconf) do
        tmp_fd:write (line .. "\n")
      end
      tmp_fd:close ()
      local res = os.rename (ldsoconf_tmp, ldsoconf)
      if res == nil then
        io.stdout:write ("Error: Unable to update configuration file 
(rename).\n")
      end
    else
      io.stdout:write ("Error: Unable to update configuration file (open).\n")
    end
  end
end
-- 8<---snip---8<
```

The difference seems to be that the lines towards the end, like these:

```lua
  if not have_include then
    -- Insert "include ld.so.conf.d/*.conf" line at the start of the
    -- file. We only support one of these post upgrades running at
    -- a time (temporary file name is fixed).
    local tmp_fd = io.open (ldsoconf_tmp, "w")
    if tmp_fd ~= nil then
      tmp_fd:write ("include ld.so.conf.d/*.conf\n")
      for line in io.lines (ldsoconf) do
        tmp_fd:write (line .. "\n")
      end
      tmp_fd:close ()
      local res = os.rename (ldsoconf_tmp, ldsoconf)
      if res == nil then
        io.stdout:write ("Error: Unable to update configuration file 
(rename).\n")
      end
    else
      io.stdout:write ("Error: Unable to update configuration file (open).\n")
    end
```

...are defined directly in the `%post -p <lua>` section of the spec.

The earlier lines (the same code that also appears in the `--filetriggers` 
output) are defined in a `%global` macro using `%{expand:`, which is then 
included in the `%post -p <lua>` and `%transfiletriggerin common -P 2000000 -p 
<lua> -- /lib /usr/lib /lib64 /usr/lib64` / `%transfiletriggerpostun common -P 
2000000 -p <lua> -- /lib /usr/lib /lib64 /usr/lib64` definitions.

```rpm-spec
%global glibc_post_funcs %{expand:
-- We use lua because there may be no shell that we can run during
-- glibc upgrade. We used to implement much of %%post as a C program,
-- but from an overall maintenance perspective the lua in the spec
-- file was simpler and safer given the operations required.
-- All lua code will be ignored by rpm-ostree; see:
-- https://github.com/projectatomic/rpm-ostree/pull/1869
-- If we add new lua actions to the %%post code we should coordinate
-- with rpm-ostree and ensure that their glibc install is functional.
-- We must not use rpm.execute because this is a RPM 4.15 features and
-- we must still support downstream bootstrap with RPM 4.14 and missing
-- containerized boostrap.

-- Open-code rpm.execute with error message handling.
function post_exec (msg, program, ...)
  if rpm.spawn ~= nil then
    local status = rpm.spawn ({program, ...})
    if status == nil then
      io.stdout:write (msg)
      assert (nil)
    end
  else
    local pid = posix.fork ()
    if pid == 0 then
      posix.exec (program, ...)
      io.stdout:write (msg)
      assert (nil)
    elseif pid > 0 then
      posix.wait (pid)
    end
  end
end

function call_ldconfig ()
  post_exec("Error: call to ldconfig failed.\n",
            "ldconfig")
end

function update_gconv_modules_cache ()
  local iconv_dir = "%{_libdir}/gconv"
  local iconv_cache = iconv_dir .. "/gconv-modules.cache"
  local iconv_modules = iconv_dir .. "/gconv-modules"
  if posix.utime(iconv_modules) == 0 then
    if posix.utime (iconv_cache) == 0 then
      post_exec ("Error: call to %{_prefix}/sbin/iconvconfig failed.\n",
                 "%{_prefix}/sbin/iconvconfig",
                 "-o", iconv_cache,
                 "--nostdlib",
                 iconv_dir)
    else
      io.stdout:write ("Error: Missing " .. iconv_cache .. " file.\n")
    end
  end
end}
```

```rpm-spec
%transfiletriggerin common -P 2000000 -p <lua> -- /lib /usr/lib /lib64 
/usr/lib64
%glibc_post_funcs
call_ldconfig()
%end

%transfiletriggerpostun common -P 2000000 -p <lua> -- /lib /usr/lib /lib64 
/usr/lib64
%glibc_post_funcs
call_ldconfig()
%end
```

```
%post -p <lua>
%glibc_post_funcs
-- (...rest of code...)
```


-- 
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/3661#issuecomment-2727579502
You are receiving this because you are subscribed to this thread.

Message ID: <rpm-software-management/rpm/issues/3661/[email protected]>
_______________________________________________
Rpm-maint mailing list
[email protected]
https://lists.rpm.org/mailman/listinfo/rpm-maint

Reply via email to