3 * PROJECT: ReactOS Operating System / POSIX Environment Subsystem
5 * --------------------------------------------------------------------
7 * This software is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this software; see the file COPYING. If not, write
19 * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
22 * --------------------------------------------------------------------
28 #define NTOS_MODE_USER
30 #include <sm/helper.h>
34 /**********************************************************************
38 PsxCheckSubSystem (LPCSTR argv0
)
40 NTSTATUS Status
= STATUS_SUCCESS
;
41 UNICODE_STRING DirectoryName
= {0, 0, NULL
};
42 OBJECT_ATTRIBUTES DirectoryAttributes
= {0};
43 HANDLE hDir
= (HANDLE
) 0;
45 RtlInitUnicodeString (& DirectoryName
, L
"\\POSIX");
46 InitializeObjectAttributes (& DirectoryAttributes
,
49 Status
= NtOpenDirectoryObject (& hDir
,
51 & DirectoryAttributes
);
52 if(NT_SUCCESS(Status
))
60 /**********************************************************************
64 PsxBootstrap (LPCSTR argv0
)
66 NTSTATUS Status
= STATUS_SUCCESS
;
67 UNICODE_STRING Program
= {0, 0, NULL
};
68 HANDLE SmApiPort
= (HANDLE
) 0;
71 printf("Connecting to the SM: ");
72 Status
= SmConnectApiPort (NULL
,
74 IMAGE_SUBSYSTEM_UNKNOWN
,
76 if(!NT_SUCCESS(Status
))
78 fprintf(stderr
,"\n%s: SmConnectApiPort failed with 0x%08lx\n",
82 RtlInitUnicodeString (& Program
, L
"POSIX");
83 Status
= SmExecuteProgram (SmApiPort
, & Program
);
84 if(STATUS_SUCCESS
!= Status
)
86 fprintf(stderr
, "%s: SmExecuteProgram = %08lx\n", argv0
, Status
);
92 /**********************************************************************
96 *********************************************************************/
97 int main (int argc
, char * argv
[])
99 NTSTATUS Status
= STATUS_SUCCESS
;
100 INT RetryCount
= RETRY_COUNT
;
102 while(RetryCount
> 0)
104 Status
= PsxCheckSubSystem (argv
[0]);
105 if(STATUS_SUCCESS
== Status
)
107 if (RETRY_COUNT
== RetryCount
)
109 fprintf(stderr
,"POSIX already booted.\n");
111 fprintf(stderr
,"POSIX booted.\n");
115 Status
= PsxBootstrap (argv
[0]);
119 return NT_SUCCESS(Status
) ? EXIT_SUCCESS
: EXIT_FAILURE
;