[tcobrowser-cvs] SF.net SVN: tcobrowser:[1011] trunk/bibdesk/BibDocument_Actions.m
Status: Beta
Brought to you by:
amaxwell
From: <ama...@us...> - 2008-10-18 04:34:46
|
Revision: 1011 http://tcobrowser.svn.sourceforge.net/tcobrowser/?rev=1011&view=rev Author: amaxwell Date: 2008-10-18 04:34:43 +0000 (Sat, 18 Oct 2008) Log Message: ----------- Improve error checking and open the pipe non-blocking. Modified Paths: -------------- trunk/bibdesk/BibDocument_Actions.m Modified: trunk/bibdesk/BibDocument_Actions.m =================================================================== --- trunk/bibdesk/BibDocument_Actions.m 2008-10-18 01:34:47 UTC (rev 1010) +++ trunk/bibdesk/BibDocument_Actions.m 2008-10-18 04:34:43 UTC (rev 1011) @@ -520,7 +520,7 @@ return; NSString *lyxPipePath = [[NSFileManager defaultManager] newestLyXPipePath]; - int fd; + int fd = 0; if (lyxPipePath == nil) { NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Unable to Find LyX Pipe", @"Message in alert dialog when LyX pipe cannot be found") @@ -530,21 +530,28 @@ informativeTextWithFormat:NSLocalizedString(@"BibDesk was unable to find the LyX pipe." , @"Informative text in alert dialog")]; [alert beginSheetModalForWindow:documentWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL]; - } else if (-1 != (fd = open([lyxPipePath fileSystemRepresentation], O_WRONLY))) { + } + // open non-blocking, so we don't hang if the pipe goes away + else if (-1 != (fd = open([lyxPipePath fileSystemRepresentation], O_WRONLY | O_NONBLOCK))) { NSArray *citeKeys = [[self selectedPublications] valueForKey:@"citeKey"]; NSMutableString *cites = [NSMutableString stringWithString:@"LYXCMD:BibDesk:citation-insert:"]; [cites appendString:[citeKeys componentsJoinedByString:@","]]; - // pipe uses line buffering + // pipe uses line buffering, so append a newline [cites appendString:@"\n"]; // presumably the LyX document uses the same encoding as the .bib file, but citekeys should be 7 bit ASCII anyway NSData *data = [cites dataUsingEncoding:[self documentStringEncoding]]; sig_t sig = signal(SIGPIPE, SIG_IGN); - write(fd, [data bytes], [data length]); + ssize_t len = write(fd, [data bytes], [data length]); + if (len != (ssize_t)[data length]) + NSLog(@"Failed to write all data to LyX pipe %@ (%d of %d bytes written)", lyxPipePath, len, [data length]); signal(SIGPIPE, sig); close(fd); + + } else if (-1 == fd) { + NSLog(@"Failed to open() LyX pipe %@ (%s)", lyxPipePath, strerror(errno)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |