Comment 20 for bug 1479093

Revision history for this message
Norman Wilson (norma7) wrote :

Here is a simpler example program:

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <wait.h>

int
main(argc, argv)
int argc;
char **argv;
{
 int pid, rpid;
 int st;

 if (argc < 2) {
  fprintf(stderr, "usage: %s command ...\n", argv[0]);
  return (1);
 }
 if ((pid = fork()) < 0) {
  fprintf(stderr, "fork: %s\n", strerror(errno));
  return (1);
 }
 if (pid == 0) {
  execvp(argv[1], &argv[1]);
  fprintf(stderr, "exec: %s\n", strerror(errno));
  return (1);
 }
 while ((rpid = wait(&st)) > 0 && rpid != pid)
  ;
 if (rpid < 0) {
  fprintf(stderr, "wait: %s\n", strerror(errno));
  return (1);
 }
 printf("status 0x%x\n", st);
 return (0);
}

There is some header-file fumble that prevents me from compiling this with cc -m32, but there are both 32- and 64-bit systems in our environment, so:

Using kernel 3.13.0-59:

Compile it on a 64-bit system, and run
      ./forkexec date
and all is well.

Compile it on a 32-bit system, then, on a 64-bit system, run
    ./forkexec date
and date prints nothing, while forkexec reports exit status 0x8b.

On the other hand, still on the 64-bit system, point it at a 32-bit binary and all is well. e.g.
   ./forkexec ./forkexec
just prints the expected usage: message, so it execed itself properly; no SIGSEGV.

To confound matters further:
-- take out the fork (so the program just calls exec) and all is well
-- run the program under strace -f and the problem vanishes

All this happens under kernel 3.13.0-59 but not 3.13.0-55 (we've put off a few updates).