Changeset 182:af486629f3d2 in roaraudio


Ignore:
Timestamp:
07/20/08 16:49:35 (16 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added lib_run_bg()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • roard/lib.c

    r181 r182  
    33#include "roard.h" 
    44 
     5int lib_run_bg(char * cmd, int infh, int outfh, int errfh) { 
     6 pid_t child = fork(); 
     7 int fh[3] = {-1, -1, -1}; 
     8 int i; 
     9 
     10 if ( child == -1 ) { 
     11  ROAR_ERR("lib_run_bg(*): Can not fork: %s", strerror(errno)); 
     12  return -1; 
     13 } 
     14 
     15 if ( child ) { 
     16  // we are the parent! 
     17  return child; 
     18 } 
     19 
     20 // we are the child. 
     21 // first we need to close a lot of open files! 
     22 
     23 // before we do this we need to keep backups of our handles: 
     24 fh[0] = dup(infh); 
     25 fh[1] = dup(outfh); 
     26 fh[2] = dup(errfh); 
     27 
     28 // TODO: test for errors here. 
     29 
     30 close(g_listen_socket); // listen socket. 
     31 
     32 clients_free(); // delete all clients!, this allso delets all streams 
     33 
     34 // TODO: what aout the output driver? 
     35 
     36 // next we need to remap our stdio: 
     37 // stdio: fh 0..2 
     38 
     39 for (i = 0; i < 3; i++) { 
     40  close(i); 
     41  dup2(fh[i], i); // todo test if this is ok. 
     42 } 
     43 
     44 // OK, now we should have set up all our fh properbly, exec our command: 
     45 
     46 execl("/bin/sh", "sh", "-c", cmd, NULL); 
     47 
     48 // still alive? BAD! 
     49 ROAR_ERR("lib_run_bg(*): We are still alive! BAD!"); 
     50 _exit(3); 
     51 return -1; 
     52} 
     53 
    554//ll 
Note: See TracChangeset for help on using the changeset viewer.