[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ossec-dev] [PATCHv2] Make syscheckd use SCHED_BATCH on Linux versions that support it



SCHED_BATCH is a Linux process scheduler added in 2.6.16 designed to
improve interactivity by giving lower priority to non-interactive and
cpu intensive processes. There is a brief description of SCHED_BATCH
here: http://kernelnewbies.org/Linux_2_6_16

I am pretty new to C, but not to Linux or software development. If
there are any obvious stupidities in here, please let me know.
Attaching the patch was easier, but if you prefer future patches
inline just let it be known.


-- 

Jeff Schroeder

Don't drink and derive, alcohol and analysis don't mix.
Index: run_check.c
===================================================================
RCS file: /usr/cvsroot/ossec-hids/src/syscheckd/run_check.c,v
retrieving revision 1.27
diff -u -r1.27 run_check.c
--- run_check.c	28 Mar 2007 02:53:58 -0000	1.27
+++ run_check.c	9 Aug 2007 18:41:34 -0000
@@ -10,6 +10,12 @@
  */
 
 
+/** SCHED_BATCH is Linux specific and is only picked up with _GNU_SOURCE **/
+#ifdef __linux__
+	#define _GNU_SOURCE
+	#include <sched.h>
+#endif
+
 #include "shared.h"
 #include "syscheck.h"
 #include "os_crypto/md5/md5_op.h"
@@ -89,6 +95,20 @@
     time_t prev_time_rk = 0;
     time_t prev_time_sk = 0;
     
+    /*
+     * SCHED_BATCH forces the kernel to assume this is a cpu intensive process
+     * and gives it a lower priority. This keeps ossec-syscheckd from reducing
+     * the interactity of an ssh session when checksumming large files.
+     * This is available in kernel flavors >= 2.6.16
+     */
+    #ifdef SCHED_BATCH
+      struct sched_param pri;
+      pri.sched_priority = 0;
+      int status = sched_setscheduler(0, SCHED_BATCH, &pri);
+      #ifdef DEBUG
+        verbose("%s: Setting SCHED_BATCH returned: %d", ARGV0, status);
+      #endif
+    #endif
             
     #ifdef DEBUG
     verbose("%s: Starting daemon ..",ARGV0);

OSSEC home | Main Index | Thread Index


OSSEC project: www.ossec.net.
Mailling list information: http://www.ossec.net/en/mailing_lists.html.