File: test-helper.c

package info (click to toggle)
ngetty 1.0-1
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 304 kB
  • ctags: 207
  • sloc: ansic: 1,503; makefile: 236; sh: 109; asm: 100
file content (37 lines) | stat: -rw-r--r-- 651 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <unistd.h>
#include <fcntl.h>
#include <time.h>
#include <sys/ioctl.h>
/* 
   A) $0 ./ngetty-helper /dev/ttyX [login] 
   B) $0 "-H" /dev/ttyX
   C) $0 "-O" /dev/ttyX
*/

int main(int argc , char **argv, char **env) {
  int k;
  char *x;
  if (argc<3) _exit(100);
  ioctl(0, TIOCNOTTY, 0);
  for (k=0; k<6; k++) close(k);
  if (0 != open(argv[2], O_RDWR | O_NOCTTY)) _exit(111);

  x = argv[1];
  if (x[0] != '-') {
    argv++;
    execve(*argv, argv, env);
    _exit(127);
  }

  ++x;
  switch (*x) {
  case 'O':
    if (fork()) _exit(0);
  case 'H':
    setsid();
    ioctl(0, TIOCSCTTY, 0);
    sleep(15);
    vhangup();
  }
  _exit(0);
}