static pid_t xfork(uchar flag)
{
+ int status;
pid_t p = fork();
if (p > 0) {
oldsighup = signal(SIGHUP, SIG_IGN);
oldsigtstp = signal(SIGTSTP, SIG_DFL);
} else if (p == 0) {
+ /* We create a grandchild to detach */
+ if (flag & F_NOWAIT) {
+ p = fork();
+
+ if (p > 0)
+ exit(0);
+ else if (p == 0) {
+ signal(SIGHUP, SIG_DFL);
+ signal(SIGINT, SIG_DFL);
+ signal(SIGQUIT, SIG_DFL);
+ signal(SIGTSTP, SIG_DFL);
+
+ setsid();
+ return p;
+ }
+
+ perror("fork");
+ exit(0);
+ }
+
/* so they can be used to stop the child */
signal(SIGHUP, SIG_DFL);
signal(SIGINT, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
signal(SIGTSTP, SIG_DFL);
-
- if (flag & F_NOWAIT)
- setsid();
}
+ /* This is the parent waiting for the child to create grandchild*/
+ if (flag & F_NOWAIT)
+ waitpid(p, &status, 0);
+
if (p == -1)
perror("fork");
return p;
static char * (*fnstrstr)(const char *haystack, const char *needle) = &strcasestr;
#ifdef PCRE
-static const unsigned char *tables;
static int pcreflags = PCRE_NO_AUTO_CAPTURE | PCRE_EXTENDED | PCRE_CASELESS;
#else
static int regflags = REG_NOSUB | REG_EXTENDED | REG_ICASE;
#ifdef PCRE
static int setfilter(pcre **pcrex, const char *filter)
{
- const char *errstr = NULL;
- int erroffset = 0;
-
- *pcrex = pcre_compile(filter, pcreflags, &errstr, &erroffset, tables);
-
- return errstr ? -1 : 0;
+ *pcrex = pcre_compile(filter, pcreflags, NULL, NULL, NULL);
+ return *pcrex ? 0 : -1;
}
#else
static int setfilter(regex_t *regex, const char *filter)