#define F_SPARSE 16
GHashTable *children;
char pidfname[256]; /**< name of our PID file */
+char pidftemplate[256]; /**< template to be used for the filename of the PID file */
char default_authname[] = SYSCONFDIR "/nbd-server/allow"; /**< default name of allow file */
/**
*/
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]\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]\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-C|--config-file\tspecify an alternat configuration file\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\n"
+ "\t-a|--idle-time\t\tmaximum idle seconds; server terminates when\n\t\t\t\tidle time exceeded\n"
+ "\t-p|--pid-file\t\tspecify a filename to write our PID to\n\n"
"\tif port is set to 0, stdin is used (for running from inetd)\n"
"\tif file_to_export contains '%%s', it is substituted with the IP\n"
"\t\taddress of the machine trying to connect\n" );
{"authorize-file", required_argument, NULL, 'l'},
{"idle-time", required_argument, NULL, 'a'},
{"config-file", required_argument, NULL, 'C'},
+ {"pid-file", required_argument, NULL, 'p'},
{0,0,0,0}
};
SERVER *serve;
}
serve=g_new0(SERVER, 1);
serve->authname = g_strdup(default_authname);
- while((c=getopt_long(argc, argv, "-a:C:cl:mr", long_options, &i))>=0) {
+ while((c=getopt_long(argc, argv, "-a:C:cl:mrp:", long_options, &i))>=0) {
switch (c) {
case 1:
/* non-option argument */
case 'm':
serve->flags |= F_MULTIFILE;
break;
+ case 'p':
+ strncpy(pidftemplate, optarg, 256);
+ break;
case 'c':
serve->flags |=F_COPYONWRITE;
break;
GArray *retval=NULL;
gchar **groups;
gboolean value;
- gint i,j;
+ gint i;
+ gint j;
errdomain = g_quark_from_string("parse_cfile");
cfile = g_key_file_new();
if (getpeername(net, (struct sockaddr *) &addrin, (socklen_t *)&addrinlen) < 0)
err("getsockname failed: %m");
- peername = inet_ntoa(addrin.sin_addr);
+ peername = g_strdup(inet_ntoa(addrin.sin_addr));
switch(client->server->virtstyle) {
case VIRT_NONE:
client->exportname=g_strdup(client->server->exportname);
break;
}
+ g_free(peername);
msg4(LOG_INFO, "connect from %s, assigned file is %s",
peername, client->exportname);
client->clientname=g_strdup(peername);
if(daemon(0,0)<0) {
err("daemon");
}
- if(serve) {
- snprintf(pidfname, sizeof(char)*255, "/var/run/nbd-server.%d.pid", serve->port);
- } else {
- strncpy(pidfname, "/var/run/nbd-server.pid", sizeof(char)*255);
+ if(!*pidftemplate) {
+ if(serve) {
+ strncpy(pidftemplate, "/var/run/server.%d.pid", 255);
+ } else {
+ strncpy(pidftemplate, "/var/run/server.pid", 255);
+ }
}
+ snprintf(pidfname, 255, pidftemplate, serve ? serve->port : 0);
pidf=fopen(pidfname, "w");
if(pidf) {
fprintf(pidf,"%d\n", (int)getpid());
sa.sa_flags = SA_RESTART;
if(sigaction(SIGTERM, &sa, NULL) == -1)
err("sigaction: %m");
- children=g_hash_table_new_full(g_int_hash, g_int_equal, NULL, destroy_pid_t);
}
/**
for(i=0;i<servers->len;i++) {
setup_serve(&(g_array_index(servers, SERVER, i)));
}
+ children=g_hash_table_new_full(g_int_hash, g_int_equal, NULL, destroy_pid_t);
}
/**
exit(-1) ;
}
+ memset(pidftemplate, '\0', 256);
+
logging();
config_file_pos = g_strdup(CFILE);
serve=cmdline(argc, argv);