Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Xiph.Org
Icecast-Server
Commits
3c481655
Commit
3c481655
authored
Aug 05, 2009
by
Karl Heyes
Browse files
win32 updates. cleanup of the start and finish of the gui and service
svn path=/icecast/trunk/icecast/; revision=16440
parent
1f92e2ab
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/compat.h
View file @
3c481655
...
...
@@ -44,6 +44,7 @@
# define uint64_t unsigned __int64
# define uint32_t unsigned int
# define PRIu64 "I64u"
# define PRId64 "I64d"
#else
# define PATH_SEPARATOR "/"
# if defined(HAVE_INTTYPES_H)
...
...
src/main.c
View file @
3c481655
...
...
@@ -17,6 +17,16 @@
#include
<stdio.h>
#include
<string.h>
#include
<errno.h>
#ifdef WIN32
#define _WIN32_WINNT 0x0400
/* For getpid() */
#include
<process.h>
#include
<windows.h>
#define snprintf _snprintf
#define getpid _getpid
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
...
...
@@ -35,7 +45,6 @@
#include
<sys/types.h>
#include
<grp.h>
#include
<pwd.h>
#include
<errno.h>
#endif
#include
"cfgfile.h"
...
...
@@ -56,14 +65,6 @@
#include
<libxml/xmlmemory.h>
#ifdef _WIN32
/* For getpid() */
#include
<process.h>
#include
<windows.h>
#define snprintf _snprintf
#define getpid _getpid
#endif
#undef CATMODULE
#define CATMODULE "main"
...
...
@@ -72,7 +73,9 @@ static char *pidfile = NULL;
static
void
_fatal_error
(
char
*
perr
)
{
#ifdef WIN32
#ifdef WIN32_SERVICE
MessageBox
(
NULL
,
perr
,
"Error"
,
MB_SERVICE_NOTIFICATION
);
#elif defined(WIN32)
MessageBox
(
NULL
,
perr
,
"Error"
,
MB_OK
);
#else
fprintf
(
stdout
,
"%s
\n
"
,
perr
);
...
...
@@ -97,7 +100,7 @@ static void _stop_logging(void)
log_close
(
playlistlog
);
}
static
void
_
initialize_subsystems
(
void
)
void
initialize_subsystems
(
void
)
{
log_initialize
();
thread_initialize
();
...
...
@@ -107,23 +110,16 @@ static void _initialize_subsystems(void)
connection_initialize
();
global_initialize
();
refbuf_initialize
();
#if !defined(WIN32) || defined(WIN32_SERVICE)
/* win32 GUI needs to do the initialise before here */
xslt_initialize
();
#ifdef HAVE_CURL_GLOBAL_INIT
curl_global_init
(
CURL_GLOBAL_ALL
);
#endif
#endif
}
static
void
_
shutdown_subsystems
(
void
)
void
shutdown_subsystems
(
void
)
{
fserve_shutdown
();
#if !defined(WIN32) || defined(WIN32_SERVICE)
/* If we do the following cleanup on the win32 GUI then the app will crash when libxml2 is
* initialised again as the process doesn't terminate */
xslt_shutdown
();
#endif
refbuf_shutdown
();
slave_shutdown
();
auth_shutdown
();
...
...
@@ -144,6 +140,7 @@ static void _shutdown_subsystems(void)
/* Now that these are done, we can stop the loggers. */
_stop_logging
();
log_shutdown
();
xslt_shutdown
();
}
static
int
_parse_config_opts
(
int
argc
,
char
**
argv
,
char
*
filename
,
int
size
)
...
...
@@ -425,9 +422,10 @@ int main(int argc, char **argv)
*/
res
=
_parse_config_opts
(
argc
,
argv
,
filename
,
512
);
if
(
res
==
1
)
{
#if !defined(_WIN32) || defined(_CONSOLE)
/* startup all the modules */
_
initialize_subsystems
();
initialize_subsystems
();
#endif
/* parse the config file */
config_get_config
();
ret
=
config_initial_parse_file
(
filename
);
...
...
@@ -451,7 +449,9 @@ int main(int argc, char **argv)
_fatal_error
(
"XML config parsing error"
);
break
;
}
_shutdown_subsystems
();
#if !defined(_WIN32) || defined(_CONSOLE)
shutdown_subsystems
();
#endif
return
1
;
}
}
else
if
(
res
==
-
1
)
{
...
...
@@ -465,7 +465,7 @@ int main(int argc, char **argv)
/* Bind socket, before we change userid */
if
(
!
_server_proc_init
())
{
_fatal_error
(
"Server startup failed. Exiting"
);
_
shutdown_subsystems
();
shutdown_subsystems
();
return
1
;
}
...
...
@@ -481,7 +481,7 @@ int main(int argc, char **argv)
{
fprintf
(
stderr
,
"ERROR: You should not run icecast2 as root
\n
"
);
fprintf
(
stderr
,
"Use the changeowner directive in the config file
\n
"
);
_
shutdown_subsystems
();
shutdown_subsystems
();
return
1
;
}
#endif
...
...
@@ -491,7 +491,7 @@ int main(int argc, char **argv)
if
(
!
_start_logging
())
{
_fatal_error
(
"FATAL: Could not start logging"
);
_
shutdown_subsystems
();
shutdown_subsystems
();
return
1
;
}
...
...
@@ -512,9 +512,9 @@ int main(int argc, char **argv)
_server_proc
();
INFO0
(
"Shutting down"
);
_
shutdown_subsystems
();
#if !defined(_WIN32) || defined(_CONSOLE)
shutdown_subsystems
();
#endif
if
(
pidfile
)
{
remove
(
pidfile
);
...
...
src/stats.c
View file @
3c481655
...
...
@@ -41,6 +41,7 @@
#include
"logging.h"
#ifdef _WIN32
#define atoll _atoi64
#define vsnprintf _vsnprintf
#define snprintf _snprintf
#endif
...
...
@@ -445,7 +446,7 @@ static void modify_node_event (stats_node_t *node, stats_event_t *event)
}
if
(
event
->
action
!=
STATS_EVENT_SET
)
{
int
value
=
0
;
int
64_t
value
=
0
;
switch
(
event
->
action
)
{
...
...
@@ -466,7 +467,7 @@ static void modify_node_event (stats_node_t *node, stats_event_t *event)
break
;
}
str
=
malloc
(
16
);
snprintf
(
str
,
16
,
"%
d
"
,
value
);
snprintf
(
str
,
16
,
"%"
PRId64
,
value
);
if
(
event
->
value
==
NULL
)
event
->
value
=
strdup
(
str
);
}
...
...
win32/Icecast2win.cpp
View file @
3c481655
...
...
@@ -5,6 +5,11 @@
#include
"Icecast2win.h"
#include
"Icecast2winDlg.h"
extern
"C"
{
#include
"xslt.h"
void
initialize_subsystems
(
void
);
void
shutdown_subsystems
(
void
);
}
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
...
...
@@ -49,6 +54,7 @@ BOOL CIcecast2winApp::InitInstance()
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
initialize_subsystems
();
if
(
strlen
(
m_lpCmdLine
)
>
0
)
{
strcpy
(
m_configFile
,
m_lpCmdLine
);
}
...
...
@@ -87,3 +93,9 @@ BOOL CIcecast2winApp::InitInstance()
// application, rather than start the application's message pump.
return
FALSE
;
}
int
CIcecast2winApp
::
ExitInstance
()
{
shutdown_subsystems
();
return
CWinApp
::
ExitInstance
();
}
win32/Icecast2win.h
View file @
3c481655
...
...
@@ -31,6 +31,7 @@ public:
//{{AFX_VIRTUAL(CIcecast2winApp)
public:
virtual
BOOL
InitInstance
();
virtual
int
ExitInstance
();
//}}AFX_VIRTUAL
// Implementation
...
...
win32/Icecast2winDlg.cpp
View file @
3c481655
...
...
@@ -339,9 +339,6 @@ BOOL CIcecast2winDlg::OnInitDialog()
sprintf
(
version
,
"Icecast2 Version %s"
,
ICECAST_VERSION
);
SetWindowText
(
version
);
xslt_initialize
();
curl_global_init
(
CURL_GLOBAL_ALL
);
if
(
m_Autostart
)
{
OnStart
();
}
...
...
win32/icecastService.cpp
View file @
3c481655
#define _WIN32_WINNT 0x0400
#include
<windows.h>
#include
<stdio.h>
#include
<direct.h>
...
...
@@ -24,14 +25,8 @@ SERVICE_STATUS_HANDLE hStatus;
void
ServiceMain
(
int
argc
,
char
**
argv
);
void
ControlHandler
(
DWORD
request
);
int
InitService
();
extern
"C"
int
mainService
(
int
argc
,
char
**
argv
);
int
InitService
()
{
int
result
=
0
;
return
(
result
);
}
void
installService
(
const
char
*
path
)
{
...
...
@@ -44,21 +39,7 @@ void installService (const char *path)
SC_HANDLE
manager
=
OpenSCManager
(
NULL
,
NULL
,
SC_MANAGER_ALL_ACCESS
);
if
(
manager
==
NULL
)
{
LPVOID
lpMsgBuf
;
FormatMessage
(
FORMAT_MESSAGE_ALLOCATE_BUFFER
|
FORMAT_MESSAGE_FROM_SYSTEM
|
FORMAT_MESSAGE_IGNORE_INSERTS
,
NULL
,
GetLastError
(),
MAKELANGID
(
LANG_NEUTRAL
,
SUBLANG_DEFAULT
),
// Default language
(
LPTSTR
)
&
lpMsgBuf
,
0
,
NULL
);
printf
(
"OpenSCManager: %s
\n
"
,
(
LPCTSTR
)
lpMsgBuf
);
LocalFree
(
lpMsgBuf
);
MessageBox
(
NULL
,
"OpenSCManager failed"
,
NULL
,
MB_SERVICE_NOTIFICATION
);
return
;
}
...
...
@@ -79,21 +60,7 @@ void installService (const char *path)
);
if
(
service
==
NULL
)
{
LPVOID
lpMsgBuf
;
FormatMessage
(
FORMAT_MESSAGE_ALLOCATE_BUFFER
|
FORMAT_MESSAGE_FROM_SYSTEM
|
FORMAT_MESSAGE_IGNORE_INSERTS
,
NULL
,
GetLastError
(),
MAKELANGID
(
LANG_NEUTRAL
,
SUBLANG_DEFAULT
),
// Default language
(
LPTSTR
)
&
lpMsgBuf
,
0
,
NULL
);
printf
(
"CreateService: %s
\n
"
,
(
LPCTSTR
)
lpMsgBuf
);
LocalFree
(
lpMsgBuf
);
MessageBox
(
NULL
,
"CreateService failed"
,
NULL
,
MB_SERVICE_NOTIFICATION
);
CloseServiceHandle
(
manager
);
return
;
}
...
...
@@ -108,67 +75,44 @@ void removeService()
SC_HANDLE
manager
=
OpenSCManager
(
NULL
,
NULL
,
SC_MANAGER_ALL_ACCESS
);
if
(
manager
==
NULL
)
{
LPVOID
lpMsgBuf
;
FormatMessage
(
FORMAT_MESSAGE_ALLOCATE_BUFFER
|
FORMAT_MESSAGE_FROM_SYSTEM
|
FORMAT_MESSAGE_IGNORE_INSERTS
,
NULL
,
GetLastError
(),
MAKELANGID
(
LANG_NEUTRAL
,
SUBLANG_DEFAULT
),
// Default language
(
LPTSTR
)
&
lpMsgBuf
,
0
,
NULL
);
printf
(
"OpenSCManager: %s
\n
"
,
(
LPCTSTR
)
lpMsgBuf
);
LocalFree
(
lpMsgBuf
);
MessageBox
(
NULL
,
"OpenSCManager failed"
,
NULL
,
MB_SERVICE_NOTIFICATION
);
return
;
}
SC_HANDLE
service
=
OpenService
(
manager
,
PACKAGE_STRING
,
DELETE
);
if
(
service
)
{
DeleteService
(
service
);
printf
(
"Service Removed
\n
"
);
CloseServiceHandle
(
service
);
printf
(
"Service deleted, may require reboot to complete removal
\n
"
);
}
else
printf
(
"Service not found
\n
"
);
CloseServiceHandle
(
manager
);
Sleep
(
1500
);
}
void
ControlHandler
(
DWORD
request
)
{
switch
(
request
)
{
case
SERVICE_CONTROL_STOP
:
global
.
running
=
ICE_HALTING
;
ServiceStatus
.
dwWin32ExitCode
=
0
;
ServiceStatus
.
dwCurrentState
=
SERVICE_STOPPED
;
SetServiceStatus
(
hStatus
,
&
ServiceStatus
);
return
;
if
(
ServiceStatus
.
dwCurrentState
!=
SERVICE_STOP
)
{
ServiceStatus
.
dwCurrentState
=
SERVICE_STOP_PENDING
;
SetServiceStatus
(
hStatus
,
&
ServiceStatus
);
global
.
running
=
ICE_HALTING
;
return
;
}
case
SERVICE_CONTROL_SHUTDOWN
:
global
.
running
=
ICE_HALTING
;
ServiceStatus
.
dwWin32ExitCode
=
0
;
ServiceStatus
.
dwCurrentState
=
SERVICE_STOPPED
;
SetServiceStatus
(
hStatus
,
&
ServiceStatus
);
return
;
default:
break
;
}
// Report current status
SetServiceStatus
(
hStatus
,
&
ServiceStatus
);
return
;
}
void
ServiceMain
(
int
argc
,
char
**
argv
)
{
int
error
;
ServiceStatus
.
dwServiceType
=
SERVICE_WIN32
;
ServiceStatus
.
dwCurrentState
=
SERVICE_START_PENDING
;
ServiceStatus
.
dwControlsAccepted
=
SERVICE_ACCEPT_STOP
|
SERVICE_ACCEPT_SHUTDOWN
;
ServiceStatus
.
dwServiceType
=
SERVICE_WIN32_OWN_PROCESS
;
ServiceStatus
.
dwWin32ExitCode
=
0
;
ServiceStatus
.
dwServiceSpecificExitCode
=
0
;
ServiceStatus
.
dwCheckPoint
=
0
;
...
...
@@ -177,19 +121,12 @@ void ServiceMain(int argc, char** argv)
hStatus
=
RegisterServiceCtrlHandler
(
PACKAGE_STRING
,
(
LPHANDLER_FUNCTION
)
ControlHandler
);
if
(
hStatus
==
(
SERVICE_STATUS_HANDLE
)
0
)
{
// Registering Control Handler failed
MessageBox
(
NULL
,
"RegisterServiceCtrlHandler failed"
,
NULL
,
MB_SERVICE_NOTIFICATION
);
return
;
}
// Initialize Service
error
=
InitService
();
if
(
error
)
{
// Initialization failed
ServiceStatus
.
dwCurrentState
=
SERVICE_STOPPED
;
ServiceStatus
.
dwWin32ExitCode
=
-
1
;
SetServiceStatus
(
hStatus
,
&
ServiceStatus
);
return
;
}
// We report the running status to SCM.
ServiceStatus
.
dwCurrentState
=
SERVICE_RUNNING
;
ServiceStatus
.
dwControlsAccepted
=
SERVICE_ACCEPT_STOP
;
SetServiceStatus
(
hStatus
,
&
ServiceStatus
);
/* Here we do the work */
...
...
@@ -205,12 +142,10 @@ void ServiceMain(int argc, char** argv)
argv2
[
2
]
=
argv
[
1
];
argv2
[
3
]
=
NULL
;
int
ret
=
mainService
(
argc2
,
(
char
**
)
argv2
);
ServiceStatus
.
dwWin32ExitCode
=
mainService
(
argc2
,
(
char
**
)
argv2
);
ServiceStatus
.
dwCurrentState
=
SERVICE_STOPPED
;
ServiceStatus
.
dwWin32ExitCode
=
-
1
;
SetServiceStatus
(
hStatus
,
&
ServiceStatus
);
return
;
}
...
...
@@ -224,10 +159,7 @@ int main(int argc, char **argv)
if
(
!
strcmp
(
argv
[
1
],
"install"
))
{
if
(
argc
>
2
)
{
printf
(
"Installing service from %s
\n
"
,
argv
[
2
]);
installService
(
argv
[
2
]);
}
else
printf
(
"install requires a path arg as well
\n
"
);
Sleep
(
2000
);
...
...
@@ -235,16 +167,15 @@ int main(int argc, char **argv)
}
if
(
!
strcmp
(
argv
[
1
],
"remove"
)
||
!
strcmp
(
argv
[
1
],
"uninstall"
))
{
printf
(
"removing service
\n
"
);
removeService
();
Sleep
(
2000
);
return
0
;
}
if
(
_chdir
(
argv
[
1
])
<
0
)
{
printf
(
"unable to change to directory %s
\n
"
,
argv
[
1
]);
Sleep
(
2000
);
char
buffer
[
256
];
_snprintf
(
buffer
,
sizeof
(
buffer
),
"Unable to change to directory %s"
,
argv
[
1
]);
MessageBox
(
NULL
,
buffer
,
NULL
,
MB_SERVICE_NOTIFICATION
);
return
0
;
}
...
...
@@ -255,7 +186,8 @@ int main(int argc, char **argv)
ServiceTable
[
1
].
lpServiceName
=
NULL
;
ServiceTable
[
1
].
lpServiceProc
=
NULL
;
// Start the control dispatcher thread for our service
StartServiceCtrlDispatcher
(
ServiceTable
);
if
(
StartServiceCtrlDispatcher
(
ServiceTable
)
==
0
)
MessageBox
(
NULL
,
"StartServiceCtrlDispatcher failed"
,
NULL
,
MB_SERVICE_NOTIFICATION
);
return
0
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment