Open accounting file for appending, not general writing.
This allows accton(1) to be used with an append-only file. PR: 7169 Reported by: Joao Carlos Mendes Luis <jonny@jonny.eng.br> Reviewed by: bde Approved by: sheldonh (mentor) MFC after: 2 weeks
This commit is contained in:
parent
8c6d67ef99
commit
92da2e7671
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=99740
@ -127,19 +127,19 @@ acct(td, uap)
|
||||
mtx_lock(&Giant);
|
||||
/*
|
||||
* If accounting is to be started to a file, open that file for
|
||||
* writing and make sure it's a 'normal'.
|
||||
* appending and make sure it's a 'normal'.
|
||||
*/
|
||||
if (SCARG(uap, path) != NULL) {
|
||||
NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path),
|
||||
td);
|
||||
flags = FWRITE;
|
||||
flags = FWRITE | O_APPEND;
|
||||
error = vn_open(&nd, &flags, 0);
|
||||
if (error)
|
||||
goto done2;
|
||||
NDFREE(&nd, NDF_ONLY_PNBUF);
|
||||
VOP_UNLOCK(nd.ni_vp, 0, td);
|
||||
if (nd.ni_vp->v_type != VREG) {
|
||||
vn_close(nd.ni_vp, FWRITE, td->td_ucred, td);
|
||||
vn_close(nd.ni_vp, FWRITE | O_APPEND, td->td_ucred, td);
|
||||
error = EACCES;
|
||||
goto done2;
|
||||
}
|
||||
@ -151,8 +151,8 @@ acct(td, uap)
|
||||
*/
|
||||
if (acctp != NULLVP || savacctp != NULLVP) {
|
||||
callout_stop(&acctwatch_callout);
|
||||
error = vn_close((acctp != NULLVP ? acctp : savacctp), FWRITE,
|
||||
td->td_ucred, td);
|
||||
error = vn_close((acctp != NULLVP ? acctp : savacctp),
|
||||
FWRITE | O_APPEND, td->td_ucred, td);
|
||||
acctp = savacctp = NULLVP;
|
||||
}
|
||||
if (SCARG(uap, path) == NULL)
|
||||
@ -316,7 +316,8 @@ acctwatch(a)
|
||||
|
||||
if (savacctp != NULLVP) {
|
||||
if (savacctp->v_type == VBAD) {
|
||||
(void) vn_close(savacctp, FWRITE, NOCRED, NULL);
|
||||
(void) vn_close(savacctp, FWRITE | O_APPEND, NOCRED,
|
||||
NULL);
|
||||
savacctp = NULLVP;
|
||||
return;
|
||||
}
|
||||
@ -330,7 +331,7 @@ acctwatch(a)
|
||||
if (acctp == NULLVP)
|
||||
return;
|
||||
if (acctp->v_type == VBAD) {
|
||||
(void) vn_close(acctp, FWRITE, NOCRED, NULL);
|
||||
(void) vn_close(acctp, FWRITE | O_APPEND, NOCRED, NULL);
|
||||
acctp = NULLVP;
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user