[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    KProcess eats SIGCHLD, so pclose() fails
From:       David Faure <david () mandrakesoft ! com>
Date:       2001-11-28 17:32:07
[Download RAW message or body]

KProcessController, instantiated by KProcess, seems to grab all SIGCHLD events,
even the ones that have nothing to do with KProcess.

For instance I'm using popen() and pclose(), and the pclose() returns -1
with errno set to "no child process", due to this.

See the attached testcase, to be compiled with
g++ -I$QTDIR/include -L$QTDIR/lib popenkde.cpp -o popenkde -lqt -lkdecore
And run "./popenkde blah" (blah being the executable that doesn't exist ;)
Before the KProcess creation, the test works fine, after it it doesn't.

Is there anything that can be done about this ? (I'm no kprocess / unix signal
expert). Or do we really require all code run in a KDE application, to use
KProcess instead of popen/pclose ? This makes it hard to use 3rd-party libraries,
in e.g. a KPart, since konqueror uses KProcess for other things.

-- 
David FAURE, david@mandrakesoft.com, faure@kde.org
http://perso.mandrakesoft.com/~david/ , http://www.konqueror.org/
KDE 3.0: Konquering the Desktops

["popenkde.cpp" (text/x-c++src)]

#include <stdio.h>
#include <stdlib.h>
#include <kprocess.h>

void test(char *exe) {
  FILE *f = popen(exe, "r");
  if (!f) perror("popen failed");

  char tmp[1000];
  while (!feof(f)) {
    fgets(tmp, 900, f);
    if (tmp && *tmp)
      printf("read: %s\n", tmp);
    fflush(stdout);
  }
  int err = pclose(f);
  printf("error code: %d\n", err >> 8);
}

int main(int argc, char **argv) {
  if (argc != 2) {
    printf("usage: %s <command>\n", argv[0]);
    exit(1);
  }

  test(argv[1]);

  printf("Creating a KProcess");
  KProcess proc;
  test(argv[1]);

  return 0;
}


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic