static int getallgroups (void) { DIR *dir; struct dirent *dp; char *gr; if (!(dir = opendir("."))) { LOG("getallgroups:opendir(%s):%m", snroot); return -1; } for (nr_keys = 0; (dp = readdir(dir)); nr_keys++) if (is_valid_group(gr = dp->d_name)) if (-1 == key_add(&gr, strlen(gr))) fail(2, "No memory"); closedir(dir); return 0; }
JNIEXPORT jboolean JNICALL Java_com_sun_netstorage_samqfs_mgmt_arc_Archiver_isValidGroup(JNIEnv *env, jclass cls /*ARGSUSED*/, jobject ctx, jstring grpName) { jboolean isCopy; int res; boolean_t isValid; char *cstr = GET_STR(grpName, isCopy); PTRACE(1, "jni:Archiver_isValidGroup"); res = is_valid_group(CTX, cstr, &isValid); REL_STR(grpName, cstr, isCopy); if (-1 == res) { ThrowEx(env); return (NULL); } PTRACE(1, "jni:done checking group"); return (JBOOL(isValid)); }
int main (int argc, char **argv) { char optdebugbuf[7]; int n, mark; char *cp; progname = ((cp = strrchr(argv[0], '/')) ? cp + 1 : argv[0]); while ((n = opt_get(argc, argv, "pthcmo")) > -1) switch (n) { case 'd': if (++debug < 6) { if (!optdebug) strcpy(optdebug = optdebugbuf, "-d"); else strcat(optdebug, "d"); } break; case 'V': version(); _exit(0); case 't': if (!opt_arg) usage(); LOG("option \"-t %s\" no longer supported", opt_arg); break; case 'p': if (!opt_arg) usage(); concurrency = strtoul(opt_arg, &cp, 10); if (concurrency > MAX_CONCURRENCY || concurrency <= 0 || *cp) fail(1, "Bad value for concurrency option -p"); break; case 'h': if (!opt_arg) usage(); throttlerate = strtoul(opt_arg, &cp, 10); if (throttlerate < 0) fail(1, "Bad value for throttle option -h"); break; case 'c': if (!(optpipelining = opt_arg)) usage(); if (strtoul(optpipelining, &cp, 10) < 0 || *cp) fail(1, "Bad value for pipeline option -c"); break; case 'm': if (!(optmax = opt_arg)) usage(); if (strtoul(optmax, &cp, 10) <= 0 || *cp) fail(1, "Bad value for max-prime-articles option -m"); break; case 'P': optlogpid = TRUE; log_with_pid(); break; default: usage(); } close(0); open("/dev/null", O_RDONLY); /* snag 6 and 7 so we can dup onto them */ if (-1 == dup2(2, 6) || -1 == dup2(2, 7) || -1 == dup2(2, 1)) fail(2, "Unable to dup standard error:%m"); parameters(TRUE); if (-1 == chdir(snroot)) fail(2, "chdir(%s):%m", snroot); init(); if (-1 == set_path_var()) fail(2, "No memory"); n = 0; if (opt_ind == argc) { DIR *dir; struct dirent *dp; struct stat st; char ch; if (!(dir = opendir("."))) fail(2, "opendir(%s):%m", snroot); while ((dp = readdir(dir))) if (is_valid_group(dp->d_name)) if (-1 == readlink(dp->d_name, &ch, 1)) /* no symlinks */ if (0 == statf(&st, "%s/.outgoing", dp->d_name)) if (S_ISDIR(st.st_mode)) if (add(dp->d_name) > -1) /* NB: add() from get.c */ n++; closedir(dir); } else { debug++; for (; opt_ind < argc; opt_ind++) if (add(argv[opt_ind]) > -1) n++; debug--; } if (n == 0) fail(0, "No groups to fetch"); for (mark = 0; jobs_not_done(); mark++) { struct timeval tv; fd_set rset; int max; while (sow() == 0) /* Start some jobs */ ; FD_ZERO(&rset); if (throttlerate) { max = throttle_setfds(&rset); if (sigusr) { sigusr = FALSE; LOG("throttling at %d bytes/sec", throttlerate); } } else max = -1; tv.tv_sec = 1; tv.tv_usec = 0; if (select(max + 1, &rset, NULL, NULL, &tv) > 0) if (throttlerate) throttle(&rset); if (sigchld || 1 == mark % 10) { sigchld = FALSE; while (reap() == 0) ; } } quit(); _exit(0); }