Check ktrstart() error in doktrace()

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Check ktrstart() error in doktrace()

Visa Hankala-2
This diff makes doktrace() check the outcome of ktrstart() and skip
tracing if the trace file header cannot be written.

OK?

Index: kern/kern_ktrace.c
===================================================================
RCS file: src/sys/kern/kern_ktrace.c,v
retrieving revision 1.101
diff -u -p -r1.101 kern_ktrace.c
--- kern/kern_ktrace.c 21 Mar 2020 08:58:50 -0000 1.101
+++ kern/kern_ktrace.c 22 Mar 2020 05:17:23 -0000
@@ -54,7 +54,7 @@
 
 void ktrinitheaderraw(struct ktr_header *, uint, pid_t, pid_t);
 void ktrinitheader(struct ktr_header *, struct proc *, int);
-void ktrstart(struct proc *, struct vnode *, struct ucred *);
+int ktrstart(struct proc *, struct vnode *, struct ucred *);
 int ktrops(struct proc *, struct process *, int, int, struct vnode *,
     struct ucred *);
 int ktrsetchildren(struct proc *, struct process *, int, int,
@@ -141,13 +141,13 @@ ktrinitheader(struct ktr_header *kth, st
  memcpy(kth->ktr_comm, pr->ps_comm, MAXCOMLEN);
 }
 
-void
+int
 ktrstart(struct proc *p, struct vnode *vp, struct ucred *cred)
 {
  struct ktr_header kth;
 
  ktrinitheaderraw(&kth, htobe32(KTR_START), -1, -1);
- ktrwriteraw(p, vp, cred, &kth, NULL);
+ return (ktrwriteraw(p, vp, cred, &kth, NULL));
 }
 
 void
@@ -449,7 +449,9 @@ doktrace(struct vnode *vp, int ops, int
  if (ops == KTROP_SET) {
  if (suser(p) == 0)
  facs |= KTRFAC_ROOT;
- ktrstart(p, vp, cred);
+ error = ktrstart(p, vp, cred);
+ if (error != 0)
+ goto done;
  }
  /*
  * do it