Browse Source

Launch generator process and abstract out more of the per process files created

master
Con Kolivas 11 years ago
parent
commit
9544d280e3
  1. 76
      src/ckpool.c
  2. 1
      src/ckpool.h
  3. 17
      src/generator.c
  4. 17
      src/generator.h

76
src/ckpool.c

@ -76,15 +76,50 @@ static bool write_pid(const char *path, pid_t pid)
return true; return true;
} }
static void create_process_unixsock(ckpool_t *ckp, unixsock_t *us, const char *process)
{
us->path = strdup(ckp->socket_dir);
realloc_strcat(&us->path, process);
LOGDEBUG("Opening %s", us->path);
us->sockd = open_unix_server(us->path);
if (unlikely(us->sockd < 0))
quit(1, "Failed to open %s socket", process);
}
void write_namepid(ckpool_t *ckp, const char *process)
{
int pid = getpid();
char s[1024];
sprintf(s, "%s%s.pid", ckp->socket_dir, process);
if (!write_pid(s, pid))
quit(1, "Failed to write %s pid %d", process, pid);
}
int launch_generator(ckpool_t *ckp)
{
pid_t pid;
pid = fork();
if (pid < 0)
quit(1, "Failed to fork in launch_generator");
if (!pid) {
unixsock_t us;
write_namepid(ckp, "generator");
create_process_unixsock(ckp, &us, "generator");
generator(&us);
}
return 0;
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
char *socket_dir = NULL;
pthread_t pth_listener; pthread_t pth_listener;
unixsock_t uslistener; unixsock_t uslistener;
pid_t mainpid;
ckpool_t ckp; ckpool_t ckp;
int c, ret; int c, ret;
char *s;
memset(&ckp, 0, sizeof(ckp)); memset(&ckp, 0, sizeof(ckp));
while ((c = getopt(argc, argv, "c:gn:s:")) != -1) { while ((c = getopt(argc, argv, "c:gn:s:")) != -1) {
@ -99,36 +134,29 @@ int main(int argc, char **argv)
ckp.name = optarg; ckp.name = optarg;
break; break;
case 's': case 's':
socket_dir = strdup(optarg); ckp.socket_dir = strdup(optarg);
break; break;
} }
} }
if (!socket_dir) if (!ckp.socket_dir)
socket_dir = strdup("/tmp/ckpool"); ckp.socket_dir = strdup("/tmp/ckpool");
realloc_strcat(&socket_dir, "/"); realloc_strcat(&ckp.socket_dir, "/");
ret = mkdir(socket_dir, 0700); ret = mkdir(ckp.socket_dir, 0700);
if (ret && errno != EEXIST) if (ret && errno != EEXIST)
quit(1, "Failed to make directory %s", socket_dir); quit(1, "Failed to make directory %s", ckp.socket_dir);
mainpid = getpid(); write_namepid(&ckp, "main");
create_process_unixsock(&ckp, &uslistener, "listener");
s = strdup(socket_dir);
realloc_strcat(&s, "main.pid");
if (!write_pid(s, mainpid))
quit(1, "Failed to write pid");
dealloc(s);
uslistener.path = strdup(socket_dir);
realloc_strcat(&uslistener.path, "listener");
LOGDEBUG("Opening %s", uslistener.path);
uslistener.sockd = open_unix_server(uslistener.path);
if (unlikely(uslistener.sockd < 0))
quit(1, "Failed to open listener socket");
create_pthread(&pth_listener, listener, &uslistener); create_pthread(&pth_listener, listener, &uslistener);
/* Launch separate processes from here */
launch_generator(&ckp);
/* Shutdown from here */
join_pthread(pth_listener); join_pthread(pth_listener);
dealloc(ckp.socket_dir);
return 0; return 0;
} }

1
src/ckpool.h

@ -122,6 +122,7 @@ static inline void flip_80(void *dest_p, const void *src_p)
} }
struct ckpool_instance { struct ckpool_instance {
char *socket_dir;
char *config; char *config;
char *name; char *name;
}; };

17
src/generator.c

@ -0,0 +1,17 @@
/*
* Copyright 2014 Con Kolivas
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version. See COPYING for more details.
*/
#include "ckpool.h"
#include "libckpool.h"
#include "generator.h"
int generator(unixsock_t *us)
{
return 0;
}

17
src/generator.h

@ -0,0 +1,17 @@
/*
* Copyright 2014 Con Kolivas
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version. See COPYING for more details.
*/
#ifndef GENERATOR_H
#define GENERATOR_H
#include "config.h"
int generator(unixsock_t *us);
#endif /* GENERATOR_H */
Loading…
Cancel
Save