From: Axel Wagner Date: Thu, 28 Apr 2011 17:54:31 +0000 (+0200) Subject: Fix compiler-warnings from libev X-Git-Tag: 4.0.1~7^2~6 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=31f661ec7390c7fde51f6483d59ef1cd22ddd9a2;p=i3%2Fi3 Fix compiler-warnings from libev --- diff --git a/i3bar/src/ipc.c b/i3bar/src/ipc.c index d5c18033..e7303bf8 100644 --- a/i3bar/src/ipc.c +++ b/i3bar/src/ipc.c @@ -20,8 +20,8 @@ #include "common.h" -ev_io i3_connection; -ev_timer reconn; +ev_io *i3_connection; +ev_timer *reconn = NULL; const char *sock_path; @@ -52,8 +52,14 @@ void retry_connection(struct ev_loop *loop, ev_timer *w, int events) { * */ void reconnect() { - ev_timer_init(&reconn, retry_connection, 0.25, 0.25); - ev_timer_start(main_loop, &reconn); + if (reconn == NULL) { + if ((reconn = malloc(sizeof(ev_timer))) == NULL) { + ELOG("malloc() failed: %s\n", strerror(errno)); + exit(EXIT_FAILURE); + } + } + ev_timer_init(reconn, retry_connection, 0.25, 0.25); + ev_timer_start(main_loop, reconn); } /* @@ -255,7 +261,7 @@ int i3_send_msg(uint32_t type, const char *payload) { uint32_t written = 0; while (to_write > 0) { - int n = write(i3_connection.fd, buffer + written, to_write); + int n = write(i3_connection->fd, buffer + written, to_write); if (n == -1) { ELOG("write() failed: %s\n", strerror(errno)); exit(EXIT_FAILURE); @@ -293,8 +299,13 @@ int init_connection(const char *socket_path) { return 0; } - ev_io_init(&i3_connection, &got_data, sockfd, EV_READ); - ev_io_start(main_loop, &i3_connection); + i3_connection = malloc(sizeof(ev_io)); + if (i3_connection == NULL) { + ELOG("malloc() failed: %s\n", strerror(errno)); + exit(EXIT_FAILURE); + } + ev_io_init(i3_connection, &got_data, sockfd, EV_READ); + ev_io_start(main_loop, i3_connection); return 1; } @@ -302,8 +313,8 @@ int init_connection(const char *socket_path) { * Destroy the connection to i3. */ void destroy_connection() { - close(i3_connection.fd); - ev_io_stop(main_loop, &i3_connection); + close(i3_connection->fd); + ev_io_stop(main_loop, i3_connection); } /* diff --git a/i3bar/src/main.c b/i3bar/src/main.c index dd3b9315..14bd917d 100644 --- a/i3bar/src/main.c +++ b/i3bar/src/main.c @@ -232,15 +232,22 @@ int main(int argc, char **argv) { /* We listen to SIGTERM/QUIT/INT and try to exit cleanly, by stopping the main-loop. * We only need those watchers on the stack, so putting them on the stack saves us * some calls to free() */ - ev_signal sig_term, sig_int, sig_hup; + ev_signal *sig_term = malloc(sizeof(ev_signal)); + ev_signal *sig_int = malloc(sizeof(ev_signal)); + ev_signal *sig_hup = malloc(sizeof(ev_signal)); - ev_signal_init(&sig_term, &sig_cb, SIGTERM); - ev_signal_init(&sig_int, &sig_cb, SIGINT); - ev_signal_init(&sig_hup, &sig_cb, SIGHUP); + if (sig_term == NULL || sig_int == NULL || sig_hup == NULL) { + ELOG("malloc() failed: %s\n", strerror(errno)); + exit(EXIT_FAILURE); + } + + ev_signal_init(sig_term, &sig_cb, SIGTERM); + ev_signal_init(sig_int, &sig_cb, SIGINT); + ev_signal_init(sig_hup, &sig_cb, SIGHUP); - ev_signal_start(main_loop, &sig_term); - ev_signal_start(main_loop, &sig_int); - ev_signal_start(main_loop, &sig_hup); + ev_signal_start(main_loop, sig_term); + ev_signal_start(main_loop, sig_int); + ev_signal_start(main_loop, sig_hup); /* From here on everything should run smooth for itself, just start listening for * events. We stop simply stop the event-loop, when we are finished */