int main(int argc, char *argv[], void *extra) { register int n; register char *cp; char *delim = "#"; int width = 80; NoP(argc); NoP(extra); error_info.id = "banner"; while (n = optget(argv, usage)) switch (n) { case 'd': delim = opt_info.arg; break; case 'w': width = opt_info.num; break; case ':': error(2, "%s", opt_info.arg); break; case '?': error(ERROR_usage(2), "%s", opt_info.arg); break; } argv += opt_info.index; if(error_info.errors || !*argv) error(ERROR_usage(2), "%s", optusage((char*)0)); sfset(sfstdout,SF_LINE,0); while(cp = *argv++) banner(cp,delim,width); exit(0); }
int link(const char* from, const char* to) { NoP(from); NoP(to); errno = ENOSYS; return -1; }
static int intercept(Sfio_t* sp, int level, int flags) { register Rule_t* r; char* m; char* s; char* t; char* e; int n; int i; Sfio_t* tmp; NoP(sp); NoP(flags); if ((state.mam.level = level) > 0 && !state.hold && (r = internal.error) && (r->property & (P_functional|P_target)) == (P_functional|P_target) && !state.compileonly && !state.interrupt && (m = stakptr(0)) && (n = staktell()) > 0) { /* * make the error trap */ state.hold = m; while (*m && *m != ':') m++; while (isspace(*++m)); n -= m - state.hold; tmp = sfstropen(); sfprintf(tmp, "%d %-.*s", level, n, m); s = sfstruse(tmp); /* * return [ level | - ] [ message ] * level is new level or - to retain old * omitted message means it has been printed */ if (t = call(r, s)) { i = strtol(t, &e, 0); if (e > t) { t = e; level = i; } else if (*t == '-') t++; while (isspace(*t)) t++; } if (!t || !*t) { level |= ERROR_OUTPUT; message((-1, "suppressed %s message: `%-.*s'", level == 1 ? "warning" : "error", n, m)); } sfstrclose(tmp); state.hold = 0; } return level; }
int mount(const char* a, char* b, int c, void* d) { NoP(a); NoP(b); NoP(c); NoP(d); errno = ENOSYS; return -1; }
static int byprefix(Dt_t* dt, register Ptprefix_t* a, register Ptprefix_t* b, Dtdisc_t* disc) { NoP(dt); NoP(disc); if (a->max < b->min) return -1; if (a->min > b->max) return 1; return 0; }
static int infof(Opt_t* op, Sfio_t* sp, const char* s, Optdisc_t* dp) { NoP(op); NoP(s); NoP(dp); sfprintf(sp,"[+Control Modes.]{"); listfields(sp,C_FLAG); listgroup(sp,SPEED,"Attempt to set input and output baud rate to number given. A value of \b0\b causes immediate hangup"); listchars(sp,NUM); listgroup(sp,SIZE,"Number of bits in a character"); sfprintf(sp,"}[+Input Modes.]{"); listfields(sp,I_FLAG); sfprintf(sp,"}[+Output Modes.]{"); listfields(sp,O_FLAG); #ifdef CRDLY listmask(sp,CRDLY,"Carriage return delay style"); #endif #ifdef NLDLY listmask(sp,NLDLY,"Newline delay style"); #endif #ifdef TABDLY listmask(sp,TABDLY,"Horizontal tab delay style"); #endif #ifdef BSDLY listmask(sp,BSDLY,"Backspace delay style"); #endif #ifdef FFDLY listmask(sp,FFDLY,"Form feed delay style"); #endif #ifdef VTDLY listmask(sp,VTDLY,"Vertical tab delay style"); #endif sfprintf(sp,"}[+Local Modes.]{"); listfields(sp,L_FLAG); sfprintf(sp,"}[+Control Assignments.?If \ac\a is \bundef\b or an empty " "string then the control assignment is disabled.]{"); listchars(sp,WIND); listchars(sp,CHAR); sfprintf(sp,"}[+Combination Modes.]{"); listmode(sp,"ek"); listmode(sp,"evenp"); listmode(sp,"lcase"); listmode(sp,"oddp"); listmode(sp,"parity"); listmode(sp,"sane"); listmode(sp,"tabs"); listmode(sp,"LCASE"); sfputc(sp,'}'); return(1); }
extern int getopt(int argc, char* const* argv, const char* optstring) { int n; NoP(argc); opt_info.index = (optind > 1 || optind == lastoptind) ? optind : 0; if (opt_info.index >= argc) return -1; switch (n = optget((char**)argv, optstring)) { case ':': n = '?'; /*FALLTHROUGH*/ case '?': if (opterr && (!optstring || *optstring != ':')) { if (!error_info.id) error_info.id = argv[0]; errormsg(NiL, 2, opt_info.arg); } optopt = opt_info.option[1]; break; case 0: n = -1; break; } optarg = opt_info.arg; lastoptind = optind = opt_info.index; return n; }
static int sfpzexcept(Sfio_t* sp, int op, void* val, Sfdisc_t* dp) { register Sfpzip_t* pz = (Sfpzip_t*)dp; int r; NoP(sp); switch (op) { case SF_ATEXIT: sfdisc(sp, SF_POPDISC); return 0; case SF_CLOSING: case SF_DPOP: case SF_FINAL: if (pz->pz) { pz->pz->flags &= ~PZ_STREAM; r = pzclose(pz->pz); pz->pz = 0; } else r = 0; if (op != SF_CLOSING) free(dp); return r; case SF_DBUFFER: return 1; case SF_SYNC: return val ? 0 : pzsync(pz->pz); case SFPZ_HANDLE: return (*((Pz_t**)val) = pz->pz) ? 1 : -1; } return 0; }
main(int argc, char** argv) { register int c; struct mam* mp; NoP(argc); error_info.id = "mamtst"; while (c = optget(argv, "d#[debug]")) switch (c) { case 'd': error_info.trace = -opt_info.num; break; case '?': error(ERROR_USAGE|4, opt_info.arg); break; case ':': error(2, opt_info.arg); break; } if (error_info.errors) error(ERROR_USAGE|4, "%s", optusage(NiL)); if (!(mp = mamalloc())) error(3, "cannot initialize"); if (mamscan(mp, NiL) < 0) error(3, "invalid input"); dumpproc(mp->main); exit(error_info.errors != 0); }
int ftw(const char* path, int(*userf)(const char*, const struct stat*, int), int depth) { NoP(depth); ftw_userf = userf; return ftwalk(path, ftw_user, FTW_DOT, NiL); }
int main(int argc, char** argv) { NoP(argc); csserve(NiL, argv[1], svc_init, NiL, svc_connect, svc_read, NiL, svc_timeout); exit(1); }
int main(int argc, char *argv[]) { register int n; NoP(argc); error_info.id = "mesg"; for (;;) { switch (optget(argv, usage)) { case ':': error(2, "%s", opt_info.arg); break; case '?': error(ERROR_usage(2), "%s", opt_info.arg); break; } break; } argv += opt_info.index; n = 0; if(error_info.errors || (*argv && (n= **argv) !='y' && n!='n')) error(ERROR_usage(2), "%s", optusage(NiL)); return mesg(n); }
int main(int argc, char** argv) { NoP(argc); csserve(NiL, argv[1], NiL, NiL, svc_connect, NiL, NiL, NiL); exit(1); }
int main(int argc, char** argv) { register char* s; register Sfio_t* sp; unsigned long n; int summary = 0; unsigned long total = 0; int trailer; NoP(argc); error_info.id = "ncsl"; for (;;) { switch (optget(argv, usage)) { case 0: break; case 's': summary = 1; continue; case '?': error(ERROR_USAGE|4, "%s", opt_info.arg); continue; case ':': error(2, "%s", opt_info.arg); continue; } break; } argv += opt_info.index; if (error_info.errors) error(ERROR_USAGE|4, "%s", optusage(NiL)); if (*argv) { trailer = *(argv + 1) != 0; while (s = *argv++) { if (!(sp = sfopen(NiL, s, "r"))) error(2, "%s: cannot open for reading", s); else { n = ncsl(sp); sfclose(sp); if (!summary) sfprintf(sfstdout, "%s: %lu\n", s, n); total += n; } } if (summary || trailer) sfprintf(sfstdout, "%lu\n", total); } else sfprintf(sfstdout, "%d\n", ncsl(sfstdin)); return error_info.errors != 0; }
void initwakeup(int repeat) { register Alarms_t* a; NoP(repeat); for (a = trap.alarms; a; a = a->next) a->rule = makerule(a->rule->name); }
static int svc_connect(void* handle, int fd, Cs_id_t* id, int clone, char** argv) { register State_t* state = (State_t*)handle; register File_t* fp; register char* s; int ad; int flags = 0; Fid_t fid; struct stat st; NoP(id); NoP(clone); if (!argv) return(-1); while ((s = *argv++) && *s != '/') switch (*s) { case 'm': flags |= CAT_MSG; break; } if (!s || (ad = csopen(s, 0)) < 0 && (ad = open(s, O_CREAT|O_APPEND|O_WRONLY|O_BINARY, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0) return(-1); if (fstat(ad, &st)) { close(ad); return(-1); } fid.dev = st.st_dev; fid.ino = st.st_ino; if (!(fp = (File_t*)hashlook(state->files, (char*)&fid, HASH_CREATE|HASH_SIZE(sizeof(File_t)), NiL))) { close(ad); return(-1); } if (!fp->reference++) fp->fd = ad; else close(ad); fp->flags |= flags; state->cat[fd] = fp; state->active++; state->dormant = 0; return(0); }
int nftw(const char* path, int(*userf)(const char*, const struct stat*, int, struct FTW*), int depth, int flags) { NoP(depth); nftw_userf = userf; if (flags & FTW_CHDIR) flags &= ~FTW_DOT; else flags |= FTW_DOT; nftw_flags = flags; return ftwalk(path, nftw_user, flags, NiL); }
void ppincref(char* parent, char* file, int line, int type) { register struct ppinstk* sp; int level; NoP(parent); NoP(line); if (type & PP_SYNC_PUSH) { level = 0; for (sp = pp.in; sp; sp = sp->prev) if (sp->type == IN_FILE) level++; if (level > 0) level--; error(0, "%-*s%s", level * 4, "", file); } }
int main(int argc, char** argv) { register Coshell_t* sp; register char* s; register int op; Coattr_t attr; NoP(argc); NoP(argv); error(-1, "debug"); init(); while ((s = sfgetr(sfstdin, '\n', 0)) && sfvalue(sfstdin) > 1) switch (s[sfvalue(sfstdin) - 1] = 0, op = *s == ':' ? (s++, *s++) : '?') { case '#': break; case '?': case ':': attributes(s, &attr, NiL); sp = state.shell; do { if (match(sp, &attr, 0)) { if (op == '?') sfputr(sfstdout, sp->name, '\n'); else { sfputr(sfstdout, sp->name, '\t'); sfputr(sfstdout, sp->misc, '\n'); } } } while ((sp = sp->next) != state.shell); break; case '=': if (!search(SET, s, NiL, NiL)) error(2, "%s: invalid host name", s); break; default: error(2, "`%s': invalid command", s - 2); break; } exit(0); }
int main(int argc, char** argv) { Css_t* css; Cssfd_t* fp; Connection_t* con; char* e; State_t state; NoP(argc); error_info.id = "css"; memset(&state, 0, sizeof(state)); state.disc.version = CSS_VERSION; state.disc.flags = CSS_DAEMON|CSS_ERROR|CSS_INTERRUPT; state.disc.acceptf = acceptf; state.disc.actionf = actionf; state.disc.errorf = errorf; state.disc.exceptf = exceptf; for (;;) { switch (optget(argv, usage)) { case 't': state.disc.timeout = strelapsed(opt_info.arg, &e, 1); if (*e) error(3, "%s: invalid timeout value", opt_info.arg); state.disc.flags |= CSS_DORMANT; continue; case '?': error(ERROR_USAGE|4, "%s", opt_info.arg); continue; case ':': error(2, "%s", opt_info.arg); continue; } break; } argv += opt_info.index; if (!argv[0] || !argv[1]) error(ERROR_USAGE|4, "%s", optusage(NiL)); if (!(state.tmp = sfstropen())) error(ERROR_SYSTEM|3, "out of space [tmp stream]"); if (!(state.proc = procopen(argv[1], argv + 1, NiL, NiL, PROC_READ|PROC_WRITE))) error(ERROR_SYSTEM|3, "%s: cannot execute", argv[1]); if (!(css = cssopen(argv[0], &state.disc))) return 1; if (!(fp = cssfd(css, state.proc->rfd, CS_POLL_READ))) error(ERROR_SYSTEM|3, "%s: cannot poll output", argv[1]); if (!(con = newof(0, Connection_t, 1, 0))) error(ERROR_SYSTEM|3, "out of space"); fp->data = con; con->service = 1; csspoll(CS_NEVER, 0); return 1; }
int pathcheck(const char* package, const char* tool, Pathcheck_t* pc) { #ifdef PARANOID register char* s; struct stat st; if (strmatch(tool, PARANOID) && environ && (s = *environ) && *s++ == '_' && *s++ == '=' && !stat(s, &st)) { unsigned long n; unsigned long o; Sfio_t* sp; n = time(NiL); o = st.st_ctime; if (n > o && (n - o) > (unsigned long)(60 * 60 * 24 * 90) && (sp = sfopen(NiL, "/etc/hosts", "r"))) { /* * this part is infallible */ n = 0; o = 0; while (n++ < 64 && (s = sfgetr(sp, '\n', 0))) if (strmatch(s, PARANOID_PAY)) { error(1, "licensed for external use -- %s employees should contact %s for the internal license", PARANOID_COMPANY, PARANOID_MAIL); break; } else if (*s != '#' && !isspace(*s) && !strneq(s, "127.", 4) && !strmatch(s, PARANOID_FREE) && o++ > 4) break; sfclose(sp); } } #else NoP(tool); #endif NoP(package); if (pc) memzero(pc, sizeof(*pc)); return(0); }
static ssize_t helpwrite(int fd, const void* buf, size_t len) { ssize_t n; NoP(fd); n = ed.help ? sfwrite(sfstderr, buf, len) : ed.verbose ? sfputr(ed.msg, "?", '\n') : 0; sfstrseek(ed.buffer.help, 0, SEEK_SET); sfwrite(ed.buffer.help, buf, len - 1); sfputc(ed.buffer.help, 0); return n; }
static int acceptf(Css_t* css, Cssfd_t* fp, Csid_t* ip, char** av, Cssdisc_t* disc) { register State_t* state = (State_t*)disc; register Connection_t* con; int i; NoP(ip); NoP(av); if (!(con = newof(0, Connection_t, 1, 0))) return -1; fp->data = con; con->fp = fp; con->mask = CHAN_DEFAULT; for (i = 0; i < elementsof(state->logs); i++) con->blocked[i] = -1; con->next = state->all; state->all = con; post(css, disc, con, NiL, 0, "join"); return fp->fd; }
static int acceptf(Css_t* css, Cssfd_t* fp, Csid_t* ip, char** av, Cssdisc_t* disc) { register Connection_t* con; NoP(av); if (!(con = newof(0, Connection_t, 1, 0))) return -1; fp->data = con; con->id = *ip; return fp->fd; }
int b_unixpath(int argc, char *argv[], void *context) { int flags = UWIN_W2U; int quote = 0; int n; char* cp; const char* dp; char buff[PATH_MAX+1]; NoP(argc); #if _AST_VERSION >= 20060701L cmdinit(argc, argv, context, NULL, 0); #else cmdinit(argv, context, NULL, 0); #endif while (n = optget(argv, usage)) switch (n) { case 'a': flags |= UWIN_U2W; break; case 'q': quote = 1; break; case ':': error(2, "%s", opt_info.arg); break; case '?': error(ERROR_usage(2), "%s", opt_info.arg); break; } argv += opt_info.index; if(!*argv || error_info.errors) error(ERROR_usage(2),"%s",optusage(NiL)); while(cp = *argv++) { uwin_pathmap(cp, buff, sizeof(buff), flags); if(quote) { for(dp=special;*dp;dp++) { if(strchr(buff, *dp)) break; } if(*dp) { sfprintf(sfstdout,"'%s'\n",buff); continue; } } sfprintf(sfstdout,"%s\n",buff); } return(0); }
static void* svc_init(void* handle, int fdmax) { State_t* state; NoP(handle); if (!(state = newof(0, State_t, 1, (fdmax - 1) * sizeof(File_t*)))) error(3, "out of space [state]"); if (!(state->files = hashalloc(NiL, HASH_set, HASH_ALLOCATE, HASH_namesize, sizeof(Fid_t), HASH_name, "files", 0))) error(3, "out of space [files]"); cstimeout(CS_SVC_DORMANT * 1000L); return((void*)state); }
int main(int argc, char** argv) { char* e; State_t state; NoP(argc); error_info.id = "mbb"; memset(&state, 0, sizeof(state)); state.disc.version = CSS_VERSION; state.disc.flags = CSS_DAEMON|CSS_ERROR|CSS_INTERRUPT|CSS_LOG; state.disc.acceptf = acceptf; state.disc.actionf = actionf; state.disc.errorf = errorf; state.disc.exceptf = exceptf; for (;;) { switch (optget(argv, usage)) { case 'b': state.backlog = opt_info.num; continue; case 'd': error_info.trace = -opt_info.num; continue; case 't': state.disc.timeout = strelapsed(opt_info.arg, &e, 1); if (*e) error(3, "%s: invalid timeout value", opt_info.arg); state.disc.flags |= CSS_DORMANT; continue; case '?': error(ERROR_USAGE|4, "%s", opt_info.arg); continue; case ':': error(2, "%s", opt_info.arg); continue; } break; } argv += opt_info.index; if (!argv[0] || argv[1]) error(ERROR_USAGE|4, "%s", optusage(NiL)); if (!(state.tmp = sfstropen())) error(ERROR_SYSTEM|3, "out of space [tmp stream]"); if (!cssopen(argv[0], &state.disc)) return 1; umask(S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); csspoll(CS_NEVER, 0); return 1; }
static int svc_connect(void* handle, int fd, Cs_id_t* id, int clone, char** argv) { Proc_t* p; int n; long ops[4]; static char* args[] = { "sh", "-i", 0 }; NoP(handle); NoP(clone); waitpid(-1, NiL, WNOHANG); n = 0; ops[n++] = PROC_FD_DUP(fd, 0, 0); ops[n++] = PROC_FD_DUP(fd, 1, 0); ops[n++] = PROC_FD_DUP(fd, 2, PROC_FD_CHILD); ops[n] = 0; if (!(p = procopen(NiL, args, NiL, ops, 0))) return(-1); procfree(p); csfd(fd, CS_POLL_CLOSE); return(0); }
static int nomalloc(Vmalloc_t* region, int type, void* obj, Vmdisc_t* disc) { Vmstat_t st; NoP(disc); switch (type) { case VM_BADADDR: error(ERROR_SYSTEM|3, "invalid pointer %p passed to free or realloc", obj); return(-1); case VM_NOMEM: vmstat(region, &st); error(ERROR_SYSTEM|3, "storage allocator out of space on %lu byte request ( region %lu segments %lu busy %lu:%lu:%lu free %lu:%lu:%lu )", (size_t)obj, st.extent, st.n_seg, st.n_busy, st.s_busy, st.m_busy, st.n_free, st.s_free, st.m_free); return(-1); } return(0); }
int main(int argc, char** argv) { char* s; char* t; pid_t pid; ssize_t n; ssize_t (*dump)(pid_t, void*, const char*, char*, size_t) = uwin_stack_process; char* sep = "\n\t"; char buf[16*1024]; NoP(argc); error_info.id = "dumpstack"; for (;;) { switch (optget(argv, usage)) { case 's': sep = opt_info.arg; continue; case 't': dump = uwin_stack_thread; continue; case '?': error(ERROR_USAGE|4, "%s", opt_info.arg); break; case ':': error(2, "%s", opt_info.arg); break; } break; } argv += opt_info.index; if (error_info.errors || !(s = *argv++) || *argv) error(ERROR_USAGE|4, "%s", optusage(NiL)); if (!(pid = strtol(s, &t, 0)) || *t) error(3, "%s: pid argument expected", s); if ((n = (*dump)(pid, 0, sep, buf, sizeof(buf))) < 0) error(ERROR_SYSTEM|3, "%d: call stack dump failed", pid); if (write(1, buf, n) != n) error(ERROR_SYSTEM|3, "write to standard output failed"); return error_info.errors != 0; }