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

tdeinit

tdelauncher_main.cpp

00001 /*
00002   This file is part of the KDE libraries
00003   Copyright (c) 1999 Waldo Bastian <bastian@kde.org>
00004 
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Library General Public
00007   License version 2 as published by the Free Software Foundation.
00008 
00009   This library is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012   Library General Public License for more details.
00013 
00014   You should have received a copy of the GNU Library General Public License
00015   along with this library; see the file COPYING.LIB.  If not, write to
00016   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017   Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "config.h"
00021 
00022 #include <unistd.h>
00023 #include <fcntl.h>
00024 
00025 #include "tdeapplication.h"
00026 #include "tdelauncher.h"
00027 #include "tdecmdlineargs.h"
00028 #include "kcrash.h"
00029 #include "kdebug.h"
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include <signal.h>
00033 #include <tqcstring.h>
00034 #include <tdelocale.h>
00035 
00036 #include "tdelauncher_cmds.h"
00037 
00038 static void sig_handler(int sig_num)
00039 {
00040    // No recursion
00041    signal( SIGHUP, SIG_IGN);
00042    signal( SIGTERM, SIG_IGN);
00043    fprintf(stderr, "[tdelauncher] Exiting on signal %d\n", sig_num);
00044    TDELauncher::destruct(255);
00045 }
00046 
00047 static TDECmdLineOptions options[] =
00048 {
00049   { "new-startup", "Internal", 0 },
00050   TDECmdLineLastOption
00051 };
00052 
00053 extern "C" KDE_EXPORT int kdemain( int argc, char**argv )
00054 {
00055    // Started via tdeinit.
00056    if (fcntl(LAUNCHER_FD, F_GETFD) == -1)
00057    {
00058       fprintf(stderr, "%s", i18n("[tdelauncher] This program is not supposed to be started manually.\n"
00059                                  "[tdelauncher] It is started automatically by tdeinit.\n").local8Bit().data());
00060       return 1;
00061    }
00062 
00063    TQCString cname = TDEApplication::launcher();
00064    char *name = cname.data();
00065    TDECmdLineArgs::init(argc, argv, name, "TDELauncher", "A service launcher.",
00066                        "v1.0");
00067 
00068    TDELauncher::addCmdLineOptions();
00069    TDECmdLineArgs::addCmdLineOptions( options );
00070 
00071    // WABA: Make sure not to enable session management.
00072    putenv(strdup("SESSION_MANAGER="));
00073 
00074    // Allow the locale to initialize properly
00075    TDELocale::setMainCatalogue("tdelibs");
00076 
00077    TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
00078 
00079    int maxTry = 3;
00080    while(true)
00081    {
00082       TQCString dcopName = TDEApplication::dcopClient()->registerAs(name, false);
00083       if (dcopName.isEmpty())
00084       {
00085          kdWarning() << "[tdelauncher] DCOP communication problem!" << endl;
00086          return 1;
00087       }
00088       if (dcopName == cname)
00089          break; // Good!
00090 
00091       if (--maxTry == 0)
00092       {
00093          kdWarning() << "[tdelauncher] Another instance of tdelauncher is already running!" << endl;
00094          return 1;
00095       }
00096       
00097       // Wait a bit...
00098       kdWarning() << "[tdelauncher] Waiting for already running tdelauncher to exit." << endl;
00099       sleep(1);
00100 
00101       // Try again...
00102    }
00103    
00104    TDELauncher *launcher = new TDELauncher(LAUNCHER_FD, args->isSet("new-startup"));
00105    launcher->dcopClient()->setDefaultObject( name );
00106    launcher->dcopClient()->setDaemonMode( true );
00107 
00108    TDECrash::setEmergencySaveFunction(sig_handler);
00109    signal( SIGHUP, sig_handler);
00110    signal( SIGPIPE, SIG_IGN);
00111    signal( SIGTERM, sig_handler);
00112 
00113    launcher->exec();
00114    return 0;
00115 }
00116 

tdeinit

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

tdeinit

Skip menu "tdeinit"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeinit by doxygen 1.7.1
This website is maintained by Timothy Pearson.