home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / ixemul-45.0-src.tgz / tar.out / contrib / ixemul / library / ix_close.c < prev    next >
C/C++ Source or Header  |  1996-10-01  |  4KB  |  142 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License as published by the Free Software Foundation; either
  8.  *  version 2 of the License, or (at your option) any later version.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public
  16.  *  License along with this library; if not, write to the Free
  17.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #define _KERNEL
  21. #include "ixemul.h"
  22. #include "kprintf.h"
  23. #include <hardware/intbits.h>
  24. #include "multiuser.h"
  25.   
  26. void
  27. __ix_close_muFS( struct user *ix_u )
  28. {
  29.   if (ix_u->u_UserInfo)
  30.   {
  31.     muFreeUserInfo(ix_u->u_UserInfo);
  32.     ix_u->u_UserInfo = NULL;
  33.   }
  34.  
  35.   if (ix_u->u_fileUserInfo)
  36.   {
  37.     muFreeUserInfo(ix_u->u_fileUserInfo);
  38.     ix_u->u_fileUserInfo = NULL;
  39.   }
  40.  
  41.   if (ix_u->u_GroupInfo)
  42.   {
  43.     muFreeGroupInfo(ix_u->u_GroupInfo);
  44.     ix_u->u_GroupInfo = NULL;
  45.   }
  46.  
  47.   if (ix_u->u_fileGroupInfo)
  48.   {
  49.     muFreeGroupInfo(ix_u->u_fileGroupInfo);
  50.     ix_u->u_fileGroupInfo = NULL;
  51.   }
  52.  
  53.   /* log me out */
  54.   while (u.u_setuid--)
  55.     muLogout(muT_Quiet, TRUE, TAG_DONE);
  56. }
  57.  
  58. void
  59. ix_close (struct ixemul_base *ixbase)
  60. {
  61.   struct Task         *me      =    SysBase->ThisTask;
  62.   struct user         *ix_u     =    (struct user *) me->tc_TrapData;
  63.   struct Process    *child;
  64.   struct user        *cu;
  65.   struct Node        *dm, *ndm;    /* really struct death_msg * */
  66.  
  67.   RemIntServer (INTB_VERTB, &ix_u->u_itimerint);
  68.   /* already reset the trap vector here. It's better to get an alert than
  69.    * to loop infinitely if one of the following functions should crash */
  70.   me->tc_TrapCode = ix_u->u_otrap_code;
  71.   
  72.   freestack();
  73.  
  74.   /* had to move this block after the SYS_close's, since close() might have
  75.      to wait for a packet, and then it's essential that our switch/launch
  76.      handlers are still active */
  77.   me->tc_Flags    = ix_u->u_otask_flags;
  78.   me->tc_Launch      = ix_u->u_olaunch;
  79.   me->tc_Switch   = ix_u->u_oswitch;
  80.   FreeSignal (ix_u->u_sleep_sig);
  81.   FreeSignal (ix_u->u_pipe_sig);
  82.  
  83.   if (ix_u->u_ixnetbase)
  84.     {
  85.       CloseLibrary (ix_u->u_ixnetbase);
  86.     }
  87.  
  88.   CloseDevice ((struct IORequest *) ix_u->u_time_req);
  89.   syscall (SYS_DeleteExtIO, ix_u->u_time_req);
  90.   
  91.   if (ix_u->u_startup_cd != (BPTR) -1)
  92.     {
  93.       __unlock (CurrentDir (ix_u->u_startup_cd));
  94.       set_dir_name_from_lock(ix_u->u_startup_cd);
  95.     }
  96.  
  97.   ix_u->u_trace_flags = 1;
  98.   DeletePort (ix_u->u_select_mp);
  99.   DeletePort (ix_u->u_sync_mp);
  100.  
  101.   /* try to free it here */
  102.   __ix_close_muFS(ix_u);
  103.  
  104.   for ((child = ix_u->p_cptr); child; (child = cu->p_osptr))
  105.     {
  106.       cu = (struct user *)child->pr_Task.tc_TrapData;
  107.       cu->p_pptr = (struct Process *) 1;
  108.     }
  109.  
  110.   ix_u->p_cptr = 0;
  111.  
  112.   /* decrease session count and possibly free the session structure */
  113.   if (ix_u->u_session)
  114.     {
  115.       if (ix_u->u_session->pgrp == (int)me)
  116.         ix_u->u_session->pgrp = 0;
  117.       if (ix_u->u_session->s_count-- <= 1)
  118.         kfree(ix_u->u_session);
  119.     }
  120.   
  121.   for (dm  = (struct Node *) ix_u->p_zombies.mlh_Head;
  122.        (ndm = dm->ln_Succ);
  123.        dm  = ndm)
  124.     {
  125.       /* there might be children sleeping on this, so wake them up now.. */
  126.       ix_wakeup ((u_int)dm);
  127.       kfree (dm);
  128.     }
  129.  
  130.   FreeSignal (ix_u->p_zombie_sig);
  131.  
  132.   all_free ();
  133.   if (ix_u->p_flag & SFREEA4)
  134.     kfree ((void *)(ix_u->u_a4 - 0x7ffe));
  135.  
  136.   /* delay this until here, since the above called functions need access
  137.    * to the user area. */
  138.   me->tc_TrapData = ix_u->u_otrap_data;
  139.  
  140.   kfree (((char *)ix_u) - ix_u->u_a4_pointers_size * 4);
  141. }
  142.