/* Send a signal to the slave */ static int pty_signal(struct tty_struct *tty, int sig) { unsigned long flags; struct pid *pgrp; if (sig != SIGINT && sig != SIGQUIT && sig != SIGTSTP) return -EINVAL; if (tty->link) { spin_lock_irqsave(&tty->link->ctrl_lock, flags); pgrp = get_pid(tty->link->pgrp); spin_unlock_irqrestore(&tty->link->ctrl_lock, flags); kill_pgrp(pgrp, sig, 1); put_pid(pgrp); } return 0; }
static GValueArray * getpid_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GValueArray *args, GError **error) { GValueArray *return_vals; gint32 pid = 0; pid = get_pid (); return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL); g_value_set_int (&return_vals->values[1], pid); return return_vals; }
static void row(void* _proc, void* _table) { struct tabl* table; struct ps_proc* proc; struct m_list values; table = _table; proc = _proc; m_list_init(&values); m_list_append(&values, M_LIST_COPY_SHALLOW, get_pid(proc), 1); m_list_append(&values, M_LIST_COPY_SHALLOW, get_command(proc), 1); m_list_append(&values, M_LIST_COPY_SHALLOW, get_uid(proc), 1); m_list_append(&values, M_LIST_COPY_SHALLOW, get_ruid(proc), 1); m_list_append(&values, M_LIST_COPY_SHALLOW, get_svuid(proc), 1); tabl_add_row(table, &values); }
static void pppox_PX_PROTO_OL2TP_PPPoL2TP(struct sockaddr **addr, socklen_t *addrlen) { struct sockaddr_pppol2tp *pppol2tp; pppol2tp = zmalloc(sizeof(struct sockaddr_pppol2tp)); pppol2tp->sa_family = PF_PPPOX; pppol2tp->sa_protocol = rnd() % 3; pppol2tp->pppol2tp.pid = get_pid(); pppol2tp->pppol2tp.fd = get_random_fd(); pppol2tp->pppol2tp.addr.sin_addr.s_addr = random_ipv4_address(); pppol2tp->pppol2tp.s_tunnel = rnd(); pppol2tp->pppol2tp.s_session = rnd(); pppol2tp->pppol2tp.d_tunnel = rnd(); pppol2tp->pppol2tp.d_session = rnd(); *addr = (struct sockaddr *) pppol2tp; *addrlen = sizeof(struct sockaddr_pppol2tp); }
void save() { save_settings(&settings,"/setting"); get_pid(); rt_kprintf("pitch: %d %d %d.\n", settings.pitch_min, settings.pitch_mid, settings.pitch_max); rt_kprintf("roll: %d %d %d.\n", settings.roll_min, settings.roll_mid, settings.roll_max); rt_kprintf("yaw: %d %d %d.\n", settings.yaw_min, settings.yaw_mid, settings.yaw_max); rt_kprintf("throttle: %d %d.\n", settings.th_min, settings.th_max); }
pid_t get_starter_pid( const char *my_name) { char buf[1024]; FILE *fp; char cmd[ 1024]; pid_t answer = 0; #if defined(AIX32) || defined(HPUX) // really SysV sprintf( cmd, "ps -ef | egrep %s", PROG_NAME ); #else sprintf( cmd, "ps -ax | egrep %s", PROG_NAME ); #endif if( (fp=popen(cmd,"r")) == NULL ) { fprintf( stderr, "Can't execute \"%s\"\n", cmd ); exit( 1 ); } while( fgets(buf,sizeof(buf),fp) ) { if( contains(buf,"egrep") ) { continue; } if( contains(buf,my_name) ) { continue; } if( contains(buf,PROG_NAME) ) { if( answer ) { fprintf( stderr, "Multiple processes named \"%s\" exist\n", PROG_NAME ); exit( 1 ); } answer = get_pid(buf); } } (void)pclose( fp ); if( answer ) { printf( "Process \"%s\" PID is %d\n", PROG_NAME, answer ); return answer; } else { printf( "Can't find \"%s\"\n", PROG_NAME ); return 0; } }
connection* endpoint::get_data_connection(endpoint* ep) const { if (NULL == ep) { return NULL; } if (this == ep) { return NULL; } bool share_pid = false, share_host = false; if (ep->get_hostname() == get_hostname()) { share_host = true; if (ep->get_pid() == get_pid()) { share_pid = true; } } // 按性能邮件及排序mem>shm>fd if (false == ep->flags_.test(flag_t::CONNECTION_SORTED)) { ep->data_conn_.sort(sort_connection_cmp_fn); ep->flags_.set(flag_t::CONNECTION_SORTED, true); } for (std::list<connection::ptr_t>::iterator iter = ep->data_conn_.begin(); iter != ep->data_conn_.end(); ++iter) { if (connection::state_t::CONNECTED != (*iter)->get_status()) { continue; } if (share_pid && (*iter)->check_flag(connection::flag_t::ACCESS_SHARE_ADDR)) { return (*iter).get(); } if (share_host && (*iter)->check_flag(connection::flag_t::ACCESS_SHARE_HOST)) { return (*iter).get(); } if (!(*iter)->check_flag(connection::flag_t::ACCESS_SHARE_HOST)) { return (*iter).get(); } } return get_ctrl_connection(ep); }
// hunt down and kill processes that have files open on the given mount point void KillProcessesWithOpenFiles(const char* mountPoint, boolean sigkill, int *excluded, int num_excluded) { DIR* dir; struct dirent* de; LOG_ERROR("KillProcessesWithOpenFiles %s\n", mountPoint); dir = opendir("/proc"); if (!dir) return; while ((de = readdir(dir)) != 0) { boolean killed = false; // does the name look like a process ID? int pid = get_pid(de->d_name); if (pid == -1) continue; if (CheckFileDescriptorSymLinks(pid, mountPoint) // check for open files || CheckFileMaps(pid, mountPoint) // check for mmap() || CheckSymLink(pid, mountPoint, "cwd", "working directory") // check working directory || CheckSymLink(pid, mountPoint, "root", "chroot") // check for chroot() || CheckSymLink(pid, mountPoint, "exe", "executable path") // check executable path ) { int i; boolean hit = false; for (i = 0; i < num_excluded; i++) { if (pid == excluded[i]) { LOG_ERROR("I just need a little more TIME captain!\n"); hit = true; break; } } if (!hit) { LOG_ERROR("Killing process %d\n", pid); kill(pid, (sigkill ? SIGKILL : SIGTERM)); } } } closedir(dir); }
int uu_lock_txfr(const char *ttyname, pid_t pid) { int fd, err; char lckname[sizeof(_PATH_UUCPLOCK) + MAXNAMLEN]; snprintf(lckname, sizeof(lckname), _PATH_UUCPLOCK LOCKFMT, ttyname); if ((fd = open(lckname, O_RDWR)) < 0) return UU_LOCK_OWNER_ERR; if (get_pid(fd, &err) != getpid()) return UU_LOCK_OWNER_ERR; lseek(fd, 0, SEEK_SET); if (put_pid(fd, pid)) return UU_LOCK_WRITE_ERR; close(fd); return UU_LOCK_OK; }
void write_info_file(void) { char info_file[PATH_MAX]; char tmp_file[PATH_MAX]; (void)snprintf(info_file, sizeof(info_file), "%s/vifminfo", cfg.config_dir); (void)snprintf(tmp_file, sizeof(tmp_file), "%s_%u", info_file, get_pid()); if(os_access(info_file, R_OK) != 0 || copy_file(info_file, tmp_file) == 0) { update_info_file(tmp_file); if(rename_file(tmp_file, info_file) != 0) { LOG_ERROR_MSG("Can't replace vifminfo file with its temporary copy"); (void)remove(tmp_file); } } }
static void pppox_PX_PROTO_OL2TP_PPPoL2TPv3(struct sockaddr **addr, socklen_t *addrlen) { #ifdef USE_PPPOL2TPV3 struct sockaddr_pppol2tpv3 *pppol2tpv3; pppol2tpv3 = zmalloc(sizeof(struct sockaddr_pppol2tpv3)); pppol2tpv3->sa_family = PF_PPPOX; pppol2tpv3->sa_protocol = rnd() % 3; pppol2tpv3->pppol2tp.pid = get_pid(); pppol2tpv3->pppol2tp.fd = get_random_fd(); pppol2tpv3->pppol2tp.addr.sin_addr.s_addr = random_ipv4_address(); pppol2tpv3->pppol2tp.s_tunnel = rnd(); pppol2tpv3->pppol2tp.s_session = rnd(); pppol2tpv3->pppol2tp.d_tunnel = rnd(); pppol2tpv3->pppol2tp.d_session = rnd(); *addr = (struct sockaddr *) pppol2tpv3; *addrlen = sizeof(struct sockaddr_pppol2tpv3); #endif }
int uu_lock_txfr(const char *tty_name, pid_t pid) { int fd, err; char lckname[PATH_MAX]; snprintf(lckname, sizeof(lckname), _PATH_UUCPLOCK LOCKFMT, tty_name); if ((fd = open(lckname, O_RDWR)) < 0) return UU_LOCK_OWNER_ERR; if (get_pid(fd, &err) != getpid()) err = UU_LOCK_OWNER_ERR; else { lseek(fd, 0, SEEK_SET); err = put_pid(fd, pid) ? 0 : UU_LOCK_WRITE_ERR; } close(fd); return err; }
Term Process::spawn(MFArity& mfa, Term* args) { // Check that we aren't on any scheduler yet G_ASSERT(false == pid_.is_pid()); initial_call_ = mfa; // Set regs to M,F,A and jump to apply_mfargs_ ctx_.arg_regs_[0] = mfa.mod; ctx_.arg_regs_[1] = mfa.fun; ctx_.arg_regs_[2] = term::build_list(get_heap(), args, args + mfa.arity); ctx_.live = 0; // Precondition: Registers should be set to execute apply call ctx_.set_cp(vm_.premade_instr(PremadeIndex::Normal_exit_)); ctx_.set_ip(vm_.premade_instr(PremadeIndex::Apply_mfargs_)); Std::fmt("Process::jump_to_mfa -> " FMT_0xHEX "\n", (Word)ctx_.ip()); vm_.scheduler().add_new_runnable(this); return get_pid(); }
/* Register a client, steal its border, grap events, etc */ void client_register(struct WM_t *W, Window xwindow_id) { struct wmclient *C = malloc(sizeof(*C)); XFetchName(W->XDisplay, xwindow_id, &(C->name)); if (!(C->name)) C->name = strdup("<notitle>"); msg("Registering \'%s\':\n", C->name); C->win = xwindow_id; decide_new_window_size_pos(W, C); /* Unless it's a window found at startup, move it * to the current head/screen */ if (!registering_existing_windows) { C->x += curr_head_x(W); C->y += curr_head_y(W); } C->fullscreen = 0; XMapWindow(W->XDisplay, C->win); set_size_pos_border(W, C); client_select_events(W, C); get_pid(W, C); W->clients[W->nclients++] = C; client_focus(W, C); XFlush(W->XDisplay); print_clients(W); }
int ceph_flock(struct file *file, int cmd, struct file_lock *fl) { u8 lock_cmd; int err; u8 wait = 1; fl->fl_nspid = get_pid(task_tgid(current)); dout("ceph_flock, fl_pid:%d", fl->fl_pid); /* set wait bit, then clear it out of cmd*/ if (cmd & LOCK_NB) wait = 0; cmd = cmd & (LOCK_SH | LOCK_EX | LOCK_UN); /* set command sequence that Ceph wants to see: shared lock, exclusive lock, or unlock */ if (LOCK_SH == cmd) lock_cmd = CEPH_LOCK_SHARED; else if (LOCK_EX == cmd) lock_cmd = CEPH_LOCK_EXCL; else lock_cmd = CEPH_LOCK_UNLOCK; err = ceph_lock_message(CEPH_LOCK_FLOCK, CEPH_MDS_OP_SETFILELOCK, file, lock_cmd, wait, fl); if (!err) { err = flock_lock_file_wait(file, fl); if (err) { ceph_lock_message(CEPH_LOCK_FLOCK, CEPH_MDS_OP_SETFILELOCK, file, CEPH_LOCK_UNLOCK, 0, fl); dout("got %d on flock_lock_file_wait, undid lock", err); } } else if (err == -ERESTARTSYS) { dout("undoing lock\n"); ceph_lock_message(CEPH_LOCK_FLOCK, CEPH_MDS_OP_SETFILELOCK, file, CEPH_LOCK_UNLOCK, 0, fl); } return err; }
static foreign_t process_wait(term_t pid, term_t code, term_t options) { pid_t p; wait_options opts; term_t tail = PL_copy_term_ref(options); term_t head = PL_new_term_ref(); term_t arg = PL_new_term_ref(); if ( !get_pid(pid, &p) ) return FALSE; memset(&opts, 0, sizeof(opts)); while(PL_get_list(tail, head, tail)) { atom_t name; int arity; if ( !PL_get_name_arity(head, &name, &arity) || arity != 1 ) return type_error(head, "option"); _PL_get_arg(1, head, arg); if ( name == ATOM_timeout ) { atom_t a; if ( !(PL_get_atom(arg, &a) && a == ATOM_infinite) ) { if ( !PL_get_float(arg, &opts.timeout) ) return type_error(arg, "timeout"); opts.has_timeout = TRUE; } } else if ( name == ATOM_release ) { if ( !PL_get_bool(arg, &opts.release) ) return type_error(arg, "boolean"); if ( opts.release == FALSE ) return domain_error(arg, "true"); } else return domain_error(head, "process_wait_option"); } if ( !PL_get_nil(tail) ) return type_error(tail, "list"); return wait_for_pid(p, code, &opts); }
static foreign_t process_kill(term_t pid, term_t signal) { int p; if ( !get_pid(pid, &p) ) return FALSE; { #ifdef __WINDOWS__ HANDLE h; if ( !(h=find_process_from_pid(p, "process_kill")) ) return FALSE; if ( TerminateProcess(h, 255) ) return TRUE; return win_error("TerminateProcess"); #else /*__WINDOWS__*/ int sig; if ( !PL_get_signum_ex(signal, &sig) ) return FALSE; if ( kill(p, sig) == 0 ) return TRUE; switch(errno) { case EPERM: return pl_error("process_kill", 2, NULL, ERR_PERMISSION, pid, "kill", "process"); case ESRCH: return pl_error("process_kill", 2, NULL, ERR_EXISTENCE, "process", pid); default: return pl_error("process_kill", 2, "kill", ERR_ERRNO, errno, "kill", "process", pid); } #endif /*__WINDOWS__*/ } }
bool inject_library(char *szProcess, char *szLibPath) { char szDLLPath[256]; DWORD dwBytesWritten, dwThreadID; HANDLE hProcess, hThread; LPTHREAD_START_ROUTINE lpModule; LPVOID lpBuffer; sprintf(szDLLPath, szLibPath); hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, get_pid(szProcess)); if (hProcess == NULL) return FALSE; lpModule = (LPTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandle("KERNEL32.DLL"), "LoadLibraryA"); lpBuffer = xVirtualAllocEx(hProcess, NULL, sizeof(szDLLPath), MEM_COMMIT, PAGE_READWRITE); if (!lpBuffer) return FALSE; if (!WriteProcessMemory(hProcess, lpBuffer, szDLLPath, sizeof(szDLLPath), &dwBytesWritten)) return FALSE; hThread = xCreateRemoteThread(hProcess, NULL, 0, lpModule, lpBuffer, 0, &dwThreadID); if (!hThread) return FALSE; WaitForSingleObject(hThread, 1000); xVirtualFreeEx(hProcess, lpBuffer, 0, MEM_RELEASE); CloseHandle(hThread); CloseHandle(hProcess); return TRUE; }
int main(){ int i, alert; //for (i=0; i<TOT_ITER; i++) // printf("simplon: i %d\n", i); printf("simplon: comienza\n"); i = get_pid(); printf("PID del simplon: %d\n", i); printf("Proceso muy largo en marcha\n"); alert = 0; for( i = 0; i < TOT_ITER; i++){ if(++alert == 10000000){ alert = 0; printf("Simplon procesando\n"); } } printf("simplon: termina\n"); return 0; }
static VALUE ptrace_setregs(VALUE self, VALUE data) { struct user_regs_struct urs; void *data_ptr = (void *)&urs; pid_t pid = get_pid(self); long ret; #define SET(reg) \ { \ VALUE v = rb_struct_getmember(data, rb_intern(#reg)); \ urs.reg = NUM2ULONG(v); \ } SET(rax); SET(rbx); SET(rcx); SET(rdi); SET(rsi); SET(rbp); SET(rsp); SET(r8); SET(r9); SET(r10); SET(r11); SET(r12); SET(r13); SET(r14); SET(r15); SET(rip); SET(cs); SET(fs); SET(gs) #undef SET CALL_PTRACE(ret, PT_SETREGS, pid, 0, data_ptr); return Qnil; }
static struct dentry *proc_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *data) { int err; struct super_block *sb; struct pid_namespace *ns; struct proc_inode *ei; if (flags & MS_KERNMOUNT) ns = (struct pid_namespace *)data; else ns = current->nsproxy->pid_ns; sb = sget(fs_type, proc_test_super, proc_set_super, ns); if (IS_ERR(sb)) return ERR_CAST(sb); if (!sb->s_root) { sb->s_flags = flags; err = proc_fill_super(sb); if (err) { deactivate_locked_super(sb); return ERR_PTR(err); } sb->s_flags |= MS_ACTIVE; } ei = PROC_I(sb->s_root->d_inode); if (!ei->pid) { rcu_read_lock(); ei->pid = get_pid(find_pid_ns(1, ns)); rcu_read_unlock(); } return dget(sb->s_root); }
void read_uhunt() { init_tree(); for (size_t i = 0; i != user.size(); ++i){ ifstream in("uhunt\\ana_" + user[i].ID + ".txt"); if (!in) { cerr << user[i].name << ":打开文件失败!" << endl; continue; } string line; vector<int> road; road.resize(4); while (getline(in, line)){ if (line.find("AOAPC") != string::npos) ++road[1], road[2] = -1, road[3] = 0; else if (line.find("Chapter") != string::npos) road[2] = get_cpt(line), road[3] = 0; else if (count(line.begin(), line.end(), '-') == 6 && line.find("Examples") == string::npos && line.find("Exercises") == string::npos && line.find("Extra") == string::npos) ++road[3]; else if (line.find("accept") != string::npos) { vector<int> pid = get_pid(line); add_tree(get_tag(road), user[i], pid, root); } } in.close(); printf(" %s:uhunt数据读取完毕\n", user[i].name.c_str()); } cout << "所有同学数据读取完毕!" << endl; }
int main(int argc, char **argv) { pid_t pid; int i = 0; int j = 0; int regions = 1; int state = 0; char *mem; mach_vm_address_t base; mach_vm_address_t past = 0; mach_vm_address_t addr; vm_region_t **vm_region_list; mach_port_t task; if (geteuid() != 0) { fprintf(stderr, "[-] are you root?\n"); exit(1); } set_signal_handler(); printf("[+] Looking for Self Service\n"); pid = get_pid(); if (!pid) { fprintf(stderr, "[-] Not found. exiting\n"); exit(2); } printf("[+] Self Service found: %d\n", pid); task = attach(pid); printf("[+] ATTACHED TO PROCESS %d WITH TASK %d\n", pid, task); base = get_base_address(task); addr = base; while (regions) { vm_region_list = get_memory_map(task, addr, ®ions); printf("[+] Found %d regions\n", regions); for (i = 0; i < regions; ++i) { if (past > vm_region_list[i]->address_start) { printf("\n[!] Looped around somehow, exiting gracefully\n\n"); exit(256); } printf("[+] Region %d:%d;\n[+]\tType:\t%s\n[+]\tBase Address:\t%016llx\n[+]\tEnd Address:\t%016llx\n[+]\tSize:\t0x%llx (%lld bytes)\n[+]\tPermissions:\t%s \n", j, i, user_tag_to_string(vm_region_list[i]->region_type), vm_region_list[i]->address_start, vm_region_list[i]->address_start + vm_region_list[i]->size, vm_region_list[i]->size, vm_region_list[i]->size, get_protection(vm_region_list[i]->protection)); if ((vm_region_list[i]->protection) & 1) { printf("[+]\tMaking Local Copy of Memory\n"); mem = (char *)read_memory_allocate(task, vm_region_list[i]->address_start, vm_region_list[i]->size); } else { printf("[+]\t\tChanging memory permissions\n"); state = vm_region_list[i]->protection; change_page_protection(task, vm_region_list[i]->address_start, VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE); printf("[+]\t\tMaking Local Copy of Memory\n"); mem = (char *)read_memory_allocate(task, vm_region_list[i]->address_start, vm_region_list[i]->size); printf("[+]\t\tChanging memory permissions back\n"); change_page_protection(task, vm_region_list[i]->address_start, state); } printf("[+]\tSearching local copy for username and password string\n"); checkit(mem, vm_region_list[i]->size); free(mem); } printf("[+] Completed searching %d regions\n", i); past = addr; addr += base; if (setjmp(buf)) { fprintf(stderr, "\n[!] Segfault at 0x%llX\n\n", addr); past = addr; addr = vm_region_list[i]->address_start + vm_region_list[i]->size; } j++; } printf("\n[+] Completed searching through allocated memory\n"); return 0; }
int uu_lock(const char *ttyname) { int fd, tmpfd, i; pid_t pid, pid_old; char lckname[sizeof(_PATH_UUCPLOCK) + MAXNAMLEN], lcktmpname[sizeof(_PATH_UUCPLOCK) + MAXNAMLEN]; int err, uuerr; pid = getpid(); (void)snprintf(lcktmpname, sizeof(lcktmpname), _PATH_UUCPLOCK LOCKTMP, pid); (void)snprintf(lckname, sizeof(lckname), _PATH_UUCPLOCK LOCKFMT, ttyname); if ((tmpfd = creat(lcktmpname, 0664)) < 0) GORET(0, UU_LOCK_CREAT_ERR); for (i = 0; i < MAXTRIES; i++) { if (link (lcktmpname, lckname) < 0) { if (errno != EEXIST) GORET(1, UU_LOCK_LINK_ERR); /* * file is already locked * check to see if the process holding the lock * still exists */ if ((fd = open(lckname, O_RDONLY)) < 0) GORET(1, UU_LOCK_OPEN_ERR); if ((pid_old = get_pid (fd, &err)) == -1) GORET(2, UU_LOCK_READ_ERR); close(fd); if (kill(pid_old, 0) == 0 || errno != ESRCH) GORET(1, UU_LOCK_INUSE); /* * The process that locked the file isn't running, so * we'll lock it ourselves */ (void)unlink(lckname); } else { if (!put_pid (tmpfd, pid)) GORET(3, UU_LOCK_WRITE_ERR); break; } } GORET(1, (i >= MAXTRIES) ? UU_LOCK_TRY_ERR : UU_LOCK_OK); ret3: (void)unlink(lckname); goto ret1; ret2: (void)close(fd); ret1: (void)close(tmpfd); (void)unlink(lcktmpname); ret0: errno = err; return uuerr; }
/*============================================================================= * READ_GADGET *=============================================================================*/ void read_gadget(FILE *icfile, float **out_x,float **out_y,float **out_z) { int i; long no_part; int massflag; char DATA[MAXSTRING]; float fdummy[3]; double ddummy[3]; double x_fac; long pid; /*================= read in GADGET IO header =================*/ if(FORMAT == 2) { GADGET_SKIP; fread(DATA,sizeof(char),blklen,icfile); DATA[4] = '\0'; fprintf(stderr,"reading... %s\n",DATA); GADGET_SKIP; } GADGET_SKIP; ReadInt(icfile,&(gadget.header.np[0]),SWAPBYTES); ReadInt(icfile,&(gadget.header.np[1]),SWAPBYTES); ReadInt(icfile,&(gadget.header.np[2]),SWAPBYTES); ReadInt(icfile,&(gadget.header.np[3]),SWAPBYTES); /* number of particles in current file */ ReadInt(icfile,&(gadget.header.np[4]),SWAPBYTES); ReadInt(icfile,&(gadget.header.np[5]),SWAPBYTES); ReadDouble(icfile,&(gadget.header.massarr[0]),SWAPBYTES); ReadDouble(icfile,&(gadget.header.massarr[1]),SWAPBYTES); ReadDouble(icfile,&(gadget.header.massarr[2]),SWAPBYTES); ReadDouble(icfile,&(gadget.header.massarr[3]),SWAPBYTES); ReadDouble(icfile,&(gadget.header.massarr[4]),SWAPBYTES); ReadDouble(icfile,&(gadget.header.massarr[5]),SWAPBYTES); ReadDouble(icfile,&(gadget.header.expansion),SWAPBYTES); ReadDouble(icfile,&(gadget.header.redshift),SWAPBYTES); ReadInt(icfile,&(gadget.header.flagsfr),SWAPBYTES); ReadInt(icfile,&(gadget.header.flagfeedback),SWAPBYTES); ReadInt(icfile,&(gadget.header.nall[0]),SWAPBYTES); ReadInt(icfile,&(gadget.header.nall[1]),SWAPBYTES); ReadInt(icfile,&(gadget.header.nall[2]),SWAPBYTES); /* total number of particles in simulation */ ReadInt(icfile,&(gadget.header.nall[3]),SWAPBYTES); ReadInt(icfile,&(gadget.header.nall[4]),SWAPBYTES); ReadInt(icfile,&(gadget.header.nall[5]),SWAPBYTES); ReadInt(icfile,&(gadget.header.flagcooling),SWAPBYTES); ReadInt(icfile,&(gadget.header.NumFiles),SWAPBYTES); ReadDouble(icfile,&(gadget.header.BoxSize),SWAPBYTES); ReadDouble(icfile,&(gadget.header.Omega0),SWAPBYTES); ReadDouble(icfile,&(gadget.header.OmegaLambda),SWAPBYTES); ReadDouble(icfile,&(gadget.header.HubbleParam),SWAPBYTES); ReadChars(icfile,&(gadget.header.unused[0]),SIZEOFGADGETHEADER- 6*4- 6*8- 2*8- 2*4- 6*4- 2*4 - 4*8); GADGET_SKIP; /*================= read in GADGET IO header =================*/ /* keep track of no. of particles in each GADGET file */ gadget.np[0][gadget.i_gadget_file] = gadget.header.np[0]; gadget.np[1][gadget.i_gadget_file] = gadget.header.np[1]; gadget.np[2][gadget.i_gadget_file] = gadget.header.np[2]; gadget.np[3][gadget.i_gadget_file] = gadget.header.np[3]; gadget.np[4][gadget.i_gadget_file] = gadget.header.np[4]; gadget.np[5][gadget.i_gadget_file] = gadget.header.np[5]; /* conversion factors to Mpc/h, km/sec, Msun/h */ x_fac = GADGET_LUNIT; //m_fac = GADGET_MUNIT; /* count total no. of particles in current file (and set massflag) */ massflag = 0; no_part = 0; gadget.nall = 0; for(i=0;i<6;i++) { no_part += gadget.header.np[i]; gadget.nall += gadget.header.nall[i]; if(gadget.header.massarr[i] < MZERO && gadget.header.np[i] > 0) massflag=1; } #ifdef _VERB fprintf(stderr,"expansion factor: %lf\n", gadget.header.expansion); fprintf(stderr,"redshift: %lf\n", gadget.header.redshift); fprintf(stderr,"boxsize: %lf (%lf Mpc/h)\n", gadget.header.BoxSize,gadget.header.BoxSize*GADGET_LUNIT); fprintf(stderr,"omega0: %lf\n", gadget.header.Omega0); fprintf(stderr,"lambda0: %lf\n", gadget.header.OmegaLambda); fprintf(stderr,"HubbleParam: %lf\n\n", gadget.header.HubbleParam); fprintf(stderr,"gas: np[0]=%9d\t nall[0]=%9d\t massarr[0]=%g\n",gadget.header.np[0],gadget.header.nall[0],gadget.header.massarr[0]); fprintf(stderr,"halo: np[1]=%9d\t nall[1]=%9d\t massarr[1]=%g\n",gadget.header.np[1],gadget.header.nall[1],gadget.header.massarr[1]); fprintf(stderr,"disk: np[2]=%9d\t nall[2]=%9d\t massarr[2]=%g\n",gadget.header.np[2],gadget.header.nall[2],gadget.header.massarr[2]); fprintf(stderr,"bulge: np[3]=%9d\t nall[3]=%9d\t massarr[3]=%g\n",gadget.header.np[3],gadget.header.nall[3],gadget.header.massarr[3]); fprintf(stderr,"stars: np[4]=%9d\t nall[4]=%9d\t massarr[4]=%g\n",gadget.header.np[4],gadget.header.nall[4],gadget.header.massarr[4]); fprintf(stderr,"bndry: np[5]=%9d\t nall[5]=%9d\t massarr[5]=%g\n",gadget.header.np[5],gadget.header.nall[5],gadget.header.massarr[5]); fprintf(stderr,"\n-> reading %ld/%ld particles from GADGET file #%d/%d...\n\n", no_part,gadget.nall, gadget.i_gadget_file+1, gadget.no_gadget_files); #endif /* allocate particle array (only once when reading the first file, of course!) */ if(gadget.i_gadget_file == 0) { fprintf(stderr,"-> allocating %f GB of RAM for particles\n\n",(float)(gadget.nall*3*sizeof(float))/1024./1024./1024.); if(!((*out_x)=(float *) calloc(gadget.nall, sizeof(float)))) { fprintf(stderr,"\nfailed to allocate memory for GADGET data\n"); exit(1); } if(!((*out_y)=(float *) calloc(gadget.nall, sizeof(float)))) { fprintf(stderr,"\nfailed to allocate memory for GADGET data\n"); exit(1); } if(!((*out_z)=(float *) calloc(gadget.nall, sizeof(float)))) { fprintf(stderr,"\nfailed to allocate memory for GADGET data\n"); exit(1); } } /*================= read in GADGET particles =================*/ if(FORMAT == 2) { GADGET_SKIP; fread(DATA,sizeof(char),blklen,icfile); DATA[4] = '\0'; fprintf(stderr,"reading... %s",DATA); //GADGET_SKIP; GADGET_SKIP; } else { fprintf(stderr,"reading "); } GADGET_SKIP; fprintf(stderr,"(%8.2g MB) ... ",blklen/1024./1024.); for(i=0;i<no_part;i++) { /* read */ if(DGADGET) { ReadDouble(icfile,&(ddummy[0]),SWAPBYTES); ReadDouble(icfile,&(ddummy[1]),SWAPBYTES); ReadDouble(icfile,&(ddummy[2]),SWAPBYTES); } else { ReadFloat(icfile,&(fdummy[0]),SWAPBYTES); ReadFloat(icfile,&(fdummy[1]),SWAPBYTES); ReadFloat(icfile,&(fdummy[2]),SWAPBYTES); } /* get proper position in array */ pid = get_pid(i); /* storage and conversion to comoving physical units */ (*out_x)[pid] = fdummy[0] * x_fac; (*out_y)[pid] = fdummy[1] * x_fac; (*out_z)[pid] = fdummy[2] * x_fac; } fprintf(stderr,"Pos[X]=%12.6g Pos[Y]=%12.6g Pos[Z]=%12.6g ... ",(*out_x)[no_part-1],(*out_y)[no_part-1],(*out_z)[no_part-1]); GADGET_SKIP; fprintf(stderr,"(%8.2g MB) done.\n",blklen/1024./1024.); /*================= read in GADGET particles =================*/ /* massflag == 1 indicates that massarr[i] = 0 which shouldnt be the case for HALOGEN */ if(massflag==1) { fprintf(stderr,"ERROR: HALOGEN does not expect to encounter variable masses\n If needed, please, contact us to implement it\n"); exit(0); } }
static int user_busy_processes (const char *name, uid_t uid) { DIR *proc; struct dirent *ent; char *tmp_d_name; pid_t pid; DIR *task_dir; /* 22: /proc/xxxxxxxxxx/task + \0 */ char task_path[22]; char root_path[22]; struct stat sbroot; struct stat sbroot_process; #ifdef ENABLE_SUBIDS sub_uid_open (O_RDONLY); #endif /* ENABLE_SUBIDS */ proc = opendir ("/proc"); if (proc == NULL) { perror ("opendir /proc"); return 0; } if (stat ("/", &sbroot) != 0) { perror ("stat (\"/\")"); (void) closedir (proc); #ifdef ENABLE_SUBIDS sub_uid_close(); #endif return 0; } while ((ent = readdir (proc)) != NULL) { tmp_d_name = ent->d_name; /* * Ingo Molnar's patch introducing NPTL for 2.4 hides * threads in the /proc directory by prepending a period. * This patch is applied by default in some RedHat * kernels. */ if ( (strcmp (tmp_d_name, ".") == 0) || (strcmp (tmp_d_name, "..") == 0)) { continue; } if (*tmp_d_name == '.') { tmp_d_name++; } /* Check if this is a valid PID */ if (get_pid (tmp_d_name, &pid) == 0) { continue; } /* Check if the process is in our chroot */ snprintf (root_path, 22, "/proc/%lu/root", (unsigned long) pid); root_path[21] = '\0'; if (stat (root_path, &sbroot_process) != 0) { continue; } if ( (sbroot.st_dev != sbroot_process.st_dev) || (sbroot.st_ino != sbroot_process.st_ino)) { continue; } if (check_status (name, tmp_d_name, uid) != 0) { (void) closedir (proc); #ifdef ENABLE_SUBIDS sub_uid_close(); #endif fprintf (stderr, _("%s: user %s is currently used by process %d\n"), Prog, name, pid); return 1; } snprintf (task_path, 22, "/proc/%lu/task", (unsigned long) pid); task_path[21] = '\0'; task_dir = opendir (task_path); if (task_dir != NULL) { while ((ent = readdir (task_dir)) != NULL) { pid_t tid; if (get_pid (ent->d_name, &tid) == 0) { continue; } if (tid == pid) { continue; } if (check_status (name, task_path+6, uid) != 0) { (void) closedir (proc); #ifdef ENABLE_SUBIDS sub_uid_close(); #endif fprintf (stderr, _("%s: user %s is currently used by process %d\n"), Prog, name, pid); return 1; } } (void) closedir (task_dir); } else { /* Ignore errors. This is just a best effort */ } } (void) closedir (proc); #ifdef ENABLE_SUBIDS sub_uid_close(); #endif /* ENABLE_SUBIDS */ return 0; }
static long afu_ioctl_start_work(struct cxl_context *ctx, struct cxl_ioctl_start_work __user *uwork) { struct cxl_ioctl_start_work work; u64 amr = 0; int rc; pr_devel("%s: pe: %i\n", __func__, ctx->pe); /* Do this outside the status_mutex to avoid a circular dependency with * the locking in cxl_mmap_fault() */ if (copy_from_user(&work, uwork, sizeof(struct cxl_ioctl_start_work))) { rc = -EFAULT; goto out; } mutex_lock(&ctx->status_mutex); if (ctx->status != OPENED) { rc = -EIO; goto out; } /* * if any of the reserved fields are set or any of the unused * flags are set it's invalid */ if (work.reserved1 || work.reserved2 || work.reserved3 || work.reserved4 || work.reserved5 || work.reserved6 || (work.flags & ~CXL_START_WORK_ALL)) { rc = -EINVAL; goto out; } if (!(work.flags & CXL_START_WORK_NUM_IRQS)) work.num_interrupts = ctx->afu->pp_irqs; else if ((work.num_interrupts < ctx->afu->pp_irqs) || (work.num_interrupts > ctx->afu->irqs_max)) { rc = -EINVAL; goto out; } if ((rc = afu_register_irqs(ctx, work.num_interrupts))) goto out; if (work.flags & CXL_START_WORK_AMR) amr = work.amr & mfspr(SPRN_UAMOR); /* * We grab the PID here and not in the file open to allow for the case * where a process (master, some daemon, etc) has opened the chardev on * behalf of another process, so the AFU's mm gets bound to the process * that performs this ioctl and not the process that opened the file. */ ctx->pid = get_pid(get_task_pid(current, PIDTYPE_PID)); trace_cxl_attach(ctx, work.work_element_descriptor, work.num_interrupts, amr); if ((rc = cxl_attach_process(ctx, false, work.work_element_descriptor, amr))) { afu_release_irqs(ctx); goto out; } ctx->status = STARTED; rc = 0; out: mutex_unlock(&ctx->status_mutex); return rc; }
SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock, struct sigevent __user *, timer_event_spec, timer_t __user *, created_timer_id) { struct k_clock *kc = clockid_to_kclock(which_clock); struct k_itimer *new_timer; int error, new_timer_id; sigevent_t event; int it_id_set = IT_ID_NOT_SET; if (!kc) return -EINVAL; if (!kc->timer_create) return -EOPNOTSUPP; new_timer = alloc_posix_timer(); if (unlikely(!new_timer)) return -EAGAIN; spin_lock_init(&new_timer->it_lock); retry: if (unlikely(!idr_pre_get(&posix_timers_id, GFP_KERNEL))) { error = -EAGAIN; goto out; } spin_lock_irq(&idr_lock); error = idr_get_new(&posix_timers_id, new_timer, &new_timer_id); spin_unlock_irq(&idr_lock); if (error) { if (error == -EAGAIN) goto retry; /* * Weird looking, but we return EAGAIN if the IDR is * full (proper POSIX return value for this) */ error = -EAGAIN; goto out; } it_id_set = IT_ID_SET; new_timer->it_id = (timer_t) new_timer_id; new_timer->it_clock = which_clock; new_timer->it_overrun = -1; if (timer_event_spec) { if (copy_from_user(&event, timer_event_spec, sizeof (event))) { error = -EFAULT; goto out; } rcu_read_lock(); new_timer->it_pid = get_pid(good_sigevent(&event)); rcu_read_unlock(); if (!new_timer->it_pid) { error = -EINVAL; goto out; } } else { event.sigev_notify = SIGEV_SIGNAL; event.sigev_signo = SIGALRM; event.sigev_value.sival_int = new_timer->it_id; new_timer->it_pid = get_pid(task_tgid(current)); } new_timer->it_sigev_notify = event.sigev_notify; new_timer->sigq->info.si_signo = event.sigev_signo; new_timer->sigq->info.si_value = event.sigev_value; new_timer->sigq->info.si_tid = new_timer->it_id; new_timer->sigq->info.si_code = SI_TIMER; if (copy_to_user(created_timer_id, &new_timer_id, sizeof (new_timer_id))) { error = -EFAULT; goto out; } error = kc->timer_create(new_timer); if (error) goto out; spin_lock_irq(¤t->sighand->siglock); new_timer->it_signal = current->signal; list_add(&new_timer->list, ¤t->signal->posix_timers); spin_unlock_irq(¤t->sighand->siglock); return 0; /* * In the case of the timer belonging to another task, after * the task is unlocked, the timer is owned by the other task * and may cease to exist at any time. Don't use or modify * new_timer after the unlock call. */ out: release_posix_timer(new_timer, it_id_set); return error; }
static unsigned long fill_arg(struct syscallrecord *rec, unsigned int argnum) { struct syscallentry *entry; unsigned int call; enum argtype argtype; call = rec->nr; entry = syscalls[call].entry; if (argnum > entry->num_args) return 0; argtype = get_argtype(entry, argnum); switch (argtype) { case ARG_UNDEFINED: if (RAND_BOOL()) return (unsigned long) rand64(); return (unsigned long) get_writable_address(page_size); case ARG_FD: if (RAND_BOOL()) { unsigned int i; /* If this is the 2nd or more ARG_FD, make it unique */ for (i = 0; i < argnum; i++) { enum argtype arg; arg = get_argtype(entry, i); if (arg == ARG_FD) return get_new_random_fd(); } } return get_random_fd(); case ARG_LEN: return (unsigned long) get_len(); case ARG_ADDRESS: return handle_arg_address(rec, argnum); case ARG_NON_NULL_ADDRESS: return (unsigned long) get_non_null_address(); case ARG_MMAP: return (unsigned long) get_map(); case ARG_PID: return (unsigned long) get_pid(); case ARG_RANGE: return handle_arg_range(entry, argnum); case ARG_OP: /* Like ARG_LIST, but just a single value. */ return handle_arg_op(entry, argnum); case ARG_LIST: return handle_arg_list(entry, argnum); case ARG_CPU: return (unsigned long) get_cpu(); case ARG_PATHNAME: return (unsigned long) generate_pathname(); case ARG_IOVEC: return handle_arg_iovec(entry, rec, argnum); case ARG_IOVECLEN: case ARG_SOCKADDRLEN: /* We already set the len in the ARG_IOVEC/ARG_SOCKADDR case * So here we just return what we had set there. */ return get_argval(rec, argnum); case ARG_SOCKADDR: return handle_arg_sockaddr(entry, rec, argnum); case ARG_MODE_T: return handle_arg_mode_t(); case ARG_SOCKETINFO: return (unsigned long) get_rand_socketinfo(); } BUG("unreachable!\n"); }
#include "rxcpp/rx.hpp" #include "rxcpp/rx-test.hpp" #include "catch.hpp" std::string get_pid(); SCENARIO("observe_on sample"){ printf("//! [observe_on sample]\n"); printf("[thread %s] Start task\n", get_pid().c_str()); auto values = rxcpp::observable<>::range(1, 3). map([](int v){ printf("[thread %s] Emit value %d\n", get_pid().c_str(), v); return v; }); values. observe_on(rxcpp::synchronize_new_thread()). as_blocking(). subscribe( [](int v){printf("[thread %s] OnNext: %d\n", get_pid().c_str(), v);}, [](){printf("[thread %s] OnCompleted\n", get_pid().c_str());}); printf("[thread %s] Finish task\n", get_pid().c_str()); printf("//! [observe_on sample]\n"); }