From 63519d6ae4cb20ae4871310e09a28fd59f5c9fc7 Mon Sep 17 00:00:00 2001 From: Johann Latocha Date: Tue, 31 Jan 2012 23:52:24 +0100 Subject: [ALL] Some refactoring --- CMakeLists.txt | 11 +++- src/client/client.c | 12 ++-- src/kernel/blk.c | 8 +-- src/kernel/blk.h | 4 +- src/kernel/core.c | 2 +- src/kernel/dnbd3.h | 4 +- src/kernel/net.c | 18 +++--- src/kernel/net.h | 4 +- src/server/net.c | 133 +++++++++++++++++++++++++++++++++++++++ src/server/net.h | 28 +++++++++ src/server/server.c | 178 +++++++++------------------------------------------- src/server/server.h | 34 ++++++++++ src/server/signal.c | 45 +++++++++++++ src/server/signal.h | 30 +++++++++ src/server/utils.h | 2 +- src/types.h | 4 +- 16 files changed, 337 insertions(+), 180 deletions(-) create mode 100644 src/server/net.c create mode 100644 src/server/net.h create mode 100644 src/server/server.h create mode 100644 src/server/signal.c create mode 100644 src/server/signal.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 78deb01..9788595 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,9 +11,14 @@ SET(CMAKE_C_FLAGS_RELEASE "-O2 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64") SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -Wall -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64") SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64" ) -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}) +FIND_PACKAGE(Threads REQUIRED) +FIND_PACKAGE(PkgConfig REQUIRED) + +PKG_CHECK_MODULES(GLIB glib-2.0) + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${GLIB_INCLUDE_DIRS}) + -FIND_PACKAGE(Threads) ################################################################################ # CLIENT # @@ -30,7 +35,7 @@ ADD_EXECUTABLE(dnbd3-client ${CLIENT_SRCS}) FILE(GLOB_RECURSE SERVER_SRCS src/server/*.c) ADD_EXECUTABLE(dnbd3-server ${SERVER_SRCS}) -TARGET_LINK_LIBRARIES(dnbd3-server ${CMAKE_THREAD_LIBS_INIT}) +TARGET_LINK_LIBRARIES(dnbd3-server ${CMAKE_THREAD_LIBS_INIT} ${GLIB_LDFLAGS}) ################################################################################ diff --git a/src/client/client.c b/src/client/client.c index c51ff86..61724d5 100644 --- a/src/client/client.c +++ b/src/client/client.c @@ -29,7 +29,7 @@ #include "../types.h" #include "../version.h" -void print_help(char* argv_0) +void dnbd3_print_help(char* argv_0) { printf("Usage: %s -H -p -i -d \n", argv_0); printf("Start the DNBD3 client.\n"); @@ -43,7 +43,7 @@ void print_help(char* argv_0) exit(EXIT_SUCCESS); } -void print_version() +void dnbd3_print_version() { printf("Version: %s\n", VERSION_STRING); exit(EXIT_SUCCESS); @@ -94,13 +94,13 @@ int main(int argc, char *argv[]) change_host = 1; break; case 'h': - print_help(argv[0]); + dnbd3_print_help(argv[0]); break; case 'v': - print_version(); + dnbd3_print_version(); break; case '?': - print_help(argv[0]); + dnbd3_print_help(argv[0]); } opt = getopt_long(argc, argv, optString, longOpts, &longIndex); } @@ -144,6 +144,6 @@ int main(int argc, char *argv[]) exit(EXIT_SUCCESS); } - print_help(argv[0]); + dnbd3_print_help(argv[0]); exit(EXIT_FAILURE); } diff --git a/src/kernel/blk.c b/src/kernel/blk.c index 7a61ba3..ccc45dc 100644 --- a/src/kernel/blk.c +++ b/src/kernel/blk.c @@ -21,7 +21,7 @@ #include "blk.h" #include "net.h" -int dnbd3_blk_add_device(struct dnbd3_device *dev, int minor) +int dnbd3_blk_add_device(dnbd3_device_t *dev, int minor) { struct gendisk *disk; struct request_queue *blk_queue; @@ -63,7 +63,7 @@ int dnbd3_blk_add_device(struct dnbd3_device *dev, int minor) return 0; } -int dnbd3_blk_del_device(struct dnbd3_device *dev) +int dnbd3_blk_del_device(dnbd3_device_t *dev) { if (dev->sock) { @@ -85,7 +85,7 @@ struct block_device_operations dnbd3_blk_ops = int dnbd3_blk_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg) { - struct dnbd3_device *lo = bdev->bd_disk->private_data; + dnbd3_device_t *lo = bdev->bd_disk->private_data; switch (cmd) { @@ -121,7 +121,7 @@ int dnbd3_blk_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, u void dnbd3_blk_request(struct request_queue *q) { struct request *req; - struct dnbd3_device *lo; + dnbd3_device_t *lo; while ((req = blk_fetch_request(q)) != NULL) { diff --git a/src/kernel/blk.h b/src/kernel/blk.h index 039d991..bf5ad80 100644 --- a/src/kernel/blk.h +++ b/src/kernel/blk.h @@ -29,8 +29,8 @@ int dnbd3_blk_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, u void dnbd3_blk_request(struct request_queue *q); -int dnbd3_blk_add_device(struct dnbd3_device *dev, int minor); +int dnbd3_blk_add_device(dnbd3_device_t *dev, int minor); -int dnbd3_blk_del_device(struct dnbd3_device *dev); +int dnbd3_blk_del_device(dnbd3_device_t *dev); #endif /* BLK_H_ */ diff --git a/src/kernel/core.c b/src/kernel/core.c index 6b50aaa..0e81fdd 100644 --- a/src/kernel/core.c +++ b/src/kernel/core.c @@ -22,7 +22,7 @@ #include "blk.h" int major; -struct dnbd3_device dnbd3_device[MAX_NUMBER_DEVICES]; +dnbd3_device_t dnbd3_device[MAX_NUMBER_DEVICES]; static int __init dnbd3_init(void) { diff --git a/src/kernel/dnbd3.h b/src/kernel/dnbd3.h index ec9dd6e..13af803 100644 --- a/src/kernel/dnbd3.h +++ b/src/kernel/dnbd3.h @@ -31,7 +31,7 @@ extern int major; -struct dnbd3_device +typedef struct { // block struct gendisk *disk; @@ -53,6 +53,6 @@ struct dnbd3_device struct list_head request_queue_send; struct list_head request_queue_receive; -}; +} dnbd3_device_t; #endif /* DNBD_H_ */ diff --git a/src/kernel/net.c b/src/kernel/net.c index 8f3227a..dba45c6 100644 --- a/src/kernel/net.c +++ b/src/kernel/net.c @@ -21,13 +21,13 @@ #include "net.h" #include "utils.h" -void dnbd3_net_connect(struct dnbd3_device *lo) +void dnbd3_net_connect(dnbd3_device_t *lo) { struct sockaddr_in sin; struct msghdr msg; struct kvec iov; - struct dnbd3_request dnbd3_request; - struct dnbd3_reply dnbd3_reply; + dnbd3_request_t dnbd3_request; + dnbd3_reply_t dnbd3_reply; if (!lo->host || !lo->port || !lo->image_id) { @@ -98,7 +98,7 @@ void dnbd3_net_connect(struct dnbd3_device *lo) add_timer(&lo->hb_timer); } -void dnbd3_net_disconnect(struct dnbd3_device *lo) +void dnbd3_net_disconnect(dnbd3_device_t *lo) { struct request *blk_request, *tmp_request; printk("INFO: Disconnecting device %s\n", lo->disk->disk_name); @@ -133,8 +133,8 @@ void dnbd3_net_disconnect(struct dnbd3_device *lo) int dnbd3_net_send(void *data) { - struct dnbd3_device *lo = data; - struct dnbd3_request dnbd3_request; + dnbd3_device_t *lo = data; + dnbd3_request_t dnbd3_request; struct request *blk_request; struct msghdr msg; struct kvec iov; @@ -196,8 +196,8 @@ int dnbd3_net_send(void *data) int dnbd3_net_receive(void *data) { - struct dnbd3_device *lo = data; - struct dnbd3_reply dnbd3_reply; + dnbd3_device_t *lo = data; + dnbd3_reply_t dnbd3_reply; struct request *blk_request; struct msghdr msg; struct kvec iov; @@ -281,7 +281,7 @@ int dnbd3_net_receive(void *data) void dnbd3_net_heartbeat(unsigned long arg) { - struct dnbd3_device *lo = (struct dnbd3_device *) arg; + dnbd3_device_t *lo = (dnbd3_device_t *) arg; list_add(&lo->hb_request.queuelist, &lo->request_queue_send); wake_up(&lo->process_queue_send); lo->hb_timer.expires = jiffies + HB_INTERVAL; diff --git a/src/kernel/net.h b/src/kernel/net.h index 66bc195..b9b31a4 100644 --- a/src/kernel/net.h +++ b/src/kernel/net.h @@ -23,9 +23,9 @@ #include "dnbd3.h" -void dnbd3_net_connect(struct dnbd3_device *lo); +void dnbd3_net_connect(dnbd3_device_t *lo); -void dnbd3_net_disconnect(struct dnbd3_device *lo); +void dnbd3_net_disconnect(dnbd3_device_t *lo); int dnbd3_net_send(void *data); diff --git a/src/server/net.c b/src/server/net.c new file mode 100644 index 0000000..87af60f --- /dev/null +++ b/src/server/net.c @@ -0,0 +1,133 @@ +/* + * This file is part of the Distributed Network Block Device 3 + * + * Copyright(c) 2011-2012 Johann Latocha + * + * This file may be licensed under the terms of of the + * GNU General Public License Version 2 (the ``GPL''). + * + * Software distributed under the License is distributed + * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either + * express or implied. See the GPL for the specific language + * governing rights and limitations. + * + * You should have received a copy of the GPL along with this + * program. If not, go to http://www.gnu.org/licenses/gpl.html + * or write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "server.h" +#include "hashtable.h" + +void *dnbd3_handle_query(void *client_socket) +{ + int image_file = -1; + off_t filesize = 0; + int sock = (int) (uintptr_t) client_socket; + dnbd3_request_t request; + dnbd3_reply_t reply; + uint16_t cmd; + + while (recv(sock, &request, sizeof(dnbd3_request_t), MSG_WAITALL) > 0) + { + cmd = request.cmd; + switch (cmd) + { + case CMD_PING: + reply.cmd = request.cmd; + memcpy(reply.handle, request.handle, sizeof(request.handle)); + send(sock, (char *) &reply, sizeof(dnbd3_reply_t), 0); + break; + + case CMD_GET_SIZE: + pthread_spin_lock(&_spinlock); // because of reloading config + image_file = open(dnbd3_ht_search(request.image_id), O_RDONLY); + pthread_spin_unlock(&_spinlock); + if (image_file < 0) + { + printf("ERROR: Client requested an unknown image id.\n"); + filesize = 0; + } + else + { + struct stat st; + fstat(image_file, &st); + filesize = st.st_size; + } + reply.cmd = request.cmd; + reply.filesize = filesize; + send(sock, (char *) &reply, sizeof(dnbd3_reply_t), 0); + break; + + case CMD_GET_BLOCK: + if (image_file < 0) + break; + + reply.cmd = request.cmd; + memcpy(reply.handle, request.handle, sizeof(request.handle)); + send(sock, (char *) &reply, sizeof(dnbd3_reply_t), 0); + + if (sendfile(sock, image_file, (off_t *) &request.offset, request.size) < 0) + printf("ERROR: sendfile returned -1\n"); + + break; + + default: + printf("ERROR: Unknown command\n"); + break; + } + + } + close(sock); + printf("INFO: Client exit.\n"); + pthread_exit((void *) 0); +} + +int dnbd3_setup_socket() +{ + int sock; + struct sockaddr_in server; + + // Create socket + sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + if (sock < 0) + { + printf("ERROR: Socket failure\n"); + return -1; + } + + memset(&server, 0, sizeof(server)); + server.sin_family = AF_INET; // IPv4 + server.sin_addr.s_addr = htonl(INADDR_ANY); // Take all IPs + server.sin_port = htons(PORT); // set port number + + // Bind to socket + if (bind(sock, (struct sockaddr*) &server, sizeof(server)) < 0) + { + printf("ERROR: Bind failure\n"); + return -1; + } + + // Listen on socket + if (listen(sock, 50) == -1) + { + printf("ERROR: Listen failure\n"); + return -1; + } + + return sock; +} diff --git a/src/server/net.h b/src/server/net.h new file mode 100644 index 0000000..3e34c99 --- /dev/null +++ b/src/server/net.h @@ -0,0 +1,28 @@ +/* + * This file is part of the Distributed Network Block Device 3 + * + * Copyright(c) 2011-2012 Johann Latocha + * + * This file may be licensed under the terms of of the + * GNU General Public License Version 2 (the ``GPL''). + * + * Software distributed under the License is distributed + * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either + * express or implied. See the GPL for the specific language + * governing rights and limitations. + * + * You should have received a copy of the GPL along with this + * program. If not, go to http://www.gnu.org/licenses/gpl.html + * or write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef NET_H_ +#define NET_H_ + +void *dnbd3_handle_query(void *client_socket); + +int dnbd3_setup_socket(); + +#endif /* NET_H_ */ diff --git a/src/server/server.c b/src/server/server.c index 0b327e3..e15249b 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -20,33 +20,26 @@ #include #include -#include -#include -#include -#include -#include -#include #include -#include #include #include -#include -#include -#include - #include #include "../types.h" #include "../version.h" +#include "server.h" #include "utils.h" #include "hashtable.h" +#include "signal.h" +#include "net.h" int _sock; -pthread_spinlock_t spinlock; -char *config_file_name = DEFAULT_CONFIG_FILE; -void print_help(char* argv_0) +pthread_spinlock_t _spinlock; +char *_config_file_name = DEFAULT_CONFIG_FILE; + +void dnbd3_print_help(char* argv_0) { printf("Usage: %s [OPTIONS]...\n", argv_0); printf("Start the DNBD3 server\n"); @@ -59,104 +52,19 @@ void print_help(char* argv_0) exit(0); } -void print_version() +void dnbd3_print_version() { printf("Version: %s\n", VERSION_STRING); exit(0); } -void cleanup() +void dnbd3_cleanup() { close(_sock); dnbd3_delete_pid_file(); exit(EXIT_SUCCESS); } -void handle_sigpipe(int signum) -{ - printf("ERROR: Received signal SIGPIPE, Broken pipe (errno: %i)\n", errno); - return; -} - -void handle_sighup(int signum) -{ - printf("INFO: SIGHUP received!\n"); - printf("INFO: Reloading configuration...\n"); - pthread_spin_lock(&spinlock); - dnbd3_reload_config(config_file_name); - pthread_spin_unlock(&spinlock); -} - -void handle_sigterm(int signum) -{ - printf("INFO: SIGTERM or SIGINT received!\n"); - cleanup(); -} - -void *handle_query(void *client_socket) -{ - int image_file = -1; - off_t filesize = 0; - int sock = (int) (uintptr_t) client_socket; - struct dnbd3_request request; - struct dnbd3_reply reply; - uint16_t cmd; - - while (recv(sock, &request, sizeof(struct dnbd3_request), MSG_WAITALL) > 0) - { - cmd = request.cmd; - switch (cmd) - { - case CMD_PING: - reply.cmd = request.cmd; - memcpy(reply.handle, request.handle, sizeof(request.handle)); - send(sock, (char *) &reply, sizeof(struct dnbd3_reply), 0); - break; - - case CMD_GET_SIZE: - pthread_spin_lock(&spinlock); // because of reloading config - image_file = open(dnbd3_ht_search(request.image_id), O_RDONLY); - pthread_spin_unlock(&spinlock); - if (image_file < 0) - { - printf("ERROR: Client requested an unknown image id.\n"); - filesize = 0; - } - else - { - struct stat st; - fstat(image_file, &st); - filesize = st.st_size; - } - reply.cmd = request.cmd; - reply.filesize = filesize; - send(sock, (char *) &reply, sizeof(struct dnbd3_reply), 0); - break; - - case CMD_GET_BLOCK: - if (image_file < 0) - break; - - reply.cmd = request.cmd; - memcpy(reply.handle, request.handle, sizeof(request.handle)); - send(sock, (char *) &reply, sizeof(struct dnbd3_reply), 0); - - if (sendfile(sock, image_file, (off_t *) &request.offset, request.size) < 0) - printf("ERROR: sendfile returned -1\n"); - - break; - - default: - printf("ERROR: Unknown command\n"); - break; - } - - } - close(sock); - printf("INFO: Client exit.\n"); - pthread_exit((void *) 0); -} - int main(int argc, char* argv[]) { int demonize = 1; @@ -179,7 +87,7 @@ int main(int argc, char* argv[]) switch (opt) { case 'f': - config_file_name = optarg; + _config_file_name = optarg; break; case 'n': demonize = 0; @@ -193,13 +101,13 @@ int main(int argc, char* argv[]) dnbd3_send_signal(SIGTERM); return EXIT_SUCCESS; case 'h': - print_help(argv[0]); + dnbd3_print_help(argv[0]); break; case 'v': - print_version(); + dnbd3_print_version(); break; case '?': - exit(1); + dnbd3_print_help(argv[0]); } opt = getopt_long(argc, argv, optString, longOpts, &longIndex); } @@ -208,63 +116,37 @@ int main(int argc, char* argv[]) daemon(1, 0); // load config file - pthread_spin_init(&spinlock, PTHREAD_PROCESS_PRIVATE); - dnbd3_load_config(config_file_name); + pthread_spin_init(&_spinlock, PTHREAD_PROCESS_PRIVATE); + dnbd3_load_config(_config_file_name); // setup signal handler - signal(SIGPIPE, handle_sigpipe); - signal(SIGHUP, handle_sighup); - signal(SIGTERM, handle_sigterm); - signal(SIGINT, handle_sigterm); + signal(SIGPIPE, dnbd3_handle_sigpipe); + signal(SIGHUP, dnbd3_handle_sighup); + signal(SIGTERM, dnbd3_handle_sigterm); + signal(SIGINT, dnbd3_handle_sigterm); // setup network - struct sockaddr_in server; - struct sockaddr_in client; - int fd; - unsigned int len; - - // Create socket - _sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + _sock = dnbd3_setup_socket(); if (_sock < 0) - { - printf("ERROR: Socket failure\n"); - exit(EXIT_FAILURE); - } - - memset(&server, 0, sizeof(server)); - server.sin_family = AF_INET; // IPv4 - server.sin_addr.s_addr = htonl(INADDR_ANY); // Take all IPs - server.sin_port = htons(PORT); // set port number - - // Bind to socket - if (bind(_sock, (struct sockaddr*) &server, sizeof(server)) < 0) - { - printf("ERROR: Bind failure\n"); - exit(EXIT_FAILURE); - } - - // Listen on socket - if (listen(_sock, 50) == -1) - { - printf("ERROR: Listen failure\n"); exit(EXIT_FAILURE); - } - - dnbd3_write_pid_file(getpid()); - printf("INFO: Server is ready...\n"); - + struct sockaddr_in client; + unsigned int len = sizeof(client); + int fd; struct timeval timeout; timeout.tv_sec = SERVER_SOCKET_TIMEOUT; timeout.tv_usec = 0; + dnbd3_write_pid_file(getpid()); + printf("INFO: Server is ready...\n"); + + // main loop while (1) { - len = sizeof(client); fd = accept(_sock, (struct sockaddr*) &client, &len); if (fd < 0) { printf("ERROR: Accept failure\n"); - exit(EXIT_FAILURE); + continue; } printf("INFO: Client: %s connected\n", inet_ntoa(client.sin_addr)); @@ -273,9 +155,9 @@ int main(int argc, char* argv[]) // FIXME: catch SIGKILL/SIGTERM and close all socket before exit pthread_t thread; - pthread_create(&(thread), NULL, handle_query, (void *) (uintptr_t) fd); + pthread_create(&(thread), NULL, dnbd3_handle_query, (void *) (uintptr_t) fd); pthread_detach(thread); } - cleanup(); + dnbd3_cleanup(); } diff --git a/src/server/server.h b/src/server/server.h new file mode 100644 index 0000000..3918faf --- /dev/null +++ b/src/server/server.h @@ -0,0 +1,34 @@ +/* + * This file is part of the Distributed Network Block Device 3 + * + * Copyright(c) 2011-2012 Johann Latocha + * + * This file may be licensed under the terms of of the + * GNU General Public License Version 2 (the ``GPL''). + * + * Software distributed under the License is distributed + * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either + * express or implied. See the GPL for the specific language + * governing rights and limitations. + * + * You should have received a copy of the GPL along with this + * program. If not, go to http://www.gnu.org/licenses/gpl.html + * or write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef SERVER_H_ +#define SERVER_H_ + +#include + +#include "config.h" +#include "../types.h" + +extern pthread_spinlock_t _spinlock; +extern char *_config_file_name; + +void dnbd3_cleanup(); + +#endif /* SERVER_H_ */ diff --git a/src/server/signal.c b/src/server/signal.c new file mode 100644 index 0000000..443742f --- /dev/null +++ b/src/server/signal.c @@ -0,0 +1,45 @@ +/* + * This file is part of the Distributed Network Block Device 3 + * + * Copyright(c) 2011-2012 Johann Latocha + * + * This file may be licensed under the terms of of the + * GNU General Public License Version 2 (the ``GPL''). + * + * Software distributed under the License is distributed + * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either + * express or implied. See the GPL for the specific language + * governing rights and limitations. + * + * You should have received a copy of the GPL along with this + * program. If not, go to http://www.gnu.org/licenses/gpl.html + * or write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include +#include + +#include "server.h" +#include "utils.h" + +void dnbd3_handle_sigpipe(int signum) +{ + printf("ERROR: SIGPIPE received!\n"); +} + +void dnbd3_handle_sighup(int signum) +{ + printf("INFO: SIGHUP received!\n"); + printf("INFO: Reloading configuration...\n"); + pthread_spin_lock(&_spinlock); + dnbd3_reload_config(_config_file_name); + pthread_spin_unlock(&_spinlock); +} + +void dnbd3_handle_sigterm(int signum) +{ + printf("INFO: SIGTERM or SIGINT received!\n"); + dnbd3_cleanup(); +} diff --git a/src/server/signal.h b/src/server/signal.h new file mode 100644 index 0000000..d91babf --- /dev/null +++ b/src/server/signal.h @@ -0,0 +1,30 @@ +/* + * This file is part of the Distributed Network Block Device 3 + * + * Copyright(c) 2011-2012 Johann Latocha + * + * This file may be licensed under the terms of of the + * GNU General Public License Version 2 (the ``GPL''). + * + * Software distributed under the License is distributed + * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either + * express or implied. See the GPL for the specific language + * governing rights and limitations. + * + * You should have received a copy of the GPL along with this + * program. If not, go to http://www.gnu.org/licenses/gpl.html + * or write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef SIGNAL_H_ +#define SIGNAL_H_ + +void dnbd3_handle_sigpipe(int signum); + +void dnbd3_handle_sighup(int signum); + +void dnbd3_handle_sigterm(int signum); + +#endif /* SIGNAL_H_ */ diff --git a/src/server/utils.h b/src/server/utils.h index 67a5444..ab8f839 100644 --- a/src/server/utils.h +++ b/src/server/utils.h @@ -26,8 +26,8 @@ #ifndef UTILS_H_ #define UTILS_H_ -void dnbd3_write_pid_file(pid_t pid); pid_t dnbd3_read_pid_file(); +void dnbd3_write_pid_file(pid_t pid); void dnbd3_delete_pid_file(); void dnbd3_load_config(char* config_file_name); diff --git a/src/types.h b/src/types.h index cdde4bd..9bc0795 100644 --- a/src/types.h +++ b/src/types.h @@ -37,7 +37,7 @@ #define CMD_PING 3 #pragma pack(1) -typedef struct dnbd3_request +typedef struct { uint16_t cmd; uint64_t offset; @@ -48,7 +48,7 @@ typedef struct dnbd3_request #pragma pack(0) #pragma pack(1) -typedef struct dnbd3_reply +typedef struct { uint16_t cmd; uint64_t filesize; -- cgit v1.2.3-55-g7522