2000-02-18 03:38:33 +08:00
|
|
|
/* syslog.cc
|
|
|
|
|
2001-09-12 04:01:02 +08:00
|
|
|
Copyright 1996, 1997, 1998, 1999, 2000, 2001 Red Hat, Inc.
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2000-08-03 00:28:18 +08:00
|
|
|
#include "winsup.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <unistd.h>
|
2005-01-13 06:40:46 +08:00
|
|
|
#include "cygerrno.h"
|
2001-07-27 03:22:24 +08:00
|
|
|
#include "security.h"
|
2001-10-01 12:10:07 +08: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 08:37:18 +08:00
|
|
|
#include "fhandler.h"
|
2000-08-12 13:35:42 +08:00
|
|
|
#include "dtable.h"
|
2000-11-17 19:30:14 +08:00
|
|
|
#include "cygheap.h"
|
2000-08-22 13:10:20 +08:00
|
|
|
#include "thread.h"
|
2003-12-24 00:26:31 +08:00
|
|
|
#include "cygtls.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/* FIXME: These should probably be in the registry. */
|
|
|
|
/* FIXME: The Win95 path should be whatever slash is */
|
|
|
|
|
|
|
|
#define WIN95_EVENT_LOG_PATH "C:\\CYGWIN_SYSLOG.TXT"
|
|
|
|
#define CYGWIN_LOG_NAME "Cygwin"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Utility function to help enable moving
|
|
|
|
* WIN95_EVENT_LOG_PATH into registry later.
|
|
|
|
*/
|
|
|
|
static const char *
|
|
|
|
get_win95_event_log_path ()
|
|
|
|
{
|
|
|
|
return WIN95_EVENT_LOG_PATH;
|
|
|
|
}
|
|
|
|
|
2003-12-24 00:26:31 +08:00
|
|
|
/* openlog: save the passed args. Don't open the
|
|
|
|
system log (NT) or log file (95) yet. */
|
2003-03-10 04:10:25 +08:00
|
|
|
extern "C" void
|
2000-02-18 03:38:33 +08:00
|
|
|
openlog (const char *ident, int logopt, int facility)
|
|
|
|
{
|
|
|
|
debug_printf ("openlog called with (%s, %d, %d)",
|
|
|
|
ident ? ident : "<NULL>", logopt, facility);
|
|
|
|
|
2003-12-24 00:26:31 +08:00
|
|
|
if (_my_tls.locals.process_ident != NULL)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-12-24 00:26:31 +08:00
|
|
|
free (_my_tls.locals.process_ident);
|
2005-03-17 01:07:32 +08:00
|
|
|
_my_tls.locals.process_ident = NULL;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
if (ident)
|
|
|
|
{
|
2003-12-24 00:26:31 +08:00
|
|
|
_my_tls.locals.process_ident = (char *) malloc (strlen (ident) + 1);
|
2005-03-17 01:07:32 +08:00
|
|
|
if (!_my_tls.locals.process_ident)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-12-24 00:26:31 +08:00
|
|
|
debug_printf ("failed to allocate memory for _my_tls.locals.process_ident");
|
2000-02-18 03:38:33 +08:00
|
|
|
return;
|
|
|
|
}
|
2003-12-24 00:26:31 +08:00
|
|
|
strcpy (_my_tls.locals.process_ident, ident);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2003-12-24 00:26:31 +08:00
|
|
|
_my_tls.locals.process_logopt = logopt;
|
|
|
|
_my_tls.locals.process_facility = facility;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* setlogmask: set the log priority mask and return previous mask.
|
|
|
|
If maskpri is zero, just return previous. */
|
|
|
|
int
|
|
|
|
setlogmask (int maskpri)
|
|
|
|
{
|
|
|
|
if (maskpri == 0)
|
2003-12-24 00:26:31 +08:00
|
|
|
return _my_tls.locals.process_logmask;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-12-24 00:26:31 +08:00
|
|
|
int old_mask = _my_tls.locals.process_logmask;
|
|
|
|
_my_tls.locals.process_logmask = maskpri & LOG_PRIMASK;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
return old_mask;
|
|
|
|
}
|
|
|
|
|
2003-12-24 00:26:31 +08:00
|
|
|
/* Private class used to handle formatting of syslog message
|
|
|
|
It is named pass_handler because it does a two-pass handling of log
|
2000-02-18 03:38:33 +08:00
|
|
|
strings. The first pass counts the length of the string, and the second
|
|
|
|
one builds the string. */
|
|
|
|
|
|
|
|
class pass_handler
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
FILE *fp_;
|
|
|
|
char *message_;
|
|
|
|
int total_len_;
|
|
|
|
|
|
|
|
void shutdown ();
|
|
|
|
|
|
|
|
/* Explicitly disallow copies */
|
|
|
|
pass_handler (const pass_handler &);
|
|
|
|
pass_handler & operator = (const pass_handler &);
|
|
|
|
|
|
|
|
public:
|
|
|
|
pass_handler ();
|
|
|
|
~pass_handler ();
|
|
|
|
|
|
|
|
int initialize (int);
|
|
|
|
|
|
|
|
int print (const char *,...);
|
|
|
|
int print_va (const char *, va_list);
|
|
|
|
char *get_message () const { return message_; }
|
2000-08-25 05:19:14 +08:00
|
|
|
void set_message (char *s) { message_ = s; *message_ = '\0'; }
|
2000-02-18 03:38:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
pass_handler::pass_handler () : fp_ (0), message_ (0), total_len_ (0)
|
|
|
|
{
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
pass_handler::~pass_handler ()
|
|
|
|
{
|
|
|
|
shutdown ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pass_handler::shutdown ()
|
|
|
|
{
|
2000-08-11 09:56:05 +08:00
|
|
|
if (fp_ != NULL)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
fclose (fp_);
|
|
|
|
fp_ = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pass_handler::initialize (int pass_number)
|
|
|
|
{
|
|
|
|
shutdown ();
|
2000-08-11 09:56:05 +08:00
|
|
|
if (pass_number)
|
|
|
|
return total_len_ + 1;
|
|
|
|
|
|
|
|
fp_ = fopen ("/dev/null", "wb");
|
2005-03-17 01:07:32 +08:00
|
|
|
setbuf (fp_, NULL);
|
2000-08-11 09:56:05 +08:00
|
|
|
if (fp_ == NULL)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-08-11 09:56:05 +08:00
|
|
|
debug_printf ("failed to open /dev/null");
|
|
|
|
return -1;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2000-08-11 09:56:05 +08:00
|
|
|
total_len_ = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pass_handler::print (const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start (ap, fmt);
|
|
|
|
int ret = print_va (fmt, ap);
|
|
|
|
va_end (ap);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pass_handler::print_va (const char *fmt, va_list list)
|
|
|
|
{
|
2000-08-25 05:19:14 +08:00
|
|
|
if (fp_ != NULL)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
int len = vfprintf (fp_, fmt, list);
|
|
|
|
if (len < 0)
|
2000-08-11 09:56:05 +08:00
|
|
|
return -1;
|
|
|
|
total_len_ += len;
|
|
|
|
return 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2000-08-25 05:19:14 +08:00
|
|
|
else if (message_ != NULL)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
char *printpos = &message_[strlen (message_)];
|
|
|
|
vsprintf (printpos, fmt, list);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
debug_printf ("FAILURE ! fp_ and message_ both 0!! ");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* syslog: creates the log message and writes to system
|
|
|
|
* log (NT) or log file (95). FIXME. WinNT log error messages
|
|
|
|
* don't look pretty, but in order to fix this we have to
|
|
|
|
* embed resources in the code and tell the NT registry
|
|
|
|
* where we are, blech (what happens if we move ?).
|
|
|
|
* We could, however, add the resources in Cygwin and
|
|
|
|
* always point to that.
|
|
|
|
*/
|
|
|
|
|
2003-03-10 04:10:25 +08:00
|
|
|
extern "C" void
|
2003-06-06 16:11:19 +08:00
|
|
|
vsyslog (int priority, const char *message, va_list ap)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
debug_printf ("%x %s", priority, message);
|
|
|
|
/* If the priority fails the current mask, reject */
|
2003-12-24 00:26:31 +08:00
|
|
|
if (((priority & LOG_PRIMASK) & _my_tls.locals.process_logmask) == 0)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
debug_printf ("failing message %x due to priority mask %x",
|
2003-12-24 00:26:31 +08:00
|
|
|
priority, _my_tls.locals.process_logmask);
|
2000-02-18 03:38:33 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Translate %m in the message to error text */
|
|
|
|
char *errtext = strerror (get_errno ());
|
|
|
|
int errlen = strlen (errtext);
|
|
|
|
int numfound = 0;
|
|
|
|
|
|
|
|
for (const char *cp = message; *cp; cp++)
|
|
|
|
if (*cp == '%' && cp[1] == 'm')
|
|
|
|
numfound++;
|
|
|
|
|
2000-08-11 09:56:05 +08:00
|
|
|
char *newmessage = (char *) alloca (strlen (message) +
|
|
|
|
(errlen * numfound) + 1);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-08-11 09:56:05 +08:00
|
|
|
if (newmessage == NULL)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
debug_printf ("failed to allocate newmessage");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *dst = newmessage;
|
|
|
|
for (const char *cp2 = message; *cp2; cp2++)
|
|
|
|
if (*cp2 == '%' && cp2[1] == 'm')
|
|
|
|
{
|
|
|
|
cp2++;
|
|
|
|
strcpy (dst, errtext);
|
|
|
|
while (*dst)
|
|
|
|
dst++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*dst++ = *cp2;
|
|
|
|
|
|
|
|
*dst = '\0';
|
|
|
|
message = newmessage;
|
|
|
|
|
|
|
|
/* Work out the priority type - we ignore the facility for now.. */
|
|
|
|
WORD eventType;
|
|
|
|
switch (LOG_PRI (priority))
|
|
|
|
{
|
2001-10-05 08:17:57 +08:00
|
|
|
case LOG_EMERG:
|
|
|
|
case LOG_ALERT:
|
|
|
|
case LOG_CRIT:
|
2000-02-18 03:38:33 +08:00
|
|
|
case LOG_ERR:
|
|
|
|
eventType = EVENTLOG_ERROR_TYPE;
|
|
|
|
break;
|
|
|
|
case LOG_WARNING:
|
|
|
|
eventType = EVENTLOG_WARNING_TYPE;
|
|
|
|
break;
|
2001-10-05 08:17:57 +08:00
|
|
|
case LOG_NOTICE:
|
2000-02-18 03:38:33 +08:00
|
|
|
case LOG_INFO:
|
2001-10-05 08:17:57 +08:00
|
|
|
case LOG_DEBUG:
|
2000-02-18 03:38:33 +08:00
|
|
|
eventType = EVENTLOG_INFORMATION_TYPE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
eventType = EVENTLOG_ERROR_TYPE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We need to know how long the buffer needs to be.
|
|
|
|
The only legal way I can see of doing this is to
|
|
|
|
do a vfprintf to /dev/null, and count the bytes
|
|
|
|
output, then do it again to a malloc'ed string. This
|
|
|
|
is ugly, slow, but prevents core dumps :-).
|
|
|
|
*/
|
|
|
|
pass_handler pass;
|
2000-08-11 09:56:05 +08:00
|
|
|
for (int pass_number = 0; pass_number < 2; ++pass_number)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-08-11 09:56:05 +08:00
|
|
|
int n = pass.initialize (pass_number);
|
|
|
|
if (n == -1)
|
2000-02-18 03:38:33 +08:00
|
|
|
return;
|
2000-08-11 09:56:05 +08:00
|
|
|
else if (n > 0)
|
|
|
|
pass.set_message ((char *) alloca (n));
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/* Deal with ident_string */
|
2003-12-24 00:26:31 +08:00
|
|
|
if (_my_tls.locals.process_ident != NULL)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-12-24 00:26:31 +08:00
|
|
|
if (pass.print ("%s : ", _my_tls.locals.process_ident) == -1)
|
2000-02-18 03:38:33 +08:00
|
|
|
return;
|
|
|
|
}
|
2003-12-24 00:26:31 +08:00
|
|
|
if (_my_tls.locals.process_logopt & LOG_PID)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-02-23 03:35:03 +08:00
|
|
|
if (pass.print ("PID %u : ", getpid ()) == -1)
|
2000-02-18 03:38:33 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
* 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-13 01:46:37 +08:00
|
|
|
if (!wincap.has_eventlog ())
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
* 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-13 01:46:37 +08:00
|
|
|
/* Add a priority string - not needed for systems with
|
|
|
|
eventlog capability. */
|
2000-02-18 03:38:33 +08:00
|
|
|
switch (LOG_PRI (priority))
|
|
|
|
{
|
2001-10-05 08:17:57 +08:00
|
|
|
case LOG_EMERG:
|
|
|
|
pass.print ("%s : ", "LOG_EMERG");
|
|
|
|
break;
|
|
|
|
case LOG_ALERT:
|
|
|
|
pass.print ("%s : ", "LOG_ALERT");
|
|
|
|
break;
|
|
|
|
case LOG_CRIT:
|
|
|
|
pass.print ("%s : ", "LOG_CRIT");
|
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
case LOG_ERR:
|
|
|
|
pass.print ("%s : ", "LOG_ERR");
|
|
|
|
break;
|
|
|
|
case LOG_WARNING:
|
|
|
|
pass.print ("%s : ", "LOG_WARNING");
|
|
|
|
break;
|
2001-10-05 08:17:57 +08:00
|
|
|
case LOG_NOTICE:
|
|
|
|
pass.print ("%s : ", "LOG_NOTICE");
|
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
case LOG_INFO:
|
|
|
|
pass.print ("%s : ", "LOG_INFO");
|
2001-10-05 08:17:57 +08:00
|
|
|
break;
|
|
|
|
case LOG_DEBUG:
|
|
|
|
pass.print ("%s : ", "LOG_DEBUG");
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pass.print ("%s : ", "LOG_ERR");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print out the variable part */
|
|
|
|
if (pass.print_va (message, ap) == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
const char *msg_strings[1];
|
|
|
|
char *total_msg = pass.get_message ();
|
|
|
|
int len = strlen (total_msg);
|
|
|
|
if (len != 0 && (total_msg[len - 1] == '\n'))
|
|
|
|
total_msg[len - 1] = '\0';
|
|
|
|
|
|
|
|
msg_strings[0] = total_msg;
|
|
|
|
|
* 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-13 01:46:37 +08:00
|
|
|
if (wincap.has_eventlog ())
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
/* For NT, open the event log and send the message */
|
2003-12-24 00:26:31 +08:00
|
|
|
HANDLE hEventSrc = RegisterEventSourceA (NULL, (_my_tls.locals.process_ident != NULL) ?
|
|
|
|
_my_tls.locals.process_ident : CYGWIN_LOG_NAME);
|
2000-08-25 05:19:14 +08:00
|
|
|
if (hEventSrc == NULL)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
debug_printf ("RegisterEventSourceA failed with %E");
|
|
|
|
return;
|
|
|
|
}
|
2003-09-29 20:31:22 +08:00
|
|
|
if (!ReportEventA (hEventSrc, eventType, 0, 0,
|
|
|
|
cygheap->user.sid (), 1, 0, msg_strings, NULL))
|
|
|
|
debug_printf ("ReportEventA failed with %E");
|
2000-02-18 03:38:33 +08:00
|
|
|
DeregisterEventSource (hEventSrc);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Under Windows 95, append the message to the log file */
|
2003-02-23 03:35:03 +08:00
|
|
|
char timestamp[24];
|
|
|
|
time_t ctime;
|
2000-02-18 03:38:33 +08:00
|
|
|
FILE *fp = fopen (get_win95_event_log_path (), "a");
|
2000-08-25 05:19:14 +08:00
|
|
|
if (fp == NULL)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
debug_printf ("failed to open file %s",
|
|
|
|
get_win95_event_log_path ());
|
|
|
|
return;
|
|
|
|
}
|
2003-02-23 03:35:03 +08:00
|
|
|
strftime (timestamp, sizeof timestamp, "%Y-%m-%d %H:%M:%S : ",
|
|
|
|
localtime (&(ctime = time (NULL))));
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Now to prevent several syslog messages from being
|
|
|
|
interleaved, we must lock the first byte of the file
|
|
|
|
This works on Win32 even if we created the file above.
|
|
|
|
*/
|
2001-04-19 05:10:15 +08:00
|
|
|
HANDLE fHandle = cygheap->fdtab[fileno (fp)]->get_handle ();
|
2003-02-23 03:35:03 +08:00
|
|
|
for (int i = 0;; i++)
|
|
|
|
if (LockFile (fHandle, 0, 0, 1, 0) == FALSE)
|
|
|
|
if (i == 3)
|
|
|
|
{
|
|
|
|
debug_printf ("failed to lock file %s", get_win95_event_log_path ());
|
|
|
|
fclose (fp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
usleep (1000);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
fputs (timestamp, fp);
|
2000-02-18 03:38:33 +08:00
|
|
|
fputs (msg_strings[0], fp);
|
|
|
|
fputc ('\n', fp);
|
|
|
|
fclose (fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-06 16:11:19 +08:00
|
|
|
extern "C" void
|
|
|
|
syslog (int priority, const char *message, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start (ap, message);
|
|
|
|
vsyslog (priority, message, ap);
|
|
|
|
va_end (ap);
|
|
|
|
}
|
|
|
|
|
2003-03-10 04:10:25 +08:00
|
|
|
extern "C" void
|
2000-02-18 03:38:33 +08:00
|
|
|
closelog (void)
|
|
|
|
{
|
|
|
|
;
|
|
|
|
}
|