From: Andre Date: Fri, 7 Apr 2006 13:07:08 +0000 (+0200) Subject: introduce mark_fd_nonblock() X-Git-Tag: v0.2.12~108 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=e57d2b9211bb734b71838142a7936fe6dfdc449c introduce mark_fd_nonblock() Calls fcntl(2) to prepare an fd for nonblocking file operations. Also, make fd.c and para_gui use the error subssytem. --- diff --git a/Makefile.in b/Makefile.in index d424c538..e01f9363 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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@ diff --git a/audiod.c b/audiod.c index 9e82b13a..9708f4fa 100644 --- 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); diff --git a/configure.ac b/configure.ac index f6b8733e..e9977e3f 100644 --- a/configure.ac +++ b/configure.ac @@ -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 ceaa6b38..d62781c4 100644 --- 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 b5310f81..c48f1fef 100644 --- 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 2db28f76..ed672151 100644 --- 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 de0e9c54..23257291 100644 --- a/gui.c +++ b/gui.c @@ -24,7 +24,10 @@ #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]; diff --git a/server.c b/server.c index 2f66dc4d..8f050096 100644 --- 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); diff --git a/signal.c b/signal.c index 5f121063..6de9adf8 100644 --- 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); }