annotate toys/other/setsid.c @ 1005:03f72b57a092

DHCP client and server, from Ashwini Sharma.
author Rob Landley <rob@landley.net>
date Wed, 14 Aug 2013 19:09:33 -0500
parents 144d5ba7d410
children cbb1aca81eca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
1 /* setsid.c - Run program in a new session ID.
371
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
2 *
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
3 * Copyright 2006 Rob Landley <rob@landley.net>
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
4
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
5 USE_SETSID(NEWTOY(setsid, "^<1t", TOYFLAG_USR|TOYFLAG_BIN))
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
6
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
7 config SETSID
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
8 bool "setsid"
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
9 default y
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
10 help
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
11 usage: setsid [-t] command [args...]
371
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
12
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
13 Run process in a new session.
371
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
14
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
15 -t Grab tty (become foreground process, receiving keyboard signals)
371
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
16 */
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
17
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
18 #include "toys.h"
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
19
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
20 void setsid_main(void)
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
21 {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
22 while (setsid()<0) if (vfork()) _exit(0);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
23 if (toys.optflags) {
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
24 setpgid(0,0);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
25 tcsetpgrp(0, getpid());
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
26 }
955
144d5ba7d410 Replace users of xexec(toys.optargs) with xexec_optargs(0) to avoid free/reuse bug during argument parsing.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
27 xexec_optargs(0);
371
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
28 }