summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorJun-ichiro itojun Hagino <itojun@cvs.openbsd.org>2002-09-16 04:34:47 +0000
committerJun-ichiro itojun Hagino <itojun@cvs.openbsd.org>2002-09-16 04:34:47 +0000
commit14effbc95a77287bc0a9664d55ba66702da6b02d (patch)
tree2f9e2014cb557d3d4a04c9ff1c98d135cfc83036 /bin
parent86a3a5aded910e8d60f3526d5269cb0fd9b02db9 (diff)
periodically save policies that have been modified. from provos
>here is a diff that will cause systrace to periodically save policies >that have been modified. Useful if you run systrace on an xterm and >kill it accidently. Or other applications like opera that are long >running and can cause weird crashes.
Diffstat (limited to 'bin')
-rw-r--r--bin/systrace/policy.c4
-rw-r--r--bin/systrace/systrace.c29
2 files changed, 29 insertions, 4 deletions
diff --git a/bin/systrace/policy.c b/bin/systrace/policy.c
index fbbb1e9e98c..1b846c80d7b 100644
--- a/bin/systrace/policy.c
+++ b/bin/systrace/policy.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: policy.c,v 1.17 2002/09/06 22:56:21 deraadt Exp $ */
+/* $OpenBSD: policy.c,v 1.18 2002/09/16 04:34:46 itojun Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
@@ -567,6 +567,8 @@ systrace_dumppolicy(void)
if (systrace_writepolicy(policy) == -1)
fprintf(stderr, "Failed to write policy for %s\n",
policy->name);
+ else
+ policy->flags &= ~POLICY_CHANGED;
}
return (0);
diff --git a/bin/systrace/systrace.c b/bin/systrace/systrace.c
index f7d0155c984..47048410a83 100644
--- a/bin/systrace/systrace.c
+++ b/bin/systrace/systrace.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: systrace.c,v 1.32 2002/08/05 23:27:53 provos Exp $ */
+/* $OpenBSD: systrace.c,v 1.33 2002/09/16 04:34:46 itojun Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
@@ -419,8 +419,9 @@ main(int argc, char **argv)
char *filename = NULL;
char *policypath = NULL;
char *guipath = _PATH_XSYSTRACE;
+ struct timeval tv, tv_wait = {60, 0};
pid_t pidattach = 0;
- int usex11 = 1;
+ int usex11 = 1, count;
int background;
while ((c = getopt(argc, argv, "aAituUd:g:f:p:")) != -1) {
@@ -523,9 +524,31 @@ main(int argc, char **argv)
if (usex11 && !automatic && !allow)
requestor_start(guipath);
- while (intercept_read(trfd) != -1)
+ /* Loop on requests */
+ count = 0;
+ while (intercept_read(trfd) != -1) {
if (!intercept_existpids())
break;
+ if (userpolicy) {
+ /* Periodically save modified policies */
+ if (count == 0) {
+ /* Set new wait time */
+ gettimeofday(&tv, NULL);
+ timeradd(&tv, &tv_wait, &tv);
+ } else if (count > 10) {
+ struct timeval now;
+ gettimeofday(&now, NULL);
+
+ count = 0;
+ if (timercmp(&now, &tv, >)) {
+ /* Dump policy and cause new time */
+ systrace_dumppolicy();
+ continue;
+ }
+ }
+ count++;
+ }
+ }
if (userpolicy)
systrace_dumppolicy();