mirror of
https://gitea.psi.ch/ELOG/elog.git
synced 2026-09-12 19:33:03 +00:00
Warn if port is already used
SVN revision: 1018
This commit is contained in:
parent
be744c15b1
commit
36b3a04f76
35
src/elogd.c
35
src/elogd.c
@ -6,6 +6,9 @@
|
|||||||
Contents: Web server program for Electronic Logbook ELOG
|
Contents: Web server program for Electronic Logbook ELOG
|
||||||
|
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 1.432 2004/08/04 12:38:22 midas
|
||||||
|
Warn if port is already used
|
||||||
|
|
||||||
Revision 1.431 2004/08/04 11:59:12 midas
|
Revision 1.431 2004/08/04 11:59:12 midas
|
||||||
Added -s(ilent) option
|
Added -s(ilent) option
|
||||||
|
|
||||||
@ -19434,17 +19437,26 @@ void server_loop(int tcp_port)
|
|||||||
}
|
}
|
||||||
|
|
||||||
serv_addr.sin_port = htons((short) tcp_port);
|
serv_addr.sin_port = htons((short) tcp_port);
|
||||||
/* try reusing address */
|
|
||||||
|
/* first try without reusing address */
|
||||||
|
flag = 0;
|
||||||
|
setsockopt(lsock, SOL_SOCKET, SO_REUSEADDR, (char *) &flag, sizeof(INT));
|
||||||
|
status = bind(lsock, (struct sockaddr *) &serv_addr, sizeof(serv_addr));
|
||||||
|
if (status < 0)
|
||||||
|
eprintf("Warning: another server might already run on port %d.\n\n",tcp_port);
|
||||||
|
|
||||||
|
/* now try with reusing address */
|
||||||
flag = 1;
|
flag = 1;
|
||||||
setsockopt(lsock, SOL_SOCKET, SO_REUSEADDR, (char *) &flag, sizeof(INT));
|
setsockopt(lsock, SOL_SOCKET, SO_REUSEADDR, (char *) &flag, sizeof(INT));
|
||||||
status = bind(lsock, (struct sockaddr *) &serv_addr, sizeof(serv_addr));
|
status = bind(lsock, (struct sockaddr *) &serv_addr, sizeof(serv_addr));
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
eprintf
|
eprintf
|
||||||
("Cannot bind to port %d.\nPlease try later or use the \"-p\" flag to specify a different port.\n",
|
("Cannot bind to port %d.\nPlease use the \"-p\" flag to specify a different port.\n",
|
||||||
tcp_port);
|
tcp_port);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* get host name for mail notification */
|
/* get host name for mail notification */
|
||||||
gethostname(host_name, sizeof(host_name));
|
gethostname(host_name, sizeof(host_name));
|
||||||
phe = gethostbyname(host_name);
|
phe = gethostbyname(host_name);
|
||||||
@ -20678,7 +20690,7 @@ int install_service(void)
|
|||||||
|
|
||||||
/* Try to start the elogd service */
|
/* Try to start the elogd service */
|
||||||
if (!StartService(hservice, 0, NULL))
|
if (!StartService(hservice, 0, NULL))
|
||||||
eprintf("The elogd service could not be started.");
|
eprintf("The elogd service could not be started.\n");
|
||||||
else
|
else
|
||||||
eprintf("The elogd service has been started successfully.\n");
|
eprintf("The elogd service has been started successfully.\n");
|
||||||
|
|
||||||
@ -20728,15 +20740,16 @@ int remove_service(int silent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Now remove the service from the SCM */
|
/* Now remove the service from the SCM */
|
||||||
if (!silent) {
|
if (!DeleteService(hservice)) {
|
||||||
if (!DeleteService(hservice)) {
|
if (!silent) {
|
||||||
if (GetLastError() == ERROR_SERVICE_MARKED_FOR_DELETE)
|
if (GetLastError() == ERROR_SERVICE_MARKED_FOR_DELETE)
|
||||||
eprintf("The elogd service is already marked to be unregistered.\n");
|
eprintf("The elogd service is already marked to be unregistered.\n");
|
||||||
else
|
else
|
||||||
eprintf("The elogd service could not be unregistered.\n");
|
eprintf("The elogd service could not be unregistered.\n");
|
||||||
} else
|
}
|
||||||
|
} else
|
||||||
|
if (!silent)
|
||||||
eprintf("The elogd service hass been unregistered successfully.\n");
|
eprintf("The elogd service hass been unregistered successfully.\n");
|
||||||
}
|
|
||||||
|
|
||||||
CloseServiceHandle(hservice);
|
CloseServiceHandle(hservice);
|
||||||
CloseServiceHandle(hsrvmanager);
|
CloseServiceHandle(hsrvmanager);
|
||||||
@ -20800,6 +20813,12 @@ void WINAPI ServiceMain(DWORD argc, LPSTR * argv)
|
|||||||
serviceStatus.dwCurrentState = SERVICE_RUNNING;
|
serviceStatus.dwCurrentState = SERVICE_RUNNING;
|
||||||
SetServiceStatus(serviceStatusHandle, &serviceStatus);
|
SetServiceStatus(serviceStatusHandle, &serviceStatus);
|
||||||
|
|
||||||
|
/* avoid recursive calls to run_service */
|
||||||
|
running_as_daemon = 0;
|
||||||
|
|
||||||
|
/* Redirect all messages handled with eprintf/efputs to syslog */
|
||||||
|
redirect_to_syslog();
|
||||||
|
|
||||||
/* start main server, exit with "_abort = TRUE" */
|
/* start main server, exit with "_abort = TRUE" */
|
||||||
server_loop(tcp_port);
|
server_loop(tcp_port);
|
||||||
|
|
||||||
@ -20887,7 +20906,7 @@ int main(int argc, char *argv[])
|
|||||||
running_as_daemon = TRUE;
|
running_as_daemon = TRUE;
|
||||||
else if (argv[i][0] == '-' && argv[i][1] == 'v')
|
else if (argv[i][0] == '-' && argv[i][1] == 'v')
|
||||||
verbose = TRUE;
|
verbose = TRUE;
|
||||||
else if (argv[i][0] == '-' && argv[i][1] == 's')
|
else if (argv[i][0] == '-' && argv[i][1] == 'S')
|
||||||
silent = TRUE;
|
silent = TRUE;
|
||||||
else if (argv[i][0] == '-' && argv[i][1] == 'k')
|
else if (argv[i][0] == '-' && argv[i][1] == 'k')
|
||||||
use_keepalive = FALSE;
|
use_keepalive = FALSE;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user