int cmd_run(int argc,char **argv,struct sub_command* cmd) { char* current=get_opt("program",0); cond_printf(1,"cmd_%s:argc=%d argv[0]=%s\n",cmd->name,argc,argv[0]); if(argc==1 && !current) { char* tmp[]={(char*)cmd->name,"--"}; return proccmd(2,tmp,top_options,top_commands); }else { int i; for(i=1;i<argc;i+=proccmd(argc-i,&argv[i],run_options,run_commands)); if(strcmp((char*)cmd->name,ROS_RUN_REPL)!=0) { char* tmp[]={"--"}; proccmd(1,tmp,run_options,run_commands); }else { char* tmp[]={"--",ROS_RUN_REPL}; proccmd(1,tmp,run_options,run_commands); } cond_printf(1,"cmd_%s ends here %d\n",cmd->name,i); return i; } }
int cmd_script_frontend(int argc,char **argv,struct sub_command* cmd) { FILE* in; char buf[800]; int i=0,j,c; int argc_; char** argv_; char** argv_gen; struct opts* opt; if(script_frontend_sentinel) return cmd_script(argc,argv,cmd); script_frontend_sentinel=1; if(strcmp(argv[0],"--")==0) ++argv,--argc; cond_printf(1,"frontend:script_%s:argc=%d argv[0]=%s\n",cmd->name,argc,argv[0]); for(opt=local_opt;opt;opt=opt->next) if(strcmp(opt->name,"lisp")==0) opt->name=s_cat(q("*"),opt->name,NULL); if((in=fopen(argv[0],"rb"))!=NULL) { if(fgetc(in)!='#'||fgetc(in)!='!') { fclose(in); cmd_script(argc,argv,cmd); } for(i=0;i<3;++i) while((c=fgetc(in))!=EOF && c!='\n'); for(i=0;(c=fgetc(in))!=EOF;buf[i++]=c) if(c=='\r'||c=='\n'||i==799) break; fclose(in); } buf[i]='\0'; cond_printf(1,"ros_script_cmd=%s\n",buf); argv_=parse_cmdline(buf,&argc_); argv_gen=alloc(sizeof(char**)*(argc+argc_)); for(i=0;i<argc_-2&&strcmp(argv_[i+2],"$0")!=0;++i) argv_gen[i]=argv_[i+2]; for(j=i;i<j+argc;++i) argv_gen[i]=argv[i-j]; j=i; for(i=0;i<j;i+=proccmd(j-i,&argv_gen[i],top_options,top_commands)); return 0; }
int cmd_script(int argc,char **argv,struct sub_command* cmd) { char* current=get_opt("program",0); cond_printf(1,"script_%s:argc=%d argv[0]=%s\n",cmd->name,argc,argv[0]); cond_printf(1,"current=%s\n",current); if(argc==1 && !current && strcmp(argv[0],"--")==0) { char* tmp[]={"help","--"}; return proccmd(2,tmp,top_options,top_commands); }else { char* result=q(""); char* tmp[]={"script"}; int i=strcmp(argv[0],"--")==0?1:0; for (;i<argc;++i) { char* val=escape_string(argv[i]); result=cat(result,"\"",val,"\"",NULL); s(val); } set_opt(&local_opt,"script",result,0); s(result); cmd_run_star(1,tmp,cmd); } return 0; }
int install_help(int argc,char **argv,struct sub_command* cmd) { if(argc==1) { cond_printf(0,"Usage: %s install impl [OPTIONS]\n\nFor more details on impl specific options, type:\n %s help install impl\n\n" "Candidates impls for installation are:\n",argv_orig[0],argv_orig[0]); char* install=lispdir(); LVal d=directory(install),v=d; for(;v;v=Next(v)) { char* str=firsts(v); if(str[strlen(str)-1]!='/') { int p=position_char(".",str); if(p!=-1) { char *sub=subseq(str,0,p); if(p>=8/*strlen("install-")*/ && strncmp(str,"install-",8)==0) printf("%s\n",sub+8); s(sub); } } } sL(d); }else if(argc==2) { int i,j,argc_; char** tmp; char* install_ros=s_cat2(lispdir(),q("install.ros")); tmp=(char**)alloc(sizeof(char*)*(argc+9)); i=0; tmp[i++]=q("--"); tmp[i++]=install_ros; tmp[i++]=q("help"); tmp[i++]=q(argv[1]); for(j=2;j<argc;tmp[i++]=q(argv[j++])); argc_=i; for(i=0;i<argc_;i+=proccmd(argc_-i,&tmp[i],top_options,top_commands)); for(j=0;j<argc_;s(tmp[j++])); dealloc(tmp); } return 0; }
int cmd_internal(int argc,char **argv,struct sub_command* cmd) { setup_uid(0); return proccmd(argc-1,&(argv[1]),(LVal)NULL,internal_commands); }
int cmd_install(int argc,char **argv,struct sub_command* cmd) { install_cmds *cmds=NULL; struct install_options param; quicklisp=1; param.os=uname(); param.arch=uname_m(); param.arch_in_archive_name=0; param.expand_path=NULL; if(argc!=1) { int ret=1,k; for(k=1;k<argc;++k) { int i,pos; param.impl=argv[k]; pos=position_char("/",param.impl); if(pos!=-1) { param.version=subseq(param.impl,pos+1,0); param.impl=subseq(param.impl,0,pos); }else { param.version=NULL; param.impl=q(param.impl); } for(install_impl=NULL,i=0;i<sizeof(impls_to_install)/sizeof(struct install_impls*);++i) { struct install_impls* j=impls_to_install[i]; if(strcmp(param.impl,j->name)==0) { install_impl=j; } } if(install_impl) { for(cmds=install_impl->call;*cmds&&ret;++cmds) ret=(*cmds)(¶m); if(ret) { // after install latest installed impl/version should be default for 'run' struct opts* opt=global_opt; struct opts** opts=&opt; char* home=configdir(); char* path=cat(home,"config",NULL); char* v=cat(param.impl,".version",NULL); char* version=param.version; if(!install_impl->util) { int i; for(i=0;version[i]!='\0';++i) if(version[i]=='-') version[i]='\0'; set_opt(opts,"default.lisp",param.impl,0); set_opt(opts,v,version,0); save_opts(path,opt); } s(home),s(path),s(v); } }else { char* lisp_path=lispdir(); int i,j,argc_; char** tmp; char* install_ros=s_cat2(lisp_path,q("install.ros")); if(verbose&1) { fprintf(stderr,"%s is not implemented internal. %s argc:%d\n",param.impl,install_ros,argc); for(i=0;i<argc;++i) fprintf(stderr,"%s:",argv[i]); fprintf(stderr,"\n"); } tmp=(char**)alloc(sizeof(char*)*(argc+9)); i=0; tmp[i++]=q("--"); tmp[i++]=install_ros; tmp[i++]=q("install"); tmp[i++]=q(argv[1]); for(j=2;j<argc;tmp[i++]=q(argv[j++])); argc_=i; if(verbose&1) { int j; fprintf(stderr,"argc_=%d",argc_); for(j=0;j<argc_;++j) fprintf(stderr,"argv[%d]=%s,",j,tmp[j]); } for(i=0;i<argc_;i+=proccmd(argc_-i,&tmp[i],top_options,top_commands)); for(j=0;j<argc_;s(tmp[j++])); dealloc(tmp); return 0; } if(param.version)s(param.version); s(param.impl),s(param.arch),s(param.os); s(param.expand_path); if(!ret) exit(EXIT_FAILURE); } }else { char* tmp[]={"help","install"}; proccmd(2,tmp,top_options,top_commands); exit(EXIT_SUCCESS); } return 0; }
int photoproc(struct tstat *tasklist, int maxtask) { static int firstcall = 1; static unsigned long long bootepoch; register struct tstat *curtask; FILE *fp; DIR *dirp; struct dirent *entp; char origdir[1024]; int tval=0; /* ** one-time initialization stuff */ if (firstcall) { /* ** check if this kernel offers io-statistics per task */ regainrootprivs(); if ( (fp = fopen("/proc/1/io", "r")) ) { supportflags |= IOSTAT; fclose(fp); } if (! droprootprivs()) cleanstop(42); /* ** find epoch time of boot moment */ bootepoch = getboot(); firstcall = 0; } /* ** probe if the netatop module and (optionally) the ** netatopd daemon are active */ regainrootprivs(); netatop_probe(); if (! droprootprivs()) cleanstop(42); /* ** read all subdirectory-names below the /proc directory */ if ( getcwd(origdir, sizeof origdir) == NULL) cleanstop(53); if ( chdir("/proc") == -1) cleanstop(53); dirp = opendir("."); while ( (entp = readdir(dirp)) && tval < maxtask ) { /* ** skip non-numerical names */ if (!isdigit(entp->d_name[0])) continue; /* ** change to the process' subdirectory */ if ( chdir(entp->d_name) != 0 ) continue; /* ** gather process-level information */ curtask = tasklist+tval; if ( !procstat(curtask, bootepoch, 1)) /* from /proc/pid/stat */ { if ( chdir("..") == -1); continue; } if ( !procstatus(curtask) ) /* from /proc/pid/status */ { if ( chdir("..") == -1); continue; } if ( !procio(curtask) ) /* from /proc/pid/io */ { if ( chdir("..") == -1); continue; } proccmd(curtask); /* from /proc/pid/cmdline */ // read network stats from netatop netatop_gettask(curtask->gen.tgid, 'g', curtask); tval++; /* increment for process-level info */ /* ** if needed (when number of threads is larger than 0): ** read and fill new entries with thread-level info */ if (curtask->gen.nthr > 1) { DIR *dirtask; struct dirent *tent; curtask->gen.nthrrun = 0; curtask->gen.nthrslpi = 0; curtask->gen.nthrslpu = 0; /* ** open underlying task directory */ if ( chdir("task") == 0 ) { dirtask = opendir("."); while ((tent=readdir(dirtask)) && tval<maxtask) { struct tstat *curthr = tasklist+tval; /* ** change to the thread's subdirectory */ if ( tent->d_name[0] == '.' || chdir(tent->d_name) != 0 ) continue; if ( !procstat(curthr, bootepoch, 0)) { if ( chdir("..") == -1); continue; } if ( !procstatus(curthr) ) { if ( chdir("..") == -1); continue; } if ( !procio(curthr) ) { if ( chdir("..") == -1); continue; } switch (curthr->gen.state) { case 'R': curtask->gen.nthrrun += 1; break; case 'S': curtask->gen.nthrslpi += 1; break; case 'D': curtask->gen.nthrslpu += 1; break; } curthr->gen.nthr = 1; // read network stats from netatop netatop_gettask(curthr->gen.pid, 't', curthr); // all stats read now tval++; /* increment thread-level */ if ( chdir("..") == -1); /* thread */ } closedir(dirtask); if ( chdir("..") == -1); /* leave task */ } } if ( chdir("..") == -1); /* leave process-level directry */ } closedir(dirp); if ( chdir(origdir) == -1) cleanstop(53); return tval; }