2004-09-08 10:08:45 -05:00
|
|
|
/* $RCSfile: quit.c,v $
|
2008-03-05 11:29:56 -06:00
|
|
|
-- $Revision: 1.8 $
|
|
|
|
-- last change: $Author: kz $ $Date: 2008-03-05 18:29:56 $
|
2000-09-22 09:33:37 -05:00
|
|
|
--
|
|
|
|
-- SYNOPSIS
|
|
|
|
-- End the dmake session.
|
|
|
|
--
|
|
|
|
-- DESCRIPTION
|
|
|
|
-- Handles dmake termination.
|
|
|
|
--
|
|
|
|
-- AUTHOR
|
|
|
|
-- Dennis Vadura, dvadura@dmake.wticorp.com
|
|
|
|
--
|
|
|
|
-- WWW
|
|
|
|
-- http://dmake.wticorp.com/
|
|
|
|
--
|
|
|
|
-- COPYRIGHT
|
|
|
|
-- Copyright (c) 1996,1997 by WTI Corp. All rights reserved.
|
|
|
|
--
|
|
|
|
-- This program is NOT free software; you can redistribute it and/or
|
|
|
|
-- modify it under the terms of the Software License Agreement Provided
|
|
|
|
-- in the file <distribution-root>/readme/license.txt.
|
|
|
|
--
|
|
|
|
-- LOG
|
|
|
|
-- Use cvs log to obtain detailed change logs.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "extern.h"
|
|
|
|
|
|
|
|
static void _handle_quit ANSI((char*));
|
2007-01-18 02:32:09 -06:00
|
|
|
static int _quitting = 0; /* Set to 1 once Quit() is called for the
|
|
|
|
* first time. */
|
2000-09-22 09:33:37 -05:00
|
|
|
|
|
|
|
|
|
|
|
PUBLIC void
|
2006-04-20 06:01:52 -05:00
|
|
|
Quit( sig )/*
|
2000-09-22 09:33:37 -05:00
|
|
|
======== Error or quit */
|
2006-04-20 06:01:52 -05:00
|
|
|
int sig;
|
2000-09-22 09:33:37 -05:00
|
|
|
{
|
2011-01-19 14:32:02 -06:00
|
|
|
int ret = ERROR_ABORT_VALUE;
|
|
|
|
|
2007-01-18 02:32:09 -06:00
|
|
|
if( sig == SIGINT )
|
|
|
|
fprintf(stderr, "Caught SIGINT. Trying to quit ...\n");
|
2007-10-15 09:41:12 -05:00
|
|
|
else
|
|
|
|
#ifdef SIGQUIT
|
|
|
|
/* MinGW, maybe others also, does not have SIGQUIT. */
|
|
|
|
if( sig == SIGQUIT )
|
2007-01-18 02:32:09 -06:00
|
|
|
fprintf(stderr, "Caught SIGQUIT. Trying to quit ...\n");
|
2007-10-15 09:41:12 -05:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if( sig == 0 )
|
2007-01-18 02:32:09 -06:00
|
|
|
/* Don't be verbose during regular program termination. */
|
2011-01-19 14:32:02 -06:00
|
|
|
ret = ERROR_EXIT_VALUE;
|
2007-01-18 02:32:09 -06:00
|
|
|
else
|
|
|
|
fprintf(stderr, "Caught signal %d. Trying to quit ...\n", sig);
|
|
|
|
|
|
|
|
if( _quitting ) return; /* Guard to only quit once. */
|
2008-03-05 11:29:56 -06:00
|
|
|
_quitting = 1;
|
2000-09-22 09:33:37 -05:00
|
|
|
|
|
|
|
while( Closefile() != NIL( FILE ) );
|
2007-01-18 02:32:09 -06:00
|
|
|
|
|
|
|
/* CTRL-c sends SIGINT and CTRL-\ sends SIGQUIT to the parent and to all
|
|
|
|
* children. No need to kill them. */
|
2007-10-15 09:41:12 -05:00
|
|
|
if( sig != SIGINT
|
|
|
|
#ifdef SIGQUIT
|
|
|
|
/* MinGW, maybe others also, does not have SIGQUIT. */
|
|
|
|
&& sig != SIGQUIT
|
|
|
|
#endif
|
|
|
|
)
|
2007-01-18 02:32:09 -06:00
|
|
|
/* This should be called Kill_all_processes(). */
|
|
|
|
Clean_up_processes();
|
|
|
|
|
|
|
|
/* Wait until all Processes are done. */
|
|
|
|
while( Wait_for_child(TRUE, -1) != -1 )
|
|
|
|
;
|
2000-09-22 09:33:37 -05:00
|
|
|
|
|
|
|
if( Current_target != NIL(CELL) )
|
|
|
|
Unlink_temp_files(Current_target);
|
|
|
|
|
2007-01-18 02:32:09 -06:00
|
|
|
if( _quitting == 0 ) _handle_quit( ".ERROR" );
|
2000-09-22 09:33:37 -05:00
|
|
|
|
|
|
|
Set_dir( Makedir ); /* No Error message if we can't do it */
|
2011-01-19 14:32:02 -06:00
|
|
|
Epilog( ret );
|
2000-09-22 09:33:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-20 06:01:52 -05:00
|
|
|
PUBLIC const int
|
|
|
|
in_quit( void )/*
|
|
|
|
=================
|
|
|
|
Called to check if we are already quitting.
|
|
|
|
(Only used in unix/runargv.c.) */
|
2002-10-11 07:42:49 -05:00
|
|
|
{
|
2007-01-18 02:32:09 -06:00
|
|
|
return _quitting;
|
2002-10-11 07:42:49 -05:00
|
|
|
}
|
|
|
|
|
2000-09-22 09:33:37 -05:00
|
|
|
static void
|
|
|
|
_handle_quit( err_target )/*
|
|
|
|
============================
|
2007-01-18 02:32:09 -06:00
|
|
|
Called by Quit() to handle the execution of termination code
|
2000-09-22 09:33:37 -05:00
|
|
|
from within make */
|
|
|
|
char *err_target;
|
|
|
|
{
|
|
|
|
HASHPTR hp;
|
|
|
|
CELLPTR cp;
|
|
|
|
|
|
|
|
if( (hp = Get_name(err_target, Defs, FALSE)) != NIL(HASH) ) {
|
|
|
|
cp = hp->CP_OWNR;
|
|
|
|
Glob_attr |= A_IGNORE;
|
|
|
|
|
|
|
|
cp->ce_flag |= F_TARGET;
|
|
|
|
Make( cp, NIL(CELL) );
|
2007-01-18 02:32:09 -06:00
|
|
|
|
|
|
|
/* Beware! If the ".ERROR" target doesn't finish the following
|
|
|
|
* wait will never return!!! */
|
|
|
|
while( Wait_for_child(FALSE, -1) != -1 );
|
|
|
|
|
2000-09-22 09:33:37 -05:00
|
|
|
}
|
|
|
|
}
|