0

Im trying to use Qt in order to create a server/client program that works with Inetd/xinetd on Linux OS.

I have added the service configuration file to /etc/xinetd.d/testServ with this text

service testServ
{
  socket_type = stream
  protocol = tcp
  wait = no
  user = root
 server = /usr/sbin/testServer
 }

Then i have added this line to the /etc/services

 testServ   5050/tcp    # the service uses the port nr 5050 and tcp protocol

I have created a special client program that connetcs to the server with the specefied port, which works without problems.

The problem is on the server program. I have written this code in the main function of the server program

Int main(int argc, char *argv[]) {
  qDebug()<<"starting the daemon version of server client app";
  QApplication app(argc, argv);
  setvbuf(stdout, NULL, _IONBF, 0);
  setvbuf(stdin,  NULL, _IONBF, 0);
  QFile fstdin;
  QFile fstdout;
  fstdout.open(stdout, QFile::WriteOnly|QFile::Unbuffered);
  fstdin.open(stdin, QFile::ReadOnly);
  CleintProcess clientproc (NULL, &slog, argc, argv, &fstdin, &fstdout);
  app.exec();
  return 0;
}

The problem on the server program is at the second line in the main function, the program does not continue after this line. If i print something after this line it does not appear on the screen, but if i print something before this line the print message appears. I dont know why Inetd/xinetd does not work with QApplication app(argc, argv);

when i delete this line and the other line (app.exe) the program terminated directly.

I need the QApplication, because i m using it manytimes in the object clientproc( ....).

Can you help me to solve this problem and get the qt working with inetd/xinetd on linux.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Waleed A
  • 95
  • 10
  • Just some clarification: the server program does not run using inetd? What about debugging the server side? Does it continue? If so, may it be an access rights problem because Qt is dynamically built? – maxik Jun 28 '16 at 06:58
  • @maxik yes, when i debug on the server side it continue working. But when i try to use the server program via Inetd, it stops at the line where QApplication app (argc,argv) is, and does not give any output. may be as you said it is an access right problem!! how to solve it – Waleed A Jun 28 '16 at 07:59
  • That's a huge field of trouble... You may start with the user which executes the intd services and its rights. Another thing is deployment, if your 'server side' is not on your development machine. You may be missing some Qt plugins which are loaded during application startup. Anyway, the deamon should provide some proper logging capability, try to redirect the debug output to a file and enable Qt debugging output, as I recommend `QT_DEBUG_PLUGINS=1` option. – maxik Jun 28 '16 at 08:07
  • @maxik when i replace Qapplication with QCoreapplication it works, but my application need actually the Qapplication becuase i have alot of Gui and widgets. I have set the QT_DEBUG_PLUGINS=1, where can i find the log information, im not that expert in QT Environemnt. – Waleed A Jun 28 '16 at 09:08
  • 2
    There's the point, sorry for hanging. ;) Why your daemon needs an UI? `QCoreApplication` is a UI-less `QApplication` (which in fact adds some widget stuff). A deamon, by definition, should not need any UI stuff, shouldn't it? So the problem seems to be the request to display some things which the daemon is not allowed to do. Stick to `QCoreApplication`. – maxik Jun 28 '16 at 09:13

0 Answers0