int ifc_set_mask(const char *name, in_addr_t mask) { struct ifreq ifr; int ret; ifc_init_ifr(name, &ifr); init_sockaddr_in(&ifr.ifr_addr, mask); ret = ioctl(ifc_ctl_sock, SIOCSIFNETMASK, &ifr); if (DBG) printerr("ifc_set_mask(%s, xx) = %d", name, ret); return ret; }
/* perform create command */ static int proccreate(const char *path, int width, int64_t limsiz) { TCFDB *fdb = tcfdbnew(); if (!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd); if (!tcfdbtune(fdb, width, limsiz)) { printerr(fdb); tcfdbdel(fdb); return 1; } if (!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | FDBOTRUNC)) { printerr(fdb); tcfdbdel(fdb); return 1; } bool err = false; if (!tcfdbclose(fdb)) { printerr(fdb); err = true; } tcfdbdel(fdb); return err ? 1 : 0; }
/* perform out command */ static int procout(const char *path, const char *pkbuf, int pksiz, int omode){ TCTDB *tdb = tctdbnew(); if(g_dbgfd != INVALID_HANDLE_VALUE) tctdbsetdbgfd(tdb, g_dbgfd); if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb); if(!tctdbopen(tdb, path, TDBOWRITER | omode)){ printerr(tdb); tctdbdel(tdb); return 1; } bool err = false; if(!tctdbout(tdb, pkbuf, pksiz)){ printerr(tdb); err = true; } if(!tctdbclose(tdb)){ if(!err) printerr(tdb); err = true; } tctdbdel(tdb); return err ? 1 : 0; }
void lgssd_mutex_get(int semid) { struct sembuf op[1] = { {0, -1, SEM_UNDO} }; int rc; rc = semop(semid, op, 1); if (rc != 0) { printerr(0, "exit on mutex_get err %d: %s\n", rc, strerror(errno)); exit(1); } }
static int lgssd_create_mutex(int *semid) { int id; int arg; id = semget(IPC_PRIVATE, 1, IPC_CREAT); if (id == -1) { printerr(0, "semget: %s\n", strerror(errno)); return -1; } arg = 1; if (semctl(id, 0, SETVAL, arg) != 0) { printerr(0, "semctl: %s\n", strerror(errno)); semctl(id, 1, IPC_RMID, arg); return -1; } *semid = id; return 0; }
/* perform out command */ static int procout(const char *path, const char *kbuf, int ksiz, int omode){ TCHDB *hdb = tchdbnew(); if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd); if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(hdb); if(!tchdbopen(hdb, path, HDBOWRITER | omode)){ printerr(hdb); tchdbdel(hdb); return 1; } bool err = false; if(!tchdbout(hdb, kbuf, ksiz)){ printerr(hdb); err = true; } if(!tchdbclose(hdb)){ if(!err) printerr(hdb); err = true; } tchdbdel(hdb); return err ? 1 : 0; }
int ifc_set_addr(const char *name, in_addr_t addr) { struct ifreq ifr; int ret; ifc_init_ifr(name, &ifr); init_sockaddr_in(&ifr.ifr_addr, addr); ret = ioctl(ifc_ctl_sock, SIOCSIFADDR, &ifr); if (DBG) printerr("ifc_set_addr(%s, xx) = %d", name, ret); return ret; }
/* perform optimize command */ static int procoptimize(const char *path, int lmemb, int nmemb, int bnum, int apow, int fpow, TCCMP cmp, int opts, int omode, bool df) { TCBDB *bdb = tcbdbnew(); if (!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd); if (cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)) printerr(bdb); if (!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(bdb); if (!tcbdbopen(bdb, path, BDBOWRITER | omode)) { printerr(bdb); tcbdbdel(bdb); return 1; } bool err = false; if (df) { if (!tcbdbdefrag(bdb, INT64_MAX)) { printerr(bdb); err = true; } } else { if (!tcbdboptimize(bdb, lmemb, nmemb, bnum, apow, fpow, opts)) { printerr(bdb); err = true; } } if (!tcbdbclose(bdb)) { if (!err) printerr(bdb); err = true; } tcbdbdel(bdb); return err ? 1 : 0; }
/* perform put command */ static int procput(const char *path, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int omode, int dmode){ TCHDB *hdb = tchdbnew(); if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd); if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(hdb); if(!tchdbopen(hdb, path, HDBOWRITER | omode)){ printerr(hdb); tchdbdel(hdb); return 1; } bool err = false; switch(dmode){ case -1: if(!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz)){ printerr(hdb); err = true; } break; case 1: if(!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)){ printerr(hdb); err = true; } break; case 10: if(tchdbaddint(hdb, kbuf, ksiz, tcatoi(vbuf)) == INT_MIN){ printerr(hdb); err = true; } break; case 11: if(isnan(tchdbadddouble(hdb, kbuf, ksiz, tcatof(vbuf)))){ printerr(hdb); err = true; } break; default: if(!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)){ printerr(hdb); err = true; } break; } if(!tchdbclose(hdb)){ if(!err) printerr(hdb); err = true; } tchdbdel(hdb); return err ? 1 : 0; }
int dentfill(char *path, struct entry **dents, int (*filter)(regex_t *, char *), regex_t *re) { DIR *dirp; struct dirent *dp; struct stat sb; char *newpath; int r, n = 0; dirp = opendir(path); if (dirp == NULL) return 0; while ((dp = readdir(dirp)) != NULL) { /* Skip self and parent */ if (strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0) continue; if (filter(re, dp->d_name) == 0) continue; *dents = xrealloc(*dents, (n + 1) * sizeof(**dents)); (*dents)[n].name = xstrdup(dp->d_name); /* Get mode flags */ newpath = mkpath(path, dp->d_name); r = lstat(newpath, &sb); if (r == -1) printerr(1, "lstat"); (*dents)[n].mode = sb.st_mode; (*dents)[n].t = sb.st_mtime; n++; } /* Should never be null */ r = closedir(dirp); if (r == -1) printerr(1, "closedir"); return n; }
int free_symlink_tree(void) { int i; char tmppath[PATH_MAX]; /* Remove the symlinks from the test tree */ for (i = num_tree_symlinks - 1; i > -1; i--) { snprintf(tmppath, PATH_MAX, "%s/%s", tree_origin, tree_symlinks[i].orig); if (unlink(tmppath) != 0) { snprintf(errmsg, ERRSIZE, "unlink %s", tmppath); printerr(errmsg); goto error; } } /* Remove the directories from the test tree */ for (i = num_tree_dirs - 1; i > -1; i--) { snprintf(tmppath, PATH_MAX, "%s/%s", tree_origin, tree_dirs[i]); if (rmdir(tmppath) != 0) { snprintf(errmsg, ERRSIZE, "rmdir %s", tmppath); printerr(errmsg); goto error; } } /* Remove the temporary directory */ if (rmdir(tree_origin) != 0) { snprintf(errmsg, ERRSIZE, "rmdir %s", tree_origin); printerr(errmsg); goto error; } return 0; error: return 1; }
int prepare_symlink_tree(void) { int i; char tmppath[PATH_MAX]; /* Create the temporary directory */ if (mkdtemp(tree_origin) == NULL) { printerr("mkdtemp"); goto error; } /* Create the directories of the test tree */ for (i = 0; i < num_tree_dirs; i++) { snprintf(tmppath, PATH_MAX, "%s/%s", tree_origin, tree_dirs[i]); if (mkdir(tmppath, 0755) != 0) { snprintf(errmsg, ERRSIZE, "mkdir %s", tmppath); printerr(errmsg); goto error; } } /* Create the symlinks of the test tree */ for (i = 0; i < num_tree_symlinks; i++) { snprintf(tmppath, PATH_MAX, "%s/%s", tree_origin, tree_symlinks[i].orig); if (symlink(tree_symlinks[i].dest, tmppath) != 0) { snprintf(errmsg, ERRSIZE, "symlink %s to %s", tmppath, tree_symlinks[i].dest); printerr(errmsg); goto error; } } return 0; error: return 1; }
/* perform out command */ static int procout(const char *path, const char *kbuf, int ksiz, TCCMP cmp, int omode) { TCBDB *bdb = tcbdbnew(); if (!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd); if (cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)) printerr(bdb); if (!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(bdb); if (!tcbdbopen(bdb, path, BDBOWRITER | omode)) { printerr(bdb); tcbdbdel(bdb); return 1; } bool err = false; if (!tcbdbout(bdb, kbuf, ksiz)) { printerr(bdb); err = true; } if (!tcbdbclose(bdb)) { if (!err) printerr(bdb); err = true; } tcbdbdel(bdb); return err ? 1 : 0; }
/* perform create command */ static int proccreate(const char *path, int bnum, int apow, int fpow, int opts){ TCTDB *tdb = tctdbnew(); if(g_dbgfd != INVALID_HANDLE_VALUE) tctdbsetdbgfd(tdb, g_dbgfd); if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb); if(!tctdbtune(tdb, bnum, apow, fpow, opts)){ printerr(tdb); tctdbdel(tdb); return 1; } if(!tctdbopen(tdb, path, TDBOWRITER | TDBOCREAT | TDBOTRUNC)){ printerr(tdb); tctdbdel(tdb); return 1; } bool err = false; if(!tctdbclose(tdb)){ printerr(tdb); err = true; } tctdbdel(tdb); return err ? 1 : 0; }
static int do_error_downcall(int k5_fd, uid_t uid, int err) { char buf[1024]; char *p = buf, *end = buf + 1024; unsigned int timeout = 0; int zero = 0; printerr(2, "doing error downcall\n"); if (WRITE_BYTES(&p, end, uid)) goto out_err; if (WRITE_BYTES(&p, end, timeout)) goto out_err; /* use seq_win = 0 to indicate an error: */ if (WRITE_BYTES(&p, end, zero)) goto out_err; if (WRITE_BYTES(&p, end, err)) goto out_err; if (write(k5_fd, buf, p - buf) < p - buf) goto out_err; return 0; out_err: printerr(1, "Failed to write error downcall!\n"); return -1; }
static void do_downcall(int k5_fd, uid_t uid, struct authgss_private_data *pd, gss_buffer_desc *context_token, OM_uint32 lifetime_rec, gss_buffer_desc *acceptor) { char *buf = NULL, *p = NULL, *end = NULL; unsigned int timeout = context_timeout; unsigned int buf_size = 0; printerr(2, "doing downcall: lifetime_rec=%u acceptor=%.*s\n", lifetime_rec, acceptor->length, acceptor->value); buf_size = sizeof(uid) + sizeof(timeout) + sizeof(pd->pd_seq_win) + sizeof(pd->pd_ctx_hndl.length) + pd->pd_ctx_hndl.length + sizeof(context_token->length) + context_token->length + sizeof(acceptor->length) + acceptor->length; p = buf = malloc(buf_size); if (!buf) goto out_err; end = buf + buf_size; /* context_timeout set by -t option overrides context lifetime */ if (timeout == 0) timeout = lifetime_rec; if (WRITE_BYTES(&p, end, uid)) goto out_err; if (WRITE_BYTES(&p, end, timeout)) goto out_err; if (WRITE_BYTES(&p, end, pd->pd_seq_win)) goto out_err; if (write_buffer(&p, end, &pd->pd_ctx_hndl)) goto out_err; if (write_buffer(&p, end, context_token)) goto out_err; if (write_buffer(&p, end, acceptor)) goto out_err; if (write(k5_fd, buf, p - buf) < p - buf) goto out_err; free(buf); return; out_err: free(buf); printerr(1, "Failed to write downcall!\n"); return; }
/* perform create command */ static int proccreate(const char *path, int bnum, int apow, int fpow, int opts){ TCHDB *hdb = tchdbnew(); if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd); if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(hdb); if(!tchdbtune(hdb, bnum, apow, fpow, opts)){ printerr(hdb); tchdbdel(hdb); return 1; } if(!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | HDBOTRUNC)){ printerr(hdb); tchdbdel(hdb); return 1; } bool err = false; if(!tchdbclose(hdb)){ printerr(hdb); err = true; } tchdbdel(hdb); return err ? 1 : 0; }
static void display_status_1(char *m, u_int32_t code, int type, const gss_OID mech) { u_int32_t maj_stat, min_stat; gss_buffer_desc msg = GSS_C_EMPTY_BUFFER; u_int32_t msg_ctx = 0; char *typestr; switch (type) { case GSS_C_GSS_CODE: typestr = "GSS"; break; case GSS_C_MECH_CODE: typestr = "mechanism"; break; default: return; /* NOTREACHED */ } for (;;) { maj_stat = gss_display_status(&min_stat, code, type, mech, &msg_ctx, &msg); if (maj_stat != GSS_S_COMPLETE) { printerr(0, "ERROR: in call to " "gss_display_status called from %s\n", m); break; } else { printerr(0, "ERROR: GSS-API: (%s) error in %s(): %s\n", typestr, m, (char *)msg.value); } if (msg.length != 0) (void) gss_release_buffer(&min_stat, &msg); if (msg_ctx == 0) break; } }
static void trace_dup(int oldfd, int newfd) { debug("trace_dup %d %d", oldfd, newfd); if (oldfd == newfd) { printerr("trace_dup: duplicating the same fd %d\n", oldfd); return; } Descriptor *o = get_descriptor(oldfd); if (o == NULL) { return; } /* Not a descriptor we are tracing */ if (o->path == NULL) { return; } /* Just in case newfd is already open */ trace_close(newfd); char *temp = strdup(o->path); if (temp == NULL) { printerr("strdup: %s\n", strerror(errno)); return; } /* Copy the old descriptor into the new */ Descriptor *n = get_descriptor(newfd); n->type = o->type; n->path = temp; n->bread = 0; n->bwrite = 0; n->nread = 0; n->nwrite = 0; n->bseek = 0; n->nseek = 0; }
static void trace_file(const char *path, int fd) { debug("trace_file %s %d", path, fd); Descriptor *f = get_descriptor(fd); if (f == NULL) { return; } if (!should_trace(path)) { return; } struct stat s; if (fstat(fd, &s) != 0) { printerr("fstat: %s\n", strerror(errno)); return; } /* Skip directories */ if (s.st_mode & S_IFDIR) { return; } char *temp = strdup(path); if (temp == NULL) { printerr("strdup: %s\n", strerror(errno)); return; } f->type = DTYPE_FILE; f->path = temp; f->bread = 0; f->bwrite = 0; f->nread = 0; f->nwrite = 0; f->bseek = 0; f->nseek = 0; }
void* initMachine(void) { /* purpose: initialize the data structure. * returns: initialized MachineLinuxInfo structure. */ unsigned long version; MachineLinuxInfo* p = (MachineLinuxInfo*) calloc(1, sizeof(MachineLinuxInfo)); if (p == NULL) { printerr("calloc: %s\n", strerror(errno)); return NULL; } /* name of this provider -- overwritten by importers */ p->basic = initBasicMachine(); p->basic->provider = "linux"; gather_meminfo(&p->ram_total, &p->ram_free, &p->ram_shared, &p->ram_buffer, &p->swap_total, &p->swap_free); gather_loadavg(p->load); gather_proc_cpuinfo(p); gather_proc_uptime(&p->boottime, &p->idletime); version = extract_version(p->basic->uname.release); /* This used to have an upper limit of 3.2 from PM-571, but it was * removed because the Linux kernel is changing version numbers too * fast to keep updating it. */ if (version >= 2006000) { gather_linux_proc26(&p->procs, &p->tasks); } else if (version >= 2004000 && version <= 2004999) { gather_linux_proc24(&p->procs, &p->tasks); } else { printerr("Info: Kernel v%lu.%lu.%lu is not supported for proc stats gathering\n", version / 1000000, (version % 1000000) / 1000, version % 1000); } return p; }
static void trace_openat(int fd) { debug("trace_openat %d", fd); char linkpath[64]; snprintf(linkpath, 64, "/proc/%d/fd/%d", getpid(), fd); char fullpath[BUFSIZ]; int len = readlink(linkpath, fullpath, BUFSIZ); if (len <= 0) { printerr("Unable to get real path for fd %d: %s\n", fd, strerror(errno)); return; } if (len == BUFSIZ) { printerr("Path too long for fd %d: %s\n", fd, strerror(errno)); return; } /* readlink doesn't add a null byte */ fullpath[len] = '\0'; trace_file(fullpath, fd); }
static void trace_truncate(const char *path, off_t length) { debug("trace_truncate %s %lu", path, length); char *fullpath = realpath(path, NULL); if (fullpath == NULL) { printerr("Unable to get real path for '%s': %s\n", path, strerror(errno)); return; } tprintf("file: '%s' %lu 0 0 0 0\n", fullpath, length); free(fullpath); }
void cart_reinit (void) { // Re/Initialize all global library settings. check_endianness(); if (!cartio.setup) { printerr("Internal error, cart input/output functions not initialized.\n"); exit(1); } cartio.linker_reinit(); }
// Write HID report static int d16_write_rep(USBDEVHANDLE dev, int reportnum, char buffer[8+1]) { int err; int len = 8 + 1; /* report id 1 byte + 8 bytes data */ buffer[0] = (char)reportnum; err = usbhidSetReport(dev, buffer, len); if ( err ) { printerr("error writing hid report: %s\n", usbErrorMessage(err)); return -1; } return err; }
int gssd_check_mechs(void) { u_int32_t maj_stat, min_stat; gss_OID_set supported_mechs = GSS_C_NO_OID_SET; int retval = -1; maj_stat = gss_indicate_mechs(&min_stat, &supported_mechs); if (maj_stat != GSS_S_COMPLETE) { printerr(0, "Unable to obtain list of supported mechanisms. " "Check that gss library is properly configured.\n"); goto out; } if (supported_mechs == GSS_C_NO_OID_SET || supported_mechs->count == 0) { printerr(0, "Unable to obtain list of supported mechanisms. " "Check that gss library is properly configured.\n"); goto out; } maj_stat = gss_release_oid_set(&min_stat, &supported_mechs); retval = 0; out: return retval; }
static void trace_open(const char *path, int fd) { debug("trace_open %s %d", path, fd); char *fullpath = realpath(path, NULL); if (fullpath == NULL) { printerr("Unable to get real path for '%s': %s\n", path, strerror(errno)); return; } trace_file(fullpath, fd); free(fullpath); }
DWORD WINAPI feedback(LPVOID arg) { feedback_args_t *feed = (feedback_args_t*)arg; char *str[1024]; DWORD len; while (ReadFile(feed->in, str, sizeof(str), &len, NULL)) if (!len || !WriteFile(feed->out, str, len, &len, NULL)) break; printerr("[EOF] from Console (%d)\n", GetLastError()); return 0; }
//a function to unset the variable void unset_sish(int argc, char *argv[]){ if (argc < 2) { printerr(debugLevel, "usage: set name\n"); return; } for (int i = 0; i < 100; ++i) { //go over the struct array and set the empty flag //of the struct with found key to 1 if (!strcmp(variables[i].key,argv[1])) { variables[i].empty = 1; break; } } }
int main(int argc, char *argv[]) { if (argc < 2) { printerr(); } unsigned long randseed = (unsigned long)time(NULL); //random up to seconds; int num_rands = 1; int i = 1; int error; while(i < argc) { if (!strcmp(argv[i],"-s")) { i++; error = sscanf(argv[i], "%lu", &(randseed)); if(error<1) { fprintf(stderr, "Error in specified randoom seed.\n"); exit(1);} } else if (!strcmp(argv[i],"-n")) { i++; error = sscanf(argv[i], "%d", &(num_rands)); if(error<1) { fprintf(stderr, "Error in -n value\n"); exit(1);} } else { fprintf(stderr, "Unknown command: %s\n", argv[i]); printerr(); } i++; } fprintf(stderr, "Random seed: %lu\n", randseed); sRandom(randseed); for(int i = 0; i < num_rands; i++) { printf("%lf\n", Random()); } return 0; }