Mercurial > hg > easyhg
comparison common.cpp @ 80:32fa40c3d174
* OS/X doesn't like fork() without exec(). Scrap that, revert to ioctl
author | Chris Cannam |
---|---|
date | Mon, 22 Nov 2010 15:21:12 +0000 |
parents | aaeabc920ca8 |
children | af7cf6f7282c |
comparison
equal
deleted
inserted
replaced
79:aaeabc920ca8 | 80:32fa40c3d174 |
---|---|
31 #include <security.h> | 31 #include <security.h> |
32 #else | 32 #else |
33 #include <errno.h> | 33 #include <errno.h> |
34 #include <pwd.h> | 34 #include <pwd.h> |
35 #include <unistd.h> | 35 #include <unistd.h> |
36 #include <sys/ioctl.h> | |
37 #include <sys/types.h> | |
38 #include <sys/stat.h> | |
39 #include <fcntl.h> | |
36 #endif | 40 #endif |
37 | 41 |
38 QString findExecutable(QString name) | 42 QString findExecutable(QString name) |
39 { | 43 { |
40 bool found = false; | 44 bool found = false; |
146 #endif | 150 #endif |
147 | 151 |
148 void loseControllingTerminal() | 152 void loseControllingTerminal() |
149 { | 153 { |
150 #ifndef Q_OS_WIN32 | 154 #ifndef Q_OS_WIN32 |
151 pid_t sid; | 155 |
152 switch (fork()) { | 156 if (!isatty(0)) { |
153 case 0: | 157 DEBUG << "stdin is not a terminal" << endl; |
154 sid = setsid(); | 158 } else { |
155 if (sid != (pid_t)-1) { | 159 DEBUG << "stdin is a terminal, detaching from it" << endl; |
156 DEBUG << "setsid() succeeded, session ID is " << sid << endl; | 160 if (ioctl(0, TIOCNOTTY, NULL) < 0) { |
161 perror("ioctl failed"); | |
162 DEBUG << "ioctl for TIOCNOTTY failed (errno = " << errno << ")" << endl; | |
157 } else { | 163 } else { |
158 perror("setsid failed"); | 164 DEBUG << "ioctl for TIOCNOTTY succeeded" << endl; |
159 DEBUG << "setsid() failed (errno = " << errno << ")" << endl; | 165 } |
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; | 166 return; |
175 default: | 167 } |
176 exit(0); | 168 |
177 } | 169 int ttyfd = open("/dev/tty", O_RDWR); |
170 if (ttyfd < 0) { | |
171 DEBUG << "failed to open controlling terminal" << endl; | |
172 } else { | |
173 if (ioctl(ttyfd, TIOCNOTTY, NULL) < 0) { | |
174 perror("ioctl failed"); | |
175 DEBUG << "ioctl for TIOCNOTTY failed (errno = " << errno << ")" << endl; | |
176 } else { | |
177 DEBUG << "ioctl for TIOCNOTTY succeeded" << endl; | |
178 } | |
179 return; | |
180 } | |
181 | |
178 #endif | 182 #endif |
179 } | 183 } |
180 | 184 |
181 FolderStatus getFolderStatus(QString path) | 185 FolderStatus getFolderStatus(QString path) |
182 { | 186 { |