signon
8.58
|
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 #define QT_DISABLE_DEPRECATED_BEFORE QT_VERSION_CHECK(4, 0, 0) 00035 00036 #include "debug.h" 00037 #include "remotepluginprocess.h" 00038 00039 #include <QDebug> 00040 00041 using namespace RemotePluginProcessNS; 00042 00043 RemotePluginProcess *process = NULL; 00044 00045 void messageHandler(QtMsgType type, const char *msg) 00046 { 00047 if (debugLevel < 2) { 00048 if (type == QtDebugMsg) return; 00049 if (debugLevel < 1 && type == QtWarningMsg) return; 00050 } 00051 00052 int priority; 00053 switch (type) { 00054 case QtWarningMsg: priority = LOG_WARNING; break; 00055 case QtCriticalMsg: priority = LOG_CRIT; break; 00056 case QtFatalMsg: priority = LOG_EMERG; break; 00057 case QtDebugMsg: 00058 /* fall through */ 00059 default: priority = LOG_INFO; break; 00060 } 00061 00062 syslog(priority, "%s", msg); 00063 } 00064 00065 int main(int argc, char *argv[]) 00066 { 00067 openlog(NULL, LOG_CONS | LOG_PID, LOG_DAEMON); 00068 qInstallMsgHandler(messageHandler); 00069 debugInit(); 00070 00071 TRACE() << "handler:" << (void *)messageHandler; 00072 00073 #ifndef NO_SIGNON_USER 00074 if (!::getuid()) { 00075 BLAME() << argv[0] << " cannot be started with root priviledges!!!"; 00076 exit(2); 00077 } 00078 #endif 00079 00080 QCoreApplication app(argc, argv); 00081 00082 if (argc < 2) { 00083 TRACE() << "Type of plugin is not specified"; 00084 exit(1); 00085 } 00086 00087 QString type = app.arguments().at(1); TRACE() << type; 00088 00089 fcntl(fileno(stdin), F_SETFL, fcntl(fileno(stdin), F_GETFL, 0) | O_NONBLOCK); 00090 00091 process = RemotePluginProcess::createRemotePluginProcess(type, &app); 00092 00093 if (!process) 00094 return 1; 00095 00096 fprintf(stdout, "process started"); 00097 fflush(stdout); 00098 00099 QObject::connect(process, SIGNAL(processStopped()), &app, SLOT(quit())); 00100 int ret = app.exec(); 00101 closelog(); 00102 return ret; 00103 }