Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
2.4 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. session.c
  5. Abstract:
  6. This module contains the worker routines called by the Sb API Request
  7. routines.
  8. Author:
  9. Steve Wood (stevewo) 04-Oct-1989
  10. Revision History:
  11. 15-Jul-91: Modified for POSIX subsystem.
  12. --*/
  13. #include "psxsrv.h"
  14. NTSTATUS
  15. PsxInitializeNtSessionList( VOID )
  16. {
  17. NTSTATUS Status;
  18. Status = RtlInitializeCriticalSection( &PsxNtSessionLock );
  19. return( Status );
  20. }
  21. RTL_CRITICAL_SECTION ConnectingTerminalListMutex;
  22. LIST_ENTRY ConnectingTerminalList;
  23. NTSTATUS
  24. InitConnectingTerminalList(
  25. VOID
  26. )
  27. {
  28. NTSTATUS Status;
  29. InitializeListHead(&ConnectingTerminalList);
  30. Status = RtlInitializeCriticalSection(&ConnectingTerminalListMutex);
  31. return Status;
  32. }
  33. //
  34. // AddConnectingTerminal - a new terminal has connected to the posix
  35. // subsystem, but has not yet asked to have a process created to
  36. // be the session leader. We keep track of the information about
  37. // the terminal in the ConnectingTerminalList until we have a process
  38. // structure to put it in.
  39. //
  40. NTSTATUS
  41. AddConnectingTerminal(
  42. int Id,
  43. HANDLE CommPort,
  44. HANDLE ReqPort
  45. )
  46. {
  47. PPSX_CONTROLLING_TTY Terminal;
  48. Terminal = RtlAllocateHeap(PsxHeap, 0, sizeof(*Terminal));
  49. if (NULL == Terminal) {
  50. return STATUS_NO_MEMORY;
  51. }
  52. Terminal->ReferenceCount = 1;
  53. Terminal->UniqueId = Id;
  54. Terminal->ConsoleCommPort = CommPort;
  55. Terminal->ConsolePort = ReqPort;
  56. RtlInitializeCriticalSection(&Terminal->Lock);
  57. RtlEnterCriticalSection(&ConnectingTerminalListMutex);
  58. InsertHeadList(&ConnectingTerminalList, &Terminal->Links);
  59. RtlLeaveCriticalSection(&ConnectingTerminalListMutex);
  60. return STATUS_SUCCESS;
  61. }
  62. //
  63. // GetConnectingTerminal - the terminal with the given id has requested
  64. // a process for session leader, so remove it from the list and return
  65. // it. NULL is returned if the terminal is not on the list.
  66. //
  67. PPSX_CONTROLLING_TTY
  68. GetConnectingTerminal(
  69. int Id
  70. )
  71. {
  72. PPSX_CONTROLLING_TTY Terminal;
  73. RtlEnterCriticalSection(&ConnectingTerminalListMutex);
  74. for (Terminal = (PVOID)ConnectingTerminalList.Flink;
  75. Terminal != (PVOID)&ConnectingTerminalList;
  76. Terminal = (PVOID)Terminal->Links.Flink) {
  77. if ((unsigned int)Id == Terminal->UniqueId) {
  78. RemoveEntryList(&Terminal->Links);
  79. Terminal->Links.Flink = Terminal->Links.Blink = NULL;
  80. RtlLeaveCriticalSection(&ConnectingTerminalListMutex);
  81. return Terminal;
  82. }
  83. }
  84. RtlLeaveCriticalSection(&ConnectingTerminalListMutex);
  85. return NULL;
  86. }