/* * Read up a line from the specified input into the line * buffer. Return the number of characters read. Do not * include the newline at the end. */ PUBLIC int readline(FILE *ibuf, char *linebuf, int linesize, int no_restart) { struct sigaction osa_sigtstp; struct sigaction osa_sigttin; struct sigaction osa_sigttou; int n; clearerr(ibuf); sig_check(); if (no_restart) { (void)sig_setflags(SIGTSTP, 0, &osa_sigtstp); (void)sig_setflags(SIGTTIN, 0, &osa_sigttin); (void)sig_setflags(SIGTTOU, 0, &osa_sigttou); } if (fgets(linebuf, linesize, ibuf) == NULL) n = -1; else { n = (int)strlen(linebuf); if (n > 0 && linebuf[n - 1] == '\n') linebuf[--n] = '\0'; } if (no_restart) { (void)sigaction(SIGTSTP, &osa_sigtstp, NULL); (void)sigaction(SIGTTIN, &osa_sigttin, NULL); (void)sigaction(SIGTTOU, &osa_sigttou, NULL); } sig_check(); return n; }
static char * readtty(const char *pr, char *src) { char *line; line = my_gets(&elm.string, pr, src); sig_check(); if (line == NULL) (void)putc('\n', stdout); return line ? savestr(line) : __UNCONST(""); }
void IpqLoop() { int status; struct pcap_pkthdr PHdr; unsigned char buf[PKT_BUFSIZE]; static ipq_packet_msg_t *m; #ifdef DEBUG_GIDS printf("Reading Packets from ipq handle \n"); #endif while(1) { ResetIV(); status = ipq_read(ipqh, buf, PKT_BUFSIZE, 1000000); if (status < 0) { ipq_perror("IpqLoop: "); } /* man ipq_read tells us that when a timeout is specified * ipq_read will return 0 when it is interupted. */ else if(status == 0) { /* Do the signal check. If we don't do this we will * evaluate the signal only when we receive an actual * packet. We don't want to depend on this. */ sig_check(); } else { switch(ipq_message_type(buf)) { case NLMSG_ERROR: fprintf(stderr, "Received error message %d\n", ipq_get_msgerr(buf)); break; case IPQM_PACKET: m = ipq_get_packet(buf); g_m = m; #ifdef DEBUG_INLINE printf("%02X:%02X:%02X:%02X:%02X:%02X\n", m->hw_addr[0], m->hw_addr[1], m->hw_addr[2], m->hw_addr[3], m->hw_addr[4], m->hw_addr[5]); #endif TranslateToPcap(m, &PHdr); PcapProcessPacket(NULL, &PHdr, (u_char *)m->payload); HandlePacket(m); break; } /* switch */ } /* if - else */ } /* while() */ }
/** * Sleep until any of the signals in \a sigs or \a timeout ticks elapse. * If the timeout elapse a SIG_TIMEOUT is added to the received signal(s). * \return the signal(s) that have awoken the process. * \note Caller must check return value to check which signal awoke the process. */ sigmask_t sig_waitTimeout(sigmask_t sigs, ticks_t timeout) { Timer t; sigmask_t res; cpu_flags_t flags; ASSERT(!sig_check(SIG_TIMEOUT)); ASSERT(!(sigs & SIG_TIMEOUT)); /* IRQ are needed to run timer */ ASSERT(IRQ_ENABLED()); timer_set_event_signal(&t, proc_current(), SIG_TIMEOUT); timer_setDelay(&t, timeout); timer_add(&t); res = sig_wait(SIG_TIMEOUT | sigs); IRQ_SAVE_DISABLE(flags); /* Remove timer if sigs occur before timer signal */ if (!(res & SIG_TIMEOUT) && !sig_check(SIG_TIMEOUT)) timer_abort(&t); IRQ_RESTORE(flags); return res; }
/* * Print out the header of a specific message. * This is a slight improvement to the standard one. */ PUBLIC void printhead(int mesg) { const char *fmtstr; char *msgline; fmtstr = value(ENAME_HEADER_FORMAT); if (fmtstr == NULL) fmtstr = DEFAULT_HEADER_FORMAT; msgline = smsgprintf(fmtstr, get_message(mesg)); if (screenwidth > 0) msgline[screenwidth] = '\0'; (void)printf("%s\n", msgline); sig_check(); }
static void NORETURN hadarp_process(void) { char buf[16]; while (1) { if (sig_check(SIG_POLIFEMO)) kfile_putc('@', &ser.fd); if (kfile_gets(&ser.fd, buf, sizeof(buf)) == EOF) { hadarp_cnt = -1; kfile_clearerr(&ser.fd); continue; } if (buf[0] == '\0') { /* Discard empty strings */ continue; } char *endptr = buf; int hadarp_raw = strtol(buf, &endptr, 10); if (*endptr != '\0' || hadarp_raw > 10000 || hadarp_raw < 0) hadarp_cnt = -1; else { /* Compensate for geiger tube dead time */ float cps = hadarp_raw / 60.0; hadarp_cnt = ABS(cps / (1.0 - (cps * 1.9e-4)) * 60.0 + 0.5); } LOG_INFO("HADARP cnt:%d\n", hadarp_cnt); } }
int main(int argc, char **argv) { int optch = -1; struct sig_context *scp = NULL; struct xcl_context *xcp = NULL; const char *sigs_opt = NULL; f_log = stderr; lem_do_wrapup = 1; if (verbose) ng_debug = 1; scp = sig_context_init(); while (-1 != (optch = getopt(argc, argv, "c:dino::ps:tvx:"))) { switch (optch) { case 'c': config_file = optarg; break; case 'd': sig_dump = 1; break; case 'i': inplace = 1; break; case 'n': new_lem = 1; break; case 'o': if (optarg) { if ((outfp = fopen(optarg,"wb"))) out_file = optarg; else { fprintf(stderr, "lemmer: can't write to `%s'\n", optarg); exit(1); } } else outfp = stdout; break; case 'p': psu = 1; break; case 's': sigs_opt = optarg; break; case 't': textmode = 1; break; case 'x': xcl_file = optarg; break; case 'v': ++verbose; break; case 'w': lem_do_wrapup = 0; break; default: break; } } nl_init(); ngramify_init(); if (textmode) { char buf[128]; while (NULL != fgets(buf, 128, stdin)) { if ('\n' == buf[strlen(buf)-1]) { } else { fprintf(stderr, "lemmer: buf overflow at %s\n", buf); exit(1); } } } else if (xcl_file) { xcp = xcl_load(xcl_file, XCL_LOAD_SANS_SIGSETS); xcp->sigs = scp; scp->xcp = xcp; textid = xcp->textid; scp->xpd = xpd_init(xcp->project,xcp->pool); if (sigs_opt) sig_context_register(scp,sigs_opt,NULL,0); else sig_context_langs(scp,xcp->langs); if (new_lem) sig_new(xcp); else sig_check(xcp); if (psu) { xcp->linkbase = new_linkbase(); xcp->linkbase->textid = textid; psus2(xcp); } if (lem_do_wrapup) xcl_map(xcp,NULL,NULL,NULL,ilem_wrapup); if (outfp) { x2_serialize(xcp,outfp,1); fclose(outfp); } xcl_destroy(&xcp); } sig_context_term(); xcl_final_term(); return 0; }
static char * readtty(const char *pr, char *src) { char canonb[LINESIZE]; char *cp, *cp2; int c; #ifdef TIOCSTI char ch; #endif (void)fputs(pr, stdout); (void)fflush(stdout); if (src != NULL && strlen(src) > sizeof(canonb) - 2) { (void)printf("too long to edit\n"); return src; } #ifndef TIOCSTI if (src != NULL) cp = copy(src, canonb); else cp = copy(__UNCONST(""), canonb); c = *cp; (void)fputs(canonb, stdout); (void)fflush(stdout); #else cp = src == NULL ? __UNCONST("") : src; while ((c = *cp++) != '\0') { if ((c_erase != _POSIX_VDISABLE && c == c_erase) || (c_kill != _POSIX_VDISABLE && c == c_kill)) { ch = '\\'; (void)ioctl(0, TIOCSTI, &ch); } ch = c; (void)ioctl(0, TIOCSTI, &ch); } cp = canonb; *cp = '\0'; #endif clearerr(stdin); cp2 = cp; while (cp2 < canonb + sizeof(canonb) - 1) { c = getc(stdin); sig_check(); if (c == EOF) { if (feof(stdin)) (void)putc('\n', stdout); break; } if (c == '\n') break; *cp2++ = c; } *cp2 = '\0'; if (c == EOF && ferror(stdin)) { cp = strlen(canonb) > 0 ? canonb : NULL; clearerr(stdin); return readtty(pr, cp); } #ifndef TIOCSTI if (cp == NULL || *cp == '\0') return src; if (ttyset == 0) return strlen(canonb) > 0 ? savestr(canonb) : NULL; /* * Do erase and kill. */ cp2 = cp; while (*cp != '\0') { c = *cp++; if (c_erase != _POSIX_VDISABLE && c == c_erase) { if (cp2 == canonb) continue; if (cp2[-1] == '\\') { cp2[-1] = c; continue; } cp2--; continue; } if (c_kill != _POSIX_VDISABLE && c == c_kill) { if (cp2 == canonb) continue; if (cp2[-1] == '\\') { cp2[-1] = c; continue; } cp2 = canonb; continue; } *cp2++ = c; } *cp2 = '\0'; #endif if (canonb[0] == '\0') return __UNCONST(""); return savestr(canonb); }
/* * Read all relevant header fields. * Returns 0 on success; 1 if there was an error or signal. */ PUBLIC int grabh(struct header *hp, int gflags) { sig_t volatile old_sigint; int retval; #ifndef USE_EDITLINE struct termios ttybuf; # if defined(TIOCSTI) && defined(TIOCEXT) int extproc; # endif if (save_erase_and_kill(&ttybuf)) return -1; # if defined(TIOCSTI) && defined(TIOCEXT) extproc = ((ttybuf.c_lflag & EXTPROC) ? 1 : 0); if (extproc) { int flag; flag = 0; if (ioctl(fileno(stdin), TIOCEXT, &flag) == -1) warn("TIOCEXT: off"); } # endif #endif /* USE_EDITLINE */ sig_check(); old_sigint = sig_signal(SIGINT, tty_sigint); /* return here if we detect a SIGINT */ if ((retval = setjmp(tty_jmpbuf)) != 0) { (void)putc('\n', stdout); goto out; } /* * Do this irrespective of whether the initial string is empty. * Otherwise, the editing is inconsistent. */ disable_erase_and_kill(&ttybuf); if (gflags & GTO) { hp->h_to = extract(readtty("To: ", detract(hp->h_to, 0)), GTO); } if (gflags & GSUBJECT) { hp->h_subject = readtty("Subject: ", hp->h_subject); } if (gflags & GCC) { hp->h_cc = extract(readtty("Cc: ", detract(hp->h_cc, 0)), GCC); } if (gflags & GBCC) { hp->h_bcc = extract(readtty("Bcc: ", detract(hp->h_bcc, 0)), GBCC); } if (gflags & GSMOPTS) { hp->h_smopts = shextract(readtty("Smopts: ", detract(hp->h_smopts, 0)), GSMOPTS); } #ifdef MIME_SUPPORT if (gflags & GSMOPTS) { /* XXX - Use a new flag for this? */ if (hp->h_attach) { struct attachment *ap; int i; i = 0; for (ap = hp->h_attach; ap; ap = ap->a_flink) i++; (void)printf("Attachment%s: %d\n", i > 1 ? "s" : "", i); } } #endif out: restore_erase_and_kill(&ttybuf); #ifndef USE_EDITLINE # if defined(TIOCSTI) && defined(TIOCEXT) if (extproc) { int flag; flag = 1; if (ioctl(fileno(stdin), TIOCEXT, &flag) == -1) warn("TIOCEXT: on"); } # endif #endif (void)sig_signal(SIGINT, old_sigint); sig_check(); return retval; }