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

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