diff --git a/flexnbd.c b/flexnbd.c index b130d52..bc3e2d4 100644 --- a/flexnbd.c +++ b/flexnbd.c @@ -14,10 +14,14 @@ void syntax() { fprintf(stderr, - "Syntax: flexnbd serve [ip addresses ...]\n" + "Syntax: flexnbd serve \\\n" + " [full path to control socket] \\\n" + " [allowed connection addresses ...]\n" + " flexnbd mirror \n" + " flexnbd status \n" " flexnbd read > data\n" " flexnbd write < data\n" - " flexnbd write \n" + " flexnbd write \n" ); exit(1); } @@ -102,7 +106,7 @@ void params_serve( char* s_port, char* s_file, int acl_entries, - char** s_acl_entries + char** s_acl_entries /* first may actually be path to control socket */ ) { int parsed; @@ -120,6 +124,12 @@ void params_serve( SERVER_ERROR("Couldn't parse server address '%s' (use 0 if " "you want to bind to all IPs)", s_ip_address); + if (acl_entries > 0 && s_acl_entries[0][0] == '/') { + out->control_socket_name = s_acl_entries[0]; + s_acl_entries++; + acl_entries--; + } + out->acl_entries = acl_entries; parsed = parse_acl(&out->acl, acl_entries, s_acl_entries); if (parsed != acl_entries) diff --git a/ioutil.c b/ioutil.c index af2e753..73f8665 100644 --- a/ioutil.c +++ b/ioutil.c @@ -44,7 +44,7 @@ char* build_allocation_map(int fd, off64_t size, int resolution) fiemap->fm_extent_count = fiemap->fm_mapped_extents; fiemap->fm_mapped_extents = 0; - if (ioctl(fd, FS_IOC_FIEMAP, fiemap) < -1) + if (ioctl(fd, FS_IOC_FIEMAP, fiemap) < 0) return NULL; for (i=0;ifm_mapped_extents;i++) { diff --git a/params.h b/params.h index 8bbd333..d55ee26 100644 --- a/params.h +++ b/params.h @@ -27,9 +27,10 @@ struct mode_serve_params { struct ip_and_mask** acl; char* filename; int tcp_backlog; + char* control_socket_name; int server; - int threads; + int control; char* block_allocation_map; }; diff --git a/serve.c b/serve.c index 0a4c5f7..7aa0441 100644 --- a/serve.c +++ b/serve.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -315,7 +316,7 @@ int is_included_in_acl(int list_length, struct ip_and_mask** list, struct sockad return 0; } -void serve_open_socket(struct mode_serve_params* params) +void serve_open_server_socket(struct mode_serve_params* params) { params->server = socket(PF_INET, SOCK_STREAM, 0); @@ -334,6 +335,28 @@ void serve_open_socket(struct mode_serve_params* params) ); } +void serve_open_control_socket(struct mode_serve_params* params) +{ + struct sockaddr_un bind_address; + + if (!params->control_socket_name) + return; + + params->control = socket(AF_UNIX, SOCK_DGRAM, 0); + SERVER_ERROR_ON_FAILURE(params->control, + "Couldn't create control socket"); + + memset(&bind_address, 0, sizeof(bind_address)); + bind_address.sun_family = AF_UNIX; + strcpy(bind_address.sun_path, params->control_socket_name); + + SERVER_ERROR_ON_FAILURE( + bind(params->control, &bind_address, sizeof(bind_address)), + "Couldn't bind control socket to %s", + params->control_socket_name + ); +} + void serve_accept_loop(struct mode_serve_params* params) { while (1) { @@ -384,7 +407,8 @@ void serve_init_allocation_map(struct mode_serve_params* params) void do_serve(struct mode_serve_params* params) { - serve_open_socket(params); + serve_open_server_socket(params); + serve_open_control_socket(params); serve_init_allocation_map(params); serve_accept_loop(params); }