void system_server(DiscoverFnTy fn_discovery, int fd1, int fd2) { struct syserv_mesg mesg; fdin = fd1; fdout = fd2; inbuf_size = INIT_INBUF_SIZE; inbuf = (char *) malloc(inbuf_size); if (inbuf == NULL) { err(1, "malloc for inbuf failed"); } signal_handler_init(); for (;;) { int ret = read_mesg(&mesg); // failure on read from pipe if (ret == FAILURE) { err(1, "read from fdin failed"); } // exit if (ret == END_OF_FILE || mesg.type == SYSERV_EXIT) { break; } // ack if (mesg.type == SYSERV_ACK) { write_mesg(SYSERV_ACK, 0); } // query else if (mesg.type == SYSERV_QUERY) { write_mesg(SYSERV_ACK, 0); do_query(fn_discovery, &mesg); } // unknown message else { err(1, "unknown mesg type from client: %d", mesg.type); } } exit(0); }
int main(void) { char *mesg; setprogname("spam-2"); spaminit(); mesg = read_mesg(stdin); if (mesg == NULL) eprintf("Could not read message."); if (isspam(mesg)) printf("spam\n"); else printf("not spam\n"); free(mesg); return 0; }