Blame tests/deleted.c

Packit 032894
/* Test program for opening already deleted running binaries.
Packit 032894
   Copyright (C) 2014 Red Hat, Inc.
Packit 032894
   This file is part of elfutils.
Packit 032894
Packit 032894
   This file is free software; you can redistribute it and/or modify
Packit 032894
   it under the terms of the GNU General Public License as published by
Packit 032894
   the Free Software Foundation; either version 3 of the License, or
Packit 032894
   (at your option) any later version.
Packit 032894
Packit 032894
   elfutils is distributed in the hope that it will be useful, but
Packit 032894
   WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 032894
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 032894
   GNU General Public License for more details.
Packit 032894
Packit 032894
   You should have received a copy of the GNU General Public License
Packit 032894
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit 032894
Packit 032894
#include <config.h>
Packit 032894
#include <locale.h>
Packit 032894
#include <stdlib.h>
Packit 032894
#include <unistd.h>
Packit 032894
#include <assert.h>
Packit 032894
#include <stdio.h>
Packit 032894
#include <errno.h>
Packit 032894
#ifdef __linux__
Packit 032894
#include <sys/prctl.h>
Packit 032894
#endif
Packit 032894
Packit 032894
extern void libfunc (void);
Packit 032894
Packit 032894
int
Packit 032894
main (int argc __attribute__ ((unused)), char **argv __attribute__ ((unused)))
Packit 032894
{
Packit 032894
  /* Set locale.  */
Packit 032894
  (void) setlocale (LC_ALL, "");
Packit 032894
Packit 032894
  pid_t pid = fork ();
Packit 032894
  assert (pid != -1);
Packit 032894
  if (pid == 0)
Packit 032894
    {
Packit 032894
      int err = close (0);
Packit 032894
      assert (!err);
Packit 032894
      err = close (1);
Packit 032894
      assert (!err);
Packit 032894
      err = close (2);
Packit 032894
      assert (!err);
Packit 032894
      /* Make sure eu-stack -p works on this process even with
Packit 032894
	 "restricted ptrace".  */
Packit 032894
#ifdef PR_SET_PTRACER_ANY
Packit 032894
      prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0, 0, 0);
Packit 032894
#endif
Packit 032894
      libfunc ();
Packit 032894
      abort ();
Packit 032894
    }
Packit 032894
  printf ("%d\n", pid);
Packit 032894
  return EXIT_SUCCESS;
Packit 032894
}