sysvinit/startpar-0.53.dif

83 lines
2.0 KiB
Plaintext
Raw Normal View History

--- startpar.c 2008-07-18 13:25:50.000000000 +0200
+++ startpar.c 2009-02-12 14:49:10.987760000 +0100
@@ -29,6 +29,8 @@
#include <sys/select.h>
#include <sys/time.h>
#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/un.h>
#include <sys/sysinfo.h>
#include <sys/stat.h>
#include <time.h>
@@ -64,6 +66,8 @@
static char *run_mode = NULL;
static struct makenode **nodevec;
+static enum { Unknown, Preload, NoPreload } ispreload = Unknown;
+
#define PBUF_SIZE 8192
struct prg {
char *name;
@@ -248,6 +252,10 @@
if (read_proc(&prcs_run, &prcs_blked))
return par;
+ /* if we have preload running, we expect I/O not to be a problem */
+ if (ispreload == Preload)
+ prcs_blked = 0;
+
newpar = (par*numcpu) - prcs_run + 1; /* +1 for startpar its self */
newpar -= (int)(((double)prcs_blked)*iorate); /* I/O load reduction */
@@ -271,6 +279,8 @@
return checksystem(par, start, false);
}
+#define SOCK_PATH "/dev/shm/preload_sock"
+
void run(struct prg *p)
{
char *m = 0;
@@ -341,6 +351,40 @@
closeall();
+ if (!strcmp(arg, "start"))
+ {
+ int s, t, len;
+ struct sockaddr_un remote;
+ char str[100];
+
+ s = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (s != -1)
+ {
+ memset(&remote, 0, sizeof(struct sockaddr_un));
+ remote.sun_family = AF_UNIX;
+ strcpy(remote.sun_path, SOCK_PATH);
+ len = strlen(remote.sun_path) + sizeof(remote.sun_family);
+
+ t = connect(s, (struct sockaddr *)&remote, len);
+ if (t != -1)
+ {
+ ispreload = Preload;
+ send(s, p->name, strlen(p->name), 0);
+ recv(s, str, 100, 0);
+ }
+ else if ( ispreload == Unknown)
+ {
+ /*
+ * if we connected to preload once, we know it ran.
+ * In case we can't connect to it later, it means it did
+ * its job and we can guess I/O is no longer a problem.
+ */
+ ispreload = NoPreload;
+ }
+ close(s);
+ }
+ }
+
if (run_mode)
{
char path[128];