int main() { const int gid = getgid(), uid = getuid(); char content[128]; format_string(content); format_print("Parent", content); pipe(pipefd); format_print("Parent", "start a container!"); int container_pid = clone(container_main, container_stack + STACK_SIZE , CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWPID | CLONE_NEWNS | CLONE_NEWUSER | SIGCHLD, NULL); char content2[64]; sprintf(content2, "Container [%5d]!", container_pid); format_print("Parent", content2); set_uid_map(container_pid, 0, uid, 1); set_gid_map(container_pid, 0, gid, 1); format_print("Parent", "user/group mapping done!"); close(pipefd[1]); waitpid(container_pid, NULL, 0); format_print("Parent", "container stopped!"); return 0; }
int main() { format_print("Parent", "start a container!"); int container_pid = clone(container_main, container_stack + STACK_SIZE , CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWPID | CLONE_NEWNS | SIGCHLD, NULL); waitpid(container_pid, NULL, 0); format_print("Parent", "container stopped!"); return 0; }
int main () { for (;;) { char *line = NULL; size_t line_size = 0; int line_len; char *invalid_reason; void *descr; line_len = getline (&line, &line_size, stdin); if (line_len < 0) break; if (line_len > 0 && line[line_len - 1] == '\n') line[--line_len] = '\0'; invalid_reason = NULL; descr = format_parse (line, false, &invalid_reason); format_print (descr); printf ("\n"); if (descr == NULL) printf ("%s\n", invalid_reason); free (invalid_reason); free (line); } return 0; }
int printf(const char *format,...) { int i; int printed_simbols; va_list arg; char simbol[]={"%s"}; char *s; va_start(arg,format); if (console_init_status==0) { i=init_console(); console_init_status=1; } if (i==0) { s=malloc(4096); printed_simbols=format_print(s,4096,format,arg); con_printf(simbol,s); free(s); } return(printed_simbols); }
static void print_nlists_32(char *ptr, struct nlist **t_el, char *st, int nsyms) { int i; char c; i = 0; while (i < nsyms) { c = get_symbol(ptr, t_el[i], FT_NM_CPU_32); if (c == 'A' || (c != 'u' && c != 'c' && *(st + t_el[i]->n_un.n_strx) && *(st + t_el[i]->n_un.n_strx) != '/' && (!t_el[i]->n_value || (i == nsyms - 1) || ((t_el[i]->n_value != t_el[i + 1]->n_value) || ft_strcmp(st + t_el[i]->n_un.n_strx, st + t_el[i + 1]->n_un.n_strx))))) { if (c != 'U' && c != 'I') ft_putnbr_base(t_el[i]->n_value, FT_NM_BASE, FT_NM_ADDR_LEN_32); else ft_putnchar(' ', FT_NM_ADDR_LEN_32); format_print(t_el[i], st, c); } ++i; } }
void printH(const char *format, ...) { __builtin_va_list ap; va_start(ap, format); format_print(format, ap); va_end(ap); }
int container_main(void *arg) { format_print("Container", "inside the container!"); sethostname("container", 10); if(mount("proc", "rootfs/proc", "proc", 0, NULL) != 0) { perror("proc"); } if(mount("sysfs", "rootfs/sys", "sysfs", 0, NULL) != 0) { perror("sys"); } if(mount("none", "rootfs/tmp", "tmpfs", 0, NULL) != 0) { perror("tmp"); } if(mount("udev", "rootfs/dev", "devtmpfs", 0, NULL) != 0) { perror("dev"); } if(mount("devpts", "rootfs/dev/pts", "devpts", 0, NULL) != 0) { perror("dev/pts"); } if(mount("shm", "rootfs/dev/shm", "tmpfs", 0, NULL) != 0) { perror("dev"); } if(mount("tmpfs", "rootfs/run", "tmpfs", 0, NULL) != 0) { perror("dev"); } if(mount("conf/hosts", "rootfs/etc/hosts", "none", MS_BIND, NULL) != 0 || mount("conf/hostname", "rootfs/etc/hostname", "none", MS_BIND, NULL) != 0 || mount("conf/resolv.conf", "rootfs/etc/resolv.conf", "none", MS_BIND, NULL) != 0) { perror("conf"); } // mount a local dir to the dir in container if(mount("/tmp/t1", "rootfs/mnt", "none", MS_BIND, NULL) != 0) { perror("mnt"); } // set up the root dir if(chdir("./rootfs") != 0 || chroot("./") != 0) { perror("chdir/chroot"); } execv(container_args[0], container_args); perror("exec"); format_print("Container", "Something's wrong!"); return 1; }
int container_main(void *arg) { format_print("Container", "inside the container!"); char content[128]; format_string(content); format_print("Container", content); char ch; close(pipefd[1]); read(pipefd[0], &ch, 1); format_print("Container", "setup hostname!"); sethostname("container", 10); mount("proc", "/proc", "proc", 0, NULL); execv(container_args[0], container_args); format_print("Container", "Something's wrong!"); return 1; }
/* print the group block infomation */ void print_group_block(struct group_block gb) { const char *help[]={ "块位图起始地址(块号)", "i-节点位图起始地址(块号)", "i-节点表起始地址(块号)", "该块组中的空闲块数", "该块组中的空闲i-节点数", "该块组中的目录数", "未使用", }; char data[50][50]; memset(data,0,sizeof(data)); int i=0; format_print(data[i++],0x00,0x03,gb.bitmap_Start_Block); format_print(data[i++],0x04,0x07,gb.nodemap_Start_Block); format_print(data[i++],0x08,0x0B,gb.nodetable_Start_Blcoks); format_print(data[i++],0x0C,0x0D,gb.free_Blocks); format_print(data[i++],0x0E,0x0F,gb.free_Nodes); format_print(data[i++],0x10,0x11,gb.free_Dir); //*format_print_s(data[i++],0x12,0x1F,"no print now"/*gb.no_Used*/); int count=i,max=0,tmp,spaceCount=4; for ( i=0;i<count;i++){ tmp=strlen(data[i]); max=max < tmp? tmp:max;} for ( i=0;i<count;i++) { printf("%s",data[i]); for (tmp=max-strlen(data[i])+spaceCount;tmp>0;tmp--) printf(" "); printf("%s\n",help[i]); } }
int fprintf(FILE* file, const char* format, ...) { va_list arg; char *buf; int printed; //int data[4]; va_start (arg, format); buf=malloc(4096*2); //8kb max //data[0]=(int)&arg-(int)&format; printed=format_print(buf,8191, format,arg); fwrite(buf,printed,1,file); free(buf); return(printed); }
main(int argc, char **argv) { char *seq; int start = 0; int end = -1; int count = 0; int rev = 0; int width = 50; char *pattern = "."; char *file = NULL; struct extract_info fi; int opt; int opt_index=0; #ifdef HAVE_GETOPT static struct option cmd_options[] = { {"in",1,0,'i'}, {"baseSkip",1,0,'s'}, {"baseskip",1,0,'s'}, {"baseCount",1,0,'c'}, {"basecount",1,0,'c'}, {"baseEnd",1,0,'e'}, {"baseend",1,0,'e'}, {"pattern",1,0,'p'}, {"width",1,0,'w'}, {"rev",0,0,'r'}, {0,0,0,0} }; #endif bzero(&fi,sizeof(struct extract_info)); fi.regex_flags = REG_EXTENDED; while (1) { #ifdef HAVE_GETOPT opt=getopt_long_only(argc,argv,"i:s:c:e:p:w:r",cmd_options,&opt_index); #else opt=getopt(argc,argv,"i:s:c:e:p:w:r"); #endif if (opt==-1 ) break; switch (opt) { case 's': start = atoi(optarg); break; case 'e': end = atoi(optarg); break; case 'c': count = atoi(optarg); break; case 'w': width = atoi(optarg); break; case 'r': rev = 1; break; case 'p': pattern = strdup(optarg); break; case 'i': file = strdup(optarg); break; } } if (! file) usage(argv[0]); for( seq = seq_extract(file,pattern,start,end,&fi); seq != NULL; seq = seq_extract(file,pattern,start,end,&fi) ) { printf("%s\n",fi.header); format_print(seq,width,rev); } }
/* print the extX file system support block information */ void print_super_block(struct super_block sb) { const char *help[]={ "文件系统总的i-节点数", "文件系统总块数", "文件系统预保留的快数", "空闲快数", "空闲i-节点数", "0号快组起始快号", "快大小(此值为1024左移动位数)", "片段大小(与快大小字段相同)", "每个快组所包含快数", "每个快组所包含片段数", "每个快组i-节点数", "最后挂载时间", "最后写入时间", "当前挂载数", "最大挂载数", "签名标志53EF", "文件系统状态(1-正常,3-有错误)", "错误处理方式", "辅版本级别", "最后进行一致性检查时间", "一致性检查间隔时间", "创建本文件系统的操作系统(0-linux)", "主版本级别(1-动态)", "默认UID保留块", "默认GID保留块", "第一个非保留i-节点", "每个i-节点结构大小", "本超级块所在的块组号", "兼容特征标志(0x10-自调节大小)", "非兼容特征标志", "只读兼容特征标志(1-稀疏超级快和组描述符表)", "文件系统ID", "卷名", "最后挂载路径", "位图使用运算法则", "文件再分配块数", "目录再分配块数", "未使用", "日志ID", "日志i-节点", "日志设备", "孤立i-节点表头", "未使用", }; char data[50][50]; memset(data,0,sizeof(data)); int i=0; format_print(data[i++],0x00,0x03,sb.total_Node); format_print(data[i++],0x04,0x07,sb.total_Blocks); format_print(data[i++],0x08,0x0B,sb.retain_Blcoks); format_print(data[i++],0x0C,0x0F,sb.free_Blocks); format_print(data[i++],0x10,0x13,sb.free_Node); format_print(data[i++],0x14,0x17,sb.No_0_Block); format_print_Ex(data[i++],0x18,0x1B,sb.block_Size,1024 << sb.block_Size); format_print_Ex(data[i++],0x1C,0x1F,sb.part_Size,1024 << sb.part_Size); format_print(data[i++],0x20,0x23,sb.block_Group_Blocks); format_print(data[i++],0x24,0x27,sb.block_Group_Parts); format_print(data[i++],0x28,0x2B,sb.block_Group_Nodes); format_print_Ex_t(data[i++],0x2C,0x2F,sb.last_Mount_Time); format_print_Ex_t(data[i++],0x30,0x33,sb.last_Write_Time); format_print(data[i++],0x34,0x35,sb.current_Mounts); format_print(data[i++],0x36,0x37,sb.max_Mounts); format_print(data[i++],0x38,0x39,sb.signature_Logo); format_print(data[i++],0x3A,0x3B,sb.filesystem_State); format_print(data[i++],0x3C,0x3D,sb.err_deal_with); format_print(data[i++],0x3E,0X3F,sb.assist_Version); format_print_Ex_t(data[i++],0x40,0x43,sb.last_Check_Time); format_print(data[i++],0x44,0x47,sb.check_Interval_Time); format_print(data[i++],0x48,0x4B,sb.create_os); format_print(data[i++],0x4C,0x4F,sb.main_Version); format_print(data[i++],0x50,0x51,sb.UID_Block); format_print(data[i++],0x52,0x53,sb.GID_Block); format_print(data[i++],0x54,0x57,sb.No_1_Noretain_Node); format_print(data[i++],0x58,0x59,sb.node_Size); format_print(data[i++],0x5A,0x5B,sb.super_Block_Group); format_print(data[i++],0x5C,0x5F,sb.signature_Compatible); format_print(data[i++],0x60,0x63,sb.signature_Uncompatible); format_print(data[i++],0x64,0x67,sb.signature_Readonly_Compatible); //char data format_print_s(data[i++],0x68,0x77,"no print now"/*sb.filesytem_ID*/); format_print_s(data[i++],0x78,0x87,sb.volume_Name); format_print_s(data[i++],0x88,0xC7,sb.last_Mount_Path); format_print(data[i++],0xC8,0xCB,sb.bitmap_rules); format_print(data[i++],0xCC,0xCC,sb.file_Redistribution_Blocks); format_print(data[i++],0xCD,0xCD,sb.dir_Redistribution_Blocks); format_print(data[i++],0xCE,0xCF,sb.no_Used1); //char data format_print_s(data[i++],0xD0,0xDF,sb.log_ID); format_print(data[i++],0xE0,0xE3,sb.log_Node); format_print(data[i++],0xE4,0xE7,sb.log_drive); format_print(data[i++],0xE8,0xEB,sb.isolate_Node_Table_Head); format_print_s(data[i++],0xEC,0x3FF,"no print now"/*sb.no_Used2*/); int count=i,max=0,tmp; for ( i=0;i<count;i++){ tmp=strlen(data[i]); max=max < tmp? tmp:max;} printf("文件系统UUID: %s\n",print_UUID(sb.filesytem_ID)); for ( i=0;i<count;i++) { printf("%s",data[i]); for (tmp=max-strlen(data[i])+3;tmp>0;tmp--) printf(" "); printf("%s\n",help[i]); } }
static int mail_user(struct offenderlist *offender, struct configparams *config) { struct usage *lptr; FILE *fp; int cnt, status; char timebuf[MAXTIMELEN]; char numbuf[3][MAXNUMLEN]; struct util_dqblk *dqb; char *to = NULL; if (offender->offender_type == USRQUOTA) { to = lookup_user(config, offender->offender_name); if (!to) return -1; } else { struct adminstable *admin; if (!(admin = bsearch(offender->offender_name, adminstable, adminscnt, sizeof(struct adminstable), admin_name_cmp))) { errstr(_("Administrator for a group %s not found. Cancelling mail.\n"), offender->offender_name); return -1; } to = sstrdup(admin->adminname); } if (!(fp = run_mailer(config->mail_cmd))) { if (to) free(to); return -1; } fprintf(fp, "From: %s\n", config->from); fprintf(fp, "Reply-To: %s\n", config->support); fprintf(fp, "Subject: %s\n", config->subject); fprintf(fp, "To: %s\n", to); if (should_cc(offender, config)) { char *cc_to = lookup_user(config, config->cc_to); if (cc_to) { fprintf(fp, "Cc: %s\n", config->cc_to); free(cc_to); } } if ((config->charset)[0] != '\0') { /* are we supposed to set the encoding */ fprintf(fp, "MIME-Version: 1.0\n"); fprintf(fp, "Content-Type: text/plain; charset=%s\n", config->charset); fprintf(fp, "Content-Disposition: inline\n"); fprintf(fp, "Content-Transfer-Encoding: 8bit\n"); } fprintf(fp, "\n"); free(to); if (offender->offender_type == USRQUOTA) if (config->user_message) format_print(fp, config->user_message, offender->offender_name); else fputs(DEF_USER_MESSAGE, fp); else if (config->group_message) format_print(fp, config->group_message, offender->offender_name); else fprintf(fp, DEF_GROUP_MESSAGE, offender->offender_name); if (!(flags & FL_NODETAILS)) { for (lptr = offender->usage; lptr; lptr = lptr->next) { dqb = &lptr->dq_dqb; for (cnt = 0; cnt < qtab_i; cnt++) if (!strcmp(quotatable[cnt].devname, lptr->devicename)) { fprintf(fp, "\n%s (%s)\n", quotatable[cnt].devdesc, quotatable[cnt].devname); break; } if (cnt == qtab_i) /* Description not found? */ fprintf(fp, "\n%s\n", lptr->devicename); fprintf(fp, _("\n Block limits File limits\n")); fprintf(fp, _("Filesystem used soft hard grace used soft hard grace\n")); if (strlen(lptr->devicename) > 15) fprintf(fp, "%s\n%15s", lptr->devicename, ""); else fprintf(fp, "%-15s", lptr->devicename); if (dqb->dqb_bsoftlimit && dqb->dqb_bsoftlimit <= toqb(dqb->dqb_curspace)) difftime2str(dqb->dqb_btime, timebuf); else timebuf[0] = '\0'; space2str(toqb(dqb->dqb_curspace), numbuf[0], flags & FL_SHORTNUMS); space2str(dqb->dqb_bsoftlimit, numbuf[1], flags & FL_SHORTNUMS); space2str(dqb->dqb_bhardlimit, numbuf[2], flags & FL_SHORTNUMS); fprintf(fp, "%c%c %7s %7s %7s %6s", dqb->dqb_bsoftlimit && toqb(dqb->dqb_curspace) >= dqb->dqb_bsoftlimit ? '+' : '-', dqb->dqb_isoftlimit && dqb->dqb_curinodes >= dqb->dqb_isoftlimit ? '+' : '-', numbuf[0], numbuf[1], numbuf[2], timebuf); if (dqb->dqb_isoftlimit && dqb->dqb_isoftlimit <= dqb->dqb_curinodes) difftime2str(dqb->dqb_itime, timebuf); else timebuf[0] = '\0'; number2str(dqb->dqb_curinodes, numbuf[0], flags & FL_SHORTNUMS); number2str(dqb->dqb_isoftlimit, numbuf[1], flags & FL_SHORTNUMS); number2str(dqb->dqb_ihardlimit, numbuf[2], flags & FL_SHORTNUMS); fprintf(fp, " %7s %5s %5s %6s\n\n", numbuf[0], numbuf[1], numbuf[2], timebuf); } } if (offender->offender_type == USRQUOTA) if (config->user_signature) format_print(fp, config->user_signature, offender->offender_name); else fprintf(fp, DEF_USER_SIGNATURE, config->support, config->phone); else if (config->group_signature) format_print(fp, config->group_signature, offender->offender_name); else fprintf(fp, DEF_GROUP_SIGNATURE, config->support, config->phone); fclose(fp); if (wait(&status) < 0) /* Wait for mailer */ errstr(_("Cannot wait for mailer: %s\n"), strerror(errno)); else if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) errstr(_("Warning: Mailer exitted abnormally.\n")); return 0; }
int vsnprintf(char *dest, size_t size,const char *format,va_list ap) { return format_print(dest,size, format, ap); }
void CWeapon::describe(_wintype* window, int y) { if (name == "None") return; _wputstring(window, y, 1, TITLE_COLOR, "Price:"); _wputcstr(window, y, 11, LIGHTGRAY, "%d", price); _wputstring(window, y, 26, TITLE_COLOR, "Hands:"); _wputstring(window, y, 37, LIGHTGRAY, twoHanded ? "Two" : "One" ); _wputstring(window, y + 1, 1, TITLE_COLOR, "Set:"); _wputstring(window, y + 1, 11, LIGHTGRAY, Set->name); if (weight) { _wputstring(window, y + 1, 26, TITLE_COLOR, "Weight:"); _wputcstr(window, y + 1, 37, LIGHTGRAY, "%d", weight); } y += 3; y = format_print(window, y, "Attack: +%d Hit: +%d", Atk, Hit); if (Set->name == "Ammunition") y = format_print(window, y, "You can carry a number of extra Ammunitions equal to your Strength. \ To throw this, equip it and attack the enemy."); if (range > 1 && Set->name != "Ammunition") y = format_print(window, y, "Deals full damage from the back row."); if (Set->name == "Gun") y = format_print(window, y, "Your strength does not impact the damage dealt."); if (adds) y = format_print(window, y, "Adds %s to the foe.", comma_list(status_to_buffer(adds)).c_str()); if (always) y = format_print(window, y, "You always have the status %s.", comma_list(status_to_buffer(always)).c_str()); if (cancels) y = format_print(window, y, "Cancels %s.", comma_list(status_to_buffer(cancels)).c_str()); if (casts) if (Set->name == "Ammunition") y = format_print(window, y, "Casts %s.", casts->name.c_str()); else y = format_print(window, y, "May cast %s upon wounding the foe.", casts->name.c_str()); if (element) { buffer buf = element_to_buffer(element); std::string ess = buf.size() == 1 ? "" : "s"; y = format_print(window, y, "It is imbued with the element%s %s.", ess.c_str(), comma_list(buf).c_str()); } if (grantsA) y = format_print(window, y, "Grants the ability %s.", grantsA->name.c_str()); if (grantsS) y = format_print(window, y, "Can be invoked to cast %s.", grantsS->name.c_str()); if (hurts) y = format_print(window, y, "Does extra damage to %s.", comma_list(race_to_buffer(hurts)).c_str()); if (starts) y = format_print(window, y, "You begin battle with the status %s.", comma_list(status_to_buffer(starts)).c_str()); if (strengthens) y = format_print(window, y, "Your %s attacks deal extra damage.", comma_list(element_to_buffer(strengthens)).c_str()); }
int sprintf(char *dest,const char *format,...) { va_list arg; va_start (arg, format); return format_print(dest,4096, format, arg); }