Browse files

Restored daemonize.

  • Loading branch information...
1 parent cd9fd9a commit 0b5f2c98d7bc6e00802cee14d0ba2b18b24a9449 @nicolasff committed Apr 9, 2011
Showing with 25 additions and 2 deletions.
  1. +0 −1 acl.c
  2. +1 −1 client.h
  3. +24 −0 server.c
View
1 acl.c
@@ -39,7 +39,6 @@ acl_match_client(struct acl *a, struct http_client *client, in_addr_t *ip) {
int
acl_allow_command(struct cmd *cmd, struct conf *cfg, struct http_client *client) {
- /* FIXME */
char *always_off[] = {"MULTI", "EXEC", "WATCH", "DISCARD"};
unsigned int i;
View
2 client.h
@@ -30,7 +30,7 @@ struct http_client {
size_t sz;
last_cb_t last_cb;
- /* various flags. TODO: bit map */
+ /* various flags. */
int keep_alive:1;
int broken:1;
int is_websocket:1;
View
24 server.c
@@ -111,10 +111,34 @@ server_can_accept(int fd, short event, void *ptr) {
s->next_worker = (s->next_worker + 1) % s->cfg->http_threads;
}
+/**
+ * Daemonize server.
+ * (taken from Redis)
+ */
+static void
+server_daemonize(void) {
+ int fd;
+
+ if (fork() != 0) exit(0); /* parent exits */
+ setsid(); /* create a new session */
+
+ /* Every output goes to /dev/null. */
+ if ((fd = open("/dev/null", O_RDWR, 0)) != -1) {
+ dup2(fd, STDIN_FILENO);
+ dup2(fd, STDOUT_FILENO);
+ dup2(fd, STDERR_FILENO);
+ if (fd > STDERR_FILENO) close(fd);
+ }
+}
+
+
int
server_start(struct server *s) {
int i;
+ if(s->cfg->daemonize) {
+ server_daemonize();
+ }
/* ignore sigpipe */
#ifdef SIGPIPE

0 comments on commit 0b5f2c9

Please sign in to comment.