Mercurial > hg > easyhg
comparison common.cpp @ 78:07405f3a428b
* Use fork/setsid/fork to escape our controlling terminal, to ensure the pty we create is used for password requests
author | Chris Cannam |
---|---|
date | Mon, 22 Nov 2010 10:03:15 +0000 |
parents | b522aaa2c053 |
children | aaeabc920ca8 |
comparison
equal
deleted
inserted
replaced
77:b522aaa2c053 | 78:07405f3a428b |
---|---|
28 #ifdef Q_OS_WIN32 | 28 #ifdef Q_OS_WIN32 |
29 #define _WIN32_WINNT 0x0500 | 29 #define _WIN32_WINNT 0x0500 |
30 #include <windows.h> | 30 #include <windows.h> |
31 #include <security.h> | 31 #include <security.h> |
32 #else | 32 #else |
33 #include <errno.h> | |
33 #include <pwd.h> | 34 #include <pwd.h> |
35 #include <unistd.h> | |
34 #endif | 36 #endif |
35 | 37 |
36 QString findExecutable(QString name) | 38 QString findExecutable(QString name) |
37 { | 39 { |
38 bool found = false; | 40 bool found = false; |
141 return s; | 143 return s; |
142 } | 144 } |
143 #endif | 145 #endif |
144 #endif | 146 #endif |
145 | 147 |
148 void loseControllingTerminal() | |
149 { | |
150 #ifndef Q_OS_WIN32 | |
151 pid_t sid; | |
152 switch (fork()) { | |
153 case 0: | |
154 sid = setsid(); | |
155 if (sid != (pid_t)-1) { | |
156 DEBUG << "setsid() succeeded, session ID is " << sid << endl; | |
157 } else { | |
158 perror("setsid failed"); | |
159 DEBUG << "setsid() failed (errno = " << errno << ")" << endl; | |
160 } | |
161 switch (fork()) { | |
162 case 0: | |
163 return; | |
164 case -1: | |
165 perror("fork failed"); | |
166 DEBUG << "second fork failed (errno = " << errno << ")" << endl; | |
167 return; | |
168 default: | |
169 exit(0); | |
170 } | |
171 case -1: | |
172 perror("fork failed"); | |
173 DEBUG << "fork failed (errno = " << errno << ")" << endl; | |
174 return; | |
175 default: | |
176 exit(0); | |
177 } | |
178 #endif | |
179 } |