int cli_main(int argc, char* argv[]) { time_t start; time_t next; struct crontab c; str jobstr; msg_debug_init(); timespec_next_init(); memset(&c, 0, sizeof c); jobstr.len = strlen(jobstr.s = argv[0]); jobstr.size = 0; if (!crontab_parse(&c, &jobstr, "nobody") || c.jobs == 0) usage(111, "Invalid crontab line"); if ((start = strtol(argv[1], 0, 10)) <= 0) usage(111, "Invalid timesstamp"); next = timespec_next(&c.jobs->times, start, localtime(&start)); obuf_put5s(&outbuf, "last: ", utoa(start), " ", fmttime(start), "\n"); obuf_put5s(&outbuf, "next: ", utoa(next), " ", fmttime(next), "\n"); obuf_flush(&outbuf); return 0; (void)argc; }
static htsmsg_t * avt_GetPositionInfo(http_connection_t *hc, htsmsg_t *args, const char *myhost, int myport) { htsmsg_t *out = htsmsg_create_map(); char tbuf[16]; hts_mutex_lock(&upnp_lock); char *didl = build_didl(http_get_my_host(hc), http_get_my_port(hc)); htsmsg_add_u32(out, "Track", upnp_current_track); fmttime(tbuf, sizeof(tbuf), upnp_current_track_duration); htsmsg_add_str(out, "TrackDuration", tbuf); htsmsg_add_str(out, "TrackMetaData", didl); free(didl); htsmsg_add_str(out, "TrackURI", upnp_current_url ?: ""); fmttime(tbuf, sizeof(tbuf), upnp_current_track_time); htsmsg_add_str(out, "RelTime", tbuf); htsmsg_add_str(out, "AbsTime", tbuf); //"NOT_IMPLEMENTED"); htsmsg_add_u32(out, "RelCount", 2147483647); htsmsg_add_u32(out, "AbsCount", 2147483647); hts_mutex_unlock(&upnp_lock); return out; }
static void prquota(struct mnttab *mntp, struct dqblk *dqp) { struct timeval tv; char ftimeleft[80], btimeleft[80]; char *cp; time(&(tv.tv_sec)); tv.tv_usec = 0; if (dqp->dqb_bsoftlimit && dqp->dqb_curblocks >= dqp->dqb_bsoftlimit) { if (dqp->dqb_btimelimit == 0) { strcpy(btimeleft, "NOT STARTED"); } else if (dqp->dqb_btimelimit > tv.tv_sec) { fmttime(btimeleft, dqp->dqb_btimelimit - tv.tv_sec); } else { strcpy(btimeleft, "EXPIRED"); } } else { btimeleft[0] = '\0'; } if (dqp->dqb_fsoftlimit && dqp->dqb_curfiles >= dqp->dqb_fsoftlimit) { if (dqp->dqb_ftimelimit == 0) { strcpy(ftimeleft, "NOT STARTED"); } else if (dqp->dqb_ftimelimit > tv.tv_sec) { fmttime(ftimeleft, dqp->dqb_ftimelimit - tv.tv_sec); } else { strcpy(ftimeleft, "EXPIRED"); } } else { ftimeleft[0] = '\0'; } if (strlen(mntp->mnt_mountp) > 12) { printf("%s\n", mntp->mnt_mountp); cp = ""; } else { cp = mntp->mnt_mountp; } printf("%-12.12s %7d %6d %6d %11s %6d %6d %6d %11s\n", cp, kb(dqp->dqb_curblocks), kb(dqp->dqb_bsoftlimit), kb(dqp->dqb_bhardlimit), btimeleft, dqp->dqb_curfiles, dqp->dqb_fsoftlimit, dqp->dqb_fhardlimit, ftimeleft); }
/* * onintr -- * on interrupt, we inform the user how far we've gotten */ static void onintr(int signo) { printf("\ninterrupted %s\n", fmttime(buf[FIRSTVALID].ut_timefld, FULLTIME)); if (signo == SIGINT) exit(1); (void)fflush(stdout); /* fix required for rsh */ }
static void update(void) { struct timespec ts; struct conf c; struct dbinfo dbi; unsigned int f, n; char buf[128]; void *ss = &c.c_ss; if (clock_gettime(CLOCK_REALTIME, &ts) == -1) { (*lfun)(LOG_ERR, "clock_gettime failed (%m)"); return; } again: for (n = 0, f = 1; state_iterate(state, &c, &dbi, f) == 1; f = 0, n++) { time_t when = c.c_duration + dbi.last; if (debug > 1) { char b1[64], b2[64]; sockaddr_snprintf(buf, sizeof(buf), "%a:%p", ss); (*lfun)(LOG_DEBUG, "%s:[%u] %s count=%d duration=%d " "last=%s " "now=%s", __func__, n, buf, dbi.count, c.c_duration, fmttime(b1, sizeof(b1), dbi.last), fmttime(b2, sizeof(b2), ts.tv_sec)); } if (c.c_duration == -1 || when >= ts.tv_sec) continue; if (dbi.id[0]) { run_change("rem", &c, dbi.id, 0); sockaddr_snprintf(buf, sizeof(buf), "%a", ss); syslog(LOG_INFO, "released %s/%d:%d after %d seconds", buf, c.c_lmask, c.c_port, c.c_duration); } state_del(state, &c); goto again; } }
static void gettimes(uid_t uid) { struct fsquot *fsqp; FILE *fd; char btime[80], ftime[80]; getdiscq(uid); if ((fd = fopen64(tmpfil, "w")) == NULL) { (void) fprintf(stderr, "edquota: "); perror(tmpfil); (void) unlink(tmpfil); exit(32); } for (fsqp = fsqlist; fsqp; fsqp = fsqp->fsq_next) { fmttime(btime, fsqp->fsq_dqb.dqb_btimelimit); fmttime(ftime, fsqp->fsq_dqb.dqb_ftimelimit); (void) fprintf(fd, "fs %s blocks time limit = %s, files time limit = %s\n", fsqp->fsq_fs, btime, ftime); } (void) fclose(fd); }
static htsmsg_t * avt_GetMediaInfo_common(http_connection_t *hc, htsmsg_t *args, const char *myhost, int myport, int ext) { char str[256]; htsmsg_t *out = htsmsg_create_map(); hts_mutex_lock(&upnp_lock); if(ext) htsmsg_add_str(out, "CurrentType", current_mediaCategory()); htsmsg_add_u32(out, "NrTracks", upnp_current_total_tracks); fmttime(str, sizeof(str), upnp_current_track_duration); htsmsg_add_str(out, "MediaDuration", str); htsmsg_add_str(out, "CurrentURI", upnp_current_url ?: ""); char *meta = build_didl(myhost, myport); htsmsg_add_str(out, "CurrentURIMetaData", meta); free(meta); htsmsg_add_str(out, "PlayMedium", upnp_current_playstatus == NULL ? "NONE" : "NETWORK"); hts_mutex_unlock(&upnp_lock); return out; }
static void process(bl_t bl) { struct sockaddr_storage rss; socklen_t rsl; char rbuf[BUFSIZ]; bl_info_t *bi; struct conf c; struct dbinfo dbi; struct timespec ts; if (clock_gettime(CLOCK_REALTIME, &ts) == -1) { (*lfun)(LOG_ERR, "clock_gettime failed (%m)"); return; } if ((bi = bl_recv(bl)) == NULL) { (*lfun)(LOG_ERR, "no message (%m)"); return; } if (getremoteaddress(bi, &rss, &rsl) == -1) goto out; if (debug) { sockaddr_snprintf(rbuf, sizeof(rbuf), "%a:%p", (void *)&rss); (*lfun)(LOG_DEBUG, "processing type=%d fd=%d remote=%s msg=%s" " uid=%lu gid=%lu", bi->bi_type, bi->bi_fd, rbuf, bi->bi_msg, (unsigned long)bi->bi_uid, (unsigned long)bi->bi_gid); } if (conf_find(bi->bi_fd, bi->bi_uid, &rss, &c) == NULL) { (*lfun)(LOG_DEBUG, "no rule matched"); goto out; } if (state_get(state, &c, &dbi) == -1) goto out; if (debug) { char b1[128], b2[128]; (*lfun)(LOG_DEBUG, "%s: db state info for %s: count=%d/%d " "last=%s now=%s", __func__, rbuf, dbi.count, c.c_nfail, fmttime(b1, sizeof(b1), dbi.last), fmttime(b2, sizeof(b2), ts.tv_sec)); } switch (bi->bi_type) { case BL_ADD: dbi.count++; dbi.last = ts.tv_sec; if (dbi.id[0]) { /* * We should not be getting this since the rule * should have blocked the address. A possible * explanation is that someone removed that rule, * and another would be that we got another attempt * before we added the rule. In anycase, we remove * and re-add the rule because we don't want to add * it twice, because then we'd lose track of it. */ (*lfun)(LOG_DEBUG, "rule exists %s", dbi.id); (void)run_change("rem", &c, dbi.id, 0); dbi.id[0] = '\0'; } if (c.c_nfail != -1 && dbi.count >= c.c_nfail) { int res = run_change("add", &c, dbi.id, sizeof(dbi.id)); if (res == -1) goto out; sockaddr_snprintf(rbuf, sizeof(rbuf), "%a", (void *)&rss); (*lfun)(LOG_INFO, "blocked %s/%d:%d for %d seconds", rbuf, c.c_lmask, c.c_port, c.c_duration); } break; case BL_DELETE: if (dbi.last == 0) goto out; dbi.last = 0; break; default: (*lfun)(LOG_ERR, "unknown message %d", bi->bi_type); } if (state_put(state, &c, &dbi) == -1) goto out; out: close(bi->bi_fd); }
/* * wtmp -- * read through the wtmp file */ void wtmp(const char *file, int namesz, int linesz, int hostsz) { struct utmp *bp; /* current structure */ TTY *T; /* tty list entry */ struct stat stb; /* stat of file for sz */ time_t delta; /* time difference */ off_t bl; int bytes, wfd; char *ct; const char *crmsg; size_t len = sizeof(*buf) * MAXUTMP; if ((buf = malloc(len)) == NULL) err(1, "Cannot allocate utmp buffer"); crmsg = NULL; if ((wfd = open(file, O_RDONLY, 0)) < 0 || fstat(wfd, &stb) == -1) err(1, "%s", file); bl = (stb.st_size + len - 1) / len; buf[FIRSTVALID].ut_timefld = time(NULL); (void)signal(SIGINT, onintr); (void)signal(SIGQUIT, onintr); while (--bl >= 0) { if (lseek(wfd, bl * len, SEEK_SET) == -1 || (bytes = read(wfd, buf, len)) == -1) err(1, "%s", file); for (bp = &buf[bytes / sizeof(*buf) - 1]; bp >= buf; --bp) { /* * if the terminal line is '~', the machine stopped. * see utmp(5) for more info. */ if (bp->ut_line[0] == '~' && !bp->ut_line[1]) { /* everybody just logged out */ for (T = ttylist; T; T = T->next) T->logout = -bp->ut_timefld; currentout = -bp->ut_timefld; crmsg = strncmp(bp->ut_name, "shutdown", namesz) ? "crash" : "shutdown"; if (want(bp, NO)) { ct = fmttime(bp->ut_timefld, fulltime); printf("%-*.*s %-*.*s %-*.*s %s\n", namesz, namesz, bp->ut_name, linesz, linesz, bp->ut_line, hostsz, hostsz, bp->ut_host, ct); if (maxrec != -1 && !--maxrec) return; } continue; } /* * if the line is '{' or '|', date got set; see * utmp(5) for more info. */ if ((bp->ut_line[0] == '{' || bp->ut_line[0] == '|') && !bp->ut_line[1]) { if (want(bp, NO)) { ct = fmttime(bp->ut_timefld, fulltime); printf("%-*.*s %-*.*s %-*.*s %s\n", namesz, namesz, bp->ut_name, linesz, linesz, bp->ut_line, hostsz, hostsz, bp->ut_host, ct); if (maxrec && !--maxrec) return; } continue; } /* find associated tty */ for (T = ttylist;; T = T->next) { if (!T) { /* add new one */ T = addtty(bp->ut_line); break; } if (!strncmp(T->tty, bp->ut_line, LINESIZE)) break; } if (TYPE(bp) == SIGNATURE) continue; if (bp->ut_name[0] && want(bp, YES)) { ct = fmttime(bp->ut_timefld, fulltime); printf("%-*.*s %-*.*s %-*.*s %s ", namesz, namesz, bp->ut_name, linesz, linesz, bp->ut_line, hostsz, hostsz, bp->ut_host, ct); if (!T->logout) puts(" still logged in"); else { if (T->logout < 0) { T->logout = -T->logout; printf("- %s", crmsg); } else printf("- %s", fmttime(T->logout, fulltime | TIMEONLY)); delta = T->logout - bp->ut_timefld; if (delta < SECSPERDAY) printf(" (%s)\n", fmttime(delta, fulltime | TIMEONLY | GMT)); else printf(" (%ld+%s)\n", delta / SECSPERDAY, fmttime(delta, fulltime | TIMEONLY | GMT)); } if (maxrec != -1 && !--maxrec) return; } T->logout = bp->ut_timefld; } } fulltime = 1; /* show full time */ crmsg = fmttime(buf[FIRSTVALID].ut_timefld, FULLTIME); if ((ct = strrchr(file, '/')) != NULL) ct++; printf("\n%s begins %s\n", ct ? ct : file, crmsg); }
int cspoll(Cs_t* state, Cspoll_t* fds, int num, int ms) { register Cspoll_t* pp; register Cspoll_t* mp; #if CS_LIB_SOCKET || CS_LIB_V10 register int events; register int width; fd_set rd; register fd_set* rp = &rd; fd_set wr; register fd_set* wp = ≀ #if CS_LIB_SOCKET fd_set ex; register fd_set* ep = &ex; struct timeval* tp; struct timeval tv; if (ms >= 0) { tv.tv_sec = ms / 1000; tv.tv_usec = (ms % 1000) * 1000; tp = &tv; } else tp = 0; FD_ZERO(ep); #endif FD_ZERO(rp); FD_ZERO(wp); events = width = 0; for (mp = (pp = fds) + num; pp < mp; pp++) if (pp->fd >= 0) { if (pp->fd > width) width = pp->fd; if (pp->events & CS_POLL_READ) { events |= CS_POLL_READ; FD_SET(pp->fd, rp); } if (pp->events & CS_POLL_WRITE) { events |= CS_POLL_WRITE; FD_SET(pp->fd, wp); } if (pp->events & CS_POLL_CONTROL) { events |= CS_POLL_CONTROL; #if CS_LIB_SOCKET FD_SET(pp->fd, ep); #endif } } if (!(events & CS_POLL_WRITE)) wp = 0; #if CS_LIB_SOCKET if (!(events & CS_POLL_READ)) rp = 0; if (!(events & CS_POLL_CONTROL)) ep = 0; messagef((state->id, NiL, -6, "poll: %s num=%d ms=%d sec=%d usec=%d", fmttime("%K", CSTIME()), num, ms, tp ? tp->tv_sec : 0, tp ? tp->tv_usec : 0)); num = select(width + 1, rp, wp, ep, tp); #else if (!(events & (CS_POLL_READ|CS_POLL_CONTROL))) rp = 0; messagef((state->id, NiL, -6, "poll: %s num=%d ms=%d", fmttime("%K", CSTIME()), num, ms); num = select(width + 1, rp, wp, ms); #endif messagef((state->id, NiL, -6, "poll: %s num=%d", fmttime("%K", CSTIME()), num)); if (num < 0) messagef((state->id, NiL, -1, "poll: select error")); else for (num = 0, pp = fds; pp < mp; pp++) { pp->status = 0; if (pp->fd >= 0) { if (rp && FD_ISSET(pp->fd, rp)) { #if CS_LIB_V10 long n; if ((pp->event & CS_POLL_CONTROL) && ioctl(fd, FIONREAD, &n)) pp->status |= CS_POLL_CLOSE; else if (!n) pp->status |= CS_POLL_CONTROL; else #endif pp->status |= CS_POLL_READ; } if (wp && FD_ISSET(pp->fd, wp)) pp->status |= CS_POLL_WRITE; #if CS_LIB_SOCKET if (ep && FD_ISSET(pp->fd, ep)) pp->status |= CS_POLL_CONTROL; #endif if (pp->status) { pp->status |= pp->events & (CS_POLL_AUTH|CS_POLL_CONNECT|CS_POLL_USER); num++; } } } return num; #else #if CS_LIB_STREAM int n; #if _lib_poll_fd_2 n = poll(num, fds, ms); #else n = poll(fds, num, ms); #endif if (n < 0) messagef((state->id, NiL, -1, "poll: poll error")); else if (n > 0) { int i; #ifdef RS_HIPRI struct strbuf buf; buf.maxlen = 0; #endif for (mp = (pp = fds) + num, i = n; pp < mp; pp++) { if (pp->status) { pp->status |= pp->events & (CS_POLL_AUTH|CS_POLL_CONNECT|CS_POLL_USER); #ifdef RS_HIPRI if (pp->status & CS_POLL_CONTROL) { int f = RS_HIPRI; if (getmsg(pp->fd, NiL, &buf, &f)) pp->status &= ~CS_POLL_CONTROL; } #endif if (--i <= 0) break; } } } return n; #else errno = EINVAL; messagef((state->id, NiL, -1, "poll: not supported")); return -1; #endif #endif }
static int prformat(Sfio_t* sp, void* vp, Sffmt_t* dp) { register Fmt_t* fmt = (Fmt_t*)dp; register Exnode_t* node; register char* s; register char* txt; int n; int from; int to; time_t tm; dp->flags |= SFFMT_VALUE; if (fmt->args) { if (node = (dp->fmt == '*') ? fmt->args->param[dp->size] : fmt->args->arg) fmt->value = exeval(fmt->expr, node, fmt->env); else fmt->value.integer = 0; to = fmt->args->arg->type; } else if (!(fmt->actuals = fmt->actuals->data.operand.right)) exerror("printf: not enough arguments"); else { node = fmt->actuals->data.operand.left; from = node->type; switch (dp->fmt) { case 'f': case 'g': to = FLOATING; break; case 's': case '[': to = STRING; break; default: switch (from) { case INTEGER: case UNSIGNED: to = from; break; default: to = INTEGER; break; } break; } if (to == from) fmt->value = exeval(fmt->expr, node, fmt->env); else { node = excast(fmt->expr, node, to, NiL, 0); fmt->value = exeval(fmt->expr, node, fmt->env); node->data.operand.left = 0; exfree(fmt->expr, node); if (to == STRING) { if (fmt->value.string) { n = strlen(fmt->value.string); if (s = fmtbuf(n + 1)) memcpy(s, fmt->value.string, n + 1); vmfree(fmt->expr->vm, fmt->value.string); fmt->value.string = s; } if (!fmt->value.string) fmt->value.string = ""; } } } switch (to) { case STRING: *((char**)vp) = fmt->value.string; fmt->fmt.size = -1; break; case FLOATING: *((double*)vp) = fmt->value.floating; fmt->fmt.size = sizeof(double); break; default: *((Sflong_t*)vp) = fmt->value.integer; dp->size = sizeof(Sflong_t); break; } if (dp->n_str > 0) { if (!fmt->tmp && !(fmt->tmp = sfstropen())) txt = exnospace(); else { sfprintf(fmt->tmp, "%.*s", dp->n_str, dp->t_str); txt = exstash(fmt->tmp, NiL); } } else txt = 0; switch (dp->fmt) { case 'q': case 'Q': s = *((char**)vp); *((char**)vp) = fmtquote(s, "$'", "'", strlen(s), 0); dp->fmt = 's'; dp->size = -1; break; case 'S': dp->flags &= ~SFFMT_LONG; s = *((char**)vp); if (txt) { if (streq(txt, "identifier")) { if (*s && !isalpha(*s)) *s++ = '_'; for (; *s; s++) if (!isalnum(*s)) *s = '_'; } else if (streq(txt, "invert")) { for (; *s; s++) if (isupper(*s)) *s = tolower(*s); else if (islower(*s)) *s = toupper(*s); } else if (streq(txt, "lower")) { for (; *s; s++) if (isupper(*s)) *s = tolower(*s); } else if (streq(txt, "upper")) { for (; *s; s++) if (islower(*s)) *s = toupper(*s); } else if (streq(txt, "variable")) { for (; *s; s++) if (!isalnum(*s) && *s != '_') *s = '.'; } } dp->fmt = 's'; dp->size = -1; break; case 't': case 'T': if ((tm = *((Sflong_t*)vp)) == -1) tm = time(NiL); *((char**)vp) = fmttime(txt ? txt : "%?%K", tm); dp->fmt = 's'; dp->size = -1; break; } return 0; }
main(int argc, char** argv) { Ardir_t* dir; Ardirent_t* ent; long touch; char* file; touch = 0; while (file = *++argv) { if (!strcmp(file, "-t") && *(argv + 1)) touch = strtol(*++argv, NiL, 0); else if (dir = ardiropen(file, NiL, touch ? ARDIR_UPDATE : 0)) { sfprintf(sfstdout, "%s: type=%s truncate=%d%s\n", file, dir->meth->name, dir->truncate, (dir->flags & ARDIR_RANLIB) ? " ranlib" : ""); while (ent = ardirnext(dir)) { if (touch) { ent->mtime = touch; ardirchange(dir, ent); sfprintf(sfstdout, "touch %s\n", ent->name); } else sfprintf(sfstdout, "%s %8u %8u %8llu %8llu %s %s\n", fmtmode(ent->mode, 1), ent->uid, ent->gid, ent->size, ent->offset, fmttime("%k", ent->mtime), ent->name); } if (ardirclose(dir)) error(2, "%s: archive read error", file); } else error(ERROR_SYSTEM|2, "%s: not an archive", file); } return 0; }
void printline(void) { char buf[9]; mvwprintw(wnd, row, 0, "%s.%s%d", sensordev.xname, sensor_type_s[sensor.type], sensor.numt); switch (sensor.type) { case SENSOR_TEMP: mvwprintw(wnd, row, 24, "%10.2f degC", (sensor.value - 273150000) / 1000000.0); break; case SENSOR_FANRPM: mvwprintw(wnd, row, 24, "%11lld RPM", sensor.value); break; case SENSOR_VOLTS_DC: mvwprintw(wnd, row, 24, "%10.2f V DC", sensor.value / 1000000.0); break; case SENSOR_WATTS: mvwprintw(wnd, row, 24, "%13.2f W", sensor.value / 1000000.0); break; case SENSOR_AMPS: mvwprintw(wnd, row, 24, "%10.2f A", sensor.value / 1000000.0); break; case SENSOR_INDICATOR: mvwprintw(wnd, row, 24, "%15s", sensor.value? "On" : "Off"); break; case SENSOR_INTEGER: mvwprintw(wnd, row, 24, "%11lld raw", sensor.value); break; case SENSOR_PERCENT: mvwprintw(wnd, row, 24, "%14.2f%%", sensor.value / 1000.0); break; case SENSOR_LUX: mvwprintw(wnd, row, 24, "%15.2f lx", sensor.value / 1000000.0); break; case SENSOR_DRIVE: if (0 < sensor.value && (size_t)sensor.value < sizeof(drvstat)/sizeof(drvstat[0])) { mvwprintw(wnd, row, 24, "%15s", drvstat[sensor.value]); break; } break; case SENSOR_TIMEDELTA: mvwprintw(wnd, row, 24, "%15s", fmttime(sensor.value / 1000000000.0)); break; case SENSOR_WATTHOUR: mvwprintw(wnd, row, 24, "%12.2f Wh", sensor.value / 1000000.0); break; case SENSOR_AMPHOUR: mvwprintw(wnd, row, 24, "%10.2f Ah", sensor.value / 1000000.0); break; case SENSOR_FREQ: humanize_number(buf, sizeof(buf), sensor.value, "Hz", HN_AUTOSCALE, HN_DIVISOR_1000 | HN_DECIMAL); mvwprintw(wnd, row, 24, "%15s", buf); break; default: mvwprintw(wnd, row, 24, "%10lld", sensor.value); break; } if (sensor.desc[0] != '\0') mvwprintw(wnd, row, 58, "(%s)", sensor.desc); switch (sensor.status) { case SENSOR_S_UNSPEC: break; case SENSOR_S_UNKNOWN: mvwaddstr(wnd, row, 45, "unknown"); break; case SENSOR_S_WARN: mvwaddstr(wnd, row, 45, "WARNING"); break; case SENSOR_S_CRIT: mvwaddstr(wnd, row, 45, "CRITICAL"); break; case SENSOR_S_OK: mvwaddstr(wnd, row, 45, "OK"); break; } row++; }
static int diskarenaclump(HConnect *c, Arena *arena, vlong off, char *scorestr) { uchar *blk, *blk2; Clump cl; char err[ERRMAX]; uchar xscore[VtScoreSize], score[VtScoreSize]; Unwhack uw; int n; if(scorestr){ if(vtparsescore(scorestr, nil, score) < 0){ hprint(&c->hout, "bad score %s: %r\n", scorestr); return -1; } if(off < 0){ off = findintoc(c, arena, score); if(off < 0){ hprint(&c->hout, "score %V not found in arena %s\n", score, arena->name); return -1; } hprint(&c->hout, "score %V at %#llx\n", score, off); } }else memset(score, 0, sizeof score); if(off < 0){ hprint(&c->hout, "bad offset %#llx\n", off); return -1; } off += arena->base; blk = vtmalloc(ClumpSize + VtMaxLumpSize); if(readpart(arena->part, off, blk, ClumpSize + VtMaxLumpSize) != ClumpSize + VtMaxLumpSize){ hprint(&c->hout, "reading at %#llx: %r\n", off); vtfree(blk); return -1; } if(unpackclump(&cl, blk, arena->clumpmagic) < 0){ hprint(&c->hout, "unpackclump: %r\n<br>"); rerrstr(err, sizeof err); if(strstr(err, "magic")){ hprint(&c->hout, "trying again with magic=%#ux<br>\n", U32GET(blk)); if(unpackclump(&cl, blk, U32GET(blk)) < 0){ hprint(&c->hout, "unpackclump: %r\n<br>\n"); goto error; } }else goto error; } hprint(&c->hout, "<pre>type=%d size=%d uncsize=%d score=%V\n", cl.info.type, cl.info.size, cl.info.uncsize, cl.info.score); hprint(&c->hout, "encoding=%d creator=%d time=%d %s</pre>\n", cl.encoding, cl.creator, cl.time, fmttime(err, cl.time)); if(cl.info.type == VtCorruptType) hprint(&c->hout, "clump is marked corrupt<br>\n"); if(cl.info.size >= VtMaxLumpSize){ hprint(&c->hout, "clump too big\n"); goto error; } switch(cl.encoding){ case ClumpECompress: blk2 = vtmalloc(VtMaxLumpSize); unwhackinit(&uw); n = unwhack(&uw, blk2, cl.info.uncsize, blk+ClumpSize, cl.info.size); if(n < 0){ hprint(&c->hout, "decompression failed\n"); vtfree(blk2); goto error; } if(n != cl.info.uncsize){ hprint(&c->hout, "got wrong amount: %d wanted %d\n", n, cl.info.uncsize); // hhex(blk2, n); vtfree(blk2); goto error; } scoremem(xscore, blk2, cl.info.uncsize); vtfree(blk2); break; case ClumpENone: scoremem(xscore, blk+ClumpSize, cl.info.size); break; } hprint(&c->hout, "score=%V<br>\n", xscore); if(scorestr && scorecmp(score, xscore) != 0) hprint(&c->hout, "score does NOT match expected %V\n", score); vtfree(blk); return 0; error: // hhex(blk, ClumpSize + VtMaxLumpSize); vtfree(blk); return -1; }
static int diskarenapart(HConnect *c, char *disk, Part *p) { char *arenaname; ArenaPart ap; ArenaHead head; Arena arena; char *table; char *score; char *clump; uchar *blk; vlong start, end, off; char tbuf[60]; hprint(&c->hout, "<h1>arena partition %s</h1>\n", disk); if((table = readap(p, &ap)) == nil){ hprint(&c->hout, "%r\n"); goto out; } hprint(&c->hout, "<pre>\n"); hprint(&c->hout, "version=%d blocksize=%d base=%d\n", ap.version, ap.blocksize, ap.arenabase); hprint(&c->hout, "</pre>\n"); arenaname = hargstr(c, "arena", ""); if(arenaname[0] == 0){ diskarenatable(c, disk, table); goto out; } if(xfindarena(table, arenaname, &start, &end) < 0){ hprint(&c->hout, "no such arena %s\n", arenaname); goto out; } hprint(&c->hout, "<h2>arena %s</h2>\n", arenaname); hprint(&c->hout, "<pre>start=%#llx end=%#llx<pre>\n", start, end); if(end < start || end - start < HeadSize){ hprint(&c->hout, "bad size %#llx\n", end - start); goto out; } // read arena header, tail blk = vtmalloc(HeadSize); if(readpart(p, start, blk, HeadSize) != HeadSize){ hprint(&c->hout, "reading header: %r\n"); vtfree(blk); goto out; } if(unpackarenahead(&head, blk) < 0){ hprint(&c->hout, "corrupt arena header: %r\n"); // hhex(blk, HeadSize); vtfree(blk); goto out; } vtfree(blk); hprint(&c->hout, "head:\n<pre>\n"); hprint(&c->hout, "version=%d name=%s blocksize=%d size=%#llx clumpmagic=%#ux\n", head.version, head.name, head.blocksize, head.size, head.clumpmagic); hprint(&c->hout, "</pre><br><br>\n"); if(head.blocksize > MaxIoSize || head.blocksize >= end - start){ hprint(&c->hout, "corrupt block size %d\n", head.blocksize); goto out; } blk = vtmalloc(head.blocksize); if(readpart(p, end - head.blocksize, blk, head.blocksize) < 0){ hprint(&c->hout, "reading tail: %r\n"); vtfree(blk); goto out; } memset(&arena, 0, sizeof arena); arena.part = p; arena.blocksize = head.blocksize; arena.clumpmax = head.blocksize / ClumpInfoSize; arena.base = start + head.blocksize; arena.size = end - start - 2 * head.blocksize; if(unpackarena(&arena, blk) < 0){ vtfree(blk); goto out; } scorecp(arena.score, blk+head.blocksize - VtScoreSize); vtfree(blk); hprint(&c->hout, "tail:\n<pre>\n"); hprint(&c->hout, "version=%d name=%s\n", arena.version, arena.name); hprint(&c->hout, "ctime=%d %s\n", arena.ctime, fmttime(tbuf, arena.ctime)); hprint(&c->hout, "wtime=%d %s\n", arena.wtime, fmttime(tbuf, arena.wtime)); hprint(&c->hout, "clumpmagic=%#ux\n", arena.clumpmagic); hprint(&c->hout, "score %V\n", arena.score); hprint(&c->hout, "diskstats:\n"); hprint(&c->hout, "\tclumps=%,d cclumps=%,d used=%,lld uncsize=%,lld sealed=%d\n", arena.diskstats.clumps, arena.diskstats.cclumps, arena.diskstats.used, arena.diskstats.uncsize, arena.diskstats.sealed); hprint(&c->hout, "memstats:\n"); hprint(&c->hout, "\tclumps=%,d cclumps=%,d used=%,lld uncsize=%,lld sealed=%d\n", arena.memstats.clumps, arena.memstats.cclumps, arena.memstats.used, arena.memstats.uncsize, arena.memstats.sealed); if(arena.clumpmax == 0){ hprint(&c->hout, "bad clumpmax\n"); goto out; } score = hargstr(c, "score", ""); clump = hargstr(c, "clump", ""); if(clump[0]){ off = strtoull(clump, 0, 0); diskarenaclump(c, &arena, off, score[0] ? score : nil); }else if(score[0]){ diskarenaclump(c, &arena, -1, score); }else{ diskarenatoc(c, &arena); } out: free(table); return 0; }
static htsmsg_t * avt_generate_props(upnp_local_service_t *uls, const char *myhost, int myport) { char *event; htsbuf_queue_t xml; char str[256]; const char *s; htsbuf_queue_init(&xml, 0); htsbuf_qprintf(&xml, "<Event xmlns=\"urn:schemas-upnp-org:metadata-1-0/RCS/\">" "<InstanceID val=\"0\">"); upnp_event_encode_str(&xml, "TransportState", current_playstate()); upnp_event_encode_str(&xml, "CurrentMediaCategory", current_mediaCategory()); // PlaybackStorageMedium if(upnp_current_playstatus == NULL) s = "NONE"; else s = "NETWORK"; upnp_event_encode_str(&xml, "PlaybackStorageMedium", s); upnp_event_encode_str(&xml, "CurrentPlayMode", current_playMode()); current_transportActions(str, sizeof(str)); upnp_event_encode_str(&xml, "CurrentTransportActions", str); upnp_event_encode_int(&xml, "NumberOfTracks", upnp_current_total_tracks); upnp_event_encode_int(&xml, "CurrentTrack", upnp_current_track); upnp_event_encode_str(&xml, "AVTransportURI", upnp_current_url ?: ""); upnp_event_encode_int(&xml, "TransportPlaySpeed", 1); // Metadata char *meta = build_didl(myhost, myport); upnp_event_encode_str(&xml, "AVTransportURIMetaData", meta); upnp_event_encode_str(&xml, "CurrentTrackMetaData", meta); free(meta); fmttime(str, sizeof(str), upnp_current_track_duration); upnp_event_encode_str(&xml, "CurrentTrackDuration", str); upnp_event_encode_str(&xml, "CurrentMediaDuration", str); upnp_event_encode_str(&xml, "PossibleRecordQualityModes", NULL); upnp_event_encode_str(&xml, "TransportStatus", "OK"); upnp_event_encode_str(&xml, "DRMState", "UNKNOWN"); upnp_event_encode_str(&xml, "RecordMediumWriteStatus", NULL); upnp_event_encode_str(&xml, "RecordStorageMedium", NULL); upnp_event_encode_str(&xml, "PossibleRecordStorageMedia", NULL); upnp_event_encode_str(&xml, "NextAVTransportURI", ""); upnp_event_encode_str(&xml, "NextAVTransportURIMetaData", NULL); upnp_event_encode_str(&xml, "CurrentRecordQualityMode", NULL); upnp_event_encode_str(&xml, "PossiblePlaybackStorageMedia", "NETWORK"); htsbuf_qprintf(&xml, "</InstanceID></Event>"); event = htsbuf_to_string(&xml); htsmsg_t *r = htsmsg_create_map(); htsmsg_add_str(r, "LastChange", event); free(event); return r; }
static void warn(struct mnttab *mntp, struct dqblk *dqp) { struct timeval tv; time(&(tv.tv_sec)); tv.tv_usec = 0; if (dqp->dqb_bhardlimit && dqp->dqb_curblocks >= dqp->dqb_bhardlimit) { printf("Block limit reached on %s\n", mntp->mnt_mountp); } else if (dqp->dqb_bsoftlimit && dqp->dqb_curblocks >= dqp->dqb_bsoftlimit) { if (dqp->dqb_btimelimit == 0) { printf("Over disk quota on %s, remove %luK\n", mntp->mnt_mountp, kb(dqp->dqb_curblocks - dqp->dqb_bsoftlimit + 1)); } else if (dqp->dqb_btimelimit > tv.tv_sec) { char btimeleft[80]; fmttime(btimeleft, dqp->dqb_btimelimit - tv.tv_sec); printf("Over disk quota on %s, remove %luK within %s\n", mntp->mnt_mountp, kb(dqp->dqb_curblocks - dqp->dqb_bsoftlimit + 1), btimeleft); } else { printf( "Over disk quota on %s, time limit has expired, remove %luK\n", mntp->mnt_mountp, kb(dqp->dqb_curblocks - dqp->dqb_bsoftlimit + 1)); } } if (dqp->dqb_fhardlimit && dqp->dqb_curfiles >= dqp->dqb_fhardlimit) { printf("File count limit reached on %s\n", mntp->mnt_mountp); } else if (dqp->dqb_fsoftlimit && dqp->dqb_curfiles >= dqp->dqb_fsoftlimit) { if (dqp->dqb_ftimelimit == 0) { printf("Over file quota on %s, remove %lu file%s\n", mntp->mnt_mountp, dqp->dqb_curfiles - dqp->dqb_fsoftlimit + 1, ((dqp->dqb_curfiles - dqp->dqb_fsoftlimit + 1) > 1 ? "s" : "")); } else if (dqp->dqb_ftimelimit > tv.tv_sec) { char ftimeleft[80]; fmttime(ftimeleft, dqp->dqb_ftimelimit - tv.tv_sec); printf( "Over file quota on %s, remove %lu file%s within %s\n", mntp->mnt_mountp, dqp->dqb_curfiles - dqp->dqb_fsoftlimit + 1, ((dqp->dqb_curfiles - dqp->dqb_fsoftlimit + 1) > 1 ? "s" : ""), ftimeleft); } else { printf( "Over file quota on %s, time limit has expired, remove %lu file%s\n", mntp->mnt_mountp, dqp->dqb_curfiles - dqp->dqb_fsoftlimit + 1, ((dqp->dqb_curfiles - dqp->dqb_fsoftlimit + 1) > 1 ? "s" : "")); } } }
static int textwrite(Dssfile_t* file, Dssrecord_t* record, Dssdisc_t* disc) { register Text_t* text = (Text_t*)file->dss->meth->data; Cxvalue_t* data = (Cxvalue_t*)record->data; register char* f; register int c; int num; num = 0; f = text->format; for (;;) { switch (c = *f++) { case 0: break; case ' ': sfputc(file->io, ' '); break; case '%': switch (c = *f++) { case 'h': case 'l': c = *f++; break; } switch (c) { case 0: f--; continue; case '%': sfputc(file->io, '%'); continue; case 'c': sfputc(file->io, (int)data[num].number); num++; break; case 'd': case 'n': case 'u': sfprintf(file->io, "%d", (long)data[num].number); num++; break; case 'i': sfprintf(file->io, "%s", fmtip4((Ipaddr_t)data[num].number, -1)); num++; break; case 'f': case 'g': sfprintf(file->io, "%Lg", data[num].number); num++; break; case 'o': sfprintf(file->io, "%o", (long)data[num].number); num++; break; case 'x': sfprintf(file->io, "%x", (long)data[num].number); num++; break; case 's': sfprintf(file->io, "%-.*s", data[num].string.size, data[num].string.data); num++; break; case 't': sfprintf(file->io, "%s", fmttime("%K", (time_t)data[num].number)); num++; break; } continue; case '\n': break; default: sfputc(file->io, c); continue; } break; } sfputc(file->io, '\n'); return 0; }