]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
introduce mark_fd_nonblock()
authorAndre <maan@p133.(none)>
Fri, 7 Apr 2006 13:07:08 +0000 (15:07 +0200)
committerAndre <maan@p133.(none)>
Fri, 7 Apr 2006 13:07:08 +0000 (15:07 +0200)
Calls fcntl(2) to prepare an fd for nonblocking file operations. Also, make
fd.c and para_gui use the error subssytem.

Makefile.in
audiod.c
configure.ac
error.h
fd.c
fd.h
gui.c
server.c
signal.c

index d424c5388ffc0a8baaefd2714d34a6faa9468c06..e01f93639b8725b4cdc3d11a51441292ffb0f5a2 100644 (file)
@@ -101,8 +101,6 @@ all: $(BINARIES)
 www: $(gen_html) $(gruta_html) $(web_pics) $(web_misc) $(shots) tags doxygen
 
 client_objs = client.cmdline.o client.o net.o string.o crypt.o
-gui_objs = gui.cmdline.o gui.o gui_common.o exec.o close_on_fork.o signal.o \
-       string.o gui_theme.o stat.o ringbuffer.o fd.o
 sdl_gui_objs = sdl_gui.cmdline.o SFont.o sdl_gui.o gui_common.o exec.o \
        close_on_fork.o string.o stat.o fd.o
 dbadm_objs = dbadm.o exec.o close_on_fork.o string.o
@@ -177,8 +175,8 @@ para_slider: $(slider_objs)
 para_client: $(client_objs)
        $(CC) -o $@ $(client_objs) $(SSL_LDFLAGS) -lreadline -lncurses $(SSL_LIBS)
 
-para_gui: $(gui_objs)
-       $(CC) -o $@ $(gui_objs) -lncurses
+para_gui: @gui_objs@
+       $(CC) -o $@ @gui_objs@ -lncurses
 
 para_audiod: @audiod_objs@
        $(CC) -o $@ @audiod_objs@ @audiod_ldflags@
index 9e82b13a782580be39ffe04d9b4f5521cfe9b097..9708f4fa363f4ffa6d3540fc7cb27c79917f76ca 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -721,7 +721,7 @@ static void start_stream_writer(int slot_num)
        s->write_fd = fds[0];
        add_close_on_fork_list(s->write_fd);
        /* we write to this fd in do_select, so we need non-blocking */
-       fcntl(s->write_fd, F_SETFL, O_NONBLOCK);
+       mark_fd_nonblock(s->write_fd);
        gettimeofday(&s->wstime, NULL);
        current_decoder = slot_num;
        activate_inactive_grab_clients(slot_num, s->format, &s->fci->filters);
index f6b8733eb06e9f84f7e4810934b0acd3b89168d0..e9977e3f740e01b1bf9b99bae27b66f7ba6c1387 100644 (file)
@@ -296,6 +296,15 @@ AC_SUBST(server_objs, add_dot_o($server_objs))
 AC_SUBST(server_ldflags, $server_ldflags)
 AC_DEFINE_UNQUOTED(INIT_SERVER_ERRLISTS, 
        objlist_to_errlist($server_errlist_objs), errors used by para_server)
+
+gui_cmdline_objs="gui.cmdline"
+gui_errlist_objs="exec close_on_fork signal string stat ringbuffer fd"
+gui_other_objs="gui gui_common gui_theme"
+gui_objs="$gui_cmdline_objs $gui_errlist_objs $gui_other_objs"
+AC_DEFINE_UNQUOTED(INIT_GUI_ERRLISTS,
+       objlist_to_errlist($gui_errlist_objs), errors used by para_gui)
+AC_SUBST(gui_objs, add_dot_o($gui_objs))
+
 AC_OUTPUT
 AC_MSG_NOTICE([creating Makefile.deps])
 gcc -MM -MG *.c > Makefile.deps
diff --git a/error.h b/error.h
index ceaa6b38b2c6b6102ef6689e9be1d46ec48b6baf..d62781c449b53f09bc628aee0101e3b9d635847a 100644 (file)
--- a/error.h
+++ b/error.h
@@ -57,6 +57,7 @@ enum para_subsystem {
        SS_DCCP_RECV,
        SS_DCCP_SEND,
        SS_FD,
+       SS_GUI,
        SS_RINGBUFFER};
 
 #define NUM_SS (SS_RINGBUFFER + 1)
@@ -157,6 +158,7 @@ extern const char **para_errlist[];
        PARA_ERROR(SIGNAL_SIG_ERR, "signal() retured SIG_ERR"), \
        PARA_ERROR(SIGNAL_READ, "read error from signal pipe"), \
        PARA_ERROR(WAITPID, "waitpid error"), \
+       PARA_ERROR(SIGNAL_PIPE, "failed to setup signal pipe"), \
 
 
 #define STRING_ERRORS \
@@ -287,6 +289,9 @@ extern const char **para_errlist[];
        PARA_ERROR(DCCP_LISTEN, "dccp listen error"), \
        PARA_ERROR(DCCP_WRITE, "dccp write error"), \
 
+#define FD_ERRORS \
+       PARA_ERROR(F_GETFL, "failed to get fd flags"), \
+       PARA_ERROR(F_SETFL, "failed to set fd flags")
 
 /* these do not need error handling (yet) */
 #define SERVER_ERRORS
@@ -296,8 +301,8 @@ extern const char **para_errlist[];
 #define CLOSE_ON_FORK_ERRORS
 #define DAEMON_ERRORS
 #define ORTP_SEND_ERRORS
+#define GUI_ERRORS
 #define RINGBUFFER_ERRORS
-#define FD_ERRORS
 
 
 /**
@@ -407,6 +412,7 @@ SS_ENUM(DCCP);
 SS_ENUM(DCCP_RECV);
 SS_ENUM(DCCP_SEND);
 SS_ENUM(FD);
+SS_ENUM(GUI);
 SS_ENUM(RINGBUFFER);
 /** \endcond */
 #undef PARA_ERROR
diff --git a/fd.c b/fd.c
index b5310f8128c85563bf2f99f30e833eb59455f6e1..c48f1fef175708331706594f51d54e6d69d0662f 100644 (file)
--- a/fd.c
+++ b/fd.c
@@ -1,4 +1,5 @@
 #include "para.h"
+#include "error.h"
 /**
  * check whether a file exists
  *
@@ -25,3 +26,14 @@ int para_select(int n, fd_set *readfds, fd_set *writefds,
                PARA_CRIT_LOG("select error (%s)\n", strerror(err));
        return ret;
 }
+
+int mark_fd_nonblock(int fd)
+{
+       int flags = fcntl(fd, F_GETFL);
+       if (flags < 0)
+               return -E_F_GETFL;
+       if (fcntl(fd, F_SETFL, ((long)flags) | O_NONBLOCK) < 0)
+               return -E_F_SETFL;
+       return 1;
+}
+
diff --git a/fd.h b/fd.h
index 2db28f761c06f9c62378cefb3a6f1d88ed8a556a..ed672151f9cdeb7b3918efed75c34e7997a2d670 100644 (file)
--- a/fd.h
+++ b/fd.h
@@ -19,6 +19,6 @@
 /** \file fd.h file handling functions */
 
 int file_exists(const char *);
-
 int para_select(int n, fd_set *readfds, fd_set *writefds,
                struct timeval *timeout);
+int mark_fd_nonblock(int fd);
diff --git a/gui.c b/gui.c
index de0e9c54a2729c4d597b8521989c233bf8340bb1..232572914bd9b7ca83038a334a7cff1b3ce2fdaf 100644 (file)
--- a/gui.c
+++ b/gui.c
 #include "ringbuffer.h"
 #include "string.h"
 #include "fd.h"
+#include "error.h"
 
+/** define the array of error lists needed by para_gui */
+INIT_GUI_ERRLISTS;
 extern const char *status_item_list[NUM_STAT_ITEMS];
 static char *stat_content[NUM_STAT_ITEMS];
 
index 2f66dc4da17833b2ac32464746645e978d8752c8..8f0500965ca1461dbe4d661ff4086ed95793cad9 100644 (file)
--- a/server.c
+++ b/server.c
@@ -269,7 +269,6 @@ static void setup_signal_handling(void)
        int ret = 0;
 
        signal_pipe = para_signal_init();
-//     fcntl(signal_pipe, F_SETFL, O_NONBLOCK);
        PARA_NOTICE_LOG("%s", "setting up signal handlers\n");
        ret += para_install_sighandler(SIGINT);
        ret += para_install_sighandler(SIGTERM);
index 5f121063c10591731a253fb1f227dd1bb0f29da5..6de9adf817f1a7b1885133729cd741dcff72399f 100644 (file)
--- a/signal.c
+++ b/signal.c
@@ -18,6 +18,7 @@
 /** \file signal.c signal handling functions */
 
 #include "para.h"
+#include "fd.h"
 #include "error.h"
 static int signal_pipe[2];
 
@@ -41,19 +42,18 @@ static int signal_pipe[2];
  */
 int para_signal_init(void)
 {
-       int i;
+       int ret = -E_SIGNAL_PIPE;
        if (pipe(signal_pipe))
                goto err_out;
-       for (i = 0; i < 2; i++) {
-               int fd = signal_pipe[i], flags = fcntl(fd, F_GETFL);
-               if (flags < 0)
-                       goto err_out;
-               if (fcntl(fd, F_SETFL, ((long)flags) | O_NONBLOCK) < 0)
-                       goto err_out;
-       }
+       ret = mark_fd_nonblock(signal_pipe[0]);
+       if (ret < 0)
+               goto err_out;
+       ret = mark_fd_nonblock(signal_pipe[1]);
+       if (ret < 0)
+               goto err_out;
        return signal_pipe[0];
 err_out:
-       PARA_EMERG_LOG("%s", "pipe error: Can not setup signal pipe");
+       PARA_EMERG_LOG("%s\n", PARA_STRERROR(-ret));
        exit(EXIT_FAILURE);
 }