[Nbd] Make pre-run/post-run configurable from cmdline.
Hi,
I have attached a patch that changes two things:
* cmdline options -x and -X for pre-run and post-run commands
(previously one could specify them only in config file);
* pre-run will run even if served file is not present (for cases when
pre-run program creates the file).
Please express your opinions :).
bye,
Filip Zyzniewski
Tefnet
diff -Naur nbd-2.9.7-orig/nbd-server.c nbd-2.9.7/nbd-server.c
--- nbd-2.9.7-orig/nbd-server.c 2007-09-27 09:54:06.000000000 +0200
+++ nbd-2.9.7/nbd-server.c 2007-09-26 13:18:39.000000000 +0200
@@ -333,10 +333,12 @@
*/
void usage() {
printf("This is nbd-server version " VERSION "\n");
- printf("Usage: port file_to_export [size][kKmM] [-l authorize_file] [-r] [-m] [-c] [-a timeout_sec] [-C configuration file] [-p PID file name] [-o section name]\n"
+ printf("Usage: port file_to_export [size][kKmM] [-l authorize_file] [-r] [-m] [-c] [-x program] [-X program] [-a timeout_sec] [-C configuration file] [-p PID file name] [-o section name]\n"
"\t-r|--read-only\t\tread only\n"
"\t-m|--multi-file\t\tmultiple file\n"
"\t-c|--copy-on-write\tcopy on write\n"
+ "\t-x|--pre-run\t pre-serving command\n"
+ "\t-X|--post-run\t post-serving command\n"
"\t-C|--config-file\tspecify an alternate configuration file\n"
"\t-l|--authorize-file\tfile with list of hosts that are allowed to\n\t\t\t\tconnect.\n"
"\t-a|--idle-time\t\tmaximum idle seconds; server terminates when\n\t\t\t\tidle time exceeded\n"
@@ -371,6 +373,12 @@
if(serve->timeout) {
printf("\ttimeout = %d\n", serve->timeout);
}
+ if(serve->prerun) {
+ printf("\tprerun = %d\n", serve->prerun);
+ }
+ if(serve->postrun) {
+ printf("\tpostrun = %d\n", serve->postrun);
+ }
exit(EXIT_SUCCESS);
}
@@ -388,6 +396,8 @@
{"read-only", no_argument, NULL, 'r'},
{"multi-file", no_argument, NULL, 'm'},
{"copy-on-write", no_argument, NULL, 'c'},
+ {"pre-run", required_argument, NULL, 'x'},
+ {"post-run", required_argument, NULL, 'X'},
{"authorize-file", required_argument, NULL, 'l'},
{"idle-time", required_argument, NULL, 'a'},
{"config-file", required_argument, NULL, 'C'},
@@ -408,7 +418,7 @@
serve=g_new0(SERVER, 1);
serve->authname = g_strdup(default_authname);
serve->virtstyle=VIRT_IPLIT;
- while((c=getopt_long(argc, argv, "-a:C:cl:mo:rp:", long_options, &i))>=0) {
+ while((c=getopt_long(argc, argv, "-a:C:cx:X:l:mo:rp:", long_options, &i))>=0) {
switch (c) {
case 1:
/* non-option argument */
@@ -457,6 +467,12 @@
case 'c':
serve->flags |=F_COPYONWRITE;
break;
+ case 'x':
+ serve->prerun = g_strdup(optarg);
+ break;
+ case 'X':
+ serve->postrun = g_strdup(optarg);
+ break;
case 'C':
g_free(config_file_pos);
config_file_pos=g_strdup(optarg);
@@ -1277,15 +1293,16 @@
* @param client a connected client
**/
void serveconnection(CLIENT *client) {
- setupexport(client);
+
+ if(!do_run(client->server->prerun, client->exportname)) {
+ setupexport(client);
- if (client->server->flags & F_COPYONWRITE) {
- copyonwrite_prepare(client);
- }
+ if (client->server->flags & F_COPYONWRITE) {
+ copyonwrite_prepare(client);
+ }
- setmysockopt(client->net);
+ setmysockopt(client->net);
- if(!do_run(client->server->prerun, client->exportname)) {
mainloop(client);
}
do_run(client->server->postrun, client->exportname);
Reply to: