static void showHelp(int fd, char const *cmd, int res) { VSERVER_DECLARE_CMD(cmd); WRITE_MSG(fd, "Usage: "); WRITE_STR(fd, cmd); WRITE_MSG(fd, " [-g] --xid <xid> <TAG>*\n" " or "); WRITE_STR(fd, cmd); WRITE_MSG(fd, " -s --xid <xid> -t <TAG>=<VALUE> [--] [<command> <args>*]\n" " or "); WRITE_STR(fd, cmd); WRITE_MSG(fd, " --dir <dir> --xid <xid> [--missingok] [--] [<command> <args>*]\n\n" " Options:\n" " -g ... get and print the value\n" " -s ... set the value\n\n" " --xid <xid> ... operate on this context; 'self' means the current one\n" " -t <TAG>=<VALUE>\n" " ... set <TAG> to <VALUE>; this option can be repeated multiple time\n" " --dir <dir> ... read values from files in <dir>. These files must\n" " have a valid TAG as their name\n" " --missingok ... do not fail when the <DIR> from '--dir' does not exist.\n" "\n" " Possible values for TAG are:\n" " context, sysname, nodename, release, version, machine, domainname\n" "\n" "Please report bugs to " PACKAGE_BUGREPORT "\n"); exit(res); }
static bool checkFile(char const *fname) { int fd = Eopen(fname, O_RDONLY, 0); off_t l = Elseek(fd, 0, SEEK_END); char const * data = 0; bool res = true; if (l>100*1024*1024) { WRITE_MSG(2, "WARNING: '"); WRITE_STR(2, fname); WRITE_STR(2, "' is too large for a vserver configuration file\n"); res = false; } else if (l>0) { data = mmap(0, l, PROT_READ, MAP_PRIVATE, fd, 0); if (data==MAP_FAILED) { perror("mmap()"); exit(wrapper_exit_code); } if (data[l-1]!='\n') { WRITE_MSG(2, "WARNING: '"); WRITE_STR(2, fname); WRITE_MSG(2, "' does not end on newline\n"); res = false; } munmap(const_cast(char *)(data), l); }
main() { int i; char buf[1024]; STD_TERM *term; term = Init_Terminal(); Write_Char('-', 50); WRITE_STR("\r\n"); #ifdef WIN32 test(term, "text\010\010st\n"); //bs bs test(term, "test\001xxxx\n"); // home test(term, "test\001\005xxxx\n"); // home test(term, "\033[A\n"); // up arrow #endif do { WRITE_STR(">> "); i = Read_Line(term, buf, 1000); printf("len: %d %s\r\n", i, term->out); } while (i > 0); Quit_Terminal(term); }
void _perror_r (struct _reent *ptr, const char *s) { char *error; int dummy; FILE *fp = _stderr_r (ptr); CHECK_INIT (ptr, fp); _newlib_flockfile_start(fp); _fflush_r (ptr, fp); if (s != NULL && *s != '\0') { WRITE_STR (s); WRITE_STR (": "); } if ((error = _strerror_r (ptr, ptr->_errno, 1, &dummy)) != NULL) WRITE_STR (error); #ifdef __SCLE WRITE_STR ((fp->_flags & __SCLE) ? "\r\n" : "\n"); #else WRITE_STR ("\n"); #endif fp->_flags &= ~__SOFF; _newlib_flockfile_end(fp); }
static int assumeNonNull(PathInfo const *cfgdir, char const *file, char const *val) { if (val!=0) return 0; WRITE_MSG(2, "vserver-start: no value configured for '"); Vwrite (2, cfgdir->d, cfgdir->l); WRITE_MSG(2, "/"); WRITE_STR(2, file); WRITE_STR(2, "'\n"); return 1; }
static void unsetPreloadEnv() { char *env = getenv("LD_PRELOAD"); char *pos; // the const <-> non-const assignment is not an issue since the following // modifying operations will not be executed in the const-case env = env ? env : ""; pos = strstr(env, LIBNAME); if (pos!=0) { char *end_pos = pos + sizeof(LIBNAME); bool is_end = (end_pos[-1]=='\0'); char *start_pos; end_pos[-1] = '\0'; start_pos = strrchr(env, ':'); if (start_pos==0) start_pos = env; else if (!is_end) ++start_pos; if (is_end) *start_pos = '\0'; else memmove(start_pos, end_pos, strlen(end_pos)+1); } #ifdef DEBUG if (isDbgLevel(DBG_VERBOSE1|DBG_VARIABLES)) { WRITE_MSG(2, "env='"); WRITE_STR(2, env); WRITE_MSG(2, "'\n"); } #endif if (*env=='\0') unsetenv("LD_PRELOAD"); }
*/ static int Read_Bytes(STD_TERM *term, char *buf, int len) /* ** Read the next "chunk" of data into the terminal buffer. ** ***********************************************************************/ { int end; // If we have leftovers: if (term->residue[0]) { end = strlen(term->residue); if (end < len) len = end; strncpy(buf, term->residue, len); // terminated below memmove(term->residue, term->residue+len, end-len); // remove term->residue[end-len] = 0; } else { // Read next few bytes. We don't know how many may be waiting. // We assume that escape-sequences are always complete in buf. // (No partial escapes.) If this is not true, then we will need // to add an additional "collection" loop here. if ((len = read(0, buf, len)) < 0) { WRITE_STR("\r\nI/O terminated\r\n"); Quit_Terminal(term); // something went wrong exit(100); } } buf[len] = 0; buf[len+1] = 0; DBG_INT("read len", len); return len; }
static void showTags() { char const * delim = ""; size_t i; WRITE_MSG(1, "Valid tags are: "); for (i=0; i<DIM_OF(TAGS); ++i) { WRITE_STR(1, delim); WRITE_STR(1, TAGS[i].tag); delim = ", "; } WRITE_MSG(1, "\n"); exit(0); }
int main(int argc, char *argv[]) { char const * dir; int root_fd; int this_fd; char * umount_cmd[] = { UMOUNT_PROG, "-l", "-n", ".", 0 }; if (argc<2) { WRITE_MSG(2, "Try '"); WRITE_STR(2, argv[0]); WRITE_MSG(2, " --help' for more information.\n"); return EXIT_FAILURE; } if (strcmp(argv[1], "--help")==0) showHelp(1, argv[0], 0); if (strcmp(argv[1], "--version")==0) showVersion(); dir = argv[1]; if (strcmp(dir, "--")==0 && argc>=3) dir = argv[2]; root_fd = Eopen("/", O_RDONLY, 0); Echroot("."); Echdir(dir); this_fd = Eopen(".", O_RDONLY, 0); Efchdir(root_fd); Echroot("."); Efchdir(this_fd); Eclose(root_fd); Eclose(this_fd); Eexecv(umount_cmd[0], umount_cmd); }
static int printSysInfo(char *buf) { int fd = open(PKGDATADIR "/FEATURES.txt", O_RDONLY); struct utsname uts; if (uname(&uts)==-1) perror("uname()"); else { WRITE_MSG(1, "Versions:\n" " Kernel: "); WRITE_STR(1, uts.release); WRITE_MSG(1, "\n" " VS-API: "); memset(buf, 0, 128); if (getAPIVer(buf)) WRITE_STR(1, buf); else WRITE_MSG(1, "???"); WRITE_MSG(1, "\n" " VCI: "); memset(buf, 0, 128); if (getAPIConfig(buf)) WRITE_STR(1, buf); else WRITE_MSG(1, "???"); WRITE_MSG(1, "\n" " util-vserver: " PACKAGE_VERSION "; " __DATE__ ", " __TIME__"\n" "\n"); } if (fd==-1) WRITE_MSG(1, "FEATURES.txt not found\n"); else { off_t l = Elseek(fd, 0, SEEK_END); Elseek(fd, 0, SEEK_SET); { char buf[l]; EreadAll(fd, buf, l); EwriteAll(1, buf, l); } Eclose(fd); } return EXIT_SUCCESS; }
static void showHelp(int fd, char const *cmd, int res) { #if !defined(VC_ENABLE_API_COMPAT) && !defined(VC_ENABLE_API_LEGACY) WRITE_MSG(1, "ERROR: tools were built without legacy API support; reducecap will not work!\n\n"); #endif WRITE_MSG(fd, "Usage:\n "); WRITE_STR(fd, cmd); WRITE_MSG(fd, " [--show] [--secure] [--flag <flag>] [--cap <capability>] [--] <cmd> <args>*\n "); WRITE_STR(fd, cmd); WRITE_MSG(fd, " --show [--pid <pid>]\n\n" "Please report bugs to " PACKAGE_BUGREPORT "\n"); exit(res); }
static void showHelp(int fd, char const *cmd) { WRITE_MSG(fd, "Usage: "); WRITE_STR(fd, cmd); WRITE_MSG(fd, " [--] <file>+\n\n" "Please report bugs to " PACKAGE_BUGREPORT "\n"); exit(0); }
static void printUtsValue(xid_t xid, int val) { char buf[128]; if (vc_get_vhi_name(xid, val, buf, sizeof(buf)-1)==-1) WRITE_MSG(1, "???"); else WRITE_STR(1, buf); }
static void showHelp(int fd, char const *cmd, int res) { WRITE_MSG(fd, "Usage: "); WRITE_STR(fd, cmd); WRITE_MSG(fd, " [--] <cmd> <args>*\n\n" "Please report bugs to " PACKAGE_BUGREPORT "\n"); exit(res); }
static void showHelp(int fd, char const *cmd, int res) { WRITE_MSG(fd, "Usage: "); WRITE_STR(fd, cmd); WRITE_MSG(fd, " [-ql] <vserver>|<pid>|<context> <tag>\n" "Please report bugs to " PACKAGE_BUGREPORT "\n"); exit(res); }
static void showHelp(int fd, char const *cmd, int res) { WRITE_MSG(fd, "Usage: "); WRITE_STR(fd, cmd); WRITE_MSG(fd, "[--help] [--version] <dir>\n\n" "Please report bugs to " PACKAGE_BUGREPORT "\n"); exit(res); }
static void showHelp(int fd, char const *cmd, int res) { WRITE_MSG(fd, "Usage:\n "); WRITE_STR(fd, cmd); WRITE_MSG(fd, " --socket <filename> [--timeout <seconds>]\n" "\n" "Please report bugs to " PACKAGE_BUGREPORT "\n"); exit(res); }
static size_t findUtsIdx(char const *str, size_t len) { size_t i; for (i=0; i<DIM_OF(UTS_STRINGS); ++i) if (UTS_STRINGS[i]!=0 && strncasecmp(UTS_STRINGS[i], str, len)==0) return i; WRITE_MSG(2, "Tag '"); Vwrite (2, str, len); WRITE_STR(2, "' not recognized\n"); exit(wrapper_exit_code); }
void showHelp(int fd, char const *cmd, int res) { WRITE_MSG(fd, "Usage: "); WRITE_STR(fd, cmd); WRITE_MSG(fd, " [-Rx] [--[~](iunlink|admin|watch|hide|barrier|iunlink-but-not-immutable|immutable|write|cow|ixunlink)]* [--] <file>+\n\n" " Options:\n" " -R ... recurse through directories\n" " -x ... do not cross filesystems\n\n" "Please report bugs to " PACKAGE_BUGREPORT "\n"); exit(res); }
static void showHelp(char const *cmd) { WRITE_MSG(1, "Usage: "); WRITE_STR(1, cmd); WRITE_MSG(1, " [--] <filename>\n" "\n" "Shows the relative age of <filename>\n" "\n" "Please report bugs to " PACKAGE_BUGREPORT "\n"); exit(0); }
static uint32_t getCap(char const *cap) { int bit = vc_text2cap(cap); if (bit!=0) { WRITE_MSG(2, "Unknown capability '"); WRITE_STR(2, optarg); WRITE_MSG(2, "'; try '--help' for more information\n"); exit(wrapper_exit_code); } return (1<<bit); }
int main(int argc, char *argv[]) { char buf[sizeof(int)*3+2]; xid_t ctx; if (argc==1) ctx = vc_get_task_xid(0); else ctx = vc_get_task_xid(atoi(argv[1])); utilvserver_fmt_int(buf, ctx); WRITE_STR(1, buf); WRITE_MSG(1, "\n"); return 0; }
static void showHelp(int fd, char const *cmd, int res) { WRITE_MSG(fd, "Usage:\n "); WRITE_STR(fd, cmd); WRITE_MSG(fd, " {--set|--get} [--nid <nid>] [--ncap [~!]<ncap>] [--flag [~!]<flag>] [--secure] --\n" " [<program> <args>*]\n" "\n" " --ncap <cap> ... network capability to be added\n" " --flag <flag> ... network flag to be added\n" "\n" "Please report bugs to " PACKAGE_BUGREPORT "\n"); exit(res); }
static void showHelp(int fd, char const *cmd, int res) { VSERVER_DECLARE_CMD(cmd); WRITE_MSG(fd, "Usage: "); WRITE_STR(fd, cmd); WRITE_MSG(fd, " [--help] [--version] [--bind] [--move] [--rbind] [-t <type>] [--chroot]\n" " [--mtab <filename>] [--fstab <filename>] [--rootfs yes|no|only]\n" " [-n] -a|([-o <options>] [--] <src> <dst>)\n\n" "Executes mount-operations under the current directory: it assumes sources in\n" "the current root-dir while destinations are expected in the chroot environment.\n\n" "For non-trivial mount-operations it uses the external 'mount' program which\n" "can be overridden by the $MOUNT environment variable.\n\n" "Options:\n" " --bind|move|rbind ... set the correspond flags; with this options\n" " the mount will be executed internally without\n" " calling an external mount program.\n" " -t <type> ... assume the given filesystem type\n" " -o <options> ... set additional options; see mount(2) for details\n" " -n ... do not update the mtab-file\n" " --mtab <filename> ... use <filename> as an alternative mtab file\n" " [default: /etc/mtab]\n" " --chroot ... chroot into the current directory before\n" " mounting the filesystem\n" " --fstab <filename> ... use <filename> as an alternative fstab file;\n" " this option has an effect only with the '-a'\n" " option [default: /etc/fstab]\n" " --rootfs yes|no|only ... specifies how to handle an entry for a rootfs\n" " ('/') when processing an fstab file. 'yes' will\n" " mount it among the other entries, 'only' will\n" " mount only the rootfs entry, and 'no' will ignore\n" " it and mount only the other entries [default: yes]\n" " --trigger-automount ... trigger automounting of <src> paths but do not\n" " mount <dst> nor touch mtab\n" " -a ... mount everything listed in the fstab-file\n\n" " <src> ... the source-filesystem; this path is absolute\n" " to the current root-filesystem. Only valid\n" " without the '-a' option.\n" " <dst> ... the destination mount-point; when used with\n" " '--chroot', this path is relative to the current\n" " directory. Only valid without the '-a' option\n\n" "Please report bugs to " PACKAGE_BUGREPORT "\n"); exit(res); }
int main(int argc, char *argv[]) { bool quiet = false; char const * vserver; VserverTag tag; while (1) { int c = getopt_long(argc, argv, "ql", CMDLINE_OPTIONS, 0); if (c==-1) break; switch (c) { case 'h' : showHelp(1, argv[0], 0); case 'v' : showVersion(); case 'l' : showTags(); case 'q' : quiet = true; break; default : WRITE_MSG(2, "Try '"); WRITE_STR(2, argv[0]); WRITE_MSG(2, " --help' for more information.\n"); exit(1); break; } } if (optind+2>argc) { execQuery("-", tgSYSINFO, 0, 0); WRITE_MSG(2, "\nAssumed 'SYSINFO' as no other option given; try '--help' for more information.\n"); exit(0); } vserver = argv[optind]; tag = stringToTag(argv[optind+1]); if (tag==tgNONE) { WRITE_MSG(2, "Unknown tag; use '-l' to get list of valid tags\n"); exit(1); } if (quiet) { int fd = Eopen("/dev/null", O_WRONLY, 0644); Edup2(fd, 1); Eclose(fd); } return execQuery(vserver, tag, argc-(optind+2), argv+optind+2); }
static void showHelp(int fd, char const *cmd, int res) { WRITE_MSG(fd, "Usage:\n "); WRITE_STR(fd, cmd); WRITE_MSG(fd, " [--xid <xid>] {--get|--set [--bcap [~!]<cap>] [--ccap [~!]<cap>]\n" " [--flag [~!]<flag>] [--secure]} -- [<program> <args>*]\n" "\n" " --bcap <cap> ... system capability to be set\n" " --ccap <cap> ... context capability to be set\n" " --flag <flag> ... context flag to be set\n" " --umask <mask> ... unshare mask to be set\n" "\n" "Please report bugs to " PACKAGE_BUGREPORT "\n"); exit(res); }
void write_groups(struct storage *store, const faction * f) { group *g; for (g = f->groups; g; g = g->next) { ally *a; WRITE_INT(store, g->gid); WRITE_STR(store, g->name); for (a = g->allies; a; a = a->next) { if (a->faction) { write_faction_reference(a->faction, store); WRITE_INT(store, a->status); } } WRITE_INT(store, 0); a_write(store, g->attribs, g); WRITE_SECTION(store); } WRITE_INT(store, 0); }
static int write_manifest(gzFile f, const struct manifest *mf) { uint16_t i, j; WRITE_INT(4, MAGIC); WRITE_INT(1, MANIFEST_VERSION); WRITE_INT(1, 16); WRITE_INT(2, 0); WRITE_INT(4, mf->n_files); for (i = 0; i < mf->n_files; i++) { WRITE_STR(mf->files[i]); } WRITE_INT(4, mf->n_file_infos); for (i = 0; i < mf->n_file_infos; i++) { WRITE_INT(4, mf->file_infos[i].index); WRITE_BYTES(mf->hash_size, mf->file_infos[i].hash); WRITE_INT(4, mf->file_infos[i].size); WRITE_INT(8, mf->file_infos[i].mtime); WRITE_INT(8, mf->file_infos[i].ctime); } WRITE_INT(4, mf->n_objects); for (i = 0; i < mf->n_objects; i++) { WRITE_INT(4, mf->objects[i].n_file_info_indexes); for (j = 0; j < mf->objects[i].n_file_info_indexes; j++) { WRITE_INT(4, mf->objects[i].file_info_indexes[j]); } WRITE_BYTES(mf->hash_size, mf->objects[i].hash.hash); WRITE_INT(4, mf->objects[i].hash.size); } return 1; error: cc_log("Error writing to manifest file"); return 0; }
static void object_write(const attrib * a, const void *owner, struct storage *store) { const object_data *data = (object_data *) a->data.v; int type = (int)data->type; WRITE_TOK(store, data->name); WRITE_INT(store, type); switch (data->type) { case TINTEGER: WRITE_INT(store, data->data.i); break; case TREAL: WRITE_FLT(store, (float)data->data.real); break; case TSTRING: WRITE_STR(store, data->data.str); break; case TUNIT: write_unit_reference(data->data.u, store); break; case TFACTION: write_faction_reference(data->data.f, store); break; case TBUILDING: write_building_reference(data->data.b, store); break; case TSHIP: /* write_ship_reference(data->data.sh, store); */ assert(!"not implemented"); break; case TREGION: write_region_reference(data->data.r, store); break; case TNONE: break; default: assert(!"illegal type in object-attribute"); } }
int main(int argc, char *argv[]) { char const * socket_name = 0; struct timeval timeout = { 0,0 }; struct timeval *timeout_ptr = 0; char const * quit_msg = false; while (1) { int c = getopt_long(argc, argv, "+", CMDLINE_OPTIONS, 0); if (c==-1) break; switch (c) { case CMD_HELP : showHelp(1, argv[0], 0); case CMD_VERSION : showVersion(); case CMD_SOCKET : socket_name = optarg; break; case CMD_QUIT : quit_msg = optarg; break; case CMD_TIMEOUT : timeout.tv_sec = atoi(optarg); timeout_ptr = &timeout; break; default : WRITE_MSG(2, "Try '"); WRITE_STR(2, argv[0]); WRITE_MSG(2, " --help' for more information.\n"); return 255; break; } } if (socket_name==0) WRITE_MSG(2, "reserve-context: No socketname specified\n"); if (quit_msg) return sendQuitSignal(socket_name, quit_msg); else return doit(socket_name, timeout_ptr); return EXIT_FAILURE; }