void * noit_livestream_thread_main(void *e_vptr) { int mask; eventer_t e = e_vptr; acceptor_closure_t *ac = e->closure; noit_livestream_closure_t *jcl = ac->service_ctx; /* Go into blocking mode */ if(eventer_set_fd_blocking(e->fd) == -1) { noitL(noit_error, "failed setting livestream to blocking: [%d] [%s]\n", errno, strerror(errno)); goto alldone; } while(1) { u_int32_t netlen; struct log_entry *le = NULL; int rv; sem_wait(&jcl->lqueue_sem); pthread_mutex_lock(&jcl->lqueue_lock); if(jcl->lqueue) { /* If there are items, pop and advance the header pointer */ le = jcl->lqueue; jcl->lqueue = jcl->lqueue->next; if(!jcl->lqueue) jcl->lqueue_end = NULL; } pthread_mutex_unlock(&jcl->lqueue_lock); if(!le) continue; /* Here we actually push the message */ netlen = htonl(le->len); if((rv = Ewrite(&netlen, sizeof(netlen))) != sizeof(netlen)) { noitL(noit_error, "Error writing le header over SSL %d != %d\n", rv, (int)sizeof(netlen)); goto alldone; } if((rv = Ewrite(le->buff, le->len)) != le->len) { noitL(noit_error, "Error writing livestream message over SSL %d != %d\n", rv, le->len); goto alldone; } } alldone: e->opset->close(e->fd, &mask, e); jcl->wants_shutdown = 1; if(ac) acceptor_closure_free(ac); return NULL; }
/// \returns true iff we are in ctx after leaving this function static bool setupContext(xid_t xid, char const **xid_str) { bool res = false; if (vc_isSupported(vcFEATURE_MIGRATE)) { xid_t rc=VC_NOCTX; if ((xid==VC_DYNAMIC_XID || !vc_is_dynamic_xid(xid)) && (rc=vc_ctx_create(xid, NULL))==VC_NOCTX && errno!=EEXIST) { perror(ENSC_WRAPPERS_PREFIX "vc_ctx_create()"); exit(255); } if (rc!=VC_NOCTX) { char buf[sizeof(xid_t)*3 + 128]; size_t l; struct vc_ctx_caps caps; struct vc_ctx_flags flags; strcpy(buf, "rpm-fake.so #"); l = utilvserver_fmt_uint(buf+sizeof("rpm-fake.so #")-1, getppid()); Evc_set_vhi_name(rc, vcVHI_CONTEXT, buf, sizeof("rpm-fake.so #")+l-1); caps.ccaps = 0ull; caps.cmask = ~0ull; caps.bcaps = ~vc_get_insecurebcaps(); caps.bmask = ~0ull; Evc_set_ccaps(rc, &caps); flags.flagword = 0; flags.mask = VC_VXF_SC_HELPER; Evc_set_cflags(rc, &flags); // context will be activated later... xid = rc; res = true; ctx_created = true; } } if (xid==VC_DYNAMIC_XID) *xid_str = 0; else { char buf[sizeof(xid_t)*3 + 2]; size_t l; l = utilvserver_fmt_uint(buf, xid); buf[l] = '\0'; *xid_str = strdup(buf); } Ewrite(3, &xid, sizeof xid); return res; }
static int noit_jlog_push(eventer_t e, noit_jlog_closure_t *jcl) { jlog_message msg; int mask; u_int32_t n_count; n_count = htonl(jcl->count); if(Ewrite(&n_count, sizeof(n_count)) != sizeof(n_count)) return -1; while(jcl->count > 0) { int rv; struct { jlog_id chkpt; u_int32_t n_sec, n_usec, n_len; } payload; if(jlog_ctx_read_message(jcl->jlog, &jcl->start, &msg) == -1) return -1; /* Here we actually push the message */ payload.chkpt.log = htonl(jcl->start.log); payload.chkpt.marker = htonl(jcl->start.marker); payload.n_sec = htonl(msg.header->tv_sec); payload.n_usec = htonl(msg.header->tv_usec); payload.n_len = htonl(msg.mess_len); if((rv = Ewrite(&payload, sizeof(payload))) != sizeof(payload)) { noitL(noit_error, "Error writing jlog header over SSL %d != %d\n", rv, (int)sizeof(payload)); return -1; } if((rv = Ewrite(msg.mess, msg.mess_len)) != msg.mess_len) { noitL(noit_error, "Error writing jlog message over SSL %d != %d\n", rv, msg.mess_len); return -1; } /* Note what the client must checkpoint */ jcl->chkpt = jcl->start; JLOG_ID_ADVANCE(&jcl->start); jcl->count--; } return 0; }
static void initMtab(struct Configuration const *cfg) { ENSC_PI_DECLARE(mtab_subpath, "apps/init/mtab"); PathInfo mtab_path = cfg->cfgdir; char mtab_buf[ENSC_PI_APPSZ(mtab_path, mtab_subpath)]; PathInfo_append(&mtab_path, &mtab_subpath, mtab_buf); char const * mtab = findMtab(mtab_path.d); pid_t pid; int p[2]; Epipe(p); pid = Efork(); if (pid==0) { Undo_detach(); Eclose(p[1]); Echdir(cfg->vdir); Echroot("."); int fd = Eopen("/etc/mtab", O_WRONLY|O_CREAT, 0644); for (;;) { char buf[4096]; ssize_t len = TEMP_FAILURE_RETRY(read(p[0], buf, sizeof buf)); if (len==0) break; if (len==-1) { perror("vserver-start: initMtab/read():"); _exit(1); } Ewrite(fd, buf, len); } Eclose(fd); Eclose(p[0]); _exit(0); } else { Eclose(p[0]); if (mtab!=0) { int fd = Eopen(mtab, O_RDONLY, 0644); for (;;) { char buf[4096]; ssize_t len = TEMP_FAILURE_RETRY(read(fd, buf, sizeof buf)); if (len==0) break; if (len==-1) { perror("vserver-start: initMtab/read():"); _exit(1); } Ewrite(p[1], buf, len); } Eclose(fd); } Eclose(p[1]); int status; TEMP_FAILURE_RETRY(wait4(pid, &status, 0,0)); if (!WIFEXITED(status) || WEXITSTATUS(status)!=0) { exit(1); } } }