64 case DDI_INFO_DEVT2INSTANCE:
65 *result = 0;
66 return (DDI_SUCCESS);
67 }
68 return (DDI_FAILURE);
69 }
70
71 /* ARGSUSED */
72 static int
73 log_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
74 {
75 if (ddi_create_minor_node(devi, "conslog", S_IFCHR,
76 LOG_CONSMIN, DDI_PSEUDO, NULL) == DDI_FAILURE ||
77 ddi_create_minor_node(devi, "log", S_IFCHR,
78 LOG_LOGMIN, DDI_PSEUDO, NULL) == DDI_FAILURE) {
79 ddi_remove_minor_node(devi, NULL);
80 return (DDI_FAILURE);
81 }
82 log_devi = devi;
83 log_msgid = ddi_getprop(DDI_DEV_T_ANY, log_devi,
84 DDI_PROP_CANSLEEP, "msgid", 1);
85 return (DDI_SUCCESS);
86 }
87
88 /*
89 * log_open can be called for either /dev/log or dev/conslog.
90 *
91 * In the /dev/conslog case log_alloc() allocates a new minor device from
92 * its cache.
93 *
94 * In the case of /dev/log, LOG_NUMCLONES devices are pre-allocated at zone
95 * creation. log_alloc() finds the zone's next available minor device.
96 *
97 * On entry devp's minor number indicates which device (log or conslog), on
98 * successful return it is the device instance.
99 */
100
101 /* ARGSUSED */
102 static int
103 log_open(queue_t *q, dev_t *devp, int flag, int sflag, cred_t *cr)
104 {
254 case M_DATA:
255 mp2 = log_makemsg(LOG_MID, LOG_CONSMIN, 0, SL_CONSOLE,
256 LOG_USER | LOG_INFO, mp->b_rptr, MBLKL(mp) + 1, 0);
257 if (mp2 != NULL)
258 log_sendmsg(mp2, zoneid);
259 break;
260 }
261
262 freemsg(mp);
263 return (0);
264 }
265
266 static int
267 log_rsrv(queue_t *q)
268 {
269 mblk_t *mp;
270 char *msg, *msgid_start, *msgid_end;
271 size_t idlen;
272
273 while (canputnext(q) && (mp = getq(q)) != NULL) {
274 if (log_msgid == 0) {
275 /*
276 * Strip out the message ID. If it's a kernel
277 * SL_CONSOLE message, replace msgid with "unix: ".
278 */
279 msg = (char *)mp->b_cont->b_rptr;
280 if ((msgid_start = strstr(msg, "[ID ")) != NULL &&
281 (msgid_end = strstr(msgid_start, "] ")) != NULL) {
282 log_ctl_t *lc = (log_ctl_t *)mp->b_rptr;
283 if ((lc->flags & SL_CONSOLE) &&
284 (lc->pri & LOG_FACMASK) == LOG_KERN)
285 msgid_start = msg + snprintf(msg,
286 7, "unix: ");
287 idlen = msgid_end + 2 - msgid_start;
288 ovbcopy(msg, msg + idlen, msgid_start - msg);
289 mp->b_cont->b_rptr += idlen;
290 }
291 }
292 mp->b_band = 0;
293 putnext(q, mp);
294 }
295 return (0);
296 }
297
298 static struct module_info logm_info =
299 { LOG_MID, "LOG", LOG_MINPS, LOG_MAXPS, LOG_HIWAT, LOG_LOWAT };
300
301 static struct qinit logrinit =
302 { NULL, log_rsrv, log_open, log_close, NULL, &logm_info, NULL };
303
304 static struct qinit logwinit =
305 { log_wput, NULL, NULL, NULL, NULL, &logm_info, NULL };
306
307 static struct streamtab loginfo = { &logrinit, &logwinit, NULL, NULL };
308
309 DDI_DEFINE_STREAM_OPS(log_ops, nulldev, nulldev, log_attach, nodev,
310 nodev, log_info, D_NEW | D_MP | D_MTPERMOD, &loginfo,
311 ddi_quiesce_not_needed);
|
64 case DDI_INFO_DEVT2INSTANCE:
65 *result = 0;
66 return (DDI_SUCCESS);
67 }
68 return (DDI_FAILURE);
69 }
70
71 /* ARGSUSED */
72 static int
73 log_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
74 {
75 if (ddi_create_minor_node(devi, "conslog", S_IFCHR,
76 LOG_CONSMIN, DDI_PSEUDO, NULL) == DDI_FAILURE ||
77 ddi_create_minor_node(devi, "log", S_IFCHR,
78 LOG_LOGMIN, DDI_PSEUDO, NULL) == DDI_FAILURE) {
79 ddi_remove_minor_node(devi, NULL);
80 return (DDI_FAILURE);
81 }
82 log_devi = devi;
83 log_msgid = ddi_getprop(DDI_DEV_T_ANY, log_devi,
84 DDI_PROP_CANSLEEP, "msgid", 0);
85 return (DDI_SUCCESS);
86 }
87
88 /*
89 * log_open can be called for either /dev/log or dev/conslog.
90 *
91 * In the /dev/conslog case log_alloc() allocates a new minor device from
92 * its cache.
93 *
94 * In the case of /dev/log, LOG_NUMCLONES devices are pre-allocated at zone
95 * creation. log_alloc() finds the zone's next available minor device.
96 *
97 * On entry devp's minor number indicates which device (log or conslog), on
98 * successful return it is the device instance.
99 */
100
101 /* ARGSUSED */
102 static int
103 log_open(queue_t *q, dev_t *devp, int flag, int sflag, cred_t *cr)
104 {
254 case M_DATA:
255 mp2 = log_makemsg(LOG_MID, LOG_CONSMIN, 0, SL_CONSOLE,
256 LOG_USER | LOG_INFO, mp->b_rptr, MBLKL(mp) + 1, 0);
257 if (mp2 != NULL)
258 log_sendmsg(mp2, zoneid);
259 break;
260 }
261
262 freemsg(mp);
263 return (0);
264 }
265
266 static int
267 log_rsrv(queue_t *q)
268 {
269 mblk_t *mp;
270 char *msg, *msgid_start, *msgid_end;
271 size_t idlen;
272
273 while (canputnext(q) && (mp = getq(q)) != NULL) {
274 msg = (char *)mp->b_cont->b_rptr;
275 if (log_msgid == 0 &&
276 (msgid_start = strstr(msg, "[ID ")) != NULL &&
277 (msgid_end = strstr(msgid_start, "] ")) != NULL) {
278 /* Strip out the message ID */
279 idlen = msgid_end + 2 - msgid_start;
280 ovbcopy(msg, msg + idlen, msgid_start - msg);
281 mp->b_cont->b_rptr += idlen;
282 }
283 mp->b_band = 0;
284 putnext(q, mp);
285 }
286 return (0);
287 }
288
289 static struct module_info logm_info =
290 { LOG_MID, "LOG", LOG_MINPS, LOG_MAXPS, LOG_HIWAT, LOG_LOWAT };
291
292 static struct qinit logrinit =
293 { NULL, log_rsrv, log_open, log_close, NULL, &logm_info, NULL };
294
295 static struct qinit logwinit =
296 { log_wput, NULL, NULL, NULL, NULL, &logm_info, NULL };
297
298 static struct streamtab loginfo = { &logrinit, &logwinit, NULL, NULL };
299
300 DDI_DEFINE_STREAM_OPS(log_ops, nulldev, nulldev, log_attach, nodev,
301 nodev, log_info, D_NEW | D_MP | D_MTPERMOD, &loginfo,
302 ddi_quiesce_not_needed);
|