- Add posix.redirect2null

- Resolves: #1287918
This commit is contained in:
Lubos Kardos 2016-03-10 15:31:16 +01:00
parent 6fa824a46b
commit 0b025ec5a1
2 changed files with 76 additions and 1 deletions

View File

@ -0,0 +1,71 @@
From 19fe0d9ae12644b8af9513aa2a8cf7d16f7caa61 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Fri, 4 Mar 2016 16:40:30 -0500
Subject: [PATCH] Add posix.redirect2null
This is useful to silence output in forked programs:
https://bugzilla.redhat.com/show_bug.cgi?id=1287918
Tested with the following scriptlet:
%post -p <lua>
pid = posix.fork()
if pid == 0 then
assert(posix.exec("/bin/sed"))
elseif pid > 0 then
posix.wait(pid)
end
pid = posix.fork()
if pid == 0 then
posix.redirect2null(2)
assert(posix.exec("/bin/awk"))
elseif pid > 0 then
posix.wait(pid)
end
As expected, the error message from sed is printed, the error message
from awk is not.
---
luaext/lposix.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/luaext/lposix.c b/luaext/lposix.c
index 51ea2b3..c578c5a 100644
--- a/luaext/lposix.c
+++ b/luaext/lposix.c
@@ -819,6 +819,25 @@ static int Pmkstemp(lua_State *L)
return 2;
}
+static int Predirect2null(lua_State *L)
+{
+ int target_fd, fd, r, e;
+
+ if (!have_forked)
+ return luaL_error(L, "silence_file_descriptor not permitted in this context");
+
+ target_fd = luaL_checkinteger(L, 1);
+
+ r = fd = open("/dev/null", O_WRONLY);
+ if (fd >= 0 && fd != target_fd) {
+ r = dup2(fd, target_fd);
+ e = errno;
+ (void) close(fd);
+ errno = e;
+ }
+ return pushresult(L, r, NULL);
+}
+
static const luaL_Reg R[] =
{
{"access", Paccess},
@@ -861,6 +880,7 @@ static const luaL_Reg R[] =
{"wait", Pwait},
{"setenv", Psetenv},
{"unsetenv", Punsetenv},
+ {"redirect2null", Predirect2null},
{NULL, NULL}
};
--
1.9.3

View File

@ -29,7 +29,7 @@
Summary: The RPM package management system
Name: rpm
Version: %{rpmver}
Release: %{?snapver:0.%{snapver}.}26%{?dist}
Release: %{?snapver:0.%{snapver}.}27%{?dist}
Group: System Environment/Base
Url: http://www.rpm.org/
Source0: http://rpm.org/releases/rpm-4.12.x/%{name}-%{srcver}.tar.bz2
@ -72,6 +72,7 @@ Patch116: rpm-4.13.0-idle-and-sleep-in-systemd-inhibit.patch
Patch117: rpm-4.13.0-add-mipsr6-support.patch
Patch118: rpm-4.13.0-Use-pkg-dpaths-during-dependency-generation.patch
Patch119: rpm-4.13.0-Noarch-ExclusiveArch.patch
Patch120: rpm-4.13.0-redirect2null.patch
# These are not yet upstream
Patch302: rpm-4.7.1-geode-i686.patch
@ -583,6 +584,9 @@ exit 0
%doc doc/librpm/html/*
%changelog
* Thu Mar 10 2016 Lubos Kardos <lkardos@redhat.com> 4.13.0-0.rc1.27
- Add posix.redirect2null (#1287918)
* Fri Feb 26 2016 Florian Festi <ffesti@rpm.org> - 4.4.13.0-0.rc1.26
- Fix ExclusiveArch/ExcludeArch for noarch packages (#1298668)