summaryrefslogtreecommitdiff
path: root/rhdropbox.c
diff options
context:
space:
mode:
Diffstat (limited to 'rhdropbox.c')
-rw-r--r--rhdropbox.c40
1 files changed, 36 insertions, 4 deletions
diff --git a/rhdropbox.c b/rhdropbox.c
index a9d5ad8..a7b3681 100644
--- a/rhdropbox.c
+++ b/rhdropbox.c
@@ -25,6 +25,7 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
+#include <sys/inotify.h>
#include "log.h"
#include "sig_handler.h"
@@ -57,6 +58,20 @@ int send_response(int fd, const char* response)
return ret;
}
+int process_watch(int inotify_fd)
+{
+ log_printf(INFO, "something changed on watch descriptor '%d'", inotify_fd);
+ u_int8_t buf[1000];
+ int ret = read(inotify_fd, buf, 1000);
+ if(ret < 0) {
+ log_printf(ERROR, "read inotify_fd error: %s", strerror(errno));
+ return ret;
+ }
+
+ log_printf(DEBUG, "received %d bytes from watch", ret);
+ return 0;
+}
+
/* client_t* client; */
/* int listener_cnt = 0; */
/* for(client = client_lst; client; client = client->next) */
@@ -161,14 +176,15 @@ int process_cmd(const char* cmd, int fd, client_t* client_lst, options_t* opt)
return 0;
}
-int main_loop(int cmd_listen_fd, options_t* opt)
+int main_loop(int cmd_listen_fd, int inotify_fd, options_t* opt)
{
log_printf(NOTICE, "entering main loop");
fd_set readfds, tmpfds;
FD_ZERO(&readfds);
FD_SET(cmd_listen_fd, &readfds);
- int max_fd = cmd_listen_fd;
+ FD_SET(inotify_fd, &readfds);
+ int max_fd = (cmd_listen_fd < inotify_fd) ? inotify_fd : cmd_listen_fd;
client_t* client_lst = NULL;
read_buffer_t switch_buffer;
@@ -200,6 +216,12 @@ int main_loop(int cmd_listen_fd, options_t* opt)
}
}
+ if(FD_ISSET(inotify_fd, &tmpfds)) {
+ return_value = process_watch(inotify_fd);
+ if(return_value)
+ break;
+ }
+
if(FD_ISSET(cmd_listen_fd, &tmpfds)) {
int new_fd = accept(cmd_listen_fd, NULL, NULL);
if(new_fd < 0) {
@@ -337,9 +359,19 @@ int main(int argc, char* argv[])
log_close();
exit(-1);
}
-
- ret = main_loop(cmd_listen_fd, &opt);
+
+ int inotify_fd = create_inotify();
+ if(inotify_fd < 0) {
+ close(cmd_listen_fd);
+ options_clear(&opt);
+ log_close();
+ exit(-1);
+ }
+
+ ret = main_loop(cmd_listen_fd, inotify_fd, &opt);
+
close(cmd_listen_fd);
+ close(inotify_fd);
if(!ret)
log_printf(NOTICE, "normal shutdown");