// open a file, and read chunks of data until we reach EOF, // printing the data found to stdout int shell::c_history (std::vector <std::string> & args, props & p) { if ( ! args.empty () ) { carp ("format: history", p); return FAILURE; } #ifndef SAGA_HAVE_HISTORY_LIST carp ("Sorry, your libreadline does not support history listing", p); return FAILURE; #else // SAGA_HAVE_HISTORY_LIST HIST_ENTRY ** hist = history_list (); if ( hist ) { for ( int i = 0; hist[i]; i++ ) { p.out += (i + history_base); p.out += ":"; p.out += hist[i]->line; p.out += "\n"; } } return SUCCESS; #endif // SAGA_HAVE_HISTORY_LIST }
int main(int argc,char **argv,char **envp) { errmsg_iam("argv0"); if (argc < 3) { carp("usage: argv0", " realname program [ arg ... ]"); return 100; } pathexec_run(argv[1],argv + 2,envp); carp("unable to run ",argv[1],": ",error_string(table,errno)); return 111; }
void main() { char a[100],b[100]; FILE *in=fopen("ride.in","r"), *out=fopen("ride.out","w"); fscanf(in,"%s\n%s\n",a,b); fclose(in); if(carp(a)%47==carp(b)%47) fprintf(out,"GO\n"); else fprintf(out,"STAY\n"); fclose(out); exit(0); }
char* sha256_file_hex(const char* filename) { size_t data_size; void* data = lslurpb(filename, &data_size); char* hash = cache_get(data, data_size); if (hash) return hash; printf("file_hex: Cache miss for file %s\n", filename); char* tempname = lstrdup("sha256_XXXXXX"); int fd = mkstemp(tempname); if (fd == -1) { perror("mkstemp"); carp("Giving up"); } char* cmd = lsprintf("sha256sum '%s' > '%s'", filename, tempname); int rv = system(cmd); if (rv != 0) { perror("system"); carp("Giving up"); } FILE* temp = fdopen(fd, "r"); hash = GC_malloc_atomic(68); int count = fread(hash, 64, 1, temp); if (count != 1) { perror("fread"); carp("Giving up"); } hash[64] = 0; fclose(temp); unlink(tempname); cache_put(data, data_size, hash); return hash; }
int main(int argc, char* argv[]) { if (argc != 3) { fprintf(stderr, "Usage:\n ./fuzzy_check xx.pgm yy.pgm\n"); return 1; } FILE* pgm0 = fopen(argv[1], "r"); FILE* pgm1 = fopen(argv[2], "r"); if (pgm0 == 0 || pgm1 == 0) carp("Failed to open something"); read_header(pgm0); read_header(pgm1); while (!feof(pgm0) && !feof(pgm1)) { int num0 = read_int(pgm0); int num1 = read_int(pgm1); if (abs(num0 - num1) > FUZZ) { printf("Mismatch: %d != %d\n", num0, num1); return 0; } } fclose(pgm1); fclose(pgm0); printf("[cake: OK]\n"); return 0; }
int shell::c_touch (std::vector <std::string> & args, props & p) { // sanity checks if ( args.empty () ) { carp ("format: touch <file> [...]", p); return FAILURE; } std::vector <std::string> :: iterator begin = args.begin (); std::vector <std::string> :: iterator end = args.end (); std::vector <std::string> :: iterator iter; for ( iter = begin; iter != end; ++iter ) { std::string arg = *iter; if ( cwd_.exists (arg) ) { // nothing to do return SUCCESS; } saga::name_space::directory d (cwd_.get_url ()); saga::name_space::entry f = d.open (arg, saga::filesystem::Create); } return SUCCESS; }
// update a given replica location int shell::c_rep_update (std::vector <std::string> & args, props & p) { #if !defined(SAGA_HAVE_PACKAGE_REPLICA) || !defined(SAGA_HAVE_PACKAGE_NAMESPACE) carp("saga has been compiled without the replica package, unable to use this command"); return FAILURE; #else if ( args.size () != 3 ) { carp ("format: rep_update <logical_file> <old_url> <new_url>", p); return FAILURE; } std::string src = args[0]; std::string url1 = args[1]; std::string url2 = args[2]; // sanity checks if ( ! cwd_.exists (src) ) { carp ("No such logical file: " + src, p); return FAILURE; } if ( cwd_.is_dir (src) ) { carp ("Cannot update replica locations on a directory: " + src, p); return FAILURE; } // open the current directory as logical dir saga::replica::logical_directory dir (cwd_.get_url ()); // open the logical file saga::replica::logical_file lf = dir.open (src, saga::replica::Write); // update the replica location lf.update_location (saga::url (url1), saga::url (url2)); // logical file and dir close when going out of scope return SUCCESS; #endif }
// print the state of the job int shell::c_status (std::vector <std::string> & args, props & p) { #if !defined(SAGA_HAVE_PACKAGE_JOB) carp("saga has been compiled without the job package, unable to use this command"); return FAILURE; #endif // sanity checks if ( args.empty () ) { carp ("format: status <pid> [...]", p); return FAILURE; } std::vector <std::string> :: iterator begin = args.begin (); std::vector <std::string> :: iterator end = args.end (); std::vector <std::string> :: iterator iter; for ( iter = begin; iter != end; ++iter ) { int pid = atoi (iter->c_str ()); // get job saga::job::job job = jobs_.get_job (pid); // get state saga::job::state state = job.get_state (); // show state p.out += state_to_string (state); p.out += "\n"; // purge old entries if ( state == saga::job::Done || state == saga::job::Failed || state == saga::job::Canceled ) { jobs_.del (pid); } } return SUCCESS; }
static int make_connection(char* ip,uint16 port,uint32 scope_id) { int v6=byte_diff(ip,12,V4mappedprefix); int s; if (v6) { s=socket_tcp6(); if (s==-1) panic("socket_tcp6()"); ndelay_off(s); if (bindport) { for (;;) { int r=socket_bind6_reuse(s,V6any,bindport,0); if (++bindport<1024) bindport=1024; if (r==0) break; if (errno!=EADDRINUSE) panic("socket_bind6"); } } if (socket_connect6(s,ip,port,scope_id)==-1) { carp("socket_connect6"); close(s); return -1; } } else { s=socket_tcp4(); if (s==-1) panic("socket_tcp4()"); ndelay_off(s); if (bindport) { for (;;) { int r=socket_bind4_reuse(s,V6any,bindport); if (++bindport<1024) bindport=1024; if (r==0) break; if (errno!=EADDRINUSE) panic("socket_bind4"); } } if (socket_connect4(s,ip+12,port)==-1) { carp("socket_connect4"); close(s); return -1; } } return s; }
TreeNode* alloc_list_node(TreeNode* head, TreeNode* tail) { if (head == NULL) carp("Can't have null CAR in list."); TreeNode* tn = alloc_tree_node(LIST_TYPE); tn->arg0 = head; tn->arg1 = tail; return tn; }
int shell::c_cp (std::vector <std::string> & args, props & p) { std::string tgt = args.back (); args.erase ((++args.rbegin()).base()); std::vector <std::string> :: iterator begin = args.begin (); std::vector <std::string> :: iterator end = args.end (); std::vector <std::string> :: iterator iter; for ( iter = begin; iter != end; ++iter ) { std::string src = *iter; // sanity checks if ( ! cwd_.exists (src) ) { carp ("No such file: " + src, p); return FAILURE; } if ( cwd_.is_dir (src) ) { carp ("cannot copy directory: " + src, p); return FAILURE; } if ( cwd_.exists (tgt) && ! cwd_.is_dir (tgt) ) { carp ("already exists: " + tgt, p); return FAILURE; } // copy! cwd_.copy (saga::url (src), saga::url (tgt)); } return SUCCESS; }
image* read_image(const char* filename) { char* line = alloca(16); size_t size = 16; size_t ww, hh; int cc; int rv; FILE* imf = fopen(filename, "r"); rv = getline(&line, &size, imf); assert(rv != -1); if (!streq(line, "P2\n")) carp("Bad image file; not ASCII PGM"); /* Assume leading comments only */ while ((cc = getc(imf))) { if (cc == '#') { // throw away the line while (getc(imf) != '\n'); } else { ungetc(cc, imf); break; } } rv = fscanf(imf, "%ld", &ww); assert(rv == 1); rv = fscanf(imf, "%ld", &hh); assert(rv == 1); rv = fscanf(imf, "%d", &cc); assert(rv == 1); assert(cc == 255); image* im = alloc_image(ww, hh); for (int ii = 0; ii < ww * hh; ++ii) { rv = fscanf(imf, "%d", &cc); assert(rv == 1); im->data[ii] = (byte) cc; } fclose(imf); return im; }
// list all known replicas on a logical file int shell::c_rep_find (std::vector <std::string> & args, props & p) { #if !defined(SAGA_HAVE_PACKAGE_REPLICA) || !defined(SAGA_HAVE_PACKAGE_NAMESPACE) carp("saga has been compiled without the replica package, unable to use this command"); return FAILURE; #else if ( args.size () < 1 ) { carp ("format: rep_find <pat> [<key=val>] [...]", p); return FAILURE; } std::string pattern = args[0]; args.erase (args.begin()); // open the current directory as logical dir saga::replica::logical_directory dir (cwd_.get_url ()); std::vector <saga::url> list = dir.find (pattern, args); p.out += "\n"; // iterate over replica locations for ( std::size_t i = 0; i < list.size (); ++i ) { p.out += " "; p.out += saga::url::unescape(list[i].get_string()); p.out += "\n"; } p.out += "\n"; return SUCCESS; #endif }
void read_header(FILE* ff) { char* ftype = lgetline(ff); if (!streq(ftype, "P2\n") && !streq(ftype, "P3\n")) carp("That's not an ASCII PGM or PPM"); int ch; while ((ch = fgetc(ff)) == '#') { char* _junk = lgetline(ff); _junk = _junk; } ungetc(ch, ff); }
static char* cache_get(const char* data, size_t size) { if (size == 0) carp("Why are we looking up a size 0 thing?"); for (int ii = 0; ii < MAX_CACHE_SIZE; ++ii) { if (cache[ii].size != size) continue; if (memeq(cache[ii].data, data, size)) return cache[ii].hash; } return 0; }
char* pretty_print_any(TreeNode* node, int dd) { int64_t vv_i; double vv_d; switch (node->type) { case INTEGER_TYPE: vv_i = *((int64_t*)node->data); return lsprintf("%ld", vv_i); case FLOAT_TYPE: vv_d = *((double*)node->data); return lsprintf("%f", vv_d); case SYMBOL_TYPE: return (char*)node->data; case STRING_TYPE: return pretty_print_string(node, dd); case BINOP_TYPE: return pretty_print_binop(node, dd); case UNOP_TYPE: return pretty_print_unop(node, dd); case DOT_TYPE: return pretty_print_dot(node, dd); case BIND_TYPE: return pretty_print_bind(node, dd); case LIST_TYPE: return pretty_print_list(node, dd); case FUN_TYPE: return pretty_print_fun(node, dd); case LAMBDA_TYPE: return pretty_print_lambda(node, dd); case CALL_TYPE: return pretty_print_call(node, dd); case CALL_LAMBDA_TYPE: return pretty_print_call_lambda(node, dd); default: carp("pretty_print_tree(): Bad node type."); } abort(); }
int shell::c_env (std::vector <std::string> & args, props & p) { if ( !args.empty () ) { carp ("format: env", p); return FAILURE; } std::map <std::string, std::string> :: iterator iter = env_.begin (); std::map <std::string, std::string> :: iterator end = env_.end (); for ( /**/; iter != end; ++iter ) { p.out += iter->first; p.out += " \t "; p.out += iter->second; p.out += "\n"; } return SUCCESS; }
/* convert: xxx option A B C D to: /sbin/ninit-reload arg(s) and start above program options: -V -E -Z[number] */ int main(int argc, char **argv) { char *x, **qq, **q; char *help_file = ".sync"; char flag[3]={ '-', 'e', 0 }; x = argv[1]; if (x == 0) { help_file = ".nsvc_help"; goto write_it; } if (x[0] != '-') _exit(1); qq = alloca(sizeof(char *) * (2*argc + 30)); q = qq; INIT_ARGS2(q, "/sbin/ninit-reload","-u"); q += 2; switch (x[1]) { case 'Z': flag[1] = 'R'; case 'E': if (x[2]) { x[1]='a'; INIT_ARGS2(q,x,"-v"); q += 2; } break; case 'V': { char buf[1024]; int r, fd; write_it: fd = open(help_file, O_RDONLY); while ((r = read(fd, buf, sizeof(buf))) > 0) /* close(fd); */ write(1, buf, r); } default: _exit(0); } for (argv += 2; (x=*argv); argv++) { if (*x == 0) continue; /* skip empty args */ INIT_ARGS2(q,flag,x); q += 2; } *q++ = "/sbin/ninit"; INIT_ENV_GET_HOME(x,"NINIT_HOME","INIT_HOME"); if (x) { x -= 2; x[0] = '-'; x[1]='H'; *q++ = x; } *q = 0; carp("NINIT-remove: starting:"); fmt_argv(1, qq, " "); errmsg_puts(1,"\n"); errmsg_puts(1,0); /* return 0; */ execve(qq[0], qq, environ); _exit(1); }
int main(int argc,char* argv[]) { char server[1024]; int* fds; int* avail; int* keepleft; long long* expected; unsigned long n=10000; /* requests */ unsigned long c=10; /* concurrency */ unsigned long t=0; /* time limit in seconds */ unsigned long k=0; /* keep-alive */ unsigned long K=1; /* keep-alive counter */ int report=0; unsigned long long errors=0; unsigned long long bytes=0; int v=0; unsigned long i,done; uint16 port=80; uint32 scope_id=0; stralloc ips={0}; char* request,* krequest; unsigned long rlen, krlen; tai6464 first,now,next,last; enum { SAME, REPLAY } mode; char* hostname; server[0]=0; errmsg_iam("bench"); #ifndef __MINGW32__ signal(SIGPIPE,SIG_IGN); #endif for (;;) { int i; int ch=getopt(argc,argv,"n:c:t:kvK:C:r"); if (ch==-1) break; switch (ch) { case 'r': report=1; break; case 'n': i=scan_ulong(optarg,&n); if (i==0) die(1,"could not parse -n argument \"",optarg,"\".\n"); break; case 'c': i=scan_ulong(optarg,&c); if (i==0) die(1,"could not parse -c argument \"",optarg,"\".\n"); break; case 't': i=scan_ulong(optarg,&t); if (i==0) die(1,"could not parse -t argument \"",optarg,"\".\n"); break; case 'k': k=1; break; case 'K': i=scan_ulong(optarg,&K); break; case 'v': v=1; break; case 'C': cookiefile(optarg); break; case '?': break; default: usage(); } } if (n<1 || c<1 || !argv[optind]) usage(); if (argv[optind][0]=='@') { mode=REPLAY; char* host; n=(unsigned long)-1; host=argv[optind]+1; { int tmp; tmp=str_chr(host,'/'); if (host[tmp]) { host[tmp]=0; if (!scan_ushort(host+tmp+1,&port)) usage(); } tmp=str_chr(host,'%'); if (host[tmp]) { host[tmp]=0; scope_id=socket_getifidx(host+tmp+1); if (scope_id==0) carp("warning: network interface \"",host+tmp+1,"\" not found."); } } { stralloc a={0}; stralloc_copys(&a,host); if (dns_ip6(&ips,&a)==-1) die(1,"could not find IP for \"",host,"\"!"); } hostname=host; request=krequest=0; rlen=krlen=0; } else { char* host=argv[optind]; int colon; int slash; char* c; mode=SAME; if (byte_equal(host,7,"http://")) host+=7; colon=str_chr(host,':'); slash=str_chr(host,'/'); if (host[0]=='[') { /* ipv6 IP notation */ int tmp; ++host; --colon; --slash; tmp=str_chr(host,']'); if (host[tmp]==']') host[tmp]=0; if (host[tmp+1]==':') colon=tmp+1; if (colon<tmp+1) colon=tmp+1+str_len(host+tmp+1); } if (colon<slash) { host[colon]=0; c=host+colon+1; if (c[scan_ushort(c,&port)]!='/') usage(); *c=0; } host[colon]=0; c=host+slash; *c=0; { char* tmp=alloca(str_len(host)+1); tmp[fmt_str(tmp,host)]=0; host=tmp; } *c='/'; { int tmp=str_chr(host,'%'); if (host[tmp]) { host[tmp]=0; scope_id=socket_getifidx(host+tmp+1); if (scope_id==0) carp("warning: network interface \"",host+tmp+1,"\" not found."); } } { stralloc a={0}; stralloc_copys(&a,host); if (dns_ip6(&ips,&a)==-1) die(1,"could not find IP for \"",host,"\"!"); } request=alloca(1300+str_len(host)+3*str_len(c)); krequest=alloca(1300+str_len(host)+3*str_len(c)); { int i,j; i=fmt_str(request,"GET "); i+=fmt_urlencoded(request+i,c,str_len(c)); i+=fmt_str(request+i," HTTP/1.0\r\nHost: "); i+=fmt_str(request+i,host); i+=fmt_str(request+i,":"); i+=fmt_ulong(request+i,port); i+=fmt_str(request+i,"\r\nUser-Agent: bench/1.0\r\nConnection: "); j=i; i+=fmt_str(request+i,"close\r\n\r\n"); rlen=i; request[rlen]=0; byte_copy(krequest,rlen,request); i=j+fmt_str(krequest+j,"keep-alive\r\n\r\n"); krlen=i; krequest[krlen]=0; } hostname=host; } fds=alloca(c*sizeof(*fds)); avail=alloca(c*sizeof(*avail)); expected=alloca(c*sizeof(*expected)); keepleft=alloca(c*sizeof(*keepleft)); last.sec.x=23; if (!k) K=1; for (i=0; i<c; ++i) { fds[i]=-1; avail[i]=1; keepleft[i]=K; } taia_now(&first); for (done=0; done<n; ) { if (t) { /* calculate timeout */ taia_now(&now); if (now.sec.x != last.sec.x) { byte_copy(&last,sizeof(now),&now); byte_copy(&next,sizeof(now),&now); next.sec.x += t; while ((i=io_timeouted())!=-1) { unsigned long j; char numbuf[FMT_ULONG]; numbuf[fmt_ulong(numbuf,i)]=0; carp("timeout on fd ",numbuf,"!"); j=(unsigned long)io_getcookie(i); io_close(i); avail[j]=1; fds[j]=-1; } } } /* first, fill available connections */ for (i=0; i<c; ++i) if (avail[i]==1 && fds[i]==-1) { fds[i]=make_connection(ips.s,port,scope_id,-1); if (fds[i]==-1) diesys(1,"socket/connect"); avail[i]=2; if (io_fd(fds[i])==0) diesys(1,"io_fd"); io_setcookie(fds[i],(void*)i); // io_wantread(fds[i]); io_wantwrite(fds[i]); } if (t) io_waituntil(next); else io_wait(); /* second, see if we can write on a connection */ while ((i=io_canwrite())!=-1) { int j; j=(unsigned long)io_getcookie(i); if (avail[j]==2) { if (make_connection(ips.s,port,scope_id,i)==-1) { ++errors; if (v) write(1,"!",1); io_close(i); avail[j]=1; fds[j]=-1; continue; } } { char* towrite; int writelen; if (mode==REPLAY) { static long lines; char line[1024]; char req[2048]; int len; int i; char* c; char* host; int hlen; if ((len=buffer_getline(buffer_0,line,sizeof(line)))) { ++lines; if (line[len]!='\n') die(0,"line too long: ",line); line[len]=0; c=line; if (str_start(line,"http://")) c+=7; if (c[0]=='/') { host=hostname; hlen=strlen(hostname); } else { host=c; c+=(hlen=str_chr(c,'/')); } if (!*c) c="/"; i=fmt_str(req,"GET "); i+=fmt_urlencoded(req+i,c,str_len(c)); i+=fmt_str(req+i," HTTP/1.0\r\nHost: "); byte_copy(req+i,hlen,host); i+=hlen; i+=fmt_str(req+i,":"); i+=fmt_ulong(req+i,port); if (cookies) { int j; i+=fmt_str(req+i,"\r\n"); j=nextcookie(req+i,sizeof(req)-i-100); if (j!=-1) i+=j; else i-=2; } i+=fmt_str(req+i,"\r\nUser-Agent: bench/1.0\r\nConnection: "); i+=fmt_str(req+i,keepleft[j]>1?"keep-alive\r\n\r\n":"close\r\n\r\n"); req[i]=0; towrite=req; writelen=i; } else { n=done; break; } } else { if (keepleft[j]>1) { towrite=krequest; writelen=krlen; } else { towrite=request; writelen=rlen; } if (cookies) { int i=writelen-2; int j=nextcookie(towrite+i,900); if (j!=-1) i+=j; i+=fmt_str(towrite+i,"\r\n\r\n"); writelen=i; } } if (io_trywrite(i,towrite,writelen)!=writelen) { ++errors; if (v) write(1,"-",1); io_close(i); avail[j]=1; fds[j]=-1; continue; } } io_dontwantwrite(i); io_wantread(i); expected[j]=-1; if (v) write(1,"+",1); } /* third, see if we got served */ while ((i=io_canread())!=-1) { char buf[8193]; int l,j; buf[8192]=0; j=(unsigned long)io_getcookie(i); if ((l=io_tryread(i,buf,sizeof(buf)-1))<=0) { if (l==0) { /* EOF. Mhh. */ if (expected[j]>0) { ++errors; if (v) write(1,"-",1); /* so whine a little */ } if (expected[j]==-2) ++done; io_close(i); avail[j]=1; fds[j]=-1; } else if (l==-3) { ++errors; if (v) write(1,"!",1); // carpsys("read"); } } else { bytes+=l; if (v) write(1,".",1); /* read something */ if (expected[j]==-1) { /* expecting header */ int k; /* OK, so this is a very simplistic header parser. No * buffering. At all. We expect the Content-Length header to * come in one piece. */ if (l>10 && !memcmp(buf,"HTTP/1.",7)) { if (buf[9]>='0' && buf[9]<='9') r[buf[9]-'0']++; else { write(1,buf,15); write(1,"\n",1); } } expected[j]=-2; if (!done) { for (k=0; k<l; ++k) if (str_start(buf+k,"\nServer: ")) { char* tmp=buf+(k+=9); for (; k<l; ++k) if (buf[k]=='\r') break; k=buf+k-tmp; if (k>sizeof(server)-1) k=sizeof(server)-1; byte_copy(server,k,tmp); server[k]=0; break; } } for (k=0; k<l; ++k) { if (str_start(buf+k,"\nContent-Length: ")) { k+=17; if (buf[k+scan_ulonglong(buf+k,(unsigned long long*)expected+j)] != '\r') die(1,"parse error in HTTP header!"); } else if (str_start(buf+k,"\r\n\r\n")) break; } if (expected[j]>0) { if (l-(k+4)>expected[j]) expected[j]=0; else expected[j]-=l-(k+4); } } else if (expected[j]==-2) { /* no content-length header, eat everything until EOF */ } else { if (l>expected[j]) { carp("got more than expected!"); expected[j]=0; } else expected[j]-=l; } if (expected[j]==0) { ++done; /* one down! */ avail[j]=1; // printf("fd %d: keepleft[%d]=%d\n",i,j,keepleft[j]); if (keepleft[j]>1) { --keepleft[j]; io_dontwantread(i); io_wantwrite(i); expected[j]=0; } else { keepleft[j]=K; io_close(i); fds[j]=-1; } } } } } taia_now(&now); taia_sub(&now,&now,&first); { char a[FMT_ULONG]; char b[FMT_ULONG]; char C[FMT_ULONG]; char d[FMT_ULONG]; char e[FMT_ULONG]; char f[FMT_ULONG]; char g[FMT_ULONG]; char h[FMT_ULONG]; char i[FMT_ULONG]; char j[FMT_ULONG]; unsigned long long l; a[fmt_ulong(a,now.sec.x)]=0; b[fmt_ulong0(b,(now.nano%1000000000)/100000,4)]=0; C[fmt_ulong(C,done)]=0; d[fmt_ulonglong(d,errors)]=0; e[fmt_ulonglong(e,bytes)]=0; /* let's say bytes = 10 MB, time = 1.2 sec. * then we want 10*1024*1024/1.2 == 8 MB/sec */ l = (now.sec.x * 1024) + now.nano/976562; if (l) { int i; l=bytes/l; if (report) i=fmt_ulong(f,l); else { i=fmt_humank(f,l*1024); i+=fmt_str(f+i,"iB/sec"); } f[i]=0; } else strcpy(f,"n/a"); l = (now.sec.x * 1000) + now.nano/1000000; l = l ? (done*10000) / l : 0; g[fmt_ulong(g,l/10)]=0; h[fmt_ulong(h,c)]=0; i[fmt_ulong(i,K)]=0; j[fmt_ulong(j,kaputt)]=0; if (server[0]) msg("Server: ",server); if (report) { errmsg_iam(0); msg("req\terr\tconcur\tkeep\tkbytes\tsec\ttput\tr/s\treset"); msg(C,"\t",d,"\t",h,"\t",i,"\t",e,"\t",a,".",b,"\t",f,"\t",g,"\t",j); } else { msg(C," requests, ",d," errors."); msg(e," bytes in ",a,".",b," seconds."); msg("Throughput: ",f); msg("Requests per second: ",g); msg("Connection refused/reset by peer: ",j); } { int i; for (i=0; i<9; ++i) { a[fmt_ulong(a,r[i])]=0; b[0]=i+'0'; b[1]=0; msg(b,"xx: ",a); } } } return 0; }
int main(int argc,char* argv[]) { static size_t x; x=23; atomic_add(&x,3); printf("%u\n",x); printf("%u\n",atomic_add_return(&x,-3)); printf("%u\n",compare_and_swap(&x,26,17)); printf("%u\n",compare_and_swap(&x,23,17)); #if 0 atomic_add(&x,3); printf("%u\n",x); x=23; atomic_add(&x,3); assert(x==26); atomic_or(&x,1); assert(x==27); atomic_and(&x,-2); assert(x==26); #endif #if 0 iarray a; char* c; iarray_init(&a,sizeof(io_entry)); printf("15 -> %p\n",c=iarray_allocate(&a,15)); printf("23 -> %p\n",c=iarray_allocate(&a,23)); printf("1234567 -> %p\n",c=iarray_allocate(&a,1234567)); printf("23 -> %p\n",iarray_get(&a,23)); #endif #if 0 io_batch* b=iob_new(1234); int64 fd=open("t.c",0); iob_addbuf(b,"fnord",5); iob_addfile_close(b,fd,0,7365); iob_write(1,b,writecb); #endif #if 0 char dest[1024]; unsigned long len; scan_urlencoded2("libstdc++.tar.gz",dest,&len); buffer_putmflush(buffer_1,dest,"\n"); #endif #if 0 static stralloc sa; stralloc_copym(&sa,"foo ","bar ","baz.\n"); write(1,sa.s,sa.len); #endif #if 0 buffer_putmflush(buffer_1,"foo ","bar ","baz.\n"); #endif #if 0 char* c="fnord"; int fd=open_read(c); errmsg_iam(argv[0]); carp("could not open file `",c,"'"); diesys(23,"could not open file `",c,"'"); #endif #if 0 errmsg_warn("could not open file `",c,"'",0); errmsg_warnsys("could not open file `",c,"'",0); #endif #if 0 char buf[100]="/usr/bin/sh"; int len=str_len(buf); assert(byte_rchr(buf,len,'/')==8); assert(byte_rchr(buf,len,'@')==len); assert(byte_rchr(buf,len,'h')==len-1); printf("%d\n",byte_rchr("x",1,'x')); #endif #if 0 char buf[IP6_FMT+100]; int i; char ip[16]; uint32 scope_id; char* s="fec0::1:220:e0ff:fe69:ad92%eth0/64"; char blubip[16]="\0\0\0\0\0\0\0\0\0\0\xff\xff\x7f\0\0\001"; i=scan_ip6if(s,ip,&scope_id); assert(s[i]=='/'); buffer_put(buffer_1,buf,fmt_ip6if(buf,ip,scope_id)); buffer_putnlflush(buffer_1); buffer_put(buffer_1,buf,fmt_ip6ifc(buf,blubip,scope_id)); buffer_putnlflush(buffer_1); scan_ip6("2001:7d0:0:f015:0:0:0:1",ip); buffer_put(buffer_1,buf,fmt_ip6(buf,ip)); buffer_putnlflush(buffer_1); #endif #if 0 char buf[100]; int i; printf("%d\n",i=fmt_pad(buf,"fnord",5,7,10)); buf[i]=0; puts(buf); #endif #if 0 char ip[16]; char buf[32]; printf("%d (expect 2)\n",scan_ip6("::",ip)); printf("%d (expect 3)\n",scan_ip6("::1",ip)); printf("%d (expect 16)\n",scan_ip6("fec0:0:0:ffff::1/0",ip)); printf("%.*s\n",fmt_ip6(buf,ip),buf); #endif #if 0 static stralloc s,t; stralloc_copys(&s,"fnord"); stralloc_copys(&t,"abc"); printf("%d\n",stralloc_diff(&s,&t)); stralloc_copys(&t,"fnor"); printf("%d\n",stralloc_diff(&s,&t)); stralloc_copys(&t,"fnord"); printf("%d\n",stralloc_diff(&s,&t)); stralloc_copys(&t,"fnordh"); printf("%d\n",stralloc_diff(&s,&t)); stralloc_copys(&t,"hausen"); printf("%d\n",stralloc_diff(&s,&t)); #endif #if 0 static stralloc s; stralloc_copys(&s,"fnord"); printf("%d\n",stralloc_diffs(&s,"abc")); printf("%d\n",stralloc_diffs(&s,"fnor")); printf("%d\n",stralloc_diffs(&s,"fnord")); printf("%d\n",stralloc_diffs(&s,"fnordh")); printf("%d\n",stralloc_diffs(&s,"hausen")); #endif #if 0 printf("%d\n",case_starts("fnordhausen","FnOrD")); printf("%d\n",case_starts("fnordhausen","blah")); #endif #if 0 char buf[]="FnOrD"; case_lowers(buf); puts(buf); #endif #if 0 char buf[100]="foo bar baz"; printf("%d (expect 7)\n",byte_rchr(buf,11,' ')); #endif #if 0 unsigned long size; char* buf=mmap_read(argv[1],&size); if (buf) { unsigned int x=fmt_yenc(0,buf,size); unsigned int y; char* tmp=malloc(x+1); y=fmt_yenc(tmp,buf,size); write(1,tmp,x); } #endif #if 0 char buf[100]; char buf2[100]; unsigned int len,len2; buf[fmt_yenc(buf,"http://localhost/~fefe",22)]=0; buffer_puts(buffer_1,buf); buffer_putsflush(buffer_1,"\n"); if ((buf[len2=scan_yenc(buf,buf2,&len)])!='\n') { buffer_putsflush(buffer_2,"parse error!\n"); return 1; } buffer_put(buffer_1,buf2,len2); buffer_putsflush(buffer_1,"\n"); return 0; #endif #if 0 char buf[100]; char buf2[100]; unsigned int len,len2; buf[fmt_base64(buf,"foo:bar",7)]=0; buffer_puts(buffer_1,buf); buffer_putsflush(buffer_1,"\n"); if ((buf[len2=scan_base64(buf,buf2,&len)])!=0) { buffer_putsflush(buffer_2,"parse error!\n"); return 1; } buffer_put(buffer_1,buf2,len2); buffer_putsflush(buffer_1,"\n"); return 0; #endif #if 0 unsigned long size; char* buf=mmap_read(argv[1],&size); if (buf) { unsigned int x=fmt_uuencoded(0,buf,size); unsigned int y; char* tmp=malloc(x+1); y=fmt_uuencoded(tmp,buf,size); write(1,tmp,x); } #endif #if 0 char buf[]="00000000000000000000000000000001"; char ip[16]; if (scan_ip6_flat(buf,ip) != str_len(buf)) buffer_putsflush(buffer_2,"parse error!\n"); #endif #if 0 int fd=open_read("t.c"); buffer b; char buf[1024]; char line[20]; int i; buffer_init(&b,read,fd,buf,1024); i=buffer_getline(&b,line,19); buffer_puts(buffer_1,"getline returned "); buffer_putulong(buffer_1,i); buffer_puts(buffer_1,"\n"); buffer_puts(buffer_1,line); buffer_flush(buffer_1); #endif #if 0 buffer_putulong(buffer_1,23); // buffer_putspace(buffer_1); buffer_putsflush(buffer_1,"\n"); // buffer_flush(buffer_1); #endif #if 0 long a,b,c; char buf[4096]; char buf2[4096]; memcpy(buf,buf2,4096); byte_copy(buf,4096,buf2); rdtscl(a); memcpy(buf,buf2,4096); rdtscl(b); byte_copy(buf,4096,buf2); rdtscl(c); printf("memcpy: %d - byte_copy: %d\n",b-a,c-b); #endif #if 0 char ip[16]; int i; if ((i=scan_ip6(argv[1],ip))) { char buf[128]; buf[fmt_ip6(buf,ip)]=0; puts(buf); } #endif #if 0 char buf[100]; strcpy(buf,"foobarbaz"); buf[fmt_fill(buf,3,5,100)]=0; printf("\"%s\"\n",buf); #endif #if 0 unsigned long len; char *c=mmap_read("/etc/passwd",&len); printf("got map %p of len %lu\n",c,len); #endif #if 0 char c; printf("%d\n",buffer_getc(buffer_0,&c)); printf("%c\n",c); #endif #if 0 char buf[100]="01234567890123456789012345678901234567890123456789"; long a,b,c; #endif #if 0 buf[ip4_fmt(buf,ip4loopback)]=0; buffer_puts(buffer_1small,buf); buffer_flush(buffer_1small); #endif #if 0 buf[0]=0; buf[fmt_8long(buf,0)]=0; puts(buf); rdtscl(a); c=str_len(buf); rdtscl(b); /*byte_zero_djb(buf,j); */ // printf("\n%lu %d\n",b-a,c); #endif #if 0 buffer_puts(buffer_1small,"hello, world\n"); buffer_flush(buffer_1small); #endif #if 0 int s=socket_tcp4(); char ip[4]={127,0,0,1}; int t=socket_connect4(s,ip,80); #endif #if 0 char buf[100]="foo bar baz fnord "; char buf2[100]="foo braz fnord"; long a,b,c; long i=0,j=0,k=0; double d; uint32 l,m,n; stralloc sa={0}; stralloc_copys(&sa,"fnord"); stralloc_catlong0(&sa,-23,5); stralloc_append(&sa,"\n"); printf("%d %d\n",str_equal("fnord","fnord1"),str_equal("fnord1","fnord")); write(1,sa.s,sa.len); printf("%d %d\n",stralloc_starts(&sa,"fnord"),stralloc_starts(&sa,"fnord\na")); l=0xdeadbeef; uint32_pack_big((char*)&m,l); uint32_unpack_big((char*)&m,&n); printf("%x %x %x\n",l,m,n); rdtscl(a); /* i=scan_double("3.1415",&d); */ rdtscl(b); /*byte_zero_djb(buf,j); */ rdtscl(c); printf("%lu %lu\n",b-a,c-b); #endif #if 0 size_t size; char* buf=mmap_read(argv[1],&size); if (buf) { unsigned int x=fmt_urlencoded2(0,buf,size,"x"); unsigned int y; char* tmp=malloc(x+1); y=fmt_urlencoded2(tmp,buf,size,"x"); write(1,tmp,x); } #endif #if 0 printf("%d %d\n",strcmp("foo","bar"),str_diff("foo","bar")); printf("%d %d\n",strcmp("foo","üar"),str_diff("foo","üar")); #endif #if 0 { int16 a; int32 b; int64 c; assert(imult16(4,10000,&a)==0); assert(imult16(-4,10000,&a)==0); assert(imult16(5,10,&a)==1 && a==50); assert(imult16(-3,10000,&a)==1 && a==-30000); assert(imult32(0x40000000,2,&b)==0); assert(imult32(0x3fffffff,2,&b)==1 && b==0x7ffffffe); assert(imult64(0x4000000000000000ll,2,&c)==0); assert(imult64(0x3fffffffffffffffll,2,&c)==1 && c==0x7ffffffffffffffell); } #endif #if 0 stralloc a; printf("%d\n",stralloc_copym(&a,"fnord",", ","foo")); #endif return 0; }
static int readanswer(int s,int measurethroughput) { char buf[8192]; int i,j,body=-1,r; unsigned long rest; unsigned long done=0; struct timeval a,b; i=0; while ((r=read(s,buf+i,sizeof(buf)-i)) > 0) { i+=r; for (j=0; j+3<i; ++j) { if (buf[j]=='\r' && buf[j+1]=='\n' && buf[j+2]=='\r' && buf[j+3]=='\n') { body=j+4; break; } } if (body!=-1) { if (byte_diff(buf,7,"HTTP/1.")) { buffer_putsflush(buffer_2,"invalid HTTP response!\n"); return -1; } break; } } if (r==-1) return -1; rest=-1; for (j=0; j<r; j+=str_chr(buf+j,'\n')) { if (byte_equal(buf+j,17,"\nContent-Length: ")) { char* c=buf+j+17; if (c[scan_ulong(c,&rest)]!='\r') { buffer_putsflush(buffer_2,"invalid Content-Length header!\n"); return -1; } break; } ++j; } if (measurethroughput) { gettimeofday(&a,0); done=r-body; } rest-=(r-body); while (rest) { r=read(s,buf,rest>sizeof(buf)?sizeof(buf):rest); if (r<1) { if (r==-1) carp("read from HTTP socket"); else { buffer_puts(buffer_2,"early HTTP EOF; expected "); buffer_putulong(buffer_2,rest); buffer_putsflush(buffer_2,"more bytes!\n"); return -1; } } else { rest-=r; if (measurethroughput) { unsigned long x=done/1000000; unsigned long y; done+=r; y=done/1000000; if (x!=y) { unsigned long d; unsigned long long z; gettimeofday(&b,0); d=(b.tv_sec-a.tv_sec)*1000000; d=d+b.tv_usec-a.tv_usec; buffer_puts(buffer_1,"tput "); z=1000000000ull/d; buffer_putulong(buffer_1,z); buffer_putnlflush(buffer_1); byte_copy(&a,sizeof(a),&b); } } } } return 0; }
void MainWindow::on_doItButton_clicked(){ int len=ui->listWidget->count(); if(isoFilename.isEmpty()){ carp("iso not selected"); return; } if(len==0) return; ui->doItButton->setEnabled(false); iso=new Iso(isoFilename); if(!iso->issue.isEmpty()){ carp(iso->issue); delete iso; ui->doItButton->setEnabled(true); return; } QString yum; rwops *rwyum=NULL; if((rwyum=iso->open("/PSP_GAME/USRDIR/YUMFILE_1.BIN"))!=NULL){ yum="/PSP_GAME/USRDIR/YUMFILE_1.BIN"; } else if((rwyum=iso->open("/PSP_GAME/USRDIR/YUMFILE_2.BIN"))!=NULL){ yum="/PSP_GAME/USRDIR/YUMFILE_2.BIN"; } else if((rwyum=iso->open("/PSP_GAME/USRDIR/YUMFILE_3.BIN"))!=NULL){ yum="/PSP_GAME/USRDIR/YUMFILE_3.BIN"; } if(rwyum){ delete rwyum; } else{ delete iso; ui->doItButton->setEnabled(true); carp("None of YUMFILE_1.BIN YUMFILE_2.BIN or YUMFILE_3.BIN were found in iso"); return; } QHash<QString,int> dups; GenericJob *job; QRegExp mifFile("(\\d+)\\.mif\\.png$"); QRegExp imageFile("(\\d+)(-(\\d+)|)(-[a-z]+)?\\.(png|gif|jpe?g|bmp)$"); QRegExp emailFile("(\\d+)\\.mail\\.txt$"); for(int i=0;i<len;i++){ QString file=ui->listWidget->item(i)->text(); QString name=filename(file); QString ext=fileext(file); int no=isanumberfile(name); if(dups.contains(file)){ job=new GenericJob(); job->issue="Skipped: already in the list"; job->state=JOB_STATE_SKIPPED; job->type="NONE"; no=-1; } else if(name.toUpper()=="EBOOT.BIN"){ job=new IsoFileJob(); job->iso_filename="/PSP_GAME/SYSDIR/EBOOT.BIN"; job->type="ISO-FILE"; } else if(file.right(10)==".lines.txt"){ job=new ExecutableLinesJob(); job->iso_filename="/PSP_GAME/SYSDIR/EBOOT.BIN"; job->type="EXEC-LINES"; } else if(emailFile.indexIn(name)!=-1){ YumMailJob *yjob=new YumMailJob(); yjob->number=no=emailFile.cap(1).toInt(); job=yjob; job->iso_filename=yum; job->type="EMAIL"; } else if(no!=-1 && ext=="txt"){ YumScriptJob *yjob=new YumScriptJob(); yjob->number=no; job=yjob; job->iso_filename=yum; job->type="SCRIPT"; } else if(mifFile.indexIn(name)!=-1){ YumMifJob *yjob=new YumMifJob(); yjob->number=no=mifFile.cap(1).toInt(); job=yjob; job->iso_filename=yum; job->type="MIF"; } else if(imageFile.indexIn(name)!=-1){ YumPomJob *yjob=new YumPomJob(); yjob->number=no=imageFile.cap(1).toInt(); bool ok; yjob->subnumber=imageFile.cap(3).toInt(&ok); if(!ok) yjob->subnumber=1; job=yjob; job->iso_filename=yum; job->type="POM"; } else if(no!=-1){ YumFileJob *yjob=new YumFileJob(); yjob->number=no; job=yjob; job->iso_filename=yum; job->type="YUM-FILE"; } else{ job=new GenericJob(); job->state=JOB_STATE_SKIPPED; job->type="NONE"; job->issue="Don't know what to do with this file"; } dups.insert(file,1); job->source=file; if(job->desc.isEmpty()) job->desc=name; jobs.append(job); if(no!=-1){ QList<unsigned short> d=yum_dups(no); for(int i=0;i<d.count();i++){ int n=d.at(i); YumCopyJob *yjob=new YumCopyJob(); yjob->number=no; yjob->target=n; yjob->type="COPY"; yjob->desc=QString("%1.pom").arg(n); yjob->output+=QString("Duplicate of %1").arg(name); yjob->source=job->source; yjob->iso_filename=job->iso_filename; jobs.append(yjob); } } } thread.start(); ok(); }
static void panic(const char* routine) { carp(routine); exit(111); }
isc_result_t dlz_lookup(const char *zone, const char *name, void *dbdata, dns_sdlzlookup_t *lookup, dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo) #endif { isc_result_t retval; config_data_t *cd = (config_data_t *) dbdata; int rrcount, r; dlz_perl_clientinfo_opaque opaque; SV *record_ref; SV **rr_type; SV **rr_ttl; SV **rr_data; #ifdef MULTIPLICITY PerlInterpreter *my_perl = cd->perl; #endif #if DLZ_DLOPEN_VERSION >= 2 UNUSED(methods); UNUSED(clientinfo); #endif dSP; PERL_SET_CONTEXT(cd->perl); ENTER; SAVETMPS; opaque.methods = methods; opaque.clientinfo = clientinfo; PUSHMARK(SP); XPUSHs(cd->perl_class); XPUSHs(sv_2mortal(newSVpv(name, 0))); XPUSHs(sv_2mortal(newSVpv(zone, 0))); XPUSHs(sv_2mortal(newSViv((IV)&opaque))); PUTBACK; carp("DLZ Perl: Searching for name %s in zone %s", name, zone); rrcount = call_method("lookup", G_ARRAY|G_EVAL); carp("DLZ Perl: Call to lookup returned %i", rrcount); SPAGAIN; if (SvTRUE(ERRSV)) { POPs; cd->log(ISC_LOG_ERROR, "DLZ Perl: lookup died in eval: %s", SvPV_nolen(ERRSV)); retval = ISC_R_FAILURE; goto CLEAN_UP_AND_RETURN; } if (!rrcount) { retval = ISC_R_NOTFOUND; goto CLEAN_UP_AND_RETURN; } retval = ISC_R_SUCCESS; r = 0; while (r++ < rrcount) { record_ref = POPs; if ((!SvROK(record_ref)) || (SvTYPE(SvRV(record_ref)) != SVt_PVAV)) { cd->log(ISC_LOG_ERROR, "DLZ Perl: lookup returned an " "invalid value (expected array of arrayrefs)!"); retval = ISC_R_FAILURE; break; } record_ref = SvRV(record_ref); rr_type = av_fetch((AV *) record_ref, 0, 0); rr_ttl = av_fetch((AV *) record_ref, 1, 0); rr_data = av_fetch((AV *) record_ref, 2, 0); if (rr_type == NULL || rr_ttl == NULL || rr_data == NULL) { cd->log(ISC_LOG_ERROR, "DLZ Perl: lookup for record %s in " "zone %s returned an array that was " "missing data", name, zone); retval = ISC_R_FAILURE; break; } carp("DLZ Perl: Got record %s = %s", SvPV_nolen(*rr_type), SvPV_nolen(*rr_data)); retval = cd->putrr(lookup, SvPV_nolen(*rr_type), SvIV(*rr_ttl), SvPV_nolen(*rr_data)); if (retval != ISC_R_SUCCESS) { cd->log(ISC_LOG_ERROR, "DLZ Perl: putrr for lookup of %s in " "zone %s failed with code %i " "(did lookup return invalid record data?)", name, zone, retval); break; } } CLEAN_UP_AND_RETURN: PUTBACK; FREETMPS; LEAVE; carp("DLZ Perl: Returning from lookup, r = %i, retval = %i", r, retval); return (retval); }
isc_result_t dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo) #endif { config_data_t *cd = (config_data_t *) dbdata; int r; isc_result_t retval; #ifdef MULTIPLICITY PerlInterpreter *my_perl = cd->perl; #endif #if DLZ_DLOPEN_VERSION >= 3 UNUSED(methods); UNUSED(clientinfo); #endif dSP; carp("DLZ Perl: findzone looking for '%s'", name); PERL_SET_CONTEXT(cd->perl); ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs(cd->perl_class); XPUSHs(sv_2mortal(newSVpv(name, 0))); PUTBACK; r = call_method("findzone", G_SCALAR|G_EVAL); SPAGAIN; if (SvTRUE(ERRSV)) { /* * On error there's an undef at the top of the stack. Pop * it away so we don't leave junk on the stack for the next * caller. */ POPs; cd->log(ISC_LOG_ERROR, "DLZ Perl: findzone died in eval: %s", SvPV_nolen(ERRSV)); retval = ISC_R_FAILURE; } else if (r == 0) { retval = ISC_R_FAILURE; } else if (r > 1) { /* Once again, clean out the stack when possible. */ while (r--) POPi; cd->log(ISC_LOG_ERROR, "DLZ Perl: findzone returned too many parameters!"); retval = ISC_R_FAILURE; } else { r = POPi; if (r) retval = ISC_R_SUCCESS; else retval = ISC_R_NOTFOUND; } PUTBACK; FREETMPS; LEAVE; return (retval); }
isc_result_t dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) { config_data_t *cd = (config_data_t *) dbdata; isc_result_t retval; int rrcount, r; SV *record_ref; SV **rr_name; SV **rr_type; SV **rr_ttl; SV **rr_data; #ifdef MULTIPLICITY PerlInterpreter *my_perl = cd->perl; #endif dSP; PERL_SET_CONTEXT(cd->perl); ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs(cd->perl_class); XPUSHs(sv_2mortal(newSVpv(zone, 0))); PUTBACK; carp("DLZ Perl: Calling allnodes for zone %s", zone); rrcount = call_method("allnodes", G_ARRAY|G_EVAL); carp("DLZ Perl: Call to allnodes returned rrcount of %i", rrcount); SPAGAIN; if (SvTRUE(ERRSV)) { POPs; cd->log(ISC_LOG_ERROR, "DLZ Perl: allnodes for zone %s died in eval: %s", zone, SvPV_nolen(ERRSV)); retval = ISC_R_FAILURE; goto CLEAN_UP_AND_RETURN; } if (!rrcount) { retval = ISC_R_NOTFOUND; goto CLEAN_UP_AND_RETURN; } retval = ISC_R_SUCCESS; r = 0; while (r++ < rrcount) { record_ref = POPs; if ( (!SvROK(record_ref)) || (SvTYPE(SvRV(record_ref)) != SVt_PVAV) ) { cd->log(ISC_LOG_ERROR, "DLZ Perl: allnodes for zone %s " "returned an invalid value " "(expected array of arrayrefs)", zone); retval = ISC_R_FAILURE; break; } record_ref = SvRV(record_ref); rr_name = av_fetch((AV *) record_ref, 0, 0); rr_type = av_fetch((AV *) record_ref, 1, 0); rr_ttl = av_fetch((AV *) record_ref, 2, 0); rr_data = av_fetch((AV *) record_ref, 3, 0); if (rr_name == NULL || rr_type == NULL || rr_ttl == NULL || rr_data == NULL) { cd->log(ISC_LOG_ERROR, "DLZ Perl: allnodes for zone %s " "returned an array that was missing data", zone); retval = ISC_R_FAILURE; break; } carp("DLZ Perl: Got record %s/%s = %s", SvPV_nolen(*rr_name), SvPV_nolen(*rr_type), SvPV_nolen(*rr_data)); retval = cd->putnamedrr(allnodes, SvPV_nolen(*rr_name), SvPV_nolen(*rr_type), SvIV(*rr_ttl), SvPV_nolen(*rr_data)); if (retval != ISC_R_SUCCESS) { cd->log(ISC_LOG_ERROR, "DLZ Perl: putnamedrr in allnodes " "for zone %s failed with code %i " "(did lookup return invalid record data?)", zone, retval); break; } } CLEAN_UP_AND_RETURN: PUTBACK; FREETMPS; LEAVE; carp("DLZ Perl: Returning from allnodes, r = %i, retval = %i", r, retval); return (retval); }
int main(int argc, char **argv) { char *x, *me = argv[0]; char *last_msg = "\\c"; errmsg_iam(me); if (argc<2) { help: errmsg_iam(0); carp(Kill_Help); _exit(1); } argv++; x = argv[0]; if (x[0]=='-' && x[1]=='h') goto help; /* -h... --help */ opendevconsole(); /* ignore next signals */ set_sa(SIGQUIT); set_sa(SIGCHLD); set_sa(SIGHUP ); set_sa(SIGTSTP); set_sa(SIGTTIN); set_sa(SIGTTOU); while (argv[0] && argv[0][0]=='-') { int sig=0, cfg_wall=0; char *y = argv[0] + 1; if ((unsigned int)(*y - '0') < 10) { sig = x_atoi(y); goto again; } switch(*y) { case 'v': cfg_verbose++; if (y[1]=='v') cfg_verbose++; break; case 'q': set_sa(SIGINT); break; case 's': chk_opt(argv,x); deep_sleep(x); break; case 'W': ++cfg_wall; case 'M': chk_opt(argv,x); if (x[0] == '%' && x[1] == 0) x = last_msg; else last_msg = x; print_escape(x, cfg_wall); break; case 'E': chk_opt(argv,x); *argv = x; execve(argv[0], argv, environ); carp("Unable to exec: ", argv[0]); _exit(1); default: #ifdef NSVC_SIGNAL_CODED { unsigned char *S, *Sig = (unsigned char *)NSVC_SIGNAL_CODED; for (S=Sig; *S; S += 2) if ((unsigned char)*y == *S) { sig = S[1]; goto again; } } #else #define kk(C,S) case C: sig=S; break kk('t',SIGTERM); kk('a',SIGALRM); kk('p',SIGSTOP); kk('c',SIGCONT); kk('h',SIGHUP); kk('i',SIGINT); kk('k',SIGKILL); #endif goto help; } again: if (sig > 0) { sync(); if (cfg_verbose) msg("Sending signal: ", y); if (kill(-1, sig)) carp("Unable to send signal: ", y); } argv++; } sync(); return 0; }