signon  8.40
main.cpp
Go to the documentation of this file.
00001 /*
00002  * This file is part of signon
00003  *
00004  * Copyright (C) 2009-2010 Nokia Corporation.
00005  *
00006  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public License
00010  * version 2.1 as published by the Free Software Foundation.
00011  *
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00020  * 02110-1301 USA
00021  */
00022 
00023 extern "C" {
00024 #include <signal.h>
00025 #include <stdlib.h>
00026 #include <stddef.h>
00027 #include <errno.h>
00028 #include <unistd.h>
00029 #include <fcntl.h>
00030 #include <sys/poll.h>
00031 #include <syslog.h>
00032 }
00033 
00034 #include "debug.h"
00035 #include "remotepluginprocess.h"
00036 
00037 #include <QDebug>
00038 
00039 using namespace RemotePluginProcessNS;
00040 
00041 RemotePluginProcess *process = NULL;
00042 
00043 void messageHandler(QtMsgType type, const char *msg)
00044 {
00045     int priority;
00046     switch (type) {
00047     case QtWarningMsg: priority = LOG_WARNING; break;
00048     case QtCriticalMsg: priority = LOG_CRIT; break;
00049     case QtFatalMsg: priority = LOG_EMERG; break;
00050     case QtDebugMsg:
00051                      /* fall through */
00052     default: priority = LOG_INFO; break;
00053     }
00054 
00055     syslog(priority, "%s", msg);
00056 }
00057 
00058 int main(int argc, char *argv[])
00059 {
00060     qInstallMsgHandler(messageHandler);
00061     debugInit();
00062 
00063     TRACE() << "handler:" << (void *)messageHandler;
00064 
00065 #ifndef NO_SIGNON_USER
00066     if (!::getuid()) {
00067         BLAME() << argv[0] << " cannot be started with root priviledges!!!";
00068         exit(2);
00069     }
00070 #endif
00071 
00072     QCoreApplication app(argc, argv);
00073 
00074     if (argc < 2) {
00075         TRACE() << "Type of plugin is not specified";
00076         exit(1);
00077     }
00078 
00079     QString type = app.arguments().at(1); TRACE() << type;
00080 
00081     fcntl(fileno(stdin), F_SETFL, fcntl(fileno(stdin), F_GETFL, 0) | O_NONBLOCK);
00082 
00083     process = RemotePluginProcess::createRemotePluginProcess(type, &app);
00084 
00085     if (!process)
00086         return 1;
00087 
00088     fprintf(stdout, "process started");
00089     fflush(stdout);
00090 
00091     QObject::connect(process, SIGNAL(processStopped()), &app, SLOT(quit()));
00092     return app.exec();
00093 }