From: Li Zhai <mrzhaili@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 13079@debbugs.gnu.org
Subject: bug#13079: 24.3.50; Emacs cannot create subprocess
Date: Thu, 6 Dec 2012 16:18:10 +0800 [thread overview]
Message-ID: <CAPPz3g62uTw0YvxatpWTYYe6wEqLqEBUA5owvnN25FpVdRgEkg@mail.gmail.com> (raw)
In-Reply-To: <83obi7q1hn.fsf@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 <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#include <stdio.h>
#include <windows.h>
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.
On Thu, Dec 6, 2012 at 11:54 AM, Eli Zaretskii <eliz@gnu.org> wrote:
>> Date: Thu, 6 Dec 2012 09:58:19 +0800
>> From: Li Zhai <mrzhaili@gmail.com>
>> Cc: 13079@debbugs.gnu.org
>>
>> I got it. The maximize number of calling mktemp is 42 if we don't
>> remove the temporary em* files.
>
> Yes.
>
>> I found a very interesting discuss about the limit of mktemp on windows.
>>
>> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47439
>>
>> They implement a new mktemp function to walk around the limit on the
>> number of concurrently open files.
>>
>> Can we implement our mktemp functions instead of using microsoft's stuff?
>
> But that will just push the limit farther. It will not fix the
> underlying fundamental problem of not deleting temporary files in this
> case. Since Emacs is typically run for long periods of time, sooner
> or later the problem will strike anyway.
next prev parent reply other threads:[~2012-12-06 8:18 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-04 8:03 bug#13079: 24.3.50; Emacs cannot create subprocess Li Zhai
2012-12-04 20:23 ` Eli Zaretskii
2012-12-05 2:26 ` Li Zhai
2012-12-05 17:29 ` Eli Zaretskii
2012-12-06 1:58 ` Li Zhai
2012-12-06 3:54 ` Eli Zaretskii
2012-12-06 8:18 ` Li Zhai [this message]
2012-12-06 19:04 ` Eli Zaretskii
2012-12-15 13:41 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAPPz3g62uTw0YvxatpWTYYe6wEqLqEBUA5owvnN25FpVdRgEkg@mail.gmail.com \
--to=mrzhaili@gmail.com \
--cc=13079@debbugs.gnu.org \
--cc=eliz@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).