/** * A circuit was just forcibly closed. If there has been no recent network * activity at all, but this circuit was launched back when we thought the * network was live, increment the number of "nonlive" circuit timeouts. * * This is used by circuit_build_times_network_check_live() to decide * if we should record the circuit build timeout or not. */ static void circuit_build_times_network_close(circuit_build_times_t *cbt, int did_onehop, time_t start_time) { time_t now = time(NULL); /* * Check if this is a timeout that was for a circuit that spent its * entire existence during a time where we have had no network activity. */ if (cbt->liveness.network_last_live < start_time) { if (did_onehop) { char last_live_buf[ISO_TIME_LEN+1]; char start_time_buf[ISO_TIME_LEN+1]; char now_buf[ISO_TIME_LEN+1]; format_local_iso_time(last_live_buf, cbt->liveness.network_last_live); format_local_iso_time(start_time_buf, start_time); format_local_iso_time(now_buf, now); log_warn(LD_BUG, "Circuit somehow completed a hop while the network was " "not live. Network was last live at %s, but circuit launched " "at %s. It's now %s.", last_live_buf, start_time_buf, now_buf); } cbt->liveness.nonlive_timeouts++; if (cbt->liveness.nonlive_timeouts == 1) { log_notice(LD_CIRC, "Tor has not observed any network activity for the past %d " "seconds. Disabling circuit build timeout recording.", (int)(now - cbt->liveness.network_last_live)); } else { log_info(LD_CIRC, "Got non-live timeout. Current count is: %d", cbt->liveness.nonlive_timeouts); } } }
static void delete_files(gpointer data, gpointer void_preserve_list) { double cap_size; const char *dir = parse_size_pfx(&cap_size, data); GList *preserve_files_list = void_preserve_list; unsigned count = 100; while (--count != 0) { GList *worst_file_list = NULL; double cur_size = get_dir_size(dir, &worst_file_list, preserve_files_list); if (cur_size <= cap_size || !worst_file_list) { list_free_with_free(worst_file_list); log_info("cur_size:%.0f cap_size:%.0f, no (more) trimming", cur_size, cap_size); break; } /* Invert the list, so that largest/oldest file is first */ worst_file_list = g_list_reverse(worst_file_list); /* And delete (some of) them */ while (worst_file_list && cur_size > cap_size) { struct name_and_size *ns = worst_file_list->data; log_notice("%s is %.0f bytes (more than %.0f MB), deleting '%s' (%llu bytes)", dir, cur_size, cap_size / (1024*1024), ns->name, (long long)ns->size); if (unlink(ns->name) != 0) perror_msg("Can't unlink '%s'", ns->name); else cur_size -= ns->size; free(ns); worst_file_list = g_list_delete_link(worst_file_list, worst_file_list); } } }
int exp_is_true(exp_t *exp, var_t *mailspec) { var_t *v; int r; if (exp == NULL) { return 1; } v = exp_eval(exp, mailspec); if (v == NULL) { log_notice("exp_is_true: evaluation failed"); return -1; } r = var_true(v); exp_free(v); return r; }
static void foreach_reported_to_line(const char *reported_to, foreach_reported_to_line_cb_type callback, void *user_data) { const char *p = reported_to; unsigned lineno = 0; while (*p) { ++lineno; const char *record = p; const char *record_label_end = strchrnul(p, ':'); const size_t label_len = record_label_end - p; const char *record_end = strchrnul(p, '\n'); p = record_end + (record_end[0] != '\0'); if (label_len == 0 || record_label_end[0] == '\0' || record_end < record_label_end) { log_notice("Miss formatted 'reported_to' record on line %d", lineno); continue; } callback(record, label_len, user_data); } }
static void gd_shutdown(int sig) { int i; // notify threads, join them, then exit running = 0; for (i=0; i<proc_nthreads; i++){ pthread_mutex_destroy(&subframe_mutex[i]); pthread_cond_destroy(&subframe_cond[i]); } for (i = 0; i < trans_nthreads; i++) { pthread_join(trans_threads[i], NULL); } for (i = 0; i < proc_nthreads; i++) { pthread_join(proc_threads[i], NULL); } log_notice("Received shutdown signal ...\n"); exit(-1); }
void load_workflow_description_from_file(workflow_t *workflow, const char* filename) { log_notice("loading workflow: '%s'", filename); struct my_parse_data parse_data = { workflow, NULL, NULL, 0, 0, 0}; parse_data.cur_locale = xstrdup(setlocale(LC_ALL, NULL)); strchrnul(parse_data.cur_locale, '.')[0] = '\0'; GMarkupParser parser; memset(&parser, 0, sizeof(parser)); /* just in case */ parser.start_element = &start_element; parser.end_element = &end_element; parser.text = &text; parser.passthrough = &passthrough; parser.error = &error; GMarkupParseContext *context = g_markup_parse_context_new( &parser, G_MARKUP_TREAT_CDATA_AS_TEXT, &parse_data, /*GDestroyNotify:*/ NULL); FILE* fin = fopen(filename, "r"); if (fin != NULL) { size_t read_bytes; char buff[1024]; while ((read_bytes = fread(buff, 1, 1024, fin)) != 0) { g_markup_parse_context_parse(context, buff, read_bytes, NULL); } fclose(fin); } g_markup_parse_context_free(context); free(parse_data.attribute_lang); /* just in case */ free(parse_data.cur_locale); }
/* add_inode_to_lf - Add dir entry to lost+found for the inode * @ip: inode to add to lost + found * * This function adds an entry into the lost and found dir * for the given inode. The name of the entry will be * "lost_<ip->i_num.no_addr>". * * Returns: 0 on success, -1 on failure. */ int add_inode_to_lf(struct gfs2_inode *ip){ char tmp_name[256]; __be32 inode_type; struct gfs2_sbd *sdp = ip->i_sbd; int err = 0; uint32_t mode; make_sure_lf_exists(ip); if (ip->i_di.di_num.no_addr == lf_dip->i_di.di_num.no_addr) { log_err( _("Trying to add lost+found to itself...skipping")); return 0; } if (sdp->gfs1) mode = gfs_to_gfs2_mode(ip); else mode = ip->i_di.di_mode & S_IFMT; switch (mode) { case S_IFDIR: add_dotdot(ip); sprintf(tmp_name, "lost_dir_%llu", (unsigned long long)ip->i_di.di_num.no_addr); inode_type = (sdp->gfs1 ? GFS_FILE_DIR : DT_DIR); break; case S_IFREG: sprintf(tmp_name, "lost_file_%llu", (unsigned long long)ip->i_di.di_num.no_addr); inode_type = (sdp->gfs1 ? GFS_FILE_REG : DT_REG); break; case S_IFLNK: sprintf(tmp_name, "lost_link_%llu", (unsigned long long)ip->i_di.di_num.no_addr); inode_type = (sdp->gfs1 ? GFS_FILE_LNK : DT_LNK); break; case S_IFBLK: sprintf(tmp_name, "lost_blkdev_%llu", (unsigned long long)ip->i_di.di_num.no_addr); inode_type = (sdp->gfs1 ? GFS_FILE_BLK : DT_BLK); break; case S_IFCHR: sprintf(tmp_name, "lost_chrdev_%llu", (unsigned long long)ip->i_di.di_num.no_addr); inode_type = (sdp->gfs1 ? GFS_FILE_CHR : DT_CHR); break; case S_IFIFO: sprintf(tmp_name, "lost_fifo_%llu", (unsigned long long)ip->i_di.di_num.no_addr); inode_type = (sdp->gfs1 ? GFS_FILE_FIFO : DT_FIFO); break; case S_IFSOCK: sprintf(tmp_name, "lost_socket_%llu", (unsigned long long)ip->i_di.di_num.no_addr); inode_type = (sdp->gfs1 ? GFS_FILE_SOCK : DT_SOCK); break; default: sprintf(tmp_name, "lost_%llu", (unsigned long long)ip->i_di.di_num.no_addr); inode_type = (sdp->gfs1 ? GFS_FILE_REG : DT_REG); break; } err = dir_add(lf_dip, tmp_name, strlen(tmp_name), &(ip->i_di.di_num), inode_type); if (err) { log_crit(_("Error adding directory %s: %s\n"), tmp_name, strerror(errno)); exit(FSCK_ERROR); } /* This inode is linked from lost+found */ incr_link_count(ip->i_di.di_num, lf_dip, _("from lost+found")); /* If it's a directory, lost+found is back-linked to it via .. */ if (mode == S_IFDIR) incr_link_count(lf_dip->i_di.di_num, ip, _("to lost+found")); log_notice( _("Added inode #%llu (0x%llx) to lost+found\n"), (unsigned long long)ip->i_di.di_num.no_addr, (unsigned long long)ip->i_di.di_num.no_addr); gfs2_dinode_out(&lf_dip->i_di, lf_dip->i_bh->b_data); bwrite(lf_dip->i_bh); return 0; }
void do_bdr_unregister(void) { PGconn *conn = NULL; ExtensionStatus extension_status = REPMGR_UNKNOWN; int target_node_id = UNKNOWN_NODE_ID; t_node_info node_info = T_NODE_INFO_INITIALIZER; RecordStatus record_status = RECORD_NOT_FOUND; bool node_record_deleted = false; PQExpBufferData event_details; char *dbname; /* sanity-check configuration for BDR-compatability */ if (config_file_options.replication_type != REPLICATION_TYPE_BDR) { log_error(_("cannot run BDR UNREGISTER on a non-BDR node")); exit(ERR_BAD_CONFIG); } dbname = pg_malloc0(MAXLEN); if (dbname == NULL) { log_error(_("unable to allocate memory; terminating.")); exit(ERR_OUT_OF_MEMORY); } /* store the database name for future reference */ get_conninfo_value(config_file_options.conninfo, "dbname", dbname); conn = establish_db_connection(config_file_options.conninfo, true); if (!is_bdr_db(conn, NULL)) { log_error(_("database \"%s\" is not BDR-enabled"), dbname); PQfinish(conn); pfree(dbname); exit(ERR_BAD_CONFIG); } extension_status = get_repmgr_extension_status(conn, NULL); if (extension_status != REPMGR_INSTALLED) { log_error(_("repmgr is not installed on database \"%s\""), dbname); PQfinish(conn); pfree(dbname); exit(ERR_BAD_CONFIG); } pfree(dbname); if (!is_bdr_repmgr(conn)) { log_error(_("repmgr metadatabase contains records for non-BDR nodes")); PQfinish(conn); exit(ERR_BAD_CONFIG); } initPQExpBuffer(&event_details); if (runtime_options.node_id != UNKNOWN_NODE_ID) target_node_id = runtime_options.node_id; else target_node_id = config_file_options.node_id; /* Check node exists and is really a BDR node */ record_status = get_node_record(conn, target_node_id, &node_info); if (record_status != RECORD_FOUND) { log_error(_("no record found for node %i"), target_node_id); PQfinish(conn); exit(ERR_BAD_CONFIG); } begin_transaction(conn); log_debug("unregistering node %i", target_node_id); node_record_deleted = delete_node_record(conn, target_node_id); if (node_record_deleted == false) { appendPQExpBuffer(&event_details, "unable to delete node record for node \"%s\" (ID: %i)", node_info.node_name, target_node_id); rollback_transaction(conn); } else { appendPQExpBuffer(&event_details, "node record deleted for node \"%s\" (ID: %i)", node_info.node_name, target_node_id); commit_transaction(conn); } /* Log the event */ create_event_notification( conn, &config_file_options, config_file_options.node_id, "bdr_unregister", true, event_details.data); PQfinish(conn); log_notice(_("bdr node \"%s\" (ID: %i) successfully unregistered"), node_info.node_name, target_node_id); termPQExpBuffer(&event_details); return; }
int main(int argc, char *argv[]) { struct gfs2_sbd sbd, *sdp = &sbd; int rindex_fd; int error = EXIT_SUCCESS; int devflags = (test ? O_RDONLY : O_RDWR) | O_CLOEXEC; setlocale(LC_ALL, ""); textdomain("gfs2-utils"); srandom(time(NULL) ^ getpid()); memset(sdp, 0, sizeof(struct gfs2_sbd)); sdp->bsize = GFS2_DEFAULT_BSIZE; sdp->rgsize = -1; sdp->jsize = GFS2_DEFAULT_JSIZE; sdp->qcsize = GFS2_DEFAULT_QCSIZE; sdp->md.journals = 1; decode_arguments(argc, argv, sdp); for(; (argc - optind) > 0; optind++) { struct metafs mfs = {0}; struct mntent *mnt; unsigned rgcount; unsigned old_rg_count; lgfs2_rgrps_t rgs; error = lgfs2_open_mnt(argv[optind], O_RDONLY|O_CLOEXEC, &sdp->path_fd, devflags, &sdp->device_fd, &mnt); if (error != 0) { fprintf(stderr, _("Error looking up mount '%s': %s\n"), argv[optind], strerror(errno)); exit(EXIT_FAILURE); } if (mnt == NULL) { fprintf(stderr, _("%s: not a mounted gfs2 file system\n"), argv[optind]); continue; } if (lgfs2_get_dev_info(sdp->device_fd, &sdp->dinfo) < 0) { perror(mnt->mnt_fsname); exit(EXIT_FAILURE); } sdp->sd_sb.sb_bsize = GFS2_DEFAULT_BSIZE; sdp->bsize = sdp->sd_sb.sb_bsize; if (compute_constants(sdp)) { log_crit("%s\n", _("Failed to compute file system constants")); exit(EXIT_FAILURE); } if (read_sb(sdp) < 0) { fprintf(stderr, _("Error reading superblock.\n")); exit(EXIT_FAILURE); } if (sdp->gfs1) { fprintf(stderr, _("cannot grow gfs1 filesystem\n")); exit(EXIT_FAILURE); } fix_device_geometry(sdp); mfs.context = copy_context_opt(mnt); if (mount_gfs2_meta(&mfs, mnt->mnt_dir, (print_level > MSG_NOTICE))) { perror(_("Failed to mount GFS2 meta file system")); exit(EXIT_FAILURE); } rindex_fd = open_rindex(mfs.path, (test ? O_RDONLY : O_RDWR)); if (rindex_fd < 0) { cleanup_metafs(&mfs); exit(EXIT_FAILURE); } /* Get master dinode */ sdp->master_dir = lgfs2_inode_read(sdp, sdp->sd_sb.sb_master_dir.no_addr); if (sdp->master_dir == NULL) { perror(_("Could not read master directory")); exit(EXIT_FAILURE); } rgs = rgrps_init(sdp); if (rgs == NULL) { perror(_("Could not initialise resource groups")); error = -1; goto out; } /* Fetch the rindex from disk. We aren't using gfs2 here, */ /* which means that the bitmaps will most likely be cached */ /* and therefore out of date. It shouldn't matter because */ /* we're only going to write out new RG information after */ /* the existing RGs, and only write to the index at EOF. */ log_info(_("Gathering resource group information for %s\n"), argv[optind]); old_rg_count = lgfs2_rindex_read_fd(rindex_fd, rgs); if (old_rg_count == 0) { perror(_("Failed to scan existing resource groups")); error = -EXIT_FAILURE; goto out; } if (metafs_interrupted) goto out; fssize = lgfs2_rgrp_align_addr(rgs, filesystem_size(rgs) + 1); /* We're done with the old rgs now that we have the fssize and rg count */ lgfs2_rgrps_free(&rgs); /* Now lets set up the new ones with alignment and all */ rgs = rgrps_init(sdp); if (rgs == NULL) { perror(_("Could not initialise new resource groups")); error = -1; goto out; } fsgrowth = (sdp->device.length - fssize); rgcount = lgfs2_rgrps_plan(rgs, fsgrowth, ((GFS2_MAX_RGSIZE << 20) / sdp->bsize)); if (rgcount == 0) { log_err( _("The calculated resource group size is too small.\n")); log_err( _("%s has not grown.\n"), argv[optind]); error = -1; goto out; } print_info(sdp, mnt->mnt_fsname, mnt->mnt_dir); rgcount = initialize_new_portion(sdp, rgs); if (rgcount == 0 || metafs_interrupted) goto out; fsync(sdp->device_fd); fix_rindex(rindex_fd, rgs, old_rg_count, rgcount); out: lgfs2_rgrps_free(&rgs); close(rindex_fd); cleanup_metafs(&mfs); close(sdp->device_fd); if (metafs_interrupted) break; } close(sdp->path_fd); sync(); if (metafs_interrupted) { log_notice( _("gfs2_grow interrupted.\n")); exit(1); } log_notice( _("gfs2_grow complete.\n")); return error; }
/* init_retrans - Routine to initialize retransmission table */ int init_retrans(PROD_RETRANS_TABLE **pp_prod_retrans_table) { static char FNAME[] = "init_retrans"; long int entry_base; /* base of entry */ long int ii,iii; /* loop counter */ int flags, rtn_val; static const char *utc_time = "UTC"; /* Pointer to prod_retrans table */ PROD_RETRANS_ENTRY *p_retrans_entry; PROD_RETRANS_ENTRY_INFO *p_retrans_entry_info; /* pointer to prod_retrans_table */ PROD_RETRANS_TABLE *pl_prod_retrans_table; pl_prod_retrans_table = *pp_prod_retrans_table; log_debug("%s Begin init retrans_table base=0x%x\n", FNAME, pl_prod_retrans_table); global_time_zone = (char *) utc_time; if (pl_prod_retrans_table != NULL){ /* IMPORTANT, special init for local prod_retrans_table */ /* Assume entries directly follow the entry info for all links */ /* and each is variable size */ /* IMPORTANT, these must be initialized in order of their index value */ /* ie, GOES_EAST(0), NMC2(1), NMC(2), NOAAPORT_OPT(3), NMC3(4), NMC1(5) */ /* note NMC2 was GOES_WEST */ /* as per RETRANS_TBL_TYP_xxxxxxx */ entry_base = (long)pl_prod_retrans_table + sizeof(PROD_RETRANS_TABLE); ii = 0; /* For now set to 0; Later can setup retrans table depending on the channel type */ pl_prod_retrans_table->entry_info[GET_RETRANS_TABLE_TYP(sbn_type)]. numb_entries = GET_RETRANS_CHANNEL_ENTRIES(sbn_type); log_debug("%s Total retrans numb_entries for channel %s of sbn_type (%d) = %d \n", FNAME, sbn_channel_name,sbn_type,pl_prod_retrans_table->entry_info[ii].numb_entries); pl_prod_retrans_table->entry_info[GET_RETRANS_TABLE_TYP(sbn_type)]. retrans_entry_base_offset = (long)entry_base - (long)(&pl_prod_retrans_table->entry_info[GET_RETRANS_TABLE_TYP(sbn_type)]. retrans_entry_base_offset); entry_base += (long) (pl_prod_retrans_table->entry_info[GET_RETRANS_TABLE_TYP(sbn_type)]. numb_entries * (sizeof(PROD_RETRANS_ENTRY))); /*ii = GET_RETRANS_TABLE_TYP(sbn_type);*/ p_prod_retrans_table->entry_info[ii].entry_bytes = sizeof(PROD_RETRANS_ENTRY); pl_prod_retrans_table->entry_info[ii].index_last = 0; pl_prod_retrans_table->entry_info[ii].run_id_last = 0; pl_prod_retrans_table->entry_info[ii].tot_prods_rcvd = 0; pl_prod_retrans_table->entry_info[ii].tot_prods_lost = 0; pl_prod_retrans_table->entry_info[ii].tot_prods_lost_seqno = 0; pl_prod_retrans_table->entry_info[ii].tot_prods_lost_abort = 0; pl_prod_retrans_table->entry_info[ii].tot_prods_lost_other = 0; pl_prod_retrans_table->entry_info[ii].tot_prods_retrans_rcvd = 0; pl_prod_retrans_table->entry_info[ii].tot_prods_retrans_rcvd_lost = 0; pl_prod_retrans_table->entry_info[ii].tot_prods_retrans_rcvd_notlost=0; pl_prod_retrans_table->entry_info[ii].tot_prods_retrans_rqstd = 0; pl_prod_retrans_table->entry_info[ii].len_wmo_hdr_max = MAX_WMO_ENTRY_LEN; pl_prod_retrans_table->entry_info[ii].len_wmo_hdr_abbrev_max = MAX_RETRANS_LEN_WMO_HDR_ABBREV; pl_prod_retrans_table->entry_info[ii].last_wmo_hdr[0] = '\0'; pl_prod_retrans_table->entry_info[ii].last_wmo_loghdr_info[0] = '\0'; p_retrans_entry_info = &pl_prod_retrans_table->entry_info[ii]; p_retrans_entry = (PROD_RETRANS_ENTRY *)(((long)&p_retrans_entry_info-> retrans_entry_base_offset) + (long)p_retrans_entry_info->retrans_entry_base_offset); /* Now clear each entry */ for(iii=0; iii < pl_prod_retrans_table->entry_info[ii].numb_entries; iii++) { p_retrans_entry[iii].prod_arrive_time = (long) 0; p_retrans_entry[iii].prod_seqno = (long) 0; p_retrans_entry[iii].prod_run_id = 0; p_retrans_entry[iii].prod_type = 0; p_retrans_entry[iii].prod_cat = 0; p_retrans_entry[iii].prod_code = 0; p_retrans_entry[iii].prod_sub_code = 0; p_retrans_entry[iii].prod_status = 0; p_retrans_entry[iii].prod_err_cause = 0; p_retrans_entry[iii].prod_link_id = 0; p_retrans_entry[iii].entry_flag = 0; p_retrans_entry[iii].WMO_hdr_abbrev[0] = '\0'; } /* end for each numb entries */ log_debug("%s OK init retrans_table for channel [%s] numb_entries = %d\n",FNAME, sbn_channel_name,pl_prod_retrans_table->entry_info[ii].numb_entries); } /* end if pl_prod_retrans_table != NULL */ /*Open retransmit pipe */ if((global_retransmitpipe_fd = open(DEFAULT_RETRANSMIT_PIPENAME, O_RDWR,0)) <= 0){ log_error("Fail to open %s pipe errno=%d \n",DEFAULT_RETRANSMIT_PIPENAME,errno); perror("pipe open err"); return (-1); } if((flags = fcntl(global_retransmitpipe_fd, F_GETFL)) < 0){ log_error("Fail fcntl(F_GETFL) %s pipe\n",DEFAULT_RETRANSMIT_PIPENAME); /* Continue for now */ }else{ flags |= DONT_BLOCK; if((rtn_val = fcntl(global_retransmitpipe_fd, F_SETFL, flags)) < 0){ log_error("Fail fcntl(F_SETFL) %s pipe \n",DEFAULT_RETRANSMIT_PIPENAME); } log_notice(" OK open pipe[%d] for %s\n", global_retransmitpipe_fd,DEFAULT_RETRANSMIT_PIPENAME); } log_debug("%s Exiting init retrans_table base=0x%lx\n", FNAME,(unsigned long) pl_prod_retrans_table); return(0); } /* end init_retrans */
static int execute_one_slave(int slave_id, int arg_cnt, ...) { va_list ap; int fd; char *request_stream; size_t request_len; int nread; fd = crt_tcp_timeout_connect(slave_ip(slave_id), slave_port(slave_id), MASTER_CONNECT_SLAVE_TIMEOUT); if (fd < 0) { if (crt_errno == ECONNREFUSED) return RET_CONNECT_REFUSED; else if (crt_errno == EWOULDBLOCK) return RET_CONNECT_TIMEOUT; else return RET_CONNECT_FAILED; } va_start(ap, arg_cnt); for (int i=0; i<arg_cnt; i++) { request_stream = va_arg(ap, char *); request_len = va_arg(ap, size_t); crt_tcp_write_to(fd, request_stream, request_len, MASTER_SEND_SLAVE_TIMEOUT); } va_end(ap); for ( ; ; ) { nread = crt_tcp_read_to(fd, return 0; } static struct query_response_s * fetch_result(struct query_request_s *request_ptr) { switch (request_ptr->cmd_type) { case cmd_sync: case cmd_power: case cmd_set: case cmd_delete: break; case cmd_get: break; default: break; } return NULL; } static int sendback_result(int fd, struct query_response_s *response_ptr) { return 0; } static void sendback_error_mesg(int fd) { const char *error_mesg = MC_ERR_STR; crt_tcp_write_to(fd, (void*)error_mesg, strlen(error_mesg), g_master_settings.write_timeout); } static void * handle_request(void *arg) { int fd = (intptr_t)arg; ssize_t nread; struct query_request_s request; struct query_response_s *response_ptr; char *p; char remote_ip[IP_STR_LEN]; struct sockaddr_in remote_peer; socklen_t addrlen; char warn_log_mesg[1024] = {0}; int ret; pre_timer(); launch_timer(); crt_set_nonblock(fd); addrlen = sizeof remote_peer; getpeername(fd, (struct sockaddr *)&remote_peer, &addrlen); inet_ntop(AF_INET, &(remote_peer.sin_addr), remote_ip, sizeof remote_ip); memset(&request, 0, sizeof request); /* {{{ recv header */ for (int i=0; i<MAX_RESP_HEADER_SIZE; i++) { nread = crt_tcp_read_to(fd, &request.query_head_buf[i], 1, g_master_settings.read_timeout); if (nread == 1) { if ((p=try_parse_memcached_string_head(&request)) == NULL) continue; else break; } else { ret = snprintf(warn_log_mesg, sizeof warn_log_mesg, "read sock failed: %d - %s", crt_errno, strerror(crt_errno)); assert(ret < (int)sizeof warn_log_mesg); /* NOT <= */ assert(ret >= 0); goto done; } } /* }}} */ /* {{{ parse header & prepare for receiving data */ request.query_head_buf_size = strlen(request.query_head_buf); if ((parse_memcached_string_head(&request) == RET_SUCCESS) && (request.parse_status == ps_succ)) { switch (request.cmd_type) { case cmd_set: request.data_size += 2; /* alloc for tailing '\r\n' */ request.data = slab_alloc(request.data_size); assert(request.data != NULL); nread = crt_tcp_read(fd, request.data, request.data_size); if (nread != (ssize_t)request.data_size) { ret = snprintf(warn_log_mesg, sizeof warn_log_mesg, "read request body failed: nread = %zd, error = %d - %s", nread, crt_errno, strerror(crt_errno)); assert(ret < (int)sizeof warn_log_mesg); /* NOT <= */ assert(ret >= 0); goto done; } break; case cmd_get: case cmd_delete: /* nothing to do */ break; /* TODO */ case cmd_sync: case cmd_power: default: break; } } else { sendback_error_mesg(fd); ret = snprintf(warn_log_mesg, sizeof warn_log_mesg, "parse request failed, cmd type: %d", request.cmd_type); assert(ret < (int)sizeof warn_log_mesg); /* NOT <= */ assert(ret >= 0); } /* }}} */ response_ptr = fetch_result(&request); sendback_result(fd, response_ptr); done: if (request.data != NULL) slab_free(request.data); stop_timer(); if (warn_log_mesg[0] == '\0') { log_notice("%s <Elapsed %ld.%06lds> {from: %s, fd = %d}", cmd_type_name(request.cmd_type), __used.tv_sec, __used.tv_usec, remote_ip, fd); } else { log_warn("%s <Elapsed %ld.%06lds> {from: %s, fd = %d} %s", cmd_type_name(request.cmd_type), __used.tv_sec, __used.tv_usec, remote_ip, fd, warn_log_mesg); } close(fd); crt_exit(NULL); }
/** Try to read the identity key from <b>identity_key_file</b>. If no such * file exists and create_identity_key is set, make a new identity key and * store it. Return 0 on success, nonzero on failure. */ static int load_identity_key(void) { file_status_t status = file_status(identity_key_file); FILE *f; if (make_new_id) { open_file_t *open_file = NULL; RSA *key; if (status != FN_NOENT) { log_err(LD_GENERAL, "--create-identity-key was specified, but %s " "already exists.", identity_key_file); return 1; } log_notice(LD_GENERAL, "Generating %d-bit RSA identity key.", IDENTITY_KEY_BITS); if (!(key = generate_key(IDENTITY_KEY_BITS))) { log_err(LD_GENERAL, "Couldn't generate identity key."); crypto_log_errors(LOG_ERR, "Generating identity key"); return 1; } identity_key = EVP_PKEY_new(); if (!(EVP_PKEY_assign_RSA(identity_key, key))) { log_err(LD_GENERAL, "Couldn't assign identity key."); return 1; } if (!(f = start_writing_to_stdio_file(identity_key_file, OPEN_FLAGS_REPLACE | O_TEXT, 0400, &open_file))) return 1; /* Write the key to the file. If passphrase is not set, takes it from * the terminal. */ if (!PEM_write_PKCS8PrivateKey_nid(f, identity_key, NID_pbe_WithSHA1And3_Key_TripleDES_CBC, passphrase, (int)passphrase_len, NULL, NULL)) { log_err(LD_GENERAL, "Couldn't write identity key to %s", identity_key_file); crypto_log_errors(LOG_ERR, "Writing identity key"); abort_writing_to_file(open_file); return 1; } finish_writing_to_file(open_file); } else { if (status != FN_FILE) { log_err(LD_GENERAL, "No identity key found in %s. To specify a location " "for an identity key, use -i. To generate a new identity key, " "use --create-identity-key.", identity_key_file); return 1; } if (!(f = fopen(identity_key_file, "r"))) { log_err(LD_GENERAL, "Couldn't open %s for reading: %s", identity_key_file, strerror(errno)); return 1; } /* Read the key. If passphrase is not set, takes it from the terminal. */ identity_key = PEM_read_PrivateKey(f, NULL, NULL, passphrase); if (!identity_key) { log_err(LD_GENERAL, "Couldn't read identity key from %s", identity_key_file); return 1; } fclose(f); } return 0; }
/** Based on our interval and our estimated bandwidth, choose a * deterministic (but random-ish) time to wake up. */ static void accounting_set_wakeup_time(void) { char buf[ISO_TIME_LEN+1]; char digest[DIGEST_LEN]; crypto_digest_env_t *d_env; int time_in_interval; uint64_t time_to_exhaust_bw; int time_to_consider; if (! identity_key_is_set()) { if (init_keys() < 0) { log_err(LD_BUG, "Error initializing keys"); tor_assert(0); } } format_iso_time(buf, interval_start_time); crypto_pk_get_digest(get_identity_key(), digest); d_env = crypto_new_digest_env(); crypto_digest_add_bytes(d_env, buf, ISO_TIME_LEN); crypto_digest_add_bytes(d_env, digest, DIGEST_LEN); crypto_digest_get_digest(d_env, digest, DIGEST_LEN); crypto_free_digest_env(d_env); if (!expected_bandwidth_usage) { char buf1[ISO_TIME_LEN+1]; char buf2[ISO_TIME_LEN+1]; format_local_iso_time(buf1, interval_start_time); format_local_iso_time(buf2, interval_end_time); time_to_exhaust_bw = GUESS_TIME_TO_USE_BANDWIDTH; interval_wakeup_time = interval_start_time; log_notice(LD_ACCT, "Configured hibernation. This interval begins at %s " "and ends at %s. We have no prior estimate for bandwidth, so " "we will start out awake and hibernate when we exhaust our quota.", buf1, buf2); return; } time_in_interval = (int)(interval_end_time - interval_start_time); time_to_exhaust_bw = (get_options()->AccountingMax/expected_bandwidth_usage)*60; if (time_to_exhaust_bw > TIME_MAX) { time_to_exhaust_bw = TIME_MAX; time_to_consider = 0; } else { time_to_consider = time_in_interval - (int)time_to_exhaust_bw; } if (time_to_consider<=0) { interval_wakeup_time = interval_start_time; } else { /* XXX can we simplify this just by picking a random (non-deterministic) * time to be up? If we go down and come up, then we pick a new one. Is * that good enough? -RD */ /* This is not a perfectly unbiased conversion, but it is good enough: * in the worst case, the first half of the day is 0.06 percent likelier * to be chosen than the last half. */ interval_wakeup_time = interval_start_time + (get_uint32(digest) % time_to_consider); format_iso_time(buf, interval_wakeup_time); } { char buf1[ISO_TIME_LEN+1]; char buf2[ISO_TIME_LEN+1]; char buf3[ISO_TIME_LEN+1]; char buf4[ISO_TIME_LEN+1]; time_t down_time; if (interval_wakeup_time+time_to_exhaust_bw > TIME_MAX) down_time = TIME_MAX; else down_time = (time_t)(interval_wakeup_time+time_to_exhaust_bw); if (down_time>interval_end_time) down_time = interval_end_time; format_local_iso_time(buf1, interval_start_time); format_local_iso_time(buf2, interval_wakeup_time); format_local_iso_time(buf3, down_time); format_local_iso_time(buf4, interval_end_time); log_notice(LD_ACCT, "Configured hibernation. This interval began at %s; " "the scheduled wake-up time %s %s; " "we expect%s to exhaust our quota for this interval around %s; " "the next interval begins at %s (all times local)", buf1, time(NULL)<interval_wakeup_time?"is":"was", buf2, time(NULL)<down_time?"":"ed", buf3, buf4); } }
void Timed::kernel_notification(const nanotime_t &jump_forwards) { log_notice("KERNEL: system time changed by %s", jump_forwards.str().c_str()) ; settings->process_kernel_notification(jump_forwards) ; }
void Timed::device_mode_reached(bool user_mode) { log_notice("MODE: running in %s mode", user_mode ? "USER" : "ACTDEAD") ; am->device_mode_detected(user_mode) ; am->unfreeze() ; }
int dcs_initialize(int udp_port, int rest_port, int fDebugCli, int fExitOnCtrlC, char *python_path) { dove_status status = DOVE_STATUS_OK; char buf[INET6_ADDRSTRLEN]; int ret; memset(&dcs_local_ip, 0, sizeof(ip_addr_t)); dcs_local_ip.family = AF_INET; dcs_local_ip.ip4 = htonl(INADDR_LOOPBACK); dcs_local_ip.port = udp_port; dcs_local_ip.port_http = rest_port; dcs_local_ip.xport_type = SOCK_DGRAM; set_initial_dps_cluster_leader(); set_initial_controller_location(); Py_Initialize(); PyEval_InitThreads(); do { log_console = 0; //Read version dcs_read_version(); log_notice(PythonDataHandlerLogLevel, "DCS version %s",dsa_version_string); if(OSW_OK != osw_init()) { status = DOVE_STATUS_OSW_INIT_FAILED; break; } log_notice(PythonDataHandlerLogLevel, "Initialized OS Wrapper"); status = python_init_dcs_protocol_interface(python_path); if (status != DOVE_STATUS_OK) { log_emergency(PythonDataHandlerLogLevel, "Cannot initialize the Protocol Interface"); break; } log_notice(PythonDataHandlerLogLevel, "Initialized DCS Protocol"); // Initialize the data handler for the Cluster Database status = python_init_cluster_db_interface(python_path); if (status != DOVE_STATUS_OK) { log_emergency(PythonDataHandlerLogLevel, "Cannot initialize the Cluster Database"); break; } log_notice(PythonDataHandlerLogLevel, "Initialized Cluster Database"); // Initialize the data handler for the DPS Controller Protocol status = python_init_controller_interface(python_path); if (status != DOVE_STATUS_OK) { log_emergency(PythonDataHandlerLogLevel, "Cannot initialize the Cluster Database"); break; } log_notice(PythonDataHandlerLogLevel, "Initialized Controller Interface"); // Initialize the debug handler status = python_init_debug_interface(python_path); if (status != DOVE_STATUS_OK) { log_emergency(PythonDataHandlerLogLevel, "Cannot initialize the Debug Handler"); break; } log_notice(PythonDataHandlerLogLevel, "Initialized Debug Interface"); // Initialize the Retransmit Handler status = python_init_retransmit_interface(python_path); if (status != DOVE_STATUS_OK) { log_emergency(PythonDataHandlerLogLevel, "Cannot Initialize Retransmit Handler"); break; } log_notice(PythonDataHandlerLogLevel, "Initialized Retransmit Interface"); // Initialize the UUID Interface status = python_init_UUID_interface(python_path); if (status != DOVE_STATUS_OK) { log_emergency(PythonDataHandlerLogLevel, "Cannot initialize the UUID API"); break; } log_notice(PythonDataHandlerLogLevel, "Initialized UUID Interface"); // Get local IP Address set_local_ip(); log_notice(PythonDataHandlerLogLevel, "Initialized Local IP"); // Initialize the REST SERVER if(dps_rest_server_init_ok == 0) { status = dcs_server_rest_init((short)DPS_REST_HTTPD_PORT); if (status != DOVE_STATUS_OK) { log_emergency(PythonDataHandlerLogLevel, "Cannot Initialize the REST SERVER"); break; } dps_rest_server_init_ok = 1; } log_notice(PythonDataHandlerLogLevel, "Initialized REST Server"); dove_status status_tmp = dcs_read_svc_app_uuid(); if (status_tmp != DOVE_STATUS_OK) { log_emergency(PythonDataHandlerLogLevel, "Could NOT read service appliance UUID from %s/%s", getenv("HOME"),SERVICE_APPLIANCE_UUID_FILE); // Create a FAKE UUID interface dps_init_uuid(); write_uuid_to_file(); } log_notice(PythonDataHandlerLogLevel, "READ SVC APP UUID"); // Register the Local DPS Node with the Cluster status = dcs_cluster_node_local_update(&dcs_local_ip); if (status != DOVE_STATUS_OK) { log_emergency(PythonDataHandlerLogLevel, "DCS: Cannot add local Node to Cluster"); break; } log_notice(PythonDataHandlerLogLevel, "Registered Local Node with Cluster"); // Initialize the Statistics status = dcs_statistics_init(python_path); if (status != DOVE_STATUS_OK) { log_emergency(PythonDataHandlerLogLevel, "DCS: Cannot Initialize Statistics Thread"); break; } log_notice(PythonDataHandlerLogLevel, "Initialized Statistics Thread"); // Initialize the Heartbeat status = dcs_heartbeat_init(python_path); if (status != DOVE_STATUS_OK) { log_emergency(PythonDataHandlerLogLevel, "DCS: Cannot Initialize Heartbeat Thread"); break; } log_notice(PythonDataHandlerLogLevel, "Initialized Heartbeat Thread"); dcs_rest_sync_init(); log_notice(PythonDataHandlerLogLevel, "Initialized Controller Sync Thread"); if (fDebugCli) { // Initialize the CLI Thread PYTHON Interface. This will // start the CLI Thread status = python_lib_embed_cli_thread_start(fExitOnCtrlC); if (status != DOVE_STATUS_OK) { log_emergency(PythonDataHandlerLogLevel, "DCS: Cannot start the CLI thread"); break; } // Initialize the CLI status = dcs_server_cli_init(); if (status != DOVE_STATUS_OK) { log_emergency(PythonDataHandlerLogLevel, "DCS: Cannot Initialize the CLI"); break; } fDebugCLIInitialized = 1; } else { //Set net.core.rmem_max to 64M ret = system("sysctl -w net.core.rmem_max=67108864 &> /dev/null"); if (WEXITSTATUS(ret) != 0) { log_emergency(PythonDataHandlerLogLevel, "DCS: Failed to set net.core.rmem_max to 64M"); } ret = system("sysctl -w net.core.rmem_default=67108864 &> /dev/null"); if (WEXITSTATUS(ret) != 0) { log_emergency(PythonDataHandlerLogLevel, "DCS: Failed to set net.core.rmem_default to 64M"); } //Read from file dcs_read_role(); } Py_BEGIN_ALLOW_THREADS // Initialize the CORE APIs status = fd_process_init(); if (status != DOVE_STATUS_OK) { log_emergency(PythonDataHandlerLogLevel, "DCS: Cannot Initialize CORE processing"); break; } // Initialize the DCS Server dps_svr_proto_init((uint32_t)udp_port); // Print the starting parameters inet_ntop(dcs_local_ip.family, dcs_local_ip.ip6, buf, INET6_ADDRSTRLEN); log_notice(PythonDataHandlerLogLevel, "DCS Server Started: IP Address <%s>, Port <%d>", buf, dcs_local_ip.port); //Initialize local IP monitor dcs_local_ip_monitor_init(); // Start the CORE APIs Communication fd_process_start(); Py_END_ALLOW_THREADS }while(0); //show_print("Quitting Abnormally: Not cleaning up threads!!!"); Py_Finalize(); return -1; }
static int interrupt_signal_handler(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata) { log_notice("Transfer aborted."); sd_event_exit(sd_event_source_get_event(s), EINTR); return 0; }
/* * Insert monitor info, this is basically the time and xlog replayed, * applied on standby and current xlog location in primary. * Also do the math to see how far are we in bytes for being uptodate */ static void MonitorExecute(void) { PGresult *res; char monitor_standby_timestamp[MAXLEN]; char last_wal_primary_location[MAXLEN]; char last_wal_standby_received[MAXLEN]; char last_wal_standby_applied[MAXLEN]; unsigned long long int lsn_primary; unsigned long long int lsn_standby_received; unsigned long long int lsn_standby_applied; int connection_retries; /* * Check if the master is still available, if after 5 minutes of retries * we cannot reconnect, try to get a new master. */ for (connection_retries = 0; connection_retries < 15; connection_retries++) { if (PQstatus(primaryConn) != CONNECTION_OK) { log_warning(_("Connection to master has been lost, trying to recover...\n")); /* wait 20 seconds between retries */ sleep(20); PQreset(primaryConn); } else { if (connection_retries > 0) { log_notice(_("Connection to master has been restored, continue monitoring.\n")); } break; } } if (PQstatus(primaryConn) != CONNECTION_OK) { log_err(_("We couldn't reconnect to master. Now checking if another node has been promoted.\n")); for (connection_retries = 0; connection_retries < 6; connection_retries++) { primaryConn = getMasterConnection(myLocalConn, local_options.node, local_options.cluster_name, &primary_options.node,NULL); if (PQstatus(primaryConn) == CONNECTION_OK) { /* Connected, we can continue the process so break the loop */ log_err(_("Connected to node %d, continue monitoring.\n"), primary_options.node); break; } else { log_err(_("We haven't found a new master, waiting before retry...\n")); /* wait 5 minutes before retries, after 6 failures (30 minutes) we stop trying */ sleep(300); } } } if (PQstatus(primaryConn) != CONNECTION_OK) { log_err(_("We couldn't reconnect for long enough, exiting...\n")); exit(ERR_DB_CON); } /* Check if we still are a standby, we could have been promoted */ if (!is_standby(myLocalConn)) { log_err(_("It seems like we have been promoted, so exit from monitoring...\n")); CloseConnections(); exit(ERR_PROMOTED); } /* * first check if there is a command being executed, * and if that is the case, cancel the query so i can * insert the current record */ if (PQisBusy(primaryConn) == 1) CancelQuery(); /* Get local xlog info */ sqlquery_snprintf( sqlquery, "SELECT CURRENT_TIMESTAMP, pg_last_xlog_receive_location(), " "pg_last_xlog_replay_location()"); res = PQexec(myLocalConn, sqlquery); if (PQresultStatus(res) != PGRES_TUPLES_OK) { log_err("PQexec failed: %s\n", PQerrorMessage(myLocalConn)); PQclear(res); /* if there is any error just let it be and retry in next loop */ return; } strncpy(monitor_standby_timestamp, PQgetvalue(res, 0, 0), MAXLEN); strncpy(last_wal_standby_received , PQgetvalue(res, 0, 1), MAXLEN); strncpy(last_wal_standby_applied , PQgetvalue(res, 0, 2), MAXLEN); PQclear(res); /* Get primary xlog info */ sqlquery_snprintf(sqlquery, "SELECT pg_current_xlog_location() "); res = PQexec(primaryConn, sqlquery); if (PQresultStatus(res) != PGRES_TUPLES_OK) { log_err("PQexec failed: %s\n", PQerrorMessage(primaryConn)); PQclear(res); return; } strncpy(last_wal_primary_location, PQgetvalue(res, 0, 0), MAXLEN); PQclear(res); /* Calculate the lag */ lsn_primary = walLocationToBytes(last_wal_primary_location); lsn_standby_received = walLocationToBytes(last_wal_standby_received); lsn_standby_applied = walLocationToBytes(last_wal_standby_applied); if (only_one_entry && only_one_entry_desired) { sqlquery_snprintf(sqlquery, "UPDATE %s.repl_monitor " "VALUES(%d, %d, '%s'::timestamp with time zone, " " '%s', '%s', " " %lld, %lld)" "WHERE primary_node=%d AND secondary_node=%d", repmgr_schema, primary_options.node, local_options.node, monitor_standby_timestamp, last_wal_primary_location, last_wal_standby_received, (lsn_primary - lsn_standby_received), (lsn_standby_received - lsn_standby_applied)); res = PQexec(primaryConn, sqlquery); if (PQresultStatus(res) != PGRES_TUPLES_OK) { log_err("PQexec failed: %s\n", PQerrorMessage(conn)); PQclear(res); CloseConnections(); exit(ERR_DB_QUERY); } if (PQntuples(res) != 1) { only_one_entry = false; } PQclear(res); } else { /* * Build and send insert */ sqlquery_snprintf(sqlquery, "INSERT INTO %s.repl_monitor " "VALUES(%d, %d, '%s'::timestamp with time zone, " " '%s', '%s', " " %lld, %lld)", repmgr_schema, primary_options.node, local_options.node, monitor_standby_timestamp, last_wal_primary_location, last_wal_standby_received, (lsn_primary - lsn_standby_received), (lsn_standby_received - lsn_standby_applied)); res = PQexec(primaryConn, sqlquery); if (PQresultStatus(res) != PGRES_TUPLES_OK) { log_err("PQexec failed: %s\n", PQerrorMessage(conn)); PQclear(res); CloseConnections(); exit(ERR_DB_QUERY); } PQclear(res); if (only_one_entry_desired) { /* * Build the SQL to execute on primary */ sqlquery_snprintf(sqlquery, "DELETE FROM %s.repl_monitor " "WHERE primary_node=%d AND standby_node=%d AND last_monitor_time < '%s'::timestamp with time zone", repmgr_schema, primary_options.node, local_options.node, monitor_standby_timestamp); res = PQexec(primaryConn, sqlquery); if (PQresultStatus(res) != PGRES_TUPLES_OK) { log_err("PQexec failed: %s\n", PQerrorMessage(conn)); PQclear(res); CloseConnections(); exit(ERR_DB_QUERY); } PQclear(res); only_one_entry = true; } } }
/* Read extended metadata areas */ static int read_extended(struct lib_context *lc, struct dev_info *di, struct asr *asr) { unsigned remaining, i, chk; struct asr_raidtable *rt = asr->rt; log_notice(lc, "%s: reading extended data on %s", handler, di->path); /* Read the RAID table. */ if (!read_file(lc, handler, di->path, rt, ASR_DISK_BLOCK_SIZE, (uint64_t) asr->rb.raidtbl * ASR_DISK_BLOCK_SIZE)) LOG_ERR(lc, 0, "%s: Could not read metadata off %s", handler, di->path); /* Convert it */ to_cpu(asr, ASR_TABLE); /* Is this ok? */ if (rt->ridcode != RVALID2) LOG_ERR(lc, 0, "%s: Invalid magic number in RAID table; " "saw 0x%X, expected 0x%X on %s", handler, rt->ridcode, RVALID2, di->path); /* Have we a valid element count? */ if (rt->elmcnt >= rt->maxelm || rt->elmcnt == 0) LOG_ERR(lc, 0, "%s: Invalid RAID config table count on %s", handler, di->path); /* Is each element the right size? */ if (rt->elmsize != sizeof(*rt->ent)) LOG_ERR(lc, 0, "%s: Wrong RAID config line size on %s", handler, di->path); /* Figure out how much else we need to read. */ if (rt->elmcnt > ASR_TBLELMCNT) { remaining = rt->elmsize * (rt->elmcnt - 7); if (!read_file(lc, handler, di->path, rt->ent + 7, remaining, (uint64_t) (asr->rb.raidtbl + 1) * ASR_DISK_BLOCK_SIZE)) return 0; to_cpu(asr, ASR_EXTTABLE); } /* Checksum only valid for raid table version 1. */ if (rt->rversion < 2) { if ((chk = compute_checksum(asr)) != rt->rchksum) log_err(lc, "%s: Invalid RAID config table checksum " "(0x%X vs. 0x%X) on %s", handler, chk, rt->rchksum, di->path); } /* Process the name of each line of the config line. */ for (i = 0; i < rt->elmcnt; i++) { /* * Weird quirks of the name field of the config line: * * - SATA HostRAID w/ ICH5 on IBM x226: The name field is null * in the drive config lines. The zeroeth item does have a * name, however. * - Spares on SCSI HostRAID on IBM x226: The name field for * all config lines is null. * * So, we'll assume that we can copy the name from the zeroeth * element in the array. The twisted logic doesn't seem to * have a problem with either of the above cases, though * attaching spares is going to be a tad tricky (primarily * because there doesn't seem to be a way to attach a spare to * a particular array; presumably the binary driver knows how * or just grabs a disk out of the spare pool. * * (Yes, the binary driver _does_ just grab a disk from the * global spare pool. We must teach dm about this...?) * * This is nuts. */ if (!*rt->ent[i].name) strncpy((char *) rt->ent[i].name, (char *) rt->ent->name, ASR_NAMELEN); /* Now truncate trailing whitespace in the name. */ handle_white_space(rt->ent[i].name, TRUNCATE); } return 1; }
int main(int argc, char * const *argv) { uint32_t client_opts, send_level; const char *identity, *facility; // ASL client options client_opts = 0; // What level of messages are sent to syslogd send_level = ASL_LEVEL_NOTICE; // Sender identity. This should be NULL, as asl_open() will set this to the // name of the program. Only set this if you really need to. identity = NULL; // This should be your UTI facility = "se.hunch.asl.example"; // Options accepted by our example program int ch; static struct option longopts[] = { { "debug", no_argument, NULL, 'd' }, { "stderr", no_argument, NULL, 's' }, { "no-remote", no_argument, NULL, 'n' }, { "help", no_argument, NULL, 'h' }, { NULL, 0, NULL, '\0' } }; // Parse options while ((ch = getopt_long(argc, argv, "dsnh", longopts, NULL)) != -1) switch (ch) { case 'd': // Send all messages send_level = ASL_LEVEL_DEBUG; // This disables the remote-control mechanism for adjusting // filter levers for processes using e.g. syslog -c ... client_opts |= ASL_OPT_NO_REMOTE; break; case 's': // Print messages to stderr (adds stderr as an output file descriptor) client_opts |= ASL_OPT_STDERR; break; case 'n': // Send no messages at all. This does only affect what messages are sent // to the server and does not restrict which message are printed to // stderr, if enabled. send_level = -1; break; // Print usage and help default: usage(argv[0]); exit(1); } argc -= optind; argv += optind; // Setting ASL_OPT_NO_DELAY connects to the server immediately when calling asl_open() client_opts |= ASL_OPT_NO_DELAY; // Open connection to ASL (log_asl_client is defined in logging.h) // See /usr/include/asl.h for more details. log_asl_client = asl_open(identity, facility, client_opts); // The log_asl_client variable is used by the log_* and Log_* macros in logging.h // Handle errors from asl_open() if (log_asl_client == NULL) { perror("asl_open"); exit(2); } // Set the level for which messages are sent to the server log_set_send_filter(send_level); // Emit one message for each level log_emerg("This is a emerg-level message -- this message may propagate " "to all TTYs and/or other user interfaces"); log_alert("This is a alert-level message"); log_crit("This is a crit-level message"); log_err("This is a err-level message"); log_warn("This is a warn-level message"); log_notice("This is a notice-level message"); log_info("This is a info-level message"); log_debug("This message is a debug-level message"); // Close connection to syslogd asl_close(log_asl_client); return 0; }
int prod_retrans_ck(ACQ_TABLE *p_acqtable, BUFF_HDR *p_buffhdr, time_t *orig_arrive_time) { char FNAME[] = "prod_retrans_ck"; int index_value; int match_value; int retrans_table_type; PROD_RETRANS_ENTRY *p_retrans_entry; PROD_RETRANS_ENTRY_INFO *p_retrans_entry_info; long orig_prod_seqno; long now_prod_seqno; long delta_prod_seqno; /* delta for prod seqno */ int valid_retrans_flag; /* valid retrans flag for table */ match_value = PROD_NODUPLICATE; *orig_arrive_time = 0; if(prod_retrans_get_addr(p_acqtable->proc_base_channel_type_last, p_prod_retrans_table, &p_retrans_entry_info, &p_retrans_entry, &retrans_table_type) < 0) { log_notice("%s ignore retrans_ck\n", FNAME); return(match_value); } if(p_acqtable->proc_orig_prod_seqno_last != 0) { log_debug("%s ok retrans channel_typ=%d tbl[%d] so ck more\n", FNAME, p_acqtable->proc_base_channel_type_last, retrans_table_type); /* Assume have retransmitted product do following */ p_acqtable->proc_tot_prods_retrans_rcvd++, p_retrans_entry_info->tot_prods_retrans_rcvd++; /* If is retransmission, need to see if original product was OK */ /* and ignore the product, else process the product */ index_value = p_acqtable->proc_orig_prod_seqno_last % p_retrans_entry_info->numb_entries; if(index_value < 0) { index_value = -index_value; } if(index_value >= p_retrans_entry_info->numb_entries) { index_value = 0; } /* Check if already have product in table */ if((p_retrans_entry[index_value].prod_seqno == p_acqtable->proc_orig_prod_seqno_last) && (p_retrans_entry[index_value].prod_run_id == p_acqtable->proc_orig_prod_run_id) && (p_retrans_entry[index_value].entry_flag != RETRANS_ENTRY_FLAG_AVAIL)) { /* Assume product matched */ match_value = PROD_DUPLICATE_MATCH; p_acqtable->proc_tot_prods_retrans_rcvd_notlost++; p_retrans_entry_info->tot_prods_retrans_rcvd_notlost++; *orig_arrive_time = p_retrans_entry[index_value].prod_arrive_time; } else { match_value = PROD_DUPLICATE_NOMATCH; p_acqtable->proc_tot_prods_retrans_rcvd_lost++; p_retrans_entry_info->tot_prods_retrans_rcvd_lost++; } log_debug("%s %s duplicate run(%d) prod|orig(%ld|%ld) tbl[%d]=%ld\n", FNAME, (match_value==PROD_DUPLICATE_MATCH)?"OK MATCH":"NO MATCH", p_acqtable->proc_orig_prod_run_id, p_buffhdr->proc_prod_seqno, p_acqtable->proc_orig_prod_seqno_last, index_value, p_retrans_entry[index_value].prod_seqno); /* Check if retransmit prod is within range of table entries */ orig_prod_seqno = (long)p_acqtable->proc_orig_prod_seqno_last; now_prod_seqno = (long)p_buffhdr->proc_prod_seqno; valid_retrans_flag = 0; delta_prod_seqno = now_prod_seqno - orig_prod_seqno; if((match_value == PROD_DUPLICATE_MATCH) || (match_value == PROD_DUPLICATE_NOMATCH)) { if((delta_prod_seqno > 0) && (delta_prod_seqno < p_retrans_entry_info->numb_entries)) { valid_retrans_flag = 1; } } if((match_value == PROD_DUPLICATE_MATCH) || (match_value == PROD_DUPLICATE_NOMATCH)) { if((delta_prod_seqno < 0) && (now_prod_seqno < p_retrans_entry_info->numb_entries)) { valid_retrans_flag = 1; } } /* Now if the original is within the number of active entries */ /* go ahead and update the match table entry */ /* Note, that p_acqtable->proc_base_prod_seqno is not yet set */ if((match_value == PROD_DUPLICATE_NOMATCH) && (valid_retrans_flag == 1)){ /* Now update the prod_retrans_entry */ prod_retrans_update_entry(p_acqtable, p_buffhdr, p_retrans_entry_info, &p_retrans_entry[index_value], index_value, p_acqtable->proc_orig_prod_seqno_last, p_acqtable->proc_orig_prod_run_id, RETRANS_ENTRY_FLAG_RETRANS_VALID, 0); p_retrans_entry_info->index_last = index_value; p_retrans_entry_info->run_id_last = p_acqtable->proc_prod_run_id; } else { /* Check if retransmit prod is within range of table entries */ if((match_value == PROD_DUPLICATE_MATCH) && (valid_retrans_flag == 1)){ /* Now update the prod_retrans_entry */ /* to tell other product is ok but duplicate */ prod_retrans_update_entry(p_acqtable, p_buffhdr, p_retrans_entry_info, &p_retrans_entry[index_value], index_value, p_acqtable->proc_orig_prod_seqno_last, p_acqtable->proc_orig_prod_run_id, RETRANS_ENTRY_FLAG_RETRANS_DUP, 0); } else { if(p_retrans_entry[index_value].prod_run_id == p_acqtable->proc_orig_prod_run_id) { /* Possibly orig prod_seqno greater than current prod_seqno */ /* so discard */ } } /* Note, prod is possibly too old to fit in table */ /* Always, set product for discard */ match_value = PROD_DUPLICATE_DISCARD; } } else { /* If this a new (not retransmitted) product do following */ match_value = PROD_NODUPLICATE; } /* end if-else retransmitted product */ /* In either case need to update entry for new product */ index_value = p_buffhdr->proc_prod_seqno % p_retrans_entry_info->numb_entries; if(index_value < 0) { index_value = -index_value; } if(index_value >= p_retrans_entry_info->numb_entries) { index_value = 0; } /* IMPORTANT, this value will be removed later if product in error */ /* Now update the prod_retrans_entry */ /* and also indicate if was a retransmission product */ prod_retrans_update_entry(p_acqtable, p_buffhdr, p_retrans_entry_info, &p_retrans_entry[index_value], index_value, p_buffhdr->proc_prod_seqno, p_acqtable->proc_prod_run_id, RETRANS_ENTRY_FLAG_NEW_VALID| ((p_acqtable->proc_orig_prod_seqno_last != 0)? RETRANS_ENTRY_FLAG_NEW_W_DUP:0), 0); p_retrans_entry_info->index_last = index_value; p_retrans_entry_info->run_id_last = p_acqtable->proc_prod_run_id; /* Debug only */ if(match_value & PROD_NODUPLICATE) { log_debug(" %s %s entry(%d) prod(%ld) code=%d %s[%d]\n", FNAME, GET_PROD_TYPE_NAME(p_buffhdr->proc_prod_type), index_value, p_buffhdr->proc_prod_seqno, p_buffhdr->proc_prod_code, (match_value & PROD_NODUPLICATE)?"NO_DUPL": (match_value & PROD_DUPLICATE_MATCH)?"DUPL_MATCH": (match_value & PROD_DUPLICATE_NOMATCH)?"DUPL_NOMATCH": "UNKNOWN", match_value); } else { log_debug("%s %s entry(%d) prod|orig(%ld|%ld) code=%d %s[%d]\n", FNAME, GET_PROD_TYPE_NAME(p_buffhdr->proc_prod_type), index_value, p_buffhdr->proc_prod_seqno, p_acqtable->proc_orig_prod_seqno_last, p_buffhdr->proc_prod_code, (match_value & PROD_NODUPLICATE)?"NO_DUPL": (match_value & PROD_DUPLICATE_MATCH)?"DUPL_MATCH": (match_value & PROD_DUPLICATE_NOMATCH)?"DUPL_NOMATCH": "UNKNOWN", match_value); } /* Debug only */ return(match_value); }
static void sighandler(int32_t s) { log_notice("Got signal %d. Total number of signals received %d", s, ++ done); }
int main(int argc, char *argv[]) { char t[] = "/tmp/journal-XXXXXX"; unsigned n; JournalFile *f; const char *verification_key = argv[1]; usec_t from = 0, to = 0, total = 0; char a[FORMAT_TIMESTAMP_MAX]; char b[FORMAT_TIMESTAMP_MAX]; char c[FORMAT_TIMESPAN_MAX]; struct stat st; uint64_t p; /* journal_file_open requires a valid machine id */ if (access("/etc/machine-id", F_OK) != 0) return EXIT_TEST_SKIP; log_set_max_level(LOG_DEBUG); assert_se(mkdtemp(t)); assert_se(chdir(t) >= 0); log_info("Generating..."); assert_se(journal_file_open("test.journal", O_RDWR|O_CREAT, 0666, true, !!verification_key, NULL, NULL, NULL, &f) == 0); for (n = 0; n < N_ENTRIES; n++) { struct iovec iovec; struct dual_timestamp ts; char *test; dual_timestamp_get(&ts); assert_se(asprintf(&test, "RANDOM=%lu", random() % RANDOM_RANGE)); iovec.iov_base = (void*) test; iovec.iov_len = strlen(test); assert_se(journal_file_append_entry(f, &ts, &iovec, 1, NULL, NULL, NULL) == 0); free(test); } journal_file_close(f); log_info("Verifying..."); assert_se(journal_file_open("test.journal", O_RDONLY, 0666, true, !!verification_key, NULL, NULL, NULL, &f) == 0); /* journal_file_print_header(f); */ journal_file_dump(f); assert_se(journal_file_verify(f, verification_key, &from, &to, &total, true) >= 0); if (verification_key && JOURNAL_HEADER_SEALED(f->header)) log_info("=> Validated from %s to %s, %s missing", format_timestamp(a, sizeof(a), from), format_timestamp(b, sizeof(b), to), format_timespan(c, sizeof(c), total > to ? total - to : 0, 0)); journal_file_close(f); if (verification_key) { log_info("Toggling bits..."); assert_se(stat("test.journal", &st) >= 0); for (p = 38448*8+0; p < ((uint64_t) st.st_size * 8); p ++) { bit_toggle("test.journal", p); log_info("[ %"PRIu64"+%"PRIu64"]", p / 8, p % 8); if (raw_verify("test.journal", verification_key) >= 0) log_notice(ANSI_HIGHLIGHT_RED ">>>> %"PRIu64" (bit %"PRIu64") can be toggled without detection." ANSI_NORMAL, p / 8, p % 8); bit_toggle("test.journal", p); } } log_info("Exiting..."); assert_se(rm_rf(t, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0); return 0; }
void ignored_problems_remove_row(ignored_problems_t *set, const char *problem_id, const char *uuid, const char *duphash) { VERB1 log("Going to remove problem '%s' from ignored problems", problem_id); FILE *orig_fp; if (!ignored_problems_file_contains(set, problem_id, uuid, duphash, &orig_fp, "r")) { if (orig_fp) { log_notice("Won't remove problem '%s' from ignored problems:" " it is already removed", problem_id); /* Close orig_fp here becuase it looks like much simpler than * exetendig the set of goto labels at the end of this function */ fclose(orig_fp); } else { /* This is not a fatal problem. We are permissive because we don't want * to scare users by strange error messages. */ log_notice("Can't remove problem '%s' from ignored problems:" " can't open the list", problem_id); } return; } /* orig_fp must be valid here because if ignored_problems_file_contains() * returned TRUE the function ensures that orig_fp is set to a valid FILE*. * * But the function moved the file position indicator. */ rewind(orig_fp); char *new_tempfile_name = xasprintf("%s.XXXXXX", set->ign_set_file_path); int new_tempfile_fd = mkstemp(new_tempfile_name); if (new_tempfile_fd < 0) { perror_msg(_("Can't create temporary file '%s'"), set->ign_set_file_path); goto ret_close_files; } unsigned line_num = 0; char *line; while ((line = xmalloc_fgetline(orig_fp)) != NULL) { ++line_num; if (!ignored_problems_eq(set, problem_id, uuid, duphash, line, line_num)) { ssize_t len = strlen(line); line[len] = '\n'; if (full_write(new_tempfile_fd, line, len + 1) < 0) { /* Probably out of space */ line[len] = '\0'; perror_msg(_("Can't write to '%s'." " Problem '%s' will not be removed from the ignored" " problems '%s'"), new_tempfile_name, problem_id, set->ign_set_file_path); free(line); goto ret_unlink_new; } } free(line); } if (rename(new_tempfile_name, set->ign_set_file_path) < 0) { /* Something nefarious happened */ perror_msg(_("Can't rename '%s' to '%s'. Failed to remove problem '%s'"), set->ign_set_file_path, new_tempfile_name, problem_id); ret_unlink_new: unlink(new_tempfile_name); } ret_close_files: fclose(orig_fp); if (new_tempfile_fd >= 0) close(new_tempfile_fd); free(new_tempfile_name); }
/* * do_bdr_register() * * As each BDR node is its own primary, registering a BDR node * will create the repmgr metadata schema if necessary. */ void do_bdr_register(void) { PGconn *conn = NULL; BdrNodeInfoList bdr_nodes = T_BDR_NODE_INFO_LIST_INITIALIZER; ExtensionStatus extension_status = REPMGR_UNKNOWN; t_node_info node_info = T_NODE_INFO_INITIALIZER; RecordStatus record_status = RECORD_NOT_FOUND; PQExpBufferData event_details; bool success = true; char *dbname = NULL; /* sanity-check configuration for BDR-compatability */ if (config_file_options.replication_type != REPLICATION_TYPE_BDR) { log_error(_("cannot run BDR REGISTER on a non-BDR node")); exit(ERR_BAD_CONFIG); } dbname = pg_malloc0(MAXLEN); if (dbname == NULL) { log_error(_("unable to allocate memory; terminating.")); exit(ERR_OUT_OF_MEMORY); } /* store the database name for future reference */ get_conninfo_value(config_file_options.conninfo, "dbname", dbname); conn = establish_db_connection(config_file_options.conninfo, true); if (!is_bdr_db(conn, NULL)) { log_error(_("database \"%s\" is not BDR-enabled"), dbname); log_hint(_("when using repmgr with BDR, the repmgr schema must be stored in the BDR database")); PQfinish(conn); pfree(dbname); exit(ERR_BAD_CONFIG); } /* Check that there are at most 2 BDR nodes */ get_all_bdr_node_records(conn, &bdr_nodes); if (bdr_nodes.node_count == 0) { log_error(_("database \"%s\" is BDR-enabled but no BDR nodes were found"), dbname); PQfinish(conn); pfree(dbname); exit(ERR_BAD_CONFIG); } /* BDR 2 implementation is for 2 nodes only */ if (get_bdr_version_num() < 3 && bdr_nodes.node_count > 2) { log_error(_("repmgr can only support BDR 2.x clusters with 2 nodes")); log_detail(_("this BDR cluster has %i nodes"), bdr_nodes.node_count); PQfinish(conn); pfree(dbname); exit(ERR_BAD_CONFIG); } if (get_bdr_version_num() > 2) { log_error(_("\"repmgr bdr register\" is for BDR 2.x only")); PQfinish(conn); pfree(dbname); exit(ERR_BAD_CONFIG); } /* check for a matching BDR node */ { PQExpBufferData bdr_local_node_name; bool node_match = false; initPQExpBuffer(&bdr_local_node_name); node_match = bdr_node_name_matches(conn, config_file_options.node_name, &bdr_local_node_name); if (node_match == false) { if (strlen(bdr_local_node_name.data)) { log_error(_("local node BDR node name is \"%s\", expected: \"%s\""), bdr_local_node_name.data, config_file_options.node_name); log_hint(_("\"node_name\" in repmgr.conf must match \"node_name\" in bdr.bdr_nodes")); } else { log_error(_("local node does not report BDR node name")); log_hint(_("ensure this is an active BDR node")); } PQfinish(conn); pfree(dbname); termPQExpBuffer(&bdr_local_node_name); exit(ERR_BAD_CONFIG); } termPQExpBuffer(&bdr_local_node_name); } /* check whether repmgr extension exists, and there are no non-BDR nodes registered */ extension_status = get_repmgr_extension_status(conn, NULL); if (extension_status == REPMGR_UNKNOWN) { log_error(_("unable to determine status of \"repmgr\" extension in database \"%s\""), dbname); PQfinish(conn); pfree(dbname); exit(ERR_BAD_CONFIG); } if (extension_status == REPMGR_UNAVAILABLE) { log_error(_("\"repmgr\" extension is not available")); PQfinish(conn); pfree(dbname); exit(ERR_BAD_CONFIG); } if (extension_status == REPMGR_INSTALLED) { if (!is_bdr_repmgr(conn)) { log_error(_("repmgr metadatabase contains records for non-BDR nodes")); PQfinish(conn); pfree(dbname); exit(ERR_BAD_CONFIG); } } else { log_debug("creating repmgr extension in database \"%s\"", dbname); begin_transaction(conn); if (!create_repmgr_extension(conn)) { log_error(_("unable to create repmgr extension - see preceding error message(s); aborting")); rollback_transaction(conn); pfree(dbname); PQfinish(conn); exit(ERR_BAD_CONFIG); } commit_transaction(conn); } pfree(dbname); if (bdr_node_has_repmgr_set(conn, config_file_options.node_name) == false) { log_debug("bdr_node_has_repmgr_set() = false"); bdr_node_set_repmgr_set(conn, config_file_options.node_name); } /* * before adding the extension tables to the replication set, if any other * BDR nodes exist, populate repmgr.nodes with a copy of existing entries * * currently we won't copy the contents of any other tables * */ { NodeInfoList local_node_records = T_NODE_INFO_LIST_INITIALIZER; (void) get_all_node_records(conn, &local_node_records); if (local_node_records.node_count == 0) { BdrNodeInfoList bdr_nodes = T_BDR_NODE_INFO_LIST_INITIALIZER; BdrNodeInfoListCell *bdr_cell = NULL; get_all_bdr_node_records(conn, &bdr_nodes); if (bdr_nodes.node_count == 0) { log_error(_("unable to retrieve any BDR node records")); log_detail("%s", PQerrorMessage(conn)); PQfinish(conn); exit(ERR_BAD_CONFIG); } for (bdr_cell = bdr_nodes.head; bdr_cell; bdr_cell = bdr_cell->next) { PGconn *bdr_node_conn = NULL; NodeInfoList existing_nodes = T_NODE_INFO_LIST_INITIALIZER; NodeInfoListCell *cell = NULL; ExtensionStatus other_node_extension_status = REPMGR_UNKNOWN; /* skip the local node */ if (strncmp(node_info.node_name, bdr_cell->node_info->node_name, sizeof(node_info.node_name)) == 0) { continue; } log_debug("connecting to BDR node \"%s\" (conninfo: \"%s\")", bdr_cell->node_info->node_name, bdr_cell->node_info->node_local_dsn); bdr_node_conn = establish_db_connection_quiet(bdr_cell->node_info->node_local_dsn); if (PQstatus(bdr_node_conn) != CONNECTION_OK) { continue; } /* check repmgr schema exists, skip if not */ other_node_extension_status = get_repmgr_extension_status(bdr_node_conn, NULL); if (other_node_extension_status != REPMGR_INSTALLED) { continue; } (void) get_all_node_records(bdr_node_conn, &existing_nodes); for (cell = existing_nodes.head; cell; cell = cell->next) { log_debug("creating record for node \"%s\" (ID: %i)", cell->node_info->node_name, cell->node_info->node_id); create_node_record(conn, "bdr register", cell->node_info); } PQfinish(bdr_node_conn); break; } } } /* Add the repmgr extension tables to a replication set */ if (get_bdr_version_num() < 3) { add_extension_tables_to_bdr_replication_set(conn); } else { /* this is the only table we need to replicate */ char *replication_set = get_default_bdr_replication_set(conn); /* * this probably won't happen, but we need to be sure we're using * the replication set metadata correctly... */ if (conn == NULL) { log_error(_("unable to retrieve default BDR replication set")); log_hint(_("see preceding messages")); log_debug("check query in get_default_bdr_replication_set()"); exit(ERR_BAD_CONFIG); } if (is_table_in_bdr_replication_set(conn, "nodes", replication_set) == false) { add_table_to_bdr_replication_set(conn, "nodes", replication_set); } pfree(replication_set); } initPQExpBuffer(&event_details); begin_transaction(conn); /* * we'll check if a record exists (even if the schema was just created), * as there's a faint chance of a race condition */ record_status = get_node_record(conn, config_file_options.node_id, &node_info); /* Update internal node record */ node_info.type = BDR; node_info.node_id = config_file_options.node_id; node_info.upstream_node_id = NO_UPSTREAM_NODE; node_info.active = true; node_info.priority = config_file_options.priority; strncpy(node_info.node_name, config_file_options.node_name, sizeof(node_info.node_name)); strncpy(node_info.location, config_file_options.location, sizeof(node_info.location)); strncpy(node_info.conninfo, config_file_options.conninfo, sizeof(node_info.conninfo)); if (record_status == RECORD_FOUND) { bool node_updated = false; /* * At this point we will have established there are no non-BDR * records, so no need to verify the node type */ if (!runtime_options.force) { log_error(_("this node is already registered")); log_hint(_("use -F/--force to overwrite the existing node record")); rollback_transaction(conn); PQfinish(conn); exit(ERR_BAD_CONFIG); } /* * don't permit changing the node name - this must match the BDR node * name set when the node was registered. */ if (strncmp(node_info.node_name, config_file_options.node_name, sizeof(node_info.node_name)) != 0) { log_error(_("a record for node %i is already registered with node_name \"%s\""), config_file_options.node_id, node_info.node_name); log_hint(_("node_name configured in repmgr.conf is \"%s\""), config_file_options.node_name); rollback_transaction(conn); PQfinish(conn); exit(ERR_BAD_CONFIG); } node_updated = update_node_record(conn, "bdr register", &node_info); if (node_updated == true) { appendPQExpBuffer(&event_details, _("node record updated for node \"%s\" (%i)"), config_file_options.node_name, config_file_options.node_id); log_verbose(LOG_NOTICE, "%s", event_details.data); } else { success = false; } } else { /* create new node record */ bool node_created = create_node_record(conn, "bdr register", &node_info); if (node_created == true) { appendPQExpBuffer(&event_details, _("node record created for node \"%s\" (ID: %i)"), config_file_options.node_name, config_file_options.node_id); log_notice("%s", event_details.data); } else { success = false; } } if (success == false) { rollback_transaction(conn); PQfinish(conn); exit(ERR_DB_QUERY); } commit_transaction(conn); /* Log the event */ create_event_notification( conn, &config_file_options, config_file_options.node_id, "bdr_register", true, event_details.data); termPQExpBuffer(&event_details); PQfinish(conn); log_notice(_("BDR node %i registered (conninfo: %s)"), config_file_options.node_id, config_file_options.conninfo); return; }
/** * vrrp_ctrl_cmd() - Interprete control fifo cmd */ static inline vrrp_event_t vrrp_ctrl_cmd(struct vrrp *vrrp, struct vrrp_net *vnet) { int nword; nword = split_cmd(vrrp->ctrl.msg, vrrp->ctrl.cmd, CTRL_CMD_NTOKEN, WHITESPACE); if (nword == 0) return INVALID; /* * control cmd stop */ if (matches(vrrp->ctrl.cmd[0], "stop")) { log_notice("vrid %d :: control cmd stop, exiting", vrrp->vrid); set_bit(UVRRPD_RELOAD, ®); clear_bit(KEEP_GOING, ®); vrrp_ctrl_cmd_flush(&vrrp->ctrl); return CTRL_FIFO; } /* * control cmd reload */ if (matches(vrrp->ctrl.cmd[0], "reload")) { set_bit(UVRRPD_RELOAD, ®); vrrp_ctrl_cmd_flush(&vrrp->ctrl); return CTRL_FIFO; } /* * control cmd state || status */ if (matches(vrrp->ctrl.cmd[0], "state") || matches(vrrp->ctrl.cmd[0], "status")) { set_bit(UVRRPD_DUMP, ®); vrrp_ctrl_cmd_flush(&vrrp->ctrl); return CTRL_FIFO; } /* * control cmd prio */ if (matches(vrrp->ctrl.cmd[0], "prio")) { if (nword != 2) { log_error ("vrid %d :: invalid syntax, control cmd prio <priority>", vrrp->vrid); vrrp_ctrl_cmd_flush(&vrrp->ctrl); return INVALID; } /* fetch priority */ int err; unsigned long opt; err = mystrtoul(&opt, vrrp->ctrl.cmd[1], VRRP_PRIO_MAX); vrrp_ctrl_cmd_flush(&vrrp->ctrl); if (err == -ERANGE) { log_error ("vrid %d :: invalid control cmd prio, 0 < priority < 255", vrrp->vrid); return INVALID; } if (err == -EINVAL) { log_error ("vrid %d :: invalid control cmd prio, error parsing \"%s\" as a number", vrrp->vrid, vrrp->ctrl.cmd[1]); return INVALID; } /* change prio */ if (vrrp->priority != (uint8_t) opt) { vrrp->priority = (uint8_t) opt; vrrp_adv_set_priority(vnet, vrrp->priority); } /* reload bit */ set_bit(UVRRPD_RELOAD, ®); return CTRL_FIFO; } vrrp_ctrl_cmd_flush(&vrrp->ctrl); return INVALID; }
int vconsole_convert_to_x11(Context *c) { const char *map; int modified = -1; map = systemd_kbd_model_map(); if (isempty(c->vc_keymap)) { modified = !isempty(c->x11_layout) || !isempty(c->x11_model) || !isempty(c->x11_variant) || !isempty(c->x11_options); context_free_x11(c); } else { _cleanup_fclose_ FILE *f = NULL; unsigned n = 0; f = fopen(map, "re"); if (!f) return -errno; for (;;) { _cleanup_strv_free_ char **a = NULL; int r; r = read_next_mapping(map, 5, UINT_MAX, f, &n, &a); if (r < 0) return r; if (r == 0) break; if (!streq(c->vc_keymap, a[0])) continue; if (!streq_ptr(c->x11_layout, strnulldash(a[1])) || !streq_ptr(c->x11_model, strnulldash(a[2])) || !streq_ptr(c->x11_variant, strnulldash(a[3])) || !streq_ptr(c->x11_options, strnulldash(a[4]))) { if (free_and_strdup(&c->x11_layout, strnulldash(a[1])) < 0 || free_and_strdup(&c->x11_model, strnulldash(a[2])) < 0 || free_and_strdup(&c->x11_variant, strnulldash(a[3])) < 0 || free_and_strdup(&c->x11_options, strnulldash(a[4])) < 0) return -ENOMEM; modified = true; } break; } } if (modified > 0) log_info("Changing X11 keyboard layout to '%s' model '%s' variant '%s' options '%s'", strempty(c->x11_layout), strempty(c->x11_model), strempty(c->x11_variant), strempty(c->x11_options)); else if (modified < 0) log_notice("X11 keyboard layout was not modified: no conversion found for \"%s\".", c->vc_keymap); else log_debug("X11 keyboard layout did not need to be modified."); return modified > 0; }
static dove_status set_local_ip() { struct ifaddrs *myaddrs, *ifa; struct sockaddr_in *s4; dove_status dps_status = DOVE_STATUS_EMPTY; //struct sockaddr_in6 *s6; int status; char buf[INET6_ADDRSTRLEN]; myaddrs = NULL; do { dps_status = get_sva_interface_ip(); if (dps_status == DOVE_STATUS_OK) { break; } status = getifaddrs(&myaddrs); if (status != 0) { break; } for (ifa = myaddrs; ifa != NULL; ifa = ifa->ifa_next) { if (ifa->ifa_addr == NULL) { continue; } if ((ifa->ifa_flags & IFF_UP) == 0) { continue; } if (ifa->ifa_addr->sa_family == AF_INET) { s4 = (struct sockaddr_in *)(ifa->ifa_addr); if (ntohl(s4->sin_addr.s_addr) == INADDR_LOOPBACK) { continue; } // Check if this was the SVA_INTERFACE_NAME if (inet_ntop(AF_INET, (void *)&(s4->sin_addr), buf, sizeof(buf)) != NULL) { dcs_local_ip.family = AF_INET; dcs_local_ip.ip4 = s4->sin_addr.s_addr; dps_status = DOVE_STATUS_OK; break; } if (!strcmp(ifa->ifa_name, SVA_INTERFACE_NAME)) { // If we found APBR, then we have our local IP! break; } } //Don't show IPv6 Address yet //else if (ifa->ifa_addr->sa_family == AF_INET6) //{ // s6 = (struct sockaddr_in6 *)(ifa->ifa_addr); // if (inet_ntop(AF_INET6, (void *)&(s6->sin6_addr), buf, sizeof(buf)) != NULL) // { // break; // } //} } } while(0); if (myaddrs != NULL) { free(myaddrs); } dcs_cluster_node_local_update(&dcs_local_ip); // Update Leader and Controller information if they are still LOOPBACK //if (dps_cluster_leader.ip4 == htonl(INADDR_LOOPBACK)) //{ // set_initial_dps_cluster_leader(); //} if (controller_location.ip4 == htonl(INADDR_LOOPBACK)) { set_initial_controller_location(); } log_notice(PythonDataHandlerLogLevel, "Initializing DCS REST Server"); if(dps_status == DOVE_STATUS_OK && dps_rest_server_init_ok == 0) { if(dcs_server_rest_init(DPS_REST_HTTPD_PORT) == DOVE_STATUS_OK) { dps_rest_server_init_ok = 1; } } return dps_status; }
/* * Parse configuration file; if any errors are encountered, * list them and exit. * * Ensure any default values set here are synced with repmgr.conf.sample * and any other documentation. */ bool parse_config(t_configuration_options *options) { FILE *fp; char *s, buff[MAXLINELENGTH]; char name[MAXLEN]; char value[MAXLEN]; /* For sanity-checking provided conninfo string */ PQconninfoOption *conninfo_options; char *conninfo_errmsg = NULL; /* Collate configuration file errors here for friendlier reporting */ static ErrorList config_errors = { NULL, NULL }; fp = fopen(config_file_path, "r"); /* * Since some commands don't require a config file at all, not having one * isn't necessarily a problem. * * If the user explictly provided a configuration file and we can't * read it we'll raise an error. * * If no configuration file was provided, we'll try and read the default\ * file if it exists and is readable, but won't worry if it's not. */ if (fp == NULL) { if (config_file_provided) { log_err(_("unable to open provided configuration file '%s'; terminating\n"), config_file_path); exit(ERR_BAD_CONFIG); } log_notice(_("no configuration file provided and default file '%s' not found - " "continuing with default values\n"), DEFAULT_CONFIG_FILE); return false; } /* Initialize configuration options with sensible defaults * note: the default log level is set in log.c and does not need * to be initialised here */ memset(options->cluster_name, 0, sizeof(options->cluster_name)); options->node = -1; options->upstream_node = NO_UPSTREAM_NODE; options->use_replication_slots = 0; memset(options->conninfo, 0, sizeof(options->conninfo)); options->failover = MANUAL_FAILOVER; options->priority = DEFAULT_PRIORITY; memset(options->node_name, 0, sizeof(options->node_name)); memset(options->promote_command, 0, sizeof(options->promote_command)); memset(options->follow_command, 0, sizeof(options->follow_command)); memset(options->rsync_options, 0, sizeof(options->rsync_options)); memset(options->ssh_options, 0, sizeof(options->ssh_options)); memset(options->pg_bindir, 0, sizeof(options->pg_bindir)); memset(options->pg_ctl_options, 0, sizeof(options->pg_ctl_options)); memset(options->pg_basebackup_options, 0, sizeof(options->pg_basebackup_options)); /* default master_response_timeout is 60 seconds */ options->master_response_timeout = 60; /* default to 6 reconnection attempts at intervals of 10 seconds */ options->reconnect_attempts = 6; options->reconnect_interval = 10; options->monitor_interval_secs = 2; options->retry_promote_interval_secs = 300; memset(options->event_notification_command, 0, sizeof(options->event_notification_command)); options->tablespace_mapping.head = NULL; options->tablespace_mapping.tail = NULL; /* Read next line */ while ((s = fgets(buff, sizeof buff, fp)) != NULL) { bool known_parameter = true; /* Parse name/value pair from line */ parse_line(buff, name, value); /* Skip blank lines */ if (!strlen(name)) continue; /* Skip comments */ if (name[0] == '#') continue; /* Copy into correct entry in parameters struct */ if (strcmp(name, "cluster") == 0) strncpy(options->cluster_name, value, MAXLEN); else if (strcmp(name, "node") == 0) options->node = repmgr_atoi(value, "node", &config_errors); else if (strcmp(name, "upstream_node") == 0) options->upstream_node = repmgr_atoi(value, "upstream_node", &config_errors); else if (strcmp(name, "conninfo") == 0) strncpy(options->conninfo, value, MAXLEN); else if (strcmp(name, "rsync_options") == 0) strncpy(options->rsync_options, value, QUERY_STR_LEN); else if (strcmp(name, "ssh_options") == 0) strncpy(options->ssh_options, value, QUERY_STR_LEN); else if (strcmp(name, "loglevel") == 0) strncpy(options->loglevel, value, MAXLEN); else if (strcmp(name, "logfacility") == 0) strncpy(options->logfacility, value, MAXLEN); else if (strcmp(name, "failover") == 0) { char failoverstr[MAXLEN]; strncpy(failoverstr, value, MAXLEN); if (strcmp(failoverstr, "manual") == 0) { options->failover = MANUAL_FAILOVER; } else if (strcmp(failoverstr, "automatic") == 0) { options->failover = AUTOMATIC_FAILOVER; } else { log_err(_("value for 'failover' must be 'automatic' or 'manual'\n")); exit(ERR_BAD_CONFIG); } } else if (strcmp(name, "priority") == 0) options->priority = repmgr_atoi(value, "priority", &config_errors); else if (strcmp(name, "node_name") == 0) strncpy(options->node_name, value, MAXLEN); else if (strcmp(name, "promote_command") == 0) strncpy(options->promote_command, value, MAXLEN); else if (strcmp(name, "follow_command") == 0) strncpy(options->follow_command, value, MAXLEN); else if (strcmp(name, "master_response_timeout") == 0) options->master_response_timeout = repmgr_atoi(value, "master_response_timeout", &config_errors); /* 'primary_response_timeout' as synonym for 'master_response_timeout' - * we'll switch terminology in a future release (3.1?) */ else if (strcmp(name, "primary_response_timeout") == 0) options->master_response_timeout = repmgr_atoi(value, "primary_response_timeout", &config_errors); else if (strcmp(name, "reconnect_attempts") == 0) options->reconnect_attempts = repmgr_atoi(value, "reconnect_attempts", &config_errors); else if (strcmp(name, "reconnect_interval") == 0) options->reconnect_interval = repmgr_atoi(value, "reconnect_interval", &config_errors); else if (strcmp(name, "pg_bindir") == 0) strncpy(options->pg_bindir, value, MAXLEN); else if (strcmp(name, "pg_ctl_options") == 0) strncpy(options->pg_ctl_options, value, MAXLEN); else if (strcmp(name, "pg_basebackup_options") == 0) strncpy(options->pg_basebackup_options, value, MAXLEN); else if (strcmp(name, "logfile") == 0) strncpy(options->logfile, value, MAXLEN); else if (strcmp(name, "monitor_interval_secs") == 0) options->monitor_interval_secs = repmgr_atoi(value, "monitor_interval_secs", &config_errors); else if (strcmp(name, "retry_promote_interval_secs") == 0) options->retry_promote_interval_secs = repmgr_atoi(value, "retry_promote_interval_secs", &config_errors); else if (strcmp(name, "use_replication_slots") == 0) /* XXX we should have a dedicated boolean argument format */ options->use_replication_slots = repmgr_atoi(value, "use_replication_slots", &config_errors); else if (strcmp(name, "event_notification_command") == 0) strncpy(options->event_notification_command, value, MAXLEN); else if (strcmp(name, "event_notifications") == 0) parse_event_notifications_list(options, value); else if (strcmp(name, "tablespace_mapping") == 0) tablespace_list_append(options, value); else { known_parameter = false; log_warning(_("%s/%s: unknown name/value pair provided; ignoring\n"), name, value); } /* * Raise an error if a known parameter is provided with an empty value. * Currently there's no reason why empty parameters are needed; if * we want to accept those, we'd need to add stricter default checking, * as currently e.g. an empty `node` value will be converted to '0'. */ if (known_parameter == true && !strlen(value)) { char error_message_buf[MAXLEN] = ""; snprintf(error_message_buf, MAXLEN, _("no value provided for parameter \"%s\""), name); error_list_append(&config_errors, error_message_buf); } } fclose(fp); /* Check config settings */ /* The following checks are for the presence of the parameter */ if (*options->cluster_name == '\0') { error_list_append(&config_errors, _("\"cluster\": parameter was not found\n")); } if (options->node == -1) { error_list_append(&config_errors, _("\"node\": parameter was not found\n")); } if (*options->node_name == '\0') { error_list_append(&config_errors, _("\"node_name\": parameter was not found\n")); } if (*options->conninfo == '\0') { error_list_append(&config_errors, _("\"conninfo\": parameter was not found\n")); } else { /* Sanity check the provided conninfo string * * NOTE: this verifies the string format and checks for valid options * but does not sanity check values */ conninfo_options = PQconninfoParse(options->conninfo, &conninfo_errmsg); if (conninfo_options == NULL) { char error_message_buf[MAXLEN] = ""; snprintf(error_message_buf, MAXLEN, _("\"conninfo\": %s"), conninfo_errmsg); error_list_append(&config_errors, error_message_buf); } PQconninfoFree(conninfo_options); } // exit_with_errors here if (config_errors.head != NULL) { exit_with_errors(&config_errors); } return true; }
/* ****************************************************************************** * dcs_set_service_role -- *//** * * \brief This routine starts or stops the DCS service role * * \param action 1:Activate/Set Local Node, 0:Reset Local Node * * \return dove_status * *****************************************************************************/ dove_status dcs_set_service_role(uint32_t action) { dove_status status = DOVE_STATUS_ERROR; do { if (action) { status = dcs_cluster_node_local_update(&dcs_local_ip); if (status != DOVE_STATUS_OK) { log_alert(RESTHandlerLogLevel, "ALERT! DCS Clustering cannot set local IP"); break; } status = dcs_controller_interface_start(); if (status != DOVE_STATUS_OK) { log_alert(RESTHandlerLogLevel, "ALERT! DCS Controller Interface cannot be started"); break; } status = dcs_protocol_handler_start(); if (status != DOVE_STATUS_OK) { log_alert(RESTHandlerLogLevel, "ALERT! DCS Client Server Protocol cannot be started"); break; } /* do "cluster node add" via sending "query cluster info" */ status = dcs_cluster_node_local_activate(1); if (status != DOVE_STATUS_OK) { log_alert(RESTHandlerLogLevel, "ALERT! DCS Clustering cannot activate Local Node"); break; } //Query the Controller for Cluster Information dcs_role_assigned = 1; } else { status = dcs_cluster_node_local_activate(0); if (status != DOVE_STATUS_OK) { log_alert(RESTHandlerLogLevel, "ALERT! DCS Clustering cannot deactivate Local Node"); break; } status = dcs_protocol_handler_stop(); if (status != DOVE_STATUS_OK) { log_alert(RESTHandlerLogLevel, "ALERT! DCS Client Server Protocol cannot be stopped"); dcs_cluster_node_local_activate(1); break; } status = dcs_controller_interface_stop(); if (status != DOVE_STATUS_OK) { log_alert(RESTHandlerLogLevel, "ALERT! DCS Controller Interface cannot be stopped"); dcs_cluster_node_local_activate(1); dcs_protocol_handler_start(); break; } dcs_role_assigned = 0; cluster_config_version = 0; } dcs_write_role_to_file(dcs_role_assigned); do { if (!controller_location_set) { log_info(RESTHandlerLogLevel, "Controller not set by user"); break; } if (dcs_local_ip.ip4 == htonl(INADDR_LOOPBACK)) { log_info(RESTHandlerLogLevel, "Local IP not yet set. Not point in sending query"); break; } if(get_dps_appliance_registration_needed()) { log_notice(RESTHandlerLogLevel, "DCS: Sending Appliance Registration"); dps_appliance_registration(); } /*if (action) { log_notice(RESTHandlerLogLevel, "DCS: Sending Query to DMC for list of Nodes"); dps_rest_client_query_dove_controller_cluster_info(); }*/ }while(0); }while(0); return status; }