int install_sexe_userdata(sexe_t *S, char *tag) { SHFL *fl; shjson_t *udata; shfs_t *fs; shbuf_t *buff; shkey_t *k; char path[PATH_MAX+1]; int is_new; k = shkey_str(tag); sprintf(path, "/sys/data/sexe/%s", shkey_hex(k)); memcpy(&S->pname, k, sizeof(S->pname)); shkey_free(&k); buff = shbuf_init(); fs = shfs_init(NULL); fl = shfs_file_find(fs, path); is_new = shfs_read(fl, buff); udata = shjson_init(shbuf_size(buff) ? (char *)shbuf_data(buff) : NULL); shbuf_free(&buff); if (is_new) shjson_num_add(udata, "birth", shtimef(shtime())); sexe_table_set(S, udata); lua_setglobal(S, "userdata"); shjson_free(&udata); shfs_free(&fs); return (0); }
static void shproc_state_set(shproc_t *proc, int state) { int ostate = proc->proc_state; if (state < 0 || state >= MAX_SHPROC_STATES) return; if (proc->proc_state == state) return; if (proc->proc_stamp) { proc->stat.span_tot[ostate] += (shtimef(shtime()) - shtimef(proc->proc_stamp)); proc->stat.span_cnt[ostate]++; } proc->proc_stamp = shtime(); proc->proc_state = state; }
static int _lfunc_sexe_timeu(lua_State *L) { time_t t = (time_t)luaL_checknumber(L, 1); lua_pushnumber(L, shtimef(shtimeu(t))); return 1; /* 'timeu' */ }
static int _lfunc_sexe_time(lua_State *L) { lua_pushnumber(L, shtimef(shtime())); return 1; /* 'time' */ }