1. Call the internal variable portname (like pidname) everywhere.
2. Have a variable wroteportfile (like wrotepidfile) everywhere.
3. Make sure the file is cleaned up on exit (like pidfile).
4. Add parameter --portfile to usage outputs everywhere.
Reviewed-by: Daniel Stenberg
Replaces #7523
Closes #7574
" --version\n"
" --logfile [file]\n"
" --pidfile [file]\n"
+ " --portfile [file]\n"
" --ipv4\n"
" --ipv6\n"
" --port [port]\n");
goto mqttd_cleanup;
}
- wroteportfile = write_portfile(portname, (int)port);
+ wroteportfile = write_portfile(portname, port);
if(!wroteportfile) {
goto mqttd_cleanup;
}
if(wrotepidfile)
unlink(pidname);
+ if(wroteportfile)
+ unlink(portname);
restore_signal_handlers(FALSE);
curl_socket_t sock = CURL_SOCKET_BAD;
curl_socket_t msgsock = CURL_SOCKET_BAD;
int wrotepidfile = 0;
+ int wroteportfile = 0;
int flag;
unsigned short port = DEFAULT_PORT;
const char *pidname = ".rtsp.pid";
- const char *portfile = NULL;
+ const char *portname = NULL; /* none by default */
struct httprequest req;
int rc;
int error;
else if(!strcmp("--portfile", argv[arg])) {
arg++;
if(argc>arg)
- portfile = argv[arg++];
+ portname = argv[arg++];
}
else if(!strcmp("--logfile", argv[arg])) {
arg++;
if(!wrotepidfile)
goto server_cleanup;
- if(portfile) {
- wrotepidfile = write_portfile(portfile, port);
- if(!wrotepidfile)
+ if(portname) {
+ wroteportfile = write_portfile(portname, port);
+ if(!wroteportfile)
goto server_cleanup;
}
if(wrotepidfile)
unlink(pidname);
+ if(wroteportfile)
+ unlink(portname);
if(serverlogslocked) {
serverlogslocked = 0;
curl_socket_t sock = CURL_SOCKET_BAD;
curl_socket_t msgsock = CURL_SOCKET_BAD;
int wrotepidfile = 0;
+ int wroteportfile = 0;
const char *pidname = ".sockfilt.pid";
- const char *portfile = NULL; /* none by default */
+ const char *portname = NULL; /* none by default */
bool juggle_again;
int rc;
int error;
else if(!strcmp("--portfile", argv[arg])) {
arg++;
if(argc > arg)
- portfile = argv[arg++];
+ portname = argv[arg++];
}
else if(!strcmp("--logfile", argv[arg])) {
arg++;
" --verbose\n"
" --logfile [file]\n"
" --pidfile [file]\n"
+ " --portfile [file]\n"
" --ipv4\n"
" --ipv6\n"
" --bindonly\n"
write_stdout("FAIL\n", 5);
goto sockfilt_cleanup;
}
- if(portfile) {
- wrotepidfile = write_portfile(portfile, port);
- if(!wrotepidfile) {
+ if(portname) {
+ wroteportfile = write_portfile(portname, port);
+ if(!wroteportfile) {
write_stdout("FAIL\n", 5);
goto sockfilt_cleanup;
}
if(wrotepidfile)
unlink(pidname);
+ if(wroteportfile)
+ unlink(portname);
restore_signal_handlers(false);
curl_socket_t sock = CURL_SOCKET_BAD;
curl_socket_t msgsock = CURL_SOCKET_BAD;
int wrotepidfile = 0;
+ int wroteportfile = 0;
const char *pidname = ".socksd.pid";
- const char *portfile = NULL;
+ const char *portname = NULL; /* none by default */
bool juggle_again;
int error;
int arg = 1;
else if(!strcmp("--portfile", argv[arg])) {
arg++;
if(argc>arg)
- portfile = argv[arg++];
+ portname = argv[arg++];
}
else if(!strcmp("--config", argv[arg])) {
arg++;
goto socks5_cleanup;
}
- if(portfile) {
- wrotepidfile = write_portfile(portfile, port);
- if(!wrotepidfile) {
+ if(portname) {
+ wroteportfile = write_portfile(portname, port);
+ if(!wroteportfile) {
goto socks5_cleanup;
}
}
if(wrotepidfile)
unlink(pidname);
+ if(wroteportfile)
+ unlink(portname);
restore_signal_handlers(false);
srvr_sockaddr_union_t me;
curl_socket_t sock = CURL_SOCKET_BAD;
int wrotepidfile = 0;
+ int wroteportfile = 0;
int flag;
unsigned short port = DEFAULT_PORT;
#ifdef USE_UNIX_SOCKETS
if(!wrotepidfile)
goto sws_cleanup;
- wrotepidfile = write_portfile(portname, port);
- if(!wrotepidfile)
+ wroteportfile = write_portfile(portname, port);
+ if(!wroteportfile)
goto sws_cleanup;
/* initialization of httprequest struct is done before get_request(), but
if(wrotepidfile)
unlink(pidname);
+ if(wroteportfile)
+ unlink(portname);
if(serverlogslocked) {
serverlogslocked = 0;
const char *serverlogfile = DEFAULT_LOGFILE;
static const char *pidname = ".tftpd.pid";
-static const char *portfile = NULL;
+static const char *portname = NULL; /* none by default */
static int serverlogslocked = 0;
static int wrotepidfile = 0;
+static int wroteportfile = 0;
#ifdef HAVE_SIGSETJMP
static sigjmp_buf timeoutbuf;
wrotepidfile = 0;
unlink(pidname);
}
+ if(wroteportfile) {
+ wroteportfile = 0;
+ unlink(portname);
+ }
if(serverlogslocked) {
serverlogslocked = 0;
clear_advisor_read_lock(SERVERLOGS_LOCK);
else if(!strcmp("--portfile", argv[arg])) {
arg++;
if(argc>arg)
- portfile = argv[arg++];
+ portname = argv[arg++];
}
else if(!strcmp("--logfile", argv[arg])) {
arg++;
" --version\n"
" --logfile [file]\n"
" --pidfile [file]\n"
+ " --portfile [file]\n"
" --ipv4\n"
" --ipv6\n"
" --port [port]\n"
goto tftpd_cleanup;
}
- if(portfile) {
- wrotepidfile = write_portfile(portfile, port);
- if(!wrotepidfile) {
+ if(portname) {
+ wroteportfile = write_portfile(portname, port);
+ if(!wroteportfile) {
result = 1;
goto tftpd_cleanup;
}
if(wrotepidfile)
unlink(pidname);
- if(portfile)
- unlink(portfile);
+ if(wroteportfile)
+ unlink(portname);
if(serverlogslocked) {
serverlogslocked = 0;