static int show_session(struct db_record *rec, void *private_data) { bool *parseable = (bool *)private_data; struct sessionid sessionid; if (rec->value.dsize != sizeof(sessionid)) return 0; memcpy(&sessionid, rec->value.dptr, sizeof(sessionid)); if (!process_exists(sessionid.pid)) { return 0; } if (*parseable) { d_printf("%s\\%s\\%s\\%s\\%s\n", procid_str_static(&sessionid.pid), uidtoname(sessionid.uid), gidtoname(sessionid.gid), sessionid.remote_machine, sessionid.hostname); } else { d_printf("%7s %-12s %-12s %-12s (%s)\n", procid_str_static(&sessionid.pid), uidtoname(sessionid.uid), gidtoname(sessionid.gid), sessionid.remote_machine, sessionid.hostname); } return 0; }
static void check_pids(void *arg) { int i; size_t nr; struct local_node lnodes[SD_MAX_NODES]; struct local_event *ev; shm_queue_lock(); nr = get_nodes(lnodes); for (i = 0; i < nr; i++) if (!process_exists(lnodes[i].pid)) { add_event(EVENT_LEAVE, lnodes + i, NULL, 0); /* unblock blocking event if sender has gone */ ev = shm_queue_peek_block_event(); if (lnode_eq(lnodes + i, &ev->sender)) { ev->removed = true; msync(ev, sizeof(*ev), MS_SYNC); } } shm_queue_unlock(); add_timer(arg, PROCESS_CHECK_INTERVAL); }
/* traversal fn for showing machine connections */ static int traverse_fn2(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state) { struct connections_data crec; if (dbuf.dsize != sizeof(crec)) return 0; memcpy(&crec, dbuf.dptr, sizeof(crec)); if (crec.cnum == -1 || !process_exists(crec.pid) || (crec.pid == smbd_pid)) return 0; addPid2Machine (crec.pid, crec.machine); printf("<tr><td>%d</td><td>%s</td><td>%s</td><td>%s</td>\n", (int)crec.pid, crec.machine,crec.addr, tstring(crec.start)); if (geteuid() == 0) { printf("<td><input type=submit value=\"X\" name=\"kill_%d\"></td>\n", (int)crec.pid); } printf("</tr>\n"); return 0; }
static int count_fn( TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *udp) { struct connections_data crec; struct count_stat *cs = (struct count_stat *)udp; if (dbuf.dsize != sizeof(crec)) return 0; memcpy(&crec, dbuf.dptr, sizeof(crec)); if (crec.cnum == -1) return 0; /* If the pid was not found delete the entry from connections.tdb */ if (cs->Clear && !process_exists(crec.pid) && (errno == ESRCH)) { DEBUG(2,("pid %u doesn't exist - deleting connections %d [%s]\n", (unsigned int)crec.pid, crec.cnum, crec.name)); if (tdb_delete(the_tdb, kbuf) != 0) DEBUG(0,("count_fn: tdb_delete failed with error %s\n", tdb_errorstr(tdb) )); return 0; } if (strequal(crec.name, cs->name)) cs->curr_connections++; return 0; }
static int traverse_sessionid(struct db_record *db, void *state) { struct sessionid sessionid; fstring uid_str, gid_str; if (db->value.dsize != sizeof(sessionid)) return 0; memcpy(&sessionid, db->value.dptr, sizeof(sessionid)); if (!process_exists(sessionid.pid) || !Ucrit_checkUid(sessionid.uid)) { return 0; } Ucrit_addPid( sessionid.pid ); fstr_sprintf(uid_str, "%d", sessionid.uid); fstr_sprintf(gid_str, "%d", sessionid.gid); d_printf("%-7s %-12s %-12s %-12s (%s)\n", procid_str_static(&sessionid.pid), numeric_only ? uid_str : uidtoname(sessionid.uid), numeric_only ? gid_str : gidtoname(sessionid.gid), sessionid.remote_machine, sessionid.hostname); return 0; }
// I'm assuming here process_ID is the receiver ID int send_message_jessie (int process_ID, void * MessageEnvelope) { // error check if (process_exists(process_ID) == FALSE) { return RTX_FAILURE; } int sender = pre_send_message (process_ID, MessageEnvelope); act_send_message(process_ID, sender, MessageEnvelope); return RTX_SUCCESS; }
TDB_DATA get_printer_notify_pid_list(TDB_CONTEXT *tdb, const char *printer_name, BOOL cleanlist) { TDB_DATA data; size_t i; ZERO_STRUCT(data); data = tdb_fetch_bystring( tdb, NOTIFY_PID_LIST_KEY ); if (!data.dptr) { ZERO_STRUCT(data); return data; } if (data.dsize % 8) { DEBUG(0,("get_printer_notify_pid_list: Size of record for printer %s not a multiple of 8 !\n", printer_name )); tdb_delete_bystring(tdb, NOTIFY_PID_LIST_KEY ); SAFE_FREE(data.dptr); ZERO_STRUCT(data); return data; } if (!cleanlist) return data; /* * Weed out all dead entries. */ for( i = 0; i < data.dsize; i += 8) { pid_t pid = (pid_t)IVAL(data.dptr, i); if (pid == sys_getpid()) continue; /* Entry is dead if process doesn't exist or refcount is zero. */ while ((i < data.dsize) && ((IVAL(data.dptr, i + 4) == 0) || !process_exists(pid))) { /* Refcount == zero is a logic error and should never happen. */ if (IVAL(data.dptr, i + 4) == 0) { DEBUG(0,("get_printer_notify_pid_list: Refcount == 0 for pid = %u printer %s !\n", (unsigned int)pid, printer_name )); } if (data.dsize - i > 8) memmove( &data.dptr[i], &data.dptr[i+8], data.dsize - i - 8); data.dsize -= 8; } } return data; }
/* kill off any connections chosen by the user */ static int traverse_fn1(const struct connections_key *key, const struct connections_data *crec, void *private_data) { if (crec->cnum == -1 && process_exists(crec->pid)) { char buf[30]; slprintf(buf,sizeof(buf)-1,"kill_%s", procid_str_static(&crec->pid)); if (cgi_variable(buf)) { kill_pid(crec->pid); sleep(SLEEP_TIME); } } return 0; }
static int delete_fn(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) { struct locking_data *data; share_mode_entry *shares; int i, del_count=0; pid_t mypid = sys_getpid(); BOOL check_self = *(BOOL *)state; int ret = 0; tdb_chainlock(tdb, kbuf); data = (struct locking_data *)dbuf.dptr; shares = (share_mode_entry *)(dbuf.dptr + sizeof(*data)); for (i=0;i<data->u.num_share_mode_entries;) { if (check_self && (shares[i].pid == mypid)) { DEBUG(0,("locking : delete_fn. LOGIC ERROR ! Shutting down and a record for my pid (%u) exists !\n", (unsigned int)shares[i].pid )); } else if (!process_exists(shares[i].pid)) { DEBUG(0,("locking : delete_fn. LOGIC ERROR ! Entry for pid %u and it no longer exists !\n", (unsigned int)shares[i].pid )); } else { /* Process exists, leave this record alone. */ i++; continue; } data->u.num_share_mode_entries--; memmove(&shares[i], &shares[i+1], dbuf.dsize - (sizeof(*data) + (i+1)*sizeof(*shares))); del_count++; } /* the record has shrunk a bit */ dbuf.dsize -= del_count * sizeof(*shares); /* store it back in the database */ if (data->u.num_share_mode_entries == 0) { if (tdb_delete(ttdb, kbuf) == -1) ret = -1; } else { if (tdb_store(ttdb, kbuf, dbuf, TDB_REPLACE) == -1) ret = -1; } tdb_chainunlock(tdb, kbuf); return ret; }
/* traversal fn for showing share connections */ static int traverse_fn3(const struct connections_key *key, const struct connections_data *crec, void *private_data) { if (crec->cnum == -1 || !process_exists(crec->pid)) return 0; printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n", crec->servicename, uidtoname(crec->uid), gidtoname(crec->gid),procid_str_static(&crec->pid), crec->machine, tstring(talloc_tos(),crec->start)); return 0; }
static int delete_fn(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) { struct lock_struct *locks; int count, i; BOOL check_self = *(BOOL *)state; pid_t mypid = sys_getpid(); tdb_chainlock(tdb, kbuf); locks = (struct lock_struct *)dbuf.dptr; count = dbuf.dsize / sizeof(*locks); for (i=0; i<count; i++) { struct lock_struct *lock = &locks[i]; /* If check_self is true we want to remove our own records. */ if (check_self && (mypid == lock->context.pid)) { DEBUG(0,("brlock : delete_fn. LOGIC ERROR ! Shutting down and a record for my pid (%u) exists !\n", (unsigned int)lock->context.pid )); } else if (process_exists(lock->context.pid)) { DEBUG(10,("brlock : delete_fn. pid %u exists.\n", (unsigned int)lock->context.pid )); continue; } DEBUG(10,("brlock : delete_fn. Deleting record for process %u\n", (unsigned int)lock->context.pid )); if (count > 1 && i < count-1) { memmove(&locks[i], &locks[i+1], sizeof(*locks)*((count-1) - i)); } count--; i--; } if (count == 0) { tdb_delete(tdb, kbuf); } else if (count < (dbuf.dsize / sizeof(*locks))) { dbuf.dsize = count * sizeof(*locks); tdb_store(tdb, kbuf, dbuf, TDB_REPLACE); } tdb_chainunlock(tdb, kbuf); return 0; }
int main(int argc,char *argv[]) { int i = 0; if(process_exists()) { fprintf(stdout,"This process already exists.\n"); exit(1); } while(i <= 30) { printf("test process pid persistant.\n"); sleep(1); i++; } return 0; }
static bool is_shm_queue_valid(void) { int i; size_t nr; struct local_node lnodes[SD_MAX_NODES]; nr = get_nodes(lnodes); if (nr == 0) return true; for (i = 0; i < nr; i++) if (process_exists(lnodes[i].pid)) return true; return false; }
int delayed_send_umi_san (int process_ID, void * MessageEnvelope, int delay) { // error check if (process_exists(process_ID) == FALSE) { return RTX_FAILURE; } int sender_ID = get_process_ID(); // fill in the message hearder *(((int*)MessageEnvelope) + 1) = sender_ID; *(((int*)MessageEnvelope) + 2) = process_ID; *(((int*)MessageEnvelope) + 4) = delay; //pre_send_message act_send_message (TIMER_INTERRUPT, sender_ID, MessageEnvelope); return RTX_SUCCESS; }
/* kill off any connections chosen by the user */ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state) { struct connections_data crec; if (dbuf.dsize != sizeof(crec)) return 0; memcpy(&crec, dbuf.dptr, sizeof(crec)); if (crec.cnum == -1 && process_exists(crec.pid)) { char buf[30]; slprintf(buf,sizeof(buf)-1,"kill_%d", (int)crec.pid); if (cgi_variable(buf)) { kill_pid(crec.pid); } } return 0; }
static int traverse_fn1(const struct connections_key *key, const struct connections_data *crec, void *state) { if (crec->cnum == -1) return 0; if (!process_exists(crec->pid) || !Ucrit_checkUid(crec->uid)) { return 0; } d_printf("%-10s %s %-12s %s", crec->servicename,procid_str_static(&crec->pid), crec->machine, time_to_asc(crec->start)); return 0; }
/******************************************************************* call the specified function on each entry under management by the share mode system ********************************************************************/ static int shm_share_forall(void (*fn)(share_mode_entry *, char *)) { int i, count=0; int *mode_array; share_mode_record *file_scanner_p; mode_array = (int *)shmops->offset2addr(shmops->get_userdef_off()); for( i = 0; i < shmops->hash_size(); i++) { shmops->lock_hash_entry(i); if(mode_array[i] == 0) { shmops->unlock_hash_entry(i); continue; } file_scanner_p = (share_mode_record *)shmops->offset2addr(mode_array[i]); while((file_scanner_p != 0) && (file_scanner_p->num_share_mode_entries != 0)) { shm_share_mode_entry *entry_scanner_p = (shm_share_mode_entry *) shmops->offset2addr(file_scanner_p->share_mode_entries); while(entry_scanner_p != 0) { if (process_exists(entry_scanner_p->e.pid)) { fn(&entry_scanner_p->e, file_scanner_p->file_name); count++; } entry_scanner_p = (shm_share_mode_entry *) shmops->offset2addr( entry_scanner_p->next_share_mode_entry); } /* end while entry_scanner_p */ file_scanner_p = (share_mode_record *) shmops->offset2addr(file_scanner_p->next_offset); } /* end while file_scanner_p */ shmops->unlock_hash_entry(i); } /* end for */ return count; }
static void check_pids(void *arg) { int i; size_t nr; struct sd_node nodes[SD_MAX_NODES]; pid_t pids[SD_MAX_NODES]; shm_queue_lock(); nr = get_nodes(nodes, pids); for (i = 0; i < nr; i++) if (!process_exists(pids[i])) add_event(EVENT_LEAVE, nodes + i, NULL, 0); shm_queue_unlock(); add_timer(arg, 1); }
static int show_share(struct db_record *rec, const struct connections_key *key, const struct connections_data *crec, void *state) { if (crec->cnum == -1) return 0; if (!process_exists(crec->pid)) { return 0; } d_printf("%-10.10s %s %-12s %s", crec->servicename, procid_str_static(&crec->pid), crec->machine, time_to_asc(crec->start)); return 0; }
/* traversal fn for showing share connections */ static int traverse_fn3(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state) { struct connections_data crec; if (dbuf.dsize != sizeof(crec)) return 0; memcpy(&crec, dbuf.dptr, sizeof(crec)); if (crec.cnum == -1 || !process_exists(crec.pid)) return 0; printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td><td>%s</td><td>%s</td></tr>\n", crec.name,uidtoname(crec.uid), gidtoname(crec.gid),(int)crec.pid, crec.machine, tstring(crec.start)); return 0; }
static int traverse_processes(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) { struct sessionid sessionid; struct process_id pid; if (dbuf.dsize != sizeof(sessionid)) return 0; memcpy(&sessionid, dbuf.dptr, sizeof(sessionid)); pid = pid_to_procid((pid_t)sessionid.pid); if (!process_exists(pid)) { return 0; } Ucrit_addPid( sessionid.pid ); d_printf("%5d %-12s %-12s", (int)sessionid.pid, uidtoname(sessionid.uid), gidtoname(sessionid.gid)); do_collect_usrstat(pid); return 0; }
/** * \brief To launch the FMS Monitor * \return raises an exception */ int MonitorFMS::run() { std::vector<std::string>::iterator iter; std::vector<std::string> tmp; std::string pid,transferId; std::string sqlUpdatedRequest; std::string sqlRequest = "SELECT transferid,processid from filetransfer,vsession where vsession.numsessionid=filetransfer.vsession_numsessionid " " and filetransfer.status=0"; try { boost::scoped_ptr<DatabaseResult> result(mdatabaseVishnu->getResult(sqlRequest.c_str())); if (result->getNbTuples() != 0) { for (size_t i = 0; i < result->getNbTuples(); ++i) { tmp.clear(); tmp = result->get(i); iter = tmp.begin(); transferId=*iter; ++iter; pid = *iter; ++iter; if(false==process_exists(vishnu::convertToString(pid))) { sqlUpdatedRequest = "UPDATE filetransfer SET status=3 where transferid='"+transferId+"'"; mdatabaseVishnu->process(sqlUpdatedRequest.c_str()); } } } sleep(minterval); } catch (VishnuException& e) { string errorInfo = e.buildExceptionString(); if (e.getMsgI() == ERRCODE_DBERR) { cerr << errorInfo << endl; exit(1); } sleep(minterval); } return 0; }
static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) { struct sessionid sessionid; if (dbuf.dsize != sizeof(sessionid)) return 0; memcpy(&sessionid, dbuf.dptr, sizeof(sessionid)); if (!process_exists(sessionid.pid) || !Ucrit_checkUsername(uidtoname(sessionid.uid))) { return 0; } Ucrit_addPid( sessionid.pid ); d_printf("%5d %-12s %-12s %-12s (%s)\n", (int)sessionid.pid, uidtoname(sessionid.uid), gidtoname(sessionid.gid), sessionid.remote_machine, sessionid.hostname); return 0; }
static int shutdown_other_smbds(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *p) { struct sessionid *sessionid = (struct sessionid *)dbuf.dptr; const char *ip = (const char *)p; if (!process_exists(pid_to_procid(sessionid->pid))) { return 0; } if (sessionid->pid == sys_getpid()) { return 0; } if (strcmp(ip, sessionid->ip_addr) != 0) { return 0; } message_send_pid(pid_to_procid(sessionid->pid), MSG_SHUTDOWN, NULL, 0, True); return 0; }
static int is_shm_queue_valid(void) { int i; size_t nr; pid_t pids[SD_MAX_NODES]; if (shm_queue->chksum != shm_queue_calc_chksum()) { dprintf("invalid shm queue\n"); return 0; } nr = get_nodes(NULL, pids); if (nr == 0) return 1; for (i = 0; i < nr; i++) if (process_exists(pids[i])) return 1; return 0; }
/* traversal fn for showing machine connections */ static int traverse_fn2(const struct connections_key *key, const struct connections_data *crec, void *private_data) { if (crec->cnum == -1 || !process_exists(crec->pid) || procid_equal(&crec->pid, &smbd_pid)) return 0; addPid2Machine (crec->pid, crec->machine); printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td>\n", procid_str_static(&crec->pid), crec->machine, crec->addr, tstring(talloc_tos(),crec->start)); if (geteuid() == 0) { printf("<td><input type=submit value=\"X\" name=\"kill_%s\"></td>\n", procid_str_static(&crec->pid)); } printf("</tr>\n"); return 0; }
static int traverse_sessionid(const char *key, struct sessionid *session, void *private_data) { fstring uid_str, gid_str; if (!process_exists(session->pid) || !Ucrit_checkUid(session->uid)) { return 0; } Ucrit_addPid(session->pid); fstr_sprintf(uid_str, "%u", (unsigned int)session->uid); fstr_sprintf(gid_str, "%u", (unsigned int)session->gid); d_printf("%-7s %-12s %-12s %-12s (%s)\n", procid_str_static(&session->pid), numeric_only ? uid_str : uidtoname(session->uid), numeric_only ? gid_str : gidtoname(session->gid), session->remote_machine, session->hostname); return 0; }
static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) { struct connections_data crec; if (dbuf.dsize != sizeof(crec)) return 0; memcpy(&crec, dbuf.dptr, sizeof(crec)); if (crec.cnum == -1) return 0; if (!process_exists(crec.pid) || !Ucrit_checkUsername(uidtoname(crec.uid))) { return 0; } d_printf("%-10.10s %5d %-12s %s", crec.name,(int)crec.pid, crec.machine, asctime(LocalTime(&crec.start))); return 0; }
static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) { struct connections_data crec; if (dbuf.dsize != sizeof(crec)) return 0; memcpy(&crec, dbuf.dptr, sizeof(crec)); if (crec.cnum == -1) return 0; if (!process_exists(crec.pid) || !Ucrit_checkUid(crec.uid)) { return 0; } d_printf("%-10s %s %-12s %s", crec.servicename,procid_str_static(&crec.pid), crec.machine, time_to_asc(crec.start)); return 0; }
bool serverid_exists(const struct server_id *id) { struct db_context *db; struct serverid_exists_state state; struct serverid_key key; TDB_DATA tdbkey; NTSTATUS status; if (procid_is_me(id)) { return true; } if (!process_exists(*id)) { return false; } if (id->unique_id == SERVERID_UNIQUE_ID_NOT_TO_VERIFY) { return true; } db = serverid_db(); if (db == NULL) { return false; } serverid_fill_key(id, &key); tdbkey = make_tdb_data((uint8_t *)&key, sizeof(key)); state.id = id; state.exists = false; status = dbwrap_parse_record(db, tdbkey, server_exists_parse, &state); if (!NT_STATUS_IS_OK(status)) { return false; } return state.exists; }