Pss_dev_t pssttydev(register Pss_t* pss, const char* name) { register const char* s; register Tty_t* tty; struct stat st; s = name; if (*s == '?' || *s == '-') return PSS_NODEV; if (pss->meth->ttydevf) return (*pss->meth->ttydevf)(pss, s); if (tty = (Tty_t*)dtmatch(pss->ttybyname, s)) return tty->dev; if (stat(s, &st)) { sfsprintf(pss->buf, sizeof(pss->buf), "/dev/%s", name); s = (const char*)pss->buf; if (stat(s, &st)) { sfsprintf(pss->buf, sizeof(pss->buf), "/dev/tty%s", name); if (stat(s, &st)) { if (pss->disc->errorf) (*pss->disc->errorf)(pss, pss->disc, ERROR_SYSTEM|2, "%s: unknown tty", name); } } } pssttyadd(pss, name, st.st_rdev); return st.st_rdev; }
static HANDLE init_module(const char* library) { HANDLE h; char* f; char buf[PATH_MAX]; static const char sys[] = "C:\\Windows\\System32"; f = "GetModuleHandle"; sfsprintf(buf, sizeof(buf), "%s\\%s.dll", sys, library); if (h = GetModuleHandle(buf)) goto found; f = "LoadLibrary"; sfsprintf(buf, sizeof(buf), "%s.dll", library); if (h = LoadLibrary(buf)) goto found; sfsprintf(buf, sizeof(buf), "%s\\%s.dll", sys, library); if (h = LoadLibrary(buf)) goto found; logmsg(LOGLEVEL(index), "library %s not found", library); return 0; found: logmsg(LOGLEVEL(index), "library %s bound to %s by %s", library, buf, f); return h; }
char* exlexname(int op, int subop) { register char* b; static int n; static char buf[TOTNAME][MAXNAME]; if (op > MINTOKEN && op < MAXTOKEN) return (char*)exop[op - MINTOKEN]; if (++n > TOTNAME) n = 0; b = buf[n]; if (op == '=') { if (subop > MINTOKEN && subop < MAXTOKEN) sfsprintf(b, MAXNAME, "%s=", exop[subop - MINTOKEN]); else if (subop > ' ' && subop <= '~') sfsprintf(b, MAXNAME, "%c=", subop); else sfsprintf(b, MAXNAME, "(%d)=", subop); } else if (op > ' ' && op <= '~') sfsprintf(b, MAXNAME, "%c", op); else sfsprintf(b, MAXNAME, "(%d)", op); return b; }
char* fmtsignal(register int sig) { char* buf; int z; if (sig >= 0) { if (sig <= sig_info.sigmax) buf = sig_info.text[sig]; else { buf = fmtbuf(z = 20); sfsprintf(buf, z, "Signal %d", sig); } } else { sig = -sig; if (sig <= sig_info.sigmax) buf = sig_info.name[sig]; else { buf = fmtbuf(z = 20); sfsprintf(buf, z, "%d", sig); } } return buf; }
int main(int argc, char** argv) { int status; pid_t pid; struct spawndata proc; char cmd[PATH_MAX]; char *name; int fd; if(name=strrchr(argv[0],'/')) name++; else name = argv[0]; error_info.id = name; memset(&proc, 0, sizeof(proc)); proc.flags |= UWIN_TRACE_CALL|UWIN_TRACE_TIME; if((fd=open("/etc/traceflags",O_RDONLY))>=0) { if((status=read(fd,cmd,4))>0) { while(--status>=0) { if(cmd[status]=='c') proc.flags |= UWIN_TRACE_COUNT; else if(cmd[status]=='v') proc.flags |= UWIN_TRACE_VERBOSE; else if(cmd[status]=='i') proc.flags |= UWIN_TRACE_INHERIT; } } close(fd); } else proc.flags |= UWIN_TRACE_VERBOSE|UWIN_TRACE_INHERIT|UWIN_TRACE_COUNT; sfsprintf(cmd,sizeof(cmd),LOGDIR "trace/%s.log",name); if ((proc.trace = open(cmd, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0) error(ERROR_SYSTEM|3, "%s: cannot write", opt_info.arg); fcntl(proc.trace, F_SETFD, FD_CLOEXEC); if (error_info.errors || !argv[0]) error(ERROR_USAGE|4, optusage(NiL)); sfsprintf(cmd,sizeof(cmd),LOGDIR "trace/%s",name); if(access(cmd,X_OK)!=0) error(ERROR_SYSTEM|ERROR_NOENT, "%s: not found", cmd); if (!(proc.flags & (UWIN_TRACE_COUNT|UWIN_TRACE_CALL))) proc.flags |= UWIN_TRACE_CALL; if ((pid = uwin_spawn(cmd, argv, NiL, &proc)) < 0) error(ERROR_SYSTEM|ERROR_NOEXEC, "%s: cannot run", cmd); while (waitpid(pid, &status, 0) == -1) if (errno != EINTR) exit(EXIT_NOEXEC); return(WEXITSTATUS(status)); }
tmain() { char buf[100]; Sfio_t *fp; int i; char *s; if(!(fp = sftmp(8))) terror("Can't open temp file"); sfset(fp,SF_LINE,1); for(i = 0; i < 1000; ++i) { sfsprintf(buf,sizeof(buf),"Number: %d",i); if(sfputr(fp,buf,'\n') <= 0) terror("Writing %s",buf); } sfseek(fp,(Sfoff_t)0,0); for(i = 0; i < 1000; ++i) { sfsprintf(buf,sizeof(buf),"Number: %d",i); if(!(s = sfgetr(fp,'\n',1))) terror("Reading %s",buf); if(strcmp(s,buf) != 0) terror("Input=%s, Expect=%s",s,buf); } sfseek(fp,(Sfoff_t)0,0); s = sfgetr(fp,'\0',1); if(s) terror("Expecting a null string"); s = sfgetr(fp,'\0',-1); if(!s) terror("Expecting a non-null string"); if(sfvalue(fp) != sfsize(fp)) terror("Wrong size"); sfclose(fp); if(!(fp = sfnew(0, buf, 12, 1, SF_WRITE)) ) terror("Opening a test stream"); sfsetbuf(fp, buf, 12); sfset(fp, SF_LINE, 0); sfdisc(fp, &Disc); if(sfputr(fp, "0123456789", '\n') != 11) terror("Sfputr failed1"); if(sfputr(fp, "0", -1) != 1) terror("Sfputr failed2"); if(sfputr(fp, "1", -1) != 1) terror("Sfputr failed3"); texit(0); }
char *fmtscale(Sfulong_t n, int k) { Sfulong_t m; int r; int z; const char *u; char suf[3]; char *s; char *buf; static const char scale[] = "bkMGTPE"; u = scale; if (n < 1000) { r = 0; } else { m = 0; while (n >= k && *(u + 1)) { m = n; n /= k; u++; } if ((r = (10 * (m % k) + (k / 2)) / k) > 9) { r = 0; n++; } if (k == 1024 && n >= 1000) { n = 1; r = 0; u++; } } buf = fmtbuf(z = 8); s = suf; if (u > scale) { if (k == 1024) { *s++ = *u == 'k' ? 'K' : *u; *s++ = 'i'; } else { *s++ = *u; } } *s = 0; if (n > 0 && n < 10) { char *decimal = nl_langinfo(RADIXCHAR); sfsprintf(buf, z, "%I*u%s%d%s", sizeof(n), n, decimal, r, suf); } else { if (r >= 5) n++; sfsprintf(buf, z, "%I*u%s", sizeof(n), n, suf); } return buf; }
char* fmtelapsed(register unsigned long u, register int n) { register unsigned long t; char* buf; int z; if (u == 0L) return "0"; if (u == ~0L) return "%"; buf = fmtbuf(z = 8); t = u / n; if (t < 60) sfsprintf(buf, z, "%lu.%02lus", t, (u * 100 / n) % 100); else if (t < 60*60) sfsprintf(buf, z, "%lum%02lus", t / 60, t - (t / 60) * 60); else if (t < 24*60*60) sfsprintf(buf, z, "%luh%02lum", t / (60*60), (t - (t / (60*60)) * (60*60)) / 60); else if (t < 7*24*60*60) sfsprintf(buf, z, "%lud%02luh", t / (24*60*60), (t - (t / (24*60*60)) * (24*60*60)) / (60*60)); else if (t < 31*24*60*60) sfsprintf(buf, z, "%luw%02lud", t / (7*24*60*60), (t - (t / (7*24*60*60)) * (7*24*60*60)) / (24*60*60)); else if (t < 365*24*60*60) sfsprintf(buf, z, "%luM%02lud", (t * 12) / (365*24*60*60), ((t * 12) - ((t * 12) / (365*24*60*60)) * (365*24*60*60)) / (12*24*60*60)); else if (t < (365UL*4UL+1UL)*24UL*60UL*60UL) sfsprintf(buf, z, "%luY%02luM", t / (365*24*60*60), ((t - (t / (365*24*60*60)) * (365*24*60*60)) * 5) / (152 * 24 * 60 * 60)); else sfsprintf(buf, z, "%luY%02luM", (t * 4) / ((365UL*4UL+1UL)*24UL*60UL*60UL), (((t * 4) - ((t * 4) / ((365UL*4UL+1UL)*24UL*60UL*60UL)) * ((365UL*4UL+1UL)*24UL*60UL*60UL)) * 5) / ((4 * 152 + 1) * 24 * 60 * 60)); return buf; }
char* pathfind(const char* name, const char* lib, const char* type, char* buf, size_t size) { register Dir_t* dp; register char* s; char tmp[PATH_MAX]; if (access(name, R_OK) >= 0) return strncpy(buf, name, size); if (type) { sfsprintf(buf, size, "%s.%s", name, type); if (access(buf, R_OK) >= 0) return buf; } if (*name != '/') { if (strchr(name, '.')) type = 0; for (dp = state.head; dp; dp = dp->next) { sfsprintf(tmp, sizeof(tmp), "%s/%s", dp->dir, name); if (pathpath(buf, tmp, "", PATH_REGULAR)) return buf; if (type) { sfsprintf(tmp, sizeof(tmp), "%s/%s.%s", dp->dir, name, type); if (pathpath(buf, tmp, "", PATH_REGULAR)) return buf; } } if (lib) { if ((s = strrchr((char*)lib, ':'))) lib = (const char*)s + 1; sfsprintf(tmp, sizeof(tmp), "lib/%s/%s", lib, name); if (pathpath(buf, tmp, "", PATH_REGULAR)) return buf; if (type) { sfsprintf(tmp, sizeof(tmp), "lib/%s/%s.%s", lib, name, type); if (pathpath(buf, tmp, "", PATH_REGULAR)) return buf; } } } return 0; }
static void setwakeup(void) { register Seconds_t t; register Seconds_t now; int level; now = CURSECS; if (!trap.alarms) t = 0; else if (trap.alarms->time <= now) t = 1; else t = trap.alarms->time - now; alarm(t); sfsprintf(tmpname, MAXNAME, "%lu", t ? (now + t) : t); setvar(internal.alarm->name, fmtelapsed(t, 1), 0); if (error_info.trace <= (level = (state.test & 0x00010000) ? 2 : CMDTRACE)) { register Alarms_t* a; if (a = trap.alarms) { error(level, "ALARM TIME RULE"); do { error(level, "%6s %s %s", fmtelapsed((a->time >= now) ? (a->time - now) : 0, 1), timestr(tmxsns(a->time, 0)), a->rule->name); } while (a = a->next); } else error(level, "ALARM -- NONE"); } }
HANDLE pdev_lock(Pdev_t *pdev, int code) { HANDLE hp; SECURITY_ATTRIBUTES sattr; char mutexName[50]; sattr.nLength = sizeof(sattr); sattr.lpSecurityDescriptor = nulldacl(); sattr.bInheritHandle = FALSE; sfsprintf(mutexName,50,"uwin_pdev#%x", block_slot(pdev)); if( (hp = CreateMutex(&sattr,FALSE,mutexName)) == NULL) logerr(0, "failed to get mutex -- name=[%s] code=[0x%x]", mutexName, code); else { int r; SetLastError(0); if((r=WaitForSingleObject(hp,5000))!=WAIT_OBJECT_0) { logmsg(0, "WaitForSingleObject failed in mutexlock pdev slot=0x%x code=0x%x", block_slot(pdev), code); CloseHandle(hp); hp=0; } } return(hp); }
static void getFileNames (char *dir, char **fileNames, int phyRecSize) { DIR *dirp; struct dirent *entp; int i = 0; int extraLen = strlen(dir) + 1 + 1; if (!(dirp = opendir(dir))) HRSerrorExit1("Could not find the directory %s\n", dir); while (entp = readdir(dirp)) { if ((strcmp(".", entp->d_name) != 0) && (strcmp("..", entp->d_name) != 0)) { int strsize = strlen(entp->d_name) + extraLen; fileNames[i] = (char *) HRSmalloc(strsize, "getFileNames"); sfsprintf(fileNames[i], strsize, "%s/%s", dir, entp->d_name); checkStreamFile(fileNames[i], phyRecSize); i++; } } closedir(dirp); }
extern int dllcheck(void* dll, const char* path, unsigned long ver, unsigned long* cur) { unsigned long v; state.error = 0; if (ver || cur) { v = dllversion(dll, path); if (cur) *cur = v; } if (!ver) return 1; if (!v) return 0; if (v < ver) { if (path) { state.error = 1; sfsprintf(state.errorbuf, sizeof(state.errorbuf), "plugin version %lu older than caller %lu", v, ver); errorf("dll", NiL, 1, "dllcheck: %s: %s", path, state.errorbuf); } return 0; } errorf("dll", NiL, -1, "dllversion: %s: %lu >= %lu", path, v, ver); return 1; }
static int deleteservice(char *account) { SC_HANDLE service, scm; int ret=1, i; char username[80]; strcpy(username, account); parse_username(username); sfsprintf(servname, sizeof(servname),"UWIN_CS%s", username); sfsprintf(servdname, sizeof(servdname),"UWIN Client(%s)", username); for(i=0;i<(signed)strlen(servname);i++) if(servname[i] == '/') servname[i]= '#'; scm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); if (scm) { service = OpenService(scm, servname, SERVICE_ALL_ACCESS); if (service) { if(DeleteService(service)) logmsg(1, "%s deleted", servdname); else { logerr(LOG_STDERR+0, "delete %s failed", servdname); ret = 0; } } else { logerr(LOG_STDERR+0, "%s service open failed", servdname); ret = 0; } CloseServiceHandle(scm); } else { logerr(LOG_STDERR+0, "OpenSCManager failed"); return(0); } return(ret); }
MAIN() { Sfio_t* f; char buf[1024], *s; int n; #ifdef DEBUG Sfio_t* logf = sfopen(0,"LOG","a"); sfsetbuf(logf,NIL(Void_t*),0); #endif alarm(10); if(argc > 1) { /* coprocess only */ while((s = sfreserve(sfstdin,-1,0)) ) { #ifdef DEBUG sfwrite(logf, s, sfvalue(sfstdin)); #endif sfwrite(sfstdout, s, sfvalue(sfstdin)); } return 0; } /* make coprocess */ if(!(f = sfpopen(NIL(Sfio_t*), sfprints("%s -p",argv[0]), "r+"))) terror("Opening for read/write\n"); for(n = 0; n < 10; ++n) { sfsprintf(buf,sizeof(buf),"Line %d",n); sfputr(f,buf,'\n'); if(!(s = sfgetr(f,'\n',1))) terror("Did not read back line\n"); if(strcmp(s,buf) != 0) terror("Input=%s, Expect=%s\n",s,buf); } if(sfputr(f,"123456789",'\n') != 10) terror("Bad write"); if(sfread(f,buf,3) != 3) terror("Did not get data back\n"); if(strncmp(s,"123",3) != 0) terror("Wrong data\n"); if(sfwrite(f,"aaa",3) != 3 || sfputc(f,'\n') != '\n') terror("Fail on write\n"); if(!(s = sfgetr(f,'\n',1)) ) terror("Should have gotten 456789\n"); if(strcmp(s,"456789") != 0) terror("Wrong data2\n"); if(!(s = sfgetr(f,'\n',1)) ) terror("Should have gotten aaa\n"); if(strcmp(s,"aaa") != 0) terror("Wrong data3\n"); sfclose(f); TSTEXIT(0); }
void getservname(void) { DWORD ret,i; HANDLE tok; char tmpbuf[1024], UserName[256], RefDomain[256]; PTOKEN_USER UserToken = (PTOKEN_USER)tmpbuf; DWORD RetLen=1024, UserNameLen, RefDomainLen; SID_NAME_USE SidType; if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &tok)) { if ((ret = GetTokenInformation(tok, TokenUser, UserToken, RetLen, &RetLen))) { UserNameLen = sizeof(UserName); RefDomainLen = sizeof(RefDomain); if ((ret = LookupAccountSid(NULL,UserToken->User.Sid,UserName,&UserNameLen,RefDomain,&RefDomainLen,&SidType))) { strcat(RefDomain,"/"); strcat(RefDomain,UserName); parse_username(RefDomain); sfsprintf(servname, sizeof(servname),"UWIN_CS%s", RefDomain); sfsprintf(servdname, sizeof(servdname),"UWIN Client(%s)", RefDomain); strcpy(evename,RefDomain); strcat(evename,"event"); for(i=0;i<strlen(servname);i++) if(servname[i] == '/') servname[i]= '#'; { unsigned char *ptr; for(ptr=(unsigned char *)evename; *ptr ; ptr++) *ptr=tolower(*ptr); } } else logerr(1, "LookupAccountSid failed in getservname"); } else logerr(1, "GetTokenInformation failed in getservname"); } else logerr(1, "OpenProcessToken failed in getservname"); }
void sh_regress(unsigned int index, const char* intercept, const char* info, unsigned int line, const char* file) { char* name; char buf[16]; if (index >= 1 && index <= elementsof(regress_options)) name = (char*)regress_options[index]; else sfsprintf(name = buf, sizeof(buf), "%u", index); sfprintf(sfstderr, REGRESS_HEADER "%s:%s:%s\n", name, intercept, fmtesc(info)); }
static char* number(register char* s, register char* e, register long n, register int p, int w, int pad) { char* b; if (w) { if (p > 0 && (pad == 0 || pad == '0')) while (w > p) { p++; n *= 10; } else if (w > p) p = w; } switch (pad) { case '-': p = 0; break; case '_': if (p > 0) p = -p; break; case '0': if (p < 0) p = -p; break; } b = s; if (p > 0) s += sfsprintf(s, e - s, "%0*lu", p, n); else if (p < 0) s += sfsprintf(s, e - s, "%*lu", -p, n); else s += sfsprintf(s, e - s, "%lu", n); if (w && (s - b) > w) *(s = b + w) = 0; return s; }
static int cokillshell(register Coshell_t* co, register Cojob_t* cj, int sig) { int n; if (sig && (co->flags & CO_SERVER)) { char buf[CO_BUFSIZ]; n = sfsprintf(buf, sizeof(buf), "#%05d\nk %d %d\n", 0, cj ? cj->id : 0, sig); sfsprintf(buf, 7, "#%05d\n", n - 7); return write(co->cmdfd, buf, n) == n ? 0 : -1; } if (cj) return cokilljob(co, cj, sig); n = 0; for (cj = co->jobs; cj; cj = cj->next) if (cj->pid > 0) n |= cokilljob(co, cj, sig); return n; }
static char* get_enum(register Namval_t* np, Namfun_t *fp) { static char buff[6]; struct Enum *ep = (struct Enum*)fp; long n = nv_getn(np,fp); if(nv_isattr(np,NV_NOTSET)==NV_NOTSET) return(""); if(n < ep->nelem) return((char*)ep->values[n]); sfsprintf(buff,sizeof(buff),"%u%c",n,0); return(buff); }
static_fn char *get_enum(Namval_t *np, Namfun_t *fp) { if (nv_isattr(np, NV_NOTSET) == NV_NOTSET) return ""; struct Enum *ep = (struct Enum *)fp; long n = nv_getn(np, fp); assert(n >= 0); if (n < ep->nelem) return (char *)ep->values[n]; static char buff[6]; sfsprintf(buff, sizeof(buff), "%u%c", n, 0); return buff; }
static void error(int level, char* fmt, ...) { DWORD err = GetLastError(); char* cur; char* end; char* s; int n; char buf[512]; va_list ap; va_start(ap, fmt); cur = buf; end = cur + sizeof(buf) - 1; cur += sfvsprintf(cur, end - cur, fmt, ap); va_end(ap); logerr(LOG_SYSTEM+level, "%s", buf); if (!quiet) { if ((level & LOG_SYSTEM) && err && (int)(end - cur) > 32) { cur += sfsprintf(cur, end - cur, "\r\n[%lu:", err); if (!(n = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, 0, err, 0, cur, (int)(end - cur), 0))) n = sfsprintf(cur, end - cur, "Unknown error code %d.\n", err); if (n >= (int)(end - cur)) cur[n-1] = 0; if (s = strchr(cur, '\n')) n = (int)(s - cur); cur += n; if (*(cur-1) == '\r') cur--; if (*(cur-1) == '.') cur--; if (cur < end) *cur++ = ']'; } *cur = 0; MessageBox(0, buf, "UWIN Setuid Service", 0x00200000L|0x00040000L|MB_OK|MB_ICONSTOP); } }
int csping(register Cs_t* state, const char* name) { register int fd; register int n; sfsprintf(state->temp, sizeof(state->path), "/dev/tcp/%s/inet.echo", name); if ((fd = csopen(state, state->temp, 0)) < 0) return -1; n = (cswrite(state, fd, M, N) != N || csread(state, fd, state->temp, N, CS_LINE) != N || strncmp(M, state->temp, N)) ? -1 : 0; close(fd); if (n) messagef((state->id, NiL, -1, "ping: %s: no contact", name)); return n; }
MAIN() { char buf[100]; Sfio_t *fp; int i; char *s; if(!(fp = sftmp(8))) terror("Can't open temp file\n"); sfset(fp,SF_LINE,1); for(i = 0; i < 1000; ++i) { sfsprintf(buf,sizeof(buf),"Number: %d",i); if(sfputr(fp,buf,'\n') <= 0) terror("Writing %s\n",buf); } sfseek(fp,(Sfoff_t)0,0); for(i = 0; i < 1000; ++i) { sfsprintf(buf,sizeof(buf),"Number: %d",i); if(!(s = sfgetr(fp,'\n',1))) terror("Reading %s\n",buf); if(strcmp(s,buf) != 0) terror("Input=%s, Expect=%s\n",s,buf); } sfseek(fp,(Sfoff_t)0,0); s = sfgetr(fp,'\0',1); if(s) terror("Expecting a null string\n"); s = sfgetr(fp,'\0',-1); if(!s) terror("Expecting a non-null string\n"); if(sfvalue(fp) != sfsize(fp)) terror("Wrong size\n"); TSTEXIT(0); }
static int expr_cond(State_t* state, Node_t *np) { register int tok = getnode(state, np); while (tok==':') { regex_t re; regmatch_t match[2]; int n; Node_t rp; char *cp; tok = getnode(state, &rp); if (np->type&T_STR) cp = np->str; else sfsprintf(cp=state->buf,sizeof(state->buf),"%d",np->num); np->num = 0; np->type = T_NUM; if (n = regcomp(&re, rp.str, REG_LEFT|REG_LENIENT)) regfatal(&re, ERROR_exit(2), n); if (!(n = regexec(&re, cp, elementsof(match), match, 0))) { if (re.re_nsub > 0) { np->type = T_STR; if (match[1].rm_so >= 0) { np->str = cp + match[1].rm_so; np->str[match[1].rm_eo - match[1].rm_so] = 0; np->num = strtol(np->str,&cp,10); if (cp!=np->str && *cp==0) np->type |= T_NUM; } else np->str = ""; } else np->num = match[0].rm_eo - match[0].rm_so; } else if (n != REG_NOMATCH) regfatal(&re, ERROR_exit(2), n); else if (re.re_nsub) { np->str = ""; np->type = T_STR; } regfree(&re); } return tok; }
char *tmpoff(char *s, size_t z, const char *p, int n, int d) { char *e = s + z; while (s < e && (*s = *p++)) s++; if (n != d && s < e) { if (n < 0) { n = -n; *s++ = '+'; } else { *s++ = '-'; } s += sfsprintf(s, e - s, "%02d%s%02d", n / 60, d == -24 * 60 ? ":" : "", n % 60); } return s; }
extern unsigned long dllversion(void* dll, const char* path) { Dll_plugin_version_f pvf; if (pvf = (Dll_plugin_version_f)dlllook(dll, "plugin_version")) return (*pvf)(); if (path) { state.error = 1; sfsprintf(state.errorbuf, sizeof(state.errorbuf), "plugin_version() not found"); errorf("dll", NiL, 1, "dllversion: %s: %s", path, state.errorbuf); } return 0; }
void systrace(const char* id) { register int n; register char* out; char* s; char buf[PATH_MAX]; char* av[7]; long ov[2]; static char* trace[] = { "trace", "truss", "strace", "traces" }; if (!(s = getenv("HOME"))) return; if (!id && !(id = (const char*)error_info.id)) id = (const char*)trace[0]; out = buf; out += sfsprintf(out, sizeof(buf), "%s/.%s/%s", s, trace[0], id); if (access(buf, F_OK)) return; av[1] = trace[0]; av[2] = "-o"; av[3] = buf; av[4] = "-p"; av[5] = out + 1; av[6] = 0; ov[0] = PROC_FD_DUP(open("/dev/null", O_WRONLY), 2, PROC_FD_PARENT|PROC_FD_CHILD); ov[1] = 0; sfsprintf(out, &buf[sizeof(buf)] - out, ".%d", getpid()); for (n = 0; n < elementsof(trace); n++) if (!procfree(procopen(trace[n], av + 1, NiL, ov, PROC_ARGMOD|PROC_GID|PROC_UID|(n == (elementsof(trace) - 1) ? PROC_CLEANUP : 0)))) { sleep(1); break; } }
static void eventlog(char *msg) { HANDLE h; char* sa[2]; char errmsg[256]; if (h = RegisterEventSource(NULL, servname)) { sfsprintf(errmsg, sizeof(errmsg), "%s error: %d", servname, GetLastError()); sa[0] = errmsg; sa[1] = msg; ReportEvent(h, EVENTLOG_ERROR_TYPE, 0, 0, NULL, 2, 0, sa, NULL); DeregisterEventSource(h); } }
static int acctinit(History_t *hp) { register char *cp, *acctfile; Namval_t *np = nv_search("ACCTFILE",((Shell_t*)hp->histshell)->var_tree,0); if(!np || !(acctfile=nv_getval(np))) return(0); if(!(cp = getlogin())) { struct passwd *userinfo = getpwuid(getuid()); if(userinfo) cp = userinfo->pw_name; else cp = "unknown"; } logname = strdup(cp); if((acctfd=sh_open(acctfile, O_BINARY|O_WRONLY|O_APPEND|O_CREAT,S_IRUSR|S_IWUSR))>=0 && (unsigned)acctfd < 10) { int n; if((n = fcntl(acctfd, F_DUPFD, 10)) >= 0) { close(acctfd); acctfd = n; } } if(acctfd < 0) { acctfd = 0; return(0); } if(sh_isdevfd(acctfile)) { char newfile[16]; sfsprintf(newfile,sizeof(newfile),"%.8s%d\0",e_devfdNN,acctfd); nv_putval(np,newfile,NV_RDONLY); } else fcntl(acctfd,F_SETFD,FD_CLOEXEC); return(1); }