signon  8.48
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  qInstallMsgHandler(messageHandler);
68  debugInit();
69 
70  TRACE() << "handler:" << (void *)messageHandler;
71 
72 #ifndef NO_SIGNON_USER
73  if (!::getuid()) {
74  BLAME() << argv[0] << " cannot be started with root priviledges!!!";
75  exit(2);
76  }
77 #endif
78 
79  QCoreApplication app(argc, argv);
80 
81  if (argc < 2) {
82  TRACE() << "Type of plugin is not specified";
83  exit(1);
84  }
85 
86  QString type = app.arguments().at(1); TRACE() << type;
87 
88  fcntl(fileno(stdin), F_SETFL, fcntl(fileno(stdin), F_GETFL, 0) | O_NONBLOCK);
89 
91 
92  if (!process)
93  return 1;
94 
95  fprintf(stdout, "process started");
96  fflush(stdout);
97 
98  QObject::connect(process, SIGNAL(processStopped()), &app, SLOT(quit()));
99  return app.exec();
100 }