From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#13079: 24.3.50; Emacs cannot create subprocess Date: Thu, 06 Dec 2012 21:04:54 +0200 Message-ID: <83boe7ovc9.fsf@gnu.org> References: <83ehj5r2gs.fsf@gnu.org> <83wqwwpfu1.fsf@gnu.org> <83obi7q1hn.fsf@gnu.org> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1354820758 29434 80.91.229.3 (6 Dec 2012 19:05:58 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 6 Dec 2012 19:05:58 +0000 (UTC) Cc: 13079@debbugs.gnu.org To: Li Zhai Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Dec 06 20:06:11 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Tgglt-000586-RI for geb-bug-gnu-emacs@m.gmane.org; Thu, 06 Dec 2012 20:06:10 +0100 Original-Received: from localhost ([::1]:48180 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tgglg-0005ba-77 for geb-bug-gnu-emacs@m.gmane.org; Thu, 06 Dec 2012 14:05:56 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:51326) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tgglc-0005bU-Gj for bug-gnu-emacs@gnu.org; Thu, 06 Dec 2012 14:05:54 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TgglX-0003k9-WF for bug-gnu-emacs@gnu.org; Thu, 06 Dec 2012 14:05:52 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:46933) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TgglX-0003k4-RO for bug-gnu-emacs@gnu.org; Thu, 06 Dec 2012 14:05:47 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1Tggll-0006am-MH for bug-gnu-emacs@gnu.org; Thu, 06 Dec 2012 14:06:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 06 Dec 2012 19:06:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 13079 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 13079-submit@debbugs.gnu.org id=B13079.135482070925223 (code B ref 13079); Thu, 06 Dec 2012 19:06:01 +0000 Original-Received: (at 13079) by debbugs.gnu.org; 6 Dec 2012 19:05:09 +0000 Original-Received: from localhost ([127.0.0.1]:57184 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Tggkv-0006Yl-3y for submit@debbugs.gnu.org; Thu, 06 Dec 2012 14:05:09 -0500 Original-Received: from mtaout21.012.net.il ([80.179.55.169]:36585) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Tggks-0006YX-Cn for 13079@debbugs.gnu.org; Thu, 06 Dec 2012 14:05:07 -0500 Original-Received: from conversion-daemon.a-mtaout21.012.net.il by a-mtaout21.012.net.il (HyperSendmail v2007.08) id <0MEM00K00I5ER200@a-mtaout21.012.net.il> for 13079@debbugs.gnu.org; Thu, 06 Dec 2012 21:04:50 +0200 (IST) Original-Received: from HOME-C4E4A596F7 ([87.69.4.28]) by a-mtaout21.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0MEM00KEVIC1R010@a-mtaout21.012.net.il>; Thu, 06 Dec 2012 21:04:50 +0200 (IST) In-reply-to: X-012-Sender: halo1@inter.net.il X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:68041 Archived-At: > Date: Thu, 6 Dec 2012 16:18:10 +0800 > From: Li Zhai > Cc: 13079@debbugs.gnu.org > > I've tried another method, using the flag FILE_FLAG_DELETE_ON_CLOSE > while open the files. > > Create a file by passed the flag FILE_FLAG_DELETE_ON_CLOSE to > CreateFile, if all the handles are closed, the file will be deleted > automatically. I wrote a very simple program to test that feature. It > seems works. > > #include > #include > #include > #include > #include > #include > > void main( void ) > { > HANDLE fh1, fh2; > char buf[100]; > DWORD dwReadSize; > DWORD dwWriteSize; > > fh1 = CreateFile("temp.txt", GENERIC_READ | GENERIC_WRITE, > FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, > NULL, CREATE_ALWAYS, > FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, NULL); > > WriteFile(fh1, "hello", 5, &dwWriteSize, NULL); > > fh2 = CreateFile("temp.txt", GENERIC_READ | GENERIC_WRITE, > FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, > NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); > > if (fh2 == INVALID_HANDLE_VALUE) > perror( "Open failed on fh2" ); > > printf("Close the first file handle...\n"); > CloseHandle(fh1); > > printf("Read file...\n"); > ReadFile(fh2, buf, 5, &dwReadSize, NULL); > buf[5] = 0; > printf("File content:\n %s\n", buf); > > _getch(); > > printf("Close the second file handle...The file should be deleted\n"); > CloseHandle(fh2); > } > > > But this method has some limit. Firstly, all the files must > create/open by Win32 API, the codes are totally unportable. Secondly, > the file must be opened with a flag FILE_SHARE_DELETE, or the file > will not be deleted. > > And I don't know how to integrate the Win32 API with the emacs codes. > Emacs codes use POSIX functions(_open, _close, _read...), and the > delete_on_close feature required WIN32 API. I've tried using > _O_TEMPORARY flags with _open function, but not succeeded. Yes, this technique will not help, for all the reasons you mention, and then some. For starters, in our case the problem is not with Emacs holding the file open -- the call to write-region within call-process-region closes the file before it returns -- but with the child process that has the file connected to its standard input. So another process is involved here, not just Emacs. Also, Emacs always uses emacs_open to open any files, which means it doesn't know which files are temporary and which aren't. Obviously, we cannot open all files with FILE_FLAG_DELETE_ON_CLOSE or _O_TEMPORARY, because most files Emacs writes should _not_ be deleted when Emacs closes them. Anyway, I think the solution to this should be to somehow retry the deletion later, when the child process exits. Nothing else will resolve this bug.