Index: trunk/src/sh_prelink.c
===================================================================
--- trunk/src/sh_prelink.c	(revision 583)
+++ trunk/src/sh_prelink.c	(revision 1)
@@ -38,6 +38,7 @@
 static char * prelink_hash = NULL;
 
-int sh_prelink_set_path (const char * str)
-{
+int sh_prelink_set_path (char * str)
+{
+  size_t len;
   SL_ENTER(_("sh_prelink_set_path"));
   if (prelink_path != NULL)
@@ -48,14 +49,11 @@
       SL_RETURN((-1), _("sh_prelink_set_path")); 
     }
-#ifdef SH_EVAL_SHELL
-  prelink_path = sh_util_strdup(str);
+  len = sl_strlen (str);
+  prelink_path = SH_ALLOC(len+1);
+  (void) sl_strlcpy(prelink_path, str, len+1);
   SL_RETURN(0, _("sh_prelink_set_path")); 
-#else
-  prelink_path = NULL;
-  SL_RETURN((-1), _("sh_prelink_set_path"));
-#endif
-}
-
-int sh_prelink_set_hash (const char * str)
+}
+
+int sh_prelink_set_hash (char * str)
 {
   size_t len;
@@ -74,37 +72,23 @@
 }
 
-int sh_prelink_iself (SL_TICKET fd, off_t size, int alert_timeout, char * path)
-{
-  long   status;
-  char   magic[4];
-  char * tmp;
-
-  /* 42 bytes is about the minimum an ELF binary might have
-   * (with plenty of hacks to reduce the size, such as interleaving
-   * the code with the header...)
-   */
-  if (size < 42)
-    return S_FALSE;
-
-  status = sl_read_timeout (fd, magic, 4, alert_timeout, S_FALSE);
-  (void) sl_rewind(fd);
-  if (status == 4)
-    {
-      /*@-usedef@*/
-      if (magic[0] == (char) 0x7f &&
-	  magic[1] == 'E'  &&
-	  magic[2] == 'L'  &&
-	  magic[3] == 'F')
-	return S_TRUE;
-      /*@+usedef@*/
-    }
-  else
-    {
-      tmp = sh_util_safe_name (path);
-      sh_error_handle(SH_ERR_ERR, FIL__, __LINE__, status, MSG_E_SUBGPATH, 
-		      _("Error reading file"), _("sh_prelink_iself"), tmp);
-      SH_FREE(path);
-    }
-  return S_FALSE;
+int sh_prelink_iself (SL_TICKET fd, off_t size, int alert_timeout)
+{
+   long status;
+   char magic[4];
+   if (size < 42)
+	return S_FALSE;
+   status = sl_read_timeout (fd, magic, 4, alert_timeout);
+   (void) sl_rewind(fd);
+   if (status == 4)
+     {
+       /*@-usedef@*/
+       if (magic[0] == (char) 0x7f &&
+	   magic[1] == 'E'  &&
+	   magic[2] == 'L'  &&
+	   magic[3] == 'F')
+	 return S_TRUE;
+       /*@+usedef@*/
+     }
+   return S_FALSE;
 }
 
@@ -115,5 +99,4 @@
   SL_TICKET ticket;
   char * tmp;
-  char hashbuf[KEYBUF_SIZE];
 
   if (task->com_ti != (-1))
@@ -123,21 +106,17 @@
       task->com_ti = -1;
     }
-  ticket = sl_open_read(FIL__, __LINE__, task->command, 
+  ticket = sl_open_read(task->command, 
 			task->privileged == 0 ? SL_NOPRIV : SL_YESPRIV);
   if (SL_ISERROR(ticket))
     {
-      char errbuf[SH_ERRBUF_SIZE];
-      char errbuf2[SH_ERRBUF_SIZE];
-      sh_error_message(errno, errbuf2, sizeof(errbuf2));
-      sl_strlcpy(errbuf, sl_error_string(ticket), sizeof(errbuf));
       tmp = sh_util_safe_name (task->command);
-      sh_error_handle(SH_ERR_ERR, FIL__, __LINE__, ticket, MSG_E_READ, errbuf, errbuf2, tmp);
+      sh_error_handle(SH_ERR_ERR, FIL__, __LINE__, ticket, MSG_E_READ, tmp);
       SH_FREE(tmp);
       return;
     }
-
+  tiger_fd = ticket;
   if (*(task->checksum) == '\0' ||
       0 == sl_strcmp(task->checksum, 
-		     sh_tiger_hash (task->command, ticket, TIGER_NOLIM, hashbuf, sizeof(hashbuf))))
+		     sh_tiger_hash (task->command, TIGER_FD, 0)))
     {
       task->com_fd = get_the_fd(ticket);
@@ -156,5 +135,5 @@
 /* returns static storage
  */
-int sh_prelink_run (char * path, char * file_hash, int alert_timeout, unsigned long mask)
+int sh_prelink_run (char * path, char * file_hash, int alert_timeout)
 {
   static int      init = S_FALSE;
@@ -164,4 +143,6 @@
   int    status = 0;
   char * p;
+  struct  sigaction  new_act;
+  struct  sigaction  old_act;
 
   SL_ENTER(_("sh_prelink_run"));
@@ -185,8 +166,6 @@
   if (init == S_FALSE)
     {
-      char dir[SH_PATHBUF];
-
       sh_ext_tas_init(&task);
-      p = sh_unix_getUIDdir (SH_ERR_ERR, task.run_user_uid, dir, sizeof(dir));
+      p = sh_unix_getUIDdir (SH_ERR_ERR, task.run_user_uid);
       if (p)
 	{
@@ -255,17 +234,18 @@
     }
 
+  /* ignore SIGPIPE (instead get EPIPE if connection is closed)
+   */
+  new_act.sa_handler = SIG_IGN;
+  (void) retry_sigaction (FIL__, __LINE__, SIGPIPE, &new_act, &old_act);
+
   /* read from pipe
    */
-  sl_read_timeout_prep (task.pipeTI);
-
-  {
-    char hashbuf[KEYBUF_SIZE];
-    UINT64 length_nolim = TIGER_NOLIM;
-    if (sh.flag.opts == S_TRUE) sh_tiger_set_hashtype_mask(mask);
-    sl_strlcpy(file_hash,
-	       sh_tiger_generic_hash (path, task.pipeTI, &length_nolim, alert_timeout,
-				      hashbuf, sizeof(hashbuf)),
-	       KEY_LEN+1);
-  }
+  tiger_fd = task.pipeTI;
+  strcpy(file_hash,                        /* known to fit */
+	 sh_tiger_generic_hash (path, TIGER_FD, 0, alert_timeout));
+
+  /* restore old signal handler
+   */
+  (void) retry_sigaction (FIL__, __LINE__, SIGPIPE, &old_act, NULL);
 
   /* close pipe and return exit status
