Commit Graph

351 Commits

Author SHA1 Message Date
Christopher Faylor ebd645e7e6 * cygheap.cc (cfree): Remove malloc debugging probe.
* dlmalloc.c (errprint): Remove abort() call which causes interesting error
message printing to abort prematurely.
* environ.cc: Sprinkle MALLOC_CHECKs liberally throughout.
(_addenv): Allocate two empty elements at end of environ to
(apparently) work around problems with some buggy applications.
(winenv): Avoid calling alloca if no forced environment variable is present.

* exceptions.cc (open_stackdumpfile): Don't print "Dumping stack trace to..."
when running in a cygwin environment (i.e., the parent is a cygwin process).

* dtable.cc (dtable::init_std_file_from_handle): Move device type detection
code from build_fhandler here since it is only used by this function.
(dtable::build_fhandler_from_name): New method.  Renamed from
dtable::build_fhandler.
(dtable::build_fhandler): Use build_fhandler_from_name.
(cygwin_attach_handle_to_fd): Ditto.
* syscalls.cc (_open): Ditto.
(stat_worker): Ditto.
* dtable.h (dtable::build_fhandler_from_name): Rename declaration from
dtable::build_fhandler.
2001-10-03 03:49:26 +00:00
Christopher Faylor 4ab6034f50 * dtable.h (dtable::build_fhandler): Make path_conv parameter non-optional.
(dtable::init_std_file_from_handle): Eliminate name parameter.
* dtable.cc (stdio_init): Don't pass bogus name to init_std_file_from_handle.
The function will figure out the name itself.
(dtable::init_std_file_from_handle): Eliminate name parameter.  Assume that
we're always called with an appropriate fd.  Pass name as NULL if we can't
simply figure it out from context.
(cygwin_attach_handle_to_fd): Pass path_conv argument to build_fhandler.
(dtable::build_fhandler): Make path_conv argument mandatory.  Eliminate
specific call to get_device_number.  With unknown device names, set name from
handle context for parsing by path_conv.
(dtable::build_fhandler): Pass path_conv argument to build_fhandler.
* path.h (path_conv::set_isdisk): Set disk device type.
(path_conv::is_device): Don't consider FH_DISK a "device".
* syscalls.cc (_open): Pass path_conv argument by reference.
(stat_worker): Ditto.
(_rename): Use path_conv operators.  Add bounds to DeleteFile/MoveFile for
loop.
2001-10-02 01:58:06 +00:00
Christopher Faylor 47063f00e4 Add "path.h" include throughout, where needed. Use new path_conv methods and
operators to simplify testing for directory and attributes, throughout.
* path.h (path_conv::exists): New method.
(path_conv::has_attribute): Ditto.
(path_conv::isdir): Ditto.
(path_conv::DWORD &): New operator.
(path_conv::int &): Ditto.
* dir.cc (rmdir): Eliminate a goto.
* dtable.cc (dtable::build_fhandler): Accept opt and suffix info for
path_conv.check.  Return fh == NULL on path_conv error.  Pass unit to set_name
as appropriate.
(dtable::reset_unix_path_name): New method.
* dtable.h (dtable): Declare new method.  Reflect arg changes to
build_fhandler.
* fhandler.cc (fhandler_disk_dummy_name): Eliminate.
(fhandler_base::set_name): Expect paths to be NULL.  Build unix_path_name from
win32_path_name when it is a device.
(fhandler_base::reset_unix_path_name): New method.
(fhandler_base::raw_read): Report EISDIR when ERROR_INVALID_FUNCTION or
ERROR_INVALID_PARAMETER and reading a directory.
(fhandler_disk_file::fstat): Don't call stat_dev since we should now never be
calling fhandler_disk_file methods with devices.
(fhandler_base::fhandler_base): Clear {unix,win32}_path_name.
(fhandler_base::~fhandler_base): Always free {unix,win32}_path_name.
(fhandler_disk_file::fhandler_disk_file): Remove set_no_free_names kludge.
(fhandler_disk_file::open): Ditto.
* fhandler.h (fhandler_base::no_free_names): Eliminate.
(fhandler_base::set_no_free_names): Ditto.
* fhandler_tty.cc (fhandler_tty_slave::fhandler_tty_slave): Don't set
unix_path_name here.
* path.cc (fchdir): Lock fd table throughout.  Use new
dtable::reset_unix_path_name method to reset path.
* syscalls.cc (stat_worker): Reorganize to always call fstat method.  Pass
path_conv method to fhandler_*::open.
(chroot): Elminate a goto.
2001-10-01 04:10:07 +00:00
Christopher Faylor 35f879a6d0 * fhandler.h (fhandler_pipe::hit_eof): New method.
(writepipe_exists): New class element.
(orig_pid): Ditto.
(id): Ditto.
(is_slow): Eliminate.
* pipe.cc (fhandler_pipe::set_close_on_exec): Set inheritance on
writepipe_exists, if it exists.
(fhandler_pipe::hit_eof): New method, modelled after tty.
(fhandler_pipe::dup): Duplicate writepipe_exists, if it exists.
(make_pipe): Set up a dummy event for pipes on windows 9x.  The nonexistence
of this event means that the write side of the pipe has closed.
(_dup): Move to syscalls.cc
(_dup2): Ditto.

* dtable.cc (dtable::build_fhandler): Fill out set_names here, if appropriate.
* syscalls.cc (_open): Call set_names in build_fhandler.
2001-09-24 21:50:44 +00:00
Corinna Vinschen 4367ec036f * syscalls.cc (_open): Set name in fhandler object after successful
creation.
        (stat_dev): Set device type to block device in FH_FLOPPY case.
2001-09-23 15:35:02 +00:00
Christopher Faylor 9854ada754 * dtable.cc (dtable::build_fhandler): Accept an optional path_conv argument.
If available, use this to calculate path name and device number.
* dtable.h (dtable): Reflect above change.
* fhandler.h (fhandler_base): Declare virtual method which accepts path_conv
rather than path string as first argument.
* fhandler.cc (fhandler_base::open): Define above new method.
* syscalls.cc (_open): Set aside a path_conv variable for use in build_fhandler
and subsequent call to open.
2001-09-22 21:44:07 +00:00
Christopher Faylor 5e733918c0 * exceptions.cc (setup_handler): Always relinquish lock after we've
interrupted.
* fhandler.cc: Move pipe methods to pipe.cc.
* fhandler.h (fhandler_pipe): Add new methods.
* fork.cc (sync_with_parent): Make error messages more informative.
* pipe.cc (fhandler_pipe::fhandler_pipe): Move here from fhandler.cc.
(fhandler_pipe::lseek): Ditto.
(fhandler_pipe::set_close_on_exec): New method.
(fhandler_pipe::read): Ditto.
(fhandler_pipe::close): Ditto.
(fhandler_pipe::dup): Ditto.
(make_pipe): Create the guard mutex on the read side of the pipe.
* select.cc (peek_pipe): Use guard_mutex to discover if we have the right to
read on this pipe.
(fhandler_pipe::readh_for_read): Pass the read pipe guard mutex to peek_pipe.
* syscalls.cc (_read): Always detect signal catchers, for now.
* debug.cc (makethread): Eliminate hack to make thread inheritable.
* sigproc.cc (subproc_init): Don't use hack to make thread inheritable.
2001-09-22 16:55:02 +00:00
Egor Duda 0aca521ab8 * path.cc (symlink): Check arguments for validity.
(getcwd): Ditto.
* syscalls.cc (ftruncate): Ditto.
* times.cc (times): Ditto.
* uname.cc (uname): Ditto.
2001-09-16 14:26:11 +00:00
Corinna Vinschen ba94682838 * Makefile.in: Build wincap.o.
* wincap.cc: New file.
        * wincap.h: Ditto.
        * autoload.cc: Add dynamic load statement for `CreateHardLinkA'.
        * dcrt0.cc (os_being_run): Eliminated.
        (osname): Ditto.
        (iswinnt): Ditto.
        (set_os_type): Ditto.
        (dll_crt0_1): Call wincap.init() instead of set_os_type().
        (_dll_crt0): Ditto.
        * environ.cc (set_chunksize): New function.
        (parse_thing): `forkchunk' setting now invokes function `set_chunksize'.
        * fork.cc (chunksize): Eliminated. Moved to be member of wincap.
        * host_dependent.h: Removed.
        * syscalls.cc (_link): Try using `CreateHardLinkA' first, if available.
        * cygheap.cc, dcrt0.cc, delqueue.cc, dir.cc,
        environ.cc, fhandler.cc, fhandler.h, fhandler_console.cc,
        fhandler_mem.cc, fork.cc, mmap.cc, net.cc, pinfo.cc, pinfo.h,
        security.cc, syscalls.cc, sysconf.cc, syslog.cc, thread.cc,
        times.cc, tty.cc, uinfo.cc, uname.cc, winsup.h: Use new wincap
        capability check throughout.
        * winsup.h: Include wincap.h. Eliminate extern declarations of
        `os_being_run' and `iswinnt'. Eliminate `os_type" definition.
        * include/cygwin/version.h: Bump version to 1.3.4.
2001-09-12 17:46:37 +00:00
Christopher Faylor aed6988a36 * exceptions.cc (call_signal_handler_now): Add additional guard against
inappropriately calling signal handler.
* syscalls.cc (_read): Reset errno if not exiting due to signal.
2001-09-12 05:09:24 +00:00
Christopher Faylor 1ff9f4b937 * cygheap.h (init_cygheap): Move heap pointers here.
* include/sys/cygwin.h (perprocess): Remove heap pointers.
* dcrt0.cc (__cygwin_user_data): Reflect obsolete perprocess stuff.
(_dll_crt0): Don't initialize heap pointers.
(cygwin_dll_init): Ditto.
(release_upto): Use heap pointers from cygheap.
* heap.h: Ditto.
* fork.cc (fork_parent): Ditto.  Don't set heap pointers in ch.
(fork_child): Remove obsolete sigproc_fixup_after_fork.
* shared.cc (memory_init): Reorganize so that cygheap initialization is called
prior to regular heap since regular heap uses cygheap now.
* sigproc.cc (proc_subproc): Eliminate zombies allocation.
(sigproc_init): Move zombies alloation here.  Don't free up array on fork, just
reuse it.
(sigproc_fixup_after_fork): Eliminate.
* sigproc.h: Ditto.
* include/cygwin/version.h: Reflect change to perprocess structure.
2001-09-07 21:32:07 +00:00
Corinna Vinschen b0cce7e127 * include/limits.h: Define PIPE_BUF.
* syscalls.cc (fpathconf): Use PIPE_BUF instead of numerical constant.
        (pathconf): Ditto.
2001-09-07 08:31:16 +00:00
Christopher Faylor 9867ecfdb3 * child_info.h: Modify magic number.
* dcrt0.cc (_cygwin_testing): Define.
(_dll_crt0): Set _cygwin_testing if CYGWIN_TESTING environment variable exists.
Don't issue "conflicting versions" error if _cygwin_testing is true.
* shared.cc (shared_name): Use _cygwin_testing global rather than testing the
environment.
* syscalls.cc (_write): Remove debugging info.
2001-09-03 02:13:05 +00:00
Christopher Faylor e32b4e81cb * syscalls.cc (check_tty_fds): New function. Check whether there is a fd
referring to pty slave.
(setsid): Don't detach console if the process has a pty slave.
2001-08-25 17:27:31 +00:00
Christopher Faylor ecaff08ccd * dtable.cc (dtable::dup2): Allow extension of fd table by dup2.
* syscalls.cc: Minor code cleanup.
(fpathconf): Check for bad fd before doing anything else.
* termios.cc (tcsetattr): Don't convert to new termios if bad fd.
(tcgetattr): Minor debugging tweak.
2001-08-23 02:27:01 +00:00
Corinna Vinschen 1457739a63 * resource.cc (getrlimit): Return getdtablesize () as current limit
on RLIMIT_NOFILE.
        * syscalls.cc (getdtablesize): Return OPEN_MAX if current dtable size
        is less than OPEN_MAX, the current dtable size otherwise.
        * sysconf.cc (sysconf): Return getdtablesize () on _SC_OPEN_MAX.
2001-08-16 14:29:21 +00:00
Corinna Vinschen 3171175e90 * resource.cc (getrlimit): Return OPEN_MAX as current limit
on RLIMIT_NOFILE.
        * syscalls.cc (getdtablesize): Return OPEN_MAX.
        * sysconf.cc (sysconf): Return OPEN_MAX on _SC_OPEN_MAX.
        * include/limits.h (OPEN_MAX): Define as 256.
2001-08-16 14:20:09 +00:00
Corinna Vinschen 5fd12fb0cc * fhandler.cc (fhandler_base::is_nonblocking): New method.
(fhandler_base::set_nonblocking): Ditto.
        * fhandler.h (fhandler_base): Declare new methods `is_nonblocking' and
        `set_nonblocking'.
        * fhandler_socket.cc (fhandler_socket::ioctl): Use `set_nonblocking'.
        * fhandler_tty.cc (fhandler_pty_master::process_slave_output):
        Use `is_nonblocking'.
        (fhandler_tty_slave::read): Ditto.
        (fhandler_tty_slave::ioctl): Use `set_nonblocking'.
        (fhandler_pty_master::ioctl): Ditto.
        * net.cc (cygwin_sendto): Fallback to winsock 1 functionality
        in case of nonblocking IO.
        (cygwin_recvfrom): Ditto.
        (cygwin_recv): Ditto.
        (cygwin_send): Ditto.
        * syscalls.cc (_read): Use `is_nonblocking'.
2001-08-15 07:49:15 +00:00
Corinna Vinschen 6a574f1ad6 * fhandler.cc (fhandler_base::fcntl): Use new O_NONBLOCK_MASK define.
* fhandler.h: Move definitions of O_NOSYMLINK, O_DIROPEN and
        OLD_O_NDELAY from winsup.h to here. Add O_NONBLOCK_MASK define.
        * fhandler_socket.cc (fhandler_socket::close): Add hack to allow
        a graceful shutdown even if shutdown() hasn't been called by the
        application. Add debug output.
        (fhandler_socket::ioctl): Set fhandler's NONBLOCK flag according
        to FIONBIO setting.
        (fhandler_socket::fcntl): Use new O_NONBLOCK_MASK define. Actually
        set `request' before using it.
        * fhandler_tty.cc: Use new O_NONBLOCK_MASK define throughout.
        (fhandler_tty_slave::ioctl): Set fhandler's NONBLOCK flag according
        to FIONBIO setting.
        (fhandler_pty_master::ioctl): Ditto.
        * net.cc (wsock_event::prepare): Compare WSACreateEvent return code
        with `WSA_INVALID_EVENT' according to MSDN.
        * syscalls.cc (_read): Use new O_NONBLOCK_MASK define.
2001-08-14 07:41:45 +00:00
Corinna Vinschen c0ae23dc47 * security.cc (alloc_sd): Don't set FILE_DELETE_CHILD for group
if S_ISVTX attribute is given.
        * dir.cc (mkdir): Allow immediate setting of S_ISUID, S_ISGID and
        S_ISVTX attribute.
        * syscalls.cc (_open): Ditto.
2001-08-07 16:14:59 +00:00
Christopher Faylor e5ba4c060e Throughout, change check for running under Windows NT to 'iswinnt'.
* dcrt0.cc (set_os_type): Set 'iswinnt' appropriately.
* cygheap.cc (init_cheap): Revert to using VirtualAlloc for allocating cygheap.
(cygheap_setup_for_child_cleanup): New function.  Standard function to call
after calling CreateProcess to cleanup cygheap info passed to child.
(cygheap_fixup_in_child): Copy cygheap from shared memory into allocated space
under Windows 9x or if can't relocate shared space under NT.
* cygheap.h: Declare new function.
* spawn.cc (spawn_guts): Use cygheap_fixup_in_child.
* fork.cc (fork_parent): Ditto.
* winsup.h: Declare iswinnt.
2001-08-04 21:10:52 +00:00
Christopher Faylor 6b91b8d53b Throughout, reorganize header file inclusion to put security.h prior to
fhandler.h.
* fhandler.h (fhandler_base::get_inheritance): New method.
* fhandler_socket.cc (fhandler_socket::create_secret_event): Use proper
close-on-exec inheritance when creating.
(fhandler_socket::check_peer_secret_event): Create handle as non-inheritable.
2001-07-26 19:22:24 +00:00
Christopher Faylor 0cc642a5f1 * syscalls.cc (setsid): Detach process from its console if the current
controlling tty is the console and already closed.
* dtable.h (class dtable): Add members to count descriptors referring to the
console.
* dtable.cc (dtable::dec_console_fds): New function to detach process from its
console.
(dtable::release): Decrement the counter of console descriptors.
(dtable::build_fhandler): Increment it.
* exception.cc (ctrl_c_handler): Send SIGTERM to myself when catch
CTRL_SHUTDOWN_EVENT.
2001-07-26 00:10:52 +00:00
Corinna Vinschen 5564cd7a89 * syscalls.cc (_unlink): Explicitely check for non-existant file. 2001-07-18 11:00:05 +00:00
Christopher Faylor fc901253d1 * syscalls.cc (stat_worker): Simplify previous change. 2001-07-14 00:09:33 +00:00
Christopher Faylor 2aa2adb2d2 * syscalls.cc (_unlink): Correct (?) logic which determines when to report an
access violation and when to queue file for eventual deletion.
(stat_worker): Check for invalid buf argument.
2001-07-13 17:22:15 +00:00
Christopher Faylor 7a4078ee34 Change check_null_empty_path* to check_null_empty_str* throughout.
* path.cc (path_conv::check): Add signal protection here since retrieving info
about remote shares can take some time.
* path.h (check_null_empty_str_errno): Convert to a function prototype.
* path.cc (check_null_empty_str): Move to miscfuncs.cc.
* miscfuncs.cc (check_null_empty_str_errno): New function.
(__check_null_invalid_struct): Ditto.
(__check_null_invalid_struct_errno): Ditto.
(check_null_empty_str): Change from VirtualQuery to IsBadWritePtr.
* thread.cc (check_valid_pointer): Ditto.
* resource.cc (getrlimit): Use check_null_invalid_struct macro for checking
validity of pointer.
(setrlimit): Ditto.
2001-06-28 02:19:57 +00:00
Christopher Faylor 07c3cd5bb1 * fhandler.cc (fhandler_disk_file::fstat): Don't rely on exactly 3 characters
being read for executable test since we could be checking for less than that.
* syscalls.cc (stat_worker): Try opening the file the "correct" way first so
that #! processing can potentially happen.  If that fails, then use "query
open" method.
* spawn.cc (spawn_guts): Delay processing of signal until after we've notified
parent about reparenting.
2001-06-26 21:03:08 +00:00
Christopher Faylor 20a2c44362 * fhandler_tty.cc (fhandler_tty_slave::init): Revert 2001-06-16 change.
* fork.cc (fork_copy): Print more debugging info.
(fork_parent): Change order of arguments to accomdate buggy gcc.
(fork): Ditto.
* syscalls.cc (_unlink): Reorganize to try harder to delete file with
DeleteFile and to recover more gracefully if FILE_FLAG_DELETE_ON_CLOSE doesn't
work properly.
2001-06-18 21:18:59 +00:00
Egor Duda 96d95e535e * fhandler.cc (fhandler_base::open): Set win32 access flags
to 0, when requested.
* fhandler.h: New status flag FH_QUERYOPEN.
(fhandler::get_query_open): New function.
(fhandler::set_query_open): Ditto.
* syscalls.cc (stat_worker): Request query-only open mode.
2001-06-14 18:21:17 +00:00
Corinna Vinschen d4217d5680 * syscalls.cc (seteuid): Set environment variables USERNAME and
USERDOMAIN before impersonation to workaround a LookupAccountSid()
        misbehaviour.
        * uinfo.cc (internal_getlogin): Revert most of the previous change.
        Don't set environment variables USERNAME and USERDOMAIN. That's
        the job of seteuid() now. Try to get logon server from Lsa
        only if logon server isn't already known.
2001-06-09 21:25:55 +00:00
Egor Duda 149da470f3 * security.h (NTWriteEA): Change prototype.
* ntea.cc (NTReadEA): Don't check for global ntea setting, now
it's caller responsibility.
(NTWriteEA): Ditto.
* security.cc (get_file_attribute): Read attribute from EA only
if 'ntea' is enabled.
(set_file_attribute): Ditto.
* path.h: (class path_conv): Add members to store file system
information.
(path_conv::get_drive_type): New function.
* syscalls.cc (stat_worker): Use it.
* path.cc (path_conv::update_fs_info): New functions.
(path_conv::check): Get file system information from device where
file resides. On NTFS, try to read symlink contents from EA.
(get_symlink_ea): New function.
(set_symlink_ea): Ditto.
(symlink): Store symlink in extended attribute, if possible.
2001-06-05 10:45:52 +00:00
Christopher Faylor 7ceb1cac3a * cygheap.cc (cygheap_root::cygheap_rot): Remove constructor.
(cygheap_root::~cygheap_root): Remove destructor.
(cygheap_root::operator =): Remove.
(cygheap_root::set): New method.
* cygheap.h (cygheap_root): Reflect above changes.  Store root info in
mount-like structure.
(cygheap_root:posix_ok): New method.
(cygheap_root::ischroot_native): Ditto.
(cygheap_root::unchroot): Ditto.
(cygheap_root::exists): Ditto.
(cygheap_root::posix_length): Ditto.
(cygheap_root::posix_path): Ditto.
(cygheap_root::native_length): Ditto.
(cygheap_root::native_path): Ditto.
* dir.cc (opendir): Remove special chroot test.
* path.cc (path_prefix_p): Remove front end.
(normalize_posix_path): Reorganize chroot tests to accomodate new convention of
allowing paths using posix chroot prefix.
(path_conv::check): Pass a "already ran normalize" option to
conv_to_win32_path.  Return if there is an error from this function.
(mount_info::conv_to_win32_path): Add extra argument.  Don't call
normalize_posix_path if caller has already done so.  Substitute chroot setting,
if any, for root translation.  Add chroot checking to final output step.
* shared_info (mount_info): Accomodate additional argument to
conv_to_win32_path.
* syscalls.cc (chroot): Store both normalized posix path and native path in
chroot.
2001-06-03 02:31:16 +00:00
Corinna Vinschen bc28fe9599 * syscalls.cc (_rename): Handle the case that `foo' is renamed to
`bar' while `bar.lnk' is an existing shortcut-symlink.
2001-06-01 11:53:20 +00:00
Christopher Faylor ecfb6f11bc * path.cc (chdir): Always send unsigned chars to isspace since newlib's isspace
doesn't deal well with "negative" chars.
* fhandler.cc (fhandler_disk_file::open): Propagate remote status of file
garnered from path_conv.  Move #! checking to fstat.
(fhandler_disk_file::fstat): Reorganize st_mode setting to eliminate
duplication.  Move check for #! here from fhandler::open.
* fhandler.h (fhandler_base::isremote): New method.
(fhandler_base::set_isremote): Ditto.
(fhandler_base::set_execable_p): Also record "don't care if executable state".
(fhandler_base::dont_care_if_execable): New method.
* path.cc (path_conv::check): Clear new flags.  Appropriately set vol_flags,
drive_type, and is_remote_drive.
* path.h: Add new flags and methods for manipulating them.
* syscalls.cc (_unlink): Use isremote() to determine if a path is remote rather
than calling GetDriveType.
(stat_worker): Ditto.
* security.cc (get_file_attribute): Or attribute with result of NTReadEA to be
consistent with get_nt_attribute.
2001-05-31 05:25:46 +00:00
Corinna Vinschen 7b9a10a60c * syscalls.cc (seteuid): Restrict overriding external provided
user tokens to ntsec. Don't test external tokens for primary
        group to evaluate if it should be overridden. Restrict creating
        internal tokens to ntsec.
2001-05-23 15:49:22 +00:00
Corinna Vinschen 07d08883d8 * syscalls.cc (chown_worker): Don't check for ENOSYS. 2001-05-23 08:12:49 +00:00
Corinna Vinschen 1fcc912f13 * autoload.cc: Add load statements for `LookupAccountNameW',
`LsaClose', `LsaEnumerateAccountRights', `LsaFreeMemory',
        `LsaOpenPolicy', `LsaQueryInformationPolicy', `NetLocalGroupEnum',
        `NetLocalGroupGetMembers', `NetServerEnum', `NetUserGetGroups' and
        `NtCreateToken'.
        * ntdll.h: Add declaration for `NtCreateToken'.
        * sec_helper.cc: Add `well_known_local_sid', `well_known_dialup_sid',
        `well_known_network_sid', `well_known_batch_sid',
        `well_known_interactive_sid', `well_known_service_sid' and
        `well_known_authenticated_users_sid'.
        (cygsid::string): Define as const method.
        (cygsid::get_sid): Set psid to NO_SID on error.
        (cygsid::getfromstr): Ditto.
        (cygsid::getfrompw): Simplify.
        (cygsid::getfromgr): Check for gr == NULL.
        (legal_sid_type): Move to security.h.
        (set_process_privilege): Return -1 on error, otherwise 0 or 1 related
        to previous privilege setting.
        * security.cc (extract_nt_dom_user): Remove `static'.
        (lsa2wchar): New function.
        (open_local_policy): Ditto.
        (close_local_policy): Ditto.
        (get_lsa_srv_inf): Ditto.
        (get_logon_server): Ditto.
        (get_logon_server_and_user_domain): Ditto.
        (get_user_groups): Ditto.
        (is_group_member): Ditto.
        (get_user_local_groups): Ditto.
        (sid_in_token_groups): Ditto.
        (get_user_primary_group): Ditto.
        (get_group_sidlist): Ditto.
        (get_system_priv_list): Ditto.
        (get_priv_list): Ditto.
        (get_dacl): Ditto.
        (create_token): Ditto.
        (subauth): Return immediately if SE_TCB_NAME can't be assigned.
        Change all return statements in case of error to jumps to `out'
        label. Add `out' label to support cleanup.
        * security.h: Add extern declarations for `well_known_local_sid',
        `well_known_dialup_sid', `well_known_network_sid',
        `well_known_batch_sid', `well_known_interactive_sid',
        `well_known_service_sid' and `well_known_authenticated_users_sid'.
        Add extern declarations for functions `create_token',
        `extract_nt_dom_user' and `get_logon_server_and_user_domain'.
        (class cygsid): Add method `assign'. Change operator= to call new
        `assign' method. Add `debug_print' method.
        (class cygsidlist): New class.
        (legal_sid_type): Moved from sec_helper.cc to here.
        * spawn.cc (spawn_guts) Revert reversion of previous patch.
        Call `RevertToSelf' and `ImpersonateLoggedOnUser' instead of `seteuid'
        again.
        * syscalls.cc (seteuid): Rearranged. Call `create_token' now when
        needed. Call `subauth' if `create_token' fails. Try setting token
        owner and primary group only if token was not explicitely created
        by `create_token'.
        * uinfo.cc (internal_getlogin): Try harder to generate correct user
        information. Especially don't trust return value of `GetUserName'.
2001-05-20 08:10:47 +00:00
Corinna Vinschen 2b0a111fcf * fork.cc (fork): Eliminate superfluous call to getuid().
* security.h: New define `NO_SID'. Remove declarations of functions
        moved to methods into class cygsid.
        (class cygsid): Declare new methods `getfromstr', `get_sid',
        `getfrompw', `getfromgr', `get_rid', `get_uid', `get_gid', `string'
        and new constructors and operators =, == and !=.
        Declare new global cygsids `well_known_XXX_sid' substituting the
        corresponding `get_XXX_sid' functions. Remove declarations of
        these functions.
        * sec_helper.cc (well_known_admin_sid): New global variable.
        (well_known_system_sid): Ditto
        (well_known_creator_owner_sid): Ditto
        (well_known_world_sid): Ditto
        (cygsid::string): New method, substituting `convert_sid_to_string_sid'.
        (cygsid::get_sid): New method, substituting `get_sid'.
        (cygsid::getfromstr): New method, substituting
        `convert_string_sid_to_sid'.
        (cygsid::getfrompw): New method, substituting `get_pw_sid'.
        (cygsid::getfromgr): New method, substituting `get_gr_sid'.
        (cygsid::get_id): New method, substituting `get_id_from_sid'.
        (get_admin_sid): Eliminated.
        (get_system_sid): Ditto.
        (get_creator_owner_sid): Ditto.
        (get_world_sid): Ditto.
        * grp.cc: Use new cygsid methods and well known sids throughout.
        * registry.cc: Ditto.
        * sec_acl.cc: Ditto.
        * security.cc: Ditto.
        * shared.cc: Ditto.
        * syscalls.cc (seteuid): Ditto. Eliminate redundant conditional.
        * uinfo.cc (internal_getlogin): Ditto.
        * spawn.cc (spawn_guts) Revert previous patch.
2001-05-15 19:23:31 +00:00
Corinna Vinschen 57ff940dd4 * autoload.cc: Add LoadDLLinitfunc for secur32.dll.
Add LoadDLLfuncEx statements for AllocateLocallyUniqueId@4,
        DuplicateTokenEx@24, LsaNtStatusToWinError@4,
        LsaDeregisterLogonProcess@4, LsaFreeReturnBuffer@4,
        LsaLogonUser@56, LsaLookupAuthenticationPackage@12,
        LsaRegisterLogonProcess@12,
        * environ.cc: Add extern declaration for `subauth_id'.
        (subauth_id_init): New function for setting `subauth_id'.
        (struct parse_thing): Add entry for `subauth_id'.
        * fork.cc (fork_parent): Call `RevertToSelf' and
        `ImpersonateLoggedOnUser' instead of `seteuid'.
        * security.cc: Define global variable `subauth_id'.
        (extract_nt_dom_user): New function.
        (cygwin_logon_user): Call `extract_nt_dom_user' now.
        (str2lsa): New static function.
        (str2buf2lsa): Ditto.
        (str2buf2uni): Ditto.
        (subauth): Ditto.
        * security.h: Add prototype for `subauth'.
        * spawn.cc (spawn_guts): Use cygheap->user.token only if impersonated.
        Use `cygsid' type. Remove impersonation before allowing access to
        workstation/desktop to everyone. Call `RevertToSelf' and
        `ImpersonateLoggedOnUser' instead of `seteuid'.
        * syscalls.cc (seteuid): Rearranged to allow using subauthentication
        to retrieve user tokens when needed.
2001-04-30 21:19:42 +00:00
Christopher Faylor b98ebf5470 Throughout, change 'tty_attached' to 'real_tty_attached', for clarity.
Throughout, change 'OutputStopped' to 'output_stopped', for consistency.
* dtable.cc (stdio_init): Set controlling tty if not set by stdio opens.
* exceptions.cc (ctrl_c_handler): Avoid special pgid checking if no tty is
associated with the process.
(Suggested by Tim Baker <dbaker@direct.ca>)
* external.cc (fillout_pinfo): Return actual tty number for ctty.
* fhandler_console.cc (get_tty_stuff): Set ctty when shared memory is
allocated.  Accept flags input from open().
(set_console_ctty): New function.
(fhandler_console::open): Pass flags to get_tty_stuff and rely on this function
to set the ctty, if appropriate.
* fhandler_termios.cc (fhandler_termios::set_ctty): Move to tty_min class.
* fhandler_tty.cc (fhandler_tty_slave::open): Use tc field to access
set_ctty().
* tty.h (TTY_CONSOLE): Move to include/sys/cygwin.h.
(tty_min): Add set_ctty class here.
* include/sys/cygwin.h (TTY_CONSOLE): New home here.
* path.cc (symlink_info): Make contents an actual buffer.  Pass more flags to
case_check.
(path_conv::check): Reorganize to do parsing based on posix path rather than
native path.
(symlink_info::check): Expect posix path as input.  Translate to native path
here.  Accept path_conv flags.  Stop parsing if not a symlink regardless of
whether previous path was a symlink.
2001-04-28 23:48:28 +00:00
Corinna Vinschen feae8d0eab * uinfo.cc (internal_getlogin): Return pointer to struct passwd.
(uinfo_init): Accommodate the above change.
        * syscalls.cc (seteuid): Ditto.
2001-04-25 12:54:21 +00:00
Corinna Vinschen d551169a9f * autoload.cc: Add LoadDLLfunc statements for SetTokenInformation@16.
* cygheap.cc: Include security.h.
        * grp.cc (internal_getgrent): New function.
        (getgroups): Rearranged using `internal_getgrent' and the new
        `cygsid' class.
        * passwd.cc (internal_getpwent): New function.
        * sec_acl.cc: Use new `cygsid' class throughout.
        (acl_access): Use `internal_getgrent' instead of `getgrent'.
        * sec_helper.cc: Use new `cygsid' class throughout.
        (get_id_from_sid): Use `internal_getgrent' instead of `getgrent'.
        Use `internal_getpwent' instead of `getpwent'.
        * security.cc: Use new `cygsid' class throughout.
        * security.h: Move `MAX_SID_LEN' from winsup.h to here.
        Add extern declarations for `internal_getgrent' and `internal_getpwent'.
        (class cygsid): New class.
        * shared.cc (sec_user): Use new `cygsid' class.
        * syscalls.cc (seteuid): Try to set owner to user and primary group to
        current group in impersonation token before performing impersonation.
        (setegid): Try to set primary group in process token to the new group
        if ntsec is on.
        * uinfo.cc (internal_getlogin): Use new `cygsid' class.
        Try to set owner to user and primary group to current group in process
        token if the process has been started from a non cygwin process.
        (uinfo_init): Set primary group only if the process has been started
        from a non cygwin process.
        * winsup.h: Move define for `MAX_SID_LEN' to security.h.
2001-04-25 09:43:25 +00:00
Christopher Faylor f3ea62a847 Remove trailing underscore from fhandler_base and friends, throughout.
* fhandler.h (fhandler_base::set_open_status): New method.  Stores original
open status.
(fhandler_base::get_open_status): New method.  Retrieves original open status.
(fhandler_base::reset_to_open_binmode): New method.
* fhandler.cc (fhandler_base::open): Save open status.
(fhandler_base::init): Ditto.
* fhandler_clipboard.cc (fhandler_clipboard::open): Ditto.
* fhandler_console.cc (fhandler_console::open): Ditto.
* fhandler_dsp.cc (fhandler_dsp::open): Ditto.
* fhandler_dev_mem.cc (fhandler_dev_mem::open): Ditto.
* fhandler_dev_random.cc (fhandler_dev_random::open): Ditto.
* fhandler_serial.cc (fhandler_serial::open): Ditto.
* fhandler_tty_slave.cc (fhandler_tty_slave::open): Ditto.
* fhandler_tty_master.cc (fhandler_tty_master::open): Ditto.
* fhandler_dev_zero.cc (fhandler_dev_zero::open): Ditto.
* syscalls.cc (setmode): Rework so that 0 mode value causes reversion to open
state.
* fhandler_tty_slave.cc (fhandler_tty_slave::read): Use correct multiplier when
converting from deciseconds to milliseconds.
2001-04-24 02:07:58 +00:00
Christopher Faylor 9cf9c14668 * fhandler.h (fhandler_base::clear_r_binary): New method.
(fhandler_base::clear_w_binary): New method.
* syscalls.cc (setmode): Accept 0 as mode value.  Resets text/binary behavior
for fd to default.
2001-04-23 17:29:33 +00:00
Christopher Faylor f940c5b1aa * net.cc [errmap]: Add '0' condition.
(find_winsock_errno): Don't translate no error to EPERM.
2001-04-23 16:46:30 +00:00
Christopher Faylor 0381fec68f Throughout, change fdtab references to cygheap->fdtab.
* child_info.h (cygheap_exec_info): Eliminate special fdtab stuff.
* spawn.cc (spawn_guts): Ditto.
* cygheap.cc (cygheap_init): Initialize fdtab, if appropriate.
* cygheap.h (CYGHEAPSIZE): Include size of init_cygheap.
(_cmalloc_entry): Include fdtab here.
* dtable.h (dtable): Declare/define new methods.
* dtable.cc (dtable::vfork_child_fixup): New method.
(dtable::fixup_after_exec): Remove unneeded extra arguments.
* dcrt0.cc (dll_crt0_1): Ditto.
* environ.cc (getwinenv): Use case sensitive comparison.
(winenv): Make a copy of environment cache to avoid realloc problems when
duplicate environment variables exist in the environment.  (From Egor Duda)
* net.cc (cygwin_socket): Revert Apr 14 change.
* include/sys/file.h: Protect against previous X_OK definition.
* passwd.cc: Eliminate passwd_sem throughout.
* security.cc: Ditto.
* cygwin.din: Export New functions.
* passwd.cc (read_etc_passwd): Make race safe.
(getpwuid_r): New function.
(getpwnam_r): New function.
2001-04-18 21:10:15 +00:00
Corinna Vinschen 0f56512627 * path.cc (path_conv::check): Set case_clash even if pcheck_case
is set to PCHECK_ADJUST when a case clash is given for the last
        component in path.
        (symlink_info::case_check): Ditto.
        * syscalls.cc (_rename): Avoid overwriting an already existing file
        if a case clash is given even if pcheck_case is set to PCHECK_ADJUST.
2001-04-17 11:47:37 +00:00
Corinna Vinschen 70c370d674 * dir.cc (mkdir): Check for case clash.
* environ.cc: Add extern declaration for `pcheck_case'.
        (check_case_init): New function.
        (struct parse_thing): Add "check_case" option.
        * errno.cc (_sys_nerrlist): Add text for ECASECLASH.
        (strerror): Add case branch for ECASECLASH.
        * fhandler.cc (fhandler_disk_file::open): Check for case clash.
        * path.cc: Add global variable `pcheck_case'.
        (struct symlink_info): Add member `case_clash' and method `case_check'.
        (path_prefix_p_): Call `pathnmatch' instead of `strncasematch'.
        (pathnmatch): New funtion.
        (pathmatch): Ditto.
        (path_conv::check): Add handling for case checking.
        (symlink): Check for case clash.
        (symlink_info::check): Add parameter for case checking.
        Handle case checking.
        (symlink_info::case_check): New method.
        (chdir): Don't use unconverted path if pcheck_case==PCHECK_STRICT.
        * path.h: Add extern declarations for `pathmatch' and
        `pathnmatch'.
        (enum case_checking): New enumeration type describing
        the case checking behaviour of path conversion routines.
        (class path_conv): Add member `case_clash'.
        * syscalls.cc (_link): Check for case clash.
2001-04-12 21:21:37 +00:00
Christopher Faylor 82d4a5d4bb * syscalls.cc (mkfifo): New function stub. 2001-04-12 16:50:13 +00:00
Corinna Vinschen 9ddfe5a04a * syscalls.cc (stat_worker): Fix conditional which still allowed
successful stat'ing of non-existant files.
2001-04-05 20:43:23 +00:00
Christopher Faylor c90e420d91 * cygrun.c (main): Fix compiler warning.
* gmon.c (_mcleanup): Ditto.
* profil.c (profile_off): Ditto.
* net.cc (find_winsock_errno): New function.
(__set_winsock_errno): Use find_winsock_errno.
(cygwin_setsockopt): Detect SO_ERROR for debugging.
(cygwin_getsockopt): Ditto.  Translate error when getsockopt returns SO_ERROR.
* winsup.h: regparmize __set_winsock_errno.
* include/sys/strace.h: Document that strace functions can't use regparm.
2001-04-03 02:53:25 +00:00
Christopher Faylor 1ba3935dfb * exceptions.cc (sigframe::call_signal_handler): Return value of
call_signal_handler_now.
* sigproc.h (sigframe): Use constructor.
* syscalls.cc (_read): Correct errno test prior to calling signal handler.
2001-04-02 00:18:29 +00:00
Christopher Faylor f2aeff27f0 * thread.h (struct _winsup_t): Remove obsolete elements. Add available_drives
element.
* path.cc (mount_info::getmntent): Report "/cygdrive" drives when mounted
drives are exhausted.
(fillout_mntent): New function.
(mount_item::getmntent): Use fillout_mntent.
(cygdrives_mntent): New function.  Returns next available "/cygdrive".
(setmntent): Initialize available "/cygdrives".
* syscalls.cc: Remove some if 0'ed code.
* times.cc (timezone): Use more descriptive variable name.
2001-04-01 03:06:02 +00:00
Christopher Faylor f611148366 * sigproc.h (class sigframe): Implement 'unregister()' method.
(sigframe::~sigframe): Use unregister method.
(sigframe::call_signal_handler): Declare new method.
* exceptions.cc (sigframe::call_signal_handler): New method.  Unregisters
current sigframe before calling signal handler.
(setup_handler): Clear waiting threads prior to arming signal_arrived.
* syscalls.cc (_read): Change goto to loop.  Recalculate sigframe inside of
loop so that constructor is called when appropriate.
* wait.cc (wait4): Ditto.
* signal.cc: Change "sig" to "signal" in debugging messages throughout.
* sigproc.cc: Ditto.
2001-04-01 00:06:17 +00:00
Corinna Vinschen 30f326bf5e * syscalls.cc (check_posix_perm): New static function.
(fpathconf): Add _PC_POSIX_PERMISSIONS and _PC_POSIX_SECURITY
        support.
        (pathconf): Ditto.
        * include/cygwin/version.h: Bump API minor number to 37.
2001-03-19 11:02:41 +00:00
Christopher Faylor 94b03f2380 Fix spacing, copyrights. 2001-03-18 21:11:25 +00:00
Corinna Vinschen 8eb72e632c * net.cc (get_95_ifconf): Use strcasematch instead of strcasecmp.
* syscalls.cc (_unlink): Ditto.
        (_rename): Ditto.
2001-03-17 19:53:52 +00:00
Christopher Faylor db15b3e359 Accomodate all devices. 2001-03-17 05:11:20 +00:00
Christopher Faylor 5bb22c6b1d * syscalls.cc (stat_dev): Give devices full read/write. 2001-03-17 05:06:14 +00:00
Corinna Vinschen 78d2c08cd9 * path.cc (lnk_suffixes): Remove.
(class suffix_scan): Add `lnk_state' flag.
        (suffix_scan::lnk_match): Return state of `lnk_state' now.
        (suffix_scan::has): Changed behaviour if file has `.lnk' suffix.
        (suffix_scan::next): Set `lnk_state' where appropriate.
        (symlink_info::check): Fix a wrong `break'.
        * syscalls.cc (chown_worker): Change debug statement to reflect
        lchown fix.
        (lchown): Call chown_worker with `PC_SYM_NOFOLLOW' instead of
        `PC_SYM_IGNORE'.
2001-03-14 11:13:46 +00:00
Christopher Faylor 941fa5ad96 * spawn.cc (spawn_guts): Don't set EXIT_REPARENTING if parent process is not a
cygwin process (suggested by Jason Gouger <cygwin@jason-gouger.com>).
2001-03-12 14:49:29 +00:00
Christopher Faylor e2f2a27ee8 * syscalls.cc (_rename): Set errno to ENOENT when an old path doesn't exist
(from Kazuhiro Fujieda <fujieda@jaist.ac.jp>).  Also set EACCES when directory
is not writable.
2001-03-10 20:25:19 +00:00
Christopher Faylor 6ebccdc110 * syscalls.cc (_read): Change definition to return ssize_t to be consistent
with read.
(_write): Change definition to return ssize_t to be consistent with write.
2001-03-07 20:52:33 +00:00
Christopher Faylor 95a8465ba0 * dlopen.c (dlopen): Return NULL when name is NULL (suggested by
chrisiasci@aol.com).
* cygwin.din: Add a new, internally used export - _check_for_executable.
* dcrt0.cc (dll_crt0_1): Set _check_for_executable for older binaries.  Pass
user_data to premain functions.
* fhandler.cc (fhandler_disk_file::open): Only check for executable if the
linked program is intereested in the executable bit.
(fhandler_disk_file::check_execable_p): Delete.
* fhandler.h (executable_states): New enumeration of various states of
executable bit caring.
(fhandler_base::set_execable_p): New method.
* fhandler_termios.cc (fhandler_termios::line_edit): Flag when a signal has
been sent to the tty.  Return -1 when this is so.
* fhandler_console.cc (fhandler_console::read): Return -1 when signal sending
character encountered.
* path.cc (path_conv::check): Record when path refers to a disk device.  Move
executable extension check here.
(check_sysfile): Accomodate new EXEC path states.
(has_suffix): Remove.
(next_suffix): Remove.
(class suffix_scan): New clas.
(suffix_scan::has): New method.
(suffix_scan:next): New method.
(symlink_info::check): Use suffix_scan method to control for scanning for
suffixes.
* path.h (path_conv::exec_state): New method.
* perprocess.h: Make "C" friendly.
* include/cygwin/version.h: Define CYGWIN_VERSION_CHECK_FOR_S_IEXEC.  Bump
CYGWIN_VERSION_API_MINOR.
* include/sys/cygwin.h: Change premain declarations.
* winsup.h: Move __cplusplus test to after builtin defines.
2001-03-05 06:28:25 +00:00
Christopher Faylor 0312ede431 *** empty log message *** 2001-03-03 03:56:34 +00:00
Corinna Vinschen c5a4eacc69 * cygerrno.h: Revert previous patch.
* errno.cc: Ditto.
        * dir.cc: Eliminate `dir_suffixes'.
        (opendir): Remove usage of `dir_suffixes'.
        (rmdir): Ditto.
        * fhandler.cc (fhandler_disk_file::open): Remove usage of
        `inner_suffixes'.
        * path.cc: Rename `inner_suffixes' to `lnk_suffixes'.
        (path_conv::check): Remove usage of `inner_suffixes'.
        (symlink): Ditto.
        (symlink_info::check): Handle checking for `.lnk' in path_conv
        exclusively here.
        (chdir): Remove usage of `dir_suffixes'.
        * shortcut.c: Eliminate debug_printf lines.
        (check_shortcut): Don't set error except on failing ReadFile.
        * spawn.cc: Remove ".lnk" from `std_suffixes'.
        * syscalls.cc (_unlink): Remove usage of `inner_suffixes'.
        Remove ".lnk" from `stat_suffixes'.
        (_rename): Add check for renaming a symlink to keep the ".lnk"
        suffix after renaming.
2001-02-22 14:51:16 +00:00
Corinna Vinschen 10b06c5ee0 * Makefile.in: Add `-lshell32 -luuid' to link pass for new-cygwin1.dll.
* autoload.cc: Add LoadDLLinitfunc for ole32.dll.
        Add LoadDLLfuncEx statements for CoInitialize@4, CoUninitialize@0
        and CoCreateInstance@20.
        * dir.cc (dir_suffixes): New datastructure.
        (readdir): Check for R/O *.lnk files to hide the suffix.
        (opendir): Use `dir_suffixes' in path conversion.
        (rmdir): Ditto.
        * fhandler.cc (fhandler_disk_file::fstat): Add S_IFLNK flag
        before calling `get_file_attribute'. Take FILE_ATTRIBUTE_READONLY
        into account only if the file is no symlink.
        * path.cc (inner_suffixes): New datastructure.
        (SYMLINKATTR): Eliminated.
        (path_conv::check): Use `inner_suffixes' on inner path components.
        (shortcut_header): New global static variable.
        (shortcut_initalized): Ditto.
        (create_shortcut_header): New function.
        (cmp_shortcut_header): Ditto.
        (symlink): Create symlinks by creating windows shortcuts. Preserve
        the old code.
        (symlink_info::check_shortcut): New method.
        (symlink_info::check_sysfile): Ditto.
        (symlink_info::check): Check for shortcuts. Move code reading
        old system attribute symlinks into symlink_info::check_sysfile().
        (chdir): Use `dir_suffixes' in path conversion.
        * security.cc (get_file_attribute): Check for S_IFLNK flag.
        Force 0777 permissions then.
        * spawn.cc (std_suffixes): Add ".lnk" suffix.
        * syscalls.cc (_unlink): Use `inner_suffixes' in path conversion.
        Check for shortcut symlinks to eliminate R/O attribute before
        calling DeleteFile().
        (stat_suffixes): Add ".lnk" suffix.
        (stat_worker): Force 0777 permissions if file is a symlink.
2001-02-21 21:49:37 +00:00
Egor Duda fc68bf34bb * signal.cc (signal): Prohibit setting handlers for SIGKILL and SIGSTOP
* signal.cc (sigaction): Ditto
* syscalls.cc (_lseek): Return EINVAL on invalid input
2001-02-16 18:49:20 +00:00
Christopher Faylor c41482c7ee * syscalls.cc (mknod): Add valid parameters. 2001-02-09 17:17:34 +00:00
Corinna Vinschen d7ed877ba3 * syscalls.cc (stat_worker): Add a check for the special case when
a process creates a file using mode 000 using ntsec.
2001-02-06 14:07:02 +00:00
Christopher Faylor 6a4878cf16 * syscalls.cc (_link): Make sure that newpath does not exist. Set errno if it
does.
* cygheap.cc (init_cheap): Don't specify a load address for the heap.  It
doesn't work on #!*& Windows 9x.
(cygheap_init): Move GetUserName to memory_init.
* dcrt0.cc (dll_crt0_1): Call new memory_init functin, eliminate call to
heap_init.
* heap.cc (heap_init): Improve error output.
* heap.h: Correct some declarations.
* shared.cc (mount_table_init): Remove.
(memory_init): Renamed from shared_init.  Reorganize to accomodate strange
Windows 9x problems with cygheap/heap interaction.
* shared_info.h: Rename shared_init to memory_init.
2001-01-29 00:46:25 +00:00
Christopher Faylor 2a6fc028ba Throughout, change 'cygwin_shared.mount' to 'mount_table'.
* child_info.h (child_info): Move shared_h, console_h to cygheap.  Add mount_h.
* cygheap.h (init_cygheap): Add shared_h, console_h.
* cygheap.cc (init_cheap): Initialize heap at a fixed location after the shared
memory regions.  Initialize cygheap->user name here.
* dcrt0.cc (dll_crt0_1): Call getpagesize () to initialize constants.  Remove
cygheap_init since it is done in shared_init now.
(_dll_crt0): Initialize mount_h, remove shared_h and console_h initialization.
* fhandler_console.cc (console_shared_h): Eliminate.
(get_tty_stuff): Use cygheap->console_h rather than console_shared_h.
* heap.cc (heap_init): Use page size constant calculated earlier in
initialization.
* shared.cc: Eliminate cygwin_shared_h.  Add cygwin_mount_h.
(mount_table_init): New function for initializing a user mount table.
(open_shared_file_map): Use constant for shared memory region.  Initialize
cygheap and mount table here.
(open_shared): Improve debugging output.
(shared_info::initialize): Eliminate call to mount.init.
(shared_terminate): Use cygheap->shared_h.  Close cygwin_mount_h.
(open_shared_file_map): Eliminate.
* shared_info.h (mount_info): Add a version field.
(shared_align_past): New macro for calculating location for shared memory
regions.
* sigproc.cc (init_child_info): Eliminate shared_h, console_h.
* spawn.cc (spawn_guts): Pass on cygwin_mount_h iff not a different user.
* syscalls.cc (system_info): New global holding system memory defaults.
(getpagesize): Use system_info.
* uinfo.cc (internal_getlogin): Only fill in user name if nonexistent.
* winsup.h: Declare system_info.
* passwd.cc (read_etc_passwd): Use cygheap->user.name () rather than retrieving
the name again.
2001-01-28 05:51:15 +00:00
Christopher Faylor c65a318355 * include/cygwin/version.h: Bump API to reflect setlogmask. 2001-01-22 20:29:24 +00:00
Christopher Faylor 4e2a97b2ac * syscalls.cc (setdtablesize): Call with amount to increment not total amount.
Return success or failure error code.
2001-01-18 04:26:04 +00:00
Christopher Faylor a7cde2b98a * autoload.cc (LoadDLLinitfunc): Remove debugging statement.
* exceptions.cc (sig_handle_tty_stop): Move setting of PID_STOPPED to earlier
in interrupt.
((interrupt_setup): i.e., here.
(sig_handle): Don't queue multiple SIGSTOPS.
* fhandler.h (bg_check_types): Enumerate return value of bg_check for clarity.
* signal.cc (kill_pgrp): Minor cleanup.
* fhandler_termios.cc (fhandler_termios::bg_check): Use enumerated type for
function return.  Don't raise signal if a signal is already queued.
* fhandler_console.cc (fhandler_console::read): Use enumerated return type for
bg_check.
* select.cc: Ditto, throughout.
* read.cc: Ditto, throughout.
* termios.cc: Ditto, throughout.
(_read): YA interrupt detect simplification.
* wait.cc (wait4): Ditto.
2001-01-17 14:57:09 +00:00
Corinna Vinschen 66097f06dd * heap.cc (heap_init): Fix extern declaration of getpagesize.
* syscalls.cc (getpagesize): Fix another typo.
2001-01-15 12:53:30 +00:00
Corinna Vinschen dc3651b6cd * syscalls.cc (getpagesize): Save pagesize in global variable to
avoid calling GetSystemInfo too often.
        * heap.cc (getpagesize): Eliminate.
        (heap_init): Use getpagesize function from syscalls.cc.
2001-01-15 12:25:00 +00:00
Christopher Faylor a3ec080b35 * syscalls.cc (_read): Use more lightweight method for determining if read has
been interrupted by a signal.
2001-01-14 19:08:30 +00:00
Christopher Faylor c3d62298ba * debug.h: Add regparm attributes to some functions.
* signal.cc (sigaction): Don't treat SIGCONT specially.
* exceptions.cc (interrupt_setup): Save sa_flags of interrupted signal for
later use.
(sig_handler): Default any stopping signal to SIGSTOP.
(call_signal_handler): New function.
(sigdelayed0): New function.
* sigproc.cc (sigproc_init): Initialize SIGSTOP sigaction for special behavior.
* sigproc.h: Define call_signal_handler.
* syscalls.cc (_read): Allow restartable signal behavior.
2001-01-12 05:38:25 +00:00
Corinna Vinschen 3112d7a41c * syscalls.cc (remove): New function, overriding the newlib
implementation.
2000-12-19 20:43:41 +00:00
Corinna Vinschen 5827f4d98a * environ.cc (struct parse_thing): Add entry for new CYGWIN option
`smbntsec'.
        * path.cc (path_conv::check): Check path for being a remote path.
        If so and `allow_smbntsec' is set to FALSE, set has_acls to FALSE.
        * security.cc: Add global definition for `allow_smbntsec'.
        * security.h: Add extern declaration for `allow_smbntsec'.
        * fhandler.cc (fhandler_disk_file::open): Eliminate extern declaration
        of `allow_ntsec'.
        * syscalls.cc: Ditto.
2000-12-19 19:52:57 +00:00
Corinna Vinschen cb6f4dbd0c * uinfo.cc (internal_getlogin): Change parameter list to reflect
that `token' is member of cygheap_user now.
        (uinfo_init): Use modified internal_getlogin.
        * syscalls.cc (seteuid): Ditto.
2000-11-15 21:14:27 +00:00
Corinna Vinschen 66c161baac * cygheap.h: Move `token' and `impersonated' from class _pinfo
to class cygheap_user.
        * pinfo.h: Ditto.
        * fork.cc (fork_child): Change usage of `token' and `impersonated'
        accordingly.
        (fork_parent): Ditto.
        * security.cc (cygwin_set_impersonation_token): Ditto.
        * sigproc.cc (proc_subproc): Ditto.
        * spawn.cc (spawn_guts): Ditto.
        * syscalls.cc (seteuid): Ditto.
        * uinfo.cc (uinfo_init): Ditto.
2000-11-15 21:04:02 +00:00
Corinna Vinschen 1f0f8e127c * cygheap.cc (cygheap_root::cygheap_root): New function.
(cygheap_root::~cygheap_root): Ditto.
        (cygheap_root::operator=): Ditto.
        (cygheap_user::~cygheap_user): Ditto.
        (cygheap_user::set_name): Ditto.
        (cygheap_user::set_logsrv): Ditto.
        (cygheap_user::set_domain): Ditto.
        (cygheap_user::set_sid): Ditto.
        * cygheap.h (cygheap_root): New class.
        (cygheap_user): Ditto.
        (init_cygheap): Change type of `root' member to cygheap_root.
        Add `user' member.
        * dir.cc (opendir): Use new `cygheap_root' class.
        * dcrt0.cc (dll_crt0_1): Use new `cygheap_user' class.
        * fork.cc (fork_parent): Ditto.
        * grp.cc (getgroups): Ditto.
        * passwd.cc (search_for): Ditto.
        * path.cc: Use new `cygheap_root' class throughout.
        * pinfo.h (_pinfo): Remove `use_psid'. Move `username', `psid',
        `logsrv', `domain', `orig_{uid,gid}' and `real_{uid,gid}' to
        cygheap_user class.
        * security.cc: Use new `cygheap_user' class throughout.
        * shared.cc (sec_user): Ditto.
        * sigproc.cc (proc_subproc): Remove copy statements for user
        related information moved to `cygheap_user' class.
        * spawn.cc (spawn_guts): Invalidate current chroot settings
        when creating Windows environment. Use new `cygheap_user' class.
        * syscalls.cc: Use new `cygheap_user' class throughout.
        * uinfo.cc: Ditto.
        * uinfo.cc (internal_getlogin): Change parameters to reflect the
        move of user information to cygheap.
2000-11-15 00:13:09 +00:00
Christopher Faylor a4785603b8 * cygheap.h (init_cygheap): New struct holding values that live in the Cygwin
heap.
* child_info.h (child_info): Change pointer type of cygheap to init_cygheap.
* cygheap.cc (init_cheap): Point cygheap_max after contents of cygheap.  Move
some stuff into cygheap.h.
* dir.cc (opendir): Change to use root and rootlen in cygheap rather than in
myself.
(mkdir): Change to use umask in cygheap rather than in myself.
* path.cc: Ditto, throughout.
* syscalls.cc (_open): Ditto.  Change to use umask in cygheap rather than in
myself.
(chroot): Change to allocate root dir on the cygwin heap.
(umask): Change to use umask in cygheap rather than in myself.
(cygwin_bind): Ditto.
* sigproc.cc (proc_subproc): Don't copy umask or root stuff as this happens
automatically now.
* pinfo.h (_pinfo): Migrate stuff out of here and into init_cheap.
* dcrt0.cc (dll_crt0_1): Call cygheap_init later in startup for first cygwin
process.
2000-11-14 05:53:32 +00:00
Christopher Faylor bb5d559a73 * pinfo.cc (pinfo::init): Reverse order of setting status and pid info in an
execed process to avoid a race.
* sigproc.cc (wait_subproc): Print more info when a WFSO error occurs.
* automode.c: New file.
* syscalls.cc (close_all_files): Streamline slightly.
* cygheap.cc (ccalloc): Clear *entire* allocated array.
2000-11-03 04:27:03 +00:00
Christopher Faylor f8f9b12e6c * dcrt0.cc (do_exit): Don't bother looking for pgrp children to send SIGHUP if
process has never created any children.
* fork.cc (fork): Set flag indicating that there is another process with our
process group.
* spawn.cc (spawn_guts): Ditto.
* pinfo.h (set_has_pgid_children): New methods for setting when process has
children in its process group.
* syscalls.cc (setpgid): Clear has_gid_children if pgid changes.
2000-10-25 03:54:50 +00:00
Corinna Vinschen 90bb77ddcb * fhandler.cc (fhandler_base::fcntl): Behave properly when passed
previous version of O_NDELAY.
        * syscalls.cc: Move OLD_O_NDELAY to winsup.h.
        * winsup.h: Define OLD_O_NDELAY now.
2000-10-24 18:15:25 +00:00
Christopher Faylor ac944e37d0 * exceptions.cc (call_handler): Make signal pending if sigsave.sig is still
active.
* syscalls.cc (_read): Don't clear errno.
* sigproc.cc (wait_sig): Don't scan the waiting process list after a SIGCHLD if
there are no zombies to reap.
* winsup.h: Use __builtin_strcmp.
* environ.cc (posify): Don't initialize len unless it is required
(from DJ Delorie <dj@redhat.com>).
2000-10-18 04:53:37 +00:00
Christopher Faylor 3f7bd53115 * sigproc.cc (proc_subproc): Remove unneeded test for correct process in
PROC_ADDCHILD.  Return 0 when terminated child has just been reparented.
(wait_subproc): Only send SIGCHLD when proc_subproc returns != 0.
* strace.cc (strace::vsprntf): Only strip .exe extension from program name.
2000-10-17 18:55:58 +00:00
Christopher Faylor 166b2571ce * Makefile.in: Remove some obsolete stuff.
* dcrt0.cc (dll_crt0_1): Call signal_fixup_after_exec where appropriate.  Set
myself->uid from parent version.  Just use ThreadItem Init method.  Close or
store hexec_proc as appropriate.
(_dll_crt0): Store user_data->forkee here so that proper tests can be made
subsequently.
(do_exit): Remove hExeced stuff.
* environ.cc (environ_init): Accept environ count as well as environ pointer.
* environ.h: Reflect above change.
* pinfo.cc (pinfo_init): Ditto.  Accept environ count.
(fixup_in_spawned_child): Remove.
* spawn.cc (spawn_guts): Move signal code to dll_crt0_1.  Don't suspend execing
process since it is no longer necessary.  Store envc.
* exceptions.cc (signal_fixup_after_exec): New function.
(call_handler): Remove hExeced test.
* child_info.h (cygheap_exec_info): Store envc as well as envp.
(child_info_spawn): Store hexec_proc so that it can be closed in child.
* path.cc (normalize_posix_path): Avoid intermediate use of temporary cwd buf.
(normalize_win32_path): Ditto.
(cwdstuff::get_initial): Always set lock.
* sigproc.h: Remove hExeced.
* strace.cc (strace::vsprntf): Modify to accomodate for lack of hExeced.
* thread.cc (MTinterface::Init): Merge Init1 and ClearReent into this method.
(MTinterface::Init1): Eliminate.
(MTinterface::ClearReent): Eliminate.
* thread.h: Reflect above changes.
* include/sys/strace.h (strace): Make microseconds() public.  Make various
functions 'regparm', throughout.
* pinfo.h (_pinfo): Inline simple signal manipulation functions.  Requires
inclusion of thread.h which was removed from .cc files, where appropriate.
throughout.
* pinfo.cc: Eliminate signal manipulation functions.
(_pinfo::exit): Calculate total rusage for exiting process here.
* cygheap.cc (size2bucket): Eliminate.
(init_buckets): Ditto.
(_cmalloc): Calculate size and bits in a loop rather than going through a
function call.
(_crealloc): Use stored array index to calculate allocated size.
* spawn.cc (spawn_guts): Use _pinfo exit method to exit, calculating cpu usage.
2000-10-16 23:55:58 +00:00
Christopher Faylor 1dc16fc74b * exceptions.cc (set_console_handler): Don't allocate
console_handler_thread_waiter.  It is obsolete.
(ctrl_c_handler): Don't use console_handler_thread_waiter.
* path.cc (hash_path_name): Fix handling of relative names.  Make case
insensitive.
* path.h (suffix_info): Use initializers.
* pinfo.h (_pinfo): Avoid initializers for null case.
* resource.cc (fill_rusage): Zero rest of rusage structure.
* security.cc (set_process_privileges): Don't reopen parent process.  Just use
hMainProc.
* signal.cc (signal): Track when a signal handler has been used.
(sigaction): Ditto.
* sigproc.cc (pchildren): Use default initializer.
(zombies): Ditto.
(sigproc_terminate): Avoid closing handles that will be closed on exit anyway.
(wait_sig): Send signal to "parent" on EXECing, not FORKing.
(wait_subproc): Send SIGCHLD here rather than in proc_wait to avoid potential
muto conflicts.
* sigproc.h (sigthread): Don't initialize to zero.  It's the default.
* spawn.cc (spawn_guts): Fill in resources from exec parent prior to
termination.
* sync.h (muto): Don't initialize to zero.
* syscalls.cc (close_all_files): Use one lock around entire loop and call
fhandler close/release stuff directly.
(_read): Don't use ready_for_read if there are not signal handlers active.
* dcrt0.cc (dll_crt0_1): Fix display of "title".
(do_exit): Use pinfo exit method to exit.
(__api_fatal): Ditto.
* exceptions.cc (signal_exit): Ditto.
* fork.cc (fork_child): Remove debugging stuff.  Use pinfo_fixup_after fork in
place of exec_fixup_after_fork.
* pinfo.cc (pinfo_fixup_after_fork): New method.
(pinfo_fixup_in_spawned_child): Ditto.
(_pinfo::exit): New method.
(_pinfo::init): Remove recursion.  Detect pathological case where pinfo
structure already exists for new pid.
* pinfo.h (_pinfo): Reorganize slightly.  Add new method and new function
declarations.
* sigproc.cc (proc_exists): Previous simplification was a little to simple.
Try harder to detect if a process exists.
(proc_terminate): Use PID_EXITED setting to determine if process is still
around.
(WFSO): Remove debugging statement.
(WFMO): Ditto.
* spawn.cc (exec_fixup_after_fork): Eliminate.
(spawn_guts): Always set old_title to NULL.  Is it really needed?  Move
hexec_proc to pinfo.cc.  Call pinfo_fixup_in_spawned_child to eliminate handle
link after a spawn.
* include/sys/cygwin.h: Remove PID_NOT_IN_USE.  Add PID_EXITED.
2000-10-15 01:37:07 +00:00
Christopher Faylor ec300c9979 * errno.cc (seterrno_from_win_error): Fix debugging output.
* fhandler.cc (fhandler_base::fstat): Move to inline method in fhandler.h.
(fhandler_base::set_io_handle): Ditto.
* fhandler.h (fhandler_base): Make some methods inline.
* fhandler_console.cc (fhandler_console::write_normal): Make buffer larger.
* sigproc.h (sigframe::sigframe): Actually use set ebp parameter correctly.
* spawn.cc (spawn_guts): Set dwProcessId when exec'ing.  Just exit immediately
after reparenting.
* syscalls.cc: Sprinkle sigframe stuff throughout.
* wait.cc (wait4): Set signal frame here.
* dcrt0.cc (__api_fatal): Don't rely on small_printf to display errors.  Always
display problems to the console, if possible.
2000-10-12 04:38:29 +00:00
Christopher Faylor 7aadaf0f7e * syscalls.cc (_read): Behave properly when passed previous version of
O_NDELAY.  Fix up debugging output.
2000-10-07 03:25:38 +00:00
Christopher Faylor 90fe77395a * path.cc (symlink_info::check): Set executable bit for a file if the first two
characters are 'MZ' to mirror spawn_guts check.
2000-09-30 01:56:40 +00:00
Christopher Faylor fb5956da13 * spawn.cc (av::dup_maybe): Make function void rather than void *.
* environ.cc (environ_init): Remember to reparse CYGWIN if envp is
supplied.
* heap.cc (_sbrk): Remember frame for signal handling.
* syscalls.cc (read_handler): Eliminate.
(_read): Move read_handler code here.  Reorganize for one path through
'ready_for_read'.
2000-09-25 16:36:12 +00:00
Christopher Faylor f0338f545d Break out more header info into separate files. Use appropriate header files
throughout.
* shared.h: Remove.
* cygwin_version.h: New file.
* delqueue.h: New file.
* environ.h: New file.
* host_dependent.h: New file.
* perprocess.h: New file.
* registry.h: New file.
* security.h: New file.
2000-09-08 02:56:55 +00:00
Christopher Faylor 29ac7f89e3 Split out tty and shared_info stuff into their own headers and use throughout.
Include sys/termios.h for files which need it.
* tty.h: New file.
* shared_info.h: New file.
* fhandler.h: Move inline methods that rely on tty stuff to
fhandler_console.cc.
* fhandler_tty.cc (fhandler_pty_master::process_slave_output): Set
output_done_event immediately after reading data to speed up tty output
processing.
(process_output): Set write_error to errno or zero.
(fhandler_tty_slave::write): Check previous write error prior to writing to
slave end of pipe.  This allows tty output to be slightly less synchronous.
* fhandler_console.cc (fhandler_console::tcsetpgrp): Moved here from
fhandler.h.
(fhandler_console::set_input_state): Ditto.
2000-09-07 16:23:51 +00:00
Christopher Faylor f76325499a * path.cc (readlink): Check if buffer length is positive. Truncate output to
buffer length.  Don't terminate buffer with '\0'.
2000-09-04 17:52:42 +00:00
Christopher Faylor b0e82b74fb * Makefile.in: Add cygheap.o.
* child_info.h: Add specific exec class.
* cygheap.h: New file.  Contains declarations for cygwin heap.
* cygheap.cc: New file.  Implements cygwin heap functions.
* dcrt0.cc (quoted): Simplify due to new method for passing arguments between
cygwin programs.
(alloc_stack_hard_way): Attempt to handle overlapped stack.
(dll_crt0_1): Move child_info processing here.  Accomodate new method for
passing arguments between cygwin programs.  Initialize cygwin heap.  Establish
__argc and __argv variables.
(_dll_crt0): Move most of child_info processing to dll_crt0_1.
(cygwin_dll_init): Remove duplication.
* dtable.cc (dtable::extend): Allocate dtable using cygwin heap.
(dtable::build_fhandler): Ditto for fhandler type being constructed.
(dtable::dup_worker): Free new fhandler from cygwin heap on error.
(dtable::select_*): Don't assume that this == fdtab.
(dtable::linearize_fd_array): Delete.
(dtable::delinearize_fd_array): Delete.
(dtable::fixup_after_exec): New file.
(dtable::vfork_child_dup): Use cygwin heap.
(dtable::vfork_parent_restore): Ditto.
* dtable.h: Remove obsolete methods.  Add new method.
* environ.cc (posify): Eliminate already_posix parameter and logic.
(envsize): New function.
(_addenv): Use envsize.
(environ_init): Accept an argument pointing to an existing environment list.
If supplied, allocate space for this in the the program's heap.
* fhandler.cc (fhandler_base::operator =): Move here from fhandler.h.  Use
cygwin heap to allocate filenames.
(fhandler_base::set_name): Allocate/free names from cygwin heap.
(fhandler_base::linearize): Delete.
(fhandler_base::de_linearize): Delete.
(fhandler_base::operator delete): Free from cygwin heap.
(fhandler_base::~fhandler_base): Ditto.
* fhandler.h: Accomodate elimination of *linearize and other changes above.
* fhandler_console.cc (fhandler_console::fixup_after_exec): Rename from
de_linearize.
* heap.h: New file.
* fhandler_tty.cc (fhandler_tty_slave::fhandler_tty_slave): Use cygwin heap for
name.  fhandler_tty::fixup_after_exec): Rename from de_linearize.
* fork.cc (fork): Call cygheap_fixup_in_child.
* heap.cc: Use declarations in heap.h.
* malloc.cc: Sprinkle assertions throughout to catch attempts to free/realloc
something from the cygwin heap.
* path.cc: Throughout, eliminate use of per-thread cache for cwd.  Use cwd_*
functions rather than cwd_* variables to access cwd_win32 and cwd_posix.
(cwd_win32): New function.
(cwd_posix): New function.
(cwd_hash): New function.
(cwd_fixup_after_exec): New function.
* path.h: Accomodate path.cc changes.
* pinfo.cc (pinfo_init): Accept a pointer to an environment table.  Pass this
to environ_init.  Eliminate old 'title' tests.
* pinfo.h: Accomodate above change in argument.
* spawn.cc (struct av): New method for building argv list.
(av::unshift): New method.
(spawn_guts): Allocate everything that the child process needs in the cygwin
heap and pass a pointer to this to the child.  Build argv list using new
method.  Eliminate delinearize stuff.
* thread.h: Eliminate _cwd_win32 and _cwd_posix buffers.
* winsup.h: Eliminate obsolete functions.  Add envsize() declaration.
2000-09-03 04:16:35 +00:00
Christopher Faylor bccd5e0d85 * winsup.h: Eliminate inclusion of most of the cygwin .h files. Use .h files
only in sources which require them.
* Makefile.in: Generate dependencies with -MD option.
2000-08-22 05:10:20 +00:00
Christopher Faylor 9e2baf8dfa * cygerrno.h: New file. Use this throughout whenever errno manipulation is
required.
* errno.cc: Use DWORD to hold Windows errors.
(geterrno_from_win_error): New function.
(seterrno_from_win_error): Use geterrno_from_win_error to convert supplied
windows error (suggested by Corinna Vinschen).
* path.cc (symlink_info): Add error element.
* path.cc (path_conv::check): Remove errno setting.  Use new symlink_info errno
element to set path_conv error, where appropriate.
(symlink_info::check): Set error element rather than attempting to manipulate
errno.  Add more checks for trailing / and /..  even though they are currently
useless.  Avoid setting EINVAL.
* path.cc (normalize_posix_path): Correct check for trailing /.
2000-08-22 03:58:47 +00:00
Christopher Faylor e2ebe11776 * winsup.h: Split out dtable definitions into separate header file.
* dtable.h: New file.
* sigproc.h: Eliminate pinfo.h usage here.  Use it in source files that need
it.
2000-08-12 05:35:42 +00:00
Christopher Faylor 9015e0fb8c Rename hinfo -> dtable. Name the former dtable array 'fdtab'. 2000-08-12 04:48:44 +00:00
Christopher Faylor 0072fdab86 * select.cc (allocfd_set): Zero allocated fd_set.
(cygwin_select): Move fd_set copying logic from ::wait to here.  Use common
return through sell.poll.
(select_stuff::wait): Just return success or failure and let caller fill in
fd_set.
* pinfo.h (pinfo): Eliminate self-referential pointer to sidbuf since pinfo
structure exists at random locations now.
* fork.cc (fork): Use 'use_psid' element to control when the psid is relevant.
* shared.cc (sec_user): Ditto.
* spawn.cc (spawn_guts): Ditto.
* uinfo.cc (internal_getlogin): Ditto.
* syscall.cc (seteuid): Ditto.  Set use_psid element.
2000-08-09 02:33:47 +00:00
Christopher Faylor 91892f50d9 * hinfo.cc (hinfo::find_unused_handle): Just check for table entry == NULL
since we are already bounds checked by default.
* thread.cc (ResourceLocks::Lock): Streamline this function since it is called
a lot.
(ReleaseResourceLock): Ditto.
2000-08-04 04:04:46 +00:00
DJ Delorie 4c8d72ded5 * winsup.h: take out protections of environ, errno, allow C use
* *.cc: put winsup.h before other headers (for __INSIDE_CYGWIN__);
use cur_environ() instead of just environ
* times.cc: remove import protections
* glob.c: add winsup.h
* localtime.c: ditto
* smallprint.c: ditto
* Makefile.in: don't __INSIDE_CYGWIN__ as it messes up profiling.
2000-08-02 16:28:18 +00:00
Christopher Faylor 84c7d40932 * include/cygwin/version.h: Bump DLL minor version number to 5 due to all of
the changes below.  Redefine process structure to avoid a fixed size table.
Redefine pinfo/_pinfo classes.  Use these throughout.
* dcrt0.cc (dll_crt0_1): Accomodate set_myself argument change.
(__api_fatal): Accomodate _pinfo::record_death argument change.
* exceptions.cc (really_exit): Ditto.
(sig_handle_tty_stop): Use pinfo constructor to access process info.
(events_init): Don't create pinfo_mutex since it is no longer required.
* external.cc (fillout_pinfo): Use winpids class to iterate over all system
pids.
(cygwin_internal): lock_pinfo_for_update and unlock_pinfo are now noops.
* fhandler_termios.cc (fhandler_termios::set_ctty): Use pinfo constructor to
access process info.
* fork.cc (fork): Reorganize to initialize child info after the child has
started since that is when we know the child's winpid, which is necessary to
allocate the pinfo shared memory.
* mmap.cc (recreate_mmaps_after_fork): Change arg type to _pinfo.
* pinfo.cc: Rename pinfo methods to _pinfo throughout.  Eliminate pinfo_list
stuff.
(set_myself): Accept a pid argument now.  Call pinfo initializer to initialize
myself.  Detect when this is an "execed" process and create an "indirect" pid
block.
(pinfo_init): Accomodate set_myself arg change.
(procinfo): Remove.
(pinfo::lock_pinfo): Remove.
(pinfo::unlock_pinfo): Remove.
(pinfo::init): New method.  Allocates shared memory space for process pinfo
structure.
(pinfo::record_death): Don't call locking functions.
(cygwin_winpid_to_pid): Simplify by using new pinfo constructor.
(EnumProcessesW95): New function for iterating over processes on Windows 95.
(winpids::winpids): New constructor for winpids class.  Sets up a list of
process ids.
(enum_init): Initialize w95/wnt pid enumerators.
* shared.cc (shared-info::initialize): Remove pid initialization.
* shared.h: Move pinfo stuff into pinfo.h.
(class shared_info): Remove pinfo_list element.
* signal.cc (kill_worker): Use pinfo constructor to access process info.
(kill_pgrp): Ditto.  Use winpids methods to access list of processes.
* sigproc.cc: Throughout, modify to use _pinfo where appropriate.
(proc_exists (pid_t)): New function.  Determines if a process exists based on
the pid.
(proc_exists (_pinfo *p): Use new proc_exists function above.
(proc_subproc): Copy pinfo stuff around rather than _pinfo pointers.  Try to be
careful about releasing shared memory when we don't need it anymore.  Remove
pinfo locks.
(remove_zombies): Remove pinfo memory when zombie is going away.
* sigproc.h: Reflect _pinfo/pinfo changes in sigproc.cc.
* spawn.cc (spawn_guts): Eliminate pinfo *child argument.  Reorganize to only
initialize child pinfo after process has been started and we know the windows
pid.
(_spawnve): Reflect spawn_guts changes.
* syscalls.cc (setpgid): Use pinfo constructor to access process info.
(getpgid): Ditto.
(internal_getlogin): Use _pinfo.
* winsup.h: Eliminate pinfo_mutex.  Eliminate spawn_guts declaration since it
is static now.  Reflect set_myself argument change.
* include/sys/cygwin.h: Add some PID_* enums to accomodate new pinfo stuff.
* include/cygwin/version.h: Update minor version for cygdrive changes below.
2000-07-29 16:24:59 +00:00
DJ Delorie d0b178fe3a * testsuite/winsup.api/winsup.exp: ignore stdout by default
* testsuite/winsup.api/crlf.c: non-verbose by default

* winsup.h: prune out windows headers we don't normally need
* assert.cc: add wingdi.h and winuser.h
* fhandler_console.cc: ditto
* fhandler_windows.cc: ditto
* select.cc: ditto
* spawn.cc: ditto
* strace.cc: ditto
* tty.cc: ditto
* window.cc: ditto
* hinfo.cc: add winsock.h
* syscalls.cc: add winnls.h
* uinfo.cc: ditto

* include/windows.h: optimize non-inclusion of repeat headers
2000-07-27 17:30:51 +00:00
Christopher Faylor f489e86b8f * syscalls.cc (stat_worker): Make stat return correct st_blocks for files with
size bigger than 2Gb and less than 4Gb
2000-07-26 17:48:49 +00:00
Christopher Faylor 00edcbb0cb * syscalls.cc (statfs): Use path_conv method to convert input path. 2000-07-26 01:56:48 +00:00
Christopher Faylor 2a1a9785eb * syscalls.cc (_link): Avoid extraneous call to cygwin_conv_to_win32_path. 2000-07-26 01:44:16 +00:00
Corinna Vinschen 8b6ebe8fd5 * syscalls.cc (_link): Corrected previous patch. 2000-07-24 19:14:38 +00:00
Corinna Vinschen 9fb628fc57 Patch suggested by Kazuhiro Fujieda <fujieda@jaist.ac.jp>.
* winsup.h: Add new macros sys_wcstombs and sys_mbstowcs.
        * syscalls.cc (_link): Replace calls to mbstowcs by call to
        sys_mbstowcs.
        * uinfo.cc (internal_getlogin): Replace calls to wcstombs and
        mbstowcs by calls to sys_wcstombs and sys_mbstowcs. Replace
        usage of constants by meaningful defines. Use result of
        GetSystemDirectory for HOMEPATH and HOMEDRIVE as a last resort.
2000-07-22 16:43:54 +00:00
Corinna Vinschen a67f4165ae * shared.h (class pinfo): New members `root' and `rootlen'.
* syscalls.cc (chroot): Set new root for process.
        * path.cc (getcwd_inner): Add parameter to force use of
        new root from chroot() call.
        (ischrootpath): New macro.
        (normalize_posix_path): Care for changed root dir.
        (normalize_win32_path): Ditto.
        (getcwd_inner): Ditto.
        (chdir): Eliminate trailing path component consisting
        entirely of dots.
        * fork.cc (fork): Copy pinfo members regarding chroot().
        * spawn.cc (_spawnve): Ditto.
        * dir.cc (opendir): Don't use computed win32 path if
        chroot() took place.
2000-07-19 20:14:24 +00:00
Christopher Faylor 5bc584ba65 Throughout, eliminate third argument to path_conv and use new PC_* constants
for second argument.
* path.h: Generalize SYMLINK_* constants to PC_*.
(path_conv): Create a new method.  Fold third argument into second.
* dll_init.cc (dll_list::alloc): Try harder to find space to allocate dll
struct.
(dll_dllcrt0): Don't check sanity if we've already called dll_crt0.
* path.cc (path_conv::check): Don't check for a null or empty path unless
specifically told with a flag setting.
(check_null_empty_path): New function, adapted from macro.
* syscalls.cc (_rename): Use already-determined file attributes rather than
checking again.
* lib/cygwin/cygwin_attach.dll.c (cygwin_attach_dll): Use a static per_process
structure since this is apparently supposed to be zeroed.
* lib/cygwin_crt0.c (cygwin_crt0): Zero per_process structure sent to older
DLLs.
2000-07-17 19:18:21 +00:00
Corinna Vinschen d501c6adee * spawn.cc (spawn_guts): Close handle `hToken' only if it's not
copied from myself->token.
        * syscalls.cc (seteuid): Replace CopySid by memcpy which is foolproof
        here.
2000-07-09 21:02:44 +00:00
Christopher Faylor bd4ec49671 * cygwin.din: Export _getmode and getmode to allow querying of binary state of
an fd.
* external.cc (cygwin_internal): Add handling of perfile_table setting.
* fhandler.cc (perfile_table): New global.
(fhandler_base::get_default_fmode): New method to return a file's default mode
based on its name.
(fhandler_base::open): Use get_default_mode method to determine a file's mode.
Record file mode in file flags.
* fhandler.h (fhandler_base): Declare get_default_fmode
* syscalls.cc (getmode): New function.
* sys/cygwin.h (__cygwin_perfile): New structure.
(cygwin_getinfo_types): Move outside of WINVER conditional.
(per_process): Move inside of WINVER conditional.
2000-07-09 05:29:51 +00:00
Christopher Faylor 610739191f * dcrt0.cc (dll_crt0_1): Eliminate SetFileApisToOEM and CharToOem.
* (dummy_autoload): Add functions used in fhandler_console.
* fhandler_console.cc (fhandler_console::read): Use ENCHANCED_KEY flag to
distinguish extended keys.  Translate an input character from the OEM code page
to the ANSI code page.
* (fhandler_console::write_normal): Translate output characters from the ANSI
code page to the OEM code page.
* syscalls.cc (_link): Use MultiByteToWideChar instead of OemToCharW.
2000-07-04 02:26:20 +00:00
Corinna Vinschen 0c4d2abd99 * winsup.h: Define MAX_SID_LEN and new MAX_HOST_NAME.
* fork.cc (fork): Use above defines instead of numerical constants.
        * shared.cc (sec_user): Ditto.
        * shared.h (class pinfo): Ditto.
        * syscall.cc (seteuid): Ditto.
        * spawn.cc (_spawnve): Ditto. Eliminate conditional.
        (spawn_guts): Set child->uid = USHRT_MAX when user context will be
        changed in child process.
        * uinfo.cc (uinfo_init): Check for myself->uid instead of myself->psid
        to avoid reloading of /etc/passwd on process startup if ntsec is off.
        Use above defines instead of numerical constants.
        * security.cc: Move define for MAX_SID_LEN to winsup.h.
2000-07-02 10:17:44 +00:00
Corinna Vinschen b3cc0634b9 * syscalls.cc (seteuid): Initialize pi.token before calling
internal_getlogin().
        * uinfo.cc (internal_getlogin): Use impersonation token instead
        of process token in case of active impersonation. Add some comments.
        (uinfo_init): Initializing myself->token and myself->impersonated
        before calling internal_getlogin(). Add some comments.
2000-06-28 17:42:28 +00:00
Corinna Vinschen 64b3062937 * cygwin.din: Define symbols for `cygwin_logon_user' and
`cygwin_set_impersonation_token'.
        * dcrt0.cc (dll_crt0_1): Eliminate superfluous conditional
        statements.
        Add load statements for `ImpersonateLoggedOnUser', `LogonUserA'
        and `RevertToSelf'.
        * fork.cc (fork): Care for correct impersonation of parent
        and child process.
        * security.cc (cygwin_set_impersonation_token): New function.
        (cygwin_logon_user): Ditto.
        shared.h (class pinfo): New members `orig_uid', `orig_gid',
        `real_uid' nad `real_gid'.
        spawn.cc (spawn_guts): Care for impersonation when starting
        child process in a different user context.
        * syscalls.cc (setgid): Call `setegid' now. Set real_gid.
        (setuid): Call `seteuid' now. Set real_uid.
        (seteuid): Functionality moved from setuid to here. Care for
        correct impersonation.
        (setegid): Functionality moved from setgid to here.
        * uinfo.cc (uinfo_init): Initialization of additional pinfo
        members.
        (getuid): Return real uid.
        (getgid): Return real gid.
        (geteuid): Return effective uid.
        (getegid): Return effective gid.
        include/sys/cygwin.h: Add prototypes for `cygwin_logon_user' and
        `cygwin_set_impersonation_token'.
        include/cygwin/version.h: Bumb API minor version to 22.
2000-06-16 19:36:07 +00:00
Corinna Vinschen 154110f5d3 * dir.cc (writable_directory): Comment out previous code,
return always 1 for now.
        (mkdir): Call set_file_attribute explicitely with S_IFDIR mode bit.
        * syscalls.cc (chown_worker): Ditto.
        (chmod): Ditto.
        * security.cc (get_nt_attribute): Fix error in debug output.
        Never set FILE_DELETE_CHILD for files.
        Construct appropriate inherit attribute according to file type.
2000-05-24 20:09:43 +00:00
DJ Delorie 56cd25ee02 * syscalls.cc (_cygwin_istext_for_stdio): New, for newlib
* include/cygwin/version.h: Bump API number for detect old
programs using old getc/putc macros
2000-05-23 23:52:50 +00:00
Corinna Vinschen 6892216822 * dir.cc (rmdir): Care for misleading error messages
when trying to remove a directory on a samba share.
        Eliminate superfluous else branch.
        * syscalls.cc (_rename): Additional check for ERROR_FILE_EXISTS
        if MoveFile fails.
2000-05-22 17:15:47 +00:00
DJ Delorie ed8387fb4f * syscalls.cc (setmode): change mode of any matching FILE* also. 2000-05-19 17:15:02 +00:00
Christopher Faylor 6201d15e3c * path.cc (mount_info::cygdrive_posix_path): Don't add trailing slash if
referring to something like c:\.
* dcrt0.cc (dll_crt0_1): Move uinfo initialization prior to sig_send
initialization to give signal thread a chance to finish.
* debug.cc (WFSO): Move to sigproc.cc
(WFMO): Ditto.
* exceptions.cc (interruptible): Allocate slightly more space for directory
just for paranoia's sake.
(call_handler): Eliminate nonmain argument.  Determine if main thread has set a
frame pointer and use it if so.
(sig_handle): Eliminate nonmain argument.
* net.cc: Record frame information in appropriate routines throughout.
* select.cc (select): Ditto.
* sigproc.cc: Use sigthread structure to record mainthread id throughout.
(sig_send): Record frame information for signal handler.
(wait_sig): Reflect argument change in sig_handle.
(WFSO): Move here and record frame information for signal handler.
(WFMO): Ditto.
* sigproc.h: Implement new "sigthread" class.  Implement "sigframe" class for
manipulating signal frame info.
* thread.cc (__pthread_kill): Use standard _kill() function rather than calling
sig_send directly.
* winsup.h: Eliminate ebp element from signal_dispatch class.
2000-05-17 05:49:51 +00:00
Mumit Khan 60c83af2ad 2000-05-06 Mumit Khan <khan@xraylith.wisc.edu>
* include/wchar.h (wcscmp, wcslen): Fix prototypes.
	* syscalls.cc (wcslen, wcscmp): Adjust.
2000-05-06 17:00:53 +00:00
Christopher Faylor 8e9b0aee25 * configure.in: Use -gstabs+ as compile debug option. This seems to promote
better handling of symbols.
* configure: Regenerate.
* delqueue.cc (delqueue_list::process_queue): Allow ERROR_ACCESS_DENIED to
indicate that a file is being shared under Windows 95.
* syscalls.cc (_unlink): Use full path name.  Take special action for Windows
95.  Assume that an ERROR_ACCESS_DENIED indicates a sharing violation unless
it's on a remote drive.  Punt if there is an ERROR_ACCESS_DENIED on a remote
drive.
2000-05-04 19:46:32 +00:00
Corinna Vinschen 07a135a6bf * errno.cc (errmap): Map ERROR_BAD_NETPATH to new errno ENOSHARE.
(_sys_errlist): Add entry for ENOSHARE.
        (strerror): Add case for ENOSHARE.
        * syscalls.cc (stat_worker): Check for errno ENOSHARE.
2000-05-03 16:11:11 +00:00
Corinna Vinschen 88c9926448 * syscalls.cc (stat_worker): Previous patch could succeed
in stating a non-existant file.
2000-04-26 15:28:06 +00:00
Corinna Vinschen 47eaa6c421 * syscalls.cc (stat_worker): Previous patch failed to stat
each drives root dir on 9X.
2000-04-25 19:39:05 +00:00
Corinna Vinschen d6581f44d4 * fhandler.cc (fhandler_disk_file::open): Check for allow_ntsec
when determining exec flag.
        * path.cc (symlink_info::check): Remove call to get_file_attribute().
        * security.cc (read_sd): Rename, ditto for variables to conform
        to common naming convention. Use GetFileSecurity() instead of
        BackupRead() to avoid permission problems when reading ACLs.
        (write_sd): Same renaming as for read_sd().
        (alloc_sd): Change default permissions according to Linux permissions
        for group and world when write permission is set.
        * syscalls.cc (stat_worker): Avoid different permission problems
        when requesting file informations.
2000-04-25 16:31:14 +00:00
Corinna Vinschen bf921462e7 * syscalls.cc (_link): Check new link path for trailing dot. 2000-04-20 13:52:41 +00:00
Corinna Vinschen f06a3648d5 * syscalls.cc (setuid): Allow switching user context after
successful call to ImpersonateLogedOnUser (NT only).
	(setgid): Ditto.
	(seteuid): Call setuid.
	(setegid): Call setgid.
2000-04-19 22:33:20 +00:00
DJ Delorie ef6581f9ff * syscalls.cc (_rename): Try MoveFile() at first before
MoveFileEx(..., MOVEFILE_REPLACE_EXISTING).
2000-04-19 03:21:13 +00:00
Christopher Faylor fbf23e34c5 * init.cc (dll_entry): Use better check for determining when to set thread
specific stuff.
* syscalls.cc (_unlink): Continue with chmod'ing file even if DELETE_ON_CLOSE
succeeds, if file still exists.
2000-04-16 22:57:05 +00:00
Christopher Faylor 2cf9359a8a * dcrt0.cc (insert_file): Avoid freeing previously allocated argument list.
* path.cc (symlink_info::check): Rename from symlink_check_one.  Use new
symlink_info struct for communication.
(path_conv::path_conv): Use symlink_info structure for communication with
symlink_info::check.  Fix typo which resulted in symbolic links always being
resolved.
(readlink): Use stat_suffixes array when resolving a link.
* syscalls.cc (stat_suffixes): Make global.
2000-04-13 22:43:48 +00:00
Corinna Vinschen 796e3b20bc * newlib/libc/include/sys/unistd.h: Add prototypes for
fchmod, fchown, lchown.
        * winsup/cygwin/syscalls.cc (chown_worker): Use previous
        uid/gid if new uid/gid is -1.
        New static function with chown functionality.
        (chown): Call chown_worker with SYMLINK_FOLLOW.
        (fchown): New function. Call chown_worker with SYMLINK_FOLLOW.
        (lchown): New function. Call chown_worker with SYMLINK_IGNORE.
        * cygwin.din: Add symbols for fchown, lchown.
        * path.cc (symlink): Call `set_file_attribute()' and
        `SetFileAttributeA()' instead of `chmod()' to set
        uid/gid correct.
2000-04-02 20:42:42 +00:00
Christopher Faylor d29b6111a5 * Makefile.in: Use default rules when compiling cygrun.o.
* dcrt0.cc (host_dependent_constants::init): Limit non-NT platforms to 32K
chunks when copying regions during a fork.
* path.cc (symlink_check_one): Add temporary debugging output.  Simplify
PATH_EXEC test.
* syscalls.cc (stat_suffixes): Null terminate this list.
2000-03-28 21:49:16 +00:00
Christopher Faylor c114dfb0c0 * path.cc (symlink_check_one): Recognize symlink settings from the mount table.
* path.h: Make PATH_SYMLINK an alias for MOUNT_SYMLINK.
* syscalls.cc (stat_worker): Use extension search mechanism in path_conv to
look for .exe rather than trying to special case it here.
* mount.h: Make MOUNT_SYMLINK a real option.
2000-03-26 01:54:22 +00:00
Corinna Vinschen 1b16b354fa * syscalls.cc (stat_worker): Set st_nlink to 1 on remote drives. 2000-03-19 11:05:14 +00:00
Christopher Faylor 87b82db4e7 * delqueue.cc (delqueue_list::queue_file): Add some debugging.
* path.h (class path_conv): Add a char * operator for the most common case.
* syscalls.cc (_unlink): Rewrite to use FILE_FLAG_DELETE_ON_CLOSE when possible
(i.e., on NT).
2000-03-18 06:26:14 +00:00
Corinna Vinschen 5d4af61e5d * security.cc (set_process_privileges): Removed `static'.
(get_nt_attribute): Returns uid and gid additionally. Removed call
        to set_process_privileges().
        (get_file_attribute): Returns uid and gid additionally. Don't
        call ntea if ntsec is ON.
        (set_nt_attribute): Removed call to set_process_privileges().
        Don't call ntea if ntsec is ON.
        (acl): Removed call to set_process_privileges().
        * dcrt0.cc (dll_crt0_1): Calls set_process_privileges() now.
        * winsup.h: New prototype for set_process_privileges(),
        changed prototype for get_file_attribute().
        * fhandler.cc (get_file_owner): Discarded.
        (get_file_group): Ditto.
        (fhandler_disk_file::fstat): Discard calls to get_file_owner() and
        get_file_group().
        * path.cc (path_conv::path_conv): Added debugging output for result
        of GetVolumeInformation().
        (mount_info::conv_to_win32_path): Call backslashify() with pathbuf
        instead of src_path.
        * syscalls.cc (chown): Reformatted.
        (chmod): Replace get_file_owner() and get_file_group() calls
        by a call to get_file_attribute(). Discard local variable has_acls.
        Slightly reformatted.
        (stat_worker): Replaced idiot's (it's me) root dir check by call
        to rootdir(). Don't call num_entries() on remote drives.
        Discard local variable has_acls.
2000-03-16 19:35:18 +00:00
Christopher Faylor af1dc7ccea * environ.cc: Eliminate oldstack CYGWIN option.
* exceptions.cc (sfta): Eliminate obsolete function.
(sgmb): Eliminate obsolete function.
(class stack_info): Remove MS method for walking the stack.
(stack_info::init): Just initialize required fields.
(stack_info::brute_force): Rename to stack_info::walk.
(handle_exceptions): Pass derived frame pointer to sig_send.
(interrupt_setup): Clear saved frame pointer here.
(interrupt_on_return): thestack is no longer a pointer.
(call_handler): Accept a flag to indicate when a signal was sent from other
than the main thread.  Use saved frame pointer for determining where to place
signal handler call.
(sig_handle): Accept "nonmain" argument.  Pass it to call_handler.
* fhandler_tty.cc (fhandler_tty_common::__acquire_output_mutex): Change
debugging output slightly.
* (fhandler_tty_common::__release_output_mutex): Ditto.
(fhandler_tty_slave::read): Fix a comment, remove a goto.
* sigproc.cc (sig_send): Accept an optional frame pointer argument for use when
suspending the main process.  sigcomplete_main is an autoreset event now.  Save
frame pointer for non-main operation.
(wait_sig): Make sigcomplete_main an autoreset event.  Eliminate NOSIGQUEUE.
Pass rc to sig_handle to signify if this was a nonmain process.
* sigproc.h: Reflect change to sig_send argument.
* syscalls.cc (swab): Eliminate swab function since it is now available in
newlib.
* winsup.h (signal_dispatch): Change CONTEXT cx to DWORD ebp.
2000-03-09 21:04:05 +00:00
Christopher Faylor 9edba13851 *** empty log message *** 2000-02-24 20:57:40 +00:00
Christopher Faylor faecc585c2 * syscalls.c (_read): Clear errno before doing any read operation. 2000-02-24 20:57:03 +00:00
Christopher Faylor 01cf5d0f5d Respond to more g++ warnings relating to initializing structures. 2000-02-23 04:07:13 +00:00
Christopher Faylor 9cec3d45aa Respond to a multitude of g++ warnings. 2000-02-21 05:20:38 +00:00
Christopher Faylor 1fd5e000ac import winsup-2000-02-17 snapshot 2000-02-17 19:38:33 +00:00