10f66f451Sopenharmony_ci/* setsid.c - Run program in a new session ID.
20f66f451Sopenharmony_ci *
30f66f451Sopenharmony_ci * Copyright 2006 Rob Landley <rob@landley.net>
40f66f451Sopenharmony_ci
50f66f451Sopenharmony_ciUSE_SETSID(NEWTOY(setsid, "^<1t", TOYFLAG_USR|TOYFLAG_BIN))
60f66f451Sopenharmony_ci
70f66f451Sopenharmony_ciconfig SETSID
80f66f451Sopenharmony_ci  bool "setsid"
90f66f451Sopenharmony_ci  default y
100f66f451Sopenharmony_ci  help
110f66f451Sopenharmony_ci    usage: setsid [-t] command [args...]
120f66f451Sopenharmony_ci
130f66f451Sopenharmony_ci    Run process in a new session.
140f66f451Sopenharmony_ci
150f66f451Sopenharmony_ci    -t	Grab tty (become foreground process, receiving keyboard signals)
160f66f451Sopenharmony_ci*/
170f66f451Sopenharmony_ci
180f66f451Sopenharmony_ci#include "toys.h"
190f66f451Sopenharmony_ci
200f66f451Sopenharmony_civoid setsid_main(void)
210f66f451Sopenharmony_ci{
220f66f451Sopenharmony_ci  while (setsid()<0) if (XVFORK()) _exit(0);
230f66f451Sopenharmony_ci  if (toys.optflags) {
240f66f451Sopenharmony_ci    setpgid(0, 0);
250f66f451Sopenharmony_ci    tcsetpgrp(0, getpid());
260f66f451Sopenharmony_ci  }
270f66f451Sopenharmony_ci  xexec(toys.optargs);
280f66f451Sopenharmony_ci}
29