signon  8.42
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 #include "debug.h"
35 #include "remotepluginprocess.h"
36 
37 #include <QDebug>
38 
39 using namespace RemotePluginProcessNS;
40 
42 
43 void messageHandler(QtMsgType type, const char *msg)
44 {
45  int priority;
46  switch (type) {
47  case QtWarningMsg: priority = LOG_WARNING; break;
48  case QtCriticalMsg: priority = LOG_CRIT; break;
49  case QtFatalMsg: priority = LOG_EMERG; break;
50  case QtDebugMsg:
51  /* fall through */
52  default: priority = LOG_INFO; break;
53  }
54 
55  syslog(priority, "%s", msg);
56 }
57 
58 int main(int argc, char *argv[])
59 {
60  qInstallMsgHandler(messageHandler);
61  debugInit();
62 
63  TRACE() << "handler:" << (void *)messageHandler;
64 
65 #ifndef NO_SIGNON_USER
66  if (!::getuid()) {
67  BLAME() << argv[0] << " cannot be started with root priviledges!!!";
68  exit(2);
69  }
70 #endif
71 
72  QCoreApplication app(argc, argv);
73 
74  if (argc < 2) {
75  TRACE() << "Type of plugin is not specified";
76  exit(1);
77  }
78 
79  QString type = app.arguments().at(1); TRACE() << type;
80 
81  fcntl(fileno(stdin), F_SETFL, fcntl(fileno(stdin), F_GETFL, 0) | O_NONBLOCK);
82 
84 
85  if (!process)
86  return 1;
87 
88  fprintf(stdout, "process started");
89  fflush(stdout);
90 
91  QObject::connect(process, SIGNAL(processStopped()), &app, SLOT(quit()));
92  return app.exec();
93 }