KInit
klauncher_main.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "config.h"
00021
00022 #include <unistd.h>
00023 #include <fcntl.h>
00024
00025 #include "kapplication.h"
00026 #include "klauncher.h"
00027 #include "kcmdlineargs.h"
00028 #include "kcrash.h"
00029 #include "kdebug.h"
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include <signal.h>
00033 #include <qcstring.h>
00034 #include <klocale.h>
00035
00036 #include "klauncher_cmds.h"
00037
00038 static void sig_handler(int sig_num)
00039 {
00040
00041 signal( SIGHUP, SIG_IGN);
00042 signal( SIGTERM, SIG_IGN);
00043 fprintf(stderr, "klauncher: Exiting on signal %d\n", sig_num);
00044 KLauncher::destruct(255);
00045 }
00046
00047 static KCmdLineOptions options[] =
00048 {
00049 { "new-startup", "Internal", 0 },
00050 KCmdLineLastOption
00051 };
00052
00053 extern "C" KDE_EXPORT int kdemain( int argc, char**argv )
00054 {
00055
00056 if (fcntl(LAUNCHER_FD, F_GETFD) == -1)
00057 {
00058 fprintf(stderr, "%s", i18n("klauncher: This program is not supposed to be started manually.\n"
00059 "klauncher: It is started automatically by kdeinit.\n").local8Bit().data());
00060 return 1;
00061 }
00062
00063 QCString cname = KApplication::launcher();
00064 char *name = cname.data();
00065 KCmdLineArgs::init(argc, argv, name, "KLauncher", "A service launcher.",
00066 "v1.0");
00067
00068 KLauncher::addCmdLineOptions();
00069 KCmdLineArgs::addCmdLineOptions( options );
00070
00071
00072 putenv(strdup("SESSION_MANAGER="));
00073
00074
00075 KLocale::setMainCatalogue("kdelibs");
00076
00077 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00078
00079 int maxTry = 3;
00080 while(true)
00081 {
00082 QCString dcopName = KApplication::dcopClient()->registerAs(name, false);
00083 if (dcopName.isEmpty())
00084 {
00085 kdWarning() << "DCOP communication problem!" << endl;
00086 return 1;
00087 }
00088 if (dcopName == cname)
00089 break;
00090
00091 if (--maxTry == 0)
00092 {
00093 kdWarning() << "Another instance of klauncher is already running!" << endl;
00094 return 1;
00095 }
00096
00097
00098 kdWarning() << "Waiting for already running klauncher to exit." << endl;
00099 sleep(1);
00100
00101
00102 }
00103
00104 KLauncher *launcher = new KLauncher(LAUNCHER_FD, args->isSet("new-startup"));
00105 launcher->dcopClient()->setDefaultObject( name );
00106 launcher->dcopClient()->setDaemonMode( true );
00107
00108 KCrash::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