1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
/* $OpenBSD: logmsg.c,v 1.2 2018/09/05 17:32:56 eric Exp $ */
/*
* Copyright (c) 2017 Eric Faurot <eric@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/un.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include "lpd.h"
#include "io.h"
#include "log.h"
#include "proc.h"
const char *
log_fmt_proto(int p)
{
switch (p) {
case PROTO_LPR:
return "lpr";
default:
return NULL;
}
};
const char *
log_fmt_imsgtype(int type)
{
static char buf[16];
switch (type) {
case IMSG_NONE:
return "IMSG_NONE";
case IMSG_SOCK_ENGINE:
return "IMSG_SOCK_ENGINE";
case IMSG_SOCK_FRONTEND:
return "IMSG_SOCK_FRONTEND";
case IMSG_CONF_START:
return "IMSG_CONF_START";
case IMSG_CONF_LISTENER:
return "IMSG_CONF_LISTENER";
case IMSG_CONF_END:
return "IMSG_CONF_END";
case IMSG_GETADDRINFO:
return "IMSG_GETADDRINFO";
case IMSG_GETADDRINFO_END:
return "IMSG_GETADDRINFO_END";
case IMSG_GETNAMEINFO:
return "IMSG_GETNAMEINFO";
case IMSG_LPR_ALLOWEDHOST:
return "IMSG_LPR_ALLOWEDHOST";
case IMSG_LPR_DISPLAYQ:
return "IMSG_LPR_DISPLAYQ";
case IMSG_LPR_PRINTJOB:
return "IMSG_LPR_PRINTJOB";
case IMSG_LPR_RECVJOB:
return "IMSG_LPR_RECVJOB";
case IMSG_LPR_RECVJOB_CLEAR:
return "IMSG_LPR_RECVJOB_CLEAR";
case IMSG_LPR_RECVJOB_CF:
return "IMSG_LPR_RECVJOB_CF";
case IMSG_LPR_RECVJOB_DF:
return "IMSG_LPR_RECVJOB_DF";
case IMSG_LPR_RECVJOB_COMMIT:
return "IMSG_LPR_RECVJOB_COMMIT";
case IMSG_LPR_RECVJOB_ROLLBACK:
return "IMSG_LPR_RECVJOB_ROLLBACK";
case IMSG_LPR_RMJOB:
return "IMSG_LPR_RMJOB";
default:
snprintf(buf, sizeof(buf), "?%d", type);
return buf;
}
}
const char *
log_fmt_proctype(int proctype)
{
switch (proctype) {
case PROC_CLIENT:
return "client";
case PROC_CONTROL:
return "control";
case PROC_ENGINE:
return "engine";
case PROC_FRONTEND:
return "frontend";
case PROC_PRINTER:
return "printer";
case PROC_PRIV:
return "priv";
default:
return NULL;
}
};
const char *
log_fmt_sockaddr(const struct sockaddr *sa)
{
static char buf[PATH_MAX];
char host[NI_MAXHOST], serv[NI_MAXSERV];
switch (sa->sa_family) {
case AF_LOCAL:
(void)strlcpy(buf, ((const struct sockaddr_un*)sa)->sun_path,
sizeof(buf));
return buf;
case AF_INET:
case AF_INET6:
if (getnameinfo(sa, sa->sa_len, host, sizeof(host),
serv, sizeof(serv), NI_NUMERICHOST | NI_NUMERICSERV)) {
log_warnx("%s: getnameinfo", __func__);
return NULL;
}
if (sa->sa_family == AF_INET6)
snprintf(buf, sizeof(buf), "[%s]:%s", host, serv);
else
snprintf(buf, sizeof(buf), "%s:%s", host, serv);
return buf;
default:
return NULL;
}
}
void
log_imsg(struct imsgproc *proc, struct imsg *imsg)
{
if (imsg == NULL)
log_debug("imsg src=%s closed",
log_fmt_proctype(proc_gettype(proc)));
else
log_debug("imsg src=%s type=%s len=%d fd=%d",
log_fmt_proctype(proc_gettype(proc)),
log_fmt_imsgtype(imsg->hdr.type),
imsg->hdr.len, imsg->fd);
}
void
log_io(const char *name, struct io *io, int ev)
{
log_debug("io %s evt=%s io=%s", name, io_strevent(ev),
io_strio(io));
}
|