Showing
8 changed files
with
38 additions
and
26 deletions
... | ... | @@ -6,7 +6,7 @@ AC_INIT([taskrambler], [0.0.1], [Georg Hopp <georg@steffers.org>]) |
6 | 6 | LT_INIT |
7 | 7 | AM_INIT_AUTOMAKE |
8 | 8 | #AM_INIT_AUTOMAKE([subdir-objects]) |
9 | -#AM_SILENT_RULES([yes]) | |
9 | +AM_SILENT_RULES([yes]) | |
10 | 10 | AC_COPYRIGHT([Copyright © 2012 Georg Hopp]) |
11 | 11 | AC_REVISION([$Revision: 0.02 $]) |
12 | 12 | AC_CONFIG_SRCDIR([src/taskrambler.c]) | ... | ... |
... | ... | @@ -46,25 +46,26 @@ serverHandleAccept(Server this, unsigned int i) |
46 | 46 | acc = socketAccept((0 == i)? this->sock : this->sockSSL, &remoteAddr); |
47 | 47 | |
48 | 48 | if (-1 != acc->handle) { |
49 | - switch(i) { | |
50 | - case 0: | |
51 | - // no SSL | |
52 | - st = new(Stream, STREAM_FD, acc->handle); | |
53 | - break; | |
54 | - | |
55 | - case 1: | |
56 | - // SSL | |
57 | - { | |
58 | - SSL * ssl = SSL_new(this->ctx); | |
59 | - SSL_set_fd(ssl, acc->handle); | |
60 | - SSL_accept(ssl); | |
61 | - st = new(Stream, STREAM_SSL, ssl); | |
62 | - } | |
63 | - break; | |
64 | - | |
65 | - default: | |
66 | - break; | |
67 | - } | |
49 | + switch(i) { | |
50 | + case 0: | |
51 | + // no SSL | |
52 | + st = new(Stream, STREAM_FD, acc->handle); | |
53 | + break; | |
54 | + | |
55 | + case 1: | |
56 | + // SSL | |
57 | + { | |
58 | + SSL * ssl = SSL_new(this->ctx); | |
59 | + SSL_set_fd(ssl, acc->handle); | |
60 | + SSL_accept(ssl); | |
61 | + st = new(Stream, STREAM_SSL, ssl); | |
62 | + } | |
63 | + break; | |
64 | + | |
65 | + default: | |
66 | + st = NULL; | |
67 | + break; | |
68 | + } | |
68 | 69 | |
69 | 70 | // save the socket handle |
70 | 71 | (this->conns)[acc->handle].sock = acc; | ... | ... |
... | ... | @@ -74,8 +74,10 @@ main() |
74 | 74 | init_signals(); |
75 | 75 | daemonize(); |
76 | 76 | |
77 | - shm = shm_open("/fooshm", O_RDWR|O_CREAT, S_IRWXU); | |
78 | - ftruncate(shm, psize); | |
77 | + shm = shm_open("/fooshm", O_RDWR|O_CREAT, S_IRWXU); | |
78 | + if (-1 == ftruncate(shm, psize)) { | |
79 | + doShutdown = 1; | |
80 | + } | |
79 | 81 | |
80 | 82 | switch((pid = fork())) { |
81 | 83 | case -1: | ... | ... |
... | ... | @@ -26,6 +26,7 @@ |
26 | 26 | #include <unistd.h> // for getopt |
27 | 27 | #include <stdlib.h> |
28 | 28 | #include <unistd.h> |
29 | +#include <errno.h> | |
29 | 30 | |
30 | 31 | #include <sys/types.h> |
31 | 32 | #include <sys/stat.h> |
... | ... | @@ -56,8 +57,10 @@ void daemonize(void) { |
56 | 57 | |
57 | 58 | // set umask and change to working directory to / |
58 | 59 | umask(UMASK); |
59 | - chdir(PWD); // this should root and assets needs to be found | |
60 | - // via some kind of configuration. | |
60 | + if (-1 == chdir(PWD)) { // this should root and assets needs to be found | |
61 | + perror("daemonize"); // via some kind of configuration. | |
62 | + exit(EXIT_FAILURE); | |
63 | + } | |
61 | 64 | |
62 | 65 | // we should close all open filedescriptors now. |
63 | 66 | // But I assume that this function is called at the very start of the | ... | ... |
... | ... | @@ -80,7 +80,9 @@ testLoggerStderr() |
80 | 80 | { |
81 | 81 | logger = new(LoggerStderr, LOGGER_ERR); |
82 | 82 | |
83 | - freopen("/dev/null", "w", stderr); | |
83 | + if (NULL == freopen("/dev/null", "w", stderr)) { | |
84 | + return TEST_ERROR; | |
85 | + } | |
84 | 86 | loggerLog(logger, LOGGER_ERR, "foo %d %s", 123, "bar"); |
85 | 87 | |
86 | 88 | /** | ... | ... |
... | ... | @@ -84,7 +84,9 @@ testDummy() |
84 | 84 | con = new(Sock, logger, TEST_PORT); |
85 | 85 | sleep(1); |
86 | 86 | socketConnect(con, "127.0.0.1", &addr); |
87 | - write(con->handle, TEST_DATA, strlen(TEST_DATA)+1); | |
87 | + if(-1 == write(con->handle, TEST_DATA, strlen(TEST_DATA)+1)) { | |
88 | + exit(EXIT_FAILURE); | |
89 | + } | |
88 | 90 | sleep(1); |
89 | 91 | delete(con); |
90 | 92 | __tearDown(); | ... | ... |
Please
register
or
login
to post a comment