Bug 81927 - ksysv crash on startup when net hostname is not found in /etc/hosts
Summary: ksysv crash on startup when net hostname is not found in /etc/hosts
Status: RESOLVED FIXED
Alias: None
Product: ksysv
Classification: Unmaintained
Component: general (other bugs)
Version First Reported In: 1.3.8
Platform: Compiled Sources Linux
: NOR crash
Target Milestone: ---
Assignee: Niels Sascha Reedijk
URL:
Keywords:
: 37123 86356 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-05-20 21:25 UTC by raunsi
Modified: 2006-05-23 18:04 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description raunsi 2004-05-20 21:25:52 UTC
Version:           1.3.8 (using KDE KDE 3.2.0)
Installed from:    Compiled From Sources
Compiler:          gcc (GCC) 3.3.2 (Mandrake Linux 10.0 3.3.2-6mdk) 
OS:                Linux

ksysv crashes immediately after starting with signal 11. The crash is caused by the fact that the hostname returned by gethostname is not found by gethostbyname in /etc/hosts. My hostname set on linux boot time is "linux", my /etc/hosts looks like:

192.168.1.1     my_router
127.0.0.1       localhost

This makes ksysv crash in ksv_core.cpp at line #106:

102  if (!gethostname (buffer, BUFFER_LEN))
103    {
104      hostent* info = gethostbyname (buffer);
105
106      hostname = info->h_name;
107    }
108  else
109    {
110      hostname = i18n("Unknown Host");
110    }

gethostname returns "linux" in buffer, but gethostbyname returns a zero pointer so that access to info caises signal 11 crash.
Comment 1 Rob Downing 2005-05-01 20:44:38 UTC
Added hostname to /etc/hosts and problem was resolved.  Believe this to confirm circumvention.
Comment 2 Dirk Mueller 2006-05-23 17:54:21 UTC
*** Bug 86356 has been marked as a duplicate of this bug. ***
Comment 3 Dirk Mueller 2006-05-23 17:55:50 UTC
*** Bug 37123 has been marked as a duplicate of this bug. ***
Comment 4 Dirk Mueller 2006-05-23 18:04:07 UTC
SVN commit 544103 by mueller:

fix crash on startup
BUG: 81927


 M  +2 -1      TopWidget.cpp  
 M  +0 -29     ksv_core.cpp  
 M  +0 -5      ksv_core.h  


--- branches/KDE/3.5/kdeadmin/ksysv/TopWidget.cpp #544102:544103
@@ -51,6 +51,7 @@
 #include <qwhatsthis.h>
 #include <qsimplerichtext.h>
 
+#include <kresolver.h>
 #include <ktoolbar.h>
 #include <kkeydialog.h>
 #include <kmenubar.h>
@@ -953,7 +954,7 @@
 
 void KSVTopLevel::setCaption (bool changed)
 {
-  setPlainCaption (kapp->makeStdCaption(ksv::hostname(), true, changed));
+  setPlainCaption (kapp->makeStdCaption(KNetwork::KResolver::localHostName(), true, changed));
 }
 
 KActionCollection* KSVTopLevel::filteredActions ()
--- branches/KDE/3.5/kdeadmin/ksysv/ksv_core.cpp #544102:544103
@@ -12,10 +12,6 @@
  *                                                                         *
  ***************************************************************************/
 
-#include <ctype.h>
-#include <unistd.h>
-#include <netdb.h>
-
 #include <qpushbutton.h>
 #include <qstylesheet.h>
 
@@ -89,31 +85,6 @@
   return c;
 }
 
-QString ksv::hostname ()
-{
-#ifndef BUFFER_LEN
-#define BUFFER_LEN 255
-#endif
-  char buffer[BUFFER_LEN];
-  QString hostname;
-
-  if (!gethostname (buffer, BUFFER_LEN))
-    {
-      hostent* info = gethostbyname (buffer);
-
-      hostname = info->h_name;
-    }
-  else
-    {
-      hostname = i18n("Unknown Host");
-    }
-#ifdef BUFFER_LEN
-#undef BUFFER_LEN
-#endif
-
-  return hostname;
-}
-
 QStyleSheet* ksv::styleSheet ()
 {
   static QStyleSheet style;
--- branches/KDE/3.5/kdeadmin/ksysv/ksv_core.h #544102:544103
@@ -32,11 +32,6 @@
    */
   const QString& copyrightSymbol ();
 
-  /**
-   * \return the hostname (or "Unknown Host")
-   */
-  QString hostname ();
-
   QStyleSheet* styleSheet ();
 
   const QString& logFileFilter ();