summaryrefslogtreecommitdiffstats
path: root/polyp/main.c
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2006-01-05 22:51:37 +0000
committerPierre Ossman <ossman@cendio.se>2006-01-05 22:51:37 +0000
commit19d9fcbda8637099854f2d8147b402b4420d19f5 (patch)
tree993f0ebc9045bd893cd3039d0ae6277ee5806c05 /polyp/main.c
parent2f74bb9d437fc165695e1d4bb7516ca979962a49 (diff)
Port to Windows. This is mostly glue layers for the poor POSIX support
on Windows. A few notes * Only sockets behave somewhat like file descriptors in UNIX. * There are no fixed paths. Closes thing is environment variables that point to system directories. We also figure out where the binary/dll is located and use that as configuration directory. git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/ossman@418 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'polyp/main.c')
-rw-r--r--polyp/main.c75
1 files changed, 71 insertions, 4 deletions
diff --git a/polyp/main.c b/polyp/main.c
index 3f9f359e..437f0a41 100644
--- a/polyp/main.c
+++ b/polyp/main.c
@@ -35,7 +35,16 @@
#include <memblock.h>
#include <limits.h>
#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
+#endif
+
+#ifdef HAVE_WINSOCK2_H
+#include <winsock2.h>
+#endif
#ifdef HAVE_LIBWRAP
#include <syslog.h>
@@ -66,6 +75,23 @@ int allow_severity = LOG_INFO;
int deny_severity = LOG_WARNING;
#endif
+#ifdef OS_IS_WIN32
+
+static void message_cb(struct pa_mainloop_api*a, struct pa_defer_event *e, void *userdata) {
+ MSG msg;
+
+ while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
+ if (msg.message == WM_QUIT)
+ raise(SIGTERM);
+ else {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ }
+}
+
+#endif
+
static void signal_callback(struct pa_mainloop_api*m, struct pa_signal_event *e, int sig, void *userdata) {
pa_log_info(__FILE__": Got signal %s.\n", pa_strsignal(sig));
@@ -124,6 +150,10 @@ int main(int argc, char *argv[]) {
gid_t gid = (gid_t) -1;
#endif
+#ifdef OS_IS_WIN32
+ struct pa_defer_event *defer;
+#endif
+
pa_limit_caps();
#ifdef HAVE_GETUID
@@ -142,6 +172,13 @@ int main(int argc, char *argv[]) {
r = lt_dlinit();
assert(r == 0);
+#ifdef OS_IS_WIN32
+ {
+ WSADATA data;
+ WSAStartup(MAKEWORD(2, 0), &data);
+ }
+#endif
+
pa_log_set_ident("polypaudio");
conf = pa_daemon_conf_new();
@@ -230,6 +267,7 @@ int main(int argc, char *argv[]) {
goto finish;
}
+#ifdef HAVE_FORK
if (pipe(daemon_pipe) < 0) {
pa_log(__FILE__": failed to create pipe.\n");
goto finish;
@@ -261,6 +299,7 @@ int main(int argc, char *argv[]) {
close(daemon_pipe[0]);
daemon_pipe[0] = -1;
+#endif
if (conf->auto_log_target)
pa_log_set_target(PA_LOG_SYSLOG, NULL);
@@ -271,7 +310,8 @@ int main(int argc, char *argv[]) {
#ifdef HAVE_SETPGID
setpgid(0,0);
#endif
-
+
+#ifndef OS_IS_WIN32
close(0);
close(1);
close(2);
@@ -279,7 +319,10 @@ int main(int argc, char *argv[]) {
open("/dev/null", O_RDONLY);
open("/dev/null", O_WRONLY);
open("/dev/null", O_WRONLY);
-
+#else
+ FreeConsole();
+#endif
+
#ifdef SIGTTOU
signal(SIGTTOU, SIG_IGN);
#endif
@@ -290,18 +333,23 @@ int main(int argc, char *argv[]) {
signal(SIGTSTP, SIG_IGN);
#endif
+#ifdef TIOCNOTTY
if ((tty_fd = open("/dev/tty", O_RDWR)) >= 0) {
ioctl(tty_fd, TIOCNOTTY, (char*) 0);
close(tty_fd);
}
+#endif
}
chdir("/");
if (conf->use_pid_file) {
if (pa_pid_file_create() < 0) {
+ pa_log(__FILE__": pa_pid_file_create() failed.\n");
+#ifdef HAVE_FORK
if (conf->daemonize)
pa_loop_write(daemon_pipe[1], &retval, sizeof(retval));
+#endif
goto finish;
}
@@ -322,9 +370,14 @@ int main(int argc, char *argv[]) {
signal(SIGPIPE, SIG_IGN);
#endif
+#ifdef OS_IS_WIN32
+ defer = pa_mainloop_get_api(mainloop)->defer_new(pa_mainloop_get_api(mainloop), message_cb, NULL);
+ assert(defer);
+#endif
+
if (conf->daemonize)
c->running_as_daemon = 1;
-
+
#ifdef SIGUSR1
pa_signal_new(SIGUSR1, signal_callback, c);
#endif
@@ -350,17 +403,23 @@ int main(int argc, char *argv[]) {
if (r < 0 && conf->fail) {
pa_log(__FILE__": failed to initialize daemon.\n");
+#ifdef HAVE_FORK
if (conf->daemonize)
pa_loop_write(daemon_pipe[1], &retval, sizeof(retval));
+#endif
} else if (!c->modules || pa_idxset_ncontents(c->modules) == 0) {
pa_log(__FILE__": daemon startup without any loaded modules, refusing to work.\n");
+#ifdef HAVE_FORK
if (conf->daemonize)
pa_loop_write(daemon_pipe[1], &retval, sizeof(retval));
+#endif
} else {
retval = 0;
+#ifdef HAVE_FORK
if (conf->daemonize)
pa_loop_write(daemon_pipe[1], &retval, sizeof(retval));
+#endif
c->disallow_module_loading = conf->disallow_module_loading;
c->exit_idle_time = conf->exit_idle_time;
@@ -378,7 +437,11 @@ int main(int argc, char *argv[]) {
pa_log_info(__FILE__": Daemon shutdown initiated.\n");
}
}
-
+
+#ifdef OS_IS_WIN32
+ pa_mainloop_get_api(mainloop)->defer_free(defer);
+#endif
+
pa_core_free(c);
pa_cpu_limit_done();
@@ -397,6 +460,10 @@ finish:
close_pipe(daemon_pipe);
+#ifdef OS_IS_WIN32
+ WSACleanup();
+#endif
+
lt_dlexit();
return retval;