It makes descriptor juggling much more reliable. Increase version
requirement on mLib to 2.1.0.
#include <mLib/daemonize.h>
#include <mLib/darray.h>
#include <mLib/dstr.h>
#include <mLib/daemonize.h>
#include <mLib/darray.h>
#include <mLib/dstr.h>
#include <mLib/mdwopt.h>
#include <mLib/quis.h>
#include <mLib/report.h>
#include <mLib/mdwopt.h>
#include <mLib/quis.h>
#include <mLib/report.h>
uid_t u = -1;
gid_t g = -1;
int pfd[2], efd[2];
uid_t u = -1;
gid_t g = -1;
int pfd[2], efd[2];
pid_t kid;
struct sigaction sa;
sigset_t newmask, oldmask;
pid_t kid;
struct sigaction sa;
sigset_t newmask, oldmask;
if ((kid = fork()) < 0)
die(EXIT_FAILURE, "fork failed: %s", strerror(errno));
if (!kid) {
if ((kid = fork()) < 0)
die(EXIT_FAILURE, "fork failed: %s", strerror(errno));
if (!kid) {
- dup2(pfd[1], STDIN_FILENO);
- dup2(pfd[1], STDOUT_FILENO);
- dup2(efd[1], STDERR_FILENO);
- close(pfd[0]); close(pfd[1]);
- close(efd[0]); close(efd[1]);
+ close(pfd[0]); close(efd[0]);
+ md[0].cur = pfd[1]; md[0].want = STDIN_FILENO;
+ md[1].cur = pfd[1]; md[1].want = STDOUT_FILENO;
+ md[2].cur = efd[1]; md[2].want = STDERR_FILENO;
+ mdup(md, 3);
if (logfp) fclose(logfp);
if (pidfp) fclose(pidfp);
closelog();
if (logfp) fclose(logfp);
if (pidfp) fclose(pidfp);
closelog();
-PKG_CHECK_MODULES([mLib], [mLib >= 2.0.4])
+PKG_CHECK_MODULES([mLib], [mLib >= 2.1.0])
PKG_CHECK_MODULES([catacomb], [catacomb >= 2.1.1])
CFLAGS="$CFLAGS $mLib_CFLAGS $catacomb_CFLAGS"
PKG_CHECK_MODULES([catacomb], [catacomb >= 2.1.1])
CFLAGS="$CFLAGS $mLib_CFLAGS $catacomb_CFLAGS"
const char *helper;
if (socketpair(PF_UNIX, SOCK_STREAM, 0, fd)) {
const char *helper;
if (socketpair(PF_UNIX, SOCK_STREAM, 0, fd)) {
if (kid == 0) {
signal(SIGCHLD, SIG_DFL);
if (detachp) detachtty();
if (kid == 0) {
signal(SIGCHLD, SIG_DFL);
if (detachp) detachtty();
- if (dup2(fd[0], 0) < 0) goto lose;
- close(fd[0]); close(fd[1]);
+ close(fd[1]);
+ md[0].cur = fd[0]; md[0].want = STDIN_FILENO;
+ if (mdup(md, 1)) goto lose;
execl(helper, helper, (char *)0);
lose:
fprintf(stderr, "helper: failed to run helper: %s\n", strerror(errno));
execl(helper, helper, (char *)0);
lose:
fprintf(stderr, "helper: failed to run helper: %s\n", strerror(errno));
#include <mLib/fwatch.h>
#include <mLib/hash.h>
#include <mLib/macros.h>
#include <mLib/fwatch.h>
#include <mLib/hash.h>
#include <mLib/macros.h>
#include <mLib/mdwopt.h>
#include <mLib/quis.h>
#include <mLib/report.h>
#include <mLib/mdwopt.h>
#include <mLib/quis.h>
#include <mLib/report.h>
{
slipif *sl = 0;
int pin[2] = { -1, -1 }, pout[2] = { -1, -1 };
{
slipif *sl = 0;
int pin[2] = { -1, -1 }, pout[2] = { -1, -1 };
pid_t kid = -1;
dstr d = DSTR_INIT;
unsigned char ch;
pid_t kid = -1;
dstr d = DSTR_INIT;
unsigned char ch;
- close(pin[1]);
- close(pout[0]);
- dup2(pin[0], STDIN_FILENO);
- dup2(pout[1], STDOUT_FILENO);
+ close(pin[1]); close(pout[0]);
+ md[0].cur = pin[0]; md[0].want = STDIN_FILENO;
+ md[1].cur = pout[0]; md[1].want = STDOUT_FILENO;
+ mdup(md, 2);
execlp(slipcmd, slipcmd, p_name(p), (char *)0);
_exit(127);
}
execlp(slipcmd, slipcmd, p_name(p), (char *)0);
_exit(127);
}