summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2009-11-19 17:54:40 (GMT)
committerChristian Pointner <equinox@helsinki.at>2009-11-19 17:54:40 (GMT)
commitc704199bb4a1ba50961be03d586e162593909549 (patch)
treeb599188843a00d8f46297ab494d6eee81475f217
parente3dea264db4f4d0edd093114a52f9a52da163407 (diff)
got rid of useless cmd_q
-rw-r--r--Makefile1
-rw-r--r--command_queue.c118
-rw-r--r--command_queue.h46
-rw-r--r--rhdropbox.c27
-rw-r--r--utils.c4
-rw-r--r--utils.h3
6 files changed, 11 insertions, 188 deletions
diff --git a/Makefile b/Makefile
index 6987edc..1114549 100644
--- a/Makefile
+++ b/Makefile
@@ -29,7 +29,6 @@ OBJ := log.o \
sig_handler.o \
string_list.o \
utils.o \
- command_queue.o \
client_list.o \
options.o \
rhdropbox.o
diff --git a/command_queue.c b/command_queue.c
deleted file mode 100644
index baec471..0000000
--- a/command_queue.c
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * door_daemon
- *
- * Copyright (C) 2009 Christian Pointner <equinox@helsinki.at>
- *
- * This file is part of door_daemon.
- *
- * door_daemon 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
- * any later version.
- *
- * door_daemon is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with door_daemon. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "command_queue.h"
-#include "datatypes.h"
-
-cmd_t* cmd_get_last(cmd_t* first)
-{
- if(!first)
- return NULL;
-
- while(first->next) {
- first = first->next;
- }
-
- return first;
-}
-
-int cmd_push(cmd_t** first, int fd, cmd_id_t cmd, const char* param)
-{
- if(!first)
- return -1;
-
- cmd_t* new_cmd = malloc(sizeof(cmd_t));
- if(!new_cmd)
- return -2;
-
- new_cmd->fd = fd;
- new_cmd->cmd = cmd;
- if(param) {
- new_cmd->param = strdup(param);
- if(!new_cmd->param) {
- free(new_cmd);
- return -2;
- }
- }
- else
- new_cmd->param = NULL;
- new_cmd->sent = 0;
- new_cmd->tv_start.tv_sec = 0;
- new_cmd->tv_start.tv_usec = 0;
- new_cmd->next = NULL;
-
- if(!(*first)) {
- *first = new_cmd;
- return 0;
- }
-
- cmd_get_last(*first)->next = new_cmd;
-
- return 0;
-}
-
-void cmd_sent(cmd_t* cmd)
-{
- if(!cmd)
- return;
-
- cmd->sent = 1;
- gettimeofday(&cmd->tv_start, NULL);
-}
-
-int cmd_has_expired(cmd_t cmd)
-{
- struct timeval now;
- timerclear(&now);
- gettimeofday(&now, NULL);
- cmd.tv_start.tv_sec++;
-
- return timercmp(&cmd.tv_start, &now, <);
-}
-
-void cmd_pop(cmd_t** first)
-{
- if(!first || !(*first))
- return;
-
- cmd_t* deletee = *first;
- *first = (*first)->next;
- if(deletee->param)
- free(deletee->param);
- free(deletee);
-}
-
-void cmd_clear(cmd_t** first)
-{
- if(!first || !(*first))
- return;
-
- while(*first) {
- cmd_t* deletee = *first;
- *first = (*first)->next;
- if(deletee->param)
- free(deletee->param);
- free(deletee);
- }
-}
diff --git a/command_queue.h b/command_queue.h
deleted file mode 100644
index e364cd5..0000000
--- a/command_queue.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * door_daemon
- *
- * Copyright (C) 2009 Christian Pointner <equinox@helsinki.at>
- *
- * This file is part of door_daemon.
- *
- * door_daemon 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
- * any later version.
- *
- * door_daemon is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with door_daemon. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef RHDROPBOX_command_queue_h_INCLUDED
-#define RHDROPBOX_command_queue_h_INCLUDED
-
-#include <sys/time.h>
-
-enum cmd_id_enum { ADD, REMOVE, STATUS, LOG, LISTEN };
-typedef enum cmd_id_enum cmd_id_t;
-
-struct cmd_struct {
- int fd;
- cmd_id_t cmd;
- char* param;
- int sent;
- struct timeval tv_start;
- struct cmd_struct* next;
-};
-typedef struct cmd_struct cmd_t;
-
-int cmd_push(cmd_t** first, int fd, cmd_id_t cmd, const char* param);
-void cmd_sent(cmd_t* cmd);
-int cmd_has_expired(cmd_t cmd);
-void cmd_pop(cmd_t** first);
-void cmd_clear(cmd_t** first);
-
-#endif
diff --git a/rhdropbox.c b/rhdropbox.c
index f5de265..b12ee16 100644
--- a/rhdropbox.c
+++ b/rhdropbox.c
@@ -30,12 +30,14 @@
#include "sig_handler.h"
#include "options.h"
-#include "command_queue.h"
#include "client_list.h"
#include "daemon.h"
#include "utils.h"
+enum cmd_id_enum { ADD, REMOVE, STATUS, LOG, LISTEN };
+typedef enum cmd_id_enum cmd_id_t;
+
int send_response(int fd, const char* response)
{
if(!response)
@@ -95,11 +97,11 @@ void process_cmd_listen(const char* param, int fd, client_t* client_lst)
}
}
-int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst, options_t* opt)
+int process_cmd(const char* cmd, int fd, client_t* client_lst, options_t* opt)
{
log_printf(DEBUG, "processing command from %d", fd);
- if(!cmd_q || !cmd)
+ if(!cmd)
return -1;
cmd_id_t cmd_id;
@@ -167,7 +169,6 @@ int main_loop(int cmd_listen_fd, options_t* opt)
FD_ZERO(&readfds);
FD_SET(cmd_listen_fd, &readfds);
int max_fd = cmd_listen_fd;
- cmd_t* cmd_q = NULL;
client_t* client_lst = NULL;
read_buffer_t switch_buffer;
@@ -180,28 +181,17 @@ int main_loop(int cmd_listen_fd, options_t* opt)
max_fd = (max_fd < sig_fd) ? sig_fd : max_fd;
int return_value = 0;
- struct timeval timeout;
while(!return_value) {
memcpy(&tmpfds, &readfds, sizeof(tmpfds));
- timeout.tv_sec = 0;
- timeout.tv_usec = 200000;
- int ret = select(max_fd+1, &tmpfds, NULL, NULL, &timeout);
+ int ret = select(max_fd+1, &tmpfds, NULL, NULL, NULL);
if(ret == -1 && errno != EINTR) {
log_printf(ERROR, "select returned with error: %s", strerror(errno));
return_value = -1;
break;
}
- if(ret == -1)
+ if(ret == -1 || !ret)
continue;
- if(!ret) {
- if(cmd_q && cmd_has_expired(*cmd_q)) {
- log_printf(ERROR, "last command expired");
- cmd_pop(&cmd_q);
- }
- else
- continue;
- }
if(FD_ISSET(sig_fd, &tmpfds)) {
if(signal_handle()) {
@@ -227,7 +217,7 @@ int main_loop(int cmd_listen_fd, options_t* opt)
client_t* lst = client_lst;
while(lst) {
if(FD_ISSET(lst->fd, &tmpfds)) {
- return_value = nonblock_recvline(&(lst->buffer), lst->fd, &cmd_q, client_lst, opt);
+ return_value = nonblock_recvline(&(lst->buffer), lst->fd, client_lst, opt);
if(return_value == 2) {
log_printf(DEBUG, "removing closed command connection (fd=%d)", lst->fd);
client_t* deletee = lst;
@@ -245,7 +235,6 @@ int main_loop(int cmd_listen_fd, options_t* opt)
}
}
- cmd_clear(&cmd_q);
client_clear(&client_lst);
signal_stop();
return return_value;
diff --git a/utils.c b/utils.c
index 653b368..2620e6f 100644
--- a/utils.c
+++ b/utils.c
@@ -110,7 +110,7 @@ int send_string(int fd, const char* string)
return ret;
}
-int nonblock_recvline(read_buffer_t* buffer, int fd, cmd_t** cmd_q, client_t* client_lst, options_t* opt)
+int nonblock_recvline(read_buffer_t* buffer, int fd, client_t* client_lst, options_t* opt)
{
int ret = 0;
for(;;) {
@@ -124,7 +124,7 @@ int nonblock_recvline(read_buffer_t* buffer, int fd, cmd_t** cmd_q, client_t* cl
if(buffer->buf[buffer->offset] == '\n') {
buffer->buf[buffer->offset] = 0;
- ret = process_cmd(buffer->buf, fd, cmd_q, client_lst, opt);
+ ret = process_cmd(buffer->buf, fd, client_lst, opt);
buffer->offset = 0;
break;
}
diff --git a/utils.h b/utils.h
index 9461321..65afba2 100644
--- a/utils.h
+++ b/utils.h
@@ -22,7 +22,6 @@
#ifndef RHDROPBOX_utils_h_INCLUDED
#define RHDROPBOX_utils_h_INCLUDED
-#include "command_queue.h"
#include "client_list.h"
#include "options.h"
#include <termios.h>
@@ -30,6 +29,6 @@
int init_command_socket(const char* path);
int connect_command_socket(const char* path);
int send_string(int fd, const char* string);
-int nonblock_recvline(read_buffer_t* buffer, int fd, cmd_t** cmd_q, client_t* client_lst, options_t* opt);
+int nonblock_recvline(read_buffer_t* buffer, int fd, client_t* client_lst, options_t* opt);
#endif