Exemplo n.º 1
0
  int
_sync(void)
{
 APIRET  rc = DosShutdown(0UL);

	if (rc) {
		errno = _rc2Errno(rc);
		return(-1);
	}
	return (0);
}
Exemplo n.º 2
0
int main(void)
{
      HFILE  hf;
#ifdef __32BIT__
      ULONG  dummy;
      ULONG  rc;
#else
      USHORT dummy;
      USHORT rc;
#endif

      rc = DosOpen("DOS$",&hf,&dummy,0L,FILE_NORMAL,FILE_OPEN,
            OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYNONE |
            OPEN_FLAGS_FAIL_ON_ERROR,NULL);
      if(!rc)
      {
            /* Flush the caches           */

            DosShutdown(1);

            /* Shut down the file system  */

            DosShutdown(1);
            rc = DosShutdown(0);
            if(!rc)
            {
                  /* reboot machine */
                  
#ifdef __32BIT__
                  rc = DosDevIOCtl(hf,0xd5,0xab,NULL,0,NULL,NULL,0,NULL);
#else
                  rc = DosDevIOCtl(NULL,NULL,0xab,0xd5,hf);
#endif
                  DosClose(hf);
            }
      }
      return rc;
}
Exemplo n.º 3
0
void shutdown(HFILE com)
{
  HAB		hAnchorBlock;
  ULONG		ulRetCode;
  ULONG		ulSendResult;
  HMQ		hMsgQWindow;
  QMSG		rMsgQWin;
  QMSG		rMsgDESK;
  int 		x;

  if ((hAnchorBlock = WinInitialize(0)) == NULLHANDLE)
    return;
  if ((hMsgQWindow = WinCreateMsgQueue(hAnchorBlock, 0)) == NULLHANDLE)
    return;
  rMsgDESK.hwnd = HWND_DESKTOP;
  rMsgDESK.msg = 0;
  rMsgDESK.mp1 = MPVOID;
  rMsgDESK.mp2 = MPVOID;
  rMsgDESK.time = 0;
  rMsgDESK.reserved = 0;
  ulSendResult = WinBroadcastMsg(HWND_DESKTOP,
				 WM_SYSCOMMAND,
				 MPFROMSHORT(SC_CLOSE),
				 MPFROM2SHORT(CMDSRC_MENU,FALSE),
				 (ULONG) BMSG_FRAMEONLY);

  for (int i=0; i < 60; i++)	// One minute for a clean stop of all programs
  {
    x = CheckState(com);
    if (x != state) state = x;
    if (state == 0) { counter = COUNT_INIT; return; };
    if (state == 2) break;
    DosSleep(1000);
  }

  DosBeep(4000, 100);
  DosBeep(3000, 100);
  DosBeep(2000, 100);
  DosBeep(1000, 100);
  DosShutdown(0);
  UPSPowerOff(com);
  WinDestroyMsgQueue(hMsgQWindow);
  WinTerminate(hAnchorBlock);
  return;
}
Exemplo n.º 4
0
/* Main procedure */
void main(int argc, char * argv[])
{
  int newState = 0;
  HFILE com;
  ULONG action;
  DCBparam DCB;

  if (argc != 2)
  {
    fprintf(stderr, "Incorrect number of parameters!\n");
    help();
    exit(1);
  }

  if ((strcmpi(argv[1], "COM1")<0) ||
      (strcmpi(argv[1], "COM4")>0))
  {
    fprintf(stderr, "Serial port name required!\n");
    help();
    exit(2);
  }

  unsigned long datasize = sizeof(DCB);
  if (DosOpen(argv[1], &com, &action,
	       0L,	// logical size
	       0L,	// file attributes
	       0x01,	// action on existence
	       0x0012,	// openbits
	       0L)) exit(1);

  RaiseDTR(com);
  if (!CheckDSR(com))
    DosBeep(1000, 1000L);

  DosDevIOCtl(com, 0x01, 0x73, NULL, 0, NULL, &DCB, datasize, &datasize);
  DCB.writeTimeout = 1000;
  DCB.readTimeout = 100;
  DCB.flags1 = 0x00;
  DCB.flags3 = (DCB.flags3 & 0xF9) + 0x04;
  SetBitRate(com, 110);

  while (CheckDSR(com))
  {
    newState = CheckState(com);
    if (newState != state)
      Powerfail(newState, com);
    switch(state)
    {
      case 1:
	DosBeep(500, 10L);
	break;
      case 2:
	DosBeep(4000, 10L);
	break;
      default:
	break;
    }
    switch (doShutdown)
    {
      case 1: shutdown(com); break;
      case 2:
	{
	  DosShutdown(0);
	  UPSPowerOff(com);
	};
	break;
      default: break;
    }
    DosSleep(1000);
  }
  DosClose(com);
  exit(-1);
}