journald-syslog.c   journald-syslog.c 
skipping to change at line 23 skipping to change at line 23
systemd is distributed in the hope that it will be useful, but systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details. Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>. along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/ ***/
#include <unistd.h> #include <unistd.h>
#include <stddef.h>
#include <sys/epoll.h> #include <sys/epoll.h>
#include "systemd/sd-messages.h"
#include "socket-util.h" #include "socket-util.h"
#include "journald.h" #include "journald.h"
#include "journald-syslog.h" #include "journald-syslog.h"
#include "journald-kmsg.h" #include "journald-kmsg.h"
#include "journald-console.h" #include "journald-console.h"
/* Warn once every 30s if we missed syslog message */
#define WARN_FORWARD_SYSLOG_MISSED_USEC (30 * USEC_PER_SEC)
static void forward_syslog_iovec(Server *s, const struct iovec *iovec, unsi gned n_iovec, struct ucred *ucred, struct timeval *tv) { static void forward_syslog_iovec(Server *s, const struct iovec *iovec, unsi gned n_iovec, struct ucred *ucred, struct timeval *tv) {
struct msghdr msghdr; struct msghdr msghdr;
struct cmsghdr *cmsg; struct cmsghdr *cmsg;
union { union {
struct cmsghdr cmsghdr; struct cmsghdr cmsghdr;
uint8_t buf[CMSG_SPACE(sizeof(struct ucred))]; uint8_t buf[CMSG_SPACE(sizeof(struct ucred))];
} control; } control;
union sockaddr_union sa; union sockaddr_union sa;
assert(s); assert(s);
skipping to change at line 76 skipping to change at line 81
/* Forward the syslog message we received via /dev/log to /* Forward the syslog message we received via /dev/log to
* /run/systemd/syslog. Unfortunately we currently can't set * /run/systemd/syslog. Unfortunately we currently can't set
* the SO_TIMESTAMP auxiliary data, and hence we don't. */ * the SO_TIMESTAMP auxiliary data, and hence we don't. */
if (sendmsg(s->syslog_fd, &msghdr, MSG_NOSIGNAL) >= 0) if (sendmsg(s->syslog_fd, &msghdr, MSG_NOSIGNAL) >= 0)
return; return;
/* The socket is full? I guess the syslog implementation is /* The socket is full? I guess the syslog implementation is
* too slow, and we shouldn't wait for that... */ * too slow, and we shouldn't wait for that... */
if (errno == EAGAIN) if (errno == EAGAIN) {
s->n_forward_syslog_missed++;
return; return;
}
if (ucred && errno == ESRCH) { if (ucred && errno == ESRCH) {
struct ucred u; struct ucred u;
/* Hmm, presumably the sender process vanished /* Hmm, presumably the sender process vanished
* by now, so let's fix it as good as we * by now, so let's fix it as good as we
* can, and retry */ * can, and retry */
u = *ucred; u = *ucred;
u.pid = getpid(); u.pid = getpid();
memcpy(CMSG_DATA(cmsg), &u, sizeof(struct ucred)); memcpy(CMSG_DATA(cmsg), &u, sizeof(struct ucred));
if (sendmsg(s->syslog_fd, &msghdr, MSG_NOSIGNAL) >= 0) if (sendmsg(s->syslog_fd, &msghdr, MSG_NOSIGNAL) >= 0)
return; return;
if (errno == EAGAIN) if (errno == EAGAIN) {
s->n_forward_syslog_missed++;
return; return;
}
} }
if (errno != ENOENT) if (errno != ENOENT)
log_debug("Failed to forward syslog message: %m"); log_debug("Failed to forward syslog message: %m");
} }
static void forward_syslog_raw(Server *s, int priority, const char *buffer, struct ucred *ucred, struct timeval *tv) { static void forward_syslog_raw(Server *s, int priority, const char *buffer, struct ucred *ucred, struct timeval *tv) {
struct iovec iovec; struct iovec iovec;
assert(s); assert(s);
skipping to change at line 466 skipping to change at line 475
zero(ev); zero(ev);
ev.events = EPOLLIN; ev.events = EPOLLIN;
ev.data.fd = s->syslog_fd; ev.data.fd = s->syslog_fd;
if (epoll_ctl(s->epoll_fd, EPOLL_CTL_ADD, s->syslog_fd, &ev) < 0) { if (epoll_ctl(s->epoll_fd, EPOLL_CTL_ADD, s->syslog_fd, &ev) < 0) {
log_error("Failed to add syslog server fd to epoll object: %m"); log_error("Failed to add syslog server fd to epoll object: %m");
return -errno; return -errno;
} }
return 0; return 0;
} }
void server_maybe_warn_forward_syslog_missed(Server *s) {
usec_t n;
assert(s);
if (s->n_forward_syslog_missed <= 0)
return;
n = now(CLOCK_MONOTONIC);
if (s->last_warn_forward_syslog_missed + WARN_FORWARD_SYSLOG_MISSED
_USEC > n)
return;
server_driver_message(s, SD_MESSAGE_FORWARD_SYSLOG_MISSED, "Forward
ing to syslog missed %u messages.", s->n_forward_syslog_missed);
s->n_forward_syslog_missed = 0;
s->last_warn_forward_syslog_missed = n;
}
 End of changes. 8 change blocks. 
2 lines changed or deleted 11 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/