int ssl_readable(struct worker_t *self, struct client_t *c) { int r; int sslerr, err; //hlog(LOG_DEBUG, "ssl_readable fd %d", c->fd); ssl_clear_error(); r = SSL_read(c->ssl_con->connection, c->ibuf + c->ibuf_end, c->ibuf_size - c->ibuf_end - 1); if (r > 0) { /* we got some data... process */ //hlog(LOG_DEBUG, "SSL_read fd %d returned %d bytes of data", c->fd, r); /* TODO: whatever the client_readable does */ return client_postread(self, c, r); } sslerr = SSL_get_error(c->ssl_con->connection, r); err = (sslerr == SSL_ERROR_SYSCALL) ? errno : 0; if (sslerr == SSL_ERROR_WANT_READ) { hlog(LOG_DEBUG, "ssl_readable fd %d: SSL_read wants to read again, doing it later", c->fd); if (c->obuf_end - c->obuf_start > 0) { /* tell the poller that we have outgoing data */ xpoll_outgoing(&self->xp, c->xfd, 1); } return 0; } if (sslerr == SSL_ERROR_WANT_WRITE) { hlog(LOG_INFO, "ssl_readable fd %d: SSL_read wants to write (peer starts SSL renegotiation?), calling ssl_write", c->fd); return ssl_write(self, c); } c->ssl_con->no_wait_shutdown = 1; c->ssl_con->no_send_shutdown = 1; if (sslerr == SSL_ERROR_ZERO_RETURN || ERR_peek_error() == 0) { hlog(LOG_DEBUG, "ssl_readable fd %d: peer shutdown SSL cleanly", c->fd); client_close(self, c, CLIERR_EOF); return -1; } if (err) { hlog(LOG_DEBUG, "ssl_readable fd %d: I/O syscall error: %s", c->fd, strerror(err)); } else { char ebuf[255]; ERR_error_string_n(sslerr, ebuf, sizeof(ebuf)); hlog(LOG_INFO, "ssl_readable fd %d failed with ret %d sslerr %d errno %d: %s (%s)", c->fd, r, sslerr, err, ebuf, ERR_reason_error_string(sslerr)); } client_close(self, c, err); return -1; }
void status_atend(void) { struct cdata_list_t *cl, *cl_next; int pe; for (cl = cdata_list; (cl); cl = cl_next) { cl_next = cl->next; cdata_free(cl->cd); hfree(cl); } if ((pe = pthread_mutex_lock(&status_json_mt))) { hlog(LOG_ERR, "status_atend(): could not lock status_json_mt: %s", strerror(pe)); return; } if (status_json_cached) { hfree(status_json_cached); status_json_cached = NULL; } if ((pe = pthread_mutex_unlock(&status_json_mt))) { hlog(LOG_ERR, "status_atend(): could not unlock status_json_mt: %s", strerror(pe)); return; } }
static void ssl_info_callback(SSL *ssl, int where, int ret) { struct client_t *c = SSL_get_ex_data(ssl, ssl_connection_index); if (!c) { hlog(LOG_ERR, "ssl_info_callback: no application data for connection"); return; } struct ssl_connection_t *ssl_conn = c->ssl_con; if (!ssl_conn) { hlog(LOG_ERR, "ssl_info_callback: no ssl_conn for connection"); return; } if (where & SSL_CB_HANDSHAKE_START) { hlog(LOG_INFO, "%s/%d: SSL handshake start", c->addr_rem, c->fd); if (ssl_conn->handshaked) { ssl_conn->renegotiation = 1; } } if (where & SSL_CB_HANDSHAKE_DONE) { hlog(LOG_INFO, "%s/%d: SSL handshake done", c->addr_rem, c->fd); } }
void uplink_stop(void) { int i, e; if (!uplink_running) return; hlog(LOG_INFO, "Signalling uplink_thread to shut down..."); uplink_shutting_down = 1; if ((e = pthread_join(uplink_th, NULL))) { hlog(LOG_ERR, "Could not pthread_join uplink_th: %s", strerror(e)); } else { hlog(LOG_INFO, "Uplink thread has terminated."); uplink_running = 0; } /* free uplink config - and clean up the uplink_client indexed pointers * which refer to the configs */ if ((e = pthread_mutex_lock(&uplink_client_mutex))) { hlog( LOG_ERR, "uplink_stop(): could not lock uplink_client_mutex: %s", strerror(e) ); return; } for (i = 0; i < MAX_UPLINKS; i++) uplink_client[i] = NULL; free_uplink_config(&uplink_config); if ((e = pthread_mutex_unlock(&uplink_client_mutex))) { hlog( LOG_ERR, "uplink_stop(): could not unlock uplink_client_mutex: %s", strerror(e) ); return; } }
// p�la engine'u int HEngineCore::Run() { guard ( HEngineCore::Run() ); /* TODO (#1#): Implement HEngineCore::Run() */ hlog ( "-HEngineCore::Run()...\n" ); m_bLoop=true; //int wait=0; hlog ( "-HEngineCore::Run() entering engine loop...\n" ); while ( m_bLoop ) { m_pTimer->Update(); m_pRenderWindow->Update(); m_pInputSystem->Update(); m_pGUI->Update(); m_pConsole->Update(); m_pGameFPP->Update(); //glClear ( GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT );//GL_COLOR_BUFFER_BIT| m_pGameFPP->Render(); m_pFont->DrawText ( 1,1,10,HINFO ); m_pFont->DrawText ( 5,HRendererWindow::GetSingleton().GetHeight()-25,26,"^\4FPS: %0.2f",m_pTimer->m_fFPS ); m_pGUI->Render(); m_pConsole->Draw(); SDL_GL_SwapBuffers(); } m_pRenderWindow->Close(); m_bLoop=false; hlog ( "-HEngineCore::Run() done...\n" ); return 0; unguard; }
void close_uplinkers(void) { int rc; hlog(LOG_DEBUG, "Closing all uplinks"); if ((rc = pthread_mutex_lock(&uplink_client_mutex))) { hlog( LOG_ERR, "close_uplinkers(): could not lock uplink_client_mutex: %s", strerror(rc) ); return; } int i; for (i = 0; i < MAX_UPLINKS; i++) { if ((uplink_client[i]) && uplink_client[i]->fd >= 0) { hlog( LOG_DEBUG, "Closing uplinking socket %d (fd %d) %s ...", i, uplink_client[i]->fd, uplink_client[i]->addr_rem ); shutdown(uplink_client[i]->fd, SHUT_RDWR); } } if ((rc = pthread_mutex_unlock(&uplink_client_mutex))) { hlog( LOG_ERR, "close_uplinkers(): could not unlock uplink_client_mutex: %s", strerror(rc) ); return; } return; }
static struct cdata_t *cdata_find_and_lock(const char *name) { struct cdata_t *cd = NULL; int e; if ((e = pthread_mutex_lock(&counterdata_mt))) { hlog(LOG_CRIT, "cdata_find_and_lock: failed to lock counterdata_mt: %s", strerror(e)); exit(1); } for (cd = counterdata; (cd); cd = cd->next) if (strcmp(name, cd->name) == 0) { if ((e = pthread_mutex_lock(&cd->mt))) { hlog(LOG_CRIT, "cdata_find_and_lock: could not lock cd: %s", strerror(e)); exit(1); } break; } if ((e = pthread_mutex_unlock(&counterdata_mt))) { hlog(LOG_CRIT, "cdata_find_and_lock: could not unlock counterdata_mt: %s", strerror(e)); exit(1); } return cd; }
int ssl_ca_certificate(struct ssl_t *ssl, const char *cafile, int depth) { STACK_OF(X509_NAME) *list; SSL_CTX_set_verify(ssl->ctx, SSL_VERIFY_PEER, ssl_verify_callback); SSL_CTX_set_verify_depth(ssl->ctx, depth); if (SSL_CTX_load_verify_locations(ssl->ctx, cafile, NULL) == 0) { hlog(LOG_ERR, "Failed to load trusted CA list from \"%s\"", cafile); ssl_error(LOG_ERR, "SSL_CTX_load_verify_locations"); return -1; } list = SSL_load_client_CA_file(cafile); if (list == NULL) { hlog(LOG_ERR, "Failed to load client CA file from \"%s\"", cafile); ssl_error(LOG_ERR, "SSL_load_client_CA_file"); return -1; } /* * before 0.9.7h and 0.9.8 SSL_load_client_CA_file() * always leaved an error in the error queue */ ERR_clear_error(); SSL_CTX_set_client_CA_list(ssl->ctx, list); ssl->validate = 1; return 0; }
void cdata_counter_sample(struct cdata_t *cd, long long value) { int e; long long l; if ((e = pthread_mutex_lock(&cd->mt))) { hlog(LOG_CRIT, "cdata_counter_sample %s: failed to lock mt: %s", cd->name, strerror(e)); exit(1); } cd->last_index++; if (cd->last_index >= CDATA_SAMPLES) cd->last_index = 0; /* calculate counter's increment and insert */ if (value == -1) { /* no data for sample */ l = -1; } else { /* check for wrap-around */ if (value < cd->last_raw_value) l = -1; else l = value - cd->last_raw_value; } cd->last_raw_value = value; cd->values[cd->last_index] = l; cd->times[cd->last_index] = tick; if ((e = pthread_mutex_unlock(&cd->mt))) { hlog(LOG_CRIT, "cdata_counter_sample %s: could not unlock counterdata_mt: %s", cd->name, strerror(e)); exit(1); } }
struct cdata_t *cdata_alloc(const char *name) { int e; struct cdata_t *cd; cd = hmalloc(sizeof(*cd)); memset(cd, 0, sizeof(*cd)); pthread_mutex_init(&cd->mt, NULL); cd->name = hstrdup(name); cd->last_index = -1; // no data inserted yet cd->is_gauge = 0; if ((e = pthread_mutex_lock(&counterdata_mt))) { hlog(LOG_CRIT, "cdata_allocate: failed to lock counterdata_mt: %s", strerror(e)); exit(1); } cd->next = counterdata; if (counterdata) counterdata->prevp = &cd->next; counterdata = cd; cd->prevp = &counterdata; if ((e = pthread_mutex_unlock(&counterdata_mt))) { hlog(LOG_CRIT, "cdata_allocate: could not unlock counterdata_mt: %s", strerror(e)); exit(1); } //hlog(LOG_DEBUG, "cdata: allocated: %s", cd->name); return cd; }
bool capture_init_shtex(struct shtex_data **data, HWND window, uint32_t base_cx, uint32_t base_cy, uint32_t cx, uint32_t cy, uint32_t format, bool flip, uint32_t handle) { if (!init_shared_info(sizeof(struct shtex_data))) { hlog("capture_init_shtex: Failed to initialize memory"); return false; } *data = shmem_info; (*data)->tex_handle = handle; global_hook_info->window = (uint32_t)window; global_hook_info->type = CAPTURE_TYPE_TEXTURE; global_hook_info->format = format; global_hook_info->flip = flip; global_hook_info->map_id = shmem_id_counter; global_hook_info->map_size = sizeof(struct shtex_data); global_hook_info->cx = cx; global_hook_info->cy = cy; global_hook_info->base_cx = base_cx; global_hook_info->base_cy = base_cy; if (!SetEvent(signal_ready)) { hlog("capture_init_shtex: Failed to signal ready: %d", GetLastError()); return false; } active = true; return true; }
static int http_compress_gzip(char *in, int ilen, char *out, int ospace) { z_stream ctx; ctx.zalloc = Z_NULL; ctx.zfree = Z_NULL; ctx.opaque = Z_NULL; /* magic 15 bits + 16 enables gzip header generation */ if (deflateInit2(&ctx, 7, Z_DEFLATED, (15+16), MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY) != Z_OK) { hlog(LOG_ERR, "http_compress_gzip: deflateInit2 failed"); return -1; } ctx.next_in = (unsigned char *)in; ctx.avail_in = ilen; ctx.next_out = (unsigned char *)out; ctx.avail_out = ospace; int ret = deflate(&ctx, Z_FINISH); if (ret != Z_STREAM_END) { hlog(LOG_ERR, "http_compress_gzip: deflate returned %d instead of Z_STREAM_END", ret); (void)deflateEnd(&ctx); return -1; } int olen = ospace - ctx.avail_out; hlog(LOG_DEBUG, "http_compress_gzip: compressed %d bytes to %d bytes: %.1f %%", ilen, olen, (float)olen / (float)ilen * 100.0); (void)deflateEnd(&ctx); return olen; }
int time_jsonais(time_t *t, char *buf, int buflen) { int i; struct tm dt; /* check that the buffer is large enough - we use * 14 bytes plus the NULL */ if (buflen < 15) { hlog(LOG_ERR, "time_jsonais: not enough space to produce JSON AIS timestamp"); return -1; } /* thread-safe UTC */ if (gmtime_r(t, &dt) == NULL) { hlog(LOG_ERR, "time_jsonais: gmtime_r failed"); return -1; } i = snprintf(buf, buflen, "%04d%02d%02d%02d%02d%02d", dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec); //hlog(LOG_DEBUG, "time_jsonais: %d => %s", *t, buf); return i; }
cJSON *status_error_json(void) { struct status_error_t *e; int pe; struct cJSON *ea; if ((pe = pthread_mutex_lock(&status_errs_mt))) { hlog(LOG_ERR, "status_error_json(): could not lock status_errs_mt: %s", strerror(pe)); return NULL; } ea = cJSON_CreateArray(); for (e = status_errs; (e); e = e->next) { if (e->ends < now) // don't display expired alarms continue; cJSON *ej = cJSON_CreateObject(); cJSON_AddStringToObject(ej, "err", e->err); cJSON_AddNumberToObject(ej, "set", e->set); cJSON_AddNumberToObject(ej, "start", e->started); cJSON_AddNumberToObject(ej, "end", e->ends); cJSON_AddItemToArray(ea, ej); } if ((pe = pthread_mutex_unlock(&status_errs_mt))) { hlog(LOG_ERR, "status_error_json(): could not unlock status_errs_mt: %s", strerror(pe)); } return ea; }
int accesslog(const char *fmt, ...) { va_list args; char s[LOG_LEN], wb[LOG_LEN]; time_t t; struct tm lt; int len; ssize_t w; va_start(args, fmt); vsnprintf(s, LOG_LEN, fmt, args); va_end(args); s[LOG_LEN-1] = 0; time(&t); gmtime_r(&t, <); len = snprintf(wb, LOG_LEN, "[%4.4d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d] %s\n", lt.tm_year + 1900, lt.tm_mon + 1, lt.tm_mday, lt.tm_hour, lt.tm_min, lt.tm_sec, s); wb[LOG_LEN-1] = 0; rwl_rdlock(&accesslog_lock); if (accesslog_file >= 0) { if ((w = write(accesslog_file, wb, len)) != len) hlog(LOG_CRIT, "Could not write to %s (fd %d): %s", accesslog_fname, accesslog_file, strerror(errno)); } else { if (accesslog_file != -666) { hlog(LOG_ERR, "Access log not open, log lines are lost!"); accesslog_file = -666; } } rwl_rdunlock(&accesslog_lock); return 1; }
/*************************************************************************** *显示接收消息内存 ***************************************************************************/ void client_recvice_message(char *pbuf,int data_len) { hlog("from user %s\n",pbuf); pbuf+=CLIENT_NAME_LEN; hlog("to user %s\n",pbuf); pbuf+=CLIENT_NAME_LEN; hlog("receive msg %s\n",pbuf); }
hprocess_t process_alloc(hcchar * command){ pid_t pid; int pipe_in[2],pipe_out[2]; pipe(pipe_in); pipe(pipe_out); pid = fork(); if(pid < 0){ hlog("fork error"); close(pipe_in[0]); close(pipe_in[1]); close(pipe_out[0]); close(pipe_out[1]); } else if(pid ==0 ){ close(pipe_out[1]); dup2(pipe_out[0],STDIN_FILENO); close(pipe_in[0]); dup2(pipe_in[1],STDOUT_FILENO); execl(command,NULL); exit(EXIT_SUCCESS); } else{ { process_t * process = (process_t *)mem_malloc(sizeof(process_t)); #ifdef O_NONBLOCK hint32 fl; #endif mem_memset(process, 0, sizeof(process_t)); close(pipe_in[1]); close(pipe_out[0]); #ifdef O_NONBLOCK fl = fcntl(pipe_in[0], F_GETFL) ; fcntl(pipe_in[0], F_SETFL, fl | O_NONBLOCK); fl = fcntl(pipe_out[1], F_GETFL) ; fcntl(pipe_out[1], F_SETFL, fl | O_NONBLOCK); #endif process->pipe_in = pipe_in[0]; process->pipe_out = pipe_out[1]; process->pid = pid; hlog("%s\n",command); return (hprocess_t)process; } } return NULL; }
int status_read_liveupgrade(void) { char path[PATHLEN+1]; char path_renamed[PATHLEN+1]; FILE *fp; char *s = NULL; int sl = 0; char buf[32768]; int i; snprintf(path, PATHLEN, "%s/liveupgrade.json", rundir); snprintf(path_renamed, PATHLEN, "%s/liveupgrade.json.old", rundir); fp = fopen(path, "r"); if (!fp) { hlog(LOG_ERR, "liveupgrade dump file read failed: Could not open %s for reading: %s", path, strerror(errno)); return -1; } hlog(LOG_INFO, "Live upgrade: Loading client status from %s ...", path); if (rename(path, path_renamed) < 0) { hlog(LOG_ERR, "Failed to rename liveupgrade dump file %s to %s: %s", path, path_renamed, strerror(errno)); unlink(path); } while ((i = fread(buf, 1, sizeof(buf), fp)) > 0) { //hlog(LOG_DEBUG, "read %d bytes", i); s = hrealloc(s, sl + i+1); memcpy(s + sl, buf, i); sl += i; s[sl] = 0; // keep null-terminated //hlog(LOG_DEBUG, "now: %s", s); } if (fclose(fp)) { hlog(LOG_ERR, "liveupgrade dump file read failed: close(%s): %s", path, strerror(errno)); hfree(s); return -1; } /* decode JSON */ cJSON *dec = cJSON_Parse(s); if (!dec) { hlog(LOG_ERR, "liveupgrade dump parsing failed"); hfree(s); return -1; } liveupgrade_status = dec; hfree(s); return 0; }
static inline void log_current_process(void) { DWORD len = GetModuleBaseNameA(GetCurrentProcess(), NULL, process_name, MAX_PATH); if (len > 0) { process_name[len] = 0; hlog("Hooked to process: %s", process_name); } hlog("(half life scientist) everything.. seems to be in order"); }
int uplink_login_handler(struct worker_t *self, struct client_t *c, int l4proto, char *s, int len) { char buf[1000]; int rc; int argc; char *argv[256]; hlog_packet(LOG_INFO, s, len, "%s: Uplink server software: ", c->addr_rem); #ifdef USE_SSL if (c->ssl_con && c->ssl_con->validate) { hlog(LOG_DEBUG, "%s/%s: Uplink: Validating SSL server cert against CA", c->addr_rem, c->username); int ssl_res = ssl_validate_peer_cert_phase1(c); if (ssl_res != 0) { hlog(LOG_WARNING, "%s/%s: SSL server cert validation failed: %s", c->addr_rem, c->username, ssl_strerror(ssl_res)); client_close(self, c, CLIERR_UPLINK_PEER_CERT_FAIL); return 0; } } #endif /* parse to arguments */ /* make it null-terminated for our string processing */ char *e = s + len; *e = 0; if ((argc = parse_args_noshell(argv, s)) == 0 || *argv[0] != '#') { hlog(LOG_ERR, "%s: Uplink's welcome message is not recognized: no # in beginning", c->addr_rem); client_close(self, c, CLIERR_UPLINK_LOGIN_PROTO_ERR); return 0; } if (argc >= 3) { strncpy(c->app_name, argv[1], sizeof(c->app_name)); c->app_name[sizeof(c->app_name)-1] = 0; strncpy(c->app_version, argv[2], sizeof(c->app_version)); c->app_version[sizeof(c->app_version)-1] = 0; } // TODO: The uplink login command here could maybe be improved to send a filter command. len = sprintf(buf, "user %s pass %s vers %s\r\n", serverid, passcode, verstr_aprsis); hlog(LOG_DEBUG, "%s: my login string: \"%.*s\"", c->addr_rem, len-2, buf, len); rc = c->write(self, c, buf, len); if (rc < -2) return rc; // the client was destroyed by client_write, don't touch it c->handler_line_in = uplink_logresp_handler; c->state = CSTATE_LOGRESP; hlog(LOG_INFO, "%s: Connected to server, logging in", c->addr_rem); return 0; }
// zwalnia wszystko int HEngineCore::DeInit() { /* TODO (#1#): Implement HEngineCore::DeInit() */ // m_pGame->DeInit(); hlog ( "-HEngineCore::DeInit()...\n" ); // SetLoadingScreenTitle("DeInitializing Engine"); // LoadingScreenUpdate(0); m_pConsole->DeInit(); // LoadingScreenUpdate(0.5f); m_pGameFPP->DeInit(); m_pRenderWindow->Close(); hlog ( "-HEngineCore::DeInit() done...\n" ); }
static int rescan_client_acls(void) { struct worker_t *w = worker_threads; struct client_t *c; struct listen_t *l; int pe; hlog(LOG_DEBUG, "Scanning old clients against new ACLs and listeners"); while (w) { if ((pe = pthread_mutex_lock(&w->clients_mutex))) { hlog(LOG_ERR, "rescan_client_acls(worker %d): could not lock clients_mutex: %s", w->id, strerror(pe)); return -1; } for (c = w->clients; (c); c = c->next) { /* do not disconnect uplinks at this point */ if (!(c->flags & CLFLAGS_INPORT)) continue; l = find_listener_hash_id(c->listener_id); if (!l) { /* listener is not there any more */ hlog(LOG_INFO, "%s - Closing client on fd %d from %s (listener has been removed)", c->addr_loc, c->fd, c->addr_rem); shutdown(c->fd, SHUT_RDWR); continue; } /* is there an acl? */ if (!l->acl) continue; /* there is, check */ if (!acl_check(l->acl, (struct sockaddr *)&c->addr, sizeof(c->addr))) { hlog(LOG_INFO, "%s - Denying client on fd %d from %s (new ACL)", c->addr_loc, c->fd, c->addr_rem); shutdown(c->fd, SHUT_RDWR); continue; } } if ((pe = pthread_mutex_unlock(&w->clients_mutex))) { hlog(LOG_ERR, "rescan_client_acls(worker %d): could not unlock clients_mutex: %s", w->id, strerror(pe)); /* we'd going to deadlock here... */ exit(1); } w = w->next; } return 0; }
struct serial_state_t *serial_init() { struct serial_state_t *state = NULL; state = (struct serial_state_t *) hmalloc(sizeof(*state)); //Returns the file descriptor on success or -1 on error. /* File descriptor for the port */ state->fd = open(serial_port, O_RDWR | O_NOCTTY | O_NDELAY); if (state->fd == -1) { // Could not open the port. hlog(LOG_CRIT, "Could not open serial port %s: %s", serial_port, strerror(errno)); return NULL; } hlog(LOG_INFO, "Opened serial port %s for NMEA output", serial_port); /* set file status flags to 0 - why? */ fcntl(state->fd, F_SETFL, 0); struct termios options; /* get the current options */ if (tcgetattr(state->fd, &options)) hlog(LOG_ERR, "Could not read serial port parameters on port %s: %s", serial_port, strerror(errno)); //set speed 4800 cfsetispeed(&options, B4800); cfsetospeed(&options, B4800); /* set raw input, 1 second timeout */ options.c_cflag |= (CLOCAL | CREAD); options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); options.c_oflag &= ~OPOST; options.c_cc[VMIN] = 0; options.c_cc[VTIME] = 10; //No parity 8N1 options.c_cflag &= ~PARENB; options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSIZE; options.c_cflag |= CS8; /* set the options */ if (tcsetattr(state->fd, TCSANOW, &options)) hlog(LOG_ERR, "Could not configure serial port parameters on port %s: %s", serial_port, strerror(errno)); return state; }
bool capture_init_shmem(struct shmem_data **data, HWND window, uint32_t base_cx, uint32_t base_cy, uint32_t cx, uint32_t cy, uint32_t pitch, uint32_t format, bool flip) { uint32_t tex_size = cy * pitch; uint32_t aligned_header = ALIGN(sizeof(struct shmem_data), 32); uint32_t aligned_tex = ALIGN(tex_size, 32); uint32_t total_size = aligned_header + aligned_tex * 2; uintptr_t align_pos; if (!init_shared_info(total_size)) { hlog("capture_init_shmem: Failed to initialize memory"); return false; } *data = shmem_info; /* to ensure fast copy rate, align texture data to 256bit addresses */ align_pos = (uintptr_t)shmem_info; align_pos += aligned_header; align_pos &= ~(32 - 1); align_pos -= (uintptr_t)shmem_info; (*data)->last_tex = -1; (*data)->tex1_offset = (uint32_t)align_pos; (*data)->tex2_offset = (*data)->tex1_offset + aligned_tex; global_hook_info->window = (uint32_t)window; global_hook_info->type = CAPTURE_TYPE_MEMORY; global_hook_info->format = format; global_hook_info->flip = flip; global_hook_info->map_id = shmem_id_counter; global_hook_info->map_size = total_size; global_hook_info->pitch = pitch; global_hook_info->cx = cx; global_hook_info->cy = cy; global_hook_info->base_cx = base_cx; global_hook_info->base_cy = base_cy; if (!init_shmem_thread(pitch, cy)) { return false; } if (!SetEvent(signal_ready)) { hlog("capture_init_shmem: Failed to signal ready: %d", GetLastError()); return false; } active = true; return true; }
int serial_write(struct serial_state_t *state, char *s, int len) { int n = write(state->fd, s, len); if (n < 0) hlog(LOG_ERR, "Could not write to serial port %s: %s", serial_port, strerror(errno)); #ifdef DEBUG_SERIAL else hlog(LOG_DEBUG, "Wrote %d bytes to serial port", n); #endif return n; }
int ipc_write(struct ipc_state_t *ipc, char *buffer, int buflength){ hlog(LOG_DEBUG,"IPC buffer: %s\n",buffer); int nbytes=0; int i; pthread_mutex_lock(&ipc_mut); for(i=0;i<(ipc->numclientsockets);i++) { nbytes = write(ipc->clientsocket[i], buffer, buflength); if(nbytes == 0){ hlog(LOG_INFO,"One gnuaisgui client is disconnected\n"); } } pthread_mutex_unlock(&ipc_mut); return 0; }
void process_outgoing(struct worker_t *self) { struct pbuf_t *pb; int e; if ((e = rwl_rdlock(&pbuf_global_rwlock))) { hlog(LOG_CRIT, "worker: Failed to rdlock pbuf_global_rwlock!"); exit(1); } while ((pb = *self->pbuf_global_prevp)) { //__sync_synchronize(); /* Some safety checks against bugs and overload conditions */ if (pb->is_free) { hlog(LOG_ERR, "worker %d: process_outgoing got pbuf %d marked free, age %d (now %d t %d)\n%.*s", self->id, pb->seqnum, tick - pb->t, tick, pb->t, pb->packet_len-2, pb->data); abort(); /* this would be pretty bad, so we crash immediately */ } else if (pb->t > tick + 2) { /* 2-second offset is normal in case of one thread updating tick earlier than another * and a little thread scheduling luck */ hlog(LOG_ERR, "worker %d: process_outgoing got packet %d from future with t %d > tick %d!\n%.*s", self->id, pb->seqnum, pb->t, tick, pb->packet_len-2, pb->data); status_error(86400, "packet_drop_future"); } else if (tick - pb->t > 5) { /* this is a bit too old, are we stuck? */ hlog(LOG_ERR, "worker %d: process_outgoing got packet %d aged %d sec (now %d t %d)\n%.*s", self->id, pb->seqnum, tick - pb->t, tick, pb->t, pb->packet_len-2, pb->data); status_error(86400, "packet_drop_hang"); } else { process_outgoing_single(self, pb); } self->last_pbuf_seqnum = pb->seqnum; self->pbuf_global_prevp = &pb->next; } while ((pb = *self->pbuf_global_dupe_prevp)) { if (pb->is_free) { hlog(LOG_ERR, "worker %d: process_outgoing got dupe %d marked free, age %d (now %d t %d)\n%.*s", self->id, pb->seqnum, tick - pb->t, tick, pb->t, pb->packet_len-2, pb->data); abort(); } else if (pb->t > tick + 2) { hlog(LOG_ERR, "worker: process_outgoing got dupe from future %d with t %d > tick %d!\n%.*s", pb->seqnum, pb->t, tick, pb->packet_len-2, pb->data); } else if (tick - pb->t > 5) { hlog(LOG_ERR, "worker: process_outgoing got dupe %d aged %d sec\n%.*s", pb->seqnum, tick - pb->t, pb->packet_len-2, pb->data); } else { process_outgoing_single(self, pb); } self->last_pbuf_dupe_seqnum = pb->seqnum; self->pbuf_global_dupe_prevp = &pb->next; } if ((e = rwl_rdunlock(&pbuf_global_rwlock))) { hlog(LOG_CRIT, "worker: Failed to rdunlock pbuf_global_rwlock!"); exit(1); } }
static void gnuais_ipc_socketlistener(void *asdf){ int connection_fd; struct ipc_state_t *ipc; ipc = (struct ipc_state_t *)asdf; socklen_t address_length; hlog(LOG_INFO,"IPC thread started"); while(((connection_fd = accept(socket_fd, (struct sockaddr *) &address, &address_length)) > - 1) && ipc->numclientsockets < (MAX_CLIENT_SOCKETS - 2)){ pthread_mutex_lock(&ipc_mut); ipc->clientsocket[ipc->numclientsockets] = connection_fd; ipc->numclientsockets++; pthread_mutex_unlock(&ipc_mut); hlog(LOG_INFO,"numclientsockets: %d\n",ipc->numclientsockets); } hlog(LOG_INFO,"Done in IPC thread"); }
static bool gl_shtex_init(HWND window) { if (!gl_shtex_init_window()) { return false; } if (!gl_shtex_init_d3d11()) { return false; } if (!gl_shtex_init_d3d11_tex()) { return false; } if (!gl_shtex_init_gl_tex()) { return false; } if (!gl_init_fbo()) { return false; } if (!capture_init_shtex(&data.shtex_info, window, data.base_cx, data.base_cy, data.cx, data.cy, data.format, true, (uintptr_t)data.handle)) { return false; } hlog("gl shared texture capture successful"); return true; }
static void init_nv_functions(void) { jimglDXSetResourceShareHandleNV = get_proc("wglDXSetResourceShareHandleNV"); jimglDXOpenDeviceNV = get_proc("wglDXOpenDeviceNV"); jimglDXCloseDeviceNV = get_proc("wglDXCloseDeviceNV"); jimglDXRegisterObjectNV = get_proc("wglDXRegisterObjectNV"); jimglDXUnregisterObjectNV = get_proc("wglDXUnregisterObjectNV"); jimglDXObjectAccessNV = get_proc("wglDXObjectAccessNV"); jimglDXLockObjectsNV = get_proc("wglDXLockObjectsNV"); jimglDXUnlockObjectsNV = get_proc("wglDXUnlockObjectsNV"); nv_capture_available = !!jimglDXSetResourceShareHandleNV && !!jimglDXOpenDeviceNV && !!jimglDXCloseDeviceNV && !!jimglDXRegisterObjectNV && !!jimglDXUnregisterObjectNV && !!jimglDXObjectAccessNV && !!jimglDXLockObjectsNV && !!jimglDXUnlockObjectsNV; if (nv_capture_available) hlog("Shared-texture OpenGL capture available"); }