1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
/* process.c -- Keep status of a process
*
* This file is part of TUA.
*
* Copyright (C) 1991,96 Lele Gaifax
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the license, or (at
* your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
/* I keep track of a per process info, storing such info in a tree keyed on
* the process id. Although this is not unique, it should be enough because
* at a single time (and probably in a day) this number will be unique. */
#include "tua.h"
static BTREE Root = NULL;
static int
DEFUN (process_compare, (proc1, proc2),
CONST process_status_t * proc1 AND CONST process_status_t * proc2)
{
int ret;
if (proc1->ProcessId < proc2->ProcessId)
ret = -1;
else if (proc1->ProcessId == proc2->ProcessId)
ret = 0;
else
ret = 1;
return ret;
}
static PTR
DEFUN (process_new, (data),
CONST PTR data)
{
process_status_t *p;
p = (process_status_t *) xmalloc (sizeof (process_status_t));
p->ProcessId = ((CONST process_status_t *) data)->ProcessId;
p->Killed = FALSE;
p->System = 0;
p->Status = TUUS_NONE;
p->LoginPassed = FALSE;
#if HDB_UUCP
p->StartTime = p->EndTime = 0;
#endif
return (PTR) p;
}
process_status_t *
DEFUN (insert_process, (procId),
int procId)
{
process_status_t p, *new_proc;
if (Root == NULL)
Root = btree_new ((compare_func_t) process_compare, (makenew_func_t) process_new);
p.ProcessId = procId;
new_proc = (process_status_t *) btree_insert (Root, &p);
if (new_proc->Killed)
{
new_proc->Killed = FALSE;
new_proc->System = 0;
new_proc->Status = TUUS_NONE;
#if HDB_UUCP
new_proc->StartTime = new_proc->EndTime = 0.0;
#endif
}
return new_proc;
}
void
DEFUN (kill_process, (procId),
int procId)
{
process_status_t p;
p.ProcessId = procId;
if (Root != NULL)
{
process_status_t * found = (process_status_t *) btree_search (Root, &p);
if (found)
found->Killed = TRUE;
}
}
static traverse_func_t originalTraverseFunction;
static void
DEFUN (FilteredEnquiry, (proc),
CONST process_status_t * proc)
{
if (! proc->Killed)
(*originalTraverseFunction) (proc);
}
void
DEFUN (enquire_processes, (funct),
traverse_func_t funct)
{
originalTraverseFunction = funct;
btree_traverse (Root, (traverse_func_t) FilteredEnquiry);
}
|