int main(int argc, char* args[]) { char epath[512]; char instr[512]; cd("ibin"); while(1) { getExecPath(epath); printf("$%s> ", epath); getln(instr); char* cmd = strtoknc(instr, " "); if(cmd != 0) { char* pargs[64]; int n = 0; do { pargs[n] = strtoknc(0, " "); } while(pargs[n++] != 0); fsexec(cmd, pargs, 0, 0, 0); printf("\n"); } } return 0; }
int main(int o_argc, const string const* o_argv) { struct sembuf _buf; _buf.sem_num = 0; _buf.sem_flg = 0; string _path = getExecPath("sys_v_sem"); key_t _key = ftok(_path, 'x'); asserts(_key, "ftok"); free(_path); _path = NULL; /* Try to obtain an id of the set of semaphores. */ int _semid = semget(_key, 1, S_IRUSR | S_IWUSR); asserts(_semid); /* lock the semaphore */ _buf.sem_op = -1; asserts( semop(_semid, &_buf, 1) ); /* enter critical section */ for(size_t i = 0; i < 5; i++) { printfln( "Hello!, %ld", cast(ulong)getpid() ); sleep(1); } println(""); /* unlock the semaphore */ _buf.sem_op = 1; asserts( semop(_semid, &_buf, 1) ); exit(EXIT_SUCCESS); }
int main(int argc, char* args[]) { char epath[512]; char instr[512]; cd("ibin"); while (1) { getExecPath(epath); printf("#%s> ", epath); getln(instr); char** array = split(instr, " ", "\"", "\\"); struct list* newArgs = list_fromarray((void**) array, -1); free(array); list_foreach(newArgs, func_reformat); interpret(newArgs); } return 0; }
void init_firewall_exceptions() { #ifdef WIN32 bool add_exception; char *master_image_path, *schedd_image_path, *startd_image_path, *dbmsd_image_path, *quill_image_path, *dagman_image_path, *negotiator_image_path, *collector_image_path, *starter_image_path, *shadow_image_path, *gridmanager_image_path, *gahp_image_path, *gahp_worker_image_path, *credd_image_path, *vmgahp_image_path, *kbdd_image_path, *hdfs_image_path, *bin_path; const char* dagman_exe = "condor_dagman.exe"; WindowsFirewallHelper wfh; add_exception = param_boolean("ADD_WINDOWS_FIREWALL_EXCEPTION", true); if ( add_exception == false ) { dprintf(D_FULLDEBUG, "ADD_WINDOWS_FIREWALL_EXCEPTION is false, skipping\n"); return; } // We use getExecPath() here instead of param() since it's // possible the the Windows Service Control Manager // (SCM) points to one location for the master (which // is exec'd), while MASTER points to something else // (and ignored). master_image_path = getExecPath(); if ( !master_image_path ) { dprintf(D_ALWAYS, "WARNING: Failed to get condor_master image path.\n" "Condor will not be excepted from the Windows firewall.\n"); return; } // We want to add exceptions for the SCHEDD and the STARTD // so that (1) shadows can accept incoming connections on their // command port and (2) so starters can do the same. schedd_image_path = param("SCHEDD"); startd_image_path = param("STARTD"); // We to also add exceptions for Quill and DBMSD quill_image_path = param("QUILL"); dbmsd_image_path = param("DBMSD"); // And add exceptions for all the other daemons, since they very well // may need to open a listen port for mechanisms like CCB, or HTTPS negotiator_image_path = param("NEGOTIATOR"); collector_image_path = param("COLLECTOR"); starter_image_path = param("STARTER"); shadow_image_path = param("SHADOW"); gridmanager_image_path = param("GRIDMANAGER"); gahp_image_path = param("CONDOR_GAHP"); gahp_worker_image_path = param("CONDOR_GAHP_WORKER"); credd_image_path = param("CREDD"); kbdd_image_path = param("KBDD"); hdfs_image_path = param("HDFS"); vmgahp_image_path = param("VM_GAHP_SERVER"); // We also want to add exceptions for the DAGMan we ship // with Condor: bin_path = param ( "BIN" ); if ( bin_path ) { dagman_image_path = (char*) malloc ( strlen ( bin_path ) + strlen ( dagman_exe ) + 2 ); if ( dagman_image_path ) { sprintf ( dagman_image_path, "%s\\%s", bin_path, dagman_exe ); } free ( bin_path ); } // Insert the master if ( !SUCCEEDED(wfh.addTrusted(master_image_path)) ) { dprintf(D_FULLDEBUG, "WinFirewall: unable to add %s to the " "windows firewall exception list.\n", master_image_path); } // Insert daemons needed on a central manager if ( (daemons.FindDaemon("NEGOTIATOR") != NULL) && negotiator_image_path ) { if ( !SUCCEEDED(wfh.addTrusted(negotiator_image_path)) ) { dprintf(D_FULLDEBUG, "WinFirewall: unable to add %s to the " "windows firewall exception list.\n", negotiator_image_path); } } if ( (daemons.FindDaemon("COLLECTOR") != NULL) && collector_image_path ) { if ( !SUCCEEDED(wfh.addTrusted(collector_image_path)) ) { dprintf(D_FULLDEBUG, "WinFirewall: unable to add %s to the " "windows firewall exception list.\n", collector_image_path); } } // Insert daemons needed on a submit node if ( (daemons.FindDaemon("SCHEDD") != NULL) && schedd_image_path ) { // put in schedd if ( !SUCCEEDED(wfh.addTrusted(schedd_image_path)) ) { dprintf(D_FULLDEBUG, "WinFirewall: unable to add %s to the " "windows firewall exception list.\n", schedd_image_path); } // put in shadow if ( shadow_image_path && !SUCCEEDED(wfh.addTrusted(shadow_image_path)) ) { dprintf(D_FULLDEBUG, "WinFirewall: unable to add %s to the " "windows firewall exception list.\n", shadow_image_path); } // put in gridmanager if ( gridmanager_image_path && !SUCCEEDED(wfh.addTrusted(gridmanager_image_path)) ) { dprintf(D_FULLDEBUG, "WinFirewall: unable to add %s to the " "windows firewall exception list.\n", gridmanager_image_path); } // put in condor gahp if ( gahp_image_path && !SUCCEEDED(wfh.addTrusted(gahp_image_path)) ) { dprintf(D_FULLDEBUG, "WinFirewall: unable to add %s to the " "windows firewall exception list.\n", gahp_image_path); } // put in condor worker gahp if ( gahp_worker_image_path && !SUCCEEDED(wfh.addTrusted(gahp_worker_image_path)) ) { dprintf(D_FULLDEBUG, "WinFirewall: unable to add %s to the " "windows firewall exception list.\n", gahp_worker_image_path); } } // Insert daemons needed on a execute node. // Note we include the starter and friends seperately, since the // starter could run on either execute or submit nodes (think // local universe jobs). if ( (daemons.FindDaemon("STARTD") != NULL) && startd_image_path ) { if ( !SUCCEEDED(wfh.addTrusted(startd_image_path)) ) { dprintf(D_FULLDEBUG, "WinFirewall: unable to add %s to the " "windows firewall exception list.\n", startd_image_path); } if ( !SUCCEEDED(wfh.addTrusted(kbdd_image_path)) ) { dprintf(D_FULLDEBUG, "WinFirewall: unable to add %s to the " "windows firewall exception list.\n", kbdd_image_path); } } if ( (daemons.FindDaemon("QUILL") != NULL) && quill_image_path ) { if ( !SUCCEEDED(wfh.addTrusted(quill_image_path)) ) { dprintf(D_FULLDEBUG, "WinFirewall: unable to add %s to the " "windows firewall exception list.\n", quill_image_path); } } if ( (daemons.FindDaemon("DBMSD") != NULL) && dbmsd_image_path ) { if ( !SUCCEEDED(wfh.addTrusted(dbmsd_image_path)) ) { dprintf(D_FULLDEBUG, "WinFirewall: unable to add %s to the " "windows firewall exception list.\n", dbmsd_image_path); } } if ( starter_image_path ) { if ( !SUCCEEDED(wfh.addTrusted(starter_image_path)) ) { dprintf(D_FULLDEBUG, "WinFirewall: unable to add %s to the " "windows firewall exception list.\n", starter_image_path); } } if ( (daemons.FindDaemon("CREDD") != NULL) && credd_image_path ) { if ( !SUCCEEDED(wfh.addTrusted(credd_image_path)) ) { dprintf(D_FULLDEBUG, "WinFirewall: unable to add %s to the " "windows firewall exception list.\n", credd_image_path); } } if ( (daemons.FindDaemon("HDFS") != NULL) && hdfs_image_path ) { if ( !SUCCEEDED(wfh.addTrusted(hdfs_image_path)) ) { dprintf(D_FULLDEBUG, "WinFirewall: unable to add %s to the " "windows firewall exception list.\n", hdfs_image_path); } } if ( vmgahp_image_path ) { if ( !SUCCEEDED(wfh.addTrusted(vmgahp_image_path)) ) { dprintf(D_FULLDEBUG, "WinFirewall: unable to add %s to the " "windows firewall exception list.\n", vmgahp_image_path); } } if ( dagman_image_path ) { if ( !SUCCEEDED(wfh.addTrusted (dagman_image_path)) ) { dprintf(D_FULLDEBUG, "WinFirewall: unable to add %s to " "the windows firewall exception list.\n", dagman_image_path); } } if ( master_image_path ) { free(master_image_path); } if ( schedd_image_path ) { free(schedd_image_path); } if ( startd_image_path ) { free(startd_image_path); } if ( quill_image_path ) { free(quill_image_path); } if ( dbmsd_image_path ) { free(dbmsd_image_path); } if ( dagman_image_path ) { free(dagman_image_path); } if ( negotiator_image_path ) { free(negotiator_image_path); } if ( collector_image_path ) { free(collector_image_path); } if ( shadow_image_path ) { free(shadow_image_path); } if ( gridmanager_image_path ) { free(gridmanager_image_path); } if ( gahp_image_path ) { free(gahp_image_path); } if ( credd_image_path ) { free(credd_image_path); } if ( vmgahp_image_path ) { free(vmgahp_image_path); } if ( kbdd_image_path ) { free(kbdd_image_path); } #endif }
int main(int o_argc, const string const* o_argv) { string _path = getExecPath(*o_argv); key_t _key = ftok(_path, 'x'); asserts(_key, "ftok"); free(_path); _path = NULL; union semun _arg ; struct sembuf _buf ; int _shmid; MyData _data ; size_t _off ; /* Nowaday, memory is so cheap that I just do not care about the unused memory. * If is it too waste, then just compile with DYN_SEG_SIZE switch. **/ #ifndef DYN_SEG_SIZE const off_t SEG_SIZE = sizeof(mydata_t); #endif /* DYN_SEG_SIZE */ _buf.sem_num = 0; _buf.sem_flg = 0; /* Try to create a set of semaphores. */ int _semid = semget(_key, 1, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR); if(_semid == -1) { const int MAX_TRIES = 6; /* If semget failed, and the set does not exist then exit */ if(errno != EEXIST) asserts(_semid, "semget"); _semid = semget(_key, 1, S_IRUSR | S_IWUSR); asserts(_semid); struct semid_ds _ds; _arg.buf = &_ds; for(size_t i = 0; i < MAX_TRIES; i++) { asserts( semctl(_semid, 0, IPC_STAT, _arg) ); if(_ds.sem_otime != 0) break; sleep(5); } if(_ds.sem_otime == 0) fatal ( "The set of semaphores already exists, but it is not initialized.\n" "This is a permanent error, and I have given up." ) ; } /* init semaphore */ else { /* Note: * Some systems, like Linux, implicitly initializes a set of semaphores by value 0, * but unfortunately some does not. For that reason, this operation is necessary to ensure * a portability. **/ _arg.val = 0; asserts( semctl(_semid, 0, SETVAL, _arg) ); /* post semaphore */ _buf.sem_op = 1; asserts( semop(_semid, &_buf, 1) ); } /* lock the semaphore */ _buf.sem_op = -1; asserts( semop(_semid, &_buf, 1) ); /* Critical section: */ /* there is no arguments so print shared memory object content */ if(o_argc == 1) { /* obtain the descriptor of shared memory object */ asserts( _shmid = shmget(_key, 0, S_IRUSR | S_IWUSR | SHM_RDONLY) ); /* map shared memory object into virtual address space */ assertv(_data = shmat(_shmid, NULL, 0), cast(void*)-1); /* read from shared memory object */ _off = 0; for(size_t i = 0; i < _data->len; i++) { print(_data->vals + _off); print(" "); _off += strlen(_data->vals + _off) + 1; } println(""); } /* write arguments in the reveres order into shared memory object */ else { #if (defined ALLOW_CLEANUP || defined DYN_SEG_SIZE) struct shmid_ds _shmds; #endif /* ALLOW_CLEANUP || DYN_SEG_SIZE */ #ifdef ALLOW_CLEANUP union semun _semun; /* if shared memory object already exist obtain its id and destroy, otherwise do nothing */ if( o_argc == 2 && !strcmp(o_argv[1], "cleanup") ) { _shmid = shmget(_key, 0, S_IRUSR | S_IWUSR); if(_shmid == -1) { if(errno != ENOENT) asserts(_shmid); } else asserts( shmctl(_shmid, IPC_RMID, &_shmds) ); /* destroy the semaphore before exit */ asserts( semctl(_semid, 0, IPC_RMID, _semun) ); exit(EXIT_SUCCESS); } #endif /* ALLOW_CLEANUP */ /* use existing shared memory object or create the new one */ #ifdef DYN_SEG_SIZE off_t _segSz = sizeof(size_t); for(size_t i = 1; i < o_argc; i++) { _segSz += strlen(o_argv[i]) + 1; } /* Try to create a new shared memory object. * If such object already exits the destoy it before. **/ _shmid = shmget(_key, _segSz, S_IRUSR | S_IWUSR | IPC_CREAT | IPC_EXCL); if(_shmid == -1) { if(errno == EEXIST) { asserts( _shmid = shmget(_key, 0, S_IRUSR | S_IWUSR) ); asserts( shmctl(_shmid, IPC_RMID, &_shmds) ); asserts( _shmid = shmget(_key, _segSz, S_IRUSR | S_IWUSR | IPC_CREAT) ); } } #else asserts( _shmid = shmget(_key, SEG_SIZE, S_IRUSR | S_IWUSR | IPC_CREAT) ); #endif /* DYN_SEG_SIZE */ /* map shared memory object into virtual address space */ assertv(_data = shmat(_shmid, NULL, 0), cast(void*)-1); /* write into the shared memory object */ _data->len = o_argc - 1; _off = 0; for(size_t i = o_argc - 1; i > 0; i--) { /* it is safe to use strcpy, because we got enought memory */ strcpy(_data->vals + _off, o_argv[i]); _off += strlen(o_argv[i]) + 1; } } /* unmap shared memory object from virtual address space */ assertz( shmdt(_data) ); _data = NULL; /* unlock the semaphore */ _buf.sem_op = 1; asserts( semop(_semid, &_buf, 1) ); exit(EXIT_SUCCESS); }