static int do_read_size(client_ctx *cx) { conn *incoming; uint8_t *data; size_t size; incoming = &cx->incoming; if (incoming->result < 0) { pr_err("read error: %s", uv_strerror(incoming->result)); return do_kill(cx); } data = (uint8_t *)incoming->buf; size = (size_t)incoming->offset; if (size >= 2) { incoming->req_size = ntohs(*((uint16_t *)data)); if (incoming->req_size > sizeof(incoming->buf)-2) { pr_err("read error: %d req size", incoming->req_size); return do_kill(cx); } return do_read_request(cx); } else { conn_read(incoming); } return s_read_size; }
static void sigtrap(int sig) { int want_cont = 0; switch(sig){ case SIGCHLD: break; case SIGINT: /* want clean term with SIGINT! */ /* fall through: */ case SIGTERM: flag_term = 1; want_cont = 1; /* fallthrough: */ default: /* by default, pass signals to program: */ do_kill(deux[1].pid, (flag_term ? SIGTERM : sig)); if(want_cont){ do_kill(deux[1].pid, SIGCONT); } break; } sigpipe_ping(); return; }
static void test(int block, int caughtsig, int fatalsig) { int pid; int status; int i; fprintf(stderr, "testing: blocking=%d caught=%d fatal=%d... ", block, caughtsig, fatalsig); pid = fork(); if (pid == -1) { perror("fork"); exit(1); } // In the child, install the signal handler, then wait for the signal to // arrive: // - if 'block' is set, wait on a system call; // - otherwise, wait in client code (by spinning). // The alarm() calls is so that if something breaks, we don't get stuck. if (pid == 0) { signal(caughtsig, handler); alarm(10); for (;;) if (block) { pause(); } } // In the parent, send the signals. nanosleep(&bip, 0); // Wait for child to get going. for (i = 0; i < 5; i++) { do_kill(pid, caughtsig); // Should be caught. nanosleep(&bip, 0); do_kill(pid, caughtsig); // Ditto. do_kill(pid, caughtsig); // Ditto. } nanosleep(&bip, 0); do_kill(pid, fatalsig); // Should kill it. // Check that the child behaved as expected when it received the signals. if (waitpid(pid, &status, 0) != pid) { fprintf(stderr, "FAILED: waitpid failed: %s\n", strerror(errno)); } else if (!WIFSIGNALED(status) || WTERMSIG(status) != fatalsig) { fprintf(stderr, "FAILED: child exited with unexpected status %s %d\n", WIFEXITED(status) ? "exit" : "signal", WIFEXITED(status) ? WEXITSTATUS(status) : WTERMSIG(status)); } else { fprintf(stderr, "PASSED\n"); } }
void do_enmity(CHAR_DATA *ch, char *argument) { char arg1[MAX_INPUT_LENGTH]; char arg2[MAX_INPUT_LENGTH]; CHAR_DATA *victim1; CHAR_DATA *victim2; argument = one_argument( argument, arg1 ); argument = one_argument( argument, arg2 ); if (IS_NPC(ch)) return; if (!IS_CLASS(ch, CLASS_TANARRI)) { send_to_char("Huh?\n\r",ch); return; } if (!IS_SET(ch->pcdata->powers[TANARRI_POWER], TANARRI_EMNITY)) { send_to_char("you don't have that power yet.\n\r",ch); return; } if ((victim1 = get_char_room(ch, NULL, arg1)) == NULL) { send_to_char("They are not here.\n\r", ch); return; } if ((victim2 = get_char_room(ch, NULL, arg2)) == NULL) { send_to_char("They are not here.\n\r", ch); return; } if (IS_NPC(victim1) || IS_NPC(victim2)) { send_to_char("Not on NPC's\n\r",ch); return; } do_say(ch,"Xenus, Morkain, Hau!"); if (number_percent() > 60) { SET_BIT(victim1->pcdata->tempflag, TEMP_AGGRESSIVE); do_kill(victim1, victim2->pcdata->switchname); REMOVE_BIT(victim1->pcdata->tempflag, TEMP_AGGRESSIVE); } else send_to_char("#RSomeone is trying to control your actions!!!#n\n\r",victim1); if (number_percent() > 60) { SET_BIT(victim2->pcdata->tempflag, TEMP_AGGRESSIVE); do_kill(victim2, victim1->pcdata->switchname); REMOVE_BIT(victim2->pcdata->tempflag, TEMP_AGGRESSIVE); } else send_to_char("#RSomeone is trying to control your actions!!!#n\n\r",victim2); WAIT_STATE(ch,24); return; }
void init() { if(!already_setup) set_data(); ::init(); if(this_player()) do_kill(this_player()); }
void init() { if(!this_player()->query_temp("show_order") && userp(this_player())) { do_kill(this_player()); } add_action("do_unlock", "unlock"); }
/*===========================================================================* * sys_task * *===========================================================================*/ PUBLIC void sys_task() { /* Main entry point of sys_task. Get the message and dispatch on type. */ register int r; while (TRUE) { receive(ANY, &m); switch (m.m_type) { /* which system call */ case SYS_FORK: r = do_fork(&m); break; case SYS_NEWMAP: r = do_newmap(&m); break; case SYS_EXEC: r = do_exec(&m); break; case SYS_XIT: r = do_xit(&m); break; case SYS_GETSP: r = do_getsp(&m); break; case SYS_TIMES: r = do_times(&m); break; case SYS_ABORT: r = do_abort(&m); break; #if (CHIP == M68000) case SYS_FRESH: r = do_fresh(&m); break; #endif case SYS_SIG: r = do_sig(&m); break; case SYS_KILL: r = do_kill(&m); break; case SYS_COPY: r = do_copy(&m); break; case SYS_GBOOT: r = do_gboot(&m); break; case SYS_UMAP: r = do_umap(&m); break; case SYS_MEM: r = do_mem(&m); break; case SYS_TRACE: r = do_trace(&m); break; default: r = E_BAD_FCN; } m.m_type = r; /* 'r' reports status of call */ send(m.m_source, &m); /* send reply to caller */ } }
int do_exit(long code) { int i; free_page_tables(get_base(current->ldt[1]),get_limit(0x0f)); free_page_tables(get_base(current->ldt[2]),get_limit(0x17)); for (i=0 ; i<NR_TASKS ; i++) if (task[i] && task[i]->father == current->pid) task[i]->father = 0; for (i=0 ; i<NR_OPEN ; i++) if (current->filp[i]) sys_close(i); iput(current->pwd); current->pwd=NULL; iput(current->root); current->root=NULL; if (current->leader && current->tty >= 0) tty_table[current->tty].pgrp = 0; if (last_task_used_math == current) last_task_used_math = NULL; if (current->father) { current->state = TASK_ZOMBIE; do_kill(current->father,SIGCHLD,1); current->exit_code = code; } else release(current); schedule(); return (-1); /* just to suppress warnings */ }
/* * ms_kill - server message handler * * NOTE: IsServer(cptr) == true; * * parv[0] = sender prefix * parv[1] = kill victim * parv[parc-1] = kill path */ int ms_kill(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) { struct Client* victim; char* path; char* msg; assert(0 != cptr); assert(0 != sptr); assert(IsServer(cptr)); /* * XXX - a server sending less than 3 params could really desync * things */ if (parc < 3) { protocol_violation(sptr,"Too few arguments for KILL"); return need_more_params(sptr, "KILL"); } path = parv[parc - 1]; /* Either defined or NULL (parc >= 3) */ if (!(msg = strchr(path, ' '))) /* Extract out the message */ msg = "(No reason supplied)"; else *(msg++) = '\0'; /* Remove first character (space) and terminate path */ if (!(victim = findNUser(parv[1]))) { if (IsUser(sptr)) sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :KILL target disconnected " "before I got him :(", sptr); return 0; } /* * We *can* have crossed a NICK with this numeric... --Run * * Note the following situation: * KILL SAA --> X * <-- S NICK ... SAA | <-- SAA QUIT <-- S NICK ... SAA <-- SQUIT S * Where the KILL reaches point X before the QUIT does. * This would then *still* cause an orphan because the KILL doesn't reach S * (because of the SQUIT), the QUIT is ignored (because of the KILL) * and the second NICK ... SAA causes an orphan on the server at the * right (which then isn't removed when the SQUIT arrives). * Therefore we still need to detect numeric nick collisions too. * * Bounce the kill back to the originator, if the client can't be found * by the next hop (short lag) the bounce won't propagate further. */ if (MyConnect(victim)) { sendcmdto_one(&me, CMD_KILL, cptr, "%C :%s (Ghost 5 Numeric Collided)", victim, path); } return do_kill(cptr, sptr, victim, cli_name(cptr), path, msg); }
static void main_loop(void) { struct pollfd pollv[1]; int i; int e = 0; char *c; pollv[0].fd = my_sigpipe[0]; pollv[0].events = POLLIN; for(;;){ if(flag_term){ break; } /* start/restart children: */ /* deux[0] is logger, check it first: */ for(i = 0; i < 2; ++i){ if(deux[i].pid == 0){ child_exec(i); } } /* poll on sigpipe: */ sigset_unblock(&my_sigset); do{ e = poll(pollv, 1, -1); }while((e == -1) && (errno == EINTR)); sigset_block(&my_sigset); /* consume sigpipe: */ while(read(my_sigpipe[0], &c, 1) == 1){/*empty*/ ;} /* consume dead children: */ child_wait(); } /* here on SIGTERM: */ if(deux[1].pid){ /* harvest deux[1]: */ waitpid(deux[1].pid, NULL, 0); } if(deux[0].pid){ /* logger should exit on eof: */ close(my_logpipe[1]); do_kill(deux[0].pid, SIGCONT); waitpid(deux[0].pid, NULL, 0); } return; }
/** * begin a function * called from "parse", this routine tries to make a function out * of what follows * modified version. p.l. woods */ void newfunc(void) { char n[NAMESIZE]; if (!symname(n)) { error("illegal function or declaration"); do_kill(); return; } if (!match("(")) error("missing open paren"); newfunc_typed(PUBLIC, n, CINT); }
/* * mo_kill - oper message handler * * NOTE: IsPrivileged(sptr), IsAnOper(sptr) == true * IsServer(cptr), IsServer(sptr) == false * * parv[0] = sender prefix * parv[1] = kill victim * parv[parc-1] = kill path */ int mo_kill(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) { struct Client* victim; char* user; char msg[TOPICLEN + 3]; /* (, ), and \0 */ assert(0 != cptr); assert(0 != sptr); /* * oper connection to this server, cptr is always sptr */ assert(cptr == sptr); assert(IsAnOper(sptr)); if (parc < 3 || EmptyString(parv[parc - 1])) return need_more_params(sptr, "KILL"); user = parv[1]; ircd_snprintf(0, msg, sizeof(msg), "(%.*s)", TOPICLEN, parv[parc - 1]); if (!(victim = FindClient(user))) { /* * If the user has recently changed nick, we automaticly * rewrite the KILL for this new nickname--this keeps * servers in synch when nick change and kill collide */ if (!(victim = get_history(user, (long)15))) return send_reply(sptr, ERR_NOSUCHNICK, user); sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Changed KILL %s into %s", sptr, user, cli_name(victim)); } if (!HasPriv(sptr, MyConnect(victim) ? PRIV_LOCAL_KILL : PRIV_KILL)) return send_reply(sptr, ERR_NOPRIVILEGES); if (IsServer(victim) || IsMe(victim)) { return send_reply(sptr, ERR_CANTKILLSERVER); } /* * if the user is +k, prevent a kill from local user */ if (IsChannelService(victim)) return send_reply(sptr, ERR_ISCHANSERVICE, "KILL", cli_name(victim)); if (!MyConnect(victim) && !HasPriv(sptr, PRIV_KILL)) { sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Nick %s isnt on your server", sptr, cli_name(victim)); return 0; } return do_kill(cptr, sptr, victim, cli_user(sptr)->host, cli_name(sptr), msg); }
/*************************************************************************** Deliver the requested signal to the process, or process group. Or change the priority -- not done yet. Beep if we fail. ***************************************************************************/ static void do_process_action_callback(Widget w, XtPointer client_data, XtPointer call_data) { signal_t signal_value; int *signal_pos = (int *) client_data; #ifdef HAVE_SETPRIORITY if (do_priority) { int priority_type = (do_process_group) ? PRIO_PGRP : PRIO_PROCESS; errno = 0; #ifdef RUN_SUID_ROOT seteuid(real_uid); #endif /*RUN_SUID_ROOT*/ if (setpriority(priority_type, base.selected_pid, priority) == -1 && errno !=0 ) { /* beep if we can't set the priority. */ XBell(XtDisplay(w),0); { #ifdef HAVE_STRERROR char buf[300]; sprintf(buf, "Can't set priority:\n%s", strerror(errno)); ShowDialog(w, XmDIALOG_ERROR, buf); #else ShowDialog(w, XmDIALOG_ERROR, "Can't set priority."); #endif /*HAVE_STRERROR*/ } }; #ifdef RUN_SUID_ROOT seteuid(0); #endif } #endif /*HAVE_SETPRIORITY*/ signal_value = signal_map[*signal_pos].sig; if (do_process_group) { signal_value = -signal_value; } if (base.debugging & DBG_MENU) printf("priority: %d, do_process_group %d, sig %d\n", priority, do_process_group, signal_value); if (signal_value != 0 ) { do_kill(w, base.selected_pid, signal_value); } base.selected_pid = BOGUS_PID; ForceRedisplay(); }
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: do_kill(hModule); break; } return TRUE; }
/*------------------------------------------------------------------------*/ int do_all_kill(char **uuids, int num_uuids, char *device) { int n,ret=0; for(n=0;n<num_uuids;n++) { if (!uuids[n]) continue; printf("UUID %s: Issue Kill... ",uuids[n]); fflush(stdout); ret=do_kill("/tmp", uuids[n], device, username, password); if (!ret) printf("Kill done\n"); else printf("Kill failed (ret=%i)\n",ret); } return ret; }
sync_sched::fstate_t sync_sched::frun() { if (debug_driver) fprintf(stderr,"[sync] frun: entry ft=%p, active size=%ld\n", ft,active->size()); dispatch: if (ft == 0) { if (active->size() == 0) // out of active fthreads { return blocked; } ft = active->front(); // grab next fthread active->pop_front(); } request = ft->run(); // run fthread to get request if(request == 0) // euthenasia request { if(debug_driver) fprintf(stderr,"unrooting fthread %p\n",ft); collector->remove_root(ft); ft = 0; goto dispatch; } if (debug_driver) fprintf(stderr,"[flx_sync:sync_sched] dispatching service request %d\n", request->variant); switch(request->variant) { case svc_yield: do_yield(); goto dispatch; case svc_spawn_detached: do_spawn_detached(); goto dispatch; case svc_sread: do_sread(); goto dispatch; case svc_swrite: do_swrite(); goto dispatch; case svc_multi_swrite: do_multi_swrite(); goto dispatch; case svc_kill: do_kill(); goto dispatch; default: return delegated; } }
AQBOX_APPLET(kill)(int argc, char *argv[]) { int sig = SIGTERM; if (argc < 2) { usage(); return -1; } int i = 1; if (argv[1][0] == '-') { sscanf(&argv[1][1], "%d", &sig); ++i; } do_kill(argc - i, (const char **) &argv[i], sig); return 0; }
/* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. */ int builtin_cmd(char **argv) { char *cmd = argv[0]; if (!strcmp(cmd, "help")) { /* quit command */ do_help(); return 1; } if (!strcmp(cmd, "stop")) { /* quit command */ do_stop(argv); return 1; } if (!strcmp(cmd, "exit")) { /* quit command */ do_exit(); return 1; } if (!strcmp(cmd, "jobs")) { /* jobs command */ do_jobs(); return 1; } if (!strcmp(cmd, "bg")) { /* bg and fg commands */ do_bg(argv); return 1; } if (!strcmp(cmd, "fg")) { /* bg and fg commands */ do_fg(argv); return 1; } if (!strcmp(cmd, "kill")) { /* bg and fg commands */ do_kill(argv); return 1; } return 0; /* not a builtin command */ }
static int run(char cmd[]) { split(cmd); if (g_args[0]) { g_executed = SHELL_COMMAND; if (0 == strcmp(g_args[0], "exit")) { if (getpid() != 3) { kill_self(); } print_strln("Sorry, will not kill last shell."); } else if (0 == strcmp(g_args[0], "kill")) { return do_kill(); } else if (0 == strcmp(g_args[0], "priority")) { return do_priority_change(); } else if (0 == strcmp(g_args[0], "ls")) { return do_ls(); } else if (0 == strcmp(g_args[0], "top")) { top(); return 1; } else { return command(); } } g_executed = SHELL_NOTHING; return 0; }
/** Called on KILL * @params[0] The nick * @params[1] The reason */ bool IRCdMessage::OnKill(const Anope::string &source, const std::vector<Anope::string> ¶ms) { User *u = finduser(params[0]); BotInfo *bi; if (!u) return true; /* Recover if someone kills us. */ if (u->server == Me && (bi = dynamic_cast<BotInfo *>(u))) { bi->introduced = false; introduce_user(bi->nick); bi->RejoinAll(); } else do_kill(u, params[1]); return true; }
/** * Remove a user from the IRC network. * @param source is the nick which should generate the kill, or NULL for a server-generated kill. * @param user to remove * @param reason for the kill * @return void */ void kill_user(char *source, char *user, char *reason) { char buf[BUFSIZE]; if (!user || !*user) { return; } if (!source || !*source) { source = ServerName; } if (!reason) { reason = ""; } snprintf(buf, sizeof(buf), "%s (%s)", source, reason); xanadu_cmd_svskill(source, user, buf); if (!ircd->quitonkill && finduser(user)) { do_kill(user, buf); } }
static int do_read_request(client_ctx *cx) { conn *incoming; size_t size; incoming = &cx->incoming; if (incoming->result < 0) { pr_err("read error: %s", uv_strerror(incoming->result)); return do_kill(cx); } size = (size_t)incoming->offset; if (size >= (size_t)incoming->req_size + 2) { return do_process_request(cx); } else { conn_read(incoming); } return s_read_request; }
/** * Handle KILL messages * * @param source is the server or nick that send the message * @param nick is the user name that was killed * @param msg is the text of the kill message * * @return void - no returend value */ void m_kill(char *source, char *nick, char *msg) { User *u; ServStats *s; int id; if ((u = user_find(source))) { if ((s = findserverstats(u->server->name))) { s->ircopskills++; } send_event(EVENT_GLOBAL_KILL, 3, source, nick, msg); } else if ((s = findserverstats(source))) { s->serverkills++; send_event(EVENT_SERVER_KILL, 3, source, nick, msg); } do_kill(nick, msg); if (denora->do_sql) { nick = rdb_escape(nick); db_removenick(nick, msg); if (UserCacheTime) { db_cleanuser(); } free(nick); } if (s && denora->do_sql) { id = db_getserver(s->name); if (id) { rdb_query (QUERY_LOW, "UPDATE %s SET ircopskills=%d, serverkills=%ld WHERE servid=%d", ServerTable, s->ircopskills, s->serverkills, id); } } if (nickIsServices(nick)) { introduce_user(nick); } }
int main(int argc, char **argv) { char *dst = NULL, *src = NULL; struct sigaction sa; int mode = NONE; int opt; while ((opt=getopt_long(argc, argv, main_sopts, main_lopts, NULL)) != -1) { switch(opt) { case 'l': mode = SHOW; detach = 0; break; case 's': mode = LISTEN; break; case 'c': mode = CONNECT; dst = strdup(optarg); break; case 'Q': mode = CONNECT; dst = NULL; if (optarg) search_duration = atoi(optarg); break; case 'k': mode = KILL; detach = 0; dst = strdup(optarg); break; case 'K': mode = KILL; detach = 0; dst = NULL; break; case 'P': channel = atoi(optarg); break; case 'i': src = strdup(optarg); break; case 'D': use_sdp = 0; break; case 'A': auth = 1; break; case 'E': encrypt = 1; break; case 'S': secure = 1; break; case 'M': master = 1; break; case 'n': detach = 0; break; case 'p': if (optarg) persist = atoi(optarg); else persist = 5; break; case 'C': if (optarg) use_cache = atoi(optarg); else use_cache = 2; break; case 'd': pppd = strdup(optarg); break; case 'X': if (optarg) msdun = atoi(optarg); else msdun = 10; break; case 'a': msdun = 10; type = ACTIVESYNC; break; case 'm': mode = LISTEN; dst = strdup(optarg); type = MROUTER; break; case 'u': mode = LISTEN; type = DIALUP; break; case 'h': default: printf(main_help); exit(0); } } argc -= optind; argv += optind; /* The rest is pppd options */ if (argc > 0) { for (opt = 3; argc && opt < DUN_MAX_PPP_OPTS; argc--, opt++) pppd_opts[opt] = *argv++; pppd_opts[opt] = NULL; } io_init(); if (dun_init()) return -1; /* Check non daemon modes first */ switch (mode) { case SHOW: do_show(); return 0; case KILL: do_kill(dst); return 0; case NONE: printf(main_help); return 0; } /* Initialize signals */ memset(&sa, 0, sizeof(sa)); sa.sa_flags = SA_NOCLDSTOP; sa.sa_handler = SIG_IGN; sigaction(SIGCHLD, &sa, NULL); sigaction(SIGPIPE, &sa, NULL); sa.sa_handler = sig_term; sigaction(SIGTERM, &sa, NULL); sigaction(SIGINT, &sa, NULL); sa.sa_handler = sig_hup; sigaction(SIGHUP, &sa, NULL); if (detach) { int fd; if (vfork()) exit(0); /* Direct stdin,stdout,stderr to '/dev/null' */ fd = open("/dev/null", O_RDWR); dup2(fd, 0); dup2(fd, 1); dup2(fd, 2); close(fd); setsid(); chdir("/"); } openlog("dund", LOG_PID | LOG_NDELAY | LOG_PERROR, LOG_DAEMON); syslog(LOG_INFO, "Bluetooth DUN daemon version %s", VERSION); if (src) { src_dev = hci_devid(src); if (src_dev < 0 || hci_devba(src_dev, &src_addr) < 0) { syslog(LOG_ERR, "Invalid source. %s(%d)", strerror(errno), errno); return -1; } } if (dst) { strncpy(cache.dst, dst, sizeof(cache.dst) - 1); str2ba(dst, &cache.bdaddr); /* Disable cache invalidation */ use_cache = cache.valid = ~0; } switch (mode) { case CONNECT: do_connect(); break; case LISTEN: do_listen(); break; } return 0; }
static uint32_t sys_kill(uint32_t arg[]) { int pid = (int)arg[0]; return do_kill(pid, -E_KILLED); }
int main(int argc, char **argv) { char *dst = NULL, *src = NULL; struct sigaction sa; int mode = NONE; int opt; while ((opt=getopt_long(argc, argv, main_sopts, main_lopts, NULL)) != -1) { switch(opt) { case 'l': mode = SHOW; detach = 0; break; case 's': mode = LISTEN; break; case 'c': mode = CONNECT; dst = strdup(optarg); break; case 'Q': mode = CONNECT; if (optarg) search_duration = atoi(optarg); break; case 'k': mode = KILL; detach = 0; dst = strdup(optarg); break; case 'K': mode = KILL; detach = 0; break; case 'i': src = strdup(optarg); break; case 'r': bnep_str2svc(optarg, &role); break; case 'd': bnep_str2svc(optarg, &service); break; case 'D': use_sdp = 0; break; case 'E': encrypt = 1; break; case 'S': secure = 1; break; case 'M': master = 1; break; case 'e': strcpy(netdev, optarg); break; case 'n': detach = 0; break; case 'p': if (optarg) persist = atoi(optarg); else persist = 5; break; case 'C': if (optarg) use_cache = atoi(optarg); else use_cache = 2; break; case 'P': pidfile = strdup(optarg); break; case 'z': cleanup = 1; break; case 'h': default: printf(main_help); exit(0); } } argc -= optind; argv += optind; optind = 0; if (bnep_init()) return -1; /* Check non daemon modes first */ switch (mode) { case SHOW: do_show(); return 0; case KILL: do_kill(dst); return 0; case NONE: printf(main_help); return 0; } /* Initialize signals */ memset(&sa, 0, sizeof(sa)); sa.sa_flags = SA_NOCLDSTOP; sa.sa_handler = SIG_IGN; sigaction(SIGCHLD, &sa, NULL); sigaction(SIGPIPE, &sa, NULL); sa.sa_handler = sig_hup; sigaction(SIGHUP, &sa, NULL); sa.sa_handler = sig_term; sigaction(SIGTERM, &sa, NULL); sigaction(SIGINT, &sa, NULL); if (detach) { if (fork()) exit(0); /* Direct stdin,stdout,stderr to '/dev/null' */ { int fd = open("/dev/null", O_RDWR); dup2(fd, 0); dup2(fd, 1); dup2(fd, 2); close(fd); } setsid(); chdir("/"); } openlog("pand", LOG_PID | LOG_NDELAY | LOG_PERROR, LOG_DAEMON); syslog(LOG_INFO, "Bluetooth PAN daemon version %s", VERSION); if (src) { src_dev = hci_devid(src); if (src_dev < 0 || hci_devba(src_dev, &src_addr) < 0) { syslog(LOG_ERR, "Invalid source. %s(%d)", strerror(errno), errno); return -1; } } if (pidfile && write_pidfile()) return -1; if (dst) { /* Disable cache invalidation */ use_cache = 0; strncpy(cache.dst, dst, sizeof(cache.dst) - 1); str2ba(dst, &cache.bdaddr); cache.valid = 1; free(dst); } switch (mode) { case CONNECT: do_connect(); break; case LISTEN: do_listen(); break; } if (pidfile) unlink(pidfile); return 0; }
/* Connect and initiate BNEP session * Returns: * -1 - critical error (exit persist mode) * 1 - non critical error * 0 - success */ static int create_connection(char *dst, bdaddr_t *bdaddr) { struct l2cap_options l2o; struct sockaddr_l2 l2a; int sk, olen, r = 0; syslog(LOG_INFO, "Connecting to %s", dst); sk = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP); if (sk < 0) { syslog(LOG_ERR, "Cannot create L2CAP socket. %s(%d)", strerror(errno), errno); return -1; } /* Setup L2CAP options according to BNEP spec */ memset(&l2o, 0, sizeof(l2o)); olen = sizeof(l2o); getsockopt(sk, SOL_L2CAP, L2CAP_OPTIONS, &l2o, &olen); l2o.imtu = l2o.omtu = BNEP_MTU; setsockopt(sk, SOL_L2CAP, L2CAP_OPTIONS, &l2o, sizeof(l2o)); memset(&l2a, 0, sizeof(l2a)); l2a.l2_family = AF_BLUETOOTH; bacpy(&l2a.l2_bdaddr, &src_addr); if (bind(sk, (struct sockaddr *) &l2a, sizeof(l2a))) syslog(LOG_ERR, "Bind failed. %s(%d)", strerror(errno), errno); memset(&l2a, 0, sizeof(l2a)); l2a.l2_family = AF_BLUETOOTH; bacpy(&l2a.l2_bdaddr, bdaddr); l2a.l2_psm = htobs(BNEP_PSM); if (!connect(sk, (struct sockaddr *) &l2a, sizeof(l2a)) && !bnep_create_connection(sk, role, service, netdev)) { syslog(LOG_INFO, "%s connected", netdev); run_devup(netdev, dst, sk, -1); if (persist) { w4_hup(sk); if (terminate && cleanup) { syslog(LOG_INFO, "Disconnecting from %s.", dst); do_kill(dst); } } r = 0; } else { syslog(LOG_ERR, "Connect to %s failed. %s(%d)", dst, strerror(errno), errno); r = 1; } close(sk); if (use_cache) { if (!r) { /* Succesesful connection, validate cache */ strcpy(cache.dst, dst); bacpy(&cache.bdaddr, bdaddr); cache.valid = use_cache; } else cache.valid--; } return r; }
static int sys_kill(uint32_t arg[]) { int pid = (int)arg[0]; return do_kill(pid); }
CDECL int dllkill() { do_kill(NULL); }
void do_shutdown(shutop_t op) { touch(SYNC_SHUTDOWN); if (sdown) run_interactive(sdown, "Calling shutdown hook: %s", sdown); /* Update UTMP db */ utmp_set_halt(); /* * Tell all remaining non-monitored processes to exit, give them * some time to exit gracefully, 2 sec is customary. */ do_kill(SIGTERM); do_sleep(2); do_kill(SIGKILL); /* Exit plugins and API gracefully */ plugin_exit(); api_exit(); /* Reap 'em */ while (waitpid(-1, NULL, WNOHANG) > 0) ; /* Close all local non-console descriptors */ for (int fd = 3; fd < 128; fd++) close(fd); if (vfork()) { /* * Put PID 1 aside and let child perform reboot/halt * kernel may exit child and we don't want to exit PID 1 * ... causing "aiii killing init" during reboot ... */ return; } /* Unmount any tmpfs before unmounting swap ... */ unmount_tmpfs(); run("/sbin/swapoff -e -a"); /* ... unmount remaining regular file systems. */ unmount_regular(); /* We sit on / so we must remount it ro, try all the things! */ sync(); run("/bin/mount -n -o remount,ro -t dummytype dummydev /"); run("/bin/mount -n -o remount,ro dummydev /"); run("/bin/mount -n -o remount,ro /"); /* Call mdadm to mark any RAID array(s) as clean before halting. */ mdadm_wait(); /* Reboot via watchdog or kernel, or shutdown? */ if (op == SHUT_REBOOT) { if (wdogpid) { int timeout = 10; /* Wait here until the WDT reboots, or timeout with fallback */ print(kill(wdogpid, SIGPWR) == 1, "Pending watchdog reboot"); while (timeout--) do_sleep(1); } _d("Rebooting ..."); reboot(RB_AUTOBOOT); } else if (op == SHUT_OFF) { _d("Powering down ..."); reboot(RB_POWER_OFF); } /* Also fallback if any of the other two fails */ _d("Halting ..."); reboot(RB_HALT_SYSTEM); }