[omniORB] system() under omniORB4
Sander Steffann
sander@steffann.nl
Wed Oct 9 21:08:00 2002
This is a multi-part message in MIME format.
------=_NextPart_000_0008_01C26FE0.4CF46E00
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Hi,
> I have a server which, under omniORB3, invoked system() to
> execute a shell command. Under omniORB4, however, the server
> dies instantly..at least the thread invoking system() does. Is
> system() prohibited under omniORB4 and if so, how can I achieve
> the same results?
I had problems with using system() too. Try the attached version. I use it
in a program here and it works for me.
Good luck,
Sander.
------=_NextPart_000_0008_01C26FE0.4CF46E00
Content-Type: application/octet-stream;
name="nbs_system.cc"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="nbs_system.cc"
/*************************************************************************\
NBS: Nederland.net Beheer Systeem (c) 2002 Computel Standby BV
*************************************************************************
Filename: nbs_system.cc - Created by SJM Steffann on 2002/07/30
Description: Alternative system call
*************************************************************************
$Id: nbs_system.cc,v 1.1 2002/08/04 13:44:34 sander Exp $
\*************************************************************************/
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
int nbs_system (char const *command) {
int pid, status;
if (command == 0)
return 1;
pid = fork();
if (pid == -1)
return -1;
if (pid == 0) {
// /dev/null file descriptors
int devnull = open("/dev/null", O_NONBLOCK | O_RDWR);
if (devnull == -1)
exit(127);
if ((dup2(devnull, 0) == -1)
|| (dup2(devnull, 1) == -1)
|| (dup2(devnull, 2) == -1))
exit(127);
close (devnull);
// Unblock all signals
sigset_t signal_set;
sigemptyset(&signal_set);
sigprocmask(SIG_SETMASK, &signal_set, NULL);
// Give me a separate process group
if (setpgrp() == -1)
exit(127);
// Ignore signals
signal(SIGINT ,SIG_IGN);
signal(SIGQUIT ,SIG_IGN);
signal(SIGTERM ,SIG_IGN);
char* argv[4];
argv[0] = "sh";
argv[1] = "-c";
argv[2] = (char*) command;
argv[3] = 0;
execv("/bin/sh", argv);
exit(127);
}
do {
if (waitpid(pid, &status, 0) == -1) {
if (errno != EINTR)
return -1;
} else {
return status;
}
} while(1);
}
------=_NextPart_000_0008_01C26FE0.4CF46E00--