/*++ /* NAME /* msg_logger 3 /* SUMMARY /* direct diagnostics to logger service /* SYNOPSIS /* #include <msg_logger.h> /* /* void msg_logger_init( /* const char *progname, /* const char *hostname, /* const char *unix_path, /* void (*fallback)(const char *)) /* /* void msg_logger_control( /* int key,...) /* DESCRIPTION /* This module implements support to report msg(3) diagnostics /* through a logger daemon, with an optional fallback mechanism. /* The log record format is like traditional syslog: /* /* .nf /* Mmm dd host progname[pid]: text... /* .fi /* /* msg_logger_init() arranges that subsequent msg(3) calls /* will write to an internal logging service. This function /* may also be used to update msg_logger settings. /* /* Arguments: /* .IP progname /* The program name that is prepended to a log record. /* .IP hostname /* The host name that is prepended to a log record. Only the /* first hostname label will be used. /* .IP unix_path /* Pathname of a unix-domain datagram service endpoint. A /* typical use case is the pathname of the postlog socket. /* .IP fallback /* Null pointer, or pointer to function that will be called /* with a formatted message when the logger service is not /* (yet) available. A typical use case is to pass the record /* to the logwriter(3) module. /* .PP /* msg_logger_control() makes adjustments to the msg_logger /* client. These adjustments remain in effect until the next /* msg_logger_init() or msg_logger_control() call. The arguments /* are a list of macros with zero or more arguments, terminated /* with CA_MSG_LOGGER_CTL_END which has none. The following /* lists the names and the types of the corresponding value /* arguments. /* /* Arguments: /* .IP CA_MSG_LOGGER_CTL_FALLBACK_ONLY /* Disable the logging socket, and use the fallback function /* only. This remains in effect until the next msg_logger_init() /* call. /* .IP CA_MSG_LOGGER_CTL_FALLBACK(void (*)(const char *)) /* Override the fallback setting (see above) with the specified /* function pointer. This remains in effect until the next /* msg_logger_init() or msg_logger_control() call. /* When the function is called with a null argument, it should /* allocate resources immediately. This is needed in programs /* that drop privileges after process initialization. /* .IP CA_MSG_LOGGER_CTL_DISABLE /* Disable the msg_logger. This remains in effect until the /* next msg_logger_init() call. /* .IP CA_MSG_LOGGER_CTL_CONNECT_NOW /* Close the logging socket if it was already open, and open /* the logging socket now, if permitted by current settings. /* Otherwise, the open is delayed until a logging request. /* SEE ALSO /* msg(3) diagnostics module /* BUGS /* Output records are truncated to ~2000 characters, because /* unlimited logging is a liability. /* LICENSE /* .ad /* .fi /* The Secure Mailer license must be distributed with this software. /* AUTHOR(S) /* Wietse Venema /* Google, Inc. /* 111 8th Avenue /* New York, NY 10011, USA /* /* Wietse Venema /* porcupine.org
/*--*/
/* *XXXIfthisprogramisset-gid,thenTZmustnotbetrusted.This *scrubbingcodeisinthewrongplace.
*/ if (first_call) { if (unsafe()) while (getenv("TZ")) /* There may be multiple. */ if (unsetenv("TZ") < 0) { /* Desperate measures. */
environ[0] = 0;
msg_fatal("unsetenv: %m");
}
tzset();
}
/* *Savetherequestinfo.Usefree-after-updatebecausethisdatawillbe *accessedwhenmystrdup()runsoutofmemory.
*/ #define UPDATE_AND_FREE(dst, src) do { \ if ((dst) == 0 || strcmp((dst), (src)) != 0) { \ char *_bak = (dst); \
(dst) = mystrdup(src); \ if ((_bak)) myfree(_bak); \
} \
} while (0)
staticvoid fallback(constchar *msg)
{ if (logwriter_one_shot(fallback_path, msg) != 0)
msg_fatal("unable to fall back to directly write %s: %m",
fallback_path);
}
int main(int argc, char **argv)
{
VSTRING *vp = vstring_alloc(256);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.