/* **********************************************************************
 * *                                                                    *
 * *       Routine to Test Translation from Message Catalogs            *
 * *                                                                    *
 * **********************************************************************
 * File: /libs/user/test2.c
 *
 *                        COPYRIGHT (c) 1993  BY
 *          SIGMET INCORPORATED, WESTFORD MASSACHUSETTS, U.S.A.
 * 
 * THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED
 * ONLY  IN  ACCORDANCE WITH  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE
 * INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE  OR  ANY OTHER
 * COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
 * OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY
 * TRANSFERED.
 */
#include <errno.h>
#include <locale.h>
#include <signal.h>
#include <stdio.h>
#include <sys/wait.h>
#include <unistd.h>
#define INCLUDE_UNISTD_PROTOTYPES 1
#include "sigtypes.h"
#include "user_lib.h"

/* ==========================================================================
 * Simple test program, reusable.
 */
void watchdog(pid_t iPid_a);

int main( int iargc, char **sargv )
{

  int iReturn;
  /* ------------------------------------------------------------
   */
  if( !setlocale(LC_ALL, "") )
    {
      printf("Setlocale failed, using C locale.\n") ;
    }


  iReturn = sig_system_int("sleep 4", watchdog );
  fprintf( stdout, "Returned:%d, errno:%d\n", iReturn, errno );
  if (iReturn==-1)
    fprintf(stdout, "Meaning:Error\n" );
  else
    {
      fprintf( stdout, "Exit:%d, signal:%d\n", WIFEXITED(iReturn), WIFSIGNALED(iReturn) );
      if (WIFEXITED(iReturn))   fprintf( stdout, "Exit status:%d\n", WEXITSTATUS(iReturn) );
      if (WIFSIGNALED(iReturn)) fprintf( stdout, "Signal:%d\n", WTERMSIG(iReturn) );
    }

  sleep(10);

  fprintf( stdout, "Done\n" );

  return(0) ;
}
void watchdog(pid_t iPid_a)
{
  sleep(3);
  kill(iPid_a,SIGKILL);

  return;
}
