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