Imported from ../bash-1.14.7.tar.gz.
[platform/upstream/bash.git] / portbash / pgrp.c
1 /*
2  * If this system has a BSD-style getpgrp() call which takes a pid
3  * as an argument, output a -DBSD_GETPGRP.
4  */
5 #include <stdio.h>
6 #include <sys/types.h>
7
8 int     pid;
9 int     pg1, pg2, pg3, pg4;
10 int     ng, np, s, child;
11
12 main()
13 {
14         pid = getpid();
15         pg1 = getpgrp(0);
16         pg2 = getpgrp();
17         pg3 = getpgrp(pid);
18         pg4 = getpgrp(1);
19
20         /*
21          * If all of these values are the same, it's pretty sure that
22          * we're on a system that ignores getpgrp's first argument.
23          */
24         if (pg2 == pg4 && pg1 == pg3 && pg2 == pg3)
25                 exit(0);
26
27         child = fork();
28         if (child < 0)
29                 exit(1);
30         else if (child == 0) {
31                 np = getpid();
32                 /*
33                  * If this is Sys V, this will not work; pgrp will be
34                  * set to np because setpgrp just changes a pgrp to be
35                  * the same as the pid.
36                  */
37                 setpgrp(np, pg1);
38                 ng = getpgrp(0);        /* Same result for Sys V and BSD */
39                 if (ng == pg1) {
40                         printf("-DBSD_GETPGRP\n");
41                         exit(0);
42                 } else
43                         exit(1);
44         } else {
45                 wait(&s);
46                 exit(s>>8);
47         }
48 }