void DeletePort ( /* SYNOPSIS */ struct MsgPort * mp) /* FUNCTION Free a message port created by CreatePort() INPUTS mp - The result of CreatePort() RESULT None. NOTES EXAMPLE BUGS SEE ALSO CreatePort(), exec.library/CreateMsgPort(), exec.library/DeleteMsgPort() INTERNALS HISTORY ******************************************************************************/ { if (mp->mp_Node.ln_Name) RemPort (mp); DeleteMsgPort (mp); } /* DeletePort */
VOID DeletePort(struct MsgPort *port) { APTR SysBase = *(APTR *)4L; if (port->mp_Node.ln_Name) RemPort(port); FreeSignal(port->mp_SigBit); FreeMem(port,sizeof(*port)); }
void amigaExit(void) { #if USE_RESETHANDLER rem_resethandler(); #endif #ifndef NO_GUI amigaCloseNewConsole(); amigaGUIDeinit(); #endif #ifdef __amigaos4__ if (ISocket) DropInterface((struct Interface *)ISocket); #else CloseLibrary((struct Library *)LocaleBase); #endif CloseLibrary((struct Library *)SocketBase); #ifdef __OS3PPC__ /* ** PPC */ #ifdef CHANGE_MIRROR_TASK_PRI SetTaskPri(FindTask(NULL), Old68kMirrorPri); #endif #ifdef __POWERUP__ /* ** PowerUp */ if (TriggerPort) { while (!PPCDeletePort(TriggerPort)) amigaSleep(0,250000); } CloseLibrary(PPCLibBase); #else /* ** WarpOS */ if (TriggerPort) { RemPortPPC(TriggerPort); DeleteMsgPortPPC(TriggerPort); } #endif #else /* ** 68K / OS4 / MorphOS */ if (TriggerPort) { RemPort(TriggerPort); DeleteMsgPort(TriggerPort); } #endif GlobalTimerDeinit(); #if USE_RESETHANDLER finish_resethandler(); #endif }
void cleanup(int kod,char *text) { shutdownnode(NODSER); CloseIO(); if(NiKwind) CloseWindow(NiKwind); if(RexxSysBase) CloseLibrary((struct Library *)RexxSysBase); if(nikomnodeport) { RemPort(nikomnodeport); DeleteMsgPort(nikomnodeport); } if(rexxport) { RemPort(rexxport); DeleteMsgPort(rexxport); } if(NiKomBase) CloseLibrary(NiKomBase); if(UtilityBase) CloseLibrary(UtilityBase); if(IntuitionBase) CloseLibrary((struct Library *)IntuitionBase); printf("%s",text); exit(kod); }
void DeletePort (struct MsgPort *port) { int i; if (port->mp_Node.ln_Name != NULL) RemPort (port); i = -1; port->mp_Node.ln_Type = i; port->mp_MsgList.lh_Head = (struct Node *)i; FreeSignal (port->mp_SigBit); PPCFreeMem (port, sizeof (struct MsgPort)); }
void cleanup(int kod,char *fel) { shutdownnode(NODCON); freealiasmem(); freeeditlist(); CloseIO(); if(NiKwind) CloseWindow(NiKwind); if(RexxSysBase) CloseLibrary((struct Library *)RexxSysBase); if(nikomnodeport) { RemPort(nikomnodeport); DeleteMsgPort(nikomnodeport); } if(rexxport) { RemPort(rexxport); DeleteMsgPort(rexxport); } if(NiKomBase) CloseLibrary(NiKomBase); if(UtilityBase) CloseLibrary(UtilityBase); if(IntuitionBase) CloseLibrary((struct Library *)IntuitionBase); printf("%s",fel); exit(kod); }
void cleanup(int kod,char *text) { CloseCatalog(g_Catalog); freealiasmem(); freeeditlist(); CloseIO(); if(NiKwind) CloseWindow(NiKwind); if(RexxSysBase) CloseLibrary((struct Library *)RexxSysBase); if(nikomnodeport) { RemPort(nikomnodeport); DeleteMsgPort(nikomnodeport); } if(rexxport) { RemPort(rexxport); DeleteMsgPort(rexxport); } shutdownnode(NODSPAWNED); if(NiKomBase) CloseLibrary(NiKomBase); if(UtilityBase) CloseLibrary(UtilityBase); if(LocaleBase) CloseLibrary(LocaleBase); if(IntuitionBase) CloseLibrary((struct Library *)IntuitionBase); printf("%s",text); exit(kod); }
/************* * FUNCTION: DeleteRexxHost * VERSION: 0.1 08.03.1995 * DESCRIPTION: Deletes a MsgPort as created by CreateRexxHost(). * Returns NULL, so user can do 'Host = DeleteRexxHost(Host);' * INPUT: RexxHost * OUTPUT: NULL * HISTORY: DATE NAME COMMENT * 08.03.95 ah first release *************/ void *DeleteRexxHost(struct MsgPort *RexxHost) { /* Valid host port given? */ if(RexxHost) { /* Remove it from the public list. */ RemPort(RexxHost); /* Free the name. */ FreeMem(RexxHost->mp_Node.ln_Name,strlen(RexxHost->mp_Node.ln_Name)+1); /* Free the allocated signal bit. */ FreeSignal(RexxHost->mp_SigBit); /* Free the body. */ FreeMem(RexxHost,sizeof(struct MsgPort)); } return(NULL); }
void arexx_cleanup(void) { if (arexx_port) { RemPort(arexx_port); DeleteMsgPort(arexx_port); } while (arexx_execute_out) { struct RexxMsg *rxmsg; WaitPort(arexx_execute_port); while ((rxmsg = (struct RexxMsg *)GetMsg(arexx_execute_port))) { arexx_execute_out--; ClearRexxMsg(rxmsg,1); DeleteRexxMsg(rxmsg); } } if (arexx_execute_port) DeleteMsgPort(arexx_execute_port); }
int main(void) { struct Library *MiamiBase; if (Setup()) { if (Port = CreateMsgPort()) { struct Message *m; Port->mp_Node.ln_Name = "SysLog"; Port->mp_Node.ln_Pri = 12; AddPort(Port); MiamiBase = OpenLibrary("miami.library",13); if (MiamiBase) { SetSysLogPort(); CloseLibrary(MiamiBase); } if (BuildGui()) { DoMethod(App, MUIM_Application_Load, MUIV_Application_Load_ENV); SetNotifications(); MainLoop(Win); MUI_DisposeObject(App); } RemPort(Port); MiamiBase = OpenLibrary("miami.library",13); if (MiamiBase) { SetSysLogPort(); CloseLibrary(MiamiBase); } while (m = GetMsg(Port)) ReplyMsg(m); DeleteMsgPort(Port); } } else Printf("Setup() failed.\n"); Cleanup(); return 0; }
void main(int argc,char *argv[]) { int going=TRUE,forsok=2,car=1,x,connectbps, i, tmp; struct NodeType *nt; char *tmppscreen,commandstring[100], configname[50] = "NiKom:DatoCfg/SerNode.cfg"; FILE *fil; if(argc>1) for(x=1; x<argc; x++) { if(argv[x][0]=='-') { if(argv[x][1]=='G') getty=TRUE; else if(argv[x][1]=='B') gettybps=atoi(&argv[x][2]); else if(argv[x][1]=='C') connectbps = atoi(&argv[x][2]); } else strcpy(configname,argv[x]); } if(!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0))) cleanup(ERROR,"Kunde inte öppna intuition.library\n"); if(!(UtilityBase=OpenLibrary("utility.library",37L))) cleanup(ERROR,"Kunde inte öppna utility.library\n"); if(!(NiKomBase=OpenLibrary("nikom.library",0L))) cleanup(ERROR,"Kunde inte öppna nikom.library\n"); if(!initnode(NODSER)) cleanup(ERROR,"Kunde inte registrera noden i Servern\n"); if(!(nikomnodeport = CreateMsgPort())) cleanup(ERROR,"Kunde inte skapa NiKomNode-porten"); sprintf(nikomnodeportnamn,"NiKomNode%d",nodnr); nikomnodeport->mp_Node.ln_Name = nikomnodeportnamn; nikomnodeport->mp_Node.ln_Pri = 1; AddPort(nikomnodeport); sprintf(rexxportnamn,"NiKomPreRexx%d",nodnr); if(!(rexxport=(struct MsgPort *)CreateMsgPort())) cleanup(ERROR,"Kunde inte öppna RexxPort\n"); rexxport->mp_Node.ln_Name=rexxportnamn; rexxport->mp_Node.ln_Pri=50; AddPort(rexxport); if(!(RexxSysBase=(struct RsxLib *)OpenLibrary("rexxsyslib.library",0L))) cleanup(ERROR,"Kunde inte öppna rexxsyslib.library\n"); getnodeconfig(configname); if(pubscreen[0]=='-') tmppscreen=NULL; else tmppscreen=pubscreen; if(!(NiKwind=openmywindow(tmppscreen))) cleanup(ERROR,"Kunde inte öppna fönstret\n"); if(getty) dtespeed = gettybps; else dtespeed = highbaud; if(!OpenIO(NiKwind)) cleanup(ERROR,"Couldn't setup IO"); strcpy(Servermem->nodid[nodnr],nodid); conreqtkn(); serreqtkn(); Delay(50); for(;;) { inloggad=-1; Servermem->idletime[nodnr] = time(NULL); Servermem->inloggad[nodnr]=-1; if(getty) Servermem->connectbps[nodnr] = connectbps; else waitconnect(); Servermem->idletime[nodnr] = time(NULL); Servermem->inloggad[nodnr]=-2; /* Sätt till <Uppringd> för att även hantera -getty-fallet */ reloginspec: updateinactive(); Servermem->inne[nodnr].flaggor = Servermem->cfg.defaultflags; if(!getty) Delay(100); Servermem->inne[nodnr].rader=0; Servermem->inne[nodnr].chrset = CHRS_LATIN1; sendfile("NiKom:Texter/Inlogg.txt"); if(Servermem->cfg.ar.preinlogg) sendrexx(Servermem->cfg.ar.preinlogg); car=TRUE; Servermem->inne[nodnr].chrset = 0; memset(commandhistory,0,1000); going=1; while(going && going<=Servermem->cfg.logintries) { putstring("\r\nNamn: ",-1,0); if(getstring(EKO,40,NULL)) { car=FALSE; break; } if(!stricmp(inmat,Servermem->cfg.ny) && !(Servermem->cfg.cfgflags & NICFG_CLOSEDBBS)) { tmp = RegisterNewUser(); if(tmp == 2) { goto panik; } car = tmp ? 0 : 1; going=FALSE; } else if((inloggad=parsenamn(inmat))>=0) { if(readuser(inloggad,&Servermem->inne[nodnr])) { puttekn("Error reading user data.\r\n", -1); goto panik; } // TODO: Extract password loop. Should be identical to in NiKomCon.c forsok=2; while(forsok) { puttekn("\r\nLösen: ",-1); if(Servermem->inne[nodnr].flaggor & STAREKOFLAG) { if(getstring(STAREKO,15,NULL)) { car=FALSE; break; } } else { if(getstring(EJEKO,15,NULL)) { car=FALSE; break; } } if(CheckPassword(inmat, Servermem->inne[nodnr].losen)) { forsok=FALSE; going=FALSE; } else forsok--; } if(going && (Servermem->cfg.logmask & LOG_FAILINLOGG)) { LogEvent(USAGE_LOG, WARN, "Nod %d, %s angivet som namn, fel lösen.", nodnr, getusername(inloggad)); } if(going) going++; } else if(inloggad==-1) puttekn("\r\nHittar ej namnet\r\n",-1); } if(!car) { if(getty) cleanup(OK,""); disconnect(); continue; } if(going) { putstring("\n\n\rTyvärr. Du har försökt maximalt antal gånger att logga in. Kopplar ned.\n\r",-1,0); goto panik; /* Urrk vad fult. :-) */ } Servermem->inloggad[nodnr]=inloggad; Servermem->idletime[nodnr] = time(NULL); if((nt = selectNodeType()) == NULL) { goto panik; } abortinactive(); abortserial(); sprintf(commandstring,"%s -N%d -B%d %s",nt->path,nodnr,dtespeed,configname); CloseConsole(); CloseWindow(NiKwind); NiKwind = NULL; RemPort(nikomnodeport); i = 0; if(Servermem->connectbps[nodnr] > 0) { while(Servermem->info.bps[i] != Servermem->connectbps[nodnr] && Servermem->info.bps[i] > 0 && i<49) i++; if(i<49) { if(Servermem->info.bps[i] == Servermem->connectbps[nodnr]) Servermem->info.antbps[i]++; else { Servermem->info.bps[i] = Servermem->connectbps[nodnr]; Servermem->info.antbps[i]++; } } if(!(fil = fopen("NiKom:datocfg/sysinfo.dat","w"))) { /* putstring("Kunde inte spara nya sysinfo.dat..\n",-1,0); */ } if(fwrite((void *)&Servermem->info,sizeof(Servermem->info),1,fil) != 1) { /* putstring("Kunde inte skriva till nya sysinfo.dat....\n",-1,0); */ } fclose(fil); } nodestate = SystemTags(commandstring, SYS_UserShell, TRUE, TAG_DONE); AddPort(nikomnodeport); if(!getty || (nodestate & NIKSTATE_RELOGIN)) { if(!(NiKwind = openmywindow(tmppscreen))) cleanup(ERROR,"Kunde inte öppna fönstret\n"); OpenConsole(NiKwind); } serreqtkn(); if(nodestate & NIKSTATE_RELOGIN) goto reloginspec; panik: Delay(hangupdelay); if(getty) cleanup(OK,""); disconnect(); } }
// Quit the program void quit(BOOL script) { // If main status window is open, close it if (main_status) { CloseProgressWindow(main_status); main_status=0; } if (GUI) { // Clear 'startup' flag for scripts GUI->flags&=~GUIF_DONE_STARTUP; // Close commodities cx_remove(GUI->cx); // Update environment settings env_update_settings(1); // Stop notify request RemoveNotifyRequest(GUI->notify_req); GUI->notify_req=0; // Is there a hide appicon? if (GUI->hide_appicon) { RemoveAppIcon(GUI->hide_appicon); FreeCachedDiskObject(GUI->hide_diskobject); } // Or an appmenuitem? if (GUI->hide_appitem) RemoveAppMenuItem(GUI->hide_appitem); // Launch shutdown script if (script) RunScript(SCRIPT_SHUTDOWN,0); // Set quit flag GUI->flags|=GUIF_PENDING_QUIT; // Shut the display down close_display(CLOSE_ALL,TRUE); // Send quit notifications quit_notify(); // Stop notifications stop_file_notify(GUI->pattern_notify); stop_file_notify(GUI->font_notify); stop_file_notify(GUI->modules_notify); stop_file_notify(GUI->commands_notify); stop_file_notify(GUI->env_notify); stop_file_notify(GUI->desktop_notify); stop_file_notify(GUI->filetype_notify); // Free application port if (GUI->appmsg_port) { DOpusAppMessage *amsg; RemPort(GUI->appmsg_port); while ((amsg=(DOpusAppMessage *)GetMsg(GUI->appmsg_port))) ReplyAppMessage(amsg); DeleteMsgPort(GUI->appmsg_port); GUI->appmsg_port=0; // Remove public semaphore RemSemaphore((struct SignalSemaphore *)&pub_semaphore); } // Flush IPC port IPC_Flush(&main_ipc); // Close all processes IPC_ListQuit(&GUI->lister_list,&main_ipc,0,TRUE); IPC_ListQuit(&GUI->group_list,&main_ipc,0,TRUE); IPC_ListQuit(&GUI->buttons_list,&main_ipc,0,TRUE); IPC_ListQuit(&GUI->startmenu_list,&main_ipc,0,TRUE); IPC_ListQuit(&GUI->process_list,&main_ipc,0,TRUE); IPC_ListQuit(&GUI->function_list,&main_ipc,0,TRUE); // Free buffers buffers_clear(0); // Remove all handlers RemFunctionTrap("*","#?"); // Free filetypes FreeMemHandle(GUI->filetype_memory); // Flush the filetype cache ClearFiletypeCache(); // Free lister toolbar FreeToolBar(GUI->toolbar); // Free menus and hotkeys CloseButtonBank(GUI->lister_menu); CloseButtonBank(GUI->hotkeys); // Free user menus CloseButtonBank(GUI->user_menu); FreeVec(GUI->user_menu_data); // Free backdrop list backdrop_free(GUI->backdrop); // Free icons if (GUI->lister_icon) FreeCachedDiskObject(GUI->lister_icon); if (GUI->button_icon) FreeCachedDiskObject(GUI->button_icon); // Free arrow image CloseImage(GUI->toolbar_arrow_image); #ifdef __amigaos3__ FreeVec(arrow_hi_data_chip); FreeVec(arrow_lo_data_chip); FreeVec(small_arrow_chip); FreeVec(big_arrow_chip); #ifndef USE_SCREENTITLE FreeVec(moon_big_data_chip); FreeVec(moon_small_data_chip); #endif FreeVec(command_arrow_chip); FreeVec(parent_arrow_chip); #endif // Free screen signal if (GUI->screen_signal!=-1) FreeSignal(GUI->screen_signal); // Delete notify port if (GUI->notify_port) DeleteMsgPort(GUI->notify_port); // Free position memory FreeMemHandle(GUI->position_memory); // Free command history Att_RemList(GUI->command_history,0); // Delete icon positioning port DeleteMsgPort(GUI->iconpos_port); // Free popup menu PopUpFreeHandle(GUI->desktop_menu); // Clear requester pattern hook in library if (GUI->flags2&GUIF2_BACKFILL_SET) SetReqBackFill(0,0); } // Free scripts FreeScripts(); // Free environment environment_free(environment); // Delete main message ports IPC_Flush(&main_ipc); DeleteMsgPort(main_ipc.command_port); DeleteMsgPort(main_ipc.reply_port); // Pause here for a couple of seconds to let everything clean up Delay(3*50); // Free global data FreeMemHandle(global_memory_pool); // Delete any temporary files delete_temp_files(0); // Free locale data free_locale_data(&locale); // Close input device if (InputBase) { #ifdef __amigaos4__ DropInterface((struct Interface *)IInput); #endif CloseDevice((struct IORequest *)&input_req); } // Close timer device if (TimerBase) { #ifdef __amigaos4__ DropInterface((struct Interface *)ITimer); #endif CloseDevice((struct IORequest *)&timer_req); } // Close console device if (ConsoleDevice) { #ifdef __amigaos4__ DropInterface((struct Interface *)IConsole); #endif CloseDevice((struct IORequest *)&console_req); } // Close libraries #ifdef __amigaos4__ DropInterface((struct Interface *)Imu); #endif CloseLibrary(muBase); #ifndef __amigaos3__ #ifdef __amigaos4__ DropInterface((struct Interface *)INewIcon); #endif CloseLibrary((struct Library *)NewIconBase); #endif #ifdef __amigaos4__ DropInterface((struct Interface *)ICyberGfx); #endif CloseLibrary(CyberGfxBase); #ifdef __amigaos4__ DropInterface((struct Interface *)IAmigaGuide); #endif CloseLibrary(AmigaGuideBase); #ifdef __amigaos4__ DropInterface((struct Interface *)IDataTypes); #endif CloseLibrary(DataTypesBase); #ifdef __amigaos4__ DropInterface((struct Interface *)IAsl); #endif CloseLibrary(AslBase); #ifdef __amigaos4__ DropInterface((struct Interface *)IIcon); #endif CloseLibrary(IconBase); #ifdef __amigaos4__ DropInterface((struct Interface *)IDiskfont); #endif CloseLibrary(DiskfontBase); #ifdef __amigaos4__ DropInterface((struct Interface *)IWorkbench); #endif CloseLibrary(WorkbenchBase); #ifdef __amigaos4__ DropInterface((struct Interface *)ICommodities); #endif CloseLibrary(CxBase); #ifdef __amigaos4__ DropInterface((struct Interface *)IRexxSys); #endif CloseLibrary((struct Library *)RexxSysBase); #ifdef __amigaos4__ DropInterface((struct Interface *)IUtility); #endif CloseLibrary(UtilityBase); #ifdef __amigaos4__ DropInterface((struct Interface *)IGadTools); #endif CloseLibrary(GadToolsBase); #ifdef __amigaos4__ DropInterface((struct Interface *)ILayers); #endif CloseLibrary((struct Library *)LayersBase); #ifdef __amigaos4__ DropInterface((struct Interface *)IGraphics); #endif CloseLibrary((struct Library *)GfxBase); #ifdef __amigaos4__ DropInterface((struct Interface *)IIntuition); #endif CloseLibrary((struct Library *)IntuitionBase); // Restore old current directory? if (old_current_dir) { UnLock(CurrentDir(old_current_dir)); } // Close the dopus5.library #ifdef __amigaos4__ DropInterface((struct Interface *)IDOpus); #endif CloseLibrary(DOpusBase); // Outahere! exit(0); }
// Save filetypes short filetype_save(config_filetypes_data *data) { Cfg_FiletypeList *list; Cfg_Filetype *type; short ret=1; struct MsgPort *port; // Open a port to stop dopus re-reading if ((port=CreateMsgPort())) { port->mp_Node.ln_Name="FILETYPE LOCK"; AddPort(port); } // Go through filetype lists for (list=(Cfg_FiletypeList *)data->list_list.lh_Head; list->node.ln_Succ; list=(Cfg_FiletypeList *)list->node.ln_Succ) { // Has this list been modified? if (list->flags&FTLISTF_CHANGED) { // Clear flag list->flags&=~FTLISTF_CHANGED; // Is the list empty? if (IsListEmpty(&list->filetype_list)) { // Valid list path? if (list->path[0]) { // Try to delete list if (!DeleteFile(list->path)) ret=0; } } // Otherwise else { short err; // Valid list path? if (!list->path[0]) { char *ptr; // Build path from name of first filetype type=(Cfg_Filetype *)list->filetype_list.lh_Head; // Storage or normal? if (list->flags&FTLISTF_STORE) strcpy(list->path,"dopus5:Filetypes/Storage/"); else strcpy(list->path,"dopus5:Filetypes/"); // Check name for / characters for (ptr=type->type.name;*ptr;ptr++) if (*ptr=='/') *ptr='\\'; // Add name strcat(list->path,type->type.name); } // Store? else if (list->flags&FTLISTF_STORE) { char buf[256]; // Build storage filename lsprintf(buf,"dopus5:Storage/Filetypes/%s",FilePart(list->path)); // Delete existing stored filetype DeleteFile(buf); // Move file to storage if (Rename(list->path,buf)) { // Get names for icon strcat(list->path,".info"); strcat(buf,".info"); // Delete existing stored filetype DeleteFile(buf); // Move icon Rename(list->path,buf); // Clear .info suffix buf[strlen(buf)-5]=0; // Use path to save strcpy(list->path,buf); } // Clear flag list->flags&=~FTLISTF_STORE; } // Success by default ret=1; // Save filetype list while ((err=SaveFiletypeList(list,list->path))>0) { // Show error if (!(ret=error_saving(err,data->window))) break; } // Failed? if (!ret) { // Set change flag again list->flags|=FTLISTF_CHANGED; break; } } } } // Remove lock port if (port) { RemPort(port); DeleteMsgPort(port); } return ret; }
LONG HandleSignal( LONG Signal ) { BlankMsg *CurMsg; LONG RetVal = OK; if( Signal & SIG_TIMER ) { MessageServer( BM_FAILED ); RetVal = UNBLANK; } if( Signal & SIG_PORT ) { while( CurMsg = ( BlankMsg * )GetMsg( ClientPort )) { LONG Type = CurMsg->bm_Type; LONG Flags = CurMsg->bm_Flags; if( Type != BM_PING ) ServerBlanking = ( LONG * )CurMsg->bm_Mess.mn_Node.ln_Name; if( Flags & BF_REPLY ) FreeVec( CurMsg ); else { CurMsg->bm_Flags |= BF_REPLY; ReplyMsg(( struct Message * )CurMsg ); } switch( Type ) { case BM_DOBLANK: case BM_DOTESTBLANK: if( !Blanking ) { PrefObject *TmpPrefs; Blanking = TRUE; CurrentTime( &InitSecs, &InitMicros ); if( Type == BM_DOTESTBLANK ) TmpPrefs = LoadPrefs( "T:GBlankerTmpPrefs" ); switch( Blank( Type == BM_DOBLANK ? CurPrefs : TmpPrefs )) { case FAILED: /* In this case the Blank() function failed to init */ /* (ie. no memory or something). So we yell. */ MessageServer( BM_FAILED ); break; case DELAYEDQUIT: case QUIT: RetVal = QUIT; break; } Blanking = FALSE; if( Type == BM_DOTESTBLANK ) FreeVec( TmpPrefs ); } break; case BM_RELOADPREFS: if( CurPrefs ) FreeVec( CurPrefs ); CurPrefs = LoadPrefs( PrefsPath ); break; case BM_DELAYEDQUIT: RemPort( ClientPort ); PortRemoved = TRUE; RetVal = DELAYEDQUIT; break; case BM_DOQUIT: RetVal = QUIT; break; case BM_UNBLANK: break; } } } if( Signal & SIGBREAKF_CTRL_C ) RetVal = QUIT; return RetVal; }
int main(void) { struct TrackedResources *crs = NULL; struct TrackedResources *start_rs = NULL; BOOL quitme = FALSE; int numlines = 30; struct Task *this; ULONG portsig; struct MsgPort *port; this = FindTask(NULL); port = CreateMsgPort(); if (!port) return 2; port->mp_Node.ln_Name = "LeakWatch"; port->mp_Node.ln_Pri = 0; AddPort(port); portsig = 1L << port->mp_SigBit; open_libs(); FPuts(Output(), "LeakWatch running, CTRL-C to exit, CTRL-E to watch for leaks since beginning, CTRL-F to watch for leaks since last CTRL-F, CTRL-D for an usage snapshot\n"); crs = NewResourcesState(); if (NULL == crs) quitme = TRUE; else start_rs = CopyResourcesState(crs); while(!quitme) { ULONG signals; signals = Wait(portsig | SIGBREAKF_CTRL_F | SIGBREAKF_CTRL_E | SIGBREAKF_CTRL_D | SIGBREAKF_CTRL_C); if (signals & SIGBREAKF_CTRL_D) { struct TrackedResources *tr; tr = NewResourcesState(); if (NULL == tr) { quitme = TRUE; break; } DisplayResourcesState(tr, numlines); DeleteResourcesState(tr); } if (signals & SIGBREAKF_CTRL_E) { struct ResourceDiff *rd = NULL; DeleteResourcesState(crs); crs = NewResourcesState(); if (NULL == crs) { quitme = TRUE; break; } /* DisplayResourcesState(crs); */ /* only for debug */ rd = NewStateDiff(start_rs, crs); DisplayStateDiff(rd, numlines); DeleteStateDiff(rd); } if (signals & SIGBREAKF_CTRL_F) { struct TrackedResources *ors = crs; struct ResourceDiff *rd = NULL; crs = NewResourcesState(); if (NULL == crs) { quitme = TRUE; break; } rd = NewStateDiff(ors, crs); DisplayStateDiff(rd, numlines); DeleteStateDiff(rd); DeleteResourcesState(ors); } if (signals & SIGBREAKF_CTRL_C) { quitme = TRUE; } if (signals & portsig) { struct Message *msg; while((msg = (struct Message *)GetMsg(port))) { D(bug("Received watch message.\n")); ReplyMsg(msg); } } } /* while(!quitme) */ DeleteResourcesState(crs); DeleteResourcesState(start_rs); close_libs(); if (port) { RemPort(port); DeleteMsgPort(port); } return 0; }
int main( void ) { struct Process *Proc = ( struct Process * )FindTask( 0L ); BlankMsg *FreeMsg; LONG ReturnVal = 0; if( Proc->pr_CLI ) { STRPTR Str = BADDR((( struct CommandLineInterface * ) BADDR( Proc->pr_CLI ))->cli_CommandName ); CopyMem( Str + 1, PrefsPath, *Str ); PrefsPath[*Str] = '\0'; strcat( PrefsPath, ".prefs" ); } IntuitionBase = OpenLibrary( "intuition.library", 37L ); GfxBase = OpenLibrary( GRAPHICSNAME, 37L ); GarshnelibBase = OpenLibrary( "Garshnelib.library", 37L ); if( IntuitionBase && GfxBase && GarshnelibBase ) { ClientPort = CreateMsgPort(); TimerPort = CreateMsgPort(); if( ClientPort && TimerPort ) { TimeOutIO = ( struct timerequest * ) CreateExtIO( TimerPort, sizeof( struct timerequest )); if( TimeOutIO && !OpenDevice( "timer.device", UNIT_VBLANK, ( struct IORequest * )TimeOutIO, 0L )) { ClientPort->mp_Node.ln_Name = PortName; ClientPort->mp_Node.ln_Pri = 0L; AddPort( ClientPort ); CurPrefs = LoadPrefs( PrefsPath ); CurrentTime( &InitSecs, &InitMicros ); RangeSeed = InitSecs + InitMicros; Blank( CurPrefs ); while( FreeMsg = ( BlankMsg * )GetMsg( ClientPort )) { if( FreeMsg->bm_Type & BF_REPLY ) FreeVec( FreeMsg ); else { FreeMsg->bm_Type |= BF_REPLY; ReplyMsg(( struct Message * )FreeMsg ); } } if( CurPrefs ) FreeVec( CurPrefs ); if( !PortRemoved ) RemPort( ClientPort ); } if( TimeOutIO ) { if( TimeOutIO->tr_node.io_Device ) CloseDevice(( struct IORequest * )TimeOutIO ); DeleteExtIO(( struct IORequest * )TimeOutIO ); } } else { Complain( "ClientPort or TimerPort failed to open." ); ReturnVal = 2; } if( ClientPort ) { BlankMsg *TmpMsg; while( TmpMsg = ( BlankMsg * )GetMsg( ClientPort )) { TmpMsg->bm_Flags |= BF_REPLY; ReplyMsg(( struct Message * )TmpMsg ); } DeleteMsgPort( ClientPort ); } if( TimerPort ) DeleteMsgPort( TimerPort ); } else { Complain( "A library failed to open." ); ReturnVal = 1; } if( GarshnelibBase ) CloseLibrary( GarshnelibBase ); if( GfxBase ) CloseLibrary( GfxBase ); if( IntuitionBase ) CloseLibrary( IntuitionBase ); return ReturnVal; }
int main(int argc, char* argv[]) { struct MsgPort *port1; struct Task *t; port1=CreateMsgPort(); if(port1!=NULL) { port1->mp_Node.ln_Name="message test port"; Forbid(); if(FindPort(port1->mp_Node.ln_Name)==NULL) { AddPort(port1); Permit(); t=(struct Task *)AllocMem(sizeof(struct Task), MEMF_PUBLIC|MEMF_CLEAR); if(t!=NULL) { UBYTE *s; s=(UBYTE *)AllocMem(STACKSIZE, MEMF_PUBLIC|MEMF_CLEAR); if(s!=NULL) { t->tc_Node.ln_Type=NT_TASK; t->tc_Node.ln_Pri=1; t->tc_Node.ln_Name="new task"; t->tc_SPLower=s; t->tc_SPUpper=s+STACKSIZE; #if AROS_STACK_GROWS_DOWNWARDS t->tc_SPReg=(UBYTE *)t->tc_SPUpper-SP_OFFSET; #else t->tc_SPReg=(UBYTE *)t->tc_SPLower-SP_OFFSET; #endif NEWLIST(&t->tc_MemEntry); AddTask(t,&entry,NULL); Wait(1<<port1->mp_SigBit); if(port1->mp_MsgList.lh_Head->ln_Succ!=NULL) { int i; for(i=0;i<10;i++) { struct Message *msg; WaitPort(port1); msg=GetMsg(port1); printf("%d\n",(int)msg->mn_Node.ln_Name); ReplyMsg(msg); } Wait(1<<port1->mp_SigBit); RemTask(t); } FreeMem(s,STACKSIZE); } FreeMem(t,sizeof(struct Task)); } RemPort(port1); }else Permit(); DeleteMsgPort(port1); } return 0; }