Siddhesh Poyarekar 17b00f
#include <sys types.h="">
Siddhesh Poyarekar 17b00f
#include <sys wait.h="">
Siddhesh Poyarekar 17b00f
#include <stdio.h>
Siddhesh Poyarekar 17b00f
#include <errno.h>
Siddhesh Poyarekar 17b00f
#include <unistd.h>
Siddhesh Poyarekar 17b00f
#include <sys time.h="">
Siddhesh Poyarekar 17b00f
#include <dirent.h>
Siddhesh Poyarekar 17b00f
#include <stddef.h>
Siddhesh Poyarekar 17b00f
#include <fcntl.h>
Siddhesh Poyarekar 17b00f
#include <string.h>
Siddhesh Poyarekar 17b00f
#include <sys stat.h="">
Siddhesh Poyarekar 17b00f
#include <elf.h>
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
#define verbose_exec(failcode, path...) \
Siddhesh Poyarekar 17b00f
  do							\
Siddhesh Poyarekar 17b00f
    {							\
Siddhesh Poyarekar 17b00f
      char *const arr[] = { path, NULL };		\
Siddhesh Poyarekar 17b00f
      vexec (failcode, arr);				\
Siddhesh Poyarekar 17b00f
    } while (0)
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
__attribute__((noinline)) void vexec (int failcode, char *const path[]);
Siddhesh Poyarekar 17b00f
__attribute__((noinline)) void says (const char *str);
Siddhesh Poyarekar 17b00f
__attribute__((noinline)) void sayn (long num);
Siddhesh Poyarekar 17b00f
__attribute__((noinline)) void message (char *const path[]);
Siddhesh Poyarekar 17b00f
__attribute__((noinline)) int check_elf (const char *name);
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
#ifdef __i386__
Siddhesh Poyarekar 17b00f
static int
Siddhesh Poyarekar 17b00f
is_ia64 (void)
Siddhesh Poyarekar 17b00f
{
Siddhesh Poyarekar 17b00f
  unsigned int fl1, fl2;
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
  /* See if we can use cpuid.  */
Siddhesh Poyarekar 17b00f
  __asm__ ("pushfl; pushfl; popl %0; movl %0,%1; xorl %2,%0;"
Siddhesh Poyarekar 17b00f
	   "pushl %0; popfl; pushfl; popl %0; popfl"
Siddhesh Poyarekar 17b00f
	   : "=&r" (fl1), "=&r" (fl2)
Siddhesh Poyarekar 17b00f
	   : "i" (0x00200000));
Siddhesh Poyarekar 17b00f
  if (((fl1 ^ fl2) & 0x00200000) == 0)
Siddhesh Poyarekar 17b00f
    return 0;
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
  /* Host supports cpuid.  See if cpuid gives capabilities, try
Siddhesh Poyarekar 17b00f
     CPUID(0).  Preserve %ebx and %ecx; cpuid insn clobbers these, we
Siddhesh Poyarekar 17b00f
     don't need their CPUID values here, and %ebx may be the PIC
Siddhesh Poyarekar 17b00f
     register.  */
Siddhesh Poyarekar 17b00f
  __asm__ ("pushl %%ecx; pushl %%ebx; cpuid; popl %%ebx; popl %%ecx"
Siddhesh Poyarekar 17b00f
	   : "=a" (fl1) : "0" (0) : "edx", "cc");
Siddhesh Poyarekar 17b00f
  if (fl1 == 0)
Siddhesh Poyarekar 17b00f
    return 0;
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
  /* Invoke CPUID(1), return %edx; caller can examine bits to
Siddhesh Poyarekar 17b00f
     determine what's supported.  */
Siddhesh Poyarekar 17b00f
  __asm__ ("pushl %%ecx; pushl %%ebx; cpuid; popl %%ebx; popl %%ecx"
Siddhesh Poyarekar 17b00f
	   : "=d" (fl2), "=a" (fl1) : "1" (1) : "cc");
Siddhesh Poyarekar 17b00f
  return (fl2 & (1 << 30)) != 0;
Siddhesh Poyarekar 17b00f
}
Siddhesh Poyarekar 17b00f
#else
Siddhesh Poyarekar 17b00f
#define is_ia64() 0
Siddhesh Poyarekar 17b00f
#endif
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
int
Siddhesh Poyarekar 17b00f
main (void)
Siddhesh Poyarekar 17b00f
{
Siddhesh Poyarekar 17b00f
  struct stat statbuf;
Siddhesh Poyarekar 17b00f
  char initpath[256];
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
  char buffer[4096];
Siddhesh Poyarekar 17b00f
  struct pref {
Siddhesh Poyarekar 17b00f
    char *p;
Siddhesh Poyarekar 17b00f
    int len;
Siddhesh Poyarekar 17b00f
  } prefix[] = { { "libc-", 5 }, { "libm-", 5 },
Siddhesh Poyarekar 17b00f
		 { "librt-", 6 }, { "libpthread-", 11 },
Siddhesh Poyarekar 17b00f
		 { "librtkaio-", 10 }, { "libthread_db-", 13 } };
Siddhesh Poyarekar 17b00f
  int i, j, fd;
Siddhesh Poyarekar 17b00f
  off_t base;
Siddhesh Poyarekar 17b00f
  ssize_t ret;
Siddhesh Poyarekar 17b00f
#ifdef __i386__
Siddhesh Poyarekar 17b00f
  const char *remove_dirs[] = { "/lib/tls", "/lib/i686", "/lib/tls/i486", "/lib/tls/i586", "/lib/tls/i686" };
Siddhesh Poyarekar 17b00f
#else
Siddhesh Poyarekar 17b00f
#ifndef LIBTLS
Siddhesh Poyarekar 17b00f
#define LIBTLS "/lib/tls"
Siddhesh Poyarekar 17b00f
#endif
Siddhesh Poyarekar 17b00f
  const char *remove_dirs[] = { LIBTLS };
Siddhesh Poyarekar 17b00f
#endif
Siddhesh Poyarekar 17b00f
  for (j = 0; j < sizeof (remove_dirs) / sizeof (remove_dirs[0]); ++j)
Siddhesh Poyarekar 17b00f
    {
Siddhesh Poyarekar 17b00f
      size_t rmlen = strlen (remove_dirs[j]);
Siddhesh Poyarekar 17b00f
      fd = open (remove_dirs[j], O_RDONLY);
Siddhesh Poyarekar 17b00f
      if (fd >= 0
Siddhesh Poyarekar 17b00f
	  && (ret = getdirentries (fd, buffer, sizeof (buffer), &base))
Siddhesh Poyarekar 17b00f
	     >= (ssize_t) offsetof (struct dirent, d_name))
Siddhesh Poyarekar 17b00f
	{
Siddhesh Poyarekar 17b00f
	  for (base = 0; base + offsetof (struct dirent, d_name) < ret; )
Siddhesh Poyarekar 17b00f
	    {
Siddhesh Poyarekar 17b00f
	      struct dirent *d = (struct dirent *) (buffer + base);
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
	      for (i = 0; i < sizeof (prefix) / sizeof (prefix[0]); i++)
Siddhesh Poyarekar 17b00f
		if (! strncmp (d->d_name, prefix[i].p, prefix[i].len))
Siddhesh Poyarekar 17b00f
		  {
Siddhesh Poyarekar 17b00f
		    char *p = d->d_name + prefix[i].len;
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
		    while (*p == '.' || (*p >= '0' && *p <= '9')) p++;
Siddhesh Poyarekar 17b00f
		    if (p[0] == 's' && p[1] == 'o' && p[2] == '\0'
Siddhesh Poyarekar 17b00f
			&& p + 3 - d->d_name
Siddhesh Poyarekar 17b00f
			   < sizeof (initpath) - rmlen - 1)
Siddhesh Poyarekar 17b00f
		      {
Siddhesh Poyarekar 17b00f
			memcpy (initpath, remove_dirs[j], rmlen);
Siddhesh Poyarekar 17b00f
			initpath[rmlen] = '/';
Siddhesh Poyarekar 17b00f
			strcpy (initpath + rmlen + 1, d->d_name);
Siddhesh Poyarekar 17b00f
			unlink (initpath);
Siddhesh Poyarekar 17b00f
			break;
Siddhesh Poyarekar 17b00f
		      }
Siddhesh Poyarekar 17b00f
		  }
Siddhesh Poyarekar 17b00f
	      base += d->d_reclen;
Siddhesh Poyarekar 17b00f
	    }
Siddhesh Poyarekar 17b00f
	  close (fd);
Siddhesh Poyarekar 17b00f
	}
Siddhesh Poyarekar 17b00f
    }
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
  int ldsocfd = open (LD_SO_CONF, O_RDONLY);
Siddhesh Poyarekar 17b00f
  struct stat ldsocst;
Siddhesh Poyarekar 17b00f
  if (ldsocfd >= 0 && fstat (ldsocfd, &ldsocst) >= 0)
Siddhesh Poyarekar 17b00f
    {
Siddhesh Poyarekar 17b00f
      char p[ldsocst.st_size + 1];
Siddhesh Poyarekar 17b00f
      if (read (ldsocfd, p, ldsocst.st_size) == ldsocst.st_size)
Siddhesh Poyarekar 17b00f
	{
Siddhesh Poyarekar 17b00f
	  p[ldsocst.st_size] = '\0';
Siddhesh Poyarekar 17b00f
	  if (strstr (p, "include ld.so.conf.d/*.conf") == NULL)
Siddhesh Poyarekar 17b00f
	    {
Siddhesh Poyarekar 17b00f
	      close (ldsocfd);
Siddhesh Poyarekar 17b00f
	      ldsocfd = open (LD_SO_CONF, O_WRONLY | O_TRUNC);
Siddhesh Poyarekar 17b00f
	      if (ldsocfd >= 0)
Siddhesh Poyarekar 17b00f
		{
Siddhesh Poyarekar 17b00f
		  size_t slen = strlen ("include ld.so.conf.d/*.conf\n");
Siddhesh Poyarekar 17b00f
		  if (write (ldsocfd, "include ld.so.conf.d/*.conf\n", slen)
Siddhesh Poyarekar 17b00f
		      != slen
Siddhesh Poyarekar 17b00f
		      || write (ldsocfd, p, ldsocst.st_size) != ldsocst.st_size)
Siddhesh Poyarekar 17b00f
		    _exit (109);
Siddhesh Poyarekar 17b00f
		}
Siddhesh Poyarekar 17b00f
	    }
Siddhesh Poyarekar 17b00f
	}
Siddhesh Poyarekar 17b00f
      if (ldsocfd >= 0)
Siddhesh Poyarekar 17b00f
	close (ldsocfd);
Siddhesh Poyarekar 17b00f
    }
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
  /* If installing bi-arch glibc, rpm sometimes doesn't unpack all files
Siddhesh Poyarekar 17b00f
     before running one of the lib's %post scriptlet.  /sbin/ldconfig will
Siddhesh Poyarekar 17b00f
     then be run by the other arch's %post.  */
Siddhesh Poyarekar 17b00f
  if (! access ("/sbin/ldconfig", X_OK))
Siddhesh Poyarekar 17b00f
    verbose_exec (110, "/sbin/ldconfig", "/sbin/ldconfig");
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
  if (! utimes (GCONV_MODULES_DIR "/gconv-modules.cache", NULL))
Siddhesh Poyarekar 17b00f
    {
Siddhesh Poyarekar 17b00f
#ifndef ICONVCONFIG
Siddhesh Poyarekar 17b00f
#define ICONVCONFIG "/usr/sbin/iconvconfig"
Siddhesh Poyarekar 17b00f
#endif
Carlos O'Donell 0457f6
      char *iconv_cache = GCONV_MODULES_DIR"/gconv-modules.cache";
Carlos O'Donell 0457f6
      char *iconv_dir = GCONV_MODULES_DIR;
Siddhesh Poyarekar 17b00f
      if (is_ia64 ())
Siddhesh Poyarekar 17b00f
	{
Siddhesh Poyarekar 17b00f
	  iconv_cache = "/emul/ia32-linux"GCONV_MODULES_DIR"/gconv-modules.cache";
Siddhesh Poyarekar 17b00f
	  iconv_dir = "/emul/ia32-linux"GCONV_MODULES_DIR;
Siddhesh Poyarekar 17b00f
	}
Siddhesh Poyarekar 17b00f
      verbose_exec (113, ICONVCONFIG, "/usr/sbin/iconvconfig",
Siddhesh Poyarekar 17b00f
		    "-o", iconv_cache,
Siddhesh Poyarekar 17b00f
		    "--nostdlib", iconv_dir);
Siddhesh Poyarekar 17b00f
    }
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
  /* Check if telinit is available and either SysVInit fifo,
Siddhesh Poyarekar 17b00f
     or upstart telinit.  */
Siddhesh Poyarekar 17b00f
  if (access ("/sbin/telinit", X_OK)
Siddhesh Poyarekar 17b00f
      || ((!!access ("/dev/initctl", F_OK))
Siddhesh Poyarekar 17b00f
	  ^ !access ("/sbin/initctl", X_OK)))
Siddhesh Poyarekar 17b00f
    _exit (0);
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
  /* Check if we are not inside of some chroot, because we'd just
Siddhesh Poyarekar 17b00f
     timeout and leave /etc/initrunlvl.
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
     On more modern systems this test is not sufficient to detect
Siddhesh Poyarekar 17b00f
     if we're in a chroot.  */
Siddhesh Poyarekar 17b00f
  if (readlink ("/proc/1/exe", initpath, 256) <= 0 ||
Siddhesh Poyarekar 17b00f
      readlink ("/proc/1/root", initpath, 256) <= 0)
Siddhesh Poyarekar 17b00f
    _exit (0);
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
  /* Here's another well known way to detect chroot, at least on an
Siddhesh Poyarekar 17b00f
     ext and xfs filesystems and assuming nothing mounted on the chroot's
Siddhesh Poyarekar 17b00f
     root. */
Siddhesh Poyarekar 17b00f
  if (stat ("/", &statbuf) != 0
Siddhesh Poyarekar 17b00f
      || (statbuf.st_ino != 2
Siddhesh Poyarekar 17b00f
	  && statbuf.st_ino != 128))
Siddhesh Poyarekar 17b00f
    _exit (0);
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
  if (check_elf ("/proc/1/exe"))
Siddhesh Poyarekar 17b00f
    verbose_exec (116, "/sbin/telinit", "/sbin/telinit", "u");
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
  /* Check if we can safely condrestart sshd.  */
Siddhesh Poyarekar 17b00f
  if (access ("/sbin/service", X_OK) == 0
Siddhesh Poyarekar 17b00f
      && access ("/usr/sbin/sshd", X_OK) == 0
Siddhesh Poyarekar 17b00f
      && access ("/etc/rc.d/init.d/sshd", X_OK) == 0
Siddhesh Poyarekar 17b00f
      && access ("/bin/bash", X_OK) == 0)
Siddhesh Poyarekar 17b00f
    {
Siddhesh Poyarekar 17b00f
      if (check_elf ("/usr/sbin/sshd"))
Siddhesh Poyarekar 17b00f
	verbose_exec (-121, "/sbin/service", "/sbin/service", "sshd", "condrestart");
Siddhesh Poyarekar 17b00f
    }
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
  _exit(0);
Siddhesh Poyarekar 17b00f
}
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
void
Siddhesh Poyarekar 17b00f
vexec (int failcode, char *const path[])
Siddhesh Poyarekar 17b00f
{
Siddhesh Poyarekar 17b00f
  pid_t pid;
Siddhesh Poyarekar 17b00f
  int status, save_errno;
Siddhesh Poyarekar 17b00f
  int devnull = 0;
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
  if (failcode < 0)
Siddhesh Poyarekar 17b00f
    {
Siddhesh Poyarekar 17b00f
      devnull = 1;
Siddhesh Poyarekar 17b00f
      failcode = -failcode;
Siddhesh Poyarekar 17b00f
    }
Siddhesh Poyarekar 17b00f
  pid = vfork ();
Siddhesh Poyarekar 17b00f
  if (pid == 0)
Siddhesh Poyarekar 17b00f
    {
Siddhesh Poyarekar 17b00f
      int fd;
Siddhesh Poyarekar 17b00f
      if (devnull && (fd = open ("/dev/null", O_WRONLY)) >= 0)
Siddhesh Poyarekar 17b00f
	{
Siddhesh Poyarekar 17b00f
	  dup2 (fd, 1);
Siddhesh Poyarekar 17b00f
	  dup2 (fd, 2);
Siddhesh Poyarekar 17b00f
	  close (fd);
Siddhesh Poyarekar 17b00f
	}
Siddhesh Poyarekar 17b00f
      execv (path[0], path + 1);
Siddhesh Poyarekar 17b00f
      save_errno = errno;
Siddhesh Poyarekar 17b00f
      message (path);
Siddhesh Poyarekar 17b00f
      says (" exec failed with errno ");
Siddhesh Poyarekar 17b00f
      sayn (save_errno);
Siddhesh Poyarekar 17b00f
      says ("\n");
Siddhesh Poyarekar 17b00f
      _exit (failcode);
Siddhesh Poyarekar 17b00f
    }
Siddhesh Poyarekar 17b00f
  else if (pid < 0)
Siddhesh Poyarekar 17b00f
    {
Siddhesh Poyarekar 17b00f
      save_errno = errno;
Siddhesh Poyarekar 17b00f
      message (path);
Siddhesh Poyarekar 17b00f
      says (" fork failed with errno ");
Siddhesh Poyarekar 17b00f
      sayn (save_errno);
Siddhesh Poyarekar 17b00f
      says ("\n");
Siddhesh Poyarekar 17b00f
      _exit (failcode + 1);
Siddhesh Poyarekar 17b00f
    }
Siddhesh Poyarekar 17b00f
  if (waitpid (0, &status, 0) != pid || !WIFEXITED (status))
Siddhesh Poyarekar 17b00f
    {
Siddhesh Poyarekar 17b00f
      message (path);
Siddhesh Poyarekar 17b00f
      says (" child terminated abnormally\n");
Siddhesh Poyarekar 17b00f
      _exit (failcode + 2);
Siddhesh Poyarekar 17b00f
    }
Siddhesh Poyarekar 17b00f
  if (WEXITSTATUS (status))
Siddhesh Poyarekar 17b00f
    {
Siddhesh Poyarekar 17b00f
      message (path);
Siddhesh Poyarekar 17b00f
      says (" child exited with exit code ");
Siddhesh Poyarekar 17b00f
      sayn (WEXITSTATUS (status));
Siddhesh Poyarekar 17b00f
      says ("\n");
Siddhesh Poyarekar 17b00f
      _exit (WEXITSTATUS (status));
Siddhesh Poyarekar 17b00f
    }
Siddhesh Poyarekar 17b00f
}
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
void
Siddhesh Poyarekar 17b00f
says (const char *str)
Siddhesh Poyarekar 17b00f
{
Siddhesh Poyarekar 17b00f
  write (1, str, strlen (str));
Siddhesh Poyarekar 17b00f
}
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
void
Siddhesh Poyarekar 17b00f
sayn (long num)
Siddhesh Poyarekar 17b00f
{
Siddhesh Poyarekar 17b00f
  char string[sizeof (long) * 3 + 1];
Siddhesh Poyarekar 17b00f
  char *p = string + sizeof (string) - 1;
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
  *p = '\0';
Siddhesh Poyarekar 17b00f
  if (num == 0)
Siddhesh Poyarekar 17b00f
    *--p = '0';
Siddhesh Poyarekar 17b00f
  else
Siddhesh Poyarekar 17b00f
    while (num)
Siddhesh Poyarekar 17b00f
      {
Siddhesh Poyarekar 17b00f
	*--p = '0' + num % 10;
Siddhesh Poyarekar 17b00f
	num = num / 10;
Siddhesh Poyarekar 17b00f
      }
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
  says (p);
Siddhesh Poyarekar 17b00f
}
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
void
Siddhesh Poyarekar 17b00f
message (char *const path[])
Siddhesh Poyarekar 17b00f
{
Siddhesh Poyarekar 17b00f
  says ("/usr/sbin/glibc_post_upgrade: While trying to execute ");
Siddhesh Poyarekar 17b00f
  says (path[0]);
Siddhesh Poyarekar 17b00f
}
Siddhesh Poyarekar 17b00f
Siddhesh Poyarekar 17b00f
int
Siddhesh Poyarekar 17b00f
check_elf (const char *name)
Siddhesh Poyarekar 17b00f
{
Siddhesh Poyarekar 17b00f
  /* Play safe, if we can't open or read, assume it might be
Siddhesh Poyarekar 17b00f
     ELF for the current arch.  */
Siddhesh Poyarekar 17b00f
  int ret = 1;
Siddhesh Poyarekar 17b00f
  int fd = open (name, O_RDONLY);
Siddhesh Poyarekar 17b00f
  if (fd >= 0)
Siddhesh Poyarekar 17b00f
    {
Siddhesh Poyarekar 17b00f
      Elf32_Ehdr ehdr;
Siddhesh Poyarekar 17b00f
      if (read (fd, &ehdr, offsetof (Elf32_Ehdr, e_version))
Siddhesh Poyarekar 17b00f
	  == offsetof (Elf32_Ehdr, e_version))
Siddhesh Poyarekar 17b00f
	{
Siddhesh Poyarekar 17b00f
	  ret = 0;
Siddhesh Poyarekar 17b00f
	  if (ehdr.e_ident[EI_CLASS]
Siddhesh Poyarekar 17b00f
	      == (sizeof (long) == 8 ? ELFCLASS64 : ELFCLASS32))
Siddhesh Poyarekar 17b00f
	    {
Siddhesh Poyarekar 17b00f
#if defined __i386__
Siddhesh Poyarekar 17b00f
	      ret = ehdr.e_machine == EM_386;
Siddhesh Poyarekar 17b00f
#elif defined __x86_64__
Siddhesh Poyarekar 17b00f
	      ret = ehdr.e_machine == EM_X86_64;
Siddhesh Poyarekar 17b00f
#elif defined __ia64__
Siddhesh Poyarekar 17b00f
	      ret = ehdr.e_machine == EM_IA_64;
Siddhesh Poyarekar 17b00f
#elif defined __powerpc64__
Siddhesh Poyarekar 17b00f
	      ret = ehdr.e_machine == EM_PPC64;
Siddhesh Poyarekar 17b00f
#elif defined __powerpc__
Siddhesh Poyarekar 17b00f
	      ret = ehdr.e_machine == EM_PPC;
Siddhesh Poyarekar 17b00f
#elif defined __s390__ || defined __s390x__
Siddhesh Poyarekar 17b00f
	      ret = ehdr.e_machine == EM_S390;
Siddhesh Poyarekar 17b00f
#elif defined __x86_64__
Siddhesh Poyarekar 17b00f
	      ret = ehdr.e_machine == EM_X86_64;
Siddhesh Poyarekar 17b00f
#elif defined __sparc__
Siddhesh Poyarekar 17b00f
	      if (sizeof (long) == 8)
Siddhesh Poyarekar 17b00f
		ret = ehdr.e_machine == EM_SPARCV9;
Siddhesh Poyarekar 17b00f
	      else
Siddhesh Poyarekar 17b00f
		ret = (ehdr.e_machine == EM_SPARC
Siddhesh Poyarekar 17b00f
		       || ehdr.e_machine == EM_SPARC32PLUS);
Siddhesh Poyarekar 17b00f
#else
Siddhesh Poyarekar 17b00f
	      ret = 1;
Siddhesh Poyarekar 17b00f
#endif
Siddhesh Poyarekar 17b00f
	    }
Siddhesh Poyarekar 17b00f
	}
Siddhesh Poyarekar 17b00f
      close (fd);
Siddhesh Poyarekar 17b00f
    }
Siddhesh Poyarekar 17b00f
  return ret;
Siddhesh Poyarekar 17b00f
}