home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 239.lha / amiga / src / server / scli.c < prev    next >
C/C++ Source or Header  |  1989-05-02  |  3KB  |  142 lines

  1.  
  2. /*
  3.  *  SCLI.C
  4.  *
  5.  *  DNET (c)Copyright 1988, Matthew Dillon, All Rights Reserved.
  6.  *
  7.  *  SHELL SERVER.   THIS REQUIRES MY PIPE DEVICE TO WORK!!!!!!!!!!
  8.  *
  9.  *  Use DSOC on the UNIX end (DSOC 8193)
  10.  *
  11.  *  Only one connection accepted at a time in this baby.
  12.  *  HUGE CLUDGE!!!
  13.  *
  14.  *  DNET_LEVEL must be 9 or higher.
  15.  */
  16.  
  17. #include <stdio.h>
  18. #include <fcntl.h>
  19. #include "servers.h"
  20.  
  21. int Enable_Abort;
  22. char Buf[4096];
  23.  
  24. typedef struct Process PROC;
  25.  
  26. extern struct MsgPort *DListen();
  27. extern PROC *FindTask();
  28.  
  29. _main()
  30. {
  31.     struct MsgPort *port;
  32.     PROC    *proc = FindTask(NULL);
  33.     long    chan;
  34.     long    mask, rmask;
  35.     long    len, n;
  36.     char    nl, co;
  37.     int     fd;
  38.     long    namei = (long)proc;
  39.     APTR    oldwptr;
  40.     char    mycis = 0, mycos = 0;
  41.  
  42.     Enable_Abort = 0;
  43.     if (proc->pr_CLI) {
  44.     Version("SCli", VERSION, SCLI_VERSION);
  45.     _exit(0);
  46.     }
  47.  
  48.  
  49.     port = DListen(8196);
  50.     WaitPort(&proc->pr_MsgPort);
  51.     ReplyMsg(GetMsg(&proc->pr_MsgPort));
  52.     if (!port)
  53.     _exit(1);
  54.     mask = SIGBREAKF_CTRL_C|(1 << port->mp_SigBit);
  55.     oldwptr = proc->pr_WindowPtr;
  56.     proc->pr_WindowPtr = (APTR)-1;
  57.     /*proc->pr_ConsoleTask = DeviceProc("dpipe:");
  58.     if (!proc->pr_CIS) {
  59.     mycis = 1;
  60.     proc->pr_CIS = Open("nil:", 1006);
  61.     }
  62.     if (!proc->pr_COS) {
  63.     mycos = 1;
  64.     proc->pr_COS = Open("nil:", 1006);
  65.     }
  66.     */
  67.     for (;;) {
  68.     rmask = Wait(mask);
  69.     if (rmask & SIGBREAKF_CTRL_C)
  70.         break;
  71.     if (chan = DAccept(port)) {
  72.         long fh;
  73.         long mask;
  74.         long fhmask, smask;
  75.         short sig;
  76.         char pname[16];
  77.         char buf[64];
  78.  
  79.         if (GetEnvVal(DNET_LEVEL) < 9) {
  80.         DWrite(chan, "Permission Denied\n", 18);
  81.         DClose(chan);
  82.         continue;
  83.         }
  84.  
  85.  
  86.         sprintf(pname, "%08lx", namei++);
  87.         sprintf(buf, "newshell <nil: >nil: dpipe:%s/St FROM s:remote-startup", pname);
  88.         Execute(buf, NULL, NULL);
  89.         sig = AllocSignal(-1);
  90.         fhmask = 1 << sig;
  91.         smask = 1 << ((struct MsgPort *)chan)->mp_SigBit;
  92.         sprintf(buf, "dpipe:%s/Mctns%ld", pname, sig);
  93.         fh = Open(buf, 1006);
  94.         if (fh) {
  95.         char notdone = 1;
  96.         DWrite(chan, "Amiga CLI   running\n", 20);
  97.         while (notdone) {
  98.             char buf[256];
  99.             int n;
  100.             mask = Wait(fhmask | smask | SIGBREAKF_CTRL_C);
  101.             while ((n = Read(fh, buf, 256)) > 0) {
  102.             DWrite(chan, buf, n);
  103.             }
  104.             if (n < 0)
  105.             notdone = 0;
  106.             while ((n = DNRead(chan, buf, 256)) > 0) {
  107.             /*
  108.             DWrite(chan, buf, n);
  109.             */
  110.             Write(fh, buf, n);
  111.             }
  112.             if (n == -2) {
  113.             short pv;
  114.             short pa;
  115.             DGetIoctl(chan, &pv, &pa);
  116.             } else if (n < 0)
  117.             notdone = 0;
  118.         }
  119.         Write(fh, "ENDCLI\n", 7);
  120.         Write(fh, "ENDCLI\n", 7);
  121.         Close(fh);
  122.         }
  123.         DClose(chan);
  124.         FreeSignal(sig);
  125.         puts("DONE");
  126.     }
  127.     }
  128.     proc->pr_WindowPtr = oldwptr;
  129.     if (mycos) {
  130.     Close(proc->pr_COS);
  131.     proc->pr_COS = NULL;
  132.     }
  133.     if (mycis) {
  134.     Close(proc->pr_CIS);
  135.     proc->pr_CIS = NULL;
  136.     }
  137.     DUnListen(port);
  138. }
  139.  
  140.  
  141.  
  142.