home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sys / hp / 15436 < prev    next >
Encoding:
Text File  |  1993-01-28  |  3.2 KB  |  144 lines

  1. Path: sparky!uunet!europa.eng.gtefsd.com!emory!gatech!darwin.sura.net!ra!mimsy!sdd.comsat.com!ctd.comsat.com!news!neal
  2. From: neal@ctd.comsat.com (Neal Becker)
  3. Newsgroups: comp.sys.hp
  4. Subject: Painless remote X execution
  5. Message-ID: <NEAL.93Jan28133827@neal.ctd.comsat.com>
  6. Date: 28 Jan 93 18:38:27 GMT
  7. Organization: COMSAT Labs
  8. Lines: 132
  9. NNTP-Posting-Host: neal.ctd.comsat.com
  10. X-Md4-Signature: bcbfa3b8472346b3f0fcbf0598036fa3
  11.  
  12. This includes 3 files.  rxterm opens a remote xterm, while rx host cmd
  13. executes any arbitrary command.
  14.  
  15. Since there is no way to get rid of the parent remsh on hpux, I have
  16. written a devilish bit of code to go along with this - daemon.c will
  17. run any program as a daemon.
  18.  
  19. Enjoy!
  20.  
  21. -------------------------------------------------------------
  22. # This is a shell archive.  Remove anything before this line,
  23. # then unpack it by saving it in a file and typing "sh file".
  24. #
  25. # Wrapped by Neal Becker <neal@neal> on Thu Jan 28 13:34:15 1993
  26. #
  27. # This archive contains:
  28. #    rx    
  29. #
  30.  
  31. LANG=""; export LANG
  32. PATH=/bin:/usr/bin:$PATH; export PATH
  33.  
  34. a - rx
  35. echo mkdir - rx
  36. mkdir rx
  37.  
  38. a - rx/rx
  39. echo x - rx/rx
  40. cat >rx/rx <<'@EOF'
  41. #!/bin/sh
  42. host=$1
  43. shift;
  44. /usr/bin/X11/xhost +$host > /dev/null
  45.  
  46. case $SHELL in
  47.     *csh)
  48.  
  49. case $DISPLAY in
  50.     shmlink:* | :*) remsh $host -n "setenv DISPLAY `hostname`:0;setenv XENVIRONMENT $XENVIRONMENT;/usr/local/bin/daemon $*" ;;
  51.     *) remsh $host -n "setenv DISPLAY $DISPLAY;setenv XENVIRONMENT $XENVIRONMENT;/usr/local/bin/daemon $*" ;;
  52. esac
  53.  
  54.     ;;
  55.  
  56.     *)
  57. case $DISPLAY in
  58.     shmlink:* | :*) remsh $host -n "DISPLAY=`hostname`:0 XENVIRONMENT=$XENVIRONMENT /usr/local/bin/daemon $*" ;;
  59.     *) remsh $host -n "DISPLAY=$DISPLAY XENVIRONMENT=$XENVIRONMENT /usr/local/bin/daemon $*" ;;
  60. esac
  61.  
  62.     ;;
  63. esac
  64. @EOF
  65.  
  66. chmod 755 rx/rx
  67.  
  68. a - rx/rxterm
  69. echo x - rx/rxterm
  70. cat >rx/rxterm <<'@EOF'
  71. #!/bin/sh
  72. host=$1
  73. shift;
  74. /usr/bin/X11/xhost +$host > /dev/null
  75. case $SHELL in
  76.     *csh)
  77.  
  78. case $DISPLAY in
  79.     shmlink:* | :*) remsh $host -n "setenv DISPLAY `hostname`:0;setenv XENVIRONMENT $XENVIRONMENT;/usr/local/bin/daemon xterm -n xterm@$host $*" ;;
  80.     *) remsh $host -n "setenv DISPLAY $DISPLAY;setenv XENVIRONMENT $XENVIRONMENT;/usr/local/bin/daemon xterm -n xterm@$host $*" ;;
  81. esac
  82.  
  83.     ;;
  84.     *)
  85. case $DISPLAY in
  86.     shmlink:* | :*) remsh $host -n "DISPLAY=`hostname`:0 XENVIRONMENT=$XENVIRONMENT /usr/local/bin/daemon xterm -n xterm@$host $*" ;;
  87.     *) remsh $host -n "DISPLAY=$DISPLAY XENVIRONMENT=$XENVIRONMENT /usr/local/bin/daemon xterm -n xterm@$host $*" ;;
  88. esac
  89.  
  90. ;;
  91.  
  92. esac
  93. @EOF
  94.  
  95. chmod 755 rx/rxterm
  96.  
  97. a - rx/daemon.c
  98. echo x - rx/daemon.c
  99. cat >rx/daemon.c <<'@EOF'
  100. #include <unistd.h>    /* For _SC_OPEN_MAX */
  101. #include <stdio.h>
  102. #include <sys/file.h>
  103. #include <stdlib.h>
  104.  
  105. static void Usage( const char* prog ) {
  106.   fprintf( stderr, "usage: %s <prog>\n", prog );
  107.   exit( 1 );
  108. }
  109.  
  110. main( int argc, char* argv[] ) {
  111.   long    tblsiz = sysconf(_SC_OPEN_MAX);
  112.   int c;
  113.   char * NewArgv[ 256 ];
  114.  
  115.   if( argc < 2 ) Usage( argv[ 0 ] );
  116.  
  117.   switch( fork() ) {
  118.   case -1:
  119.     perror( argv[ 0 ] );
  120.     exit( 1 );
  121.  
  122.   case 0:
  123.     setsid();
  124.     for (c = 0; c < tblsiz; c++)
  125.       (void) close(c);
  126.     (void) open("/", O_RDONLY);
  127.     (void) dup2(0, 1);
  128.     (void) dup2(0, 2);
  129.     execvp( argv[ 1 ], &argv[ 1 ] );
  130.     _exit( -1 );
  131.  
  132.   default:
  133.     exit( 0 );
  134.  
  135.   }
  136. }
  137. @EOF
  138.  
  139. chmod 644 rx/daemon.c
  140.  
  141. chmod 755 rx
  142.  
  143. exit 0
  144.