PsmAddress Sm_rbt_create(char *file, int line, PsmPartition partition) { sm_SemId lock; PsmAddress rbt; SmRbt *rbtPtr; lock = sm_SemCreate(SM_NO_KEY, SM_SEM_FIFO); if (lock < 0) { putErrmsg("Can't create semaphore for rbt.", NULL); return 0; } rbt = Psm_zalloc(file, line, partition, sizeof(SmRbt)); if (rbt == 0) { sm_SemDelete(lock); putErrmsg("Can't allocate space for rbt object.", NULL); return 0; } rbtPtr = (SmRbt *) psp(partition, rbt); eraseTree(rbtPtr); rbtPtr->lock = lock; return rbt; }
static void dropVdb(PsmPartition wm, PsmAddress vdbAddress) { IonVdb *vdb; vdb = (IonVdb *) psp(wm, vdbAddress); /* Time-ordered list of probes can simply be destroyed. */ sm_list_destroy(wm, vdb->probes, rfx_erase_data, NULL); /* Three of the red-black tables in the Vdb are * emptied and recreated by rfx_stop(). Destroy them. */ sm_rbt_destroy(wm, vdb->contactIndex, NULL, NULL); sm_rbt_destroy(wm, vdb->rangeIndex, NULL, NULL); sm_rbt_destroy(wm, vdb->timeline, NULL, NULL); /* cgr_stop clears all routing objects, so nodes and * neighbors themselves can now be deleted. */ sm_rbt_destroy(wm, vdb->nodes, destroyIonNode, NULL); sm_rbt_destroy(wm, vdb->neighbors, rfx_erase_data, NULL); /* Safely delete the ZCO availability semaphore. */ sm_SemEnd(vdb->zcoSemaphore); sm_SemDelete(vdb->zcoSemaphore); vdb->zcoSemaphore = SM_SEM_NONE; vdb->zcoClaimants = 0; vdb->zcoClaims = 0; zco_unregister_callback(); }
PsmAddress Sm_list_create(const char *fileName, int lineNbr, PsmPartition partition) { sm_SemId lock; PsmAddress list; SmList *listBuffer; lock = sm_SemCreate(SM_NO_KEY, SM_SEM_FIFO); if (lock < 0) { putErrmsg("Can't create semaphore for list.", NULL); return 0; } list = Psm_zalloc(fileName, lineNbr, partition, sizeof(SmList)); if (list == 0) { sm_SemDelete(lock); putErrmsg("Can't allocate space for list header.", NULL); return 0; } listBuffer = (SmList *) psp(partition, list); eraseList(listBuffer); listBuffer->lock = lock; return list; }
static int wipeList(const char *fileName, int lineNbr, PsmPartition partition, PsmAddress list, SmListDeleteFn deleteFn, void *arg, int destroy) { SmList *listBuffer; PsmAddress elt; PsmAddress next; SmListElt *eltBuffer; listBuffer = (SmList *) psp(partition, list); if (lockSmlist(listBuffer) < 0) { putErrmsg(_cannotLockMsg(), NULL); return -1; } for (elt = listBuffer->first; elt != 0; elt = next) { eltBuffer = (SmListElt *) psp(partition, elt); CHKERR(eltBuffer); next = eltBuffer->next; if (deleteFn) { deleteFn(partition, elt, arg); } /* clear in case user mistakenly accesses later... */ eraseListElt(eltBuffer); Psm_free(fileName, lineNbr, partition, elt); } eraseList(listBuffer); if (destroy) { sm_SemDelete(listBuffer->lock); listBuffer->lock = SM_SEM_NONE; Psm_free(fileName, lineNbr, partition, list); } else { unlockSmlist(listBuffer); } return 0; }
void Sm_rbt_destroy(char *file, int line, PsmPartition partition, PsmAddress rbt, SmRbtDeleteFn deleteFn, void *arg) { SmRbt *rbtPtr; CHKVOID(partition); CHKVOID(rbt); rbtPtr = (SmRbt *) psp(partition, rbt); oK(lockSmrbt(rbtPtr)); destroyRbtNodes(file, line, partition, rbtPtr, deleteFn, arg); /* Now destroy the tree itself. */ sm_SemDelete(rbtPtr->lock); /* just in case user mistakenly accesses later... */ eraseTree(rbtPtr); Psm_free(file, line, partition, rbt); }
void psm_unmanage(PsmPartition partition) { PartitionMap *map; CHKVOID(partition); map = (PartitionMap *) (partition->space); if (map->status == MANAGED) { /* Wait for partition to be no longer in use; unmanage. */ sm_SemTake(map->semaphore); sm_SemDelete(map->semaphore); map->status = INITIALIZED; } /* Destroy space management structure if necessary. */ if (partition->freeNeeded) { free(partition); } }
int bpcp(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10) { int t; char* argv[5]; int argc; /*Initialize CFDP*/ ion_cfdp_init(); /*Recursive flag is a1*/ iamrecursive = atoi((char*)a1); if(iamrecursive!=0 && iamrecursive!=1) { iamrecursive=0; } /*Pretty progress meter always disabled*/ showprogress=0; /*Lifetime is a2. a2=0 results in default lifetime.*/ t=strtol((char*)a2, NULL, 10); if (t > 0) { parms.utParms.lifespan=t; } /*Custody Switch is a3. 1=ON, 0=OFF*/ t = atoi((char*)a3); if(t==1) { parms.utParms.custodySwitch = SourceCustodyRequired; } else { if(t==0) { parms.utParms.custodySwitch = NoCustodyRequested; } } /*Class of Service is a4.*/ t=strtol((char*)a4, NULL, 10); if (t>=0 && t <= 2) { parms.utParms.classOfService=t; } /*Debug flag is a5.*/ debug=atoi((char*)a5); if(debug>0) { version(); } /*a6-a10 are files to copy/destinations*/ argc=0; if((char*)a6!=NULL) { argv[argc]=(char*)a6; argc++; } if((char*)a7!=NULL) { argv[argc]=(char*)a7; argc++; } if((char*)a8!=NULL) { argv[argc]=(char*)a8; argc++; } if((char*)a9!=NULL) { argv[argc]=(char*)a9; argc++; } if((char*)a10!=NULL) { argv[argc]=(char*)a10; argc++; } #else int main(int argc, char **argv) { int ch; extern char *optarg; extern int optind; int tmpoption; /*Initialize CFDP*/ ion_cfdp_init(); /*Parse commandline options*/ while ((ch = getopt(argc, argv, "dqrL:C:S:v")) != -1) { switch (ch) { case 'r': /*Recursive*/ iamrecursive = 1; break; case 'd': /*Debug*/ debug++; break; case 'v': /*Print Version info*/ version(); break; case 'q': /*Quiet*/ showprogress = 0; break; case 'L': /*Lifetime*/ tmpoption=-1; tmpoption=strtol(optarg, NULL, 10); if (tmpoption > 0) { parms.utParms.lifespan=tmpoption; } else { dbgprintf(0, "Error: Invalid BP Lifetime\n"); exit_nicely(1); } break; case 'C': /*Custody Transfer*/ if (strcmp(optarg, "Yes")==0 || strcmp(optarg, "YES")==0 || strcmp(optarg, "yes")==0 || strcmp(optarg, "y")==0 || strcmp(optarg, "On")==0 || strcmp(optarg, "ON")==0 || strcmp(optarg, "on")==0 || strcmp(optarg, "1")==0) { parms.utParms.custodySwitch = SourceCustodyRequired; } else { if (strcmp(optarg, "No")==0 || strcmp(optarg, "NO")==0 || strcmp(optarg, "yes")==0 || strcmp(optarg, "n")==0 || strcmp(optarg, "Off")==0 || strcmp(optarg, "OFF")==0 || strcmp(optarg, "off")==0 || strcmp(optarg, "0")==0) { parms.utParms.custodySwitch = NoCustodyRequested; } else { dbgprintf(0, "Error: Invalid Custody Transfer Setting\n"); } } break; case 'S': /*Class of Service*/ tmpoption=-1; tmpoption=strtol(optarg, NULL, 10); if (tmpoption>=0 && tmpoption <= 2) { parms.utParms.classOfService=tmpoption; } else { dbgprintf(0, "Error: Invalid BP Class of Service\n"); exit_nicely(1); } break; default: usage(); } } argc -= optind; argv += optind; #endif char *targ; /*Initialize tmp file array*/ memset(tmp_files,0, NUM_TMP_FILES*255); #ifdef SIG_HANDLER /*Set SIGTERM and SIGINT handlers*/ isignal(SIGTERM, handle_sigterm); isignal(SIGINT, handle_sigterm); #endif /*Additional argument checks*/ if (!isatty(STDOUT_FILENO)) { showprogress = 0; } if (argc < 2) { usage(); } if (argc > 2) { /*We are moving multiple files, destination must be a directory*/ targetshouldbedirectory = 1; } /*Connect to CFDP*/ if (cfdp_attach() < 0) { dbgprintf(0, "Error: Can't initialize CFDP. Is ION running?\n"); exit(1); } /*Create receiver thread*/ events_sem=sm_SemCreate(SM_NO_KEY, SM_SEM_FIFO); if (events_sem==SM_SEM_NONE || sm_SemTake(events_sem)<0) { dbgprintf(0, "Error: Can't create semaphore\n"); exit(1); } recv_running=1; if (pthread_begin(&rcv_thread, NULL, &rcv_msg_thread, (void*)&recv_running)) { dbgprintf(0, "Error: Can't start message thread\n"); sm_SemDelete(events_sem); exit(1); } /*Parse Paths*/ if ((targ = remote_path(argv[argc - 1]))) { /* Last path is remote path * Destination is remote host*/ toremote(targ, argc, argv); } else { /*Destination is localhost*/ if (targetshouldbedirectory) { /*If we are moving multiple files, check that destination * is directory*/ if (is_dir(argv[argc - 1])) { tolocal(argc, argv); } else { dbgprintf(0, "Error: Destination is not a directory\n"); exit_nicely(1); } } else { /*Single file copy*/ tolocal(argc, argv); } } exit_nicely(0); return 0; }