void main(int argc, char **argv) { int which; which = 0; ARGBEGIN{ case 'p': which |= Plan9; break; case 'n': which |= Securenet; break; case 'd': debug++; break; default: usage(); }ARGEND argv0 = "warning"; if(!which) which |= Plan9 | Securenet; if(which & Plan9) dodir(&fs[Plan9]); if(which & Securenet) dodir(&fs[Securenet]); }
void main(int argc,char **argv) { int fdlock; unsigned long delay; (void) umask(022); sig_pipeignore(); when = now(); getconfopt(argc,argv,options,1,0); if (flagreturn < 0) /* default to returning timed-out messages */ flagreturn = !getconf_isset("noreturnposts"); getconf_line(&modtime,"modtime",0); if (!stralloc_0(&modtime)) die_nomem(); scan_ulong(modtime.s,&delay); if (!delay) delay = DELAY_DEFAULT; else if (delay < DELAY_MIN) delay = DELAY_MIN; else if (delay > DELAY_MAX) delay = DELAY_MAX; older = (unsigned long) when - 3600L * delay; /* delay is in hours */ fdlock = lockfile("mod/lock"); dodir("mod/pending/",flagreturn); dodir("mod/accepted/",0); dodir("mod/rejected/",0); dodir("mod/unconfirmed/",0); _exit(0); }
int main(int argc, char **argv) { int option; int i; int rc = 0; while((option = getopt(argc, argv, "o:rv?")) != EOF) { switch(option) { case 'o': strcpy(outname, optarg); break; case 'r': recursive++; break; case 'v': verbose++; break; default: usage(); return 1; } } argc -= optind; argv += optind; if(outname[0]) { if((fpout = fopen(outname, "w")) == NULL) { fprintf(stderr, "Can't write to %s\n", outname); return 3; } } else fpout = stdout; fprintf(fpout, "/*\n"); fprintf(fpout, " * This file is automatically created by " IDENT " " VERSION "\n"); fprintf(fpout, " */\n"); fprintf(fpout, "#include <fs/uromfs.h>\n\n"); if(argc) { for(i = 0; i < argc && rc == 0; i++) { strcpy(rootdir, argv[i]); strcat(rootdir, "/"); rootlen = strlen(rootdir); rc = dodir(argv[i]); } } else { strcpy(rootdir, "./"); rootlen = 2; rc = dodir("."); } fprintf(fpout, "\nROMENTRY *romEntryList = &file%dentry;\n", entryno); if(fpout != stdout) fclose(fpout); return rc; }
int dodir(char *dirpath) { int rc = 0; char path[256]; DIR *dir; struct dirent *dire; struct stat statbuf; if((dir = opendir(dirpath)) == NULL) { fprintf(stderr, "Failed to scan directory %s\n", dirpath); return -1; } if(verbose) fprintf(stderr, "Scan %s\n", dirpath); while((dire = readdir(dir)) != NULL && rc == 0) { if(dire->d_name[0] == '.' || stricmp(dire->d_name, "cvs") == 0) continue; strcpy(path, dirpath); strcat(path, "/"); strcat(path, dire->d_name); stat(path, &statbuf); if(statbuf.st_mode & S_IFDIR) rc = dodir(path); else if(statbuf.st_mode & S_IFREG) rc = dofile(path); } closedir(dir); return rc; }
/* * dodir - process the directory d. Return the long size (in blocks) * of d and its descendants. */ long dodir(char *d, int thislev, dev_t dev) { int maybe_print; struct stat s; long total; DIR dir; struct dirent *entry; static char dent[LINELEN]; if (lstat(d, &s) < 0) { fprintf(stderr, "%s: %s: %s\n", prog, d, strerror(errno)); return 0L; } if (s.st_dev != dev && dev != 0 && crosschk) return 0L; total = s.st_size; if (kbytes) total = (total + 1023L) / 1024L; else total = (total + (long) (BLOCK_SIZE - 1L)) / (long) BLOCK_SIZE; switch (s.st_mode & S_IFMT) { case S_IFDIR: /* * Directories should not be linked except to "." and "..", so this * directory should not already have been done. */ maybe_print = !silent; if (opendir_r(&dir, d) == NULL) break; while ((entry = readdir(&dir)) != NULL) { if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) continue; if (!makedname(d, entry->d_name, dent, sizeof(dent))) continue; total += dodir(dent, thislev - 1, s.st_dev); } closedir_r(&dir); break; case S_IFBLK: case S_IFCHR: /* st_size for special files is not related to blocks used. */ total = 0L; /* Fall through. */ default: if (s.st_nlink > 1 && done(s.st_dev, s.st_ino, s.st_nlink)) return 0L; maybe_print = all; break; } if (thislev >= levels || (maybe_print && thislev >= 0)) printf("%ld\t%s\n", total, d); return (total); }
void listDir(char* params[], int paramNumber) { if (paramNumber!=1&¶mNumber!=2) { printf(helpStr); } else { if (paramNumber==1) { dodir("."); } else { dodir(params[1]); } } }
int main (int ac, char *av[]) { char *prog_name = av[0]; char *fn, *tn; struct stat fs, ts; while (++av, --ac) { if (strcmp(*av, "-silent") == 0) silent = 1; else if (strcmp(*av, "-ignorelinks") == 0) ignore_links = 1; else if (strcmp(*av, "-withrevinfo") == 0) with_revinfo = 1; else if (strcmp(*av, "--") == 0) { ++av, --ac; break; } else break; } if (ac < 1 || ac > 2) quit (1, "usage: %s [-silent] [-ignorelinks] fromdir [todir]", prog_name); fn = av[0]; if (ac == 2) tn = av[1]; else tn = "."; /* to directory */ if (stat (tn, &ts) < 0) quiterr (1, tn); #ifdef S_ISDIR if (!(S_ISDIR(ts.st_mode))) #else if (!(ts.st_mode & S_IFMT) == S_IFDIR) #endif quit (2, "%s: Not a directory", tn); if (chdir (tn) < 0) quiterr (1, tn); /* from directory */ if (stat (fn, &fs) < 0) quiterr (1, fn); #ifdef S_ISDIR if (!(S_ISDIR(fs.st_mode))) #else if (!(fs.st_mode & S_IFMT) == S_IFDIR) #endif quit (2, "%s: Not a directory", fn); exit (dodir (fn, &fs, &ts, 0)); }
int main(int argc, char *argv[]) { int c; prog = argv[0]; while ((c = getopt(argc, argv, optstr)) != EOF) switch (c) { case 'a': all = 1; break; case 's': silent = 1; break; case 'x': case 'd': crosschk = 1; break; case 'l': levels = atoi(optarg); break; case 'k': kbytes = 1; break; default: fprintf(stderr, "Usage: %s [-asxk] [-l levels] [startdir]\n", prog); exit(1); } do { if (optind < argc) startdir = argv[optind++]; alc = 0; dodir(startdir, levels, 0); } while (optind < argc); return (0); }
/* * run all user directories, must be bootes (or root on unix) to do this */ void doalldirs(void) { Dir *db; int fd; long i, n; fd = open(".", OREAD); if(fd == -1){ warning("reading %s", root); return; } n = sysdirreadall(fd, &db); if(n > 0){ for(i=0; i<n; i++){ if(db[i].qid.type & QTDIR){ if(emptydir(db[i].name)) continue; switch(forkltd()){ case -1: syslog(0, runqlog, "out of procs"); doload(0); exits(0); case 0: if(sysdetach() < 0) error("%r", 0); dodir(db[i].name); exits(0); default: break; } } } free(db); } close(fd); }
/* Recursively create symbolic links from the current directory to the "from" directory. Assumes that files described by fs and ts are directories. */ static int dodir (char *fn, /* name of "from" directory, either absolute or relative to cwd */ struct stat *fs, struct stat *ts, /* stats for the "from" directory and cwd */ int rel) /* if true, prepend "../" to fn before using */ { DIR *df; struct dirent *dp; char buf[MAXPATHLEN + 1], *p; char symbuf[MAXPATHLEN + 1]; char basesym[MAXPATHLEN + 1]; struct stat sb, sc; int n_dirs; int symlen; int basesymlen = -1; char *ocurdir; if ((fs->st_dev == ts->st_dev) && (fs->st_ino == ts->st_ino)) { msg ("%s: From and to directories are identical!", fn); return 1; } if (rel) strcpy (buf, "../"); else buf[0] = '\0'; strcat (buf, fn); if (!(df = opendir (buf))) { msg ("%s: Cannot opendir", buf); return 1; } p = buf + strlen (buf); if (*(p - 1) != '/') *p++ = '/'; n_dirs = fs->st_nlink; while ((dp = readdir (df))) { if (dp->d_name[strlen(dp->d_name) - 1] == '~') continue; #ifdef __DARWIN__ /* Ignore these Mac OS X Finder data files */ if (!strcmp(dp->d_name, ".DS_Store") || !strcmp(dp->d_name, "._.DS_Store")) continue; #endif strcpy (p, dp->d_name); if (n_dirs > 0) { if (lstat (buf, &sb) < 0) { mperror (buf); continue; } #ifdef S_ISDIR if(S_ISDIR(sb.st_mode)) #else if ((sb.st_mode & S_IFMT) == S_IFDIR) #endif { /* directory */ n_dirs--; if (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || (dp->d_name[1] == '.' && dp->d_name[2] == '\0'))) continue; if (!with_revinfo) { if (!strcmp (dp->d_name, "BitKeeper")) continue; if (!strcmp (dp->d_name, "RCS")) continue; if (!strcmp (dp->d_name, "SCCS")) continue; if (!strcmp (dp->d_name, "CVS")) continue; if (!strcmp (dp->d_name, "CVS.adm")) continue; if (!strcmp (dp->d_name, ".svn")) continue; } ocurdir = rcurdir; rcurdir = buf; curdir = silent ? buf : (char *)0; if (!silent) printf ("%s:\n", buf); if ((stat (dp->d_name, &sc) < 0) && (errno == ENOENT)) { if (mkdir (dp->d_name, 0777) < 0 || stat (dp->d_name, &sc) < 0) { mperror (dp->d_name); curdir = rcurdir = ocurdir; continue; } } if (readlink (dp->d_name, symbuf, sizeof(symbuf) - 1) >= 0) { msg ("%s: is a link instead of a directory", dp->d_name); curdir = rcurdir = ocurdir; continue; } if (chdir (dp->d_name) < 0) { mperror (dp->d_name); curdir = rcurdir = ocurdir; continue; } dodir (buf, &sb, &sc, (buf[0] != '/')); if (chdir ("..") < 0) quiterr (1, ".."); curdir = rcurdir = ocurdir; continue; } } /* non-directory */ symlen = readlink (dp->d_name, symbuf, sizeof(symbuf) - 1); if (symlen >= 0) symbuf[symlen] = '\0'; /* The option to ignore links exists mostly because checking for them slows us down by 10-20%. But it is off by default because this really is a useful check. */ if (!ignore_links) { /* see if the file in the base tree was a symlink */ basesymlen = readlink(buf, basesym, sizeof(basesym) - 1); if (basesymlen >= 0) basesym[basesymlen] = '\0'; } if (symlen >= 0) { /* Link exists in new tree. Print message if it doesn't match. */ if (!equivalent (basesymlen>=0 ? basesym : buf, symbuf, basesymlen>=0 ? (char **) 0 : &p)) msg ("%s: %s", dp->d_name, symbuf); } else { char *sympath; if (basesymlen>=0) { if ((buf[0] == '.') && (buf[1] == '.') && (buf[2] == '/') && (basesym[0] == '.') && (basesym[1] == '.') && (basesym[2] == '/')) { /* It becomes very tricky here. We have ../../bar/foo symlinked to ../xxx/yyy. We can't just use ../xxx/yyy. We have to use ../../bar/foo/../xxx/yyy. */ int i; char *start, *end; strcpy (symbuf, buf); /* Find the first char after "../" in symbuf. */ start = symbuf; do { start += 3; } while ((start[0] == '.') && (start[1] == '.') && (start[2] == '/')); /* Then try to eliminate "../"s in basesym. */ i = 0; end = strrchr (symbuf, '/'); if (start < end) { do { i += 3; end--; while ((*end != '/') && (end != start)) end--; if (end == start) break; } while ((basesym[i] == '.') && (basesym[i + 1] == '.') && (basesym[i + 2] == '/')); } if (*end == '/') end++; strcpy (end, &basesym[i]); sympath = symbuf; } else sympath = basesym; } else sympath = buf; if (symlink (sympath, dp->d_name) < 0) mperror (dp->d_name); } } closedir (df); return 0; }
/*this is the main routine*/ void doshell() { char line[80]; /*run forever - the shell shouldn't end*/ while(1==1) { /*read in a line*/ printstring("SHELL>\0"); readstring(line); /*match it against each possible command*/ /*if the user presses return, ignore it*/ if (line[0]==0xd) continue; else if (iscommand(line,"CLS\0")==1) doclear(); else if (iscommand(line,"cls\0")==1) doclear(); else if (iscommand(line,"COPY\0")==1) docopy(); else if (iscommand(line,"copy\0")==1) docopy(); else if (iscommand(line,"CREATE \0")==1) docreate(line); else if (iscommand(line,"create \0")==1) docreate(line); else if (iscommand(line,"DELETE \0")==1) dodelete(line); else if (iscommand(line,"delete \0")==1) dodelete(line); else if (iscommand(line,"DIR\0")==1) dodir(); else if (iscommand(line,"dir\0")==1) dodir(); else if (iscommand(line,"EXEC \0")==1) doexecute(line,1); else if (iscommand(line,"exec \0")==1) doexecute(line,1); else if (iscommand(line,"EXECBACK \0")==1) doexecute(line,0); else if (iscommand(line,"execback \0")==1) doexecute(line,0); else if (iscommand(line,"HELP\0")==1) dohelp(); else if (iscommand(line,"help\0")==1) dohelp(); else if (line[0]=='?') dohelp(); else if (iscommand(line,"TYPE \0")==1) dotype(line); else if (iscommand(line,"type \0")==1) dotype(line); else if (iscommand(line,"KILL \0")==1) dokill(line); else if (iscommand(line,"kill \0")==1) dokill(line); else if (iscommand(line,"mkdir \0")==1) domkdir(line); else if (iscommand(line,"MKDIR\0")==1) domkdir(line); else if (iscommand(line,"FORMAT\0")==1) doFormat(); else if (iscommand(line,"format\0")==1) doFormat(); else if (iscommand(line,"remove\0")==1) doRemove(line); else if (iscommand(line,"REMOVE\0")==1) doRemove(line); else if (iscommand(line,"list\0")==1) doList(); else if (iscommand(line,"LIST\0")==1) doList(); else if (iscommand(line,"count\0")==1) doCount(line); else if (iscommand(line,"WRITE\0")==1) doCreateFile(line); else if (iscommand(line,"write\0")==1) doCreateFile(line); else if (iscommand(line,"READ\0")==1) doEcho(line); else if (iscommand(line,"read\0")==1) doEcho(line); else printstring("Command not found\r\n\0"); printstring("\r\n\0"); } }
int DOlnlst(void) { dodir(".", 0); return(0); }
/* * Descend through the directories, starting at "name". * Call dofile() for each directory entry. * Save each directory name, and process at the end. */ static void dodir(char *name) { size_t dn_mark, dn_next; char *prev_base; int seg_stat_err; int num_segs; strcpy(base_name, name); /* * Change to the new directory. * Extend the full path. */ if ((dir_fd = open(name, O_RDONLY)) == -1) { error(0, errno, catgets(catfd, SET, 3088, "Cannot open directory %s"), fullpath); if (exit_status < ES_Path) exit_status = ES_Path; return; } getdent_s.offset = 0; dir_buf_count = 0; if (chdir(name) == -1 && chdir(fullpath) == -1) { error(0, errno, catgets(catfd, SET, 3038, "cannot chdir to %s"), fullpath); (void) close(dir_fd); if (exit_status < ES_Path) exit_status = ES_Path; return; } prev_base = base_name; base_name += strlen(name); if (base_name[-1] != '/') { *base_name++ = '/'; } *base_name = '\0'; /* * Mark the directory name stack. */ dn_mark = dn_next = dn_size; while (getdent() > 0) { /* ignore dot and dot-dot */ if (strcmp((const char *) dir->d_name, ".") == 0 || strcmp((const char *) dir->d_name, "..") == 0) continue; /* * check to assure that construction of the full path name does * not exceed the limit before doing the idstat call */ if ((int)(strlen(fullpath) + dir->d_namlen + 1) > MAXPATHLEN) { error(0, errno, catgets(catfd, SET, 268, "%s: Pathname too long"), fullpath); if (exit_status < ES_File) exit_status = ES_File; continue; } strcpy(base_name, (const char *) dir->d_name); idstat.id = dir->d_id; seg_num = 0; if (ioctl(fs_fd, F_IDSTAT, &idstat) < 0) { error(0, errno, catgets(catfd, SET, 1090, "Ioctl call to stat %s (%d, %d) failed."), fullpath, (int)idstat.id.ino, idstat.id.gen); if (exit_status < ES_IDstat) exit_status = ES_IDstat; continue; } if (S_ISREQ(inode.di.mode)) { /* * Try to eliminate removable media files which don't * actually represent space on tape. These are those * for the archiver and stager, and those created by * users for disaster recovery. * For newly created filesystems, those for the * archiver and stager will have parent inode * SAM_ARCH_INO (5) and SAM_STAGE_INO (7) respectively. * For legacy file systems we don't have a clue. * Those created by users for reading * (disaster recovery) which haven't been referenced * will have size of MAXOFFSET_T, so throw these out too * (in CheckRmStatus() ). */ if ((inode.di.parent_id.ino != SAM_ARCH_INO) && (inode.di.parent_id.ino != SAM_STAGE_INO)) { CheckRmStatus(); } } else { CheckArchiveStatus(); } if (S_ISSEGI(&inode.di)) { /* * Inode is an index inode, perform archive_audit of * any archive copies of the file's data segments. */ seg_stat_err = seg_stat_path(&num_segs); if (seg_stat_err) { continue; } for (seg_num = 1; seg_num <= num_segs; seg_num++) { idstat.id.ino = (sam_ino_t)seg_stat_buf[seg_num - 1].st_ino; idstat.id.gen = (int32_t)seg_stat_buf[seg_num - 1].gen; if (ioctl(fs_fd, F_IDSTAT, &idstat) < 0) { error(0, errno, catgets(catfd, SET, 1091, "Ioctl call to stat %s, " "segment %d (%d, %d) failed."), fullpath, seg_num, (int)idstat.id.ino, idstat.id.gen); if (exit_status < ES_IDstat) exit_status = ES_IDstat; continue; } CheckArchiveStatus(); } } if (S_ISDIR(inode.di.mode)) adddir((char *)dir->d_name); } if (close(dir_fd) < 0) { error(0, errno, catgets(catfd, SET, 3040, "cannot close directory %s"), fullpath); if (exit_status < ES_CloseFile) exit_status = ES_CloseFile; } /* * Process all the directories found. */ while (dn_next < dn_size) { char *name; name = &dir_names[dn_next]; dn_next += strlen(name) + 1; dodir(name); } dn_size = dn_mark; base_name = prev_base; *base_name = '\0'; if (chdir("..") < 0 && chdir(fullpath) < 0) { error(0, errno, catgets(catfd, SET, 572, "cannot chdir to \"..\" %s"), fullpath); if (exit_status < ES_Path) exit_status = ES_Path; } }
int main( int argc, /* Number of arguments */ char *argv[]) /* Argument pointer list */ { extern int optind; char *cwd; int c, i; int errors = 0; /* * Process arguments. */ CustmsgInit(0, NULL); program_name = basename(argv[0]); while ((c = getopt(argc, argv, "c:df:Vv")) != EOF) { switch (c) { case 'c': i = atoi(optarg); if (i < 1 || i > 4) { errors++; fprintf(stderr, "%s: -c %s: invalid copy number\n", program_name, optarg); } CopyMask |= 1<<(i-1); break; case 'd': Damaged = TRUE; break; case 'f': o_fname = optarg; o_fname_specified = TRUE; break; case 'V': case 'v': Verbose = TRUE; break; case '?': default: errors++; } } if (optind == argc) errors++; /* No root_path */ if (errors != 0) { fprintf(stderr, catgets(catfd, SET, 13001, "Usage: %s %s\n"), program_name, "[-c copy_number]... [-f audit_file] [-V] root_path"); return (ES_Args); } if (CopyMask == 0) CopyMask = 0xf; /* If no -c,interested in all copies */ if ((cwd = getcwd(NULL, sizeof (fullpath)-1)) == NULL) { error(1, errno, catgets(catfd, SET, 587, "Cannot get cwd")); } /* * Open the audit output file. Rule is: * If -f not specified, or "-f -" specified, then use stdout * else use filename from -f argument. */ if (o_fname_specified && strcmp(o_fname, "-") != 0) { uid_t uid = getuid(); gid_t gid = getgid(); if ((*o_fname != '/') && (cwd != NULL)) { strncpy(fullpath, cwd, sizeof (fullpath)-1); strncat(fullpath, "/", sizeof (fullpath)-1); } else *fullpath = '\0'; strncat(fullpath, o_fname, sizeof (fullpath)-1); if (NormalizePath(fullpath) == NULL) { error(ES_OutputFile, 0, catgets(catfd, SET, 1423, "Invalid output file path")); } if ((o_st = FOPEN(fullpath, "a")) == NULL) { error(ES_OutputFile, errno, catgets(catfd, SET, 574, "Cannot create %s"), fullpath); } if (chown(fullpath, uid, gid) < 0) { error(0, errno, catgets(catfd, SET, 573, "Cannot chown %s"), fullpath); exit_status = ES_OutputFile; } } else { o_st = stdout; } /* * Check the path to audit. */ if ((*argv[optind] != '/') && (cwd != NULL)) { strncpy(fullpath, cwd, sizeof (fullpath)-1); strncat(fullpath, "/", sizeof (fullpath)-1); } else *fullpath = '\0'; strncat(fullpath, argv[optind], sizeof (fullpath)-1); if (NormalizePath(fullpath) == NULL) error(ES_Path, 0, catgets(catfd, SET, 1425, "Invalid path to audit")); if ((dir_buf = malloc(DIRBUF_SIZE)) == NULL) { error(ES_Malloc, errno, catgets(catfd, SET, 1773, "No memory for directory buffer %d"), DIRBUF_SIZE); } if ((fs_fd = open(fullpath, O_RDONLY)) < 0) { error(ES_Path, errno, catgets(catfd, SET, 613, "Cannot open %s"), fullpath); } /*LINTED pointer cast may result in improper alignment */ getdent_s.dir.ptr = (struct sam_dirent *)dir_buf; /* * Examine the audit path. */ base_name = fullpath; dodir(fullpath); if (o_st != stdout) fclose(o_st); if (Verbose) ListVsns(); if (seg_stat_buf) { free(seg_stat_buf); seg_stat_buf = (struct sam_stat *)NULL; seg_capacity = 0; } return (exit_status); }
main() { register int i, j, nlen = 0; time_t curtime, t; dodir(CMDSDIR, "C.", CMDSLEN, '\0', CMDTYPE); dodir(DATADIR, "D.", DATALEN, '\0', DATTYPE); dodir(XEQTDIR, "X.", XEQTLEN, 'X', XEQTYPE); getstst(SPOOL); time(&curtime); for(i=0; i<sndx; ++i) if((j = strlen(sys[i].name)) > nlen) nlen = j; for(i=0; i<sndx; ++i) { t = (sys[i].st_lastime +sys[i].st_retry) - curtime; /* decide if STST text is worth printing */ if (-t < ONEDAY*2 && sys[i].st_type == SS_WRONGTIME) { sys[i].stst[0] = '\0'; if (sys[i].cntr[0]+sys[i].cntr[1]+sys[i].cntr[2] == 0) continue; /* ignore entire line */ } printf("%-*.*s ", nlen, nlen, sys[i].name); if(sys[i].cntr[CMDTYPE]) printf("%3.d Cmd%s ", sys[i].cntr[CMDTYPE], sys[i].cntr[CMDTYPE]>1?"s":" "); else printf(" --- "); if(sys[i].cntr[DATTYPE]) printf("%3.d Data ", sys[i].cntr[DATTYPE]); else printf(" --- "); if(sys[i].cntr[XEQTYPE]) printf("%3.d Xqt%s ", sys[i].cntr[XEQTYPE], sys[i].cntr[XEQTYPE]>1?"s":" "); else printf(" --- "); if(*sys[i].stst == '\0' || sys[i].locked > sys[i].st_lastime) { if(sys[i].locked) printf("LOCKED\n"); else printf("\n"); continue; } printf("%s ", sys[i].stst); /* decide if STST info is worth pursuing */ if (-t < ONEDAY*2 && (sys[i].st_count == 0 || sys[i].st_type == SS_WRONGTIME || (sys[i].st_type == SS_INPROGRESS && sys[i].locked))) { printf("\n"); continue; } t = (sys[i].st_lastime +sys[i].st_retry) - curtime; if (-t < ONEDAY*2 && sys[i].st_type != SS_FAIL) t = 0; if (sys[i].st_count > MAXRECALLS) printf("at MAX RECALLS"); else if (-t >= ONEDAY*2) printf("%ld days ago", (long)-t/ONEDAY); else if (t <= 0) printf("Retry time reached"); else if (t < 60) printf("Retry time %ld sec%s", (long)(t%60), (t%60)!=1? "s": ""); else printf("Retry time %ld min%s", (long)(t/60), (t/60)!=1? "s": ""); if(sys[i].st_count > 1) printf(" Count: %d\n", sys[i].st_count); else printf("\n"); } if (xqtisrunning) printf("\nUuxqt is running\n"); exit(0); }
int DOllist(void) { dodir(".", 1); return(0); }
void main(int argc, char **argv) { char *qdir, *x; qdir = 0; ARGBEGIN{ case 'l': x = ARGF(); if(x == 0) usage(); load = atoi(x); if(load < 0) load = 0; break; case 'E': Eflag++; break; case 'R': /* no giving up -- just leave stuff in the queue */ Rflag++; break; case 'a': aflag++; break; case 'd': debug++; break; case 'r': limit = atoi(ARGF()); break; case 's': sflag++; break; case 't': giveup = 60*60*atoi(ARGF()); break; case 'q': qdir = ARGF(); if(qdir == 0) usage(); break; case 'n': npid = atoi(ARGF()); if(npid == 0) usage(); break; }ARGEND; if(argc != 2) usage(); pidlist = malloc(npid*sizeof(*pidlist)); if(pidlist == 0) error("can't malloc", 0); if(aflag == 0 && qdir == 0) { qdir = getuser(); if(qdir == 0) error("unknown user", 0); } root = argv[0]; cmd = argv[1]; if(chdir(root) < 0) error("can't cd to %s", root); doload(1); if(aflag) doalldirs(); else dodir(qdir); doload(0); exits(0); }
/* * Read the file to be transfered. * Write that file on the data socket. * The caller closes the socket. */ int source(int sock) { int fd, n, size; char *s; char file[100]; char hbuf[1024]; struct stat sb; #define name &buf[5] n = read(sock, buf, XFERSIZE); if (n <= 0) { perror("control nbytes"); return (-1); } buf[n] = 0; if (dflg) printf("%.*s\n", n, buf); if (zflg) { return (0); } if (!strncmp(buf, "EXIT", 4)) { exit(0); } if (strncmp(buf, "GET /", 5)) { perror(buf); return(1); } for (s = buf; *s && *s != '\r' && *s != '\n'; s++) ; *s = 0; for (s = name; *s && *s != ' '; s++) ; *s = 0; if (lflg) strncpy(file, name, sizeof(file)); if (dflg) printf("OPEN %s\n", name); fd = open(name, 0); if (fd == -1) { error: perror(name); close(fd); return (1); } if (fstat(fd, &sb) == -1) { if (dflg) printf("Couldn't stat %s\n", name); goto error; } size = sb.st_size; n = sprintf(hbuf, "HTTP/1.0 200 OK\r\n%s\r\nServer: lmhttp/0.1\r\nContent-Type: %s\r\nLast-Modified: %s\r\n\r\n", http_time(), type(name), date(&sb.st_mtime)); if (write(sock, hbuf, n) != n) { goto error; } if (Dflg && isdir(name)) { dodir(name, sock); } else if (nflg) { fake(sock, buf, size); } else if ((size > MMAPS_BETTER)) { /* XXX */ if (mmap_rdwr(fd, sock, size) == -1) { printf("%s mmap failed\n", name); } } else { rdwr(fd, sock, buf); } if (lflg) logit(sock, file, size); close(fd); return(0); }