annotate toys/setsid.c @ 562:4d802d438983

Match uint64_t with PRIu64 to avoid warnings on 64 bit builds.
author Rob Landley <rob@landley.net>
date Sat, 14 Apr 2012 21:27:00 -0500
parents 878b94b32866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
371
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
1 /* vi: set sw=4 ts=4:
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
2 *
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
3 * setsid.c - Run program in a new session ID.
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
4 *
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
5 * Copyright 2006 Rob Landley <rob@landley.net>
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
6 *
528
878b94b32866 Comment and whitespace tweaks.
Rob Landley <rob@landley.net>
parents: 371
diff changeset
7 * Not in SUSv4.
371
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
8
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
9 USE_SETSID(NEWTOY(setsid, "^<1t", TOYFLAG_USR|TOYFLAG_BIN))
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
10
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
11 config SETSID
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
12 bool "setsid"
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
13 default y
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
14 help
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
15 usage: setsid [-t] command [args...]
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
16
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
17 Run process in a new session.
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
18
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
19 -t Grab tty (become foreground process, receiving keyboard signals)
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
20 */
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
21
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
22 #include "toys.h"
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
23
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
24 void setsid_main(void)
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
25 {
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
26 while (setsid()<0)
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
27 if (vfork()) _exit(0);
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
28 if (toys.optflags) {
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
29 setpgid(0,0);
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
30 tcsetpgrp(0, getpid());
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
31 }
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
32 xexec(toys.optargs);
2cec41ee6eea Add setsid.
Rob Landley <rob@landley.net>
parents:
diff changeset
33 }