mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 11:51:27 +00:00
Detach process with F_NOWAIT (#450)
* Experimental PCRE library support To compile with PCRE install libpcre-dev(el) and run: cc -Wall -Wextra -O3 -DPCRE -D_GNU_SOURCE -D_DEFAULT_SOURCE -I/usr/include/ncursesw -I/usr/include -o nnn src/nnn.c -lreadline -lncursesw -ltinfo -lpcre * Detach process with F_NOWAIT Co-authored-by: Mischievous Meerkat <engineerarun@gmail.com>
This commit is contained in:
parent
827875c3ef
commit
27617c0446
35
src/nnn.c
35
src/nnn.c
|
@ -1279,6 +1279,7 @@ static int parseargs(char *line, char **argv)
|
||||||
|
|
||||||
static pid_t xfork(uchar flag)
|
static pid_t xfork(uchar flag)
|
||||||
{
|
{
|
||||||
|
int status;
|
||||||
pid_t p = fork();
|
pid_t p = fork();
|
||||||
|
|
||||||
if (p > 0) {
|
if (p > 0) {
|
||||||
|
@ -1286,16 +1287,37 @@ static pid_t xfork(uchar flag)
|
||||||
oldsighup = signal(SIGHUP, SIG_IGN);
|
oldsighup = signal(SIGHUP, SIG_IGN);
|
||||||
oldsigtstp = signal(SIGTSTP, SIG_DFL);
|
oldsigtstp = signal(SIGTSTP, SIG_DFL);
|
||||||
} else if (p == 0) {
|
} else if (p == 0) {
|
||||||
/* so they can be used to stop the child */
|
/* 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(SIGHUP, SIG_DFL);
|
||||||
signal(SIGINT, SIG_DFL);
|
signal(SIGINT, SIG_DFL);
|
||||||
signal(SIGQUIT, SIG_DFL);
|
signal(SIGQUIT, SIG_DFL);
|
||||||
signal(SIGTSTP, SIG_DFL);
|
signal(SIGTSTP, SIG_DFL);
|
||||||
|
|
||||||
if (flag & F_NOWAIT)
|
|
||||||
setsid();
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* This is the parent waiting for the child to create grandchild*/
|
||||||
|
if (flag & F_NOWAIT)
|
||||||
|
waitpid(p, &status, 0);
|
||||||
|
|
||||||
if (p == -1)
|
if (p == -1)
|
||||||
perror("fork");
|
perror("fork");
|
||||||
return p;
|
return p;
|
||||||
|
@ -1854,7 +1876,6 @@ static char xchartohex(char c)
|
||||||
|
|
||||||
static char * (*fnstrstr)(const char *haystack, const char *needle) = &strcasestr;
|
static char * (*fnstrstr)(const char *haystack, const char *needle) = &strcasestr;
|
||||||
#ifdef PCRE
|
#ifdef PCRE
|
||||||
static const unsigned char *tables;
|
|
||||||
static int pcreflags = PCRE_NO_AUTO_CAPTURE | PCRE_EXTENDED | PCRE_CASELESS;
|
static int pcreflags = PCRE_NO_AUTO_CAPTURE | PCRE_EXTENDED | PCRE_CASELESS;
|
||||||
#else
|
#else
|
||||||
static int regflags = REG_NOSUB | REG_EXTENDED | REG_ICASE;
|
static int regflags = REG_NOSUB | REG_EXTENDED | REG_ICASE;
|
||||||
|
@ -1863,12 +1884,8 @@ static int regflags = REG_NOSUB | REG_EXTENDED | REG_ICASE;
|
||||||
#ifdef PCRE
|
#ifdef PCRE
|
||||||
static int setfilter(pcre **pcrex, const char *filter)
|
static int setfilter(pcre **pcrex, const char *filter)
|
||||||
{
|
{
|
||||||
const char *errstr = NULL;
|
*pcrex = pcre_compile(filter, pcreflags, NULL, NULL, NULL);
|
||||||
int erroffset = 0;
|
return *pcrex ? 0 : -1;
|
||||||
|
|
||||||
*pcrex = pcre_compile(filter, pcreflags, &errstr, &erroffset, tables);
|
|
||||||
|
|
||||||
return errstr ? -1 : 0;
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static int setfilter(regex_t *regex, const char *filter)
|
static int setfilter(regex_t *regex, const char *filter)
|
||||||
|
|
Loading…
Reference in a new issue