Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/kern_event.c
| Show First 20 Lines • Show All 3,343 Lines • ▼ Show 20 Lines | |||||
| kern_proc_kqueues_out1(struct thread *td, struct proc *p, struct sbuf *s, | kern_proc_kqueues_out1(struct thread *td, struct proc *p, struct sbuf *s, | ||||
| bool compat32) | bool compat32) | ||||
| { | { | ||||
| struct kern_proc_kqueues_out1_cb_args a; | struct kern_proc_kqueues_out1_cb_args a; | ||||
| a.s = s; | a.s = s; | ||||
| a.compat32 = compat32; | a.compat32 = compat32; | ||||
| return (fget_remote_foreach(td, p, kern_proc_kqueues_out1_cb, &a)); | return (fget_remote_foreach(td, p, kern_proc_kqueues_out1_cb, &a)); | ||||
| } | |||||
| struct kern_proc_kqueues_drain_ctx { | |||||
| struct sbuf *sb; | |||||
| size_t remaining; | |||||
| bool full; | |||||
| }; | |||||
| static int | |||||
| kern_proc_kqueues_drain(void *arg, const char *data, int len) | |||||
| { | |||||
| struct kern_proc_kqueues_drain_ctx *c; | |||||
| size_t n; | |||||
| c = arg; | |||||
| n = MIN((size_t)len, c->remaining); | |||||
| if (n != 0) { | |||||
| if (sbuf_bcat(c->sb, data, n) != 0) | |||||
| return (-ENOMEM); | |||||
| c->remaining -= n; | |||||
| } | |||||
| if (c->remaining == 0) { | |||||
| c->full = true; | |||||
| return (-ENOSPC); | |||||
| } | } | ||||
| return (len); | |||||
| } | |||||
| int | int | ||||
| kern_proc_kqueues_out(struct proc *p, struct sbuf *sb, size_t maxlen, | kern_proc_kqueues_out(struct proc *p, struct sbuf *sb, size_t maxlen, | ||||
| bool compat32) | bool compat32) | ||||
| { | { | ||||
| struct kern_proc_kqueues_drain_ctx c; | |||||
| struct sbuf *s, sm; | struct sbuf *s, sm; | ||||
| size_t sb_len; | |||||
| int error; | int error; | ||||
| if (maxlen == -1) | if (maxlen == -1) | ||||
| return (kern_proc_kqueues_out1(curthread, p, sb, compat32)); | return (kern_proc_kqueues_out1(curthread, p, sb, compat32)); | ||||
| if (maxlen == 0) | c.sb = sb; | ||||
| sb_len = 128; | c.remaining = maxlen; | ||||
| else | c.full = false; | ||||
| sb_len = maxlen; | s = sbuf_new(&sm, NULL, PAGE_SIZE, SBUF_FIXEDLEN); | ||||
| s = sbuf_new(&sm, NULL, sb_len + 1, SBUF_FIXEDLEN); | sbuf_set_drain(s, kern_proc_kqueues_drain, &c); | ||||
| error = kern_proc_kqueues_out1(curthread, p, s, compat32); | error = kern_proc_kqueues_out1(curthread, p, s, compat32); | ||||
| sbuf_finish(s); | sbuf_finish(s); | ||||
| if (error == 0) | |||||
| sbuf_bcat(sb, sbuf_data(s), MIN(sbuf_len(s), maxlen)); | |||||
| sbuf_delete(s); | sbuf_delete(s); | ||||
| if (c.full) | |||||
| error = 0; | |||||
| return (error); | return (error); | ||||
| } | } | ||||
| static int | static int | ||||
| sysctl_kern_proc_kqueue_one(struct thread *td, struct sbuf *s, struct proc *p, | sysctl_kern_proc_kqueue_one(struct thread *td, struct sbuf *s, struct proc *p, | ||||
| int kq_fd, bool compat32) | int kq_fd, bool compat32) | ||||
| { | { | ||||
| struct file *fp; | struct file *fp; | ||||
| ▲ Show 20 Lines • Show All 79 Lines • Show Last 20 Lines | |||||