Example #1
0
static uint set_max_open_files(uint max_file_limit)
{
  LONG     cbReqCount;
  ULONG    cbCurMaxFH0;
  APIRET   ulrc;
  DBUG_ENTER("set_max_open_files");

  /* get current limit */
  cbReqCount = 0;
  DosSetRelMaxFH( &cbReqCount, &cbCurMaxFH0);

  /* set new limit */
  if ((cbReqCount = max_file_limit - cbCurMaxFH0) > 0)
    ulrc = DosSetRelMaxFH( &cbReqCount, &cbCurMaxFH);
  DBUG_RETURN(cbCurMaxFH0);
}
Example #2
0
int WantUsage( const char *ptr )
{
    LONG    lReq = 20;
    ULONG   ulCurMax;

    /* This is a stupid place to do this, but it's the only system
       specific hook that I've got. */
    DosSetRelMaxFH( &lReq, &ulCurMax );

    if( (*ptr == '-') || (*ptr == '/') )
        ++ptr;
    return( *ptr == '?' );
}
Example #3
0
void rel_grow_handles(int nh)
{ LONG addfh=0;
  static ULONG curmaxfh=0;

  LockSem(&fhsem);
  if (curmaxfh == 0)
  { if (DosSetRelMaxFH(&addfh, &curmaxfh))
    { Log(1, "Cannot DosSetRelMaxFH");
      return;
    }
  }
#ifdef __WATCOMC__
  if ((addfh=_grow_handles((int)(curmaxfh += nh))) < curmaxfh)
#else
  addfh=nh;
  if (DosSetRelMaxFH(&addfh, &curmaxfh))
#endif
    Log(1, "Cannot grow handles to %ld (now %ld): %s", curmaxfh, addfh, strerror(errno));
  else
    Log(6, "Set MaxFH to %ld (res %ld)", curmaxfh, addfh);
  ReleaseSem(&fhsem);
}
Example #4
0
void connectthread( void * parameters ) {

    struct connectthreadparameters * ctp;
    unsigned long curmax;
    HPIPE hpipe;
    struct messagequeue * msgq;
    unsigned char maxpipes;
    char pipename[CCHMAXPATH];
    APIRET rc;
    long req;
    HEV shutdown;
    HEV terminated;

    /*  Grab data from parameter block, and signal when done.  */

    ctp = ( struct connectthreadparameters * ) parameters;

    maxpipes = ctp->maxpipes;
    strcpy(pipename,ctp->pipename);
    shutdown = ctp->shutdown;
    msgq = ctp->msgq;
    terminated = ctp->terminated;

    DosPostEventSem(ctp->initialized);

    /*  Clear the pipe handle ( this is checked for a non-NULLHANDLE     **
    **  value on thread exit ).                                          */

    hpipe = NULLHANDLE;

    create:    /*  Create a new instance of the pipe.  */

    rc =
            DosCreateNPipe( pipename, &hpipe,
                NP_NOINHERIT|NP_ACCESS_DUPLEX,
                NP_NOWAIT|NP_TYPE_BYTE|NP_READMODE_BYTE|maxpipes,
                inbuffersize, outbuffersize, 0 );

    if (
            rc != NO_ERROR && rc != ERROR_PIPE_BUSY &&
                rc != ERROR_TOO_MANY_OPEN_FILES ) {
        /*  Some unexpected error has occurred.  Notify the              **
        **  application.                                                 */
        DosRequestMutexSem(msgq->access,SEM_INDEFINITE_WAIT);
        *msgq->qtail = malloc( sizeof( struct message ) );
        (*msgq->qtail)->id = cterror;
        (*msgq->qtail)->data.cterrordata.ec = apiret2ec(rc);
        (*msgq->qtail)->next = NULL;
        DosPostEventSem(msgq->available);
        DosReleaseMutexSem(msgq->access);
        goto completed;
        }

    if ( rc == ERROR_PIPE_BUSY )
        /*  Max pipes created.  */
        goto busy;

    if ( rc == ERROR_TOO_MANY_OPEN_FILES ) {
        req = 1;
        rc = DosSetRelMaxFH(&req,&curmax);
        if ( rc  == NO_ERROR )
            goto create;
        /*  Can trigger a 'max connections reached' message here ...  */
        goto busy;
        }

    connect:    /*  Connect pipe ( allows client to connect ).  */

    rc = DosConnectNPipe(hpipe);

    if (
            rc != NO_ERROR && rc != ERROR_PIPE_NOT_CONNECTED &&
                rc != ERROR_BROKEN_PIPE ) {
        /*  Unexpected error ...  */
        DosRequestMutexSem(msgq->access,SEM_INDEFINITE_WAIT);
        *msgq->qtail = malloc( sizeof( struct message ) );
        (*msgq->qtail)->id = cterror;
        (*msgq->qtail)->data.cterrordata.ec = apiret2ec(rc);
        (*msgq->qtail)->next = NULL;
        DosPostEventSem(msgq->available);
        DosReleaseMutexSem(msgq->access);
        DosClose(hpipe);
        hpipe = NULLHANDLE;
        goto completed;
        }

    if ( rc == ERROR_PIPE_NOT_CONNECTED )
        /*  No client connected, so wait a while ...  */
        goto waiting;

    if ( rc == ERROR_BROKEN_PIPE ) {
        /*  Client connected, but probably immediately closed.  */
        DosClose(hpipe);
        hpipe = NULLHANDLE;
        goto create;
        }

    /*  Send handle of the newly connected pipe to the application.  */

    DosRequestMutexSem(msgq->access,SEM_INDEFINITE_WAIT);
    *msgq->qtail = malloc( sizeof( struct message ) );
    (*msgq->qtail)->id = connected;
    (*msgq->qtail)->data.connecteddata.hpipe = hpipe;
    (*msgq->qtail)->next = NULL;
    DosPostEventSem(msgq->available);
    DosReleaseMutexSem(msgq->access);

    /*  Create a new instance of the pipe for the next client.  */

    goto create;

    waiting:    /*  Wait to see if the application is ready to exit.  */

    rc = DosWaitEventSem(shutdown,connectpolltimeout);
    if ( rc != ERROR_TIMEOUT )
        goto completed;

    /*  Not shutting down, so wait for a client to connect.  */

    goto connect;

    busy:    /*  Pipe is busy.  */

    rc = DosWaitEventSem(shutdown,connectpolltimeout);
    if ( rc != ERROR_TIMEOUT )
        goto completed;

    /*  Not shutting down, but in this case, unlike waiting above, go    **
    **  and create a new pipe.                                           */

    goto create;

    completed:    /*  Processing completed.  */

    /*  Close pipe if no client had connected.  */

    if ( hpipe != NULLHANDLE )
        DosClose(hpipe);

    /*  Notify application that the thread will not accept more          **
    **  connections.                                                     */

    DosRequestMutexSem(msgq->access,SEM_INDEFINITE_WAIT);
    *msgq->qtail = malloc( sizeof( struct message ) );
    (*msgq->qtail)->id = ctclosed;
    (*msgq->qtail)->next = NULL;
    DosPostEventSem(msgq->available);
    DosReleaseMutexSem(msgq->access);

    /*  Shutdown processing completed.  Signal owner.  */

    DosEnterCritSec();
    DosPostEventSem(terminated);

    }
Example #5
0
int main(int argc, char *argv[]) {

  int do_load,do_unload,do_help,do_path;
  do_load=do_unload=do_help=do_path=0;

  char basepath[CCHMAXPATH];

  if (argc == 1)
    do_help = 1;
  else {
    for (int i=1; i < argc; i++) {
      if (strnicmp(argv[i],"-l", 2) == 0)
        do_load = 1;
      else if (strnicmp(argv[i],"-u", 2) == 0)
        do_unload = 1;
      else if (strnicmp(argv[i],"-h", 2) == 0) 
        do_help = 1;
      else if (strnicmp(argv[i],"-?", 2) == 0)
        do_help = 1;
      else if (strnicmp(argv[i],"-p", 2) == 0) {
        if (argc > i+1) {
          strcpy(basepath, argv[i+1]);
          if (basepath[strlen(basepath)] !='\\') {
            strcat(basepath, "\\");
          }
        do_path = 1;
        } else {
          do_help = 1;
        }
      }
    }
  }


  if (do_help) {
    printf("%s for OS/2 preloader\n"\
           "\n"\
           "Usage: %s [-h] [-l | -u] [-p path]\n"\
           "       -h display this help\n"\
           "       -l load modules\n"\
           "       -u unload modules\n"\
           "       -p specify fully qualified path to directory where EXE is located\n",
           MOZ_APP_DISPLAYNAME, argv[0]);
    return(1);
  }

  if (do_unload) {
    HEV hev = NULLHANDLE;
    if (DosOpenEventSem(SEMNAME, &hev) == NO_ERROR) {
      if (DosPostEventSem(hev) == NO_ERROR) {
        if (DosCloseEventSem(hev) == NO_ERROR) {
          return(0);
        }
      }
    }
    printf("%s for OS/2 preloader is not running\n", MOZ_APP_DISPLAYNAME);
    return(1);
  }

  if (do_path == 0) {
    /* Get the name of this EXE and use its location as the path */
    HMODULE hmodule;
    DosQueryModFromEIP(&hmodule, NULL, 0, NULL, NULL, (ULONG)ForceModuleLoad);
    DosQueryModuleName(hmodule, CCHMAXPATH, basepath);
    char *pchar = strrchr(basepath, '\\');
    pchar++;
    *pchar = '\0';
  }

  if (do_load) {
    ULONG ulCurMaxFH;
    LONG ulReqFH = 40;
    DosSetRelMaxFH(&ulReqFH, &ulCurMaxFH);

    HEV hev;
    if (DosCreateEventSem(SEMNAME, &hev, DC_SEM_SHARED, FALSE) != NO_ERROR) {
      printf("%s for OS/2 preloader is already running\n", MOZ_APP_DISPLAYNAME);
      return(1);
    }

    /* Add directory where EXE is located to LIBPATH */
    DosSetExtLIBPATH(basepath, BEGIN_LIBPATH);

    /* loop through list loading named modules */
    char filepath[CCHMAXPATH];
    HMODULE hmod;

    int i = 0, nummodules = 0;
    while (bindir[i]) {
      strcpy(filepath,basepath);
      strcat(filepath,bindir[i]);
   
      if (DosLoadModule(NULL, 0, filepath, &hmod) == NO_ERROR) {
        ForceModuleLoad(hmod);
        nummodules++;
      }
      i++;
    }

    i = 0;
    while (compdir[i]) {
      strcpy(filepath, basepath);
      strcat(filepath, "COMPONENTS\\");
      strcat(filepath, compdir[i]);

      if (DosLoadModule(NULL, 0, filepath, &hmod) == NO_ERROR) {
        ForceModuleLoad(hmod);
        nummodules++;
      }
      i++;
    }
   
    if (nummodules > 0) {
      if (DosWaitEventSem(hev, SEM_INDEFINITE_WAIT) != NO_ERROR) {
        printf("DosWaitEventSem failed\n");
        return(1);
      }

      if (DosCloseEventSem(hev) != NO_ERROR) {
        printf("DosCloseEventSem failed\n");
        return(1);
      }
    } else {
      printf("No modules available to load\n");
    }
  }

 return(0);
}
Example #6
0
void xf86OpenConsole()
{
    /* try to catch problems before they become obvious */
    os2_checkinstallation();

    if (serverGeneration == 1) {
	HKBD fd;
	ULONG drive;
	ULONG dummy;
	KBDHWID hwid;
	APIRET rc;
	int VioTid;
        ULONG actual_handles;
        LONG new_handles;

	/* hv 250197 workaround for xkb-Problem: switch to X11ROOT drive */
	char *x11r = getenv("X11ROOT");
        /* Make sure X11ROOT is set before we go further sm280297 */
        if (x11r == NULL){ 
           ErrorF("The environment variable X11ROOT is not set! The xserver is aborting.\n");	
           exit(1);  
           }
        if (_chdir2(x11r) < 0) {
		ErrorF("xf86-OS/2: Cannot change to X11ROOT directory!\n");
	}

	ErrorF("xf86-OS/2: Console opened\n");
	OriginalVideoMode.cb=sizeof(VIOMODEINFO);
	rc=VioGetMode(&OriginalVideoMode,(HVIO)0);
	if(rc!=0) ErrorF("xf86-OS/2: Could not get original video mode. RC=%d\n",rc);
	xf86Info.consoleFd = -1;
        
        /* Set the number of handles to higher than the default 20. Set to 80 which should be plenty */
        new_handles = 0;
        rc = DosSetRelMaxFH(&new_handles,&actual_handles);
        if (actual_handles < 80) {
		new_handles = 80 - actual_handles;
		rc = DosSetRelMaxFH(&new_handles,&actual_handles);
		ErrorF("xf86-OS/2: Increased number of available handles to %d\n",actual_handles);
	}

	/* grab the keyboard */
	rc = KbdGetFocus(0,0);
	if (rc != 0)
		FatalError("xf86OpenConsole: cannot grab kbd focus, rc=%d\n",rc);

	/* open the keyboard */
	rc = KbdOpen(&fd);
	if (rc != 0)
		FatalError("xf86OpenConsole: cannot open keyboard, rc=%d\n",rc);
	xf86Info.consoleFd = fd;

	ErrorF("xf86-OS/2: Keyboard opened\n");

	/* assign logical keyboard */
	KbdFreeFocus(0);
	rc = KbdGetFocus(0,fd);
	if (rc != 0)
		FatalError("xf86OpenConsole: cannot set local kbd focus, rc=%d\n",rc);

/* Create kbd queue semaphore */
 
         rc = DosCreateEventSem(NULL,&hKbdSem,DC_SEM_SHARED,TRUE);
         if (rc != 0)
                  FatalError("xf86OpenConsole: cannot create keyboard queue semaphore, rc=%d\n",rc);
 
/* Create popup semaphore */

	rc=DosCreateEventSem("\\SEM32\\XF86PUP",&hevPopupPending,DC_SEM_SHARED,1);
	if(rc) ErrorF("xf86-OS/2: Could not create popup semaphore! RC=%d\n",rc);
	/* rc=VioRegister("xf86vio","XF86POPUP_SUBCLASS",0x20002004L,0L);
	if(rc) {
		FatalError("xf86-OS2: Could not register XF86VIO.DLL module. Please install in LIBPATH! RC=%d\n",rc);
	}  */

/* Start up the VIO monitor thread */
	VioTid=_beginthread(os2VideoNotify,NULL,0x4000,(void *)NULL);
	ErrorF("xf86-OS/2: Started Vio thread, Tid=%d\n",VioTid);
	rc=DosSetPriority(2,3,0,VioTid);

/* Start up the hard-error VIO monitor thread */
	VioTid=_beginthread(os2HardErrorNotify,NULL,0x4000,(void *)NULL);
	ErrorF("xf86-OS/2: Started hard error Vio mode monitor thread, Tid=%d\n",VioTid);
	rc=DosSetPriority(2,3,0,VioTid);

/* Start up the kbd monitor thread */
	VioTid=_beginthread(os2KbdMonitorThread,NULL,0x4000,(void *)NULL);
	ErrorF("xf86-OS/2: Started Kbd monitor thread, Tid=%d\n",VioTid);
	rc=DosSetPriority(2,3,0,VioTid);

/* Disable hard-errors through DosError */
	rc = DosQuerySysInfo(5,5,&drive,sizeof(drive));
	rc = DosSuppressPopUps(0x0001L,drive+96);     /* Disable popups */
	
	rc = KbdSetCp(0,0,fd);
	if(rc != 0)
		FatalError("xf86-OS/2: xf86OpenConsole: cannot set keyboard codepage, rc=%d\n",rc);

	hwid.cb = sizeof(hwid);	/* fix crash on P9000 */
	rc = KbdGetHWID(&hwid, fd);
	if (rc == 0) {
		switch (hwid.idKbd) {
		default:
		case 0xab54: /* 88/89 key */
		case 0:	/*unknown*/
		case 1: /*real AT 84 key*/
			xf86Info.kbdType = KB_84; break;
		case 0xab85: /* 122 key */
			FatalError("xf86-OS/2: OS/2 has detected an extended 122key keyboard: unsupported!\n");
		case 0xab41: /* 101/102 key */
			xf86Info.kbdType = KB_101; break;
		}				
	} else
		xf86Info.kbdType = KB_84; /*defensive*/

/* Start up the Kbd bit-bucket thread. We don't want to leave the kbd events in the driver queue */
	VioTid=_beginthread(os2KbdBitBucketThread,NULL,0x2000,(void *)NULL);
	ErrorF("xf86-OS/2: Started Kbd bit-bucket thread, Tid=%d\n",VioTid);

	xf86Config(FALSE); /* Read XF86Config */
    }
    return;
}
Example #7
0
/*
 *  _PR_MD_OPEN() -- Open a file
 *
 *  returns: a fileHandle
 *
 *  The NSPR open flags (osflags) are translated into flags for OS/2
 *
 *  Mode seems to be passed in as a unix style file permissions argument
 *  as in 0666, in the case of opening the logFile. 
 *
 */
PRInt32
_PR_MD_OPEN(const char *name, PRIntn osflags, int mode)
{
    HFILE file;
    PRInt32 access = OPEN_SHARE_DENYNONE;
    PRInt32 flags = 0L;
    APIRET rc = 0;
    PRUword actionTaken;

#ifdef MOZ_OS2_HIGH_MEMORY
    /*
     * All the pointer arguments (&file, &actionTaken and name) have to be in
     * low memory for DosOpen to use them.
     * The following moves name to low memory.
     */ 
    if ((ULONG)name >= 0x20000000)
    {
        size_t len = strlen(name) + 1;
        char *copy = (char *)alloca(len);
        memcpy(copy, name, len);
        name = copy;
    }
#endif

    if (osflags & PR_SYNC) access |= OPEN_FLAGS_WRITE_THROUGH;

    if (osflags & PR_RDONLY)
        access |= OPEN_ACCESS_READONLY;
    else if (osflags & PR_WRONLY)
        access |= OPEN_ACCESS_WRITEONLY;
    else if(osflags & PR_RDWR)
        access |= OPEN_ACCESS_READWRITE;

    if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL )
    {
        flags = OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_FAIL_IF_EXISTS;
    }
    else if (osflags & PR_CREATE_FILE)
    {
        if (osflags & PR_TRUNCATE)
            flags = OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_REPLACE_IF_EXISTS;
        else
            flags = OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS;
    } 
    else
    {
        if (osflags & PR_TRUNCATE)
            flags = OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_REPLACE_IF_EXISTS;
        else
            flags = OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS;
    }

    do {
        if (isWSEB)
        {
                rc = myDosOpenL((char*)name,
                     &file,            /* file handle if successful */
                     &actionTaken,     /* reason for failure        */
                     0,                /* initial size of new file  */
                     FILE_NORMAL,      /* file system attributes    */
                     flags,            /* Open flags                */
                     access,           /* Open mode and rights      */
                     0);               /* OS/2 Extended Attributes  */
        }
        else
        {
                rc = DosOpen((char*)name,
                     &file,            /* file handle if successful */
                     &actionTaken,     /* reason for failure        */
                     0,                /* initial size of new file  */
                     FILE_NORMAL,      /* file system attributes    */
                     flags,            /* Open flags                */
                     access,           /* Open mode and rights      */
                     0);               /* OS/2 Extended Attributes  */
        };
        if (rc == ERROR_TOO_MANY_OPEN_FILES) {
            ULONG CurMaxFH = 0;
            LONG ReqCount = 20;
            APIRET rc2;
            rc2 = DosSetRelMaxFH(&ReqCount, &CurMaxFH);
            if (rc2 != NO_ERROR) {
                break;
            }
        }
    } while (rc == ERROR_TOO_MANY_OPEN_FILES);

    if (rc != NO_ERROR) {
        _PR_MD_MAP_OPEN_ERROR(rc);
        return -1; 
    }

    return (PRInt32)file;
}