TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tdelauncher_main.cpp 3.3KB

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