Commit bf1ab61e authored by Lubos Slovak's avatar Lubos Slovak

Formatted files in src/

- indentation
- spaces
- pointers
- 80-char lines with 8-char tabs
- file comment
- ifdefs
- doxygen grouping

refs #151
parent 81836149
#ifndef COMMON
#define COMMON
/*!
* \file common.h
*
* \author Lubos Slovak <lubos.slovak@nic.cz>
*
* \brief Common macros, includes and utilities.
*
* \addtogroup utils
* @{
*/
#ifndef _CUTEDNS_COMMON_H_
#define _CUTEDNS_COMMON_H_
#include <signal.h>
#include <stdint.h>
......@@ -27,7 +39,9 @@ typedef unsigned int uint;
/* Common macros.
*/
#define ERR_ALLOC_FAILED log_error("Allocation failed at %s:%d (%s ver.%x)\n", __FILE__, __LINE__, PROJECT_NAME, PROJECT_VER)
#define ERR_ALLOC_FAILED log_error("Allocation failed at %s:%d (%s ver.%x)\n", \
__FILE__, __LINE__, PROJECT_NAME, PROJECT_VER)
/* Eliminate compiler warning with unused parameters. */
#define UNUSED(param) (param) = (param)
......@@ -38,4 +52,6 @@ typedef unsigned int uint;
//#define STAT_COMPILE
#endif // COMMON
#endif /* _CUTEDNS_COMMON_H_ */
/*! @} */
......@@ -6,65 +6,65 @@
/*----------------------------------------------------------------------------*/
static volatile short s_stopping = 0;
static cute_server* s_server = NULL;
static cute_server *s_server = NULL;
// SIGINT signal handler
void interrupt_handle(int s)
{
// Omit other signals
if(s != SIGINT || s_server == NULL) {
return;
}
// Omit other signals
if (s != SIGINT || s_server == NULL) {
return;
}
// Stop server
if(s_stopping == 0) {
s_stopping = 1;
cute_stop(s_server);
}
else {
log_error("\nOK! OK! Exiting immediately.\n");
exit(1);
}
// Stop server
if (s_stopping == 0) {
s_stopping = 1;
cute_stop(s_server);
} else {
log_error("\nOK! OK! Exiting immediately.\n");
exit(1);
}
}
int main( int argc, char **argv )
int main(int argc, char **argv)
{
// Open log
log_open(LOG_UPTO(LOG_ERR), LOG_MASK(LOG_ERR)|LOG_MASK(LOG_WARNING));
// Open log
log_open(LOG_UPTO(LOG_ERR), LOG_MASK(LOG_ERR) | LOG_MASK(LOG_WARNING));
if (argc < 2) {
print_msg(LOG_ERR, "Usage: %s <filename1> [<filename2> ...] .\n",
argv[0]);
return -1;
}
if (argc < 2) {
print_msg(LOG_ERR, "Usage: %s <filename1> [<filename2> ...].\n",
argv[0]);
return -1;
}
int res = 0;
int res = 0;
// Create server instance
s_server = cute_create();
// Create server instance
s_server = cute_create();
// Run server
if ((res = cute_start(s_server, argv + 1, argc - 1)) == 0) {
// Run server
if ((res = cute_start(s_server, argv + 1, argc - 1)) == 0) {
// Register service and signal handler
struct sigaction sa;
sa.sa_handler = interrupt_handle;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sigaction(SIGINT, &sa, NULL);
sigaction(SIGALRM, &sa, NULL); // Interrupt
// Register service and signal handler
struct sigaction sa;
sa.sa_handler = interrupt_handle;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sigaction(SIGINT, &sa, NULL);
sigaction(SIGALRM, &sa, NULL); // Interrupt
if((res = cute_wait(s_server)) != 0) {
log_error("There was an error while waiting for server to finish.");
}
}
else {
log_error("There was an error while starting the server, exiting...\n");
}
if ((res = cute_wait(s_server)) != 0) {
log_error("There was an error while waiting for server"
" to finish.");
}
} else {
log_error("There was an error while starting the server, "
"exiting...\n");
}
// Stop server and close log
cute_destroy(&s_server);
log_close();
// Stop server and close log
cute_destroy(&s_server);
log_close();
return res;
return res;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment