@@ -96,18 +96,42 @@ int main(int argc, char **argv) {
96
96
load_config ();
97
97
if (!StartServiceCtrlDispatcherW (dispatch_table )) {
98
98
if (GetLastError () == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT ) {
99
- if (argc == 1 ) {
100
- /* console app - start in debug mode*/
99
+ /*todo - support debug mode*/
100
+ /*
101
+ if (debugmode) {
101
102
SetConsoleCtrlHandler(ctrl_c_handler, TRUE);
102
103
log_init("ssh-agent", 7, 1, 1);
103
104
agent_start(TRUE, FALSE, 0, 0);
104
105
return 0;
105
106
}
106
- else {
107
+ */
108
+ if (argc == 2 ) {
109
+ /*agent process is likely a spawned child*/
107
110
char * h = 0 ;
108
111
h += atoi (* (argv + 1 ));
109
- log_init ("ssh-agent" , config_log_level (), 1 , 0 );
110
- agent_start (FALSE, TRUE, h , atoi (* (argv + 2 )));
112
+ if (h != 0 ) {
113
+ log_init ("ssh-agent" , config_log_level (), 1 , 0 );
114
+ agent_start (FALSE, TRUE, h , atoi (* (argv + 2 )));
115
+ return 0 ;
116
+ }
117
+ }
118
+ /* to support linux compat scenarios where ssh-agent.exe is typically launched per session*/
119
+ /* - just start ssh-agent service if needed */
120
+ {
121
+ SC_HANDLE sc_handle , svc_handle ;
122
+ DWORD err ;
123
+
124
+ if ((sc_handle = OpenSCManagerW (NULL , NULL , SERVICE_START )) == NULL ||
125
+ (svc_handle = OpenServiceW (sc_handle , L"ssh-agent" , SERVICE_START )) == NULL ){
126
+ fatal ("unable to open service handle" );
127
+ return -1 ;
128
+ }
129
+
130
+ if (StartService (svc_handle , 0 , NULL ) == FALSE && GetLastError () != ERROR_SERVICE_ALREADY_RUNNING ) {
131
+ fatal ("unable to start ssh-agent service, error :%d" , GetLastError ());
132
+ return -1 ;
133
+ }
134
+
111
135
return 0 ;
112
136
}
113
137
}
0 commit comments