summaryrefslogtreecommitdiff
path: root/core/qws/main.cpp
Unidiff
Diffstat (limited to 'core/qws/main.cpp') (more/less context) (show 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 @@
1#include <qwindowsystem_qws.h>
2#include <qapplication.h>
3
4#include "oqwsserver.h"
5
6#include <sys/types.h>
7#include <sys/stat.h>
8#include <fcntl.h>
9#include <unistd.h>
10
11#include <syslog.h>
12#include <stdio.h>
13
14#define APPNAME "op-qws"
15
16void toSyslog(QtMsgType type, const char *msg)
17{
18 int level = LOG_INFO;
19 switch (type) {
20 case QtDebugMsg:
21 level = LOG_DEBUG;
22 break;
23 case QtWarningMsg:
24 level = LOG_WARNING;
25 break;
26 case QtFatalMsg:
27 level = LOG_ERR;
28 break;
29 }
30 syslog (LOG_DAEMON | level, msg);
31}
32
33int daemon_init(void)
34{
35 pid_t pid;
36
37 if ((pid = fork()) < 0)
38 return(-1);
39 else if (pid != 0)
40 exit(0);
41
42 setsid();
43
44 chdir("/");
45
46 umask(0);
47
48 fclose(stdout);
49 fclose(stderr);
50 fclose(stdin);
51
52 return(0);
53}
54
55int main( int argc, char ** argv )
56{
57 while (argc > 1) {
58 if (strcmp(argv[--argc], "-d") == 0) {
59 // daemonize
60 openlog(APPNAME, 0, LOG_DAEMON);
61 qInstallMsgHandler(toSyslog);
62 if (daemon_init() != 0) {
63 fprintf(stderr, "%s: Error: Unable to daemonize\n", APPNAME);
64 return 1;
65 }
66 }
67 }
68
69 OQWSServer a(argc, argv, QApplication::GuiServer);
70 return a.exec();
71}