MCPcopy Create free account
hub / github.com/F-Stack/f-stack / sysctl_kern_console

Function sysctl_kern_console

freebsd/kern/kern_cons.c:316–365  ·  view source on GitHub ↗

* sysctl_kern_console() provides output parseable in conscontrol(1). */

Source from the content-addressed store, hash-verified

314 * sysctl_kern_console() provides output parseable in conscontrol(1).
315 */
316static int
317sysctl_kern_console(SYSCTL_HANDLER_ARGS)
318{
319 struct cn_device *cnd;
320 struct consdev *cp, **list;
321 char *p;
322 int delete, error;
323 struct sbuf *sb;
324
325 sb = sbuf_new(NULL, NULL, CNDEVPATHMAX * 2, SBUF_AUTOEXTEND |
326 SBUF_INCLUDENUL);
327 if (sb == NULL)
328 return (ENOMEM);
329 sbuf_clear(sb);
330 STAILQ_FOREACH(cnd, &cn_devlist, cnd_next)
331 sbuf_printf(sb, "%s,", cnd->cnd_cn->cn_name);
332 sbuf_printf(sb, "/");
333 SET_FOREACH(list, cons_set) {
334 cp = *list;
335 if (cp->cn_name[0] != '\0')
336 sbuf_printf(sb, "%s,", cp->cn_name);
337 }
338 sbuf_finish(sb);
339 error = sysctl_handle_string(oidp, sbuf_data(sb), sbuf_len(sb), req);
340 if (error == 0 && req->newptr != NULL) {
341 p = sbuf_data(sb);
342 error = ENXIO;
343 delete = 0;
344 if (*p == '-') {
345 delete = 1;
346 p++;
347 }
348 SET_FOREACH(list, cons_set) {
349 cp = *list;
350 if (strcmp(p, cp->cn_name) != 0)
351 continue;
352 if (delete) {
353 cnremove(cp);
354 error = 0;
355 } else {
356 error = cnadd(cp);
357 if (error == 0)
358 cnselect(cp);
359 }
360 break;
361 }
362 }
363 sbuf_delete(sb);
364 return (error);
365}
366
367SYSCTL_PROC(_kern, OID_AUTO, console,
368 CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_NEEDGIANT, 0, 0,

Callers

nothing calls this directly

Calls 12

sbuf_newFunction · 0.85
sbuf_clearFunction · 0.85
sbuf_printfFunction · 0.85
sbuf_finishFunction · 0.85
sysctl_handle_stringFunction · 0.85
sbuf_dataFunction · 0.85
sbuf_lenFunction · 0.85
strcmpFunction · 0.85
cnremoveFunction · 0.85
cnaddFunction · 0.85
cnselectFunction · 0.85
sbuf_deleteFunction · 0.85

Tested by

no test coverage detected