2000-02-17 20:38:33 +01:00
|
|
|
/* environ.cc: Cygwin-adopted functions from newlib to manipulate
|
|
|
|
process's environment.
|
|
|
|
|
2003-07-02 05:16:00 +02:00
|
|
|
Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2000-08-02 18:28:18 +02:00
|
|
|
#include "winsup.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <ctype.h>
|
2002-06-13 03:28:51 +02:00
|
|
|
#include <assert.h>
|
2000-09-08 04:56:55 +02:00
|
|
|
#include <sys/cygwin.h>
|
|
|
|
#include <cygwin/version.h>
|
2000-08-12 07:35:42 +02:00
|
|
|
#include "pinfo.h"
|
2001-03-05 07:28:25 +01:00
|
|
|
#include "perprocess.h"
|
2001-07-26 21:22:24 +02:00
|
|
|
#include "security.h"
|
2000-08-22 07:10:20 +02:00
|
|
|
#include "path.h"
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
#include "fhandler.h"
|
2000-08-22 05:58:47 +02:00
|
|
|
#include "cygerrno.h"
|
2001-04-18 23:10:15 +02:00
|
|
|
#include "dtable.h"
|
2000-09-03 06:45:52 +02:00
|
|
|
#include "cygheap.h"
|
2000-09-08 04:56:55 +02:00
|
|
|
#include "registry.h"
|
|
|
|
#include "environ.h"
|
2002-06-21 07:01:17 +02:00
|
|
|
#include "child_info.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2003-07-02 05:16:00 +02:00
|
|
|
extern bool allow_glob;
|
2001-03-05 07:28:25 +01:00
|
|
|
extern bool ignore_case_with_glob;
|
2003-07-02 05:16:00 +02:00
|
|
|
extern bool allow_ntea;
|
|
|
|
extern bool allow_smbntsec;
|
|
|
|
extern bool allow_winsymlinks;
|
|
|
|
extern bool strip_title_path;
|
2001-04-12 23:21:37 +02:00
|
|
|
extern int pcheck_case;
|
2001-04-30 23:19:42 +02:00
|
|
|
extern int subauth_id;
|
2003-07-02 05:16:00 +02:00
|
|
|
bool reset_com = false;
|
|
|
|
static bool envcache = true;
|
2003-08-25 20:21:07 +02:00
|
|
|
#ifdef USE_SERVER
|
|
|
|
extern bool allow_server;
|
|
|
|
#endif
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2001-09-06 06:41:59 +02:00
|
|
|
static char **lastenviron;
|
2000-09-03 06:16:35 +02:00
|
|
|
|
2000-11-08 21:36:37 +01:00
|
|
|
#define ENVMALLOC \
|
|
|
|
(CYGWIN_VERSION_DLL_MAKE_COMBINED (user_data->api_major, user_data->api_minor) \
|
|
|
|
<= CYGWIN_VERSION_DLL_MALLOC_ENV)
|
|
|
|
|
2002-06-16 07:45:37 +02:00
|
|
|
#define NL(x) x, (sizeof (x) - 1)
|
2000-02-17 20:38:33 +01:00
|
|
|
/* List of names which are converted from dos to unix
|
2000-12-10 01:45:12 +01:00
|
|
|
on the way in and back again on the way out.
|
2001-03-18 22:11:25 +01:00
|
|
|
|
2000-12-10 01:45:12 +01:00
|
|
|
PATH needs to be here because CreateProcess uses it and gdb uses
|
|
|
|
CreateProcess. HOME is here because most shells use it and would be
|
|
|
|
confused by Windows style path names. */
|
2003-11-15 00:40:06 +01:00
|
|
|
static int return_MAX_PATH (const char *) {return CYG_MAX_PATH;}
|
2004-05-08 04:55:38 +02:00
|
|
|
static win_env conv_envvars[] =
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2002-06-16 07:45:37 +02:00
|
|
|
{NL ("PATH="), NULL, NULL, cygwin_win32_to_posix_path_list,
|
2000-02-17 20:38:33 +01:00
|
|
|
cygwin_posix_to_win32_path_list,
|
|
|
|
cygwin_win32_to_posix_path_list_buf_size,
|
|
|
|
cygwin_posix_to_win32_path_list_buf_size},
|
2002-06-19 17:27:27 +02:00
|
|
|
{NL ("HOME="), NULL, NULL, cygwin_conv_to_full_posix_path,
|
|
|
|
cygwin_conv_to_full_win32_path, return_MAX_PATH, return_MAX_PATH},
|
2002-06-16 07:45:37 +02:00
|
|
|
{NL ("LD_LIBRARY_PATH="), NULL, NULL, cygwin_conv_to_full_posix_path,
|
2000-02-17 20:38:33 +01:00
|
|
|
cygwin_conv_to_full_win32_path, return_MAX_PATH, return_MAX_PATH},
|
2002-06-19 17:27:27 +02:00
|
|
|
{NL ("TMPDIR="), NULL, NULL, cygwin_conv_to_full_posix_path,
|
|
|
|
cygwin_conv_to_full_win32_path, return_MAX_PATH, return_MAX_PATH},
|
|
|
|
{NL ("TMP="), NULL, NULL, cygwin_conv_to_full_posix_path,
|
|
|
|
cygwin_conv_to_full_win32_path, return_MAX_PATH, return_MAX_PATH},
|
|
|
|
{NL ("TEMP="), NULL, NULL, cygwin_conv_to_full_posix_path,
|
|
|
|
cygwin_conv_to_full_win32_path, return_MAX_PATH, return_MAX_PATH},
|
2000-02-21 06:20:38 +01:00
|
|
|
{NULL, 0, NULL, NULL, NULL, NULL, 0, 0}
|
2000-02-17 20:38:33 +01:00
|
|
|
};
|
|
|
|
|
2000-10-19 02:45:39 +02:00
|
|
|
static unsigned char conv_start_chars[256] = {0};
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
void
|
|
|
|
win_env::add_cache (const char *in_posix, const char *in_native)
|
|
|
|
{
|
2001-10-03 05:49:26 +02:00
|
|
|
MALLOC_CHECK;
|
2000-02-17 20:38:33 +01:00
|
|
|
posix = (char *) realloc (posix, strlen (in_posix) + 1);
|
|
|
|
strcpy (posix, in_posix);
|
|
|
|
if (in_native)
|
|
|
|
{
|
|
|
|
native = (char *) realloc (native, namelen + 1 + strlen (in_native));
|
|
|
|
(void) strcpy (native, name);
|
|
|
|
(void) strcpy (native + namelen, in_native);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
native = (char *) realloc (native, namelen + 1 + win32_len (in_posix));
|
|
|
|
(void) strcpy (native, name);
|
|
|
|
towin32 (in_posix, native + namelen);
|
|
|
|
}
|
2001-10-03 05:49:26 +02:00
|
|
|
MALLOC_CHECK;
|
2000-02-17 20:38:33 +01:00
|
|
|
debug_printf ("posix %s", posix);
|
|
|
|
debug_printf ("native %s", native);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Check for a "special" environment variable name. *env is the pointer
|
2002-06-13 03:28:51 +02:00
|
|
|
to the beginning of the environment variable name. *in_posix is any
|
|
|
|
known posix value for the environment variable. Returns a pointer to
|
|
|
|
the appropriate conversion structure. */
|
2000-02-21 04:13:24 +01:00
|
|
|
win_env * __stdcall
|
2000-02-17 20:38:33 +01:00
|
|
|
getwinenv (const char *env, const char *in_posix)
|
|
|
|
{
|
2000-10-19 02:45:39 +02:00
|
|
|
if (!conv_start_chars[(unsigned char)*env])
|
|
|
|
return NULL;
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
for (int i = 0; conv_envvars[i].name != NULL; i++)
|
2001-04-18 23:10:15 +02:00
|
|
|
if (strncmp (env, conv_envvars[i].name, conv_envvars[i].namelen) == 0)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2001-09-06 07:17:22 +02:00
|
|
|
win_env * const we = conv_envvars + i;
|
2000-02-17 20:38:33 +01:00
|
|
|
const char *val;
|
2002-06-13 03:28:51 +02:00
|
|
|
if (!cur_environ () || !(val = in_posix ?: getenv (we->name)))
|
2000-02-17 20:38:33 +01:00
|
|
|
debug_printf ("can't set native for %s since no environ yet",
|
|
|
|
we->name);
|
2001-05-04 22:39:38 +02:00
|
|
|
else if (!envcache || !we->posix || strcmp (val, we->posix) != 0)
|
2000-02-17 20:38:33 +01:00
|
|
|
we->add_cache (val);
|
|
|
|
return we;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert windows path specs to POSIX, if appropriate.
|
|
|
|
*/
|
|
|
|
static void __stdcall
|
2000-09-03 06:16:35 +02:00
|
|
|
posify (char **here, const char *value)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
char *src = *here;
|
|
|
|
win_env *conv;
|
|
|
|
|
|
|
|
if (!(conv = getwinenv (src)))
|
|
|
|
return;
|
|
|
|
|
2000-10-18 06:53:37 +02:00
|
|
|
int len = strcspn (src, "=") + 1;
|
|
|
|
|
2000-09-03 06:16:35 +02:00
|
|
|
/* Turn all the items from c:<foo>;<bar> into their
|
|
|
|
mounted equivalents - if there is one. */
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2000-09-03 06:16:35 +02:00
|
|
|
char *outenv = (char *) malloc (1 + len + conv->posix_len (value));
|
|
|
|
memcpy (outenv, src, len);
|
|
|
|
conv->toposix (value, outenv + len);
|
2001-03-26 03:16:11 +02:00
|
|
|
conv->add_cache (outenv + len, *value != '/' ? value : NULL);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2000-09-03 06:16:35 +02:00
|
|
|
debug_printf ("env var converted to %s", outenv);
|
|
|
|
*here = outenv;
|
|
|
|
free (src);
|
2001-10-03 05:49:26 +02:00
|
|
|
MALLOC_CHECK;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* my_findenv --
|
|
|
|
* Returns pointer to value associated with name, if any, else NULL.
|
|
|
|
* Sets offset to be the offset of the name/value combination in the
|
|
|
|
* environment array, for use by setenv(3) and unsetenv(3).
|
|
|
|
* Explicitly removes '=' in argument name.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static char * __stdcall
|
|
|
|
my_findenv (const char *name, int *offset)
|
|
|
|
{
|
|
|
|
register int len;
|
|
|
|
register char **p;
|
|
|
|
const char *c;
|
|
|
|
|
|
|
|
c = name;
|
|
|
|
len = 0;
|
|
|
|
while (*c && *c != '=')
|
|
|
|
{
|
|
|
|
c++;
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
|
2000-08-02 18:28:18 +02:00
|
|
|
for (p = cur_environ (); *p; ++p)
|
2000-02-17 20:38:33 +01:00
|
|
|
if (!strncmp (*p, name, len))
|
|
|
|
if (*(c = *p + len) == '=')
|
|
|
|
{
|
2000-08-02 18:28:18 +02:00
|
|
|
*offset = p - cur_environ ();
|
2000-02-17 20:38:33 +01:00
|
|
|
return (char *) (++c);
|
|
|
|
}
|
2001-10-03 05:49:26 +02:00
|
|
|
MALLOC_CHECK;
|
2000-02-17 20:38:33 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* getenv --
|
|
|
|
* Returns ptr to value associated with name, if any, else NULL.
|
|
|
|
*/
|
|
|
|
|
2000-02-21 04:13:24 +01:00
|
|
|
extern "C" char *
|
2000-02-17 20:38:33 +01:00
|
|
|
getenv (const char *name)
|
|
|
|
{
|
|
|
|
int offset;
|
|
|
|
|
|
|
|
return my_findenv (name, &offset);
|
|
|
|
}
|
|
|
|
|
2002-06-12 07:13:54 +02:00
|
|
|
static int __stdcall
|
|
|
|
envsize (const char * const *in_envp)
|
2000-09-03 06:16:35 +02:00
|
|
|
{
|
|
|
|
const char * const *envp;
|
|
|
|
for (envp = in_envp; *envp; envp++)
|
2002-06-12 07:13:54 +02:00
|
|
|
continue;
|
2000-09-03 06:16:35 +02:00
|
|
|
return (1 + envp - in_envp) * sizeof (const char *);
|
|
|
|
}
|
|
|
|
|
2000-07-26 03:44:16 +02:00
|
|
|
/* Takes similar arguments to setenv except that overwrite is
|
|
|
|
either -1, 0, or 1. 0 or 1 signify that the function should
|
|
|
|
perform similarly to setenv. Otherwise putenv is assumed. */
|
|
|
|
static int __stdcall
|
|
|
|
_addenv (const char *name, const char *value, int overwrite)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2000-07-26 03:44:16 +02:00
|
|
|
int issetenv = overwrite >= 0;
|
|
|
|
int offset;
|
|
|
|
char *p;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2000-07-26 03:44:16 +02:00
|
|
|
unsigned int valuelen = strlen (value);
|
|
|
|
if ((p = my_findenv (name, &offset)))
|
|
|
|
{ /* Already exists. */
|
|
|
|
if (!overwrite) /* Ok to overwrite? */
|
|
|
|
return 0; /* No. Wanted to add new value. FIXME: Right return value? */
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2000-07-26 03:44:16 +02:00
|
|
|
/* We've found the offset into environ. If this is a setenv call and
|
|
|
|
there is room in the current environment entry then just overwrite it.
|
|
|
|
Otherwise handle this case below. */
|
|
|
|
if (issetenv && strlen (p) >= valuelen)
|
|
|
|
{
|
|
|
|
strcpy (p, value);
|
2000-02-17 20:38:33 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2000-07-26 03:44:16 +02:00
|
|
|
{ /* Create new slot. */
|
2000-09-03 06:16:35 +02:00
|
|
|
int sz = envsize (cur_environ ());
|
2001-10-03 05:49:26 +02:00
|
|
|
int allocsz = sz + (2 * sizeof (char *));
|
2000-07-26 03:44:16 +02:00
|
|
|
|
2000-09-03 06:16:35 +02:00
|
|
|
offset = (sz - 1) / sizeof (char *);
|
2000-07-26 03:44:16 +02:00
|
|
|
|
|
|
|
/* Allocate space for additional element plus terminating NULL. */
|
2001-10-03 05:49:26 +02:00
|
|
|
if (cur_environ () == lastenviron)
|
2000-09-03 06:16:35 +02:00
|
|
|
lastenviron = __cygwin_environ = (char **) realloc (cur_environ (),
|
|
|
|
allocsz);
|
|
|
|
else if ((lastenviron = (char **) malloc (allocsz)) != NULL)
|
|
|
|
__cygwin_environ = (char **) memcpy ((char **) lastenviron,
|
|
|
|
__cygwin_environ, sz);
|
|
|
|
|
2000-07-17 17:59:27 +02:00
|
|
|
if (!__cygwin_environ)
|
2000-10-23 05:35:50 +02:00
|
|
|
{
|
2000-11-07 20:00:02 +01:00
|
|
|
#ifdef DEBUGGING
|
2000-10-23 05:35:50 +02:00
|
|
|
try_to_debug ();
|
|
|
|
#endif
|
2001-10-03 05:49:26 +02:00
|
|
|
return -1; /* Oops. No more memory. */
|
2000-10-23 05:35:50 +02:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2000-07-26 03:44:16 +02:00
|
|
|
__cygwin_environ[offset + 1] = NULL; /* NULL terminate. */
|
|
|
|
update_envptrs (); /* Update any local copies of 'environ'. */
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2000-07-26 03:44:16 +02:00
|
|
|
char *envhere;
|
|
|
|
if (!issetenv)
|
2000-11-08 21:36:37 +01:00
|
|
|
/* Not setenv. Just overwrite existing. */
|
|
|
|
envhere = cur_environ ()[offset] = (char *) (ENVMALLOC ? strdup (name) : name);
|
2000-07-26 03:44:16 +02:00
|
|
|
else
|
|
|
|
{ /* setenv */
|
|
|
|
/* Look for an '=' in the name and ignore anything after that if found. */
|
|
|
|
for (p = (char *) name; *p && *p != '='; p++)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int namelen = p - name; /* Length of name. */
|
|
|
|
/* Allocate enough space for name + '=' + value + '\0' */
|
2000-08-02 18:28:18 +02:00
|
|
|
envhere = cur_environ ()[offset] = (char *) malloc (namelen + valuelen + 2);
|
2000-07-26 03:44:16 +02:00
|
|
|
if (!envhere)
|
|
|
|
return -1; /* Oops. No more memory. */
|
|
|
|
|
|
|
|
/* Put name '=' value into current slot. */
|
|
|
|
strncpy (envhere, name, namelen);
|
|
|
|
envhere[namelen] = '=';
|
|
|
|
strcpy (envhere + namelen + 1, value);
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2000-07-26 03:44:16 +02:00
|
|
|
/* Update cygwin's cache, if appropriate */
|
2000-02-17 20:38:33 +01:00
|
|
|
win_env *spenv;
|
2000-07-26 03:44:16 +02:00
|
|
|
if ((spenv = getwinenv (envhere)))
|
2000-02-17 20:38:33 +01:00
|
|
|
spenv->add_cache (value);
|
|
|
|
|
2001-10-03 05:49:26 +02:00
|
|
|
MALLOC_CHECK;
|
2000-02-17 20:38:33 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-12-10 01:45:12 +01:00
|
|
|
/* putenv Sets an environment variable */
|
2000-07-26 03:44:16 +02:00
|
|
|
extern "C" int
|
2004-11-26 05:21:47 +01:00
|
|
|
putenv (char *str)
|
2000-07-26 03:44:16 +02:00
|
|
|
{
|
2000-07-26 20:51:14 +02:00
|
|
|
int res;
|
2001-06-28 04:19:57 +02:00
|
|
|
if ((res = check_null_empty_str (str)))
|
2000-07-26 20:51:14 +02:00
|
|
|
{
|
|
|
|
if (res == ENOENT)
|
2000-09-03 06:16:35 +02:00
|
|
|
return 0;
|
2000-07-26 20:51:14 +02:00
|
|
|
set_errno (res);
|
|
|
|
return -1;
|
|
|
|
}
|
2000-07-26 03:44:16 +02:00
|
|
|
char *eq = strchr (str, '=');
|
|
|
|
if (eq)
|
|
|
|
return _addenv (str, eq + 1, -1);
|
|
|
|
|
|
|
|
/* Remove str from the environment. */
|
|
|
|
unsetenv (str);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-12-10 01:45:12 +01:00
|
|
|
/* setenv -- Set the value of the environment variable "name" to be
|
|
|
|
"value". If overwrite is set, replace any current value. */
|
2000-07-26 03:44:16 +02:00
|
|
|
extern "C" int
|
|
|
|
setenv (const char *name, const char *value, int overwrite)
|
|
|
|
{
|
|
|
|
int res;
|
2001-06-28 04:19:57 +02:00
|
|
|
if ((res = check_null_empty_str (value)) == EFAULT)
|
2000-07-26 20:51:14 +02:00
|
|
|
{
|
|
|
|
set_errno (res);
|
|
|
|
return -1;
|
|
|
|
}
|
2001-06-28 04:19:57 +02:00
|
|
|
if ((res = check_null_empty_str (name)))
|
2000-07-26 03:44:16 +02:00
|
|
|
{
|
2000-07-26 20:51:14 +02:00
|
|
|
if (res == ENOENT)
|
2000-09-03 06:16:35 +02:00
|
|
|
return 0;
|
2000-07-26 03:44:16 +02:00
|
|
|
set_errno (res);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (*value == '=')
|
|
|
|
value++;
|
|
|
|
return _addenv (name, value, !!overwrite);
|
|
|
|
}
|
|
|
|
|
2000-12-10 01:45:12 +01:00
|
|
|
/* unsetenv(name) -- Delete environment variable "name". */
|
2000-02-21 04:13:24 +01:00
|
|
|
extern "C" void
|
2000-02-17 20:38:33 +01:00
|
|
|
unsetenv (const char *name)
|
|
|
|
{
|
2000-07-17 21:18:21 +02:00
|
|
|
register char **e;
|
2000-02-17 20:38:33 +01:00
|
|
|
int offset;
|
|
|
|
|
|
|
|
while (my_findenv (name, &offset)) /* if set multiple times */
|
2000-07-17 21:18:21 +02:00
|
|
|
/* Move up the rest of the array */
|
2000-08-02 18:28:18 +02:00
|
|
|
for (e = cur_environ () + offset; ; e++)
|
2000-07-17 21:18:21 +02:00
|
|
|
if (!(*e = *(e + 1)))
|
2000-02-17 20:38:33 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Turn environment variable part of a=b string into uppercase. */
|
2000-02-21 06:20:38 +01:00
|
|
|
static __inline__ void
|
2000-02-17 20:38:33 +01:00
|
|
|
ucenv (char *p, char *eq)
|
|
|
|
{
|
|
|
|
/* Amazingly, NT has a case sensitive environment name list,
|
|
|
|
but only sometimes.
|
|
|
|
It's normal to have NT set your "Path" to something.
|
|
|
|
Later, you set "PATH" to something else. This alters "Path".
|
|
|
|
But if you try and do a naive getenv on "PATH" you'll get nothing.
|
|
|
|
|
|
|
|
So we upper case the labels here to prevent confusion later but
|
|
|
|
we only do it for the first process in a session group. */
|
|
|
|
for (; p < eq; p++)
|
|
|
|
if (islower (*p))
|
2000-10-19 05:12:44 +02:00
|
|
|
*p = cyg_toupper (*p);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Parse CYGWIN options */
|
|
|
|
|
2003-07-02 05:16:00 +02:00
|
|
|
static NO_COPY bool export_settings = false;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
enum settings
|
|
|
|
{
|
|
|
|
justset,
|
|
|
|
isfunc,
|
|
|
|
setbit,
|
|
|
|
set_process_state,
|
|
|
|
};
|
|
|
|
|
2000-11-11 06:36:34 +01:00
|
|
|
/* When BUF is:
|
2000-12-10 01:45:12 +01:00
|
|
|
null or empty: disables globbing
|
|
|
|
"ignorecase": enables case-insensitive globbing
|
|
|
|
anything else: enables case-sensitive globbing */
|
2000-11-11 06:36:34 +01:00
|
|
|
static void
|
|
|
|
glob_init (const char *buf)
|
|
|
|
{
|
|
|
|
if (!buf || !*buf)
|
|
|
|
{
|
2003-07-02 05:16:00 +02:00
|
|
|
allow_glob = false;
|
|
|
|
ignore_case_with_glob = false;
|
2000-11-11 06:36:34 +01:00
|
|
|
}
|
|
|
|
else if (strncasematch (buf, "ignorecase", 10))
|
|
|
|
{
|
2003-07-02 05:16:00 +02:00
|
|
|
allow_glob = true;
|
|
|
|
ignore_case_with_glob = true;
|
2000-11-11 06:36:34 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-07-02 05:16:00 +02:00
|
|
|
allow_glob = true;
|
|
|
|
ignore_case_with_glob = false;
|
2000-11-11 06:36:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-12 23:21:37 +02:00
|
|
|
static void
|
|
|
|
check_case_init (const char *buf)
|
|
|
|
{
|
|
|
|
if (!buf || !*buf)
|
|
|
|
return;
|
|
|
|
|
2003-07-24 21:33:14 +02:00
|
|
|
if (strncasematch (buf, "relax", 5))
|
2001-04-12 23:21:37 +02:00
|
|
|
{
|
|
|
|
pcheck_case = PCHECK_RELAXED;
|
|
|
|
debug_printf ("File case checking set to RELAXED");
|
|
|
|
}
|
2002-06-26 21:39:05 +02:00
|
|
|
else if (strcasematch (buf, "adjust"))
|
2001-04-12 23:21:37 +02:00
|
|
|
{
|
|
|
|
pcheck_case = PCHECK_ADJUST;
|
|
|
|
debug_printf ("File case checking set to ADJUST");
|
|
|
|
}
|
2002-06-26 21:39:05 +02:00
|
|
|
else if (strcasematch (buf, "strict"))
|
2001-04-12 23:21:37 +02:00
|
|
|
{
|
|
|
|
pcheck_case = PCHECK_STRICT;
|
|
|
|
debug_printf ("File case checking set to STRICT");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
debug_printf ("Wrong case checking name: %s", buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-12 13:31:05 +02:00
|
|
|
void
|
|
|
|
set_file_api_mode (codepage_type cp)
|
|
|
|
{
|
|
|
|
if (cp == oem_cp)
|
|
|
|
{
|
|
|
|
SetFileApisToOEM ();
|
|
|
|
debug_printf ("File APIs set to OEM");
|
|
|
|
}
|
|
|
|
else if (cp == ansi_cp)
|
|
|
|
{
|
|
|
|
SetFileApisToANSI ();
|
|
|
|
debug_printf ("File APIs set to ANSI");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-08 05:02:02 +01:00
|
|
|
static void
|
|
|
|
codepage_init (const char *buf)
|
|
|
|
{
|
|
|
|
if (!buf || !*buf)
|
|
|
|
return;
|
|
|
|
|
2002-06-26 07:29:41 +02:00
|
|
|
if (strcasematch (buf, "oem"))
|
2001-01-08 05:02:02 +01:00
|
|
|
{
|
|
|
|
current_codepage = oem_cp;
|
2001-06-12 13:31:05 +02:00
|
|
|
set_file_api_mode (current_codepage);
|
2001-01-08 05:02:02 +01:00
|
|
|
}
|
2002-06-26 07:29:41 +02:00
|
|
|
else if (strcasematch (buf, "ansi"))
|
2001-01-08 05:02:02 +01:00
|
|
|
{
|
|
|
|
current_codepage = ansi_cp;
|
2001-06-12 13:31:05 +02:00
|
|
|
set_file_api_mode (current_codepage);
|
2001-01-08 05:02:02 +01:00
|
|
|
}
|
|
|
|
else
|
2002-06-26 07:29:41 +02:00
|
|
|
debug_printf ("Wrong codepage name: %s", buf);
|
2001-01-08 05:02:02 +01:00
|
|
|
}
|
|
|
|
|
2001-04-30 23:19:42 +02:00
|
|
|
static void
|
|
|
|
subauth_id_init (const char *buf)
|
|
|
|
{
|
|
|
|
if (!buf || !*buf)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int i = strtol (buf, NULL, 0);
|
|
|
|
|
|
|
|
/* 0..127 are reserved by Microsoft, 132 is IIS subauthentication. */
|
|
|
|
if (i > 127 && i != 132 && i <= 255)
|
|
|
|
subauth_id = i;
|
|
|
|
}
|
|
|
|
|
* Makefile.in: Build wincap.o.
* wincap.cc: New file.
* wincap.h: Ditto.
* autoload.cc: Add dynamic load statement for `CreateHardLinkA'.
* dcrt0.cc (os_being_run): Eliminated.
(osname): Ditto.
(iswinnt): Ditto.
(set_os_type): Ditto.
(dll_crt0_1): Call wincap.init() instead of set_os_type().
(_dll_crt0): Ditto.
* environ.cc (set_chunksize): New function.
(parse_thing): `forkchunk' setting now invokes function `set_chunksize'.
* fork.cc (chunksize): Eliminated. Moved to be member of wincap.
* host_dependent.h: Removed.
* syscalls.cc (_link): Try using `CreateHardLinkA' first, if available.
* cygheap.cc, dcrt0.cc, delqueue.cc, dir.cc,
environ.cc, fhandler.cc, fhandler.h, fhandler_console.cc,
fhandler_mem.cc, fork.cc, mmap.cc, net.cc, pinfo.cc, pinfo.h,
security.cc, syscalls.cc, sysconf.cc, syslog.cc, thread.cc,
times.cc, tty.cc, uinfo.cc, uname.cc, winsup.h: Use new wincap
capability check throughout.
* winsup.h: Include wincap.h. Eliminate extern declarations of
`os_being_run' and `iswinnt'. Eliminate `os_type" definition.
* include/cygwin/version.h: Bump version to 1.3.4.
2001-09-12 19:46:37 +02:00
|
|
|
static void
|
|
|
|
set_chunksize (const char *buf)
|
|
|
|
{
|
|
|
|
wincap.set_chunksize (strtol (buf, NULL, 0));
|
|
|
|
}
|
|
|
|
|
2004-08-21 17:50:33 +02:00
|
|
|
static void
|
|
|
|
set_ntea (const char *buf)
|
|
|
|
{
|
|
|
|
allow_ntea = (buf && strcasematch (buf, "yes") && wincap.has_security ());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_ntsec (const char *buf)
|
|
|
|
{
|
|
|
|
allow_ntsec = (buf && strcasematch (buf, "yes") && wincap.has_security ());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_smbntsec (const char *buf)
|
|
|
|
{
|
|
|
|
allow_smbntsec = (buf && strcasematch (buf, "yes") && wincap.has_security ());
|
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
/* The structure below is used to set up an array which is used to
|
2000-12-10 01:45:12 +01:00
|
|
|
parse the CYGWIN environment variable or, if enabled, options from
|
|
|
|
the registry. */
|
2001-09-06 07:17:22 +02:00
|
|
|
static struct parse_thing
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
union parse_setting
|
|
|
|
{
|
2003-07-02 05:16:00 +02:00
|
|
|
bool *b;
|
2000-02-17 20:38:33 +01:00
|
|
|
DWORD *x;
|
|
|
|
int *i;
|
|
|
|
void (*func)(const char *);
|
|
|
|
} setting;
|
|
|
|
|
|
|
|
enum settings disposition;
|
|
|
|
char *remember;
|
|
|
|
union parse_values
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
const char *s;
|
|
|
|
} values[2];
|
2001-09-06 07:17:22 +02:00
|
|
|
} known[] NO_COPY =
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2000-08-24 19:54:43 +02:00
|
|
|
{"binmode", {x: &binmode}, justset, NULL, {{O_TEXT}, {O_BINARY}}},
|
2001-04-12 23:21:37 +02:00
|
|
|
{"check_case", {func: &check_case_init}, isfunc, NULL, {{0}, {0}}},
|
2000-12-10 01:45:12 +01:00
|
|
|
{"codepage", {func: &codepage_init}, isfunc, NULL, {{0}, {0}}},
|
2003-08-25 20:21:07 +02:00
|
|
|
#ifdef USE_SERVER
|
|
|
|
{"server", {&allow_server}, justset, NULL, {{false}, {true}}},
|
|
|
|
#endif
|
2003-07-02 05:16:00 +02:00
|
|
|
{"envcache", {&envcache}, justset, NULL, {{true}, {false}}},
|
2000-02-17 20:38:33 +01:00
|
|
|
{"error_start", {func: &error_start_init}, isfunc, NULL, {{0}, {0}}},
|
2003-07-02 05:16:00 +02:00
|
|
|
{"export", {&export_settings}, justset, NULL, {{false}, {true}}},
|
* Makefile.in: Build wincap.o.
* wincap.cc: New file.
* wincap.h: Ditto.
* autoload.cc: Add dynamic load statement for `CreateHardLinkA'.
* dcrt0.cc (os_being_run): Eliminated.
(osname): Ditto.
(iswinnt): Ditto.
(set_os_type): Ditto.
(dll_crt0_1): Call wincap.init() instead of set_os_type().
(_dll_crt0): Ditto.
* environ.cc (set_chunksize): New function.
(parse_thing): `forkchunk' setting now invokes function `set_chunksize'.
* fork.cc (chunksize): Eliminated. Moved to be member of wincap.
* host_dependent.h: Removed.
* syscalls.cc (_link): Try using `CreateHardLinkA' first, if available.
* cygheap.cc, dcrt0.cc, delqueue.cc, dir.cc,
environ.cc, fhandler.cc, fhandler.h, fhandler_console.cc,
fhandler_mem.cc, fork.cc, mmap.cc, net.cc, pinfo.cc, pinfo.h,
security.cc, syscalls.cc, sysconf.cc, syslog.cc, thread.cc,
times.cc, tty.cc, uinfo.cc, uname.cc, winsup.h: Use new wincap
capability check throughout.
* winsup.h: Include wincap.h. Eliminate extern declarations of
`os_being_run' and `iswinnt'. Eliminate `os_type" definition.
* include/cygwin/version.h: Bump version to 1.3.4.
2001-09-12 19:46:37 +02:00
|
|
|
{"forkchunk", {func: set_chunksize}, isfunc, NULL, {{0}, {0}}},
|
2000-11-11 06:36:34 +01:00
|
|
|
{"glob", {func: &glob_init}, isfunc, NULL, {{0}, {s: "normal"}}},
|
2004-08-21 17:50:33 +02:00
|
|
|
{"ntea", {func: set_ntea}, isfunc, NULL, {{0}, {s: "yes"}}},
|
|
|
|
{"ntsec", {func: set_ntsec}, isfunc, NULL, {{0}, {s: "yes"}}},
|
|
|
|
{"smbntsec", {func: set_smbntsec}, isfunc, NULL, {{0}, {s: "yes"}}},
|
2003-07-02 05:16:00 +02:00
|
|
|
{"reset_com", {&reset_com}, justset, NULL, {{false}, {true}}},
|
|
|
|
{"strip_title", {&strip_title_path}, justset, NULL, {{false}, {true}}},
|
2001-04-30 23:19:42 +02:00
|
|
|
{"subauth_id", {func: &subauth_id_init}, isfunc, NULL, {{0}, {0}}},
|
2003-07-02 05:16:00 +02:00
|
|
|
{"title", {&display_title}, justset, NULL, {{false}, {true}}},
|
2000-02-17 20:38:33 +01:00
|
|
|
{"tty", {NULL}, set_process_state, NULL, {{0}, {PID_USETTY}}},
|
2003-07-02 05:16:00 +02:00
|
|
|
{"winsymlinks", {&allow_winsymlinks}, justset, NULL, {{false}, {true}}},
|
2000-02-17 20:38:33 +01:00
|
|
|
{NULL, {0}, justset, 0, {{0}, {0}}}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Parse a string of the form "something=stuff somethingelse=more-stuff",
|
2000-12-10 01:45:12 +01:00
|
|
|
silently ignoring unknown "somethings". */
|
2000-02-17 20:38:33 +01:00
|
|
|
static void __stdcall
|
|
|
|
parse_options (char *buf)
|
|
|
|
{
|
|
|
|
int istrue;
|
2001-03-14 16:32:49 +01:00
|
|
|
char *p, *lasts;
|
2000-02-17 20:38:33 +01:00
|
|
|
parse_thing *k;
|
|
|
|
|
|
|
|
if (buf == NULL)
|
|
|
|
{
|
2003-11-15 00:40:06 +01:00
|
|
|
char newbuf[CYG_MAX_PATH + 7];
|
2002-07-01 04:11:30 +02:00
|
|
|
newbuf[0] = '\0';
|
2000-02-17 20:38:33 +01:00
|
|
|
for (k = known; k->name != NULL; k++)
|
|
|
|
if (k->remember)
|
|
|
|
{
|
|
|
|
strcat (strcat (newbuf, " "), k->remember);
|
|
|
|
free (k->remember);
|
|
|
|
k->remember = NULL;
|
|
|
|
}
|
2002-07-01 04:11:30 +02:00
|
|
|
|
|
|
|
if (export_settings)
|
|
|
|
{
|
|
|
|
debug_printf ("%s", newbuf + 1);
|
|
|
|
setenv ("CYGWIN", newbuf + 1, 1);
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf = strcpy ((char *) alloca (strlen (buf) + 1), buf);
|
2001-03-14 16:32:49 +01:00
|
|
|
for (p = strtok_r (buf, " \t", &lasts);
|
|
|
|
p != NULL;
|
|
|
|
p = strtok_r (NULL, " \t", &lasts))
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2002-08-08 20:02:09 +02:00
|
|
|
char *keyword_here = p;
|
2000-02-17 20:38:33 +01:00
|
|
|
if (!(istrue = !strncasematch (p, "no", 2)))
|
|
|
|
p += 2;
|
|
|
|
else if (!(istrue = *p != '-'))
|
|
|
|
p++;
|
|
|
|
|
|
|
|
char ch, *eq;
|
|
|
|
if ((eq = strchr (p, '=')) != NULL || (eq = strchr (p, ':')) != NULL)
|
|
|
|
ch = *eq, *eq++ = '\0';
|
|
|
|
else
|
|
|
|
ch = 0;
|
|
|
|
|
|
|
|
for (parse_thing *k = known; k->name != NULL; k++)
|
|
|
|
if (strcasematch (p, k->name))
|
|
|
|
{
|
|
|
|
switch (k->disposition)
|
|
|
|
{
|
|
|
|
case isfunc:
|
|
|
|
k->setting.func ((!eq || !istrue) ?
|
|
|
|
k->values[istrue].s : eq);
|
|
|
|
debug_printf ("%s (called func)", k->name);
|
|
|
|
break;
|
|
|
|
case justset:
|
|
|
|
if (!istrue || !eq)
|
|
|
|
*k->setting.x = k->values[istrue].i;
|
|
|
|
else
|
|
|
|
*k->setting.x = strtol (eq, NULL, 0);
|
|
|
|
debug_printf ("%s %d", k->name, *k->setting.x);
|
|
|
|
break;
|
|
|
|
case set_process_state:
|
|
|
|
k->setting.x = &myself->process_state;
|
|
|
|
/* fall through */
|
|
|
|
case setbit:
|
|
|
|
*k->setting.x &= ~k->values[istrue].i;
|
|
|
|
if (istrue || (eq && strtol (eq, NULL, 0)))
|
|
|
|
*k->setting.x |= k->values[istrue].i;
|
|
|
|
debug_printf ("%s %x", k->name, *k->setting.x);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eq)
|
|
|
|
*--eq = ch;
|
|
|
|
|
|
|
|
int n = eq - p;
|
2002-08-08 20:02:09 +02:00
|
|
|
p = strdup (keyword_here);
|
2000-02-17 20:38:33 +01:00
|
|
|
if (n > 0)
|
|
|
|
p[n] = ':';
|
|
|
|
k->remember = p;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
debug_printf ("returning");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set options from the registry. */
|
2002-07-01 04:11:30 +02:00
|
|
|
static bool __stdcall
|
2000-02-17 20:38:33 +01:00
|
|
|
regopt (const char *name)
|
|
|
|
{
|
2002-07-01 04:11:30 +02:00
|
|
|
bool parsed_something = false;
|
2003-11-15 00:40:06 +01:00
|
|
|
char buf[CYG_MAX_PATH];
|
2002-09-23 02:31:31 +02:00
|
|
|
char lname[strlen (name) + 1];
|
2000-02-17 20:38:33 +01:00
|
|
|
strlwr (strcpy (lname, name));
|
2002-07-01 04:11:30 +02:00
|
|
|
|
2004-12-03 03:00:37 +01:00
|
|
|
for (int i = 0; i < 2; i++)
|
2002-07-01 04:11:30 +02:00
|
|
|
{
|
2004-12-03 03:00:37 +01:00
|
|
|
reg_key r (i, KEY_READ, CYGWIN_INFO_PROGRAM_OPTIONS_NAME, NULL);
|
|
|
|
|
|
|
|
if (r.get_string (lname, buf, sizeof (buf) - 1, "") == ERROR_SUCCESS)
|
2002-07-01 04:11:30 +02:00
|
|
|
{
|
|
|
|
parse_options (buf);
|
|
|
|
parsed_something = true;
|
2004-12-03 03:00:37 +01:00
|
|
|
break;
|
2002-07-01 04:11:30 +02:00
|
|
|
}
|
2000-05-22 23:19:36 +02:00
|
|
|
}
|
2004-12-03 03:00:37 +01:00
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
MALLOC_CHECK;
|
2002-07-01 04:11:30 +02:00
|
|
|
return parsed_something;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the environ array. Look for the CYGWIN environment
|
2000-12-10 01:45:12 +01:00
|
|
|
environment variable and set appropriate options from it. */
|
2000-02-17 20:38:33 +01:00
|
|
|
void
|
2000-10-17 01:55:58 +02:00
|
|
|
environ_init (char **envp, int envc)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2000-09-03 06:16:35 +02:00
|
|
|
char *rawenv;
|
2000-10-17 01:55:58 +02:00
|
|
|
int i;
|
2000-07-26 03:44:16 +02:00
|
|
|
char *p;
|
2000-09-03 06:16:35 +02:00
|
|
|
char *newp;
|
2000-02-17 20:38:33 +01:00
|
|
|
int sawTERM = 0;
|
2000-09-25 18:36:12 +02:00
|
|
|
bool envp_passed_in;
|
2002-07-01 04:11:30 +02:00
|
|
|
bool got_something_from_registry;
|
2001-09-06 07:17:22 +02:00
|
|
|
static char NO_COPY cygterm[] = "TERM=cygwin";
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2001-09-06 06:41:59 +02:00
|
|
|
static int initted;
|
2000-10-19 02:45:39 +02:00
|
|
|
if (!initted)
|
|
|
|
{
|
|
|
|
for (int i = 0; conv_envvars[i].name != NULL; i++)
|
|
|
|
{
|
2002-09-30 04:51:22 +02:00
|
|
|
conv_start_chars[(int) cyg_tolower (conv_envvars[i].name[0])] = 1;
|
|
|
|
conv_start_chars[(int) cyg_toupper (conv_envvars[i].name[0])] = 1;
|
2000-10-19 02:45:39 +02:00
|
|
|
}
|
|
|
|
initted = 1;
|
|
|
|
}
|
|
|
|
|
2002-07-01 04:11:30 +02:00
|
|
|
got_something_from_registry = regopt ("default");
|
2000-02-17 20:38:33 +01:00
|
|
|
if (myself->progname[0])
|
2002-07-01 04:11:30 +02:00
|
|
|
got_something_from_registry = regopt (myself->progname) || got_something_from_registry;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
/* Set ntsec explicit as default, if NT is running */
|
* Makefile.in: Build wincap.o.
* wincap.cc: New file.
* wincap.h: Ditto.
* autoload.cc: Add dynamic load statement for `CreateHardLinkA'.
* dcrt0.cc (os_being_run): Eliminated.
(osname): Ditto.
(iswinnt): Ditto.
(set_os_type): Ditto.
(dll_crt0_1): Call wincap.init() instead of set_os_type().
(_dll_crt0): Ditto.
* environ.cc (set_chunksize): New function.
(parse_thing): `forkchunk' setting now invokes function `set_chunksize'.
* fork.cc (chunksize): Eliminated. Moved to be member of wincap.
* host_dependent.h: Removed.
* syscalls.cc (_link): Try using `CreateHardLinkA' first, if available.
* cygheap.cc, dcrt0.cc, delqueue.cc, dir.cc,
environ.cc, fhandler.cc, fhandler.h, fhandler_console.cc,
fhandler_mem.cc, fork.cc, mmap.cc, net.cc, pinfo.cc, pinfo.h,
security.cc, syscalls.cc, sysconf.cc, syslog.cc, thread.cc,
times.cc, tty.cc, uinfo.cc, uname.cc, winsup.h: Use new wincap
capability check throughout.
* winsup.h: Include wincap.h. Eliminate extern declarations of
`os_being_run' and `iswinnt'. Eliminate `os_type" definition.
* include/cygwin/version.h: Bump version to 1.3.4.
2001-09-12 19:46:37 +02:00
|
|
|
if (wincap.has_security ())
|
2003-07-02 05:16:00 +02:00
|
|
|
allow_ntsec = true;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2000-09-25 18:36:12 +02:00
|
|
|
if (!envp)
|
|
|
|
envp_passed_in = 0;
|
|
|
|
else
|
2000-09-03 06:16:35 +02:00
|
|
|
{
|
2002-06-12 07:13:54 +02:00
|
|
|
envc++;
|
|
|
|
envc *= sizeof (char *);
|
2000-10-17 01:55:58 +02:00
|
|
|
char **newenv = (char **) malloc (envc);
|
|
|
|
memcpy (newenv, envp, envc);
|
2000-09-03 06:16:35 +02:00
|
|
|
cfree (envp);
|
2000-11-08 21:36:37 +01:00
|
|
|
|
|
|
|
/* Older applications relied on the fact that cygwin malloced elements of the
|
|
|
|
environment list. */
|
2000-09-03 06:45:52 +02:00
|
|
|
envp = newenv;
|
2000-11-08 21:36:37 +01:00
|
|
|
if (ENVMALLOC)
|
|
|
|
for (char **e = newenv; *e; e++)
|
|
|
|
{
|
|
|
|
char *p = *e;
|
|
|
|
*e = strdup (p);
|
|
|
|
cfree (p);
|
|
|
|
}
|
2000-09-25 18:36:12 +02:00
|
|
|
envp_passed_in = 1;
|
2000-09-03 06:16:35 +02:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate space for environment + trailing NULL + CYGWIN env. */
|
2000-10-17 01:55:58 +02:00
|
|
|
lastenviron = envp = (char **) malloc ((4 + (envc = 100)) * sizeof (char *));
|
2000-09-03 06:16:35 +02:00
|
|
|
rawenv = GetEnvironmentStrings ();
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
/* Current directory information is recorded as variables of the
|
|
|
|
form "=X:=X:\foo\bar; these must be changed into something legal
|
|
|
|
(we could just ignore them but maybe an application will
|
|
|
|
eventually want to use them). */
|
|
|
|
for (i = 0, p = rawenv; *p != '\0'; p = strchr (p, '\0') + 1, i++)
|
|
|
|
{
|
2000-07-26 20:51:14 +02:00
|
|
|
newp = strdup (p);
|
2000-10-17 01:55:58 +02:00
|
|
|
if (i >= envc)
|
|
|
|
envp = (char **) realloc (envp, (4 + (envc += 100)) * sizeof (char *));
|
2000-07-26 20:51:14 +02:00
|
|
|
envp[i] = newp;
|
|
|
|
if (*newp == '=')
|
|
|
|
*newp = '!';
|
2003-02-13 16:15:32 +01:00
|
|
|
char *eq = strechr (newp, '=');
|
2002-06-21 07:01:17 +02:00
|
|
|
if (!child_proc_info)
|
2000-07-26 20:51:14 +02:00
|
|
|
ucenv (newp, eq);
|
2000-10-19 02:45:39 +02:00
|
|
|
if (*newp == 'T' && strncmp (newp, "TERM=", 5) == 0)
|
2000-02-17 20:38:33 +01:00
|
|
|
sawTERM = 1;
|
2002-09-23 02:31:31 +02:00
|
|
|
if (*newp == 'C' && strncmp (newp, "CYGWIN=", sizeof ("CYGWIN=") - 1) == 0)
|
|
|
|
parse_options (newp + sizeof ("CYGWIN=") - 1);
|
2000-10-19 02:45:39 +02:00
|
|
|
if (*eq && conv_start_chars[(unsigned char)envp[i][0]])
|
2000-09-03 06:16:35 +02:00
|
|
|
posify (envp + i, *++eq ? eq : --eq);
|
2000-11-07 20:00:02 +01:00
|
|
|
debug_printf ("%p: %s", envp[i], envp[i]);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!sawTERM)
|
2004-12-04 00:49:06 +01:00
|
|
|
envp[i++] = strdup (cygterm);
|
2000-02-17 20:38:33 +01:00
|
|
|
envp[i] = NULL;
|
2000-09-03 06:16:35 +02:00
|
|
|
FreeEnvironmentStrings (rawenv);
|
|
|
|
|
|
|
|
out:
|
2000-07-16 22:06:11 +02:00
|
|
|
__cygwin_environ = envp;
|
2000-07-15 04:48:11 +02:00
|
|
|
update_envptrs ();
|
2000-09-25 18:36:12 +02:00
|
|
|
if (envp_passed_in)
|
|
|
|
{
|
|
|
|
p = getenv ("CYGWIN");
|
|
|
|
if (p)
|
|
|
|
parse_options (p);
|
|
|
|
}
|
2002-07-01 04:11:30 +02:00
|
|
|
|
|
|
|
if (got_something_from_registry)
|
|
|
|
parse_options (NULL); /* possibly export registry settings to
|
|
|
|
environment */
|
2000-02-17 20:38:33 +01:00
|
|
|
MALLOC_CHECK;
|
|
|
|
}
|
|
|
|
|
2000-12-10 01:45:12 +01:00
|
|
|
/* Function called by qsort to sort environment strings. */
|
2000-02-17 20:38:33 +01:00
|
|
|
static int
|
|
|
|
env_sort (const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const char **p = (const char **) a;
|
|
|
|
const char **q = (const char **) b;
|
|
|
|
|
|
|
|
return strcmp (*p, *q);
|
|
|
|
}
|
|
|
|
|
2002-06-29 04:36:08 +02:00
|
|
|
char * __stdcall
|
|
|
|
getwinenveq (const char *name, size_t namelen, int x)
|
|
|
|
{
|
|
|
|
char dum[1];
|
|
|
|
char name0[namelen - 1];
|
|
|
|
memcpy (name0, name, namelen - 1);
|
|
|
|
name0[namelen - 1] = '\0';
|
|
|
|
int totlen = GetEnvironmentVariable (name0, dum, 0);
|
|
|
|
if (totlen > 0)
|
|
|
|
{
|
|
|
|
totlen++;
|
|
|
|
if (x == HEAP_1_STR)
|
|
|
|
totlen += namelen;
|
|
|
|
else
|
|
|
|
namelen = 0;
|
|
|
|
char *p = (char *) cmalloc ((cygheap_types) x, totlen);
|
|
|
|
if (namelen)
|
|
|
|
strcpy (p, name);
|
|
|
|
if (GetEnvironmentVariable (name0, p + namelen, totlen))
|
|
|
|
{
|
|
|
|
debug_printf ("using value from GetEnvironmentVariable for '%s'",
|
|
|
|
name0);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cfree (p);
|
|
|
|
}
|
|
|
|
|
|
|
|
debug_printf ("warning: %s not present in environment", name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-06-12 07:13:54 +02:00
|
|
|
struct spenv
|
|
|
|
{
|
|
|
|
const char *name;
|
2002-06-16 07:45:37 +02:00
|
|
|
size_t namelen;
|
2004-10-07 23:28:57 +02:00
|
|
|
bool add_always; /* If true, always add to env if missing */
|
2002-06-29 04:36:08 +02:00
|
|
|
const char * (cygheap_user::*from_cygheap) (const char *, size_t);
|
2004-10-07 23:28:57 +02:00
|
|
|
|
2002-06-16 07:45:37 +02:00
|
|
|
char *retrieve (bool, const char * const = NULL)
|
2002-06-15 23:59:32 +02:00
|
|
|
__attribute__ ((regparm (3)));
|
2002-06-12 07:13:54 +02:00
|
|
|
};
|
|
|
|
|
2002-06-27 22:44:27 +02:00
|
|
|
#define env_dontadd almost_null
|
2002-06-17 01:34:43 +02:00
|
|
|
|
2001-05-11 05:27:22 +02:00
|
|
|
/* Keep this list in upper case and sorted */
|
2002-06-12 07:13:54 +02:00
|
|
|
static NO_COPY spenv spenvs[] =
|
|
|
|
{
|
2004-10-07 23:28:57 +02:00
|
|
|
{NL ("HOMEDRIVE="), false, &cygheap_user::env_homedrive},
|
|
|
|
{NL ("HOMEPATH="), false, &cygheap_user::env_homepath},
|
|
|
|
{NL ("LOGONSERVER="), false, &cygheap_user::env_logsrv},
|
|
|
|
{NL ("SYSTEMDRIVE="), false, NULL},
|
|
|
|
{NL ("SYSTEMROOT="), true, &cygheap_user::env_systemroot},
|
|
|
|
{NL ("USERDOMAIN="), false, &cygheap_user::env_domain},
|
|
|
|
{NL ("USERNAME="), false, &cygheap_user::env_name},
|
|
|
|
{NL ("USERPROFILE="), false, &cygheap_user::env_userprofile},
|
2002-06-12 07:13:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
char *
|
2002-06-16 07:45:37 +02:00
|
|
|
spenv::retrieve (bool no_envblock, const char *const envname)
|
2002-06-12 07:13:54 +02:00
|
|
|
{
|
2002-06-16 07:45:37 +02:00
|
|
|
if (envname && !strncasematch (envname, name, namelen))
|
2002-06-12 07:13:54 +02:00
|
|
|
return NULL;
|
2002-06-19 17:27:27 +02:00
|
|
|
|
|
|
|
debug_printf ("no_envblock %d", no_envblock);
|
|
|
|
|
2002-06-12 07:13:54 +02:00
|
|
|
if (from_cygheap)
|
|
|
|
{
|
|
|
|
const char *p;
|
2002-06-29 08:40:19 +02:00
|
|
|
if (envname && !cygheap->user.issetuid ())
|
2002-06-17 01:34:43 +02:00
|
|
|
{
|
2002-06-29 04:36:08 +02:00
|
|
|
debug_printf ("duping existing value for '%s'", name);
|
|
|
|
return cstrdup1 (envname); /* Don't really care what it's set to
|
2002-06-12 07:13:54 +02:00
|
|
|
if we're calling a cygwin program */
|
2002-06-17 01:34:43 +02:00
|
|
|
}
|
2002-06-12 07:13:54 +02:00
|
|
|
|
2002-06-17 01:34:43 +02:00
|
|
|
/* Calculate (potentially) value for given environment variable. */
|
2002-06-29 04:36:08 +02:00
|
|
|
p = (cygheap->user.*from_cygheap) (name, namelen);
|
2002-06-29 19:26:13 +02:00
|
|
|
if (!p || (no_envblock && !envname) || (p == env_dontadd))
|
2002-06-21 07:01:17 +02:00
|
|
|
return env_dontadd;
|
2002-06-12 07:13:54 +02:00
|
|
|
char *s = (char *) cmalloc (HEAP_1_STR, namelen + strlen (p) + 1);
|
|
|
|
strcpy (s, name);
|
|
|
|
(void) strcpy (s + namelen, p);
|
2002-06-19 17:27:27 +02:00
|
|
|
debug_printf ("using computed value for '%s'", name);
|
2002-06-12 07:13:54 +02:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2002-06-16 07:45:37 +02:00
|
|
|
if (envname)
|
2002-06-12 07:13:54 +02:00
|
|
|
return cstrdup1 (envname);
|
|
|
|
|
2002-06-29 04:36:08 +02:00
|
|
|
return getwinenveq (name, namelen, HEAP_1_STR);
|
2002-06-12 07:13:54 +02:00
|
|
|
}
|
2001-05-11 05:27:22 +02:00
|
|
|
|
2002-06-12 07:13:54 +02:00
|
|
|
#define SPENVS_SIZE (sizeof (spenvs) / sizeof (spenvs[0]))
|
2001-05-11 05:27:22 +02:00
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
/* Create a Windows-style environment block, i.e. a typical character buffer
|
2000-12-10 01:45:12 +01:00
|
|
|
filled with null terminated strings, terminated by double null characters.
|
|
|
|
Converts environment variables noted in conv_envvars into win32 form
|
|
|
|
prior to placing them in the string. */
|
2002-06-12 07:13:54 +02:00
|
|
|
char ** __stdcall
|
|
|
|
build_env (const char * const *envp, char *&envblock, int &envc,
|
|
|
|
bool no_envblock)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2002-06-13 03:28:51 +02:00
|
|
|
int len, n;
|
2000-02-17 20:38:33 +01:00
|
|
|
const char * const *srcp;
|
2002-06-12 07:13:54 +02:00
|
|
|
char **dstp;
|
|
|
|
bool saw_spenv[SPENVS_SIZE] = {0};
|
2001-05-11 05:27:22 +02:00
|
|
|
|
2002-06-12 07:13:54 +02:00
|
|
|
debug_printf ("envp %p", envp);
|
2001-05-11 05:27:22 +02:00
|
|
|
|
2002-06-13 03:28:51 +02:00
|
|
|
/* How many elements? */
|
2000-02-17 20:38:33 +01:00
|
|
|
for (n = 0; envp[n]; n++)
|
|
|
|
continue;
|
|
|
|
|
2002-06-13 03:28:51 +02:00
|
|
|
/* Allocate a new "argv-style" environ list with room for extra stuff. */
|
|
|
|
char **newenv = (char **) cmalloc (HEAP_1_ARGV, sizeof (char *) *
|
|
|
|
(n + SPENVS_SIZE + 1));
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2002-06-13 03:28:51 +02:00
|
|
|
int tl = 0;
|
|
|
|
/* Iterate over input list, generating a new environment list and refreshing
|
|
|
|
"special" entries, if necessary. */
|
2002-06-17 01:34:43 +02:00
|
|
|
for (srcp = envp, dstp = newenv; *srcp; srcp++)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2002-06-13 03:28:51 +02:00
|
|
|
/* Look for entries that require special attention */
|
2002-06-12 07:13:54 +02:00
|
|
|
for (unsigned i = 0; i < SPENVS_SIZE; i++)
|
2002-06-16 07:45:37 +02:00
|
|
|
if (!saw_spenv[i] && (*dstp = spenvs[i].retrieve (no_envblock, *srcp)))
|
2002-06-12 07:13:54 +02:00
|
|
|
{
|
|
|
|
saw_spenv[i] = 1;
|
2002-06-17 01:34:43 +02:00
|
|
|
if (*dstp == env_dontadd)
|
|
|
|
goto next1;
|
|
|
|
goto next0;
|
2002-06-12 07:13:54 +02:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2002-06-16 07:45:37 +02:00
|
|
|
/* Add entry to new environment */
|
2002-06-13 03:28:51 +02:00
|
|
|
*dstp = cstrdup1 (*srcp);
|
2001-05-11 05:27:22 +02:00
|
|
|
|
2002-06-17 01:34:43 +02:00
|
|
|
next0:
|
2002-06-16 07:45:37 +02:00
|
|
|
/* If necessary, calculate rough running total for envblock size */
|
2002-06-13 03:28:51 +02:00
|
|
|
if (!no_envblock)
|
|
|
|
tl += strlen (*dstp) + 1;
|
2002-06-17 01:34:43 +02:00
|
|
|
dstp++;
|
|
|
|
next1:
|
|
|
|
continue;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2002-07-01 04:11:30 +02:00
|
|
|
assert ((srcp - envp) == n);
|
2002-06-13 03:28:51 +02:00
|
|
|
/* Fill in any required-but-missing environment variables. */
|
2004-10-07 23:28:57 +02:00
|
|
|
for (unsigned i = 0; i < SPENVS_SIZE; i++)
|
|
|
|
if (!saw_spenv[i] && (spenvs[i].add_always || cygheap->user.issetuid ()))
|
2004-05-28 21:50:07 +02:00
|
|
|
{
|
2004-05-09 17:17:15 +02:00
|
|
|
*dstp = spenvs[i].retrieve (no_envblock);
|
|
|
|
if (*dstp && !no_envblock && *dstp != env_dontadd)
|
|
|
|
{
|
|
|
|
tl += strlen (*dstp) + 1;
|
|
|
|
dstp++;
|
|
|
|
}
|
|
|
|
}
|
2004-05-28 21:50:07 +02:00
|
|
|
|
2002-06-16 07:45:37 +02:00
|
|
|
envc = dstp - newenv; /* Number of entries in newenv */
|
2002-07-01 04:11:30 +02:00
|
|
|
assert ((size_t) envc <= (n + SPENVS_SIZE));
|
2002-06-12 07:13:54 +02:00
|
|
|
*dstp = NULL; /* Terminate */
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2002-06-12 07:13:54 +02:00
|
|
|
if (no_envblock)
|
|
|
|
envblock = NULL;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
debug_printf ("env count %d, bytes %d", envc, tl);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2002-06-12 07:13:54 +02:00
|
|
|
/* Windows programs expect the environment block to be sorted. */
|
|
|
|
qsort (newenv, envc, sizeof (char *), env_sort);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2002-06-12 07:13:54 +02:00
|
|
|
/* Create an environment block suitable for passing to CreateProcess. */
|
2002-06-13 03:28:51 +02:00
|
|
|
char *s;
|
|
|
|
envblock = (char *) malloc (2 + tl);
|
|
|
|
int new_tl = 0;
|
|
|
|
for (srcp = newenv, s = envblock; *srcp; srcp++)
|
2002-06-12 07:13:54 +02:00
|
|
|
{
|
2002-06-13 03:28:51 +02:00
|
|
|
const char *p;
|
|
|
|
win_env *conv;
|
|
|
|
len = strcspn (*srcp, "=") + 1;
|
|
|
|
|
2005-01-11 13:42:35 +01:00
|
|
|
/* Check for a bad entry. This is necessary to get rid of empty
|
|
|
|
strings, induced by putenv and changing the string afterwards.
|
|
|
|
Note that this doesn't stop invalid strings without '=' in it
|
|
|
|
etc., but we're opting for speed here for now. Adding complete
|
|
|
|
checking would be pretty expensive. */
|
|
|
|
if (len == 1)
|
|
|
|
continue;
|
|
|
|
|
2002-06-13 03:28:51 +02:00
|
|
|
/* See if this entry requires posix->win32 conversion. */
|
|
|
|
conv = getwinenv (*srcp, *srcp + len);
|
|
|
|
if (conv)
|
|
|
|
p = conv->native; /* Use win32 path */
|
|
|
|
else
|
|
|
|
p = *srcp; /* Don't worry about it */
|
|
|
|
|
|
|
|
len = strlen (p);
|
|
|
|
new_tl += len + 1; /* Keep running total of block length so far */
|
|
|
|
|
|
|
|
/* See if we need to increase the size of the block. */
|
|
|
|
if (new_tl > tl)
|
2002-06-14 16:08:07 +02:00
|
|
|
{
|
2002-06-29 19:26:13 +02:00
|
|
|
tl = new_tl + 100;
|
2002-06-14 16:08:07 +02:00
|
|
|
char *new_envblock =
|
2002-09-19 05:30:20 +02:00
|
|
|
(char *) realloc (envblock, 2 + tl);
|
2002-06-14 16:08:07 +02:00
|
|
|
/* If realloc moves the block, move `s' with it. */
|
|
|
|
if (new_envblock != envblock)
|
2002-09-19 05:30:20 +02:00
|
|
|
{
|
2002-06-14 16:08:07 +02:00
|
|
|
s += new_envblock - envblock;
|
|
|
|
envblock = new_envblock;
|
|
|
|
}
|
|
|
|
}
|
2002-06-13 03:28:51 +02:00
|
|
|
|
|
|
|
memcpy (s, p, len + 1);
|
|
|
|
|
|
|
|
/* See if environment variable is "special" in a Windows sense.
|
|
|
|
Under NT, the current directories for visited drives are stored
|
|
|
|
as =C:=\bar. Cygwin converts the '=' to '!' for hopefully obvious
|
|
|
|
reasons. We need to convert it back when building the envblock */
|
|
|
|
if (s[0] == '!' && (isdrive (s + 1) || (s[1] == ':' && s[2] == ':'))
|
|
|
|
&& s[3] == '=')
|
|
|
|
*s = '=';
|
|
|
|
s += len + 1;
|
2002-06-12 07:13:54 +02:00
|
|
|
}
|
2002-06-13 03:28:51 +02:00
|
|
|
*s = '\0'; /* Two null bytes at the end */
|
|
|
|
assert ((s - envblock) <= tl); /* Detect if we somehow ran over end
|
|
|
|
of buffer */
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2002-06-14 23:46:19 +02:00
|
|
|
debug_printf ("envp %p, envc %d", newenv, envc);
|
2002-06-12 07:13:54 +02:00
|
|
|
return newenv;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
2000-07-16 22:06:11 +02:00
|
|
|
|
|
|
|
/* This idiocy is necessary because the early implementers of cygwin
|
|
|
|
did not seem to know about importing data variables from the DLL.
|
|
|
|
So, we have to synchronize cygwin's idea of the environment with the
|
|
|
|
main program's with each reference to the environment. */
|
2000-07-29 18:24:59 +02:00
|
|
|
extern "C" char ** __stdcall
|
2000-07-16 22:06:11 +02:00
|
|
|
cur_environ ()
|
|
|
|
{
|
|
|
|
if (*main_environ != __cygwin_environ)
|
|
|
|
{
|
|
|
|
__cygwin_environ = *main_environ;
|
|
|
|
update_envptrs ();
|
|
|
|
}
|
|
|
|
|
|
|
|
return __cygwin_environ;
|
|
|
|
}
|