Ignore:
Timestamp:
Jul 2, 2008 4:35:26 PM (6 years ago)
Author:
sam
Message:
  • Fork the grabbed process and exit the parent. Unfortunately for some reason it still survives as a zombie, there must be something wrong with the setsid/setpgid mechanism we use (maybe setpgrp is needed?).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • neercs/trunk/src/grab.c

    r2512 r2516  
    3939#if defined HAVE_LINUX_KDEV_T_H 
    4040    char fdstr[1024]; 
    41     struct mytrace *t; 
     41    struct mytrace *parent, *child; 
    4242    int i, fd = 0, mode, ret; 
    4343    char to_open[3]; 
     
    4646    debug("pty is %s", ptyname); 
    4747 
    48     t = mytrace_attach(pid); 
    49     if(!t) 
     48    parent = mytrace_attach(pid); 
     49    if(!parent) 
    5050    { 
    5151        fprintf(stderr, "Cannot access process %ld\n", pid); 
    5252        return -1; 
    5353    } 
     54 
     55    child = mytrace_fork(parent); 
     56    pid = mytrace_getpid(child); 
    5457 
    5558    /* Look for file descriptors that are PTYs */ 
     
    7578        debug("found pty %d", i); 
    7679 
    77         ret = mytrace_close(t, i); 
     80        if(i == 2) 
     81        { 
     82            mytrace_write(parent, i, "\x1b]0;\x07", 5); 
     83            mytrace_write(parent, i, "\x1b[1000l", 7); 
     84            mytrace_write(parent, i, "\x1b[?12l\x1b[?25h", 12); 
     85            mytrace_write(parent, i, "\n[Process stolen by neercs]\n", 28); 
     86        } 
     87 
     88        ret = mytrace_close(child, i); 
    7889        if(ret < 0) 
    7990        { 
     
    8697    debug("Running setsid on process %ld (sid=%d)", pid, getsid(pid)); 
    8798 
    88     ret = mytrace_setpgid(t, 0, getsid(pid)); 
     99    ret = mytrace_setpgid(child, 0, getsid(pid)); 
    89100    if(ret < 0) 
    90101    { 
    91102        fprintf(stderr, "syscall setpgid failed\n"); 
    92         mytrace_detach(t); 
     103        mytrace_detach(child); 
    93104        return -1; 
    94105    } 
     
    97108    { 
    98109        fprintf(stderr, "setpgid returned %d\n", ret); 
    99         mytrace_detach(t); 
     110        mytrace_detach(child); 
    100111        return -1; 
    101112    } 
    102113 
    103     ret = mytrace_setsid(t); 
     114    ret = mytrace_setsid(child); 
    104115    if(ret < 0) 
    105116    { 
    106117        fprintf(stderr, "syscall setsid failed\n"); 
    107         mytrace_detach(t); 
     118        mytrace_detach(child); 
    108119        return -1; 
    109120    } 
    110121 
    111122    debug("pid %ld has now sid %d", pid, getsid(pid)); 
     123 
     124    mytrace_exit(parent, 0); 
     125    mytrace_detach(parent); 
    112126 
    113127    /* Reopen PTY file descriptors */ 
     
    116130        if(!to_open[i]) 
    117131            continue; 
    118         fd = mytrace_open(t, ptyname, mode); 
     132        fd = mytrace_open(child, ptyname, mode); 
    119133        if(fd < 0) 
    120134        { 
    121135            perror("mytrace_open"); 
    122136        } 
    123         ret = mytrace_dup2(t, fd, i); 
     137        ret = mytrace_dup2(child, fd, i); 
    124138        if(ret < 0) 
    125139        { 
     
    129143 
    130144    kill(pid, SIGWINCH); 
    131  
    132     mytrace_detach(t); 
     145    mytrace_detach(child); 
    133146 
    134147    return 0; 
Note: See TracChangeset for help on using the changeset viewer.