• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • sources
  • kde-4.14
  • kdelibs
  • kdecore
  • auth
kauthhelpersupport.cpp
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2008 Nicola Gigante <nicola.gigante@gmail.com>
3 * Copyright (C) 2009 Dario Freddi <drf@kde.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation; either version 2.1 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program; if not, write to the
17 * Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA .
19 */
20 
21 #include "kauthhelpersupport.h"
22 
23 #include <cstdlib>
24 #include <syslog.h>
25 
26 #ifdef Q_OS_UNIX
27 #include <unistd.h>
28 #include <sys/types.h>
29 #include <pwd.h>
30 #endif
31 
32 #include <QCoreApplication>
33 #include <QTimer>
34 
35 #include "BackendsManager.h"
36 
37 Q_DECLARE_METATYPE(QTimer*)
38 
39 namespace KAuth
40 {
41 
42 namespace HelperSupport
43 {
44 void helperDebugHandler(QtMsgType type, const char *msg);
45 }
46 
47 static bool remote_dbg = false;
48 
49 #ifdef Q_OS_UNIX
50 static void fixEnvironment()
51 {
52  //try correct HOME
53  const char *home = "HOME";
54  if(getenv(home)==NULL)
55  {
56  struct passwd *pw = getpwuid(getuid());
57  int overwrite = 0;
58 
59  if (pw!=NULL) setenv(home, pw->pw_dir, overwrite);
60  }
61 }
62 #endif
63 
64 int HelperSupport::helperMain(int argc, char **argv, const char *id, QObject *responder)
65 {
66 #ifdef Q_OS_UNIX
67  fixEnvironment();
68 #endif
69 
70  openlog(id, 0, LOG_USER);
71  qInstallMsgHandler(&HelperSupport::helperDebugHandler);
72 
73  if (!BackendsManager::helperProxy()->initHelper(QString::fromLatin1(id))) {
74  syslog(LOG_DEBUG, "Helper initialization failed");
75  return -1;
76  }
77 
78  //closelog();
79  remote_dbg = true;
80 
81  BackendsManager::helperProxy()->setHelperResponder(responder);
82 
83  QCoreApplication app(argc, argv);
84  // Attach the timer
85  QTimer *timer = new QTimer(0);
86  responder->setProperty("__KAuth_Helper_Shutdown_Timer", QVariant::fromValue(timer));
87  timer->setInterval(10000);
88  timer->start();
89  QObject::connect(timer, SIGNAL(timeout()), &app, SLOT(quit()));
90  app.exec(); //krazy:exclude=crashy
91 
92  return 0;
93 }
94 
95 void HelperSupport::helperDebugHandler(QtMsgType type, const char *msg)
96 {
97  if (!remote_dbg) {
98  int level = LOG_DEBUG;
99  switch (type) {
100  case QtDebugMsg:
101  level = LOG_DEBUG;
102  break;
103  case QtWarningMsg:
104  level = LOG_WARNING;
105  break;
106  case QtCriticalMsg:
107  case QtFatalMsg:
108  level = LOG_ERR;
109  break;
110  }
111  syslog(level, "%s", msg);
112  } else {
113  BackendsManager::helperProxy()->sendDebugMessage(type, msg);
114  }
115 
116  // Anyway I should follow the rule:
117  if (type == QtFatalMsg) {
118  exit(-1);
119  }
120 }
121 
122 void HelperSupport::progressStep(int step)
123 {
124  BackendsManager::helperProxy()->sendProgressStep(step);
125 }
126 
127 void HelperSupport::progressStep(const QVariantMap &data)
128 {
129  BackendsManager::helperProxy()->sendProgressStep(data);
130 }
131 
132 bool HelperSupport::isStopped()
133 {
134  return BackendsManager::helperProxy()->hasToStopAction();
135 }
136 
137 } // namespace Auth
KAuth::HelperSupport::helperMain
int helperMain(int argc, char **argv, const char *id, QObject *responder)
Method that implements the main function of the helper tool.
Definition: kauthhelpersupport.cpp:64
QTimer::setInterval
void setInterval(int msec)
kauthhelpersupport.h
KAuth::HelperSupport::isStopped
bool isStopped()
Check if the caller asked the helper to stop the execution.
Definition: kauthhelpersupport.cpp:132
timeout
int timeout
Definition: kkernel_mac.cpp:46
QCoreApplication
KAuth::fixEnvironment
static void fixEnvironment()
Definition: kauthhelpersupport.cpp:50
QCoreApplication::exec
int exec()
QTimer
KAuth::remote_dbg
static bool remote_dbg
Definition: kauthhelpersupport.cpp:47
QObject
KAuth::HelperSupport::helperDebugHandler
void helperDebugHandler(QtMsgType type, const char *msg)
Definition: kauthhelpersupport.cpp:95
QVariant::fromValue
QVariant fromValue(const T &value)
QString::fromLatin1
QString fromLatin1(const char *str, int size)
QTimer::start
void start(int msec)
QObject::setProperty
bool setProperty(const char *name, const QVariant &value)
KAuth::HelperSupport::progressStep
void progressStep(int step)
Send a progressStep signal to the caller application.
Definition: kauthhelpersupport.cpp:122
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
BackendsManager.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal