int client_thread_kill(struct conn_element_st *ce){ /* * This function is what is passed to conn_element_init4(). */ int status = 0; void *pthread_status; char *nameorip; nameorip = conn_element_get_nameorip(ce); /* * If the thread loop function calls get_quit_flag() then it is not * necessary to call pthread_cancel for the final termination. But in cases * in which the server wants to terminate the thread early due to * errors this is the only way to notify the client thread. */ status = pthread_cancel((ce->threadinfo)->thread_id); if((status != 0) && (status != ESRCH)) log_errx("Error %d canceling client thread %s.", status, nameorip); status = pthread_join((ce->threadinfo)->thread_id, &pthread_status); if(status != 0) log_errx("Error %d joining client thread %s.", status, nameorip); else if(pthread_status == PTHREAD_CANCELED) log_info("Canceled client thread %s.", nameorip); else if(pthread_status == NULL) log_info("Finished client thread %s.", nameorip); return(0); }
static void tnt_priv_drop(struct passwd *pw) { struct stat ss; /* Heil! */ /* All this part is a preparation to the privileges dropping */ if (stat(pw->pw_dir, &ss) == -1) log_err(1, "%s", pw->pw_dir); if (ss.st_uid != 0) log_errx(1, "_tnetacle's home has unsafe owner"); if ((ss.st_mode & (S_IWGRP | S_IWOTH)) != 0) log_errx(1, "_tnetacle's home has unsafe permissions"); if (chroot(pw->pw_dir) == -1) log_err(1, "%s", pw->pw_dir); if (chdir("/") == -1) log_err(1, "%s", pw->pw_dir); /* * TODO: * if debug is not set dup stdin, stdout and stderr to /dev/null */ if (setgroups(1, &pw->pw_gid) == -1) log_err(1, "can't drop privileges (setgroups)"); #ifdef HAVE_SETRESXID if (setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) == -1) log_err(1, "can't drop privileges (setresgid)"); if (setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) == -1) log_err(1, "can't drop privileges (setresuid)"); #else /* Fallback to setuid, but it might not work */ if (setgid(pw->pw_gid) == -1) log_err(1, "can't drop privileges (setgid)"); if (setuid(pw->pw_uid) == -1) log_err(1, "can't drop privileges (setuid)"); #endif }
static struct pdu * text_receive(struct connection *conn) { struct pdu *response; struct iscsi_bhs_text_response *bhstr; response = pdu_new(conn); pdu_receive(response); if (response->pdu_bhs->bhs_opcode != ISCSI_BHS_OPCODE_TEXT_RESPONSE) log_errx(1, "protocol error: received invalid opcode 0x%x", response->pdu_bhs->bhs_opcode); bhstr = (struct iscsi_bhs_text_response *)response->pdu_bhs; #if 0 if ((bhstr->bhstr_flags & BHSTR_FLAGS_FINAL) == 0) log_errx(1, "received Text PDU without the \"F\" flag"); #endif /* * XXX: Implement the C flag some day. */ if ((bhstr->bhstr_flags & BHSTR_FLAGS_CONTINUE) != 0) log_errx(1, "received Text PDU with unsupported \"C\" flag"); if (ntohl(bhstr->bhstr_statsn) != conn->conn_statsn + 1) { log_errx(1, "received Text PDU with wrong StatSN: " "is %u, should be %u", ntohl(bhstr->bhstr_statsn), conn->conn_statsn + 1); } conn->conn_statsn = ntohl(bhstr->bhstr_statsn); return (response); }
static image_t *read_image_from_file(toc_entry_t *toc_entry, char *filename) { struct stat st; image_t *image; FILE *fp; fp = fopen(filename, "r"); if (fp == NULL) log_err("fopen %s", filename); if (fstat(fileno(fp), &st) == -1) log_errx("fstat %s", filename); image = malloc(sizeof(*image)); if (image == NULL) log_err("malloc"); memcpy(&image->uuid, &toc_entry->uuid, sizeof(uuid_t)); image->buffer = malloc(st.st_size); if (image->buffer == NULL) log_err("malloc"); if (fread(image->buffer, 1, st.st_size, fp) != st.st_size) log_errx("Failed to read %s", filename); image->size = st.st_size; image->toc_entry = toc_entry; fclose(fp); return image; }
static image_t *read_image_from_file(const uuid_t *uuid, const char *filename) { struct BLD_PLAT_STAT st; image_t *image; FILE *fp; assert(uuid != NULL); assert(filename != NULL); fp = fopen(filename, "rb"); if (fp == NULL) log_err("fopen %s", filename); if (fstat(fileno(fp), &st) == -1) log_errx("fstat %s", filename); image = xzalloc(sizeof(*image), "failed to allocate memory for image"); image->toc_e.uuid = *uuid; image->buffer = xmalloc(st.st_size, "failed to allocate image buffer"); if (fread(image->buffer, 1, st.st_size, fp) != st.st_size) log_errx("Failed to read %s", filename); image->toc_e.size = st.st_size; fclose(fp); return image; }
void slavenet_kill_thread(struct slave_element_st *slave){ /* * This comment is adapted from the reader.c for np channels. * * This "joins" the nbs reader thread. Normally it quits * in their loop when they check the quit flag. But if a reader * is waiting on a channel without data, it can wait for the * g.tmout_readbroadcast_s timeout and that may be too long. * Therefore we "cancel" them. It is possible that some of them * have already quit by the time we send them the cancelation request, * and in that case pthread_cancel returns ESRCH. */ int status; void *pthread_status; if(slave->f_slave_thread_created == 0) return; /* * log_info("Canceling slave thread."); */ status = pthread_cancel(slave->slave_thread_id); if((status != 0) && (status != ESRCH)) log_errx("Error %d canceling slave thread %s:%s.", status, slave->mastername, slave->masterport); status = pthread_join(slave->slave_thread_id, &pthread_status); if(status != 0) log_errx("Error %d joining slave thread.", status); else if(pthread_status == PTHREAD_CANCELED) log_info("Cancelled slave thread."); else if(pthread_status == NULL) log_info("Finished slave thread %s:%s.", slave->mastername, slave->masterport); }
struct chap * chap_new(void) { struct chap *chap; int rv; chap = calloc(sizeof(*chap), 1); if (chap == NULL) log_err(1, "calloc"); /* * Generate the challenge. */ rv = RAND_bytes(chap->chap_challenge, sizeof(chap->chap_challenge)); if (rv != 1) { log_errx(1, "RAND_bytes failed: %s", ERR_error_string(ERR_get_error(), NULL)); } rv = RAND_bytes(&chap->chap_id, sizeof(chap->chap_id)); if (rv != 1) { log_errx(1, "RAND_bytes failed: %s", ERR_error_string(ERR_get_error(), NULL)); } return (chap); }
/* * slot read functions */ static int _nbsp_mspoolbdb_open(struct mspoolbdb_st *mspool, char *fpath){ /* * Returns: * * -1 => error other than DB_NOTFOUND * -2 => not found in bdb (DB_NOTFOUND) * sd >= 0 */ int sd = -1; int status; char fkey[FKEY_SPOOLBDB_SIZE + 1]; status = get_fpath_key(fpath, fkey); assert(status == 0); if(status != 0) return(-1); status = mspoolbdb_slots_open(mspool, fkey, &sd); if(status != 0){ if(status == DB_NOTFOUND){ log_errx("%s[%s] not found in mspoolbdb.", fpath, fkey); return(-2); }else{ log_errx("Cannot open read slot in mspoolbdb for %s[%s]: %s", fpath, fkey, db_strerror(status)); return(-1); } } return(sd); }
int nbsp_cspoolbdb_create(void){ int status; int f_rdonly = 0; /* set the DB_CREATE flag to the underlying db */ int f_mpool_nofile = 0; if(spooltype_cspool() == 0){ log_errx("Invalid value of spooltype in nbsp_cspoolbdb_create()"); return(-1); } f_mpool_nofile = 0; if(spooltype_cspool_nofile()) f_mpool_nofile = 1; status = cspoolbdb_create(&g.cspoolbdb, g.cspoolbdb_dir, g.cspoolbdb_mode, g.cspoolbdb_dbcache_mb, g.cspoolbdb_maxsize_per128, g.cspoolbdb_name, g.cspoolbdb_mode, g.cspoolbdb_ndb, g.cspoolbdb_nslots, f_mpool_nofile, f_rdonly); if(status != 0){ log_errx("Cannot create spool cache bdb. %s", db_strerror(status)); return(-1); } return(0); }
int main(int argc, char **argv){ char *optstr = "bClqtc:"; char *usage = "nbspradinfo [-b] [-c <count> | -C] [-l] [-q] [-t] " "<file> | < file"; int status = 0; int c; int opt_cC = 0; /* c and C together is a conflict */ set_progname(basename(argv[0])); while((status == 0) && ((c = getopt(argc, argv, optstr)) != -1)){ switch(c){ case 'b': g.opt_background = 1; break; case 'l': g.opt_lengthonly = 1; break; case 'q': g.opt_quiet_invalid_pdb = 1; break; case 't': g.opt_timeonly = 1; break; case 'C': ++opt_cC; g.opt_skipcount = CCB_SIZE; break; case 'c': ++opt_cC; status = strto_int(optarg, &g.opt_skipcount); if((status == 1) || (g.opt_skipcount <= 0)){ log_errx(1, "Invalid argument to [-c] option."); } break; default: log_info(usage); exit(0); break; } } if(opt_cC > 1) log_errx(1, "Invalid combination of options: c and C."); if(g.opt_background == 1) set_usesyslog(); if(optind < argc - 1) log_errx(1, "Too many arguments."); else if(optind == argc - 1) g.opt_inputfile = argv[optind++]; atexit(cleanup); status = process_file(); return(status != 0 ? 1 : 0); }
int loop(void){ int i; int status = 0; struct emwin_server *es; es = get_next_server(); if(es == NULL){ status = 1; log_errx("No servers available."); log_info("Waiting %d seconds.", g.retrysleep); for(i = 0; i <= g.retrysleep; ++i){ sleep(1); if(get_quit_flag() != 0) break; } log_info("Trying server list again."); }else if(es->fd == -1){ if(es->gai_code != 0){ log_errx("Cannot open connection to %s. %s", es->ip, gai_strerror(es->gai_code)); }else{ log_err2("Cannot open connection to", es->ip); } status = 1; }else if(es->fd == -2){ if(server_type_serial_device(es)) log_errx("Cannot configure or synchronize %s:%s", es->ip, es->port); else log_errx("Could not get packet from %s", es->ip); status = 1; }else{ log_info("Connected to %s @ %s", es->ip, es->port); } while((status == 0) && (get_quit_flag() == 0)){ if(g.f_server_enabled == 1) server_loop(); status = process_packets(es); periodic(); if(get_reload_servers_list_flag()) reload_servers_list(); if(get_send_bbclientid_flag()) bb_send_clientid(es); } if(get_quit_flag() != 0) log_info("Closing processor."); return(status); }
static int _nbsp_mspoolbdb_insert(struct mspoolbdb_st *mspool, char *fpath, void *fdata, size_t fdata_size){ int status; char fkey[FKEY_SPOOLBDB_SIZE + 1]; status = get_fpath_key(fpath, fkey); assert(status == 0); if(status != 0) return(-1); if(fdata_size > (size_t)UINT32_MAX){ log_errx("Cannot insert %s in mspoolbdb. Data size too large.", fpath); return(-1); } status = mspoolbdb_insert(mspool, fkey, fdata, (uint32_t)fdata_size); if(status == ENOMEM){ log_errx("Trying to make room for %s[%u bytes] in mspoolbdb.", fkey, fdata_size); /* * Try a two-step recovery. First truncate the oldest db, and if that * is not enough try truncating all of them. This procesure assumes * that the reason for the error is a bdb memory error (status == ENOMEM) * and that releasing some memory solves the problem. */ status = mspoolbdb_truncate_oldest(mspool); if(status == 0) status = mspoolbdb_insert(mspool, fkey, fdata, (uint32_t)fdata_size); if(status == 0) log_info("Truncated oldest db in mspoolbdb. Inserted %s.", fkey); } if(status == ENOMEM){ status = mspoolbdb_truncate(mspool); if(status == 0) status = mspoolbdb_insert(mspool, fkey, fdata, (uint32_t)fdata_size); if(status == 0) log_info("Truncated mspoolbdb completely. Inserted %s.", fkey); } if(status != 0){ if(status == ENOMEM) log_errx("Droping %s in mspoolbdb: %s", fkey, db_strerror(status)); else log_errx("Error inserting %s in mspoolbdb: %s", fkey, db_strerror(status)); return(-1); } /* log_verbose(2, "nbsp_mspoolbdb_insert(): inserted %s", fkey); */ return(0); }
int write_file_info(char *in_file){ /* * This function extracts and prints (to stdout) the information * from the nesdis pdb that is used by the filters. It tries to * detect if the input file is compresed (in the gempak-like form * with a wmo and the compressed frames appended one after the other. * If the file is compressed, then there is a plain text wmo. Then * comes the first compressed frame, which contains the wmo * and the pdb after it is uncompressed. */ int fd; struct nesdis_pdb_st npdb; int status = 0; if(in_file != NULL){ fd = open(in_file, O_RDONLY); if(fd == -1){ log_err(1, "Could not open %s", in_file); return(-1); } }else fd = fileno(stdin); status = read_nesdis_pdb_compressed(fd, &npdb); if(in_file != NULL){ close(fd); } if(status == -1){ if(in_file != NULL) log_err(1, "Error reading from %s", in_file); else log_err(1, "Error reading from stdin."); return(-1); }else if(status != 0){ if(in_file != NULL) log_warnx("Error reading pdb from %s:", in_file); if(status == 1) log_errx(1, "File too short."); else if(status == 2) log_errx(1, "Invalid wmo header."); else if(status == 3) log_errx(1, "Error from zlib."); else log_errx(1, "Undocumented error from read_nesdis_pdb_compressed()"); return(1); } output(&npdb, g.opt_extended_info); return(0); }
static int eupdate_activepce(struct nbs1_packet_st *nbs){ /* * This function updates the active pce. * * Returns: * 0 if there are no errors. * 1 if the element (seqnumber) is not in the control list. * 2 if the block has jumped the block number (missing blocks) * -1 a memory or write error msave_nbs_block */ int status = 0; struct pctl_element_st *pce; /* * This function updates the frame counter, checking that the received * frame is the next one in the sequence, and the next function * saves the frame in the product mfile. * * NOTE: The last argument of this function assumes a zero-based * block_number (as in the noaaport frames). Since we are using * a 1-based block number we substract 1. */ status = update_activepce_framecounter(g.pctl, nbs->slavenbs_reader_index, nbs->seq_number, nbs->block_number - 1); if(status == 1){ log_verbose(3, "PROGRESS: %u is not active.", nbs->seq_number); return(1); }else if(status == 2){ pce = get_pctl_activepce(g.pctl, nbs->slavenbs_reader_index, nbs->seq_number); if(pce != NULL){ log_errx("Missing frames for %s[%d]: %d -> %d of %d: [z=%d]", pce->fname, pce->np_channel_index, pce->recv_fragments - 1, nbs->block_number, pce->num_fragments, nbs->f_zip); }else log_errx("Missing frames for %u.", nbs->seq_number); }else if(status == -1){ log_err2u("Could not update", nbs->seq_number); } if(status == 0) status = msave_nbs_block(nbs); if(status != 0){ update_stats_products_missed(); close_pctl_activepce(g.pctl, nbs->slavenbs_reader_index); } return(status); }
static char *slave_make_configuration_string(void){ /* * This function should be called after calling * feedmode_inputfifo_enabled(), and if that function returns 1. * It will then add the infifo configuration to the masterservers list. */ char *r; int n; if(valid_str(g.infifo) == 0){ /* * This should have been caught already by the caller of this function */ log_errx("Invalid setting of infifo."); return(NULL); } /* Leave room for 3, */ n = strlen(g.infifo) + 1 + strlen(SLAVE_STRING_JOIN2); if(feedmode_masterservers_enabled()){ if(valid_str(g.masterservers) == 0){ /* * This should have been caught already by the caller of this function */ log_errx("Invalid setting of masterservers."); return(NULL); } /* Leave room for the SEP1 char */ n += strlen(g.masterservers) + strlen(SLAVE_STRING_JOIN1); } r = malloc(n + 1); if(r == NULL) return(NULL); if(feedmode_masterservers_enabled()){ if(snprintf(r, n + 1, "3%s%s%s%s", SLAVE_STRING_JOIN2, g.infifo, SLAVE_STRING_JOIN1, g.masterservers) != n){ log_errx("Configuration error in slave_make_configuration_string()."); free(r); return(NULL); } }else{ if(snprintf(r, n + 1, "3%s%s", SLAVE_STRING_JOIN2, g.infifo) != n){ log_errx("Configuration error in slave_make_configuration_string()."); free(r); return(NULL); } } return(r); }
int wait_qrunner(void){ /* * This function is called from periodic(). * * Returns: * 0 => A qrunner is still running * -1 => No qrunner running. * > 0 => Just caught a qrunner exiting. */ pid_t pid = 0; int wait_status = 0; int exit_status = 0; int signo = 0; if(g.qrunner_pid < 0) return(-1); pid = waitpid(g.qrunner_pid, &wait_status, WNOHANG); if(pid <= 0) return(pid); /* * log_info("A child was awaited."); */ if(WIFEXITED(wait_status)) exit_status = WEXITSTATUS(wait_status); else if(WIFSIGNALED(wait_status)){ exit_status = 1; signo = WTERMSIG(wait_status); /* signal number */ } if(exit_status != 0){ if(signo != 0){ if(g.qrunner_pid == pid) log_errx("%s exited abnormally with signal %d.", g.qrunner, signo); else log_errx("%u exited abnormally with signal %d.", (unsigned int)pid, signo); }else{ if(g.qrunner_pid == pid) log_errx("%s exited with error %d.", g.qrunner, exit_status); else log_errx("%u exited with error %d.", (unsigned int)pid, exit_status); } } if(pid == g.qrunner_pid) g.qrunner_pid = -1; return(pid); }
void log_set_peer_name(const char *name) { /* * XXX: Turn it into assertion? */ if (peer_name != NULL) log_errx(1, "%s called twice", __func__); if (peer_addr == NULL) log_errx(1, "%s called before log_set_peer_addr", __func__); peer_name = checked_strdup(name); }
void pdu_send(struct pdu *pdu) { struct connection *conn; ssize_t ret, total_len; size_t padding; uint32_t zero = 0; struct iovec iov[3]; int iovcnt; conn = pdu->pdu_connection; #ifdef ICL_KERNEL_PROXY if (conn->conn_conf.isc_iser != 0) return (pdu_send_proxy(pdu)); #endif assert(conn->conn_conf.isc_iser == 0); pdu_set_data_segment_length(pdu, pdu->pdu_data_len); iov[0].iov_base = pdu->pdu_bhs; iov[0].iov_len = sizeof(*pdu->pdu_bhs); total_len = iov[0].iov_len; iovcnt = 1; if (pdu->pdu_data_len > 0) { iov[1].iov_base = pdu->pdu_data; iov[1].iov_len = pdu->pdu_data_len; total_len += iov[1].iov_len; iovcnt = 2; padding = pdu_padding(pdu); if (padding > 0) { assert(padding < sizeof(zero)); iov[2].iov_base = &zero; iov[2].iov_len = padding; total_len += iov[2].iov_len; iovcnt = 3; } } ret = writev(conn->conn_socket, iov, iovcnt); if (ret < 0) { if (timed_out()) log_errx(1, "exiting due to timeout"); log_err(1, "writev"); } if (ret != total_len) log_errx(1, "short write"); }
int nbsp_open_dbenv(void){ DB_ENV *dbenv = NULL; int status = 0; uint32_t mb; uint32_t dbenv_flags = DBENV_FLAGS; mb = (1024 * 1024) * g.dbcache_mb; status = db_env_create(&dbenv, 0); if(status == 0) status = dbenv->set_cachesize(dbenv, 0, mb, 0); if(status == 0) status = dbenv->open(dbenv, g.dbhome, dbenv_flags, g.dbfile_mode); if(status != 0){ log_errx("Cannot initialize db environment. %s", db_strerror(status)); status = -1; if(dbenv != NULL) (void)dbenv->close(dbenv, 0); }else g.dbenv = dbenv; return(status); }
/* output functions */ static void gini_shp_write(struct dcgini_st *dcg){ char *shpfile = NULL; char *shxfile = NULL; if(g.opt_shpfile != NULL) shpfile = g.opt_shpfile; else if(g.opt_shp != 0){ if(g.opt_basename != NULL) shpfile = dcgini_optional_name(g.opt_basename, DCGINI_SHPEXT); else shpfile = dcgini_default_name(&dcg->pdb, NULL, DCGINI_SHPEXT); if(shpfile == NULL) log_err(1, "dcgini_xxx_name()"); } if(g.opt_shxfile != NULL) shxfile = g.opt_shxfile; else if(g.opt_shx != 0){ if(g.opt_basename != NULL) shxfile = dcgini_optional_name(g.opt_basename, DCGINI_SHXEXT); else shxfile = dcgini_default_name(&dcg->pdb, NULL, DCGINI_SHXEXT); if(shxfile == NULL) log_err(1, "dcgini_xxx_name()"); } if(dcgini_shp_write(shpfile, shxfile, &dcg->pointmap) != 0) log_errx(1, "Error in dcgini_shp_write_data()"); }
void log_err2_db(char *s1, char *s2, int dberror){ if(dberror == 0) log_err2(s1, s2); else log_errx("%s %s. %s", s1, s2, db_strerror(dberror)); }
static void loop(struct conn_element_st *ce){ /* * The only job of this function is to read from the ce->cq, and * write to the ce->fd client file descriptor. The *data returned * points to a reusable internal storage in the ce->cq, and * should not be free()'d explicitly. It is released when the * main thread deletes the client from the table. */ int status; int dberror; void *data = NULL; uint32_t data_size; int timeout_ms = conn_element_get_queue_read_timeout_ms(ce); /* * The nbs1 and nbs2 threads receive the packetinfo->packet while * the emwin threads receive a "struct emwin_queue_info_st". */ status = connqueue_rcv(ce->cq, &data, &data_size, timeout_ms, &dberror); if(status == -1) log_err2_db("Error reading from queue for %s.", conn_element_get_nameorip(ce), dberror); else if(status == 1) log_errx("No data in queue for %s.", conn_element_get_nameorip(ce)); if(status != 0) return; status = send_client(ce, data, data_size); if(status != 0){ conn_stats_update_errors(&ce->cs); conn_element_set_exit_flag(ce); } }
static int send_client1(struct conn_element_st *ce, void *data, uint32_t data_size){ int protocol; int status = 0; /* * Find out what type of client this thread is serving and dispatch * accordingly. */ protocol = get_client_protocol_byce(ce); if(protocol == PROTOCOL_NBS1) status = send_nbs1_client(ce, data, data_size); else if(protocol == PROTOCOL_NBS2) status = send_nbs2_client(ce, data, data_size); else if(protocol == PROTOCOL_EMWIN) status = send_emwin_client(ce, (struct emwin_queue_info_st*)data, data_size); else { log_errx("Server client thread running with unknown client protocol."); return(1); } if(status != 0) conn_stats_update_errors(&ce->cs); return(status); }
static int bbserver_open(void){ if(valid_str(g.bbserver) == 0){ log_errx("No bbserver registrar defined."); return(1); } g.bbserverfp = popen(g.bbserver, "w"); if(g.bbserverfp != NULL){ if(fprintf(g.bbserverfp, "%s\n", "init") < 0){ (void)pclose(g.bbserverfp); g.bbserverfp = NULL; } } if(g.bbserverfp != NULL){ if(fflush(g.bbserverfp) != 0){ (void)pclose(g.bbserverfp); g.bbserverfp = NULL; } } if(g.bbserverfp == NULL){ log_err("Could not start bbserver registrar."); return(-1); }else log_info("Started bbserver registrar."); return(0); }
void isns_req_add_addr(struct isns_req *req, uint32_t tag, struct addrinfo *ai) { struct sockaddr_in *in4; struct sockaddr_in6 *in6; uint8_t buf[16]; switch (ai->ai_addr->sa_family) { case AF_INET: in4 = (struct sockaddr_in *)(void *)ai->ai_addr; memset(buf, 0, 10); buf[10] = 0xff; buf[11] = 0xff; memcpy(&buf[12], &in4->sin_addr, sizeof(in4->sin_addr)); isns_req_add(req, tag, sizeof(buf), buf); break; case AF_INET6: in6 = (struct sockaddr_in6 *)(void *)ai->ai_addr; isns_req_add(req, tag, sizeof(in6->sin6_addr), &in6->sin6_addr); break; default: log_errx(1, "Unsupported address family %d", ai->ai_addr->sa_family); } }
int httpd_open(void){ if(g.httpd_enable == 0) return(0); if(valid_str(g.httpd) == 0){ log_errx("No httpd defined."); return(1); } ghttpd_fp = popen(g.httpd, "w"); if(ghttpd_fp != NULL){ if(fprintf(ghttpd_fp, "%s\n", "init") < 0){ (void)pclose(ghttpd_fp); ghttpd_fp = NULL; } } if(ghttpd_fp == NULL){ log_err("Could not start httpd server."); return(-1); }else log_info("Started httpd."); return(0); }
static void nids_csv_write(struct nids_data_st *nd){ /* * Output the polygon data. */ char *csvfile; FILE *fp; struct dcnids_polygon_map_st *pm = &nd->polygon_map; if(g.opt_csvfile != NULL) csvfile = g.opt_csvfile; else csvfile = nids_file_name(&nd->nids_header, g.opt_basename, DCNIDS_CSVEXT); if(csvfile == NULL) return; if(strcmp(csvfile, "-") == 0) fp = stdout; else fp = fopen(csvfile, "w"); if(dcnids_csv_write(fp, pm) != 0) log_errx(1, "Cannot write to csv file."); if(fp != stdout) fclose(fp); }
static void pdu_read(int fd, char *data, size_t len) { ssize_t ret; while (len > 0) { ret = read(fd, data, len); if (ret < 0) { if (timed_out()) log_errx(1, "exiting due to timeout"); log_err(1, "read"); } else if (ret == 0) log_errx(1, "read: connection lost"); len -= ret; data += ret; } }
/* * These are the functions called by main to launch and terminate * the slave threads. */ int init_slavet(void){ struct slave_table_st *slavet; struct slave_options_st defaults; char *conf_str = NULL; int status = 0; defaults.infifo_mode = g.infifo_mode; defaults.infifo_grp = g.infifo_grp; defaults.slavestatsfile = g.slavestatsfile; defaults.slave_masterport = g.slave_masterport; defaults.slave_read_timeout_secs = g.slave_read_timeout_secs; defaults.slave_read_timeout_retry = g.slave_read_timeout_retry; defaults.slave_reopen_timeout_secs = g.slave_reopen_timeout_secs; defaults.slave_so_rcvbuf = g.slave_so_rcvbuf; defaults.slave_stats_logperiod_secs = g.slave_stats_logperiod_secs; /* * Check both of these here once and for all */ if(feedmode_masterservers_enabled() && (valid_str(g.masterservers) == 0)){ log_errx("Slave mode enabled with masterservers unset."); return(-1); } if(feedmode_inputfifo_enabled() && (valid_str(g.infifo) == 0)){ log_errx("Input fifo mode enabled with invalid setting of infifo."); return(-1); } if(feedmode_inputfifo_enabled()){ conf_str = slave_make_configuration_string(); if(conf_str == NULL) return(-1); status = slave_table_create(&slavet, conf_str, &defaults); free(conf_str); }else status = slave_table_create(&slavet, g.masterservers, &defaults); if(status == 0) g.slavet = slavet; return(status); }
static int process_stdin_entry(void) { char *optstr = "c:f:gmno:p:s:v"; int status = 0; process_args(g.strp->argc, g.strp->argv, optstr, 0); if(optind < g.strp->argc - 1) log_errx(1, "Too many arguments."); else if(optind == g.strp->argc - 1) g.input_fname = g.strp->argv[optind++]; else log_errx(1, "Not enough arguments"); status = process_file(); return(status != 0 ? 1 : 0); }