home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / pty4 / part02 / disconnect.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-18  |  1.6 KB  |  81 lines

  1. #include <stdio.h>
  2. #include "ptymisc.h"
  3. #include "ptycomm.h"
  4. #include "config/ptydir.h"
  5. #include "getopt.h"
  6. #include "env.h"
  7.  
  8. main(argc,argv)
  9. int argc;
  10. char *argv[];
  11. {
  12.  int opt;
  13.  int uid;
  14.  char *ext;
  15.  int fdcomm;
  16.  char resp6[6];
  17.  
  18.  uid = getuid();
  19.  ext = env_get("PTY");
  20.  while ((opt = getopt(argc,argv,"s:")) != opteof)
  21.    switch(opt)
  22.     {
  23.      case 's':
  24.        ext = optarg;
  25.        break;
  26.      case '?':
  27.      default:
  28.        exit(1);
  29.     }
  30.  argc -= optind;
  31.  argv += optind;
  32.  
  33.  if (!ext)
  34.   {
  35.    fprintf(stderr,"%s: fatal: no -s specified, and PTY not set; are we under a session?\n",optprogname);
  36.    exit(2);
  37.   }
  38.  
  39.  if (chdir(PTYDIR) == -1)
  40.   {
  41.    fprintf(stderr,"%s: fatal: cannot change to session directory %s\n",optprogname,PTYDIR);
  42.    exit(2);
  43.   }
  44.  
  45.  fdcomm = comm_write(ext,uid);
  46.  if (fdcomm == -1)
  47.   {
  48.    fprintf(stderr,"%s: fatal: cannot find session %s; if it exists, do you own it?\n",optprogname,ext);
  49.    exit(2);
  50.   }
  51.  if (bwrite(fdcomm,"d",1) < 1)
  52.   {
  53.    close(fdcomm);
  54.    fprintf(stderr,"%s: weird: session %s refuses to listen\n",optprogname,ext);
  55.    exit(2);
  56.   }
  57.  if (bread(fdcomm,resp6,6) < 6)
  58.   {
  59.    close(fdcomm);
  60.    fprintf(stderr,"%s: weird: session %s refuses to respond\n",optprogname,ext);
  61.    exit(2);
  62.   }
  63.  close(fdcomm);
  64.  
  65.  if (respeq(resp6,"kinky!"))
  66.   {
  67.    fprintf(stderr,"%s: fatal: pty %s does not support disconnects\n",optprogname,ext);
  68.    exit(2);
  69.   }
  70.  if (respeq(resp6,"no-op!"))
  71.   {
  72.    fprintf(stderr,"%s: warning: session %s already disconnected\n",optprogname,ext);
  73.    exit(2);
  74.   }
  75.  
  76.  if (!respeq(resp6,"yessir"))
  77.    ; /* unrecognized reply code */
  78.  
  79.  exit(0);
  80. }
  81.