Browse Source

Store the pid in the proc instance structure and try to clean up on processes exiting

master
Con Kolivas 11 years ago
parent
commit
2f7f3ecad4
  1. 24
      src/ckpool.c
  2. 1
      src/libckpool.h

24
src/ckpool.c

@ -101,12 +101,20 @@ static void create_process_unixsock(proc_instance_t *pi)
static void write_namepid(proc_instance_t *pi) static void write_namepid(proc_instance_t *pi)
{ {
int pid = getpid(); char s[256];
char s[1024];
pi->pid = getpid();
sprintf(s, "%s%s.pid", pi->ckp->socket_dir, pi->processname); sprintf(s, "%s%s.pid", pi->ckp->socket_dir, pi->processname);
if (!write_pid(s, pid)) if (!write_pid(s, pi->pid))
quit(1, "Failed to write %s pid %d", pi->processname, pid); quit(1, "Failed to write %s pid %d", pi->processname, pi->pid);
}
static void rm_namepid(proc_instance_t *pi)
{
char s[256];
sprintf(s, "%s%s.pid", pi->ckp->socket_dir, pi->processname);
unlink(s);
} }
static void launch_process(proc_instance_t *pi) static void launch_process(proc_instance_t *pi)
@ -117,10 +125,15 @@ static void launch_process(proc_instance_t *pi)
if (pid < 0) if (pid < 0)
quit(1, "Failed to fork %s in launch_process", pi->processname); quit(1, "Failed to fork %s in launch_process", pi->processname);
if (!pid) { if (!pid) {
int ret;
rename_proc(pi->processname); rename_proc(pi->processname);
write_namepid(pi); write_namepid(pi);
create_process_unixsock(pi); create_process_unixsock(pi);
exit(pi->process(pi)); ret = pi->process(pi);
close_unix_socket(pi->us.sockd, pi->us.path);
rm_namepid(pi);
exit(ret);
} }
} }
@ -175,6 +188,7 @@ int main(int argc, char **argv)
/* Shutdown from here */ /* Shutdown from here */
join_pthread(pth_listener); join_pthread(pth_listener);
rm_namepid(&proc_main);
dealloc(ckp.socket_dir); dealloc(ckp.socket_dir);
return 0; return 0;

1
src/libckpool.h

@ -130,6 +130,7 @@ struct proc_instance {
unixsock_t us; unixsock_t us;
char *processname; char *processname;
char *sockname; char *sockname;
int pid;
int (*process)(proc_instance_t *); int (*process)(proc_instance_t *);
}; };

Loading…
Cancel
Save