signon  8.58
main.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of signon
3  *
4  * Copyright (C) 2009-2010 Nokia Corporation.
5  *
6  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * version 2.1 as published by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  */
22 
23 extern "C" {
24 #include <signal.h>
25 #include <stdlib.h>
26 #include <stddef.h>
27 #include <errno.h>
28 #include <unistd.h>
29 #include <fcntl.h>
30 #include <sys/poll.h>
31 #include <syslog.h>
32 }
33 
34 #define QT_DISABLE_DEPRECATED_BEFORE QT_VERSION_CHECK(4, 0, 0)
35 
36 #include "debug.h"
37 #include "remotepluginprocess.h"
38 
39 #include <QDebug>
40 
41 using namespace RemotePluginProcessNS;
42 
44 
45 void messageHandler(QtMsgType type, const char *msg)
46 {
47  if (debugLevel < 2) {
48  if (type == QtDebugMsg) return;
49  if (debugLevel < 1 && type == QtWarningMsg) return;
50  }
51 
52  int priority;
53  switch (type) {
54  case QtWarningMsg: priority = LOG_WARNING; break;
55  case QtCriticalMsg: priority = LOG_CRIT; break;
56  case QtFatalMsg: priority = LOG_EMERG; break;
57  case QtDebugMsg:
58  /* fall through */
59  default: priority = LOG_INFO; break;
60  }
61 
62  syslog(priority, "%s", msg);
63 }
64 
65 int main(int argc, char *argv[])
66 {
67  openlog(NULL, LOG_CONS | LOG_PID, LOG_DAEMON);
68  qInstallMsgHandler(messageHandler);
69  debugInit();
70 
71  TRACE() << "handler:" << (void *)messageHandler;
72 
73 #ifndef NO_SIGNON_USER
74  if (!::getuid()) {
75  BLAME() << argv[0] << " cannot be started with root priviledges!!!";
76  exit(2);
77  }
78 #endif
79 
80  QCoreApplication app(argc, argv);
81 
82  if (argc < 2) {
83  TRACE() << "Type of plugin is not specified";
84  exit(1);
85  }
86 
87  QString type = app.arguments().at(1); TRACE() << type;
88 
89  fcntl(fileno(stdin), F_SETFL, fcntl(fileno(stdin), F_GETFL, 0) | O_NONBLOCK);
90 
92 
93  if (!process)
94  return 1;
95 
96  fprintf(stdout, "process started");
97  fflush(stdout);
98 
99  QObject::connect(process, SIGNAL(processStopped()), &app, SLOT(quit()));
100  int ret = app.exec();
101  closelog();
102  return ret;
103 }
int debugLevel
Definition: debug.cpp:27
#define BLAME()
Definition: debug.h:32
static RemotePluginProcess * createRemotePluginProcess(QString &type, QObject *parent)
void messageHandler(QtMsgType type, const char *msg)
Definition: main.cpp:45
Class to execute plugin process.
RemotePluginProcess * process
Definition: main.cpp:43
int main(int argc, char *argv[])
Definition: main.cpp:65
#define TRACE()
Definition: debug.h:28
void debugInit()
Definition: debug.cpp:29