home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / gcc / ixemulsrc.lha / ixemul / library / ix_close.c < prev    next >
C/C++ Source or Header  |  1996-12-11  |  4KB  |  150 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 (muBase)
  30.     {
  31.       if (ix_u->u_UserInfo)
  32.         {
  33.           muFreeUserInfo(ix_u->u_UserInfo);
  34.           ix_u->u_UserInfo = NULL;
  35.         }
  36.  
  37.       if (ix_u->u_fileUserInfo)
  38.         {
  39.           muFreeUserInfo(ix_u->u_fileUserInfo);
  40.           ix_u->u_fileUserInfo = NULL;
  41.         }
  42.  
  43.       if (ix_u->u_GroupInfo)
  44.         {
  45.           muFreeGroupInfo(ix_u->u_GroupInfo);
  46.          ix_u->u_GroupInfo = NULL;
  47.         }
  48.  
  49.       if (ix_u->u_fileGroupInfo)
  50.         {
  51.           muFreeGroupInfo(ix_u->u_fileGroupInfo);
  52.           ix_u->u_fileGroupInfo = NULL;
  53.         }
  54.  
  55.       /* log me out */
  56.       while (ix_u->u_setuid--)
  57.         muLogout(muT_Quiet, TRUE, TAG_DONE);
  58.     }
  59. }
  60.  
  61. void
  62. ix_close (struct ixemul_base *ixbase)
  63. {
  64.   struct Task         *me = SysBase->ThisTask;
  65.   struct user         *ix_u =    getuser(me);
  66.   struct Process    *child;
  67.   struct user        *cu;
  68.   struct Node        *dm, *ndm;    /* really struct death_msg * */
  69.  
  70.   RemIntServer (INTB_VERTB, &ix_u->u_itimerint);
  71.  
  72. #ifndef NOTRAP
  73.   /* already reset the trap vector here. It's better to get an alert than
  74.    * to loop infinitely if one of the following functions should crash */
  75.   me->tc_TrapCode = ix_u->u_otrap_code;
  76. #endif
  77.   
  78.   freestack();
  79.  
  80.   /* had to move this block after the SYS_close's, since close() might have
  81.      to wait for a packet, and then it's essential that our switch/launch
  82.      handlers are still active */
  83.   me->tc_Flags    = ix_u->u_otask_flags;
  84.   me->tc_Launch      = ix_u->u_olaunch;
  85.   me->tc_Switch   = ix_u->u_oswitch;
  86.   FreeSignal (ix_u->u_sleep_sig);
  87.   FreeSignal (ix_u->u_pipe_sig);
  88.  
  89.   if (ix_u->u_ixnetbase)
  90.     {
  91.       CloseLibrary (ix_u->u_ixnetbase);
  92.     }
  93.  
  94.   CloseDevice ((struct IORequest *) ix_u->u_time_req);
  95.   syscall (SYS_DeleteExtIO, ix_u->u_time_req);
  96.   
  97.   if (ix_u->u_startup_cd != (BPTR) -1)
  98.     {
  99.       __unlock (CurrentDir (ix_u->u_startup_cd));
  100.       set_dir_name_from_lock(ix_u->u_startup_cd);
  101.     }
  102.  
  103.   ix_u->u_trace_flags = 1;
  104.   DeletePort (ix_u->u_select_mp);
  105.   DeletePort (ix_u->u_sync_mp);
  106.  
  107.   /* try to free it here */
  108.   __ix_close_muFS(ix_u);
  109.  
  110.   for ((child = ix_u->p_cptr); child; (child = cu->p_osptr))
  111.     {
  112.       cu = getuser(child);
  113.       cu->p_pptr = (struct Process *) 1;
  114.     }
  115.  
  116.   ix_u->p_cptr = 0;
  117.  
  118.   /* decrease session count and possibly free the session structure */
  119.   if (ix_u->u_session)
  120.     {
  121.       if (ix_u->u_session->pgrp == (int)me)
  122.         ix_u->u_session->pgrp = 0;
  123.       if (ix_u->u_session->s_count-- <= 1)
  124.         kfree(ix_u->u_session);
  125.     }
  126.   
  127.   for (dm  = (struct Node *) ix_u->p_zombies.mlh_Head;
  128.        (ndm = dm->ln_Succ);
  129.        dm  = ndm)
  130.     {
  131.       /* there might be children sleeping on this, so wake them up now.. */
  132.       ix_wakeup ((u_int)dm);
  133.       kfree (dm);
  134.     }
  135.  
  136.   FreeSignal (ix_u->p_zombie_sig);
  137.  
  138.   all_free ();
  139.   if (ix_u->p_flag & SFREEA4)
  140.     kfree ((void *)(ix_u->u_a4 - 0x7ffe));
  141.  
  142. #ifndef NOTRAP
  143.   /* delay this until here, since the above called functions need access
  144.    * to the user area. */
  145.   getuser(me) = ix_u->u_otrap_data;
  146. #endif
  147.  
  148.   kfree (((char *)ix_u) - ix_u->u_a4_pointers_size * 4);
  149. }
  150.