PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Programm als root starten



ChMaster|LFreak
04-11-2003, 07:24
moin zusammen,

ich möchte meine programm als root starten, in dem ich einfach nur auf die datei klicke.
hier ist mal ein codesnipe meiner main.cpp.



#include <kcmdlineargs.h>
#include <kaboutdata.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kapp.h>

#include "kkyrocard.h"
#include "kkc_main.h"
#include "kkc_check.h"

#include <qprocess.h>
#include <qstringlist.h>
#include <sys/utsname.h>
#include <unistd.h>
#include <sys/wait.h>

static const char *description =
I18N_NOOP("KKyroCard");
// INSERT A DESCRIPTION FOR YOUR APPLICATION HERE


static KCmdLineOptions options[] =
{
{ 0, 0, 0 }
// INSERT YOUR COMMANDLINE OPTIONS HERE
};

int main(int argc, char *argv[])
{

KAboutData aboutData( "kkyrocard", I18N_NOOP("KKyroCard"),
VERSION, description, KAboutData::License_GPL,
"(c) 2003, Alexander", 0, 0, "chmaster.cm@web.de");
aboutData.addAuthor("Alexander",0, "chmaster.cm@web.de");
KCmdLineArgs::init( argc, argv, &aboutData );
KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.

KApplication a;

KKC_Check *gui_kkc = new KKC_Check();
a.setMainWidget( gui_kkc );
gui_kkc->show();

if (getuid() != 0)
{
gui_kkc->hide();
switch (KMessageBox::questionYesNo(0, i18n("You are not running K-KyroCard as root\nK-KyroCard only"
" works if run as root.\nDo you want to launch root authentication"
" (using kdesu)?")))
{
case KMessageBox::Yes:
{
execlp("kdesu", "kdesu", "-n", "./kkyrocard", (void*)0);
KMessageBox::error(0, i18n("You don't have kdesu in your system, so root authentication can't be launched using"
" kkyrocard.\nUse 'su' in the shell"));
}
}
}
else
{
return a.exec();
}
}


wenn ich es in kdevelop kompeliere und starte funktiniert es aber wenn ich nur auf die datei klicke bringt er mir das kdesu (gebe mein pwd ein), und das wars. wer kann mir helfen? der codeteil stammt aus dem programm klt von tsdgeos zu finden unter KLT (http://klt.sourceforge.net/)

habe vergessen noch zu erwähnen, wenn ich es in einer konsole starte funktioniert es auch.

gruss
ChMaster, LFreak aka Alexander