mirror of
https://github.com/FAUSheppy/colorredstderr-mirror
synced 2025-12-09 16:38:32 +01:00
Hook vfork() and replace it with fork().
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
TESTS = run.sh
|
||||
check_PROGRAMS = example
|
||||
check_PROGRAMS = example example_vfork
|
||||
example_SOURCES = example.c
|
||||
example_vfork_SOURCES = example_vfork.c
|
||||
|
||||
dist_check_SCRIPTS = run.sh lib.sh
|
||||
dist_check_DATA = example.expected \
|
||||
example_vfork.expected \
|
||||
example-noforce.sh \
|
||||
example-noforce.sh.expected \
|
||||
example-redirects.sh \
|
||||
|
||||
43
tests/example_vfork.c
Normal file
43
tests/example_vfork.c
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Test issues with vfork().
|
||||
*
|
||||
* Copyright (C) 2013 Simon Ruderich
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
pid_t pid;
|
||||
|
||||
fprintf(stderr, "Before vfork().\n");
|
||||
|
||||
pid = vfork();
|
||||
if (pid == 0) {
|
||||
/* This violates the POSIX standard! The "child" is only allowed to
|
||||
* modify the result of vfork(), e.g. the pid variable. Some programs
|
||||
* (e.g. gdb) do it anyway so we have to workaround it. */
|
||||
dup2(STDOUT_FILENO, STDERR_FILENO);
|
||||
|
||||
_exit(2);
|
||||
}
|
||||
|
||||
fprintf(stderr, "After vfork().\n");
|
||||
puts("");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
3
tests/example_vfork.expected
Normal file
3
tests/example_vfork.expected
Normal file
@@ -0,0 +1,3 @@
|
||||
>stderr>Before vfork().
|
||||
<stderr<>stderr>After vfork().
|
||||
<stderr<
|
||||
@@ -33,3 +33,4 @@ force_write=1
|
||||
test_script example-simple.sh
|
||||
test_script example-redirects.sh
|
||||
test_program example
|
||||
test_program example_vfork
|
||||
|
||||
Reference in New Issue
Block a user