Commit Graph

743 Commits

Author SHA1 Message Date
Christopher Faylor bc837d22f3 Throughout, update copyrights to reflect dates which correspond to main-branch
checkins.  Regularize copyright format.
2013-01-21 04:38:31 +00:00
Corinna Vinschen a32a9a87a1 * syscalls.cc (rename): Remove ill-conceived NFS workaround from
2013-01-10 for self-inflicted NFS server problem.
2013-01-19 14:54:18 +00:00
Corinna Vinschen 7142197465 * syscalls.cc (rename): Drop handling paths > 32757 chars, emit EINVAL
instead, thus simplifying code allocating and filling pfri.  Drop size
	and use constant expression in NtSetInformationFile call.  Add comments.
	Drop redundant test for fs_serial_number and change comment accordingly.
2013-01-11 12:34:41 +00:00
Corinna Vinschen 34ce80888a * path.h (path_conv::fs_type): New method.
* syscalls.cc (rename): Check for cross-device situation before
	touching anything.  Explain why.  Workaround NFS bug in call to
	NtSetInformationFile(FileRenameInformation).
2013-01-10 15:08:22 +00:00
Christopher Faylor f6187d46b1 * dtable.cc (dtable::dup3): Fix bounds checking for valid newfd.
* syscalls.cc (dup2): Ditto.
* winsup.h (events_terminate): Delete obsolete function declaration.
2012-12-31 18:31:49 +00:00
Christopher Faylor 46f5dd5958 whitespace cleanup 2012-08-16 23:34:45 +00:00
Corinna Vinschen a654829ade * syscalls.cc (enum bin_status): Add dir_not_empty.
(try_to_bin): Call NtQueryInformationFile(FileInternalInformation)
	with exact buffer size.  Explain why.
	Ditto for NtSetInformationFile(FileRenameInformation).
	Handle race-condition which might lead to renaming a non-empty
	directory.
	(unlink_nt): Rearrange and partially rephrase comments related to the
	STATUS_SHARING_VIOLATION case.  Fix condition under which a dir is
	tested for being non-empty.  Handle dir_not_empty return code from
	try_to_bin.  Gracefully handle disappearing directory in rm -r
	workaround.  Fix typo in comment.
2012-07-25 12:32:37 +00:00
Christopher Faylor 962f9a2ccc * DevNotes: Add entry cgf-000013.
* cygserver_ipc.h (ipc_set_proc_info): Use _cygtls::ipc_set_proc_info to set
per-thread signal arrived value.
* cygthread.cc (cygthread::detach): Use per-thread signal_arrived via
set_thread_waiting.
* fork.cc (_cygtls::fixup_after_fork): Clear signal_arrived.
(_cygtls::remove): Close any signal_arrived handle when thread exists.
(_cygtls::find_tls): Remove unneeded function.
* cygtls.h: Update copyright.
(class _cygtls): Reorganize to help avoid rebuilding newlib when structure
changes.
(_cygtls::event): Delete.
(_cygtls::threadkill): Ditto.
(_cygtls::signal_waiting): Declare new bool.
(_cygtls::find_tls): Delete declaration.
(_cygtls::set_threadkill): Ditto.
(_cygtls::reset_threadkill): Ditto.
(_cygtls::set_signal_arrived): Declare new function.
(class set_thread_waiting): Declare new class.
* cygwait.cc (cw_nowait_storage): Define.
(cygwait): Set per-thread signal_arrived via set_thread_waiting.  Don't
special-case _main_tls.
* cygwait.h (cw_nowait): Define.
(cw_infinite): Ditto.
(cygwait): Redefine pathological wait-only case.
* dcrt0.cc (dll_crt0_0): Remove call to now-defunct events_init().
(dll_crt0_1): Remove call to now-defunct create_signal_arrived().
* exceptions.cc: Reflect set_signal_mask() argument reordering throughout.
Remove signal mask synchronization throughout.
(events_init): Delete definition.
(mask_sync): Delete now-unneeded mask synchronization.
(set_signal_mask): Reverse order of arguments to "standard" to, from layout.
Rename "newmask" argument to "setmask".  Remove debugging.
(sig_handle_tty_stop): Use cancelable_wait rather than WFMO.
(_cygtls::interrupt_setup): Don't treat "threadkill" events specially.
Conditionally set signal_arrived depending on whether the thread has created it
or not.
(sigpacket::process): Reorganize to reflect thread-specific sending of signals
which is more in line with the way it was actually supposed to work.
* fhandler_socket.cc (get_inet_addr): Use cancelable_wait rather than
IsEventSignalled to avoid potential race.
(fhandler_socket::wait_for_events): Set signal_arrived event using
set_thread_waiting().
(fhandler_socket::close): Use cygwait for the case of just waiting 10 ms for a
signal.
* fhandler_tape.cc (fhandler_dev_tape::_lock): Use cancelable_wait rather than
WFMO.  Redo switch/case tests accordingly.
* fhandler_termios.cc (fhandler_termios::bg_check): Use cygwait for case of
just waiting 0 ms for a potential signal.
* fhandler_tty.cc (fhandler_pty_master::process_slave_output): Use
cancelable_wait rather than WFSO.
* fhandler_windows.cc (fhandler_windows::read): Set per-thread signal_arrived
via set_thread_waiting().
* flock.cc (lf_setlock): Ditto.
* select.cc (pselect): Ditto.  Set per-thread signal_arrived using
set_thread_waiting().
* gendef: Don't special case handling of _cygtls::sig for threads.
* gentls_offsets: Use #pragma once in tlsoffsets.h.
* ntdll.h: Use #pragma once.
* poll.cc: Reflect set_signal_mask() argument reordering.
* posix_ipc.cc (ipc_mutex_lock): Use cancelable_wait rather than WFMO.
(ipc_cond_timedwait): Set perl-thread signal arrived using
set_thread_waiting().
* security.h: Use #pragma once.
* signal.cc (abort): Reflect set_signal_mask() argument reordering.
(clock_nanosleep): Ditto.  Change call to cancelable_wait to properly specify
handling of cancel and interrupt.
(sigwaitinfo): Remove handling of per-thread event in favor of per-thread
signal_arrived.  Use cancelable_wait rather than WFSO.
* sigproc.cc (signal_arrived): Delete definition.
(create_signal_arrived): Ditto.
* sigproc.h (signal_arrived): Delete declaration.
(set_signal_mask): Avoid defining as a "C" function.  Don't conditionally
declare.
(create_signal_arrived): Delete declaration.
* syscalls.cc (rename): Use cygwait() rather than WFSO.
* thread.h (fast_mutex::lock): Use cw_infinite rather than LARGE_NULL.
* wait.cc (wait4): Ditto.
* thread.cc (pthread_mutex::lock): Ditto.
(pthread::join): Ditto.
(semaphore::_wait): Ditto.
(pthread_kill): Remove set_threadkill() accommodation.
* tlsoffsets.h: Regenerate.
2012-07-21 22:58:20 +00:00
Christopher Faylor 2addde8cb1 Revert errneous checkin.
Check in actual change associated with ChangeLog.
2012-06-19 00:38:02 +00:00
Christopher Faylor af5cd14583 * cygwait.cc (cancelable_wait): Mimic old cygwait behavior more closely wrt
handling of call_signal_handler.
* cygwait.h (WAIT_CANCELED): Move here and redefine.
(WAIT_SIGNALED): Ditto.
* thread.h (WAIT_CANCELED): Delete.
(WAIT_SIGNALED): Ditto.
2012-06-19 00:31:15 +00:00
Christopher Faylor b9c61a8d7b * dtable.cc (dtable::dup3): Only return with lock set when O_EXCL flag is
passed in.
* syscalls.cc (dup_finish): Pass O_EXCL in flags to dtable::dup3.
2012-06-04 01:26:05 +00:00
Christopher Faylor 3143cb7c00 * DevNotes: Add entry cgf-000011.
* fhandler.h (fhandler_base::refcnt): Delete.
(fhandler_base::inc_refcnt): New function.
(fhandler_base::dec_refcnt): New function.
* cygheap.h (cygheap_fdnew::~cygheap_fdnew): Accommodate split of refcnt to
inc_refcnt/dec_refcnt.
(cygheap_fdget::cygheap_fdget): Ditto.
(cygheap_fdget::~cygheap_fdget::cygheap_fdget): Ditto.
* dtable.cc (dtable::release): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::init_std_file_from_handle): Ditto.
(dtable::dup3): On success, return with fdtab locked.
* dtable.h (dtable): Add dup_finish as a friend.
* syscalls.cc (dup_finish): Define new function.  Increment refcnt while fdtab
is locked.
(dup2): Use common dup_finish() to perform dup operation.
(dup3): Ditto.
2012-06-03 18:02:45 +00:00
Corinna Vinschen 115d74b99e * globals.cc (ro_u_refs): New R/O unicode string.
* mount.cc (fs_info::update): Recognize ReFS.
	* mount.h (enum fs_info_type): Add refs.
	(class fs_info): Add refs flag and accessor methods.
	* ntdll.h (RtlAddAccessAllowedAceEx): Declare.
	(RtlAddAccessDeniedAceEx): Declare.
	* path.h (path_conv::fs_is_refs): Define.
	* sec_helper.cc (_recycler_sd): New function to create security
	descriptors suitable for the recycler bin starting with Vista.
	* security.cc (add_access_allowed_ace): Use RtlAddAccessAllowedAceEx
	and drop code to set AceFlags explicitely.
	(add_access_denied_ace): Use RtlAddAccessDeniedAceEx and drop code to
	set AceFlags explicitely.
	* security.h (_recycler_sd): Declare.
	(recycler_sd): Define.
	* syscalls.cc (desktop_ini): Change formatting.
	(desktop_ini_ext): Define third line of recycler desktop.ini file
	since Vista,
	(try_to_bin): Handle ReFS just like NTFS.  Write Vista and later
	Recycler in all uppercase, just like shell32 does when recreating it.
	Fix comments to include ReFS.  Don't implicitely reuse object
	attributes from earlier NtOpenFile call, rather recreate it for safety.
	Use recycler_sd call when creating security descriptor for Recycler
	dirs and files on Vista and later.  Write third line of desktop.ini
	when on Vista and later.
2012-06-03 16:46:53 +00:00
Corinna Vinschen e62d782aec * syscalls.cc (fhandler_base::stat_fixup): Fix inode numbers of
non-device files in virtual fileysystems.
2012-04-11 08:49:52 +00:00
Corinna Vinschen f777ddfbe3 * syscalls.cc (fhandler_base::stat_fixup): Replace string comparison
with new device::is_dev_resident() call.
2012-04-03 07:28:48 +00:00
Corinna Vinschen eb7729eb36 * devices.h (device::get_device): New method.
* fhandler_dev.cc (fhandler_dev::readdir): Set st_ino to device number.
	* syscalls.cc (fhandler_base::stat_fixup): Ditto.  Fix link count for
	CD-ROM devices.  Fix typo in comment.
2012-04-02 19:25:58 +00:00
Corinna Vinschen 467e17b9af * fhandler.h (fhandler_base::stat_fixup): Rename from
fhandler_base::set_ino_and_dev.
	* syscalls.cc (fhandler_base::stat_fixup): Ditto. Accommodate name
	change throughout.  Fixup link count of console devices.
2012-04-02 16:19:29 +00:00
Corinna Vinschen f7c8c4540a * devices.h (FH_CYGDRIVE): Define as DEV_VIRTFS_MAJOR class device.
(DEV_CYGDRIVE_MAJOR): Remove.
	(iscygdrive_dev): Define.
	* dtable.cc (fh_alloc): Accommodate above change.
	* path.cc (path_conv::check): Use iscygdrive_dev to check for cygdrive.
	* syscalls.cc (fhandler_base::set_ino_and_dev): Drop check for
	DEV_CYGDRIVE_MAJOR from conditional.
2012-04-02 15:56:43 +00:00
Corinna Vinschen 1f312200d3 * devices.h (FH_DEV): Define as DEV_VIRTFS_MAJOR class device.
(DEV_DEV_MAJOR): Remove.
	* dtable.cc (fh_alloc): Accommodate above change.
	* syscalls.cc (set_ino_and_dev): Drop check for DEV_DEV_MAJOR from
	conditional.
2012-04-02 11:45:56 +00:00
Corinna Vinschen 949cc8b640 * fhandler.h (fhandler_base::set_ino_and_dev): Declare.
* syscalls.cc (fhandler_base::set_ino_and_dev): New method to set
	st_ino, st_dev, and st_rdev for devices in a single spot.
	(fstat64): Call fhandler_base::set_ino_and_dev instead of setting
	st_ino, st_dev, and st_rdev here.
	(stat_worker): Ditto.
2012-04-02 11:18:45 +00:00
Corinna Vinschen c1c62a1368 * syscalls.cc (lseek): Fix debug output. 2012-03-20 20:39:32 +00:00
Yaakov Selkowitz e587f14b6f * cygwin.din (scandirat): Export.
* posix.sgml (std-gnu): Add scandirat.
	* syscalls.cc (scandirat): New function.
	* include/cygwin/version.h (CYGWIN_VERSION_API_MINOR): Bump.
	* include/sys/dirent.h (scandirat): Declare.
2012-02-22 01:58:24 +00:00
Christopher Faylor 4eb5175d90 * pinfo.cc (_pinfo::set_ctty): Revert 2012-02-07 change to skip function if tty
in question == our ctty.
* syscalls.cc (setsid): Avoid two function calls.
* dtable.cc (dtable::dup_worker): Remove debugging.
* init.cc (search_for): Calculate for every new process rather than using
shared value.
(threadfunc_ix): Fill in for ever new process rather than sing shared value.
2012-02-14 19:08:20 +00:00
Christopher Faylor c38a2d8373 * syscalls.cc (setsid): On second thought, in the spirit of keeping things
kludgy, set ctty to -2 here as a special flag, and...
(open): ...only eschew setting O_NOCTTY when that case is detected.
2012-02-10 16:43:36 +00:00
Christopher Faylor 93b18fd232 * syscalls.cc (open): Semi-revert (?) to allowing open of a tty to become
controlling tty if there is no controlling tty.
2012-02-10 16:33:53 +00:00
Corinna Vinschen 3b8698d7be * include/process.h: Move here from include/cygwin subdir.
* exec.cc: Change include of process.h to reflect the fact that it's
	now back in include.
	* spawn.cc: Ditto.
	* syscalls.cc: Ditto.
2012-02-07 17:15:07 +00:00
Christopher Faylor 3e9c8f2e81 * cygheap.cc (init_cygheap::manage_console_count): Delete.
* cygheap.h (init_cygheap::manage_console_count): Ditto.
(init_cygheap::console_count): Ditto.
* fhandler.h (fhandler_console::has_a): Ditto.
(fhandler_console::free_console): Declare new function.
* fhandler_console.cc (fhandler_console::free_console): Define new function.
(fhandler_console::open_setup): Delete call to manage_console_count.
(fhandler_console::close): Ditto.  Replace with call to free_console().
* fhandler_tty.cc (fhandler_pty_slave::open): Delete call to
manage_console_count.
(fhandler_pty_slave::cleanup): Ditto.
(fhandler_pty_slave::close): Call fhandler_console::free_console() if this is
our controlling tty.
* pinfo.cc (_pinfo::set_ctty): Skip function if tty in question == our ctty.
Delete call to manage_console_count.
* syscalls.cc (close_all_files): Avoid locking and avoid setting errno when
iterating over fds.
2012-02-07 16:54:14 +00:00
Christopher Faylor ab1fb53505 * syscalls.cc (close_all_files): Use cygheap_fdget to manipulate fhandler. Use
debug_only_printf.
2012-02-02 16:58:13 +00:00
Christopher Faylor 8fa8b3a389 * dtable.cc (dtable::dup_worker): Add comment explaining why refcnt isn't
incremented here.
(dtable::dup3): Simplify slightly.  Add comment.
* syscalls.cc (dup3): Increment refcnt here, similarly to dup2.
2012-02-01 17:20:02 +00:00
Christopher Faylor d3cb1dffef * syscalls.cc (dup3): Fix debug typo.
* fhandler.cc (flush_async_io): Assume only called for writer.  Call
GetOverlappedResult directly rather than kluding call to has_ongoing_io.
(fhandler_base_overlapped::close): Only start flush thread when closing write
handle.  Only cancel I/O when reading.
2012-01-31 23:52:52 +00:00
Corinna Vinschen 5ad6d0a486 * syscalls.cc (gethostid): Simplify. Just fetch MachineGuid and
create hash from there.
2012-01-23 12:59:44 +00:00
Christopher Faylor 0646a508aa * cygheap.h (cygheap_fdmanip::release): Simplify.
* dtable.cc (dtable::release): Make void again.  Skip not_open check since it
is guaranteed to be open.  Don't bother deleting here since actual deletion
will be handled in cygheap_fdget::~cygheap_fdget.
* dtable.h (dtable::release): Make void again.
* syscalls.cc (dup2): Bump fhandler use count on successful dup.
2012-01-22 07:27:57 +00:00
Corinna Vinschen 02c8acc1b4 * include/cygwin/process.h: Move here from newlib.
* exec.cc: Change include of process.h to reflect the fact that it's
	now in the include/cygwin subfolder.
	* spawn.cc: Ditto.
	* syscalls.cc: Ditto.
2012-01-09 17:03:39 +00:00
Christopher Faylor 3fc91be72b * fhandler_dsp.cc (fhandler_dev_dsp::fhandler_dev_dsp): Set up device.
* syscalls.cc (open): Very minor formatting tweak.
2011-12-25 04:05:31 +00:00
Corinna Vinschen 177dc6c7f6 Throughout use wincap.allocation_granularity instead of getpagesize.
Throughout use wincap.page_size instead of getsystempagesize.
	Throughout use "status" as variable name to hold NTSTATUS values.
	* fhandler_mem.cc: Check for NT_SUCCESS rather than for STATUS_SUCCESS.
	Fix debug_printf output.  Rectify long statements.  Fix comment
	formatting.
	* fhandler_proc.cc: Ditto.
	(format_proc_swaps): Drop useless test for ERROR_PROC_NOT_FOUND.
	* fhandler_process.cc: Ditto as in fhandler_mem.cc.
	(get_process_state): Rearrange allocation loop.  Use malloc/realloc.
	(get_mem_values): Fix potential NULL pointer usage.  Drop unused
	variable.
	* pinfo.cc (winpids::enum_processes): Handle low memory gracefully.
	* sec_auth.cc (get_priv_list): Drop local variable ret.
	* shared.cc (memory_init): Drop outdated call to getpagesize.
	* syscalls.cc (getsystempagesize): Remove.
	* sysconf.cc: Check for NT_SUCCESS rather than for STATUS_SUCCESS.
	(sysinfo): Constify sizeof_stodi.  Drop useless test for
	ERROR_PROC_NOT_FOUND.
	* thread.cc (pthread_getattr_np): Cast pointers to uintptr_t rather
	than to int for pointer arithmetic.
	* winsup.h (getsystempagesize): Drop declaration.
2011-12-22 11:02:36 +00:00
Corinna Vinschen 18d0c0fb8b * syscalls.cc (rename): Fix typo in comment. Fix condition to handle
the case oldpath is no .lnk symlink and newpath points to an existing
	.lnk symlink or .exe file and no explicit .lnk suffix has been given
	in oldpath.  Add a comment to explain.
2011-12-19 17:01:37 +00:00
Christopher Faylor d004a27971 * fhandler.cc (fhandler_base::close): Move setting isclosed() from here to
closed().
(fhandler_base_overlapped::close): Correct comment.
(fhandler_base_overlapped::destroy_overlapped): Signal overlapped event before
closing it to potentially wake up a waiting thread.
(fhandler_base_overlapped::wait_overlapped): Expand setting of err when closed
to encompass non-signal event.  Test for a cancel event before making
nonblocking decisions.
* syscalls.cc (close): Set closed flag here so that any concurrently executing
functions will be notified ASAP.
2011-12-18 04:07:47 +00:00
Christopher Faylor 1b23b30b29 Clean up whitespace. 2011-12-17 23:39:47 +00:00
Christopher Faylor ce3318344c * exceptions.cc (set_signal_mask): Remove useless debugging output.
* fhandler.cc (fhandler_base::write): Ditto.
(fhandler_base_overlapped::close): Cancel any ongoing I/O before closing.
* syscalls.cc (write): Default to always reporting all writes in strace output
via syscall_printf.
* wait.cc (wait4): Fix debugging output.  Use standard syscall leaver output.
2011-12-17 07:01:21 +00:00
Christopher Faylor ca35d41cec Implement fhandler reference counting.
* cygheap.h
(cygheap_fdmanip::release): Make virtual.
(cygheap_fdnew::~cygheap_fdnew): New destructor increments reference count when
fd has been allocated.
(cygheap_fdget::fh): New (old?) field.
(cygheap_fdget::cygheap_fdget): Increment reference count when we've found an
active fd.  Set fh appropriately.
(cygheap_fdget::~cygheap_fdget): Decrement reference count when appropriate.
Delete fh if reference count goes to zero.
(cygheap_fdget::release): New function.  Do more bookkeping on release.
* dtable.cc (dtable::release): Change from void to boolean return.  Only delete
the fhandler when its reference count is <= 0 (this should be a fairly unusual
case).  Return true if fhandler has been deleted.
(cygwin_attach_handle_to_fd): Increment reference count when fh is assigned.
(dtable::init_std_file_from_handle): Ditto.
* dtable.h (dtable::release): Change return to boolean.
* fhandler.cc (fhandler_base::fhandler_base): Set new isclosed flag to false.
Set _refcnt to zero.
(fhandler_base::close): Simplify paranoid debugging output.  Set new isclosed()
flag.
(fhandler_base_overlapped::wait_overlapped): Use isclosed() flag to avoid
querying the exception handle.
* fhandler.h (fhandler_base::_refcnt): New field.
(fhandler_base::refcnt): New function.
(fhandler_base::isclosed): Implement.
(fhandler_base::fhandler_base): Set isclosed to false.
* syscalls.cc: Remove space after function before parentheses for several
strace printfs.
(dup): Add standard strace "leaver" code.
(dup2): Ditto.
(dup3): Ditto.
(remove): Ditto.
(getpid): Ditto.
(getppid): Ditto.
(lseek64): Fix strace debugging to correctly use %R.
* fhandler_termios.cc (fhandler_termios::tcsetpgrp): Avoid sending signals to
other processes if we're debugging since it can cause a deadlock with the
calling debugger.
* exceptions.cc (_cygtls::call_signal_handler): Add debugging-only strace
output.
2011-12-17 00:03:31 +00:00
Christopher Faylor 69864e48cb * mmap.cc (mlock): Add standard syscall return value debugging output.
(munlock): Ditto.
(posix_madvise): Ditto.
* signal.cc: Remove obsolete sigcatchers stuff throughout.
(sigaction_worker): Add function name parameter and use it to show standard
syscall return value debugging output.  Also add fault protection.
(sigaction): Accommodate extra argument to sigaction_worker.
(siginterrupt): Ditto.
* syscalls.cc (read): Remove obsolete sigcatchers stuff.
(readv): Ditto.
2011-12-03 23:55:21 +00:00
Christopher Faylor b9aa81491f Throughout, remove extra space after function name from debugging output.
Throughout, change syscalls to report on return values using new %R format
option.
* smallprint.cc (__small_vsprintf): Add parsing for %R to report on return
values and possible errno from syscalls.
* errno.cc (errmap): Add PRIVILEGE_NOT_HELD.
* fhandler_tty.cc (fhandler_pty_master::setup): When creating a thread use
shorter name to reduce debuggging output.
* select.cc (start_thread_pipe): Ditto.
(start_thread_serial): Ditto.
(start_thread_socket): Ditto.
(start_thread_mailslot): Ditto.
* sigproc.cc (talktome): Ditto.
2011-12-03 21:43:27 +00:00
Christopher Faylor 480b13a37a * sigproc.cc (remove_proc): Don't terminate the currently executing thread. 2011-11-29 15:34:49 +00:00
Christopher Faylor 56a1971526 Throughout use "have_execed" macro rather than "hExeced" global handle.
Throughout rename _PROC_* to _CH_*.
* child_info.h: Include "pinfo.h".
(child_info_types): Rename _PROC_* -> _CH_* to avoid confusion with similarly
named constants.
(_PROC_*): Delete unneeded aliases.
(PROC_*): Ditto.
(CURR_CHILD_INFO_MAGIC): Ditto.
(cchildren): Define using "pinfo_minimal".
(child_info::set_saw_ctrl_c): Move to
(child_info_spawn::set_saw_ctrl_c): Here.
(child_info_spawn::lock): New field.
(child_info_spawn::hExeced): Ditto.
(child_info_spawn::ev): Ditto.
(child_info_spawn::~child_info_spawn): Move to sigproc.cc.
(child_info_spawn::child_info_spawn): Ditto.
(child_info_spawn::cleanup): Declare new function.
(child_info_spawn::set_saw_ctrl_c): Move to this class.  Set flag only when
execed and return true when we have set the flag.
(child_info_spawn::child_info_spawn::signal_myself_exited): New function.
(child_info_spawn::wait_for_myself): Ditto.
(child_info_spawn::has_execed_cygwin): Ditto.
(child_info_spawn::has_execed): Ditto.  Replaces "hExeced" test.
(child_info_spawn::operator HANDLE&): New operator.
(child_info_spawn::worker): Define old "spawn_guts" as class member.
(ch_spawn): Declare.
(have_execed): Define.
(have_execed_cygwin): Ditto.
* cygheap.h: Update comment.
* dcrt0.cc (get_cygwin_startup_info): Use _CH_* enums.
(child_info_spawn::handle_spawn): Ditto.
(dll_crt0_0): Ditto.
(multiple_cygwin_problem): Ditto.
* exceptions.cc (chExeced): Delete obsolete declaration.
(ctrl_c_handler): Reference set_saw_ctrl_c via new ch_spawn global.
* globals.cc (hExeced): Delete.
* pinfo.cc (pinfo::thisproc): Refer to cygheap as ::cygheap for consistency in
handle naming when -DDEBUGGING.
(pinfo::init): Accommodate case where myself.h is known but h0 is passed in.
(pinfo::pinfo): New constructor for setting up a pinfo passed in by previous
exec'or.
(pinfo::proc_waiter): Don't handle subprocess if we're in the process of
exiting due to an exec of a cygwin process.  Don't close rd_proc_pipe here.
Close it when we actually are finished with the process.  Use new
ch_spawn.signal_myself_exited function to let exec stub know that subprocess
has exited.
(pinfo::wait): Clarify debugging output.
(pinfo::release): Use "close_h" to close all handles to avoid races.
(winpids::add): Assume that elements of the array do not need to be zeroed and
are properly initialized or suffer problems on pinfo::release.  Don't close
hProcess since release does that now.
* pinfo.h: Update comment.
(pinfo_minimal): Move some elements from pinfo here so that child_info_spawn
can use them.
(pinfo): Inherit from pinfo_minimal.
(pinfo::pinfo): Modify to accommodate new pinfo_minimal.
(pinfo::allow_remove): New function.
* sigproc.cc (proc_subproc): Use boolean values for true/false.  Implement
PROC_EXEC_CLEANUP.
(proc_terminate): Set ppid = 1 since the procs list will only be iterated when
the process has not execed.  Don't do any cleanup here since it is now handled
in pinfo::release.
(sigproc_init): Initialize sync_proc_subproc earlier.
(child_info::child_info): Assume that all important fields are properly
initialized and avoid memset().
(child_info_spawn::child_info_spawn): Specifically test for execing and then
set up appropriate fields in the struct.
(child_info_spawn::cleanup): Define new function.
(child_info_spawn::record_children): Specifically test for being execed here.
Fill in pinfo_minimal part of children array.
(child_info_spawn::reattach_children): Use constructor to duplicate information
for previous exec'or.  Add more debugging output.
(remove_proc): Force deletion of thread when exiting due to exec.  Rely on
pinfo::cleanup in release.
* sigproc.h (PROC_EXEC_CLEANUP): New enum.
(PROC_DETACHED_CHILD): Delete.
* spawn.cc (chExeced): Delete.
(child_info_spawn::worker): Rename from spawn_guts.  Use elements of
child_info_spawn throughout rather than ch.whatever.  Use ::cygheap to refer to
global rather than element of child_info.  Use wait_for_myself() rather than
waitpid().  Call child_info_spawn::cleanup on function return.
(spawnve): Reflect movement of spawn_guts functionality into
child_info_spawn::worker.
* syscalls.cc (popen): Ditto.
* winsup.h (spawn_guts): Delete declaration.
2011-11-14 01:29:49 +00:00
Christopher Faylor 65a6152f18 * cygwin.din (ptsname_r): Export.
* fhandler.cc (fhandler_base::ptsname_r): Define.
* fhandler.h (fhandler_base::ptsname): Delete.
(fhandler_base::ptsname_r): Declare.
(fhandler_pty_master::ptsname_r): Declare.
* fhandler_tty.cc (fhandler_pty_master::ptsname): Delete.
(fhandler_pty_master::ptsname_r): New reentrant function derived from previous
ptsname.
* syscalls.cc (ptsname_r): Implement new function with functionality similar to
Linux.
(ptsname): Use ptsname_r () to fill out buf.
* include/cygwin/stdlib.h (ptsname_r): Declare.
* include/cygwin/version.h: Bump CYGWIN_VERSION_API_MINOR to 255 to reflect
export of ptsname_r.
* pinfo.cc (pinfo::wait): Return bool rather than int.
* pinfo.h (info::wait): Ditto.
(pinfo::reattach): Define !defined(_SIGPROC_H) case for consistency.
* sigproc.cc (child_info_spawn::reattach_children): Use correct dwProcessId
rather than pid when duplicating handle.
2011-11-07 20:05:49 +00:00
Corinna Vinschen 28fa2a72f8 * syscalls.cc (check_dir_not_empty): Check surplus directory entries
by calling NtQueryAttributesFile.  Make STATUS_DIRECTORY_NOT_EMPTY
	return value dependent on its status code.  Add long comment to explain.
	(unlink_nt): Add comment to explain flaw in checking the sharing mode.
	Set status to STATUS_SUCCESS instead of 0.  Add a retry loop to setting
	the delete disposition and trying to move a directory to bin to
	workaround rare cases of lingering, already deleted subdirectory
	entries.  Add long comment to explain.
	(rename): Set status to STATUS_SUCCESS instead of 0.
2011-11-07 10:03:30 +00:00
Corinna Vinschen 53e93974c8 * syscalls.cc (unlink_nt): Fix a bug which overwrites the NT status
value in case setting the delete disposition returns with
	STATUS_DIRECTORY_NOT_EMPTY.
2011-10-24 14:02:32 +00:00
Corinna Vinschen 22e671336e * fhandler_disk_file.cc (fhandler_disk_file::rmdir): Check invalid
success only on Samba shares.
	* mount.cc (fs_info::update): Drop has_buggy_basic_info flag for
	NcFsd.
	* syscalls.cc (unlink_nt): Fix typo in comment.
2011-10-21 17:43:00 +00:00
Corinna Vinschen 69178ca038 * globals.cc (ro_u_ncfsd): New R/O unicode string.
* mount.cc (fs_info::update): Check for "NcFsd" FS.  Set flags and
	change comments accordingly.
	(fs_names): Add entry for NcFsd FS.
	* mount.h (enum fs_info_type): Add ncfsd.
	(class fs_info): Add ncfsd flag and accessor methods.
	* path.h (class path_conv): Add fs_is_ncfsd method.
	* syscalls.cc (unlink_nt): Experimentally try delete-on-close on NcFsd
	in STATUS_CANNOT_DELETE case.
2011-10-21 08:29:19 +00:00
Corinna Vinschen aa982024d1 * syscalls.cc (try_to_bin): Improve debug output.
(check_dir_not_empty): Take additional path_conv argument.  Improve
	debug output.  Change syscall_printf to debug_printf.
	(unlink_nt): Improve debug output.  Change syscall_printf to
	debug_printf.
	(unlink): Change syscall_printf to debug_printf.

	* cygthread.h: Fix copyright dates.
2011-10-20 10:59:01 +00:00
Christopher Faylor 23771fa1f7 * cygerrno.h (__set_errno): Modify debugging output to make searching strace
logs easier.  Throughout, change /dev/tty* to /dev/pty*.  Throughout, add flags
argument to fhandler_*::dup methods.
* devices.in: Rename (temporarily?) /dev/ttyN to /dev/ptyN.  Add /dev/ptymN
devices for pty masters.
* devices.cc: Regenerate.
* devices.h (MAX_CONSOLES): Set to max number supported by devices.in.
(fh_devices::FH_PTMX): Rename from FH_PTYM.
(device::operator int): Return by reference.
* dtable.cc (fh_alloc): Take pc as an argument rather than just the device.
This makes debugging easier since more information is available.  Actually
implement handling for already-allocated pty master devices.  Make different
decisions when generating fhandler for not-opened devices.  Add kludge to deal
with opening /dev/tty.
(cnew_no_ctor): New macro.
(build_fh_pc): Make debugging output more verbose.  Use new clone() fhandler
interface to duplicate archetypes.  Reset last term opened.
(dtable::dup_worker): Use Use new clone() fhandler interface to duplicate
archetypes.  Pass flags to child dup handler.
(dtable::dup3): Set O_NOCTTY flag if newfd is not stdin/stdout/stderr.
* fhandler.cc (fhandler_base::reset): Rename from operator =() and reduce
functionality and sense of copy direction.
(fhandler_base::open_with_arch): Use published interface to query io_handle().
Use new copyto() fhandler method to copy from/to found archetype.
* fhandler.h: Throughout, delete size(), add copyout, clone, and fhandler_*
(void *) methods.
(fhandler_base::reset): Rename from operator =().
(fhandler_termios::is_dev_tty): Delete.
(fhandler_termios): change "protected" region to "private".
(fhandler_termios::is_dev_tty): Delete.
(fhandler_termios): Rearrange protected/public.
(fhandler_termios::fhandler_termios): Remember last fhandler_termios "opened".
(fhandler_termios::~fhandler_termios): Forget last fhandler_termios opened.
(ioctl): Rename from ioctl_termios.  Take a void * argument.  Reflect argument
change in pinfo::set_ctty.
(fhandler_console::dup): Declare new function.  Set ctty here if appropriate.
(fhandler_pty_master::from_master): Privatize.
(fhandler_pty_master::to_master): Ditto.
(fhandler_pty_master::dwProcessId): Ditto.
(fhandler_pty_master::fhandler_pty_master): Add an `int' argument.
(fhandler_pty_master::open_setup): Declare new function.
(fhandler_pty_master::~fhandler_pty_master): Declare new method.
(fhandler_nodevice): Remove commented out function declaration.
* fhandler_console.cc: Use get_ttyp() instead of tc() throughout.
(fhandler_console::dup): Define new function to set controlling ctty on dup, as
appropriate.
(fhandler_console::ioctl): Reflect ioctl_termios name change.
(fhandler_console::setup): Rename from get_tty_stuff.
(fhandler_console::open_setup): Reflect argument change in pinfo::set_ctty.
(fhandler_console::fhandler_console): Set _tc here.
* fhandler_termios.cc (handler_termios::ioctl): Rename.  Take a void * arg like
other ioctl functions.
* fhandler_tty.cc (fhandler_pty_slave::dup): Call myself->set_ctty to
potentially reset the controlling terminal.
(fhandler_pty_slave::ioctl): Reflect name/arg change for ioctl_termios.
(fhandler_pty_slave::fhandler_pty_slave): Take a "unit" argument.  Call setup()
here so that we will know the unit number of this fhandler as soon as possible.
Set the unit as appropriate.
(handler_pty_master::open): Move most stuff to constructor and open_setup.
(handler_pty_slave::open_setup): Reflect argument change in pinfo::set_ctty.
(handler_pty_master::open_setup): Define new function.
(fhandler_pty_master::cleanup): Clear handles as a flag that the destructor
does not have to do "close" operations.
(fhandler_pty_master::close): Ditto.
(fhandler_pty_master::~fhandler_pty_master): Define new method.
(fhandler_pty_master::ioctl): Reflect name/arg change for ioctl_termios.
(fhandler_pty_master::setup): Allocate tty here.  Rely on handles being
returned from allocated test rather than opening them here.  Avoid setting
_need_nl here since it is already zeroed in the constructor.  Set up device
information with DEV_TTYM_MAJOR.
* path.h (path_conv &operator =): Take a const argument.
(path_conv::dup): Ditto.
(pathconv_arg::PC_OPEN): New enum.
(pathconv_arg::PC_CTTY): Ditto.
(path_types::PATH_CTTY): Ditto.
(path_types::PATH_OPEN): Ditto.
(path_conv::isopen): New method.
(path_conv::isctty_capable): Ditto.
* path.cc (path_conv::check): Set PATH_OPEN and PATH_CTTY as appropriate.
* pipe.cc (fhandler_pipe::open): Use copyto to copy pipe handle.
* syscall.cc (open): Reinstate fd > 2 check to disallow resetting ctty on
non-std* handles.
* tty.cc (tty_list::allocate): Pass out handles for allocated tty.  use
`not_allocated' to find unallocated ttys.  Avoid keeping the lock since the
allocation of the tty should be sufficient to prevent multiple access.
(tty::not_allocated): Clarify comment.  Rename.  Return handles when an unused
tty is found.  Simply test for existing tty.
(tty::exists): Rewrite to use `not_allocated'.
* tty.h (NTTYS): Reset down to actual number supported by devices.in.
(tty::not_allocated): Declare new function.
(tty_list::allocate): Pass out read/write tty handles.  Zero them when not
found.
* fhandler_proc.cc: Reflect name change from FH_PTYM -> FH_PTMX.
* pinfo.h (pinfo::set_ctty): Reduce/reorder arguments passed in.
* pinfo.cc (pinfo::set_ctty): Ditto.  Just use tc() built into the passed-in
fhandler_termios pointer.  Return true if ctty is assigned.
* syscalls.cc (open): Call build_fh_pc with PC_OPEN flag.  Set PC_CTTY if
appropriate.
(stat_worker): Remove is_dev_tty () stuff.
2011-10-15 22:37:30 +00:00
Christopher Faylor 4add6f8db1 * cygwin.din: Remove some _tc* exports. Add tcgetsid().
* dtable.cc (fh_alloc): Revert ill-advised setting of major/minor.  Use new
is_dev_tty to remember that this device was opened as /dev/tty.
* fhandler.cc (fhandler_base::fstat): Remove leftover debugging statement.
(fhandler_base::tcgetsid): New function.
* fhandler.h ((fhandler_base::tcgetsid): Declare new function.
(fhandler_base::is_dev_tty): Ditto.
(fhandler_termios::opened_as_dev_tty): Declare new field.
(fhandler_termios::is_dev_tty): Declare new function.
(fhandler_termios::tcgetsid): Ditto.
(fhandler_pty_common::use_archetype): Move here from subclass.
(fhandler_pty_slave::use_archetype): Move up.
(fhandler_pty_master::use_archetype): Ditto.
* fhandler_console.cc (fhandler_console::ioctl): Rename second argument from
`buf' to `arg' for consistency.  Call ioctl_termios for common fhandler_termios
ioctl handling.
* fhandler_tty.cc (fhandler_pty_slave::ioctl): Call ioctl_termios for common
fhandler_termios ioctl handling.
(fhandler_pty_master::ioctl): Ditto.
* fhandler_termios.cc (fhandler_termios::tcgetsid): Implement new function.
(fhandler_termios::ioctl_termios): Ditto.  Implements TIOCSCTTY handling.
* syscalls.cc (stat_worker): Set /dev/tty device info when appropriate.
* termios.cc (tcgetpgrp): Avoid extraneous "isatty" check.
(tcgetsid): Implement new function.
* include/cygwin/version.h: Bump CYGWIN_VERSION_API_MINOR to 253.
* include/sys/termios.h (TIOCSCTTY): Define.
2011-10-11 23:20:38 +00:00
Christopher Faylor be96a30c43 * syscalls.cc (open): Add temporary kludge to avoid assigning the controlling
tty on open unless the open is for stdin/stdout/stderr.
* tty.cc (tty_list::connect): Set ENXIO when can't find a tty.
2011-10-10 22:01:06 +00:00
Corinna Vinschen d32e0bfc08 * syscalls.cc (faccessat): Fix parens in flag expression when calling
build_fh_name.

	* fhandler_disk_file.cc (fhandler_disk_file::mkdir): Fix typo in
	comment.
	* fhandler_socket.cc (fhandler_socket::bind): Ditto.
	* path.cc (symlink_worker): Ditto.
2011-08-01 17:01:38 +00:00
Corinna Vinschen 303dc0230d * fhandler_disk_file.cc (__DIR_mounts::eval_ino): Create path_conv
with PC_KEEP_HANDLE flag.
	* path.h (path_conv::operator =): Duplicate UNICODE path as well.
	* security.cc (check_file_access): Use path_conv handle if available.
	* syscalls.cc (access): Create fhandler with PC_KEEP_HANDLE flag set.
	(euidaccess): Ditto.
	(faccessat): Ditto.
2011-07-26 13:30:41 +00:00
Christopher Faylor b86f999af1 whitespace elimination 2011-06-06 05:02:13 +00:00
Christopher Faylor 44d2fc0a45 * autoload.cc: Call _api_fatal in asm.
* child_info.h: Redefine CURR_CHILD_INFO_MAGIC.
(child_info_fork::abort): Rename from handle_failure.  Change arguments.
* cygtls.h (_local_storage::ttybuf): New field.
* dcrt0.cc (vapi_fatal): Split api_fatal.  Add "in forked process" to message
when appropriate.
(api_fatal): Use vapi_fatal.
* devices.h: Make multiple inclusion safe.
(fh_devices): Add FH_CONS* stuff.  Reorder slightly.
(device): Eliminate anonymous union.  Add more ways to access minor/major.
(device::setunit): Accommodate no-longer-anonymous union.
(device::is_fs): Ditto.
(device::is_fs_special): Ditto.
(device::major): New function.
(device::minor): Ditto.
(device::is_device): New function.
(device::not_device): Ditto.
(device::operator int): New operator.
(device::operator fh_devices): Ditto.
(device::operator bool): Ditto.
(device::operator DWORD): Ditto.
(device::operator =): Ditto.
(isproc_dev): New function.
(isprocsys_dev): Ditto.
(iscons_dev): Ditto.
(istty_slave_dev): Ditto.
* devices.in: Add new "/dev/cons*" strings.  Accommodate no-longer-anonymous
union throughout.
(BRACK): Use more precise method for initialization.
* devices.cc: Regenerate.
* dtable.cc (dtable::stdio_init): Use get_cttyp instead of get_tty.
(dtable::find_archetype): Use new DWORD operator in device to test archetypes.
(dtable::init_std_file_from_handle): Use different method to initialize 'dev'.
Adapt to different ctty handling and accommodate /dev/cons*.
(fh_alloc): Accommodate no-longer-anonymous union.  Adapt to new /dev/cons*.
(build_fh_pc): Make debugging output more useful.
* exceptions.cc (ctrl_c_handler): Use get_cttyp instead of get_tty.
* external.cc (fillout_pinfo): Accommodate new cons* stuff.
* fhandler.cc (fhandler_base::read): Eliminate is_slow() test.
* fhandler.h (fhandler_base::*): Adapt to changes in device.h.
(fhandler_*::is_slow): Delete.
( fhandler_proc::get_proc_fhandler): Return fh_devices type.
* fhandler_console.cc (open_shared_console): New function.
(console_unit): New class.
(console_unit::console_unit): New constructor.
(enum_windows): New function.  Declare as friend to console_unit.
(fhandler_console::set_unit): New function.
(fhandler_console::get_tty_stuff): Call set_unit to set the unit number and
determine if initialization is needed.  Eliminate flags parameter.
(tty_list::get_cttyp): Rename (sorta) from get_tty.  Return pointer to correct
tty_min.
(fhandler_console::open): Adapt to elimination of argument to get_tty_stuff.
(fhandler_console::output_tcsetattr): Properly detect error condition.
(fhandler_console::fixup_after_fork_exec): Adapt to get_tty_stuff() setting tc
automatically.
* fhandler_proc.cc: Use FH_BAD rather than 0 throughout where using fh_devices
enum.
(fhandler_proc::get_proc_fhandler): Return fh_devices.  Adapt to devices.h
changes.
* fhandler_process.cc: Adapt to devices.h changes.  Use FH_BAD rather than 0
throughout where using fh_devices enum.
* fhandler_procnet.cc: Ditto.
* fhandler_procsys.cc: Ditto.
* fhandler_procsysvipc.cc: Ditto.
* fhandler_tape.cc (fhandler_dev_tape::fhandler_dev_tape): Ditto.
* fhandler_termios.cc (handler_termios::bg_check): Use tc->ttyname() rather
than assuming that we can construct a tty.
* fhandler_tty.cc (fhandler_tty_master::fhandler_tty_master): Just return
get_minor() of dev.
(fhandler_pty_master::process_slave_output): Add slightly more debugging info.
(fhandler_tty_slave::fhandler_tty_slave): Change name from ntty to unit.
(fhandler_pty_master::open): Ditto.
(fhandler_tty_slave::ioctl): Adapt to change which causes ctty to represent a
complete device.
(fhandler_tty_master::init_console): Add debugging for failure path.
(fhandler_pty_master::setup): Use get_unit() to retrieve unit number rather
than relying on raw ntty.
(fhandler_pty_master::setup): Ditto.
* fhandler_virtual.h (virt_tab_t): Redefine fhandler as fh_devices.
* fork.cc: Remove obsolete vfork stuff.
(frok::child): Don't assume that a ctty == 0 is valid.
* mount.cc (mount_info::conv_to_win32_path): Adapt to device struct changes.
(mount_info::conv_to_win32_path): Ditto.
* path.cc (path_conv::check): Retrive major/minor numbers via a method rather
than accessing them directly from device.  Rely on dev operators to
set/retrieve device information as required by device struct change.
* path.h (isproc_dev): Move to devices.h.
(isprocsys_dev): Ditto.
(isvirtual_dev): Ditto.
(path_conv:{isdevice,isfifo,isspecial,iscygdrive,issocket,get_devn,get_unitn}):
Use device methods to access/manipulate devices.
* pinfo.cc (pinfo::exit): Don't assume that ctty == 0 is valid.  Use iscons_dev
to determine if a device is a console.
(_pinfo::_ctty): Use device::parse to generate tty/cons name.
(_pinfo::set_ctty): Don't assume that ctty == 0 is valid.  Remove redundant
info from debugging.
* shared.cc (offsets): Remove console offset.
* shared_info.h (shared_locations): Ditto.
* syscalls.cc (umask): Use device methods to manipulate device information.
(ctermid): Use device::parse to generate term device name.
* tlsoffsets.h: Regenerate.
* tty.cc (ttyslot): Return minor number of ctty since ctty now represents a
full device.
(tty::create_master): Set ctty to a complete device.
(tty_list::attach): Rework to detect new /dev/cons* stuff.
(tty_list::terminate): Adapt to changes to ctty.
(tty_list::init): Adapt to change to setntty - pass in device major number.
(tty::exists): Use get_unit() to retrive tty unit number.
(tty::open_mutex): Ditto.
(tty::open_inuse): Ditto.
(tty::create_inuse): Ditto.
(tty::get_event): Ditto.
(tty_min::ttyname): Define new function.
* tty.h (tty_min::ntty): Redefine as fh_devices.
(tty::exists): Use get_unit() to retrive tty unit number.
(tty::open_mutex): Ditto.
(tty::open_inuse): Ditto.
(tty::create_inuse): Ditto.
(tty::get_event): Ditto.
(tty_min::ttyname): Declare new function.
(tty::getntty): Declare as const.
(tty_list::operator []): Assure that only minor part of argument is used.
* dll_init.cc (dll_list::alloc): Detect mismatch of data segments early issuing
an explicit error message if necessary.
* heap.cc (heap_init): Adapt to changes from fork->handle_failure to
fork->abort.
* pinfo.h (EXITCODE_FORK_FAILED): New enum.  (from Ryan Johnson)
* sigproc.cc (child_info_fork::abort): Rename from handle_failure.  Change
arguments to allow passing in a printf-like message.
* winsup.h (api_fatal): Delete macro definition.
(api_fatal): Redefine from __api_fatal.
(vapi_fatal): Declare new function.
* include/sys/strace.h (strace_vprintf): Define new macro.
* ntdll.h (_SYSTEM_INFORMATION_CLASS): Add SystemHandleInformation.
2011-05-28 18:17:09 +00:00
Corinna Vinschen c29e693388 * fhandler_proc.cc (format_proc_uptime): Don't call GetSystemInfo.
Fetch CPU count from wincap.
	(format_proc_stat): Ditto.
	* globals.cc (system_info): Move to wincap.
	* heap.cc (heap_init): Fetch page size from wincap.
	* syscalls.cc (getpagesize): Fetch allocation granularity from wincap.
	(getsystempagesize): Fetch page size from wincap.
	* wincap.cc (wincap_2003): Default is_server to false.
	(wincapc::init): Call GetSystemInfo here.  Always set is_server value.
	* wincap.h (class wincapc): Add system_info as private member.
	(wincapc::cpu_count): New public method.
	(wincapc::page_size): Ditto.
	(wincapc::allocation_granularity): Ditto.
2011-05-10 15:39:02 +00:00
Corinna Vinschen a4e5706eb2 * fhandler.h (fhandler_socket::read): Declare.
(fhandler_socket::write): Declare.
	* fhandler_procsys.cc (fhandler_procsys::read): Add FIXME comment.
	(fhandler_procsys::write): Ditto.
	* fhandler_socket.cc (fhandler_socket::read): New method.
	(fhandler_socket::write): New method.
	* syscalls.cc: Rearrange order of read/write functions.
	(read): Call fhandler read method directly instead of just readv.
	(readv): Remove EINTR loop.  This is done in all affected fhandler's
	now.
	(write): Call fhandler write method directly instead of just writev.
	Fix debug output.
2011-05-06 10:56:37 +00:00
Christopher Faylor 92ddb74290 * cygheap.cc (cygheap::close_ctty): Close ctty via close_with_arch().
* debug.cc (close_handle): Call debugger on failure.
* devices.in (device::tty_to_real_device): Delete.
* devices.h (device::tty_to_real_device): Ditto.
* devices.cc: Regenerate.
* dtable.cc: Delete old ifdef'ed vfork code.
(dtable::release): Don't handle archetype here.
(dtable::init_std_file_from_handle): Consolidate console tests.  Generate
major/minor for tty ASAP.  Fix incorrect setting of DEV_TTYS* for serial.
(fh_alloc): New function derived from build_fh_pc.  Pass current tty when
building tty.
(build_pc_pc): Use fh_alloc to create.  Set name from fh->dev if appropriate.
Generate an archetype or point to one here.
(dtable::dup_worker): Deal with archetypes.  Rely on = operator copying whole
class rather than just fhandler_base.
(dtable::fixup_after_exec): Call close_with_arch to handle closing of fhandlers
with archetypes.
* fhandler.cc (fhandler_base::operator =): Call memcpy with fhandler's size()
rather than sizeof fhandler_base.
(fhandler_base::open_with_arch): New function.  Handles opening of fhandler's
with archetypes, dealing with usecounts, etc.
(fhandler_base::close_with_arch): Ditto for close.
* fhandler.h: Many changes for archetypes.
(fhandler_base::set_name): Set both normalized path and regular path.
(fhandler_base::open_with_arch): New function.
(fhandler_base::open_setup): Ditto.
(fhandler_base::use_archetype): Ditto.
(fhandler_base::_archetype_usecount): Ditto.
(fhandler_*::size): Ditto.
(fhandler_dev_tape::open): Remove virtual decoration.
(fhandler_console::use_archetype): New function.  Return true.
(fhandler_console::open_setup): New function.
(fhandler_console::dup): Delete.
(fhandler_tty_slave::fhandler_tty_slave): Redeclare to take an argument.
(fhandler_tty_slave::use_archetype): New function.  Return true.
(fhandler_tty_slave::cleanup): New function.
(fhandler_pty_master::use_archetype): New function.  Return true.
(fhandler_pty_master::cleanup): New function.
(fhandler_pty_master::is_tty_master): New function.  Return false.
(fhandler_tty_master::is_tty_master): New function.  Return true.
(fhandler_dev_dsp::fhandler_dev_dsp): New function.  Return true.
(report_tty_counts): Only report on archetype's usecount if there is one.
* fhandler_console.cc (fhandler_console::get_tty_stuff): Remove handling of
setsid, set_ctty, set_flags, and manage_console_count.
(fhandler_console::open_setup): New function.  Implement functionality removed
from get_tty_stuff.
(fhandler_console::dup): Delete.
(fhandler_console::output_tcsetattr): Set errno on error.
(fhandler_console::fhandler_console): Set device early.
(fhandler_console::init): Use open_with_arch to open console handles.
(fhandler_console::fixup_after_fork_exec): Nuke most of the stuff for dealing
with console handles.
* fhandler_dsp.cc (fhandler_dev_dsp::open): Remove archetype handling.
(fhandler_dev_dsp::write): Ditto.
(fhandler_dev_dsp::read): Ditto.
(fhandler_dev_dsp::close): Ditto.
(fhandler_dev_dsp::dup): Ditto.
(fhandler_dev_dsp::ioctl): Ditto.
(fhandler_dev_dsp::fixup_after_fork): Ditto.
(fhandler_dev_dsp::fixup_after_exec): Ditto.
* fhandler_tty.cc (fhandler_tty_common::__acquire_output_mutex): Add a little
more debugging.
(fhandler_tty_common::__release_output_mutex): Ditto.
(fhandler_pty_master::process_slave_output): Ditto.  Don't do signal handling
or pthread_cancel handling in the tty master thread.
(process_output): Minor reorg.
(fhandler_tty_slave::fhandler_tty_slave): Set device based on new ntty
argument.
(fhandler_tty_slave::open): Remove archetype handling.  Move some processing
into open_setup().
(fhandler_tty_slave::open_setup): New function.
(fhandler_tty_slave::cleanup): New function.
(fhandler_tty_slave::close): Remove archetype handling.  Move some processing
into cleanup().
(fhandler_tty_slave::init): Rename argument from f to h.  Open device using
open_with_arch().  Remove archetype handling.
(fhandler_pty_master::dup): Ditto.
(fhandler_pty_master::open): Ditto.
(fhandler_pty_master::close): Ditto.  Move some handling to cleanup().
(fhandler_pty_master::cleanup): New function.
(fhandler_tty_master::init_console): Give unique name to captive console
fhandler.
* pinfo.cc (_pinfo::set_ctty): Rename argument from arch to fh.  Eliminate
archetype assumption.
* syscalls.cc (close_all_files): Use close_with_arch for closing.
(open): Use open_with_arch() rather than open().
(close): Use close_with_arch() rather than close().
2011-05-05 22:30:53 +00:00
Corinna Vinschen d8ff96389f * pinfo.h (class push_process_state): New class to push a process state
flag temporarily into myself->process_state.
	* fhandler_console.cc (fhandler_console::read): Add push_process_state
	handler.
	(fhandler_console::write): Call bg_check from here.  Add
	push_process_state handler.
	* fhandler_tty.cc (fhandler_tty_slave::write): Ditto.
	(fhandler_tty_slave::read): Ditto.
	(fhandler_pty_master::write): Ditto.
	(fhandler_pty_master::read): Ditto.
	* syscalls.cc (readv): Remove bg_check call and setting process state.
	(writev): Ditto.
2011-05-05 19:43:04 +00:00
Corinna Vinschen 23db0a41d8 * syscalls.cc (readv): Add myfault handler. Don't check repeatedly
open state of file handler.  Streamline loop.
	(writev): Add myfault handler.
2011-05-05 18:46:38 +00:00
Corinna Vinschen 54e4df33a2 * fhandler.h (class fhandler_base): Remove uninterruptible_io status
flag.
	(fhandler_base::ready_for_read): Remove declaration.
	(fhandler_socket::ready_for_read): Ditto.
	(fhandler_pipe::ready_for_read): Ditto.
	(fhandler_tty_master::is_slow): Remove.
	* fhandler_console.cc (fhandler_console::open): Drop setting
	uninterruptible_io.
	* fhandler_serial.cc (fhandler_serial::open): Ditto.
	* fhandler_tty.cc (fhandler_tty_slave::fhandler_tty_slave): Ditto.
	(fhandler_tty_master::init_console): Ditto.
	* pipe.cc (fhandler_pipe::fhandler_pipe): Ditto.
	(fhandler_pipe::open): Ditto.
	(_pipe): Ditto.
	* select.cc (fhandler_pipe::ready_for_read): Remove.
	(fhandler_base::ready_for_read): Remove.
	* syscalls.cc (readv): Drop unneeded wait variable.  Remove entire test
	which might lead to calling ready_for_read.  Remove now unused label
	out.
2011-05-04 13:06:10 +00:00
Corinna Vinschen 1804be048a * fcntl.cc (fcntl64): Call pthread_testcancel.
* fhandler_socket.cc (fhandler_socket::connect): Ditto.
	(fhandler_socket::accept4): Ditto.
	(fhandler_socket::recvfrom): Ditto.
	(fhandler_socket::recvmsg): Ditto.
	(fhandler_socket::sendto): Ditto.
	(fhandler_socket::sendmsg): Ditto.
	* flock.cc (lf_setlock): Allow to cancel thread running blocking
	file lock.  Try to make code more readable.
	(lockf): Call pthread_testcancel.
	* mmap.cc (msync): Ditto.
	* posix_ipc.cc (ipc_cond_timedwait): Call pthread::static_cancel_self
	rather than pthread_testcancel.
	* select.cc (cygwin_select): Call pthread_testcancel.
	* syscalls.cc (pread): Ditto.
	(pwrite): Ditto.
	(readv): Ditto.
	(writev): Ditto.
	(open): Ditto.
	(close): Ditto.
	(fsync): Ditto.
	* termios.cc (tcdrain): Ditto.
	* thread.cc: Align list of cancellation points with above changes.
	Mark not-implemented functions, too.
	(cancelable_wait): Don't set unused object indices to WAIT_FAILED
	since that could result in wrong behaviour.  Set them to the invalid
	value WAIT_TIMEOUT + 1 instead.
2011-04-30 16:34:48 +00:00
Corinna Vinschen 12eac211c9 * advapi32.cc (GetTokenInformation): Remove.
(SetTokenInformation): Remove.
	* grp.cc: Replace above functions throughout with their ntdll.dll
	equivalent.
	* sec_auth.cc: Ditto.
	* syscalls.cc: Ditto.
	* uinfo.cc: Ditto.
2011-04-29 07:34:05 +00:00
Corinna Vinschen b18cb86be7 * Makefile.in (DLL_IMPORTS): Drop advapi32.dll.
* autoload.cc: Enable autoloading advapi32 functions.
	* environ.cc (regopt): Use wide char arguments in reg_key functions.
	* fhandler_console.cc (beep): Ditto.  Use WCHAR throughout.
	* registry.cc (reg_key): Rewrite reg_key class to use native NT registry
	functions.  Use WCHAR string parameters throughout.  Use PCWSTR rather
	than const WCHAR.  Drop multibyte char functionality.  Drop unused
	methods.
	(get_registry_hive_path): Use RtlQueryRegistryValues to fetch path from
	registry.
	(load_registry_hive): Drop useless check for user hive being available.
	Load hive using NtLoadKey.
	* registry.h: Accommodate above changes.
	* sched.cc (sched_rr_get_interval): Use wide char arguments in reg_key
	functions.
	* shared.cc (init_installation_root): Ditto.
	(shared_info::init_obcaseinsensitive): Use RtlQueryRegistryValues to
	fetch obcaseinsensitive value.
	(shared_info::heap_slop_size): Use wide char arguments in reg_key
	functions.
	(shared_info::heap_chunk_size): Ditto.
	* syscalls.cc (gethostid): Ditto.
	* winsup.h (__WIDE): Define.
	(_WIDE): Define.
	* libc/minires-os-if.c (get_registry_dns_items): Don't fetch values
	from registry.  Just extract them from given UNICODE_STRING parameter.
	(get_registry_dns): Fetch all registry values at once using
	RtlQueryRegistryValues.
2011-04-19 10:02:06 +00:00
Corinna Vinschen 6ce541281e Drop NT4 support.
* autoload.cc (DnsQuery_A): Fatal if not available.
	(DnsRecordListFree): Ditto.
	(DsGetDcNameW): Ditto.
	(NetGetAnyDCName): Remove.
	(NetGetDCName): Remove.
	(EnumProcessModules): Fatal if not available.
	(GetModuleFileNameExW): Ditto.
	(GetModuleInformation): Ditto.
	(GetProcessMemoryInfo): Ditto.
	(QueryWorkingSet): Ditto.
	(LsaRegisterLogonProcess): Ditto.
	* fenv.cc (_feinitialise): Drop supports_sse condition.
	* fhandler_disk_file.cc (path_conv::isgood_inode): Fix comment.
	(fhandler_base::fstat_by_name): Drop has_fileid_dirinfo condition.
	(fhandler_disk_file::opendir): Ditto.
	* fhandler_netdrive.cc (fhandler_netdrive::readdir): Fix comment.
	* fhandler_proc.cc (format_proc_partitions): Drop NT4-only code.
	* fhandler_process.cc (get_process_state): Ditto.
	* kernel32.cc (GetWindowsDirectoryW): Remove.
	(GetWindowsDirectoryA): Remove.
	* miscfuncs.cc (nice_to_winprio): Drop NT4-only code.
	* mount.cc (fs_info::update): Fix comments.
	* net.cc (get_2k_ifs): Drop NT4-only code.
	* sec_auth.cc (get_logon_server): Ditto.
	(lsaauth): Drop NT4-specific error handling.
	* security.cc (alloc_sd): Set SE_DACL_PROTECTED unconditionally.
	* select.cc (select_stuff::wait): Always use MWMO_INPUTAVAILABLE.
	(peek_windows): Drop NT4-only condition in call to PeekMessage.
	* syscalls.cc (gethostid): Remove NT4-only workaround.
	* wincap.cc: Througout, drop has_dacl_protect,
	has_broken_if_oper_status, has_process_io_counters,
	has_terminal_services, has_extended_priority_class, has_guid_volumes,
	has_fileid_dirinfo, has_mwmo_inputavailable and supports_sse from
	wincaps.
	(wincap_nt4sp4): Remove.
	(wincap_minimal): Set to wincap_2000.
	(wincapc::init): Rely on availability of OSVERSIONINFOEX structure.
	Treat error from GetVersionEx as fatal.  Treat NT4 as fatal.
	* wincap.h (struct wincaps): Drop has_dacl_protect,
	has_broken_if_oper_status, has_process_io_counters,
	has_terminal_services, has_extended_priority_class, has_guid_volumes,
	has_fileid_dirinfo, has_mwmo_inputavailable and supports_sse flags
	and methods.
	* winlean.h (GetWindowsDirectoryW) Define as GetSystemWindowsDirectoryW.
	(GetWindowsDirectoryA): Define as GetSystemWindowsDirectoryA.
2011-04-04 12:23:36 +00:00
Corinna Vinschen 0d6f2b0117 * autoload.cc (FindFirstVolumeA): Remove.
(FindNextVolumeA): Remove.
	(FindVolumeClose): Remove.
	(GetVolumeNameForVolumeMountPointA): Remove.
	* ntdll.h (NtFlushBuffersFile): Declare.
	* syscalls.cc (sync_worker): Rewrite using native NT functions.
	(sync): Ditto.
2011-04-02 11:43:43 +00:00
Corinna Vinschen 5f660ecf24 * autoload.cc (UuidCreate): Remove.
(UuidCreateSequential): Remove.
	* passwd.cc (internal_getpwsid): Avoid a strict-aliasing compiler
	error with gcc 4.5.1.
	* fhandler_floppy.cc (fhandler_dev_floppy::get_drive_info): Ditto.
	* ntdll.h (NtAllocateUuids): Declare.
	* syscalls.cc (gethostid): Use NtAllocateUuids function rather than
	UuidCreateSequential/UuidCreate to get rid of rpcrt4 dependency.
2011-03-29 10:42:11 +00:00
Corinna Vinschen 12374d7d2f * dcrt0.cc: Fix copyright dates.
* winsup.h: Ditto.
	* syscalls.cc (_read): Move EXPORT_ALIAS to its rightful place.
2011-02-22 09:17:57 +00:00
Corinna Vinschen 3591470260 * Throughout fix copyright dates. 2011-02-15 15:56:03 +00:00
Corinna Vinschen 2daa7e07ce * syscalls.cc (utmp_data): Fix potential buffer overflow. 2011-01-31 13:58:59 +00:00
Corinna Vinschen a1c35b8b65 * syscalls.cc (rename): Fix permission problem with symlinks on NFS.
Rework how NtOpenFile gets called to make it more readable.  Change
	comment.
2011-01-21 13:13:00 +00:00
Corinna Vinschen e52961c403 * syscalls.cc (check_dir_not_empty): Never count more than 3 directory
entries.
2010-12-12 15:32:45 +00:00
Corinna Vinschen 41c91ad68d * syscalls.cc (gethostid): Use correct path to ProductId registry value. 2010-09-28 07:54:52 +00:00
Corinna Vinschen 4c9d01fdad * mount.h (class fs_info): Add has_buggy_reopen flag and accessor
methods.
	* mount.cc (fs_info::update): Set has_buggy_reopen flag for NWFS.
	Add comment.
	* path.h (path_conv::get_object_attr) Make inline method.
	(path_conv::init_reopen_attr): New inline method.
	* path.cc (path_conv::get_object_attr): Remove.
	* fhandler_disk_file.cc (fhandler_base::fstat_helper): Use
	path_conv::init_reopen_attr method to initialize OBJECT_ATTRIBUTE for
	reopening file.
	(fhandler_disk_file::fchmod): Ditto.
	(fhandler_base::utimens_fs): Ditto.
	(fhandler_disk_file::rewinddir): Ditto.
	* syscalls.cc (unlink_nt): Ditto.
2010-09-21 16:32:22 +00:00
Corinna Vinschen 18df393573 * syscalls.cc (start_transaction): Make inline function. Move up to be
more generally available.
	(stop_transaction): Ditto.
	(unlink_nt): Potentially start transaction when trying to delete file
	with DOS R/O attribute set.  If file is .lnk symlink, check for number
	of hardlinks.  Add "out" label and only return via "out".  Rearrange
	reversion of DOS R/O attribute and, on success, only revert R/O
	attribute if file is .lnk symlink with more than one hardlink.  Add
	length comment to explain why.
2010-09-12 11:41:56 +00:00
Corinna Vinschen f7dea7f233 * syscalls.cc (rename): Limit retry loop in case of sharing violation
to about a second.
2010-09-10 19:55:26 +00:00
Corinna Vinschen 396561aa0b * syscalls.cc (fstatat): Call stat_worker directly from here. 2010-09-10 18:51:44 +00:00
Corinna Vinschen df70da7f6c * syscalls.cc (rename): Open file with FILE_READ_ATTRIBUTES. 2010-08-25 08:51:41 +00:00
Corinna Vinschen dd442880af * fhandler_disk_file.cc (fhandler_disk_file::fstatvfs): Revert usage
of get_stat_handle () to get_handle ().  Add comment to explain why.
	* syscalls.cc (statvfs): Drop using PC_KEEP_HANDLE.
2010-08-20 08:52:25 +00:00
Corinna Vinschen ce9898da68 * syscalls.cc (rename): Fix renaming file-based devices. 2010-08-18 15:21:35 +00:00
Corinna Vinschen 975a85f42c * syscalls.cc (unlink_nt): Disable try_to_bin for netapp drives.
Explain why.
2010-07-07 07:53:22 +00:00
Corinna Vinschen 5a0d1edba4 * dtable.cc (dtable::dup_worker): Reset path_conv handle in duplicated
fhandler.
	* fhandler.cc (fhandler_base::fstatvfs): Keep handle in created
	path_conv.
	* fhandler.h (fhandler_base::get_stat_access): New method.
	(fhandler_base::get_stat_handle): New method.
	* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Use handle
	returned by get_stat_handle.  Only request inode from system if it
	isn't already set in the fhandler, and only for filesystems supporting
	them.
	(fhandler_base::fstat_fs): Use handle returned by get_stat_handle.
	Change the way open_fs is called.  Explain why.
	(fhandler_base::fstat_helper): Use handle returned by get_stat_handle.
	Never use 0 inode number.  Simplify executable recognition by re-using
	get_stat_handle if file could be opened with sufficient rights.
	(fhandler_disk_file::fstatvfs): Use handle returned by get_stat_handle.
	(fhandler_disk_file::facl): Use handle returned by get_stat_handle in
	GETACL and GETACLCNT cases.
	(fhandler_disk_file::link): Use handle returned by get_stat_handle
	instead of opening file here again.  Add comment.
	(readdir_get_ino): Keep handle in created path_conv and drop
	opening file.
	* ntdll.h (wait_pending): New helper function.
	* path.cc (symlink_info::check): Drop unused 'opt' parameter from
	declaration.  Add path_conv_handle argument.
	(path_conv::check): Make sure conv_handle is closed.  Keep
	PC_KEEP_HANDLE flag in pflags_or.  Accommodate call to sym.check to
	new args.
	(path_conv::~path_conv): Close conv_handle.
	(symlink_info::check_shortcut): Don't re-open file here, just use
	incoming handle.  Drop goto's and label out.
	(symlink_info::check_sysfile): Don't re-open file here, just use
	incoming handle.  Keep track of file position to accommodate the fact
	that file has been opened asynchronously in calling function.
	(symlink_info::check_nfs_symlink): Don't re-open file here, just use
	incoming handle.
	(symlink_info::check): Drop unused 'opt' parameter.  Add
	path_conv_handle argument.  Always try to open file with GENERIC_READ
	rights first to allow reading file content w/o having to re-open the
	file.  Drop back to READ_CONTROL | FILE_READ_ATTRIBUTES otherwise.
	Call symlink test functions (except for check_reparse_point) only if
	file could be opened with GENERIC_READ.  Keep file handle open if
	PC_KEEP_HANDLE is set in pflags.
	* path.h (enum pathconv_arg): Add PC_KEEP_HANDLE flag.
	(class path_conv_handle): New class.
	(class path_conv): Add conv_handle member.
	(path_conv::operator =): Duplicate conv_handle.
	(path_conv::handle): New method.
	(path_conv::access): New method.
	(path_conv::reset_conv_handle): New method.
	(path_conv::close_conv_handle): New method.
2010-06-15 12:05:15 +00:00
Corinna Vinschen bc8a5a9f66 * syscalls.cc (rename): On STATUS_ACCESS_VIOLATION, retry to open
for DELETE until the STATUS_ACCESS_VIOLATION goes away.  Add comment
	to explain why.
2010-04-19 08:09:51 +00:00
Christopher Faylor 1908518227 * fhandler.h (fhandler_base::has_ongoing_io): Declare virtual method.
* select.cc (peek_pipe): Reorganize slightly.  Don't attempt to check a handle
if it has ongoing I/O.
(select_pipe_info::select_pipe_info): Delete definition.
(select_pipe_info::~select_pipe_info): Delete definition.
(thread_pipe): Get rid of WFMO call.  Reorganize loop.
(pipe_cleanup): Remove dependence on destructor.
(thread_serial): Reorganize loop.
* select.h (select_pipe_info): Empty this class since it no longer has any
special requirements (for now).
* syscalls.cc (readv): Remove an unneeded debug printf.
2010-04-02 22:36:44 +00:00
Corinna Vinschen 298cf05c21 * syscalls.cc (open): Remove call to sig_dispatch_pending. 2010-03-30 14:36:42 +00:00
Christopher Faylor cef5dfd75a * shared_info.h (user_info): Add dll_crt0_1 as a friend.
(user_info::version): Make LONG to accommodate spinlock use.
(user_info::create): New static function renamed from user_info_create.
(user_info::initialize): New private function renamed from
user_info_initialize.
(SHARED_VERSION): Delete.
(SHARED_VERSION_MAGIC): Ditto.
(USER_VERSION_MAGIC): Ditto.
(SHARED_INFO_CB): Ditto.
(USER_VERSION): Ditto.
(USER_VERSION_MAGIC): Ditto.
(CURR_SHARED_MAGIC): Update.
(CURR_USER_MAGIC): Ditto.
(shared_info::version): Make LONG to accommodate spinlock use.
(shared_info::create): New static function mirroring user_info::create.
(dll_crt0_1): Accommodate change to user_info::initialize.
* spinlock.h (spinlock::setto): New variable member.
(spinlock::done): New function.
(spinlock::spinlock): Generalize to allow arbitrary values and timeouts.  Call
done() when lock is not needed.
* ntdll.h: Make multiple-inclusion safe.
(NtQuerySystemTime): Declare.
* shared.cc (installation_root_inited): Rename from shared_mem_inited.
(init_installation_root): Make inline.  Use a spinlock to ensure that this is
initialized only once per session.
(user_info::initialize): Rename from user_shared_initialize.  Protect with
spinlock on sversion and remove other spinlock-like things.  Remove reference
to user_shared since it is now implicit.  Refer to spinlock version of
multiple_cygwin_problem to ensure that any spinlock is released.
(user_info::create): Rename from user_shared_create.  Accommodate change from
user_shared_initialize to user_info::initialize.
(shared_info::create): New inline function.
(shared_info::initialize): Protect with spinlock on sversion.  Move heap_init
back under specific control of shared_info spinlock.  Remove reference to
SHARED_INFO_CB and just use sizeof(*this).
(memory_init): Move all locking into respective functions where it is needed.
Accommodate name changes.  Remove call to heap_init().
* syscalls.cc (seteuid32): Accommodate name change to user_info::create().
* mount.cc (mount_info::create_root_entry): Report on errors from add_item
since they should be nonexistent.
(mount_info::init): Don't initialize nmounts.  It should already be zero.  Give
more verbose error when root_idx < 0.  Implicitly use this pointer rather than
explicitly referencing mount_table->.
(mount_info::add_item): Minor whitespace fix.
2010-03-15 21:29:15 +00:00
Corinna Vinschen 8e75995c7f * syscalls.cc (nt_path_has_executable_suffix): Change storage class of
blessed_executable_suffixes to static.
	(rename): Revert meaning of old_explicit_suffix.  Change the rules
	for appending a .exe suffix and (yikes!) document them.
2010-03-04 16:20:37 +00:00
Corinna Vinschen 57c7e05ea7 * nlsfuncs.cc (check_codepage): Move from syscalls.cc here.
(internal_setlocale): Ditto.
	(initial_setlocale): Ditto.
	(setlocale): Ditto.
	* strfuncs.cc (__sjis_wctomb): Revert previous patch.
	(__sjis_mbtowc): Ditto.
	* syscalls.cc: Move setlocale-related functions to nlsfuncs.cc.
2010-01-24 12:29:49 +00:00
Corinna Vinschen 62910474ac * syscalls.cc (internal_setlocale): Use UTF-8 internally if external
charset is ASCII.
2010-01-17 09:41:01 +00:00
Corinna Vinschen 41d184bb62 * dcrt0.cc (dll_crt0_1): Reset locale to "C" at the last moment before
calling the application's main.
	* syscalls.cc (internal_setlocale): Don't reset locale to "C here.
	Change comment accordingly.
2010-01-14 18:56:24 +00:00
Corinna Vinschen e70fdfb99f * cygwin.din (dup3): Export.
(pipe2): Export.
	* dtable.cc (dtable::dup_worker): Take additional flags parameter.
	Handle O_CLOEXEC flag.
	(dtable::dup3): Rename from dup2.  Take additional flags parameter.
	Check for valid flags.  Drop check for newfd == oldfd.
	* dtable.h (dtable::dup_worker): Add flags parameter.
	(dtable::dup3): Rename from dup2.
	* fcntl.cc (fcntl64): Add F_DUPFD_CLOEXEC case.
	* fhandler.h (fhandler_mailslot::get_object_attr): Add flags parameter.
	* fhandler.cc (fhandler_base::open): Use security attribute with
	inheritance according to setting of O_CLOEXEC flag.
	* fhandler_console.cc (fhandler_console::open): Ditto.
	* fhandler_fifo.cc (sec_user_cloexec): New inline function to
	create security attribute with inheritance according to setting of
	O_CLOEXEC flag.
	(fhandler_fifo::open): Call sec_user_cloexec to fetch security
	attribute.
	(fhandler_fifo::wait): Ditto.
	* fhandler_mem.cc (fhandler_dev_mem::open): Ditto.
	* fhandler_mailslot.cc (fhandler_mailslot::get_object_attr): Take
	additional flags parameter.  Use security attribute with inheritance
	according to setting of O_CLOEXEC flag.
	(fhandler_mailslot::open): Call get_object_attr with flags parameter.
	* fhandler_registry.cc (fhandler_registry::open): Call set_close_on_exec
	on real handles to accommodate O_CLOEXEC flag.
	* fhandler_tty.cc (fhandler_tty_slave::open): Ditto.
	* fhandler_tape.cc: Create mutex with inheritance according to setting
	of O_CLOEXEC flag.
	* pipe.cc: Replace usage of O_NOINHERIT with O_CLOEXEC.
	 (fhandler_pipe::init): Simplify setting close_on_exec flag.
	(fhandler_pipe::open): Remove setting close_on_exec flag.
	(fhandler_pipe::create): Use security attribute with inheritance
	according to setting of O_CLOEXEC flag.
	(pipe2): New exported function.
	* posix_ipc.cc: Throughout, open backing files with O_CLOEXEC
	flag to follow POSIX semantics.
	* security.h (sec_none_cloexec): New define.
	* syscalls.cc (dup): Add missing extern "C" qualifier.  Accommodate
	renaming of dtable::dup2 to dtable::dup3.
	(dup2): Ditto.  Check newfd == oldfd here.
	(dup3): New function.  Check newfd == oldfd here.
	(open): Set close_on_exec flag according to O_CLOEXEC flag before
	calling fhandler->open.
	* include/cygwin/version.h (CYGWIN_VERSION_API_MINOR): Bump.
2010-01-14 18:46:02 +00:00
Corinna Vinschen 4bcdec7276 * syscalls.cc (rename): Don't exit prematurely with EROFS when trying
to rename an AF_LOCAL socket or when trying to replace an AF_LOCAL
	socket.
2010-01-13 09:45:18 +00:00
Corinna Vinschen 4ee93264fd * dtable.cc (build_fh_name_worker): Remove. Move all functionality
back into build_fh_name.
	(build_fh_name): Drop unused HANDLE parameter.  Drop call to pc.fillin.
	Remove disabled build_fh_name with UNICODE_STRING name parameter.
	* dtable.h (build_fh_name): Drop HANDLE parameter from declaration.
	Remove declaration for build_fh_name with UNICODE_STRING name parameter.
	* path.cc (path_conv::fillin): Remove.
	(symlink_info::check): Fix comment.
	* path.h (path_conv::fillin): Remove declaration.
	* dir.cc: Accommodate change in build_fh_name parameters throughout.
	* sec_acl.cc: Ditto.
	* syscalls.cc: Ditto.

	* ntea.cc (getxattr_worker): Fix debug output.
	(setxattr_worker): Ditto.
	* times.cc (utimens_worker): Ditto.
2010-01-12 10:14:59 +00:00
Corinna Vinschen f16706de97 Throughout, replace hMainProc with GetCurrentProcess/NtCurrentProcess
according to context.  Throughout, replace hMainThread with
	GetCurrentThread/NtCurrentThread according to context.
	* dcrt0.cc (dll_crt0_0): Drop duplication of GetCurrentProcess to
	hMainProc.  Drop duplication of GetCurrentThread to hMainThread.
	* dtable.cc (dtable::stdio_init): Remove useless comment.
	* globals.cc (hMainProc): Remove.
	(hMainThread): Remove.
	* ntdll.h (NtCurrentProcess): Define.
	(NtCurrentThread: Define.
2009-12-18 20:32:04 +00:00
Corinna Vinschen 314c2d2fed * syscalls.cc (try_to_bin): Handle remote shares as well. Just rename
files in this case, instead of moving them to the recycler.  Create
	even more unique filename.  Add comment to explain filename.
	(unlink_nt): Remove code returning with EBUSY on remote shares.
	Set bin_stat to move_to_bin except on NFS.  Add comment to explain.
2009-12-17 18:33:05 +00:00
Corinna Vinschen d9e9c7b5a7 * globals.cc (ro_u_dll): New R/O unicode string.
* syscalls.cc (nt_path_has_executable_suffix): Add ro_u_dll to
	blessed_executable_suffixes array.  Explain why.
2009-11-21 12:44:13 +00:00
Corinna Vinschen 16a72f7e4b * path.cc (symlink_info::check_reparse_point): Always check
SubstituteName for volume string to recognize volume mount points.
	Reuse subst when calling sys_wcstombs.
	* syscalls.cc (rename): Set errno to EBUSY when trying to rename
	volume mount points.  Explain why.
2009-11-09 19:46:36 +00:00
Corinna Vinschen b36d8c46e5 * globals.cc (ro_u_scr): New R/O unicode string.
(ro_u_sys): Ditto.
	* syscalls.cc (nt_path_has_suffix): Replace with ...
	(nt_path_has_executable_suffix): New function checking for explicit
	executable suffixes.
	(rename): Call nt_path_has_executable_suffix instead of
	nt_path_has_suffix.  Check oldpath for nt_path_has_executable_suffix
	as well to set old_explicit_suffix.
2009-11-06 20:51:03 +00:00
Corinna Vinschen ac4ad8bffc * syscalls.cc (nt_path_has_suffix): New function.
(rename): Don't append .exe suffix if binary target name has any suffix
	at all.
2009-11-05 14:44:12 +00:00
Corinna Vinschen 8d648dc555 * syscalls.cc (internal_setlocale): Only convert $PATH if there is a
$PATH.
2009-10-19 19:47:15 +00:00
Corinna Vinschen 0191627a26 * include/sys/cygwin.h: Add new cygwin_getinfo_type
CW_SET_EXTERNAL_TOKEN.
	Add new enum CW_TOKEN_IMPERSONATION, CW_TOKEN_RESTRICTED.
	* cygheap.h (cyguser): New flags ext_token_is_restricted,
	curr_token_is_restricted and setuid_to_restricted.
	* external.cc (cygwin_internal): Add CW_SET_EXTERNAL_TOKEN.
	* sec_auth.cc (set_imp_token): New function.
	(cygwin_set_impersonation_token): Call set_imp_token ().
	* security.h (set_imp_token): New prototype.
	* spawn.cc (spawn_guts): Use CreateProcessAsUserW if restricted token
	was enabled by setuid().  Do not create new window station in this case.
	* syscalls.cc (seteuid32): Add handling of restricted external tokens.
	Set HANDLE_FLAG_INHERIT for primary token.
	(setuid32): Set setuid_to_restricted flag.
	* uinfo.cc (uinfo_init): Do not reimpersonate if restricted token was
	enabled by setuid ().  Initialize user.*_restricted flags.
2009-10-13 10:23:31 +00:00
Corinna Vinschen dfbf36f8db * syscalls.cc (seteuid32): Call set_cygwin_privileges on primary token
as well.
2009-10-07 08:20:49 +00:00
Corinna Vinschen 960624f47e * syscalls.cc (internal_setlocale): Add comment. 2009-10-04 11:32:07 +00:00
Corinna Vinschen 0ca6c6b802 * dcrt0.cc (dll_crt0_1): Drop calls to setlocale/_setlocale_r. Just
call initial_setlocale from here.
	* syscalls.cc (initial_setlocale): Set internal charset and revert
	application locale to "C".
	(setlocale): Don't set Cygwin's internal charset here.
2009-10-02 14:58:10 +00:00
Eric Blake 1c0909882c * syscalls.cc (rename): Fix regression in rename("dir","d/"). 2009-09-30 02:11:05 +00:00
Corinna Vinschen d856640e1c * cygheap.cc (cygheap_init): Default locale.charset to "UTF-8".
* dcrt0.cc (dll_crt0_1): Call setlocale (LC_CTYPE, "") here, just
	before resetting application locale to "C".
	* environ.cc (environ_init): Drop code setting locale here.
	* syscalls.cc (check_codepage): Break out check for required codepage
	from internal_setlocale.
	(internal_setlocale): Just convert CWD and $PATH from old charset to
	new charset and set internal charset.
	(setlocale): Change accordingly.  Don't require LC_ALL or LC_CTYPE to
	store old locale value.  Always call internal_setlocale if charset
	changed due to locale environment changes.
2009-09-28 10:43:49 +00:00
Eric Blake 52dba6a5c4 Fix some POSIX-compliance bugs in link, rename, mkdir.
* syscalls.cc (link): Delete obsolete comment.  Reject directories
and missing source up front.
(rename): Use correct errno for trailing '.'.  Detect empty
strings.  Allow trailing slash to newpath iff oldpath is
directory.
* dir.cc (mkdir): Reject dangling symlink with trailing slash.
* fhandler_disk_file.cc (fhandler_disk_file::link): Reject
trailing slash.
* fhandler.cc (fhandler_base::link): Match Linux errno.
2009-09-26 15:51:53 +00:00
Eric Blake 2bf78f0928 Provide euidaccess, canonicalize_file_name; fix fchmodat.
* syscalls.cc (fchmodat): lchmod is not yet implemented.
(euidaccess): New function.
* path.cc (realpath): Update comment.
(canonicalize_file_name): New function.
* include/cygwin/stdlib.h (canonicalize_file_name): Declare it.
* include/cygwin/version.h (CYGWIN_VERSION_API_MINOR): Bump.
* cygwin.din: Export canonicalize_file_name, eaccess, euidaccess.
* posix.sgml: Mention them.
2009-09-25 23:55:00 +00:00
Eric Blake 3dbe243afa Fix faccessat(,0) and access() semantics.
* fhandler.h (fhandler_base::fhaccess): Add parameter.
* security.h (check_file_access, check_registry_access): Likewise.
* security.cc (check_file_access, check_registry_access)
(check_access): Implement new parameter.
* fhandler.cc (fhandler_base::fhaccess): Likewise.
(device_access_denied): Update caller.
* syscalls.cc (access, faccessat): Update callers.
* spawn.cc (find_exec, fixup): Likewise.
2009-09-25 13:44:45 +00:00
Eric Blake 74a67d01a5 Make *at functions more like Linux.
* syscalls.cc (faccessat): Fix typo, reject bad flags.
(fchmodat, fchownat, fstatat, utimensat, linkat, unlinkat): Reject
bad flags.
2009-09-22 12:13:53 +00:00
Eric Blake 29bca9bb0c Match dup2 and fcntl error values to POSIX.
* dtable.h (OPEN_MAX_MAX): New macro.
* resource.cc (getrlimit) [RLIMIT_NOFILE]: Use it.
* dtable.cc (dtable::extend): Likewise.
* fcntl.cc (fcntl64): Obey POSIX rule with too-large F_DUPFD.
* syscalls.cc (dup2): Likewise.
2009-09-22 04:09:03 +00:00
Corinna Vinschen ee42ccd3a2 * cygheap.h (cwdstuff::get_posix): Convert to const inline method just
returning pointer to posix path.
	(cwdstuff::reset_posix): Convert to non-inline method taking a wchar_t
	pointer.
	* path.cc (cwdstuff::set): Revert change from 2009-05-13.  Set posix
	to valid incoming path again.
	(cwdstuff::reset_posix): New implementation setting posix path from
	incoming wchar_t path.  Explain usage.
	(cwdstuff::get_posix): Drop implementation.
	(cwdstuff::get): Drop special case to handle empty posix path.
	* syscalls.cc (internal_setlocale): Store old posix cwd as wide char
	path.  Restore posix cwd using new charset.  Explain why.
2009-09-21 19:29:16 +00:00
Christopher Faylor 7b9f3ce02c * exceptions.cc (sigpacket::process): Give sigwait() processing precedence even
when a handler is present.
* syscalls.cc (getpagesize): Change return to 'int'.
2009-09-18 21:27:02 +00:00
Christopher Faylor 4315703af7 * syscalls.cc (popen): Reorganize slightly for clarity. Fix a comment. 2009-08-18 01:51:35 +00:00
Christopher Faylor d5c44ae231 * syscalls.cc (popen): Rewrite to accommodate situations where stdin, stdout,
or stderr are closed.
2009-08-18 01:40:46 +00:00
Christopher Faylor 43c23d4b82 * sigproc.h (wait_for_sigthread): Eliminate parameter.
* sigproc.cc (wait_for_sigthread): Ditto.  Don't synchronize with wait_sig
after receiving an event that it is ready to go.
(init_sig_pipe): New function.
(wait_sig): Call init_sig_pipe to create pipes for communicating signals to
this process.  Don't send sigCONT signal when initializing.
* fork.cc (frok::child): Accommodate wait_for_sigpipe parameter change.
* fhandler.h (fhandler_*::write): Make ssize_t/__stdcall.
(fhandler_*::write_overlapped): Ditto.
(fhandler_*::raw_write): Ditto.
(fhandler_*::readv): Ditto.
(fhandler_*::writev): Ditto.
(fhandler_*::raw_read): Make __stdcall.
* fhandler: Accommodate changes to read/write functions throughout.
* fhandler_clipboard.cc: Ditto.
* fhandler_console.cc: Ditto.
* fhandler_dsp.cc: Ditto.
* fhandler_fifo.cc: Ditto.
* fhandler_mailslot.cc: Ditto.
* fhandler_mem.cc: Ditto.
* fhandler_mem.cc: Ditto.
* fhandler_random.cc: Ditto.
* fhandler_tape.cc: Ditto.
* fhandler_tty.cc: Ditto.
* fhandler_virtual.cc: Ditto.
* fhandler_windows.cc: Ditto.
* fhandler_zero.cc: Ditto.
* syscalls.cc (readv): Use ssize_t as temp variable.
* fhandler.cc (fhandler_base::read): Coerce returned len to signed or it will
never be treated as < 0.
(fhandler_base::wait_overlapped): Minimize calls to GetLastError.  Remove
duplicate debugging test.  Fix error return.
* fhandler.h (fhandler_fifo::fifo_name): Declare new function.
(fhandler_fifo::close): Ditto.
(fhandler_fifo::dup): Ditto.
(fhandler_fifo::close_on_exec): Ditto.
* fhandler.cc (fhandler_fifo::fifo_name): Define new function.
(FIFO_BUF_SIZE): New define.
(cnp): Ditto.
(fhandler_fifo::open): Rework.  Use cnp to open named pipe.  Always open write
side as a client.  Open dummy client when writing and can't connect.
(wait): Rework.  Implement fifo_wait_for_next_client.  Handle signals during
connect better.  Add new fifo_wait_for_server code which polls
(sigh) waiting for server.
(fhandler_fifo::raw_read): Handle transition states when one client closes and
another is available.
(fhandler_fifo::close): Define.
(fhandler_fifo::dup): Ditto.
(fhandler_fifo::close_on_exec): Ditto.
2009-07-24 20:54:33 +00:00
Corinna Vinschen f8cb4b4916 * syscalls.cc (internal_setlocale): Fix typo in GBK codepage. 2009-07-24 18:24:57 +00:00
Corinna Vinschen 92d816d492 * syscalls.cc (unlink_nt): Ignore sharing violation on NFS. Align
comments.
2009-07-24 14:13:44 +00:00
Corinna Vinschen 20fc2f4936 * wincap.h (wincaps::has_always_all_codepages): New element.
* wincap.cc: Implement above element throughout.
	* wchar.h (__sjis_mbtowc): Declare.
	(__eucjp_mbtowc): Ditto.
	(__gbk_mbtowc): Ditto.
	(__kr_mbtowc): Ditto.
	(__big5_mbtowc): Ditto.
	* syscalls.cc (internal_setlocale): Convert to char * function.
	Return parameter by default.  Return NULL if request to use a
	charset can't be satisfied due to missing codepage support in the
	underlying OS.  Fix comment.
	(setlocale): Store original locale.  Restore to original locale if
	internal_setlocale returns NULL.
2009-07-20 15:44:55 +00:00
Corinna Vinschen 8319377680 * syscalls.cc (unlink_nt): Just return when a sharing violation
occurs on remote filesystems.
2009-07-17 16:45:22 +00:00
Corinna Vinschen d6f45fb002 * syscalls.cc (unlink_nt): First remove the R/O DOS attribute with
FILE_WRITE_ATTRIBUTES access only, then re-open the file for DELETE.
	Explain why.
2009-07-16 16:55:25 +00:00
Corinna Vinschen 8deb411836 Throughout avoid having to initialize constant UNICODE_STRINGs.
* globals.cc: Define constant UNICODE_STRINGs and store in .rdata
	section.
	* fhandler_disk_file.cc: Throughout, use readonly UNICODE_STRINGs
	rather then initializing local UNICODE_STRING variable where
	applicable.
	* fhandler_mem.cc (fhandler_dev_mem::open): Ditto.
	* flock.cc (inode_t::inode_t): Ditto.
	* mmap.cc: Ditto.
	* syscalls.cc: Ditto.
	* mount.cc (fs_info::update): Ditto.
	* path.cc: Ditto.

	* ntdll.h (RtlEqualUnicodePathPrefix): Redefine to take prefix as
	UNICODE_STRING.
	(RtlEqualUnicodePathSuffix): Redefine to take suffix as UNICODE_STRING.
	* fhandler_disk_file.cc: Accommodate throughout.
	* mount.cc (fs_info::update): Ditto.
	* path.cc (cwdstuff::set): Ditto.
	* syscalls.cc: Ditto.
2009-07-14 17:37:42 +00:00
Christopher Faylor b4fa816474 * select.h: New file split from fhandler.h.
(select_record::select_record): Define do-nothing constructor for "new" to
avoid gratuitous zeroing.
(select_info): New base class.
(select_pipe_info): New class with methods for dealing with pipes.
(select_socket_info): New class with methods for dealing with sockets.
(select_serial_info): Dummy class for serial.
(select_mailslot_info): Dummy class for mailslots.
(select_stuff): Define device_specific_* as actual classes rather than void *.
* dtable.h (dtable::select_read): Accommodate return value change to 'bool' and
argument change to "select_stuff".
(dtable::select_write): Ditto.
(dtable::select_except): Ditto.
* dtable.cc (dtable::select_read): Accommodate return value change to 'bool'
and argument change to "select_stuff".
(dtable::select_write): Ditto.
(dtable::select_except): Ditto.
* fhandler.h: Excise select-related classes.
(fhandler_*::select_read): Change argument to select_stuff.
(fhandler_*::select_write): Ditto.
(fhandler_*::select_except): Ditto.
* select.cc (UNIX_FD_ZERO): Use memset rather than bzero.
(select_stuff::test_and_set): Change return type to bool.  Allocate
select_record on entry and let fhandler_*::select_* operate on the start.next
field of select_stuff.
(pipeinf): Delete.
(select_pipe_info::select_pipe_info): New constructor.  Allocates event for
controlling pipe waits.
(select_pipe_info::~select_pipe_info): New destructor.  Destroy event.  Stop
thread.
(select_pipe_info::add_watch_handle): New function.
(thread_pipe): Wait for the hEvent part of any overlapped pipes before peeking.
(start_thread_pipe): Don't allocate device_specific_pipe stuff here.  Assume
that it has been allocated earlier.
(pipe_cleanup): Rely on select_pipe_info destructor to clean up pipe
paraphenalia.
(fhandler_*::select_*): Derive select_record from new select_stuff argument.
(fhandler_pipe::select_*): Ditto.  Allocate pipe-specific field if not already
allocated.
(serialinf): Delete.
(thread_serial): serialinf -> select_serial_info.
(fhandler_base::ready_for_read): Rewrite to accommodate change in argument to
fhandler_*::select_*.
(socketinf): Delete.
(thread_socket): socketinf -> select_socket_info.
(mailslotinf): Delete.
(thread_mailslot): mailslotinf -> select_mailslot_info.
2009-06-30 21:18:44 +00:00
Corinna Vinschen 6f401eccfb * cygheap.cc (cygheap_init): Set Cygwin default locale values.
* cygheap.h (struct cygheap_locale): New structure.
	(struct user_heap_info): Add cygheap_locale member locale.
	* dcrt0.cc (dll_crt0_1): Revert to calling _setlocale_r so that only
	the applications locale is reverted to "C".
	* environ.cc (environ_init): Remove unused got_lc variable.
	* fhandler.h (class dev_console): Remove now unsed locale variables.
	* fhandler_console.cc (fhandler_console::get_tty_stuff): Remove
	setting dev_console's locale members.
	(dev_console::con_to_str): Use internal locale settings.  Default to
	__ascii_wctomb if charset is "ASCII".
	(fhandler_console::write_normal): Ditto.
	* strfuncs.cc (__ascii_wctomb): Drop declaration.
	(__db_wctomb): Use fixed value 2 instead of not
	necessarily matching MB_CUR_MAX.
	(__eucjp_wctomb): Use 3 instead of MB_CUR_MAX.
	(sys_cp_wcstombs): Remove special case for "C" locale.
	(sys_wcstombs): Implement here.  Use internal locale data stored on
	cygheap.
	(sys_cp_mbstowcs): Remove special case for "C" locale.
	(sys_mbstowcs): Implement here.  Use internal locale data stored on
	cygheap.
	* syscalls.cc (internal_setlocale): New function to set cygheap locale
	data and to reset CWD posix path.
	(setlocale): Just call internal_setlocale from here if necessary.
	* wchar.h (__ascii_wctomb): Declare.
	(sys_wcstombs): Don't define inline, just declare.
	(sys_mbstowcs): Ditto.
2009-05-14 19:49:37 +00:00
Corinna Vinschen b6c6ea43f3 * cygheap.h (cwdstuff): Convert to class. Make posix and dir private.
(cwdstuff::get_posix): New method.
	(cwdstuff::reset_posix): New method.
	* dcrt0.cc (dll_crt0_1): Call setlocale rather than _setlocale_r.
	* environ.cc (environ_init): Ditto.  Prefer "C" locale over current
	codepage default locale.
	* path.cc (chdir): Use cwdstuff::get_posix method instead of accessing
	cwdstuff::posix directly.
	(cwdstuff::set): Defer creating posix path to first usage.
	(cwdstuff::get_posix): Create posix path if it's empty, and return it.
	(cwdstuff::get): Create posix path if it's empty.
	* strfuncs.cc (sys_cp_wcstombs): Use UTF-8 conversion in the "C"
	locale.
	(sys_cp_mbstowcs): Ditto.
	* syscalls.cc (gen_full_path_at): Fetch CWD posix path locked.
	(setlocale): Implement here.  Reset CWD posix path.
2009-05-13 15:00:06 +00:00
Corinna Vinschen 03897d8dda * ntdll.h (STATUS_LOCK_NOT_GRANTED): Define.
* syscalls.cc (unlink_nt): Handle STATUS_LOCK_NOT_GRANTED same as
	STATUS_SHARING_VIOLATION.  Add lengthy comment to explain why.
2009-04-16 12:16:35 +00:00
Corinna Vinschen 0c4023011d * syscalls.cc (try_to_bin): Use tmp_pathbuf buffer to allocate infobuf
rather than using the stack.
2009-04-09 17:55:01 +00:00
Corinna Vinschen 214a0e67fd * syscalls.cc (try_to_bin): Fix alignment of infobuf. 2009-04-09 17:00:35 +00:00
Corinna Vinschen 7a9f309bcd * syscalls.cc (pathconf): Fix memory leak. 2009-03-27 11:29:56 +00:00
Corinna Vinschen 64d6e1d43e * syscalls.cc (open): Handle O_DIRECTORY flag.
* include/fcntl.h: Add SUSv4 flags O_DIRECTORY, O_EXEC and O_SEARCH.
	* include/cygwin/version.h: Bump API minor number.
2009-02-11 16:06:39 +00:00
Corinna Vinschen 8a0f3bbf2d * syscalls.cc (enum bin_status): New type.
(try_to_bin): Return bin_status.  Rename win32_path to pc.  Rename h
	to fh.  Rename fh to tmp_fh.  Add code to set delete dispostion and
	more code to replace file moved to bin by another, temporary file.
	Add comments to explain why.
	(unlink_nt): Replace move_to_bin with bin_stat.  Only set bin_stat
	to move_to_bin for non-remote files.  As a last resort, call try_to_bin
	if setting delete-on-close failed.  Only re-set R/O DOS attribute
	and only close handle if it's still valid.
2009-01-12 15:51:23 +00:00
Corinna Vinschen f4ad04049f * ntdll.h: Reorder NT status flags. Fix a case difference. Add
STATUS_CANNOT_DELETE flag.
	* syscalls.cc (unlink_nt): Change initial NtOpenFile to request
	FILE_SHARE_DELETE sharing mode.  Change comment accordingly.
	If setting delete disposition failed with STATUS_CANNOT_DELETE, try
	to delete using delete-on-close.  Explain why.
	Rearrange setting R/O DOS attribute after trying to delete.  Simplify
	comment.
2009-01-07 18:18:23 +00:00
Christopher Faylor 66a83f3eac Remove unneeded header files from source files throughout. Update copyrights
where appropriate.
* globals.cc: New file for generic global variables.
* mkglobals_h: New file to generate globals.h.
* mkstatic: New Script used to build a (currently non-working) static
libcygwin_s.a.
* Makefile.in: Add unused rule to build a non-working libcygwin_s.a.
(DLL_OFILES): Add globals.o.  Make all objects rely on globals.h.
(globals.h): New target.  Generate globals.h.
* cygtls.h: Honor new CYGTLS_HANDLE define to control when the HANDLE operator
is allowed in _cygtls.
* dcrt0.cc: Move most globals to globals.cc.
* init.cc: Ditto.
* environ.cc (strip_title_path): Remove now-unneeded extern.
* fhandler_serial.cc (fhandler_serial::open): Ditto.
* pinfo.cc: Ditto.
(commune_process): Ditto.
* shared.cc: Ditto.
* glob.cc: Ditto.
* strace.cc: Ditto.
* exceptions.cc: Define CYGTLS_HANDLE before including winsup.h.
* path.cc (stat_suffixes): Move here.
* security.h: Add forward class path_conv declaration.
* smallprint.cc (__small_vsprintf): Make a true c++ function.
(__small_sprintf): Ditto.
(small_printf): Ditto.
(console_printf): Ditto.
(__small_vswprintf): Ditto.
(__small_swprintf): Ditto.
* spawn.cc (spawn_guts): Remove _stdcall decoration in favor of regparm.
(hExeced): Move to globals.cc
* strfuncs.cc (current_codepage): Ditto.
(active_codepage): Ditto.
* sync.cc (lock_process::locker): Move here from dcrt0.cc.
* syscalls.cc (stat_suffixes): Move to path.cc.
* tty.cc (tty::create_master): Uncapitalize fatal warning for consistency.
* winsup.h: Include globals.h to declare most of the grab bag list of globals
which were previously defined here.
* mount.h: Move USER_* defines back to shared_info.h.
* speclib: Force temporary directory cleanup.
2009-01-03 05:12:22 +00:00
Corinna Vinschen 1348f65bb9 * syscalls.cc (gen_full_path_at): Use isabspath instead of isdirsep
to recognize absolute path.
2008-12-15 20:53:18 +00:00
Christopher Faylor 025c1fac6e Remove unneeded whitespace.
* fhandler_fifo.cc (fhandler_fifo::open): Rework to cause errno to be set to
ENXIO when opening a fifo write/nonblocking.
* environ.cc (ucreqenv): Rename to ucenv.  Move code from old ucenv here and
conditionalize it on create_upcaseenv.
(ucenv): Delete.
(environ_init): Fix compiler warning by moving create_upcaseenv test to ucenv.
Don't bother checking for child_proc_info when calling ucenv since it is
assumed to be NULL at the point where the function is called.
* path.cc (symlink_worker): Turn off MS-DOS path warnings when dealing with
devices since the device handler passes in a translated MS-DOS path.
* sec_auth.cc (lsaprivkeyauth): Avoid variable initialization which causes a
compiler error.
* fhandler_netdrive.cc: Update copyright.
2008-11-26 17:21:04 +00:00
Corinna Vinschen 51303cbd0c * Makefile.in (DLL_OFILES): Add setlsapwd.o.
* cygserver.h (CYGWIN_SERVER_VERSION_API): Bump.
	(request_code_t): Define CYGSERVER_REQUEST_SETPWD request type.
	* cygserver_msg.h (client_request_msg::retval): Use default value of -1
	for retval if msglen is 0.
	* cygserver_sem.h (client_request_sem::retval): Ditto.
	* cygserver_shm.h (client_request_shm::retval): Ditto.
	* cygserver_setpwd.h: New file.
	* external.cc (cygwin_internal): Implement new CW_SET_PRIV_KEY type.
	* sec_auth.cc (open_local_policy): Make externally available.
	Get ACCESS_MASK as argument.
	(create_token): Accommodate change to open_local_policy.
	(lsaauth): Ditto.
	(lsaprivkeyauth): New function fetching token by retrieving
	password stored in Cygwin or Interix LSA private data area and
	calling LogonUser with it.
	* security.h (lsaprivkeyauth): Declare.
	(open_local_policy): Declare.
	* setlsapwd.cc: New file implementing setting LSA private data password
	using LsaStorePrivateData or by calling cygserver if available.
	* syscalls.cc (seteuid32): Add workaround to get the original token
	when switching back to the original privileged user, even if
	setgroups group list is still active.  Add long comment to explain why.
	Call lsaprivkeyauth first, only if that fails call lsaauth or
	create_token.
	* include/cygwin/version.h: Bump API minor number.
	* include/sys/cygwin.h (cygwin_getinfo_types): Add CW_SET_PRIV_KEY.
2008-11-26 10:18:10 +00:00
Corinna Vinschen 669bdeb822 * ntdll.h (NtSetAttributesFile): New inline function.
* fhandler_disk_file.cc (fhandler_disk_file::fchmod): Use
	NtSetAttributesFile.
	* path.cc (symlink_worker): Ditto.
	* syscalls.cc (unlink_nt): Ditto.
	(rename): Omit FILE_SHARE_DELETE when opening files on Samba.  Add
	comment to explain why.
2008-10-20 19:30:06 +00:00
Corinna Vinschen c32849c5bc * path.cc (path_conv::is_binary): Always check for GetBinaryType.
* syscalls.cc (rename): Fix test for just changing case of name on
	case insensitive filesystems.
2008-10-09 09:43:02 +00:00
Christopher Faylor 7b9e380f03 * cygheap.cc (creturn): Reorganize to avoid a new compiler warning/error.
* dtable.cc (handle_to_fn): Ditto.
* fhandler_console.cc (fhandler_console::read): Ditto.
(fhandler_console::scroll_screen): Ditto.
(dev_console::set_color): Ditto.
* fhandler_dsp.cc (fhandler_dev_dsp::write): Ditto.
(fhandler_dev_dsp::read): Ditto.
* fhandler_tape.cc (mtinfo_drive::get_status): Ditto.
* hookapi.cc (find_first_notloaded_dll): Ditto.
* mmap.cc (msync): Ditto.
* pipe.cc (pipesync::pipesync): Ditto.
* sec_acl.cc (getace): Ditto.
* sec_auth.cc (create_token): Ditto.
(lsaauth): Ditto.
* select.cc (peek_pipe): Ditto.
* spawn.cc (av::fixup): Ditto.
* syscalls.cc (popen): Ditto.
* tty.cc (tty::init_session): Ditto.
* uinfo.cc (pwdgrp::load): Ditto.
* fhandler.cc (fhandler_base::setup_overlapped): Ditto.
(fhandler_base::wait_overlapped): Rename second use of res variable to wres or
errors are not returned correctly.
* dcrt0.cc: Remove obsolete variable.
* dll_init.cc (release_upto): Fix typo involving incorrect use of '|'.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Avoid a compiler
warning regarding coercing type-punned variables.
(fhandler_base::fstat_by_name): Ditto.  fhandler_fifo.cc
(fhandler_fifo::open_nonserver): Fix = vs.  == typo.
(fhandler_fifo::wait): Add all conditions to switch statement to avoid a
compiler warning.
* fhandler_process.cc: Avoid unneeded initialization of variables to zero.
(fhandler_socket::listen): Add braces around initializer.
* flock.cc (inode_t::get_all_locks_list): Reorganize to avoid a compiler
warning.  Fix problem with EWOULDBLOCK error return.
* path.cc (GUID_shortcut): Use braces around struct initializer.
(cygwin_conv_path): Reorganize to avoid a compiler warning.
* random.cc (dummy): Mark variable as volatile to avoid a "used uninitialized"
warning.
* libc/getopt.c: Mark some variables as dllexport although gcc doesn't seem to
do the right thing with them.
* libc/minires-os-if.c (get_registry_dns_items): Coerce some function arguments
to avoid a compiler warning.
2008-09-11 04:34:24 +00:00
Corinna Vinschen 0ea2c19934 * syscalls.cc (rename): If newpath doesn't exist, check if .exe suffix
in oldpath has been omitted before appending .exe to newpath.
2008-08-11 15:05:25 +00:00
Christopher Faylor a010e6abed * cygwin.din (_getutline): Remove.
* lib/bsdlib.cc (login): Make argument const as per linux.
(logout): Ditto.
* syscalls.cc (getutid): Ditto.
(getutline): Ditto.
(pututline): Ditto.
(getutxent): Add comment mentioning non-thread-safety.
(getutxid): Ditto.
(getutxline): Ditto.
(pututxline): Ditto.
* sys/utmp.h: Declare arguments to various functions as const as per linux.
Remove bogus _getutline definition.
2008-07-30 04:58:24 +00:00
Corinna Vinschen f9afd0ced7 * Makefile.in (DLL_OFILES): Remove v8 regexp files.
(OBSOLETE_FUNCTIONS): Remove v8 regexp functions.
	(NEW_FUNCTIONS): Remove POSIX regex functions.
	* cygwin.din: Export POSIX regex functions with their correct symbol
	name.  Export with posix_ prefix for backward compatibility.
	* syscalls.cc (regfree): Remove ancient fake function.
	* regex/regex.h: Remove renaming regex functions within Cygwin.
	* regexp/*: Remove.
	* include /cygwin/version,.h: Bump API minor number.
2008-07-29 10:40:37 +00:00
Christopher Faylor 038af33480 * dcrt0.cc (dll_crt0_0): Remove calling malloc_init and
user_shared_initialize_1 from here.
(dll_crt0_1): Remove dynamically_loaded check.  Just call malloc_init and
user_shared_initialize unconditionally.
* shared.cc (user_shared_create): Rename from user_shared_initialize.
(user_shared_initialize): Rename from user_shared_initialize_1.  Move complete
user_shared content initialization code here from user_shared_create.
* syscalls.cc (seteuid32): Remove call to user_shared_initialize_1.  That is
implied by the "true" argument to user_shared_create().
2008-07-27 22:31:48 +00:00
Corinna Vinschen 1d011c0a68 * dcrt0.cc (dll_crt0_0): Call malloc_init and user_shared_initialize_1
here in case we're dynamically loaded.  Explain why.
	(dll_crt0_1): Call user_shared_initialize_1 from here.
	* mount.cc (is_native_path): New inline function testing for native
	and long Win32 path prefix.
	(is_unc_share): Remove long WIn32 path prefix test.
	(mount_info::create_root_entry): Use PATH_MAX buffer.
	(mount_info::init): Ditto.
	(mount_info::add_item): Test for is_native_path as well.
	* path.cc (normalize_win32_path): Simplify native path prefix code.
	* shared.cc (user_shared_initialize_1): New function taking user
	shared initialization code relying on malloc and cygtls.
	(user_shared_initialize): Move mountinfo initialization to
	user_shared_initialize_1.
	* shared_info.h (user_shared_initialize_1): Declare.
	* syscalls.cc (seteuid32): Call user_shared_initialize_1 after user
	changed.
2008-07-25 15:23:56 +00:00
Corinna Vinschen e4b575030b Add case-sensitivity.
Unconditionally handle mount points case-sensitive.
	Unconditionally handle virtual paths case-sensitive.
	Unconditionally handle registry paths case-insensitive.
	Otherwise, accommodate case-sensitivity of given path throughout.
	* cygheap.cc (cygheap_root::set): Get additional caseinsensitive
	parameter and store it.
	* cygheap.h (struct cygheap_root_mount_info): Add member
	caseinsensitive.
	* dlfcn.cc (get_full_path_of_dll): Drop PC_NOFULL parameter from call
	to path_conv::check.
	* environ.cc (pcheck_case): Remove.
	(check_case_init): Remove.
	(known): Drop "check_case" option.
	* exceptions.cc (open_stackdumpfile): Add comment.
	* fhandler.cc (fhandler_base::get_default_fmode): Call pathmatch
	instead of strcasematch.
	* fhandler_disk_file.cc: Accommodate case-sensitivity of given path
	throughout.
	(__DIR_mounts::check_mount): Unconditionally check virtual paths
	case-sensitive.
	(fhandler_disk_file::link): Drop case clash handling.
	(fhandler_disk_file::open): Ditto.
	(fhandler_disk_file::readdir_helper): Drop managed mount code.
	* mount.cc: Remove managed mount code and datastructures.
	(struct opt): Remove "managed" option.  Add "posix=0" and "posix=1"
	options.
	(fillout_mntent): Remove "managed" output.  Add "posix" output.
	* path.cc (struct symlink_info): Remove case_clash member and
	case_check method.
	(pcheck_case): Remove.
	(path_prefix_p): Take additional bool parameter "caseinsensitive".
	(pathnmatch): Ditto.
	(pathmatch): Ditto.
	(mkrelpath): Ditto.
	(fs_info::update): Set caseinsensitive flag according to file system
	name and FILE_CASE_SENSITIVE_SEARCH flag.  Add comment.
	(tfx_chars_managed): Remove.
	(transform_chars): Drop "managed" parameter.  Always use tfx_chars.
	(get_nt_native_path): Drop "managed" parameter.  Make sure drive letters
	are always upper case.
	(getfileattr): Change second parameter to denote caseinsensitivity.
	(path_conv::check): Initialize caseinsensitive to OBJ_CASE_INSENSITIVE.
	Set caseinsensitive according to global obcaseinsensitive flag, file
	system case sensitivity and MOUNT_NOPOSIX mount flag.
	Drop case_clash and all the related code.
	(symlink_worker): Drop case clash handling.
	(symlink_info::set): Drop setting case_clash.
	(symlink_info::case_check): Remove.
	(cwdstuff::set): Add comment.
	(etc::init): Take path_conv instead of PUNICODE_STRING as parameter to
	allow case sensitivity.
	* path.h (enum pathconv_arg): Drop PC_SYM_IGNORE.
	(enum case_checking): Remove.
	(enum path_types): Drop PATH_ENC, add PATH_NOPOSIX flag.
	(struct fs_info): Add caseinsensitive flag and accessor methods.
	(class path_conv): Add caseinsensitive member and define
	objcaseinsensitive method.  Drop case_clash member and isencoded method.
	(pathmatch): Change prototype according to above change.
	(pathnmatch): Ditto.
	(path_prefix_p): Ditto.
	(get_nt_native_path): Ditto.
	(class etc): Ditto.
	(fnunmunge): Remove prototype.
	* shared.cc (shared_info::init_obcaseinsensitive): Initialize
	obcaseinsensitive flag from obcaseinsensitive registry value.
	(shared_info::initialize): Call init_obcaseinsensitive here by the
	first process creating the shared memory.
	* shared_info.h (mount_item::fnmunge): Remove.
	(shared_info::obcaseinsensitive): Rename from obcaseinsensitivity.
	(shared_info::init_obcaseinsensitive): Declare.
	* syscalls.cc (try_to_bin): Add comment.
	* include/sys/mount.h (MOUNT_ENC): Remove flag.
	(MOUNT_NOPOSIX): Add flag.
2008-07-16 20:20:45 +00:00
Corinna Vinschen b72918135c * path.cc (cygwin_conv_path): Define tp before setting up faul handler.
* syscalls.cc: Ditto, throughout.
	(gen_full_path_at): Add bool parameter to allow NULL pathname.
	(futimesat): Allow NULL pathname as GLIBC.
2008-05-22 11:18:46 +00:00
Christopher Faylor 9ea50a60e1 * string.h (strchr): Eliminate.
* syscalls.cc (rename): Work around inexplicable C++ warning.
2008-05-22 01:25:37 +00:00
Corinna Vinschen 2762ac6c19 * syscalls.cc (FILTERED_MODE): Define valid chmod mode mask.
(chmod): Call fh->fchmod with filtered mode.
	(fchmod): Ditto.
2008-05-21 08:05:53 +00:00