Mercurial > vim
comparison src/gui.c @ 3147:7ba2f171cdac v7.3.344
updated for version 7.3.344
Problem: Problem with GUI startup related to XInitThreads.
Solution: Use read() and write() instead of fputs() and fread(). (James
Vega)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Thu, 20 Oct 2011 21:28:01 +0200 |
parents | 3ecf9e91d88a |
children | 7bafe52b6245 |
comparison
equal
deleted
inserted
replaced
3146:5da0b66c52a7 | 3147:7ba2f171cdac |
---|---|
210 int pipefd[2]; /* pipe between parent and child */ | 210 int pipefd[2]; /* pipe between parent and child */ |
211 int pipe_error; | 211 int pipe_error; |
212 int status; | 212 int status; |
213 int exit_status; | 213 int exit_status; |
214 pid_t pid = -1; | 214 pid_t pid = -1; |
215 FILE *parent_file; | |
216 | 215 |
217 /* Setup a pipe between the child and the parent, so that the parent | 216 /* Setup a pipe between the child and the parent, so that the parent |
218 * knows when the child has done the setsid() call and is allowed to | 217 * knows when the child has done the setsid() call and is allowed to |
219 * exit. */ | 218 * exit. */ |
220 pipe_error = (pipe(pipefd) < 0); | 219 pipe_error = (pipe(pipefd) < 0); |
288 # if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | 287 # if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) |
289 /* Tell the session manager our new PID */ | 288 /* Tell the session manager our new PID */ |
290 gui_mch_forked(); | 289 gui_mch_forked(); |
291 # endif | 290 # endif |
292 | 291 |
293 if (!pipe_error) | |
294 parent_file = fdopen(pipefd[1], "w"); | |
295 else | |
296 parent_file = NULL; | |
297 | |
298 /* Try to start the GUI */ | 292 /* Try to start the GUI */ |
299 gui_attempt_start(); | 293 gui_attempt_start(); |
300 | 294 |
301 /* Notify the parent */ | 295 /* Notify the parent */ |
302 if (parent_file != NULL) | 296 if (!pipe_error) |
303 { | 297 { |
304 fputs(gui.in_use ? "ok" : "fail", parent_file); | 298 if (gui.in_use) |
305 fclose(parent_file); | 299 write_eintr(pipefd[1], "ok", 3); |
300 else | |
301 write_eintr(pipefd[1], "fail", 5); | |
302 close(pipefd[1]); | |
306 } | 303 } |
307 | 304 |
308 /* If we failed to start the GUI, exit now. */ | 305 /* If we failed to start the GUI, exit now. */ |
309 if (!gui.in_use) | 306 if (!gui.in_use) |
310 exit(1); | 307 exit(1); |
321 * The file descriptor will be closed before the function returns. | 318 * The file descriptor will be closed before the function returns. |
322 */ | 319 */ |
323 static int | 320 static int |
324 gui_read_child_pipe(int fd) | 321 gui_read_child_pipe(int fd) |
325 { | 322 { |
326 size_t bytes_read; | 323 long bytes_read; |
327 FILE *file; | 324 #define READ_BUFFER_SIZE 10 |
328 char buffer[10]; | 325 char buffer[READ_BUFFER_SIZE]; |
329 | 326 |
330 file = fdopen(fd, "r"); | 327 bytes_read = read_eintr(fd, buffer, READ_BUFFER_SIZE - 1); |
331 if (!file) | 328 #undef READ_BUFFER_SIZE |
329 close(fd); | |
330 if (bytes_read < 0) | |
332 return GUI_CHILD_IO_ERROR; | 331 return GUI_CHILD_IO_ERROR; |
333 | 332 buffer[bytes_read] = NUL; |
334 bytes_read = fread(buffer, sizeof(char), sizeof(buffer)-1, file); | |
335 buffer[bytes_read] = '\0'; | |
336 fclose(file); | |
337 if (strcmp(buffer, "ok") == 0) | 333 if (strcmp(buffer, "ok") == 0) |
338 return GUI_CHILD_OK; | 334 return GUI_CHILD_OK; |
339 return GUI_CHILD_FAILED; | 335 return GUI_CHILD_FAILED; |
340 } | 336 } |
341 | 337 |