summaryrefslogtreecommitdiff
path: root/core/qws/main.cpp
authorkergoth <kergoth>2003-05-08 16:48:20 (UTC)
committer kergoth <kergoth>2003-05-08 16:48:20 (UTC)
commit7d24cfad2a564436950b5f42e74c0bd51481f5a9 (patch) (side-by-side diff)
treebc55466250fd15014a35a9c13f0538893b2245fc /core/qws/main.cpp
parent0cb4111d34d9fe96731f48983e1ff2e67262db02 (diff)
downloadopie-7d24cfad2a564436950b5f42e74c0bd51481f5a9.zip
opie-7d24cfad2a564436950b5f42e74c0bd51481f5a9.tar.gz
opie-7d24cfad2a564436950b5f42e74c0bd51481f5a9.tar.bz2
Start work on a new launcher. This commit is simply a minimal Opie QWS server.
Diffstat (limited to 'core/qws/main.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/qws/main.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/core/qws/main.cpp b/core/qws/main.cpp
new file mode 100644
index 0000000..bfed283
--- a/dev/null
+++ b/core/qws/main.cpp
@@ -0,0 +1,71 @@
+#include <qwindowsystem_qws.h>
+#include <qapplication.h>
+
+#include "oqwsserver.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <syslog.h>
+#include <stdio.h>
+
+#define APPNAME "op-qws"
+
+void toSyslog(QtMsgType type, const char *msg)
+{
+ int level = LOG_INFO;
+ switch (type) {
+ case QtDebugMsg:
+ level = LOG_DEBUG;
+ break;
+ case QtWarningMsg:
+ level = LOG_WARNING;
+ break;
+ case QtFatalMsg:
+ level = LOG_ERR;
+ break;
+ }
+ syslog (LOG_DAEMON | level, msg);
+}
+
+int daemon_init(void)
+{
+ pid_t pid;
+
+ if ((pid = fork()) < 0)
+ return(-1);
+ else if (pid != 0)
+ exit(0);
+
+ setsid();
+
+ chdir("/");
+
+ umask(0);
+
+ fclose(stdout);
+ fclose(stderr);
+ fclose(stdin);
+
+ return(0);
+}
+
+int main( int argc, char ** argv )
+{
+ while (argc > 1) {
+ if (strcmp(argv[--argc], "-d") == 0) {
+ // daemonize
+ openlog(APPNAME, 0, LOG_DAEMON);
+ qInstallMsgHandler(toSyslog);
+ if (daemon_init() != 0) {
+ fprintf(stderr, "%s: Error: Unable to daemonize\n", APPNAME);
+ return 1;
+ }
+ }
+ }
+
+ OQWSServer a(argc, argv, QApplication::GuiServer);
+ return a.exec();
+}