--- Linux-Clone/Clone.xs 2011/11/28 05:43:03 1.1 +++ Linux-Clone/Clone.xs 2016/08/24 03:34:24 1.2 @@ -9,6 +9,28 @@ #define _GNU_SOURCE #include +/* from schmorp.h */ +static int +s_fileno (SV *fh, int wr) +{ + dTHX; + SvGETMAGIC (fh); + + if (SvROK (fh)) + { + fh = SvRV (fh); + SvGETMAGIC (fh); + } + + if (SvTYPE (fh) == SVt_PVGV) + return PerlIO_fileno (wr ? IoOFP (sv_2io (fh)) : IoIFP (sv_2io (fh))); + + if (SvOK (fh) && (SvIV (fh) >= 0) && (SvIV (fh) < 0x7fffffffL)) + return SvIV (fh); + + return -1; +} + static int clone_cb (void *arg) { @@ -100,23 +122,19 @@ # ifdef CLONE_IO const_iv (IO) # endif +# ifdef CLONE_NEWCGROUP + const_iv (NEWCGROUP) +# endif }; for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); int -unshare (int flags) - CODE: - RETVAL = unshare (flags); - OUTPUT: - RETVAL - -int clone (SV *sub, IV stacksize, int flags, SV *ptid = 0, SV *tls = &PL_sv_undef) CODE: { - if (!stacksize) + if (!stacksize) stacksize = 4 << 20; pid_t ptid_; @@ -146,3 +164,9 @@ OUTPUT: RETVAL +int +unshare (int flags) + +int +setns (SV *fh_or_fd, int nstype = 0) + C_ARGS: s_fileno (fh_or_fd, 0), nstype