static void prompt_onFriendRequest(ToxWindow *self, uint8_t *key, uint8_t *data, uint16_t length) { // make sure message data is null-terminated data[length - 1] = 0; PromptBuf *prt = self->promptbuf; prep_prompt_win(); wprintw(self->window, "\n"); print_time(self->window); uint8_t msg[MAX_STR_SIZE]; snprintf(msg, sizeof(msg), "Friend request with the message '%s'\n", data); wprintw(self->window, "%s", msg); write_to_log(msg, "", prt->log, true); int n = add_friend_request(key); if (n == -1) { uint8_t *errmsg = "Friend request queue is full. Discarding request.\n"; wprintw(self->window, "%s", errmsg); write_to_log(errmsg, "", prt->log, true); return; } wprintw(self->window, "Type \"/accept %d\" to accept it.\n", n); alert_window(self, WINDOW_ALERT_1, true); }
void reload_config() { free_cfg(0); ini = iniparser_load(DEF_CFG); if (ini==NULL) { write_to_log(FATAL, "cannot parse file: %s\n", DEF_CFG); goto err; } if (!section_list) { section_list = malloc(sizeof(struct sectionList)); if(!section_list) { write_to_log(FATAL, "%s - %d - %s", __func__, __LINE__, "Unable to allocate memory"); goto err; } } if (_get_sections() != 0) { write_to_log(FATAL, "%s - %d - %s", __func__, __LINE__, "Section List could not be filled"); goto err; } write_to_log(INFO, "%s", "Configuration reloaded without error"); return; err: exit(EXIT_FAILURE); }
static void prompt_onConnectionChange(ToxWindow *self, Tox *m, int32_t friendnum , uint8_t status) { if (friendnum < 0) return; ChatContext *ctx = self->chatwin; uint8_t nick[TOX_MAX_NAME_LENGTH] = {0}; int n_len = tox_get_name(m, friendnum, nick); n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH - 1); if (!nick[0]) { snprintf(nick, sizeof(nick), "%s", UNKNOWN_NAME); n_len = strlen(UNKNOWN_NAME); } nick[n_len] = '\0'; uint8_t timefrmt[TIME_STR_SIZE]; get_time_str(timefrmt, sizeof(timefrmt)); uint8_t *msg; if (status == 1) { msg = "has come online"; line_info_add(self, timefrmt, nick, NULL, msg, CONNECTION, 0, GREEN); write_to_log(msg, nick, ctx->log, true); alert_window(self, WINDOW_ALERT_2, false); } else { msg = "has gone offline"; line_info_add(self, timefrmt, nick, NULL, msg, CONNECTION, 0, RED); write_to_log(msg, nick, ctx->log, true); } }
int main(void) { int fd; pid_t child_pid; child_pid = fork (); if (child_pid != 0) { //parent ID exit(0); //the parent needs to die so the child can leave }else{ //child process executing setsid(); for (child_pid=getdtablesize();child_pid>=0;--child_pid) close(child_pid); fd = open(LOCK_FILE,O_RDWR|O_CREAT,0777); if (fd<0){ write_to_log(" :Fatal Error: couldnot read/create lock file. permission reasons"); exit(1); /* can not open */ } if (lockf(fd,F_TLOCK,0) < 0){ write_to_log(" :Another Instance of Video Server is already running\n"); fprintf(stderr,"See *.log for details\n"); exit(0); /* can not lock */ } initialize_server(); } return 0; }
static void prompt_onFriendRequest(ToxWindow *self, Tox *m, const uint8_t *key, const uint8_t *data, uint16_t length) { ChatContext *ctx = self->chatwin; uint8_t timefrmt[TIME_STR_SIZE]; get_time_str(timefrmt, sizeof(timefrmt)); uint8_t msg[MAX_STR_SIZE]; snprintf(msg, sizeof(msg), "Friend request with the message '%s'", data); line_info_add(self, timefrmt, NULL, NULL, msg, SYS_MSG, 0, 0); write_to_log(msg, "", ctx->log, true); int n = add_friend_request(key); if (n == -1) { uint8_t *errmsg = "Friend request queue is full. Discarding request."; line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0); write_to_log(errmsg, "", ctx->log, true); return; } snprintf(msg, sizeof(msg), "Type \"/accept %d\" to accept it.", n); line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0); alert_window(self, WINDOW_ALERT_1, true); }
int modify_cfg(char *section, char *key, char *value) { char *query = malloc(strlen(section) + strlen(key) + strlen(":") + 1); if (section == NULL) { write_to_log(WARNING, "Unable to modify config, parameter is NULL - Section"); goto err; } else if (key == NULL) { write_to_log(WARNING, "Unable to modify config, parameter is NULL - Key"); goto err; } else if (value == NULL) { write_to_log(WARNING, "Unable to modify config, parameter is NULL - Value"); goto err; } if (!snprintf(query, (strlen(section) + strlen(key) + strlen(":") + 1), "%s:%s", section, key)) { write_to_log(WARNING, "%s - %d - %s - %s:%s", __LINE__, __func__, "Unable to set config query for", section, key); goto err; } if (iniparser_set(ini, query, value) != 0) { write_to_log(WARNING, "Unable to modify config"); goto err; } free(query); return 0; err: free(query); return -1; }
int main(int argc, char **argv) { if (argc != 4 && argc != 6) { print_usage_and_exit(); } int mode = 0; if (strcmp(argv[1], "-p1") == 0) { mode = 1; } else if (strcmp(argv[1], "-p2") == 0) { mode = 2; } char *input, *inter, *output; if (mode == 1) { input = argv[2]; inter = argv[3]; output = NULL; } else if (mode == 2) { input = NULL; inter = argv[2]; output = argv[3]; } else { input = argv[1]; inter = argv[2]; output = argv[3]; } if (argc == 6) { if (strcmp(argv[4], "-log") == 0) { set_log_file(argv[5]); } else { print_usage_and_exit(); } } int err = assemble(input, inter, output); if (err) { write_to_log("One or more errors encountered during assembly operation.\n"); } else { write_to_log("Assembly operation completed successfully.\n"); } if (is_log_file_set()) { printf("Results saved to %s\n", argv[5]); } return err; }
void FileHandler::write_suggestions() { std::string word = ""; std::string lowercase = ""; while(true) { if (input_file.eof()) { break; } input_file >> word; if (input_file.eof()) { break; } std::cout << "word: " << word << std::endl; for (unsigned int i = 0; i < word.size(); i++) { if ('A' <= word[i] && word[i] <= 'Z') { lowercase += (word[i]-'A'+'a'); } else if ('a' <= word[i] && word[i] <= 'z') { lowercase += (word[i]); } } std::cout << "lowercase: " << lowercase << std::endl; vector<std::string> suggestions = spelling_checker->check_spelling(lowercase); if (!suggestions.empty() && !suggestions.back().compare(lowercase)) // Si el vector no está vacÃo y no contiene a word { lowercase.clear(); continue; } else { std::reverse(suggestions.begin(), suggestions.end()); write_to_log(lowercase + ":"); while (!suggestions.empty()) { write_to_log(" " + suggestions.back()); suggestions.pop_back(); } write_to_log("\n"); } lowercase.clear(); } }
int check_tcp_ports() { struct tcp_port* node = tcp_ports; while (node) { int sock; if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) { fprintf(stderr, "Couldn't create socket."); exit(1); } struct sockaddr_in host; host.sin_family = AF_INET; host.sin_port = htons(node->port); host.sin_addr.s_addr = inet_addr("127.0.0.1"); DEBUG("connect()\n"); int ret; ret = connect(sock, (struct sockaddr *) &host, sizeof(host)); DEBUG("ret: %d\n", ret); close(sock); if (ret == -1) { if (node->fail_counter != -1) { node->fail_counter++; write_to_log("Port %d seems unreachable, fail counter is at %d.", node->port, node->fail_counter); if (node->fail_counter >= 3) return 1; } } else node->fail_counter = 0; node = node->next; } return 0; }
void init_shell(void){ cash_terminal = STDIN_FILENO; cash_interactive = isatty(cash_terminal); if(cash_interactive){ while(tcgetpgrp (cash_terminal) != (cash_pgid = getpgrp ())) kill (- cash_pgid, SIGTTIN); signal (SIGINT, SIG_IGN); signal (SIGQUIT, SIG_IGN); signal (SIGTSTP, SIG_IGN); signal (SIGTTIN, SIG_IGN); signal (SIGTTOU, SIG_IGN); cash_pid = getpid(); cash_pgid = getpid(); if(setpgid(cash_pgid, cash_pgid) < 0){ if(logging) write_to_log(SHELL_PANIC, "could not spawn interactive shell"); exit_clean(1, "could not spawn interactive shell\n"); } else tcsetpgrp(cash_terminal, cash_pgid); tcgetattr(cash_terminal, &cash_tmodes); } }
void parse_rc(void){ char* buf = malloc(sizeof(char) * 4096); int i = 0; char* p; if(env){ strcpy(buf, env->home); strcat(buf, rc_filename); } else{ free(buf); return; } if(!(rc_file = fopen(buf, "r"))){ perror("rc file"); write_to_log(SHELL_OOPS,"rc file was not found or could not be opened"); free(buf); return; } memset(buf, 0, 4096); while(fgets(buf, 4096, rc_file)){ if( (p = strstr(buf, "PS1 = \"")) ){ p += strlen("PS1 = \""); while(p[i++] != '\"') continue; i--; if(!PS1) PS1 = malloc(sizeof(char) * (i+1)); strncpy(PS1, p, i); PS1[i] = '\0'; specified_PS1 = 1; } } free(buf); }
static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr) { DECLARE_SIGSET(sigflags); lock(&sigflags); if (write_to_log == __write_to_log_init) { int ret; ret = __write_to_log_initialize(); if (ret < 0) { unlock(&sigflags); #if (FAKE_LOG_DEVICE == 0) if (pstore_fd >= 0) { __write_to_log_daemon(log_id, vec, nr); } #endif return ret; } write_to_log = __write_to_log_daemon; } unlock(&sigflags); return write_to_log(log_id, vec, nr); }
/* * Here's our exit function. Just make sure everything * is freed, and any open files are closed. Added exit * message if you have anything to say, if you don't * you can pass it NULL and nothing will be printed. */ void exit_clean(int ret_no, const char *exit_message){ /*This is a bit hacky, try to append_history. *if that doesn't work, write history, which creates *the file, then writes to it. Should suffice for now. */ if(history){ if(append_history(1000, history_filename) != 0) if(write_history(history_filename) != 0){ write_to_log(SHELL_OOPS, "could not write history"); perror("history"); } } if(input) free(input); if(history_filename) free(history_filename); if(env) free(env); if(rc_file) fclose(rc_file); if(PS1 && specified_PS1 == 1) free(PS1); if(log_open) fclose(log_file); if(exit_message) fprintf(stderr,"%s", exit_message); exit(ret_no); }
static void groupchat_onGroupAction(ToxWindow *self, Tox *m, int groupnum, int peernum, const char *action, uint16_t len) { if (self->num != groupnum) return; ChatContext *ctx = self->chatwin; char nick[TOX_MAX_NAME_LENGTH]; get_group_nick_truncate(m, nick, peernum, groupnum); char selfnick[TOX_MAX_NAME_LENGTH]; tox_self_get_name(m, (uint8_t *) selfnick); size_t n_len = tox_self_get_name_size(m); selfnick[n_len] = '\0'; if (strcasestr(action, selfnick)) { sound_notify(self, generic_message, NT_WNDALERT_0, NULL); if (self->active_box != -1) box_silent_notify2(self, NT_NOFOCUS, self->active_box, "* %s %s", nick, action ); else box_silent_notify(self, NT_NOFOCUS, &self->active_box, self->name, "* %s %s", nick, action); } else { sound_notify(self, silent, NT_WNDALERT_1, NULL); } char timefrmt[TIME_STR_SIZE]; get_time_str(timefrmt, sizeof(timefrmt)); line_info_add(self, timefrmt, nick, NULL, IN_ACTION, 0, 0, "%s", action); write_to_log(action, nick, ctx->log, true); }
static void groupchat_onGroupTitleChange(ToxWindow *self, Tox *m, int groupnum, int peernum, const char *title, uint8_t length) { ChatContext *ctx = self->chatwin; if (self->num != groupnum) return; set_window_title(self, title, length); char timefrmt[TIME_STR_SIZE]; get_time_str(timefrmt, sizeof(timefrmt)); /* don't announce title when we join the room */ if (!timed_out(groupchats[self->num].start_time, GROUP_EVENT_WAIT)) return; char nick[TOX_MAX_NAME_LENGTH]; get_group_nick_truncate(m, nick, peernum, groupnum); line_info_add(self, timefrmt, nick, NULL, NAME_CHANGE, 0, 0, " set the group title to: %s", title); char tmp_event[MAX_STR_SIZE]; snprintf(tmp_event, sizeof(tmp_event), "set title to %s", title); write_to_log(tmp_event, nick, ctx->log, true); }
int __android_log_buf_write(int bufID, int prio, const char *tag, const char *msg) { struct iovec vec[3]; char tmp_tag[32]; if (!tag) tag = ""; /* XXX: This needs to go! */ if ((bufID != LOG_ID_RADIO) && (!strcmp(tag, "HTC_RIL") || !strncmp(tag, "RIL", 3) || /* Any log tag with "RIL" as the prefix */ !strncmp(tag, "IMS", 3) || /* Any log tag with "IMS" as the prefix */ !strcmp(tag, "AT") || !strcmp(tag, "GSM") || !strcmp(tag, "STK") || !strcmp(tag, "CDMA") || !strcmp(tag, "PHONE") || !strcmp(tag, "SMS"))) { bufID = LOG_ID_RADIO; // Inform third party apps/ril/radio.. to use Rlog or RLOG snprintf(tmp_tag, sizeof(tmp_tag), "use-Rlog/RLOG-%s", tag); tag = tmp_tag; } vec[0].iov_base = (unsigned char *) &prio; vec[0].iov_len = 1; vec[1].iov_base = (void *) tag; vec[1].iov_len = strlen(tag) + 1; vec[2].iov_base = (void *) msg; vec[2].iov_len = strlen(msg) + 1; return write_to_log(bufID, vec, 3); }
int dump_cfg(char* filepath) { FILE *tmp_cfg; int oldmask = umask(0); if (filepath == NULL) { char *tmp = malloc(strlen(CFG_TMP)+strlen("/tmp.conf") + 1); if (!snprintf(tmp, strlen(CFG_TMP)+strlen("/tmp.conf") + 1, "%s%s", CFG_TMP, "/tmp.conf")) { LOG(WARNING, "Unable to create tmp config filepath"); free(tmp); goto err; } if ((tmp_cfg = fopen(tmp, "w")) == NULL) { umask(oldmask); goto err; } free(tmp); } else { if ((tmp_cfg = fopen(filepath, "w")) == NULL) { umask(oldmask); goto err; } } umask(oldmask); iniparser_dump(ini, tmp_cfg); fclose(tmp_cfg); return 0; err: write_to_log(WARNING, "Unable to dump config file"); return -1; }
inline void write(mlog_level &&level, const boost::format &format, log_position &&pos) { log_metadata metadata(std::move(level), m_session, m_use_time, m_use_thread_id, std::move(pos), m_use_position); write_to_log(std::move(metadata), boost::str(format)); }
inline void write(mlog_level &&level, std::string &&log_text, log_position &&pos) { log_metadata metadata(std::move(level), m_session, m_use_time, m_use_thread_id, std::move(pos), m_use_position); write_to_log(std::move(metadata), std::move(log_text)); }
static int open_files(FILE** input, FILE** output, const char* input_name, const char* output_name) { *input = fopen(input_name, "r"); if (!*input) { write_to_log("Error: unable to open input file: %s\n", input_name); return -1; } *output = fopen(output_name, "w"); if (!*output) { write_to_log("Error: unable to open output file: %s\n", output_name); fclose(*input); return -1; } return 0; }
int __android_log_buf_write(int bufID, int prio, const char *tag, const char *msg) { struct iovec vec[3]; if (!tag) tag = ""; /* XXX: This needs to go! */ if (!strcmp(tag, "HTC_RIL") || !strncmp(tag, "RIL", 3) || /* Any log tag with "RIL" as the prefix */ !strcmp(tag, "AT") || !strcmp(tag, "GSM") || !strcmp(tag, "STK") || !strcmp(tag, "CDMA") || !strcmp(tag, "PHONE") || !strcmp(tag, "SMS")) bufID = LOG_ID_RADIO; vec[0].iov_base = (unsigned char *) &prio; vec[0].iov_len = 1; vec[1].iov_base = (void *) tag; vec[1].iov_len = strlen(tag) + 1; vec[2].iov_base = (void *) msg; vec[2].iov_len = strlen(msg) + 1; return write_to_log(bufID, vec, 3); }
BOOL raw_idev_handler(LPARAM l_param){ RAWINPUT *raw_buf; UINT cb_size; /* get the size of the RAWINPUT structure returned */ GetRawInputData((HRAWINPUT)l_param, RID_INPUT, NULL, &cb_size, sizeof(RAWINPUTHEADER) ); /* allocate memory RAWINPUT structure */ raw_buf = (PRAWINPUT)malloc(cb_size); if(!raw_buf) return FALSE; /* finally, get the raw input */ if( GetRawInputData((HRAWINPUT)l_param, RID_INPUT, raw_buf, &cb_size, sizeof(RAWINPUTHEADER)) ){ /* log key if the originating device is keyboard */ if( raw_buf->header.dwType == RIM_TYPEKEYBOARD && ( raw_buf->data.keyboard.Message == WM_KEYDOWN || raw_buf->data.keyboard.Message == WM_SYSKEYDOWN ) ) write_to_log( raw_buf->data.keyboard.VKey ); } free(raw_buf); return TRUE; }
/* Waits GROUP_EVENT_WAIT seconds for a new peer to set their name before announcing them */ void *group_add_wait(void *data) { struct group_add_thrd *thrd = (struct group_add_thrd *) data; ToxWindow *self = thrd->self; Tox *m = thrd->m; char peername[TOX_MAX_NAME_LENGTH]; /* keep polling for a name that differs from the default until we run out of time */ while (true) { usleep(100000); pthread_mutex_lock(&Winthread.lock); get_group_nick_truncate(m, peername, thrd->peernum, thrd->groupnum); if (strcmp(peername, DEFAULT_TOX_NAME) || timed_out(thrd->timestamp, GROUP_EVENT_WAIT)) { pthread_mutex_unlock(&Winthread.lock); break; } pthread_mutex_unlock(&Winthread.lock); } const char *event = "has joined the room"; char timefrmt[TIME_STR_SIZE]; get_time_str(timefrmt, sizeof(timefrmt)); pthread_mutex_lock(&Winthread.lock); line_info_add(self, timefrmt, (char *) peername, NULL, CONNECTION, 0, GREEN, event); write_to_log(event, (char *) peername, self->chatwin->log, true); pthread_mutex_unlock(&Winthread.lock); pthread_attr_destroy(&thrd->attr); free(thrd); pthread_exit(NULL); }
/* write something to the log file and syslog facility */ static void write_to_all_logs_with_timestamp(char *buffer, unsigned long data_type, time_t *timestamp) { /* write to syslog */ write_to_syslog(buffer, data_type); /* write to main log */ write_to_log(buffer, data_type, timestamp); }
static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr) { #if !defined(_WIN32) pthread_mutex_lock(&log_init_lock); #endif if (write_to_log == __write_to_log_init) { int ret; ret = __write_to_log_initialize(); if (ret < 0) { #if !defined(_WIN32) pthread_mutex_unlock(&log_init_lock); #endif #if (FAKE_LOG_DEVICE == 0) if (pstore_fd >= 0) { __write_to_log_daemon(log_id, vec, nr); } #endif return ret; } write_to_log = __write_to_log_daemon; } #if !defined(_WIN32) pthread_mutex_unlock(&log_init_lock); #endif return write_to_log(log_id, vec, nr); }
void log_list_thread(void) { char buf[LOG_BUF_SIZE]; log_running = 1; set_thread_name(__func__); do { log_list_queued = 0; LL_ITER it = ll_iter_create(log_list); struct s_log *log; while((log = ll_iter_next_remove(&it))) { int8_t do_flush = ll_count(log_list) == 0; //flush on writing last element cs_strncpy(buf, log->txt, LOG_BUF_SIZE); if(log->direct_log) { cs_write_log(buf, do_flush); } else { write_to_log(buf, log, do_flush); } NULLFREE(log->txt); NULLFREE(log); } if(!log_list_queued) // The list is empty, sleep until new data comes in and we are woken up sleepms_on_cond(&log_thread_sleep_cond_mutex, &log_thread_sleep_cond, 60 * 1000); } while(log_running); ll_destroy(log_list); log_list = NULL; }
static void write_to_log_int(char *txt, int8_t header_len) { #if !defined(WEBIF) && !defined(MODULE_MONITOR) if(cfg.disablelog) { return; } #endif char *newtxt = cs_strdup(txt); if(!newtxt) { return; } struct s_log *log; if(!cs_malloc(&log, sizeof(struct s_log))) { NULLFREE(newtxt); return; } log->txt = newtxt; log->header_len = header_len; log->direct_log = 0; struct s_client *cl = cur_client(); log->cl_usr = ""; if(!cl) { log->cl_text = "undef"; log->cl_typ = ' '; } else { switch(cl->typ) { case 'c': case 'm': if(cl->account) { log->cl_text = cl->account->usr; log->cl_usr = cl->account->usr; } else { log->cl_text = ""; } break; case 'p': case 'r': log->cl_text = cl->reader ? cl->reader->label : ""; break; default: log->cl_text = "server"; break; } log->cl_typ = cl->typ; } if(exit_oscam == 1 || cfg.disablelog) //Exit or log disabled. if disabled, just display on webif/monitor { char buf[LOG_BUF_SIZE]; cs_strncpy(buf, log->txt, LOG_BUF_SIZE); write_to_log(buf, log, 1); NULLFREE(log->txt); NULLFREE(log); } else { log_list_add(log); } }
/* ** TODO: gnuart.h */ int write_uart_fd(unsigned char * tx_buffer, size_t size_tx_buffer) { // Check if file descriptor is available if (uart_fd > -1) { // Write on file descriptor int retcount = write(uart_fd, tx_buffer, size_tx_buffer); write_to_log("write OK"); return retcount; } else { // Means that non writable file descriptor write_to_log("write NOK"); return -1; } }
char * get_cfg(char *section, char *key) { char *value; char *query = malloc(strlen(section) + strlen(key) + strlen(":") + 1); if (!snprintf(query, (strlen(section) + strlen(key) + strlen(":") + 1), "%s:%s", section, key)) { write_to_log(WARNING, "%s - %d - %s - %s:%s", __LINE__, __func__, "Unable to set config query for", section, key); goto err; } if ((value = iniparser_getstring(ini, query, NULL)) == NULL) { write_to_log(WARNING, "%s - %d - %s - %s:%s", __LINE__, __func__, "Unable to get config value for", section, key); } free(query); return value; err: free(query); return NULL; }
static void prompt_onConnectionChange(ToxWindow *self, Tox *m, int friendnum , uint8_t status) { if (friendnum < 0) return; PromptBuf *prt = self->promptbuf; prep_prompt_win(); uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'}; if (tox_get_name(m, friendnum, nick) == -1) return; if (!nick[0]) snprintf(nick, sizeof(nick), "%s", UNKNOWN_NAME); wprintw(self->window, "\n"); print_time(self->window); uint8_t *msg; if (status == 1) { msg = "has come online"; wattron(self->window, COLOR_PAIR(GREEN)); wattron(self->window, A_BOLD); wprintw(self->window, "* %s ", nick); wattroff(self->window, A_BOLD); wprintw(self->window, "%s\n", msg); wattroff(self->window, COLOR_PAIR(GREEN)); write_to_log(msg, nick, prt->log, true); alert_window(self, WINDOW_ALERT_2, false); } else { msg = "has gone offline"; wattron(self->window, COLOR_PAIR(RED)); wattron(self->window, A_BOLD); wprintw(self->window, "* %s ", nick); wattroff(self->window, A_BOLD); wprintw(self->window, "%s\n", msg); wattroff(self->window, COLOR_PAIR(RED)); write_to_log(msg, nick, prt->log, true); } }