tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: In-kernel process exit hooks?
So I reiterate my suggestion to use fd_getfile2:
fd = *((int *)data);
if ((filemon->fm_fp = fd_getfile2(curproc, fd)) == NULL) {
error = EBADF;
break;
}
Ack - let me test and confirm that it works.
Yes, it works just fine. Revised diffs are attached.
So, I'll plan on committing this in the next couple of days. Unless
there is strong objection raised.
+------------------+--------------------------+------------------------+
| Paul Goyette | PGP Key fingerprint: | E-mail addresses: |
| (Retired) | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com |
| Kernel Developer | 0786 F758 55DE 53BA 7731 | pgoyette at netbsd.org |
+------------------+--------------------------+------------------------+
Index: filemon.c
===================================================================
RCS file: /cvsroot/src/sys/dev/filemon/filemon.c,v
retrieving revision 1.26
diff -u -p -r1.26 filemon.c
--- filemon.c 8 Jan 2016 08:57:14 -0000 1.26
+++ filemon.c 9 Jan 2016 04:05:21 -0000
@@ -222,7 +222,6 @@ filemon_open(dev_t dev, int oflags __unu
filemon = kmem_alloc(sizeof(struct filemon), KM_SLEEP);
rw_init(&filemon->fm_mtx);
- filemon->fm_fd = -1;
filemon->fm_fp = NULL;
filemon->fm_pid = curproc->p_pid;
@@ -265,7 +264,7 @@ filemon_close(struct file * fp)
*/
rw_enter(&filemon->fm_mtx, RW_WRITER);
if (filemon->fm_fp) {
- fd_putfile(filemon->fm_fd); /* release our reference */
+ closef(filemon->fm_fp); /* release our reference */
filemon->fm_fp = NULL;
}
rw_exit(&filemon->fm_mtx);
@@ -279,6 +278,7 @@ static int
filemon_ioctl(struct file * fp, u_long cmd, void *data)
{
int error = 0;
+ int fd;
struct filemon *filemon;
struct proc *tp;
@@ -301,11 +301,11 @@ filemon_ioctl(struct file * fp, u_long c
/* First, release any current output file descriptor */
if (filemon->fm_fp)
- fd_putfile(filemon->fm_fd);
+ closef(filemon->fm_fp);
/* Now set up the new one */
- filemon->fm_fd = *((int *) data);
- if ((filemon->fm_fp = fd_getfile(filemon->fm_fd)) == NULL) {
+ fd = *((int *) data);
+ if ((filemon->fm_fp = fd_getfile2(curproc, fd)) == NULL) {
error = EBADF;
break;
}
Index: filemon.h
===================================================================
RCS file: /cvsroot/src/sys/dev/filemon/filemon.h,v
retrieving revision 1.8
diff -u -p -r1.8 filemon.h
--- filemon.h 25 Nov 2015 07:34:49 -0000 1.8
+++ filemon.h 9 Jan 2016 04:05:21 -0000
@@ -41,7 +41,6 @@ struct filemon {
char fm_fname1[MAXPATHLEN];/* Temporary filename buffer. */
char fm_fname2[MAXPATHLEN];/* Temporary filename buffer. */
char fm_msgbufr[32 + 2 * MAXPATHLEN]; /* Output message buffer. */
- int fm_fd; /* Output fd */
struct file *fm_fp; /* Output file pointer. */
krwlock_t fm_mtx; /* Lock mutex for this filemon. */
TAILQ_ENTRY(filemon) fm_link; /* Link into the in-use list. */
Home |
Main Index |
Thread Index |
Old Index