On Mon, Oct 02, 2000, flobro wrote:
> I have an application that can be built with and without pthreads.
> Without pthreads I can make a system() call to mkisofs .. OK..
>
> With pthreads, it just stops when it hits the system() call, and the
> main thread is showing as blocking on I/O - I have to ctrl-C to get out.
>
> Has anybody seen anything like this?
>
> Is it me or is there something special I have to do to make a system
> call (from the main thread)?
system(2) blocks the whole process and this way all of your Pth threads.
You have to use a thread-aware system(2) variant. For Pth 1.4a4 I've now
written such a pth_system() function. The source is appended below. You
can use this in your own source until Pth 1.4a4 is released.
Yours,
Ralf S. Engelschall
[EMAIL PROTECTED]
www.engelschall.com
/* Pth variant of system(3) */
int pth_system(const char *cmd)
{
#ifdef _PATH_BSHELL
#define PTH_PATH_BINSH _PATH_BSHELL
#else
#define PTH_PATH_BINSH "/bin/sh"
#endif
struct sigaction sa_ign, sa_int, sa_quit;
sigset_t ss_block, ss_old;
struct stat sb;
pid_t pid;
int pstat;
/* POSIX calling convention: determine whether the
Bourne Shell ("sh") is available on this platform */
if (cmd == NULL) {
if (stat(PTH_PATH_BINSH, &sb) == -1)
return 0;
return 1;
}
/* temporarily ignore SIGINT and SIGQUIT actions */
sa_ign.sa_handler = SIG_IGN;
sigemptyset(&sa_ign.sa_mask);
sa_ign.sa_flags = 0;
sigaction(SIGINT, &sa_ign, &sa_int);
sigaction(SIGQUIT, &sa_ign, &sa_quit);
/* block SIGCHLD signal */
sigemptyset(&ss_block);
sigaddset(&ss_block, SIGCHLD);
sigprocmask(SIG_BLOCK, &ss_block, &ss_old);
/* fork the current process */
pstat = -1;
switch (pid = pth_fork()) {
case -1: /* error */
break;
case 0: /* child */
/* restore original signal dispositions and execute the command */
sigaction(SIGINT, &sa_int, NULL);
sigaction(SIGQUIT, &sa_quit, NULL);
sigprocmask(SIG_SETMASK, &ss_old, NULL);
/* stop the Pth scheduling */
pth_scheduler_kill();
/* execute the command through Bourne Shell */
execl("/bin/sh", "sh", "-c", cmd, NULL);
/* POSIX compliant return in case execution failed */
exit(127);
default: /* parent */
/* wait until child process terminates */
pid = pth_waitpid(pid, &pstat, 0);
break;
}
/* restore original signal dispositions and execute the command */
sigaction(SIGINT, &sa_int, NULL);
sigaction(SIGQUIT, &sa_quit, NULL);
sigprocmask(SIG_SETMASK, &ss_old, NULL);
/* return error or child process result code */
return (pid == -1 ? -1 : pstat);
}
______________________________________________________________________
GNU Portable Threads (Pth) http://www.gnu.org/software/pth/
User Support Mailing List [EMAIL PROTECTED]
Automated List Manager (Majordomo) [EMAIL PROTECTED]