2000-02-17 20:38:33 +01:00
|
|
|
/* delqueue.cc
|
|
|
|
|
2001-09-11 22:01:02 +02:00
|
|
|
Copyright 1996, 1998, 1999, 2000, 2001 Red Hat, Inc.
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
|
|
|
#include "winsup.h"
|
2000-09-08 04:56:55 +02:00
|
|
|
#include "shared_info.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
/* FIXME: this delqueue module is very flawed and should be rewritten.
|
|
|
|
First, having an array of a fixed size for keeping track of the
|
|
|
|
unlinked but not yet deleted files is bad. Second, some programs
|
|
|
|
will unlink files and then create a new one in the same location
|
|
|
|
and this behavior is not supported in the current code. Probably
|
|
|
|
we should find a move/rename function that will work on open files,
|
|
|
|
and move delqueue files to some special location or some such
|
|
|
|
hack... */
|
|
|
|
|
|
|
|
void
|
|
|
|
delqueue_list::init ()
|
|
|
|
{
|
|
|
|
empty = 1;
|
2002-09-23 02:31:31 +02:00
|
|
|
memset (inuse, 0, MAX_DELQUEUES_PENDING);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
delqueue_list::queue_file (const char *dosname)
|
|
|
|
{
|
|
|
|
char temp[MAX_PATH], *end;
|
|
|
|
GetFullPathName (dosname, sizeof (temp), temp, &end);
|
|
|
|
|
|
|
|
/* Note about race conditions: The only time we get to this point is
|
|
|
|
when a delete fails because someone's holding the descriptor open.
|
|
|
|
In those cases, other programs will be unable to delete the file
|
|
|
|
also, so any entries referring to that file will not be removed
|
|
|
|
from the queue while we're here. */
|
|
|
|
|
|
|
|
if (!empty)
|
|
|
|
{
|
|
|
|
/* check for duplicates */
|
|
|
|
for (int i=0; i < MAX_DELQUEUES_PENDING; i++)
|
2002-09-23 02:31:31 +02:00
|
|
|
if (inuse[i] && strcmp (name[i], temp) == 0)
|
2000-02-17 20:38:33 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < MAX_DELQUEUES_PENDING; i++)
|
|
|
|
if (!inuse[i])
|
|
|
|
{
|
|
|
|
/* set the name first, in case someone else is running the
|
|
|
|
queue they'll get a valid name */
|
2002-09-23 02:31:31 +02:00
|
|
|
strcpy (name[i], temp);
|
2000-02-17 20:38:33 +01:00
|
|
|
inuse[i] = 1;
|
|
|
|
empty = 0;
|
2000-03-18 07:26:14 +01:00
|
|
|
debug_printf ("adding '%s' to queue %d", temp, i);
|
2000-02-17 20:38:33 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
system_printf ("Out of queue slots");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
delqueue_list::process_queue ()
|
|
|
|
{
|
|
|
|
if (empty)
|
|
|
|
return;
|
|
|
|
/* We set empty to 1 here, rather than later, to avoid a race
|
|
|
|
condition - some other program might queue up a file while we're
|
|
|
|
processing, and it will zero out empty also. */
|
|
|
|
empty = 1; /* but might get set to zero again, below */
|
|
|
|
|
|
|
|
syscall_printf ("Running delqueue");
|
|
|
|
|
|
|
|
for (int i = 0; i < MAX_DELQUEUES_PENDING; i++)
|
|
|
|
if (inuse[i])
|
|
|
|
{
|
|
|
|
if (DeleteFileA (name[i]))
|
|
|
|
{
|
|
|
|
syscall_printf ("Deleted %s", name[i]);
|
|
|
|
inuse[i] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int res = GetLastError ();
|
|
|
|
empty = 0;
|
2000-05-04 21:46:32 +02:00
|
|
|
if (res == ERROR_SHARING_VIOLATION ||
|
* Makefile.in: Build wincap.o.
* wincap.cc: New file.
* wincap.h: Ditto.
* autoload.cc: Add dynamic load statement for `CreateHardLinkA'.
* dcrt0.cc (os_being_run): Eliminated.
(osname): Ditto.
(iswinnt): Ditto.
(set_os_type): Ditto.
(dll_crt0_1): Call wincap.init() instead of set_os_type().
(_dll_crt0): Ditto.
* environ.cc (set_chunksize): New function.
(parse_thing): `forkchunk' setting now invokes function `set_chunksize'.
* fork.cc (chunksize): Eliminated. Moved to be member of wincap.
* host_dependent.h: Removed.
* syscalls.cc (_link): Try using `CreateHardLinkA' first, if available.
* cygheap.cc, dcrt0.cc, delqueue.cc, dir.cc,
environ.cc, fhandler.cc, fhandler.h, fhandler_console.cc,
fhandler_mem.cc, fork.cc, mmap.cc, net.cc, pinfo.cc, pinfo.h,
security.cc, syscalls.cc, sysconf.cc, syslog.cc, thread.cc,
times.cc, tty.cc, uinfo.cc, uname.cc, winsup.h: Use new wincap
capability check throughout.
* winsup.h: Include wincap.h. Eliminate extern declarations of
`os_being_run' and `iswinnt'. Eliminate `os_type" definition.
* include/cygwin/version.h: Bump version to 1.3.4.
2001-09-12 19:46:37 +02:00
|
|
|
(wincap.access_denied_on_delete ()
|
|
|
|
&& res == ERROR_ACCESS_DENIED))
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
/* File still inuse, that's ok */
|
|
|
|
syscall_printf ("Still using %s", name[i]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
syscall_printf ("Hmm, don't know what to do with '%s', %E", name[i]);
|
2000-09-03 06:16:35 +02:00
|
|
|
inuse[i] = 0;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|