~ubuntu-branches/ubuntu/oneiric/python-scipy/oneiric-proposed

« back to all changes in this revision

Viewing changes to scipy/sandbox/xplt/src/play/unix/uinbg.c

  • Committer: Bazaar Package Importer
  • Author(s): Ondrej Certik
  • Date: 2008-06-16 22:58:01 UTC
  • mfrom: (2.1.24 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080616225801-irdhrpcwiocfbcmt
Tags: 0.6.0-12
* The description updated to match the current SciPy (Closes: #489149).
* Standards-Version bumped to 3.8.0 (no action needed)
* Build-Depends: netcdf-dev changed to libnetcdf-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * uinbg.c -- $Id: uinbg.c 685 2003-03-08 15:26:51Z travo $
 
3
 * foreground/background detection function (UNIX arcana)
 
4
 *
 
5
 * Copyright (c) 1998.  See accompanying LEGAL file for details.
 
6
 */
 
7
 
 
8
#include "config.h"
 
9
#include "playu.h"
 
10
 
 
11
#ifndef _POSIX_SOURCE
 
12
#define _POSIX_SOURCE 1
 
13
#endif
 
14
 
 
15
#include <sys/types.h>
 
16
extern pid_t tcgetpgrp(int fd);
 
17
/* POSIX and SYSV getpgrp prototype is:    pid_t getpgrp(void)
 
18
 * BSD4.3 is more like 2nd branch, where the parameter is the pid of the
 
19
 *   process whose process group is returned (pid=0 means this process)
 
20
 * - passing the parameter to the POSIX/SYSV function is harmless,
 
21
 *   while omitting the paramter to the BSD function is disastrous
 
22
 * - the only reason for the first branch is if sys/types.h has the
 
23
 *   POSIX prototype for getpgrp */
 
24
#ifdef USE_POSIX_GETPGRP
 
25
#undef USE_POSIX_GETPGRP
 
26
#define USE_POSIX_GETPGRP
 
27
extern pid_t getpgrp(void);
 
28
#else
 
29
#define USE_POSIX_GETPGRP 0
 
30
extern pid_t getpgrp(pid_t);
 
31
#endif
 
32
 
 
33
int
 
34
u_in_background(void)
 
35
{
 
36
  /* if the process group of the controlling terminal for stdin (fd 0)
 
37
   *   does not match our process group, we are in the background, and
 
38
   *   any attempt to read stdin will generate a SIGTTIN signal
 
39
   * read the intro(2) and termio(4) man pages for more
 
40
   * (possibly easier to just handle SIGTTIN if it happens...) */
 
41
  pid_t tgid = tcgetpgrp(0);      /* controlling terminal process group */
 
42
  if (tgid>0) {
 
43
    pid_t pgid = getpgrp(USE_POSIX_GETPGRP);   /* get our process group */
 
44
    return (pgid!=tgid);
 
45
  }
 
46
  return 0;
 
47
}
 
48
 
 
49
#ifdef USE_TIOCGPGRP_IOCTL
 
50
#include USE_TIOCGPGRP_IOCTL
 
51
pid_t
 
52
tcgetpgrp(int fd)
 
53
{
 
54
  int tgid;
 
55
  if (ioctl(fd, TIOCGPGRP, &tgid)<0) return -1;
 
56
  else return tgid;
 
57
}
 
58
#endif