• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kinit
 

kinit

  • kinit
klauncher_main.cpp
1 /*
2  This file is part of the KDE libraries
3  Copyright (c) 1999 Waldo Bastian <bastian@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "config.h"
21 
22 #include <unistd.h>
23 #include <fcntl.h>
24 
25 #include "kapplication.h"
26 #include "klauncher.h"
27 #include "kcmdlineargs.h"
28 #include "kcrash.h"
29 #include "kdebug.h"
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <signal.h>
33 #include <tqcstring.h>
34 #include <klocale.h>
35 
36 #include "klauncher_cmds.h"
37 
38 static void sig_handler(int sig_num)
39 {
40  // No recursion
41  signal( SIGHUP, SIG_IGN);
42  signal( SIGTERM, SIG_IGN);
43  fprintf(stderr, "[klauncher] Exiting on signal %d\n", sig_num);
44  KLauncher::destruct(255);
45 }
46 
47 static KCmdLineOptions options[] =
48 {
49  { "new-startup", "Internal", 0 },
50  KCmdLineLastOption
51 };
52 
53 extern "C" KDE_EXPORT int kdemain( int argc, char**argv )
54 {
55  // Started via kdeinit.
56  if (fcntl(LAUNCHER_FD, F_GETFD) == -1)
57  {
58  fprintf(stderr, "%s", i18n("[klauncher] This program is not supposed to be started manually.\n"
59  "[klauncher] It is started automatically by kdeinit.\n").local8Bit().data());
60  return 1;
61  }
62 
63  TQCString cname = KApplication::launcher();
64  char *name = cname.data();
65  KCmdLineArgs::init(argc, argv, name, "KLauncher", "A service launcher.",
66  "v1.0");
67 
68  KLauncher::addCmdLineOptions();
69  KCmdLineArgs::addCmdLineOptions( options );
70 
71  // WABA: Make sure not to enable session management.
72  putenv(strdup("SESSION_MANAGER="));
73 
74  // Allow the locale to initialize properly
75  KLocale::setMainCatalogue("kdelibs");
76 
77  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
78 
79  int maxTry = 3;
80  while(true)
81  {
82  TQCString dcopName = KApplication::dcopClient()->registerAs(name, false);
83  if (dcopName.isEmpty())
84  {
85  kdWarning() << "[klauncher] DCOP communication problem!" << endl;
86  return 1;
87  }
88  if (dcopName == cname)
89  break; // Good!
90 
91  if (--maxTry == 0)
92  {
93  kdWarning() << "[klauncher] Another instance of klauncher is already running!" << endl;
94  return 1;
95  }
96 
97  // Wait a bit...
98  kdWarning() << "[klauncher] Waiting for already running klauncher to exit." << endl;
99  sleep(1);
100 
101  // Try again...
102  }
103 
104  KLauncher *launcher = new KLauncher(LAUNCHER_FD, args->isSet("new-startup"));
105  launcher->dcopClient()->setDefaultObject( name );
106  launcher->dcopClient()->setDaemonMode( true );
107 
108  KCrash::setEmergencySaveFunction(sig_handler);
109  signal( SIGHUP, sig_handler);
110  signal( SIGPIPE, SIG_IGN);
111  signal( SIGTERM, sig_handler);
112 
113  launcher->exec();
114  return 0;
115 }
116 

kinit

Skip menu "kinit"
  • Main Page
  • File List
  • Related Pages

kinit

Skip menu "kinit"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kinit by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |