Port-amiga archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Reproducible panic in NetBSD-6
Michael van Elst wrote:
>>The only non-Amiga m68k I have is a Mac running NetBSD 6, and it
>>compiled m4 just fine. Hmmm...
>
>
> That crash seems to be easily reproducable by the posix_spawn test.
True, but the problem cannot be isolated. I tried to extract the posix_spawn
test source from the configure script and compiled it on my Amiga. But it
worked!
Source is attached.
--
Frank Wille
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <spawn.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
extern char **environ;
#ifndef STDIN_FILENO
# define STDIN_FILENO 0
#endif
#ifndef STDOUT_FILENO
# define STDOUT_FILENO 1
#endif
#ifndef STDERR_FILENO
# define STDERR_FILENO 2
#endif
#ifndef WTERMSIG
# define WTERMSIG(x) ((x) & 0x7f)
#endif
#ifndef WIFEXITED
# define WIFEXITED(x) (WTERMSIG (x) == 0)
#endif
#ifndef WEXITSTATUS
# define WEXITSTATUS(x) (((x) >> 8) & 0xff)
#endif
#define CHILD_PROGRAM_FILENAME "/non/exist/ent"
static int
fd_safer (int fd)
{
if (0 <= fd && fd <= 2)
{
int f = fd_safer (dup (fd));
int e = errno;
close (fd);
errno = e;
fd = f;
}
return fd;
}
int
main ()
{
char *argv[2] = { CHILD_PROGRAM_FILENAME, NULL };
int ofd[2];
sigset_t blocked_signals;
sigset_t fatal_signal_set;
posix_spawn_file_actions_t actions;
bool actions_allocated;
posix_spawnattr_t attrs;
bool attrs_allocated;
int err;
pid_t child;
int status;
int exitstatus;
setvbuf (stdout, NULL, _IOFBF, 0);
puts ("This should be seen only once.");
if (pipe (ofd) < 0 || (ofd[1] = fd_safer (ofd[1])) < 0)
{
perror ("cannot create pipe");
exit (1);
}
sigprocmask (SIG_SETMASK, NULL, &blocked_signals);
sigemptyset (&fatal_signal_set);
sigaddset (&fatal_signal_set, SIGINT);
sigaddset (&fatal_signal_set, SIGTERM);
sigaddset (&fatal_signal_set, SIGHUP);
sigaddset (&fatal_signal_set, SIGPIPE);
sigprocmask (SIG_BLOCK, &fatal_signal_set, NULL);
actions_allocated = false;
attrs_allocated = false;
if ((err = posix_spawn_file_actions_init (&actions)) != 0
|| (actions_allocated = true,
(err = posix_spawn_file_actions_adddup2 (&actions, ofd[0],
STDIN_FILENO)) != 0
|| (err = posix_spawn_file_actions_addclose (&actions, ofd[0])) != 0
|| (err = posix_spawn_file_actions_addclose (&actions, ofd[1])) != 0
|| (err = posix_spawnattr_init (&attrs)) != 0
|| (attrs_allocated = true,
(err = posix_spawnattr_setsigmask (&attrs, &blocked_signals)) != 0
|| (err = posix_spawnattr_setflags (&attrs,
POSIX_SPAWN_SETSIGMASK)) != 0)
|| (err = posix_spawnp (&child, CHILD_PROGRAM_FILENAME, &actions,
&attrs, argv, environ)) != 0))
{
if (actions_allocated)
posix_spawn_file_actions_destroy (&actions);
if (attrs_allocated)
posix_spawnattr_destroy (&attrs);
sigprocmask (SIG_UNBLOCK, &fatal_signal_set, NULL);
if (err == ENOENT)
return 0;
else
{
errno = err;
perror ("subprocess failed");
exit (1);
}
}
posix_spawn_file_actions_destroy (&actions);
posix_spawnattr_destroy (&attrs);
sigprocmask (SIG_UNBLOCK, &fatal_signal_set, NULL);
close (ofd[0]);
close (ofd[1]);
status = 0;
while (waitpid (child, &status, 0) != child)
;
if (!WIFEXITED (status))
{
fprintf (stderr, "subprocess terminated with unexpected wait status
%d\n", status);
exit (1);
}
exitstatus = WEXITSTATUS (status);
if (exitstatus != 127)
{
fprintf (stderr, "subprocess terminated with unexpected exit status
%d\n", exitstatus);
exit (1);
}
return 0;
}
Home |
Main Index |
Thread Index |
Old Index