int main(int argc, char **argv) { int rc = 0, fd; char *path; if (argc >= 2) { if (strcmp(argv[1], "--h") == 0) { usage(); goto out; } else { path = argv[1]; } } else { goto out; } fd = open(path, 0, 0); if (fd == -1) { printf("open %s failed.\n", path); } else { rc = cat_file(fd); close(fd); } out: return rc; }
void cmd_line_cat(const char *arg_line) { if(strcmp(arg_line, "--HELP") == 0) { console_printf("Print contents of a file to screen\nusage: cat <file1, file2, ...>\n"); return; } char arg_line_copy[256]; strcpy(arg_line_copy, arg_line); char *fname = arg_line_copy; int i; for(i = 0; i < strlen(arg_line); i++) { if (arg_line_copy[i] == ' ') { arg_line_copy[i] = '\0'; cat_file(fname); fname = arg_line_copy + i + 1; } } cat_file(fname); }
/* * Main routine */ int main(int argc, char *argv[]) { char test_str[] = "test stdout...\n\n"; syslog(LOG_INFO, "\nfileio: fs test program\n"); /* Wait 1 sec until loading fs server */ timer_sleep(1000, 0); /* * Prepare to use a file system. */ fslib_init(); /* * Mount file systems */ mount("", "/", "ramfs", 0, NULL); mkdir("/dev", 0); mount("", "/dev", "devfs", 0, NULL); /* device */ mkdir("/boot", 0); mount("/dev/ram0", "/boot", "arfs", 0, NULL); /* archive */ mkdir("/tmp", 0); /* * Prepare stdio */ open("/dev/tty", O_RDWR); /* stdin */ dup(0); /* stdout */ dup(0); /* stderr */ /* Test device write */ write(STDOUT_FILENO, test_str, strlen(test_str)); test_write(); cat_file(); /* test read/write */ test_invalid(); /* test invalid request */ test_read(); /* test read loop */ test_open(); /* test open/close loop */ /* * Disconnect from a file system. */ fslib_exit(); return 0; }
int main(int argc, char *argv[]) { int nlines = -1; if (argc > 3 || argc < 2) { printf("USAGE: cat_file <filename> [<nlines>]\n" "where <filename> usually does not specify an extension\n" " <nlines> is number of lines from top to display\n" "Tries to open the file using the following search pattern:\n" " %LANG%\\<filename>.TXT\n" " %LANG%\\<filename>\n" " <filename>.%LANG%\n" " if %LANG% in format \"aa-BB\", such as \"en-UK\" then try\n" " {\n" " aa\\<filename>.TXT (ie en\\filename.TXT)\n" " aa\\<filename> (ie en\\filename\n" " <filename>.aa (ie filename.en )\n" " }\n" " <filename>.TXT\n" " <filename>\n" " \n" " Repeat above search, except instead of .,\n" " use each ; separated path in %NLSPATH%\n" " If still not found then prints an error message indicating not found.\n" ); return 1; } if (argc > 2) nlines = atoi(argv[2]); if (cat_file(argv[1], nlines) == -1) { printf("ERROR: unable to open %s\n", argv[1]); return 1; } return 0; }
inst_t install_top (dat_t *dat_ary, int dat_count) { /* Top-level piece for the install program. Determines what disk sets the user wants to install, then installs them. */ char *s; /* used for retrieving localized text */ char txtfile[MAXPATH]; /* name of text descr file */ int ch; int i; inst_t ret; /* return: no. of errors,warnings */ inst_t this; /* no. of errors,warnings */ /* Where to install from, to */ if (!fromdirflag || !destdirflag) /* only prompt if one or both are missing */ do { /* get directories from user */ repaint_empty(); fromdir[0] = MAXDIR; /* max length of the string */ destdir[0] = MAXDIR; /* max length of the string */ s = catgets (cat, SET_PROMPT_LOC, MSG_INSTALLFROM, MSG_INSTALLFROM_STR); gotoxy (5, 10); cputs (s); gotoxy (5, 12); if (fromdirflag) cputs(&(fromdir[2])); else cgets (fromdir); s = catgets (cat, SET_PROMPT_LOC, MSG_INSTALLTO, MSG_INSTALLTO_STR); gotoxy (5, 16); cputs (s); gotoxy (5, 18); if (destdirflag) cputs(&(destdir[2])); else cgets (destdir); /* let user verify */ repaint_empty(); gotoxy (5, 10); cputs (catgets (cat, SET_PROMPT_LOC, MSG_WILLINSTALLFROM, MSG_WILLINSTALLFROM_STR)); gotoxy (5, 11); cputs (&fromdir[2]); gotoxy (5, 13); cputs (catgets (cat, SET_PROMPT_LOC, MSG_WILLINSTALLTO, MSG_WILLINSTALLTO_STR)); gotoxy (5, 14); cputs (&destdir[2]); gotoxy (5, 16); s = catgets (cat, SET_PROMPT_LOC, MSG_INSTALLDIROK, MSG_INSTALLDIROK_STR); ch = select_yn (s, yes, no, NULL, NULL); } while (ch); /* Make sure destination directory exists (or create if not) */ createdestpath(&destdir[2]); /* open the log file, if user wants it */ if (wantlog) { if ((i = openlog(&destdir[2], "INSTALL.LOG")) != 0) { repaint_empty(); gotoxy (5, 10); cputs (catgets (cat, SET_PROMPT_LOC, MSG_WILLINSTALLTO, MSG_WILLINSTALLTO_STR)); gotoxy (5, 11); cputs (&destdir[2]); gotoxy (5, 13); fprintf(stderr, catgets(cat, SET_ERRORS, MSG_ERRCREATELOG, MSG_ERRCREATELOG_STR), i); pause(); } /* note: if log is not opened, then calls to log immediately return, so if (wantlog) log(...) wrapper is not needed for calls to log() */ log("<install ver=\"%s\" logformat=\"1.0\" >\n", INSTALL_VERSION); log("<source path=\"%s\" />\n", &fromdir[2]); log("<dest path=\"%s\" />\n\n", &destdir[2]); } /* Ask to install every disk set */ log("<installsets>\n"); for (i = 0; i < dat_count; i++) { repaint_empty(); gotoxy (2, 5); s = catgets (cat, SET_PKG_GENERAL, MSG_DISKSET, MSG_DISKSET_STR); cputs (s); cputs (dat_ary[i].name); log("<diskset name=\"%s\" ", dat_ary[i].name); /* create the txt file name */ gotoxy (2, 10); cat_file (dat_ary[i].name, 10 /* no. lines */); gotoxy (2, 6); switch (dat_ary[i].rank) { case 'Y': case 'y': s = catgets (cat, SET_PKG_NEED, MSG_REQUIRED, MSG_REQUIRED_STR); cputs (s); log("choice=\"y\" />\n"); pause(); break; case 'N': case 'n': s = catgets (cat, SET_PKG_NEED, MSG_SKIPPED, MSG_SKIPPED_STR); cputs (s); log("choice=\"n\" />\n"); /* don't need to pause for this */ break; default: s = catgets (cat, SET_PKG_NEED, MSG_OPTIONAL, MSG_OPTIONAL_STR); cputs (s); s = catgets (cat, SET_PROMPT_YN, MSG_INSTALLSETYN, MSG_INSTALLSETYN_STR); ch = select_yn (s, yes, no, NULL, NULL); switch (ch) { case 0: dat_ary[i].rank = 'y'; log("choice=\"y\" />\n"); break; default: dat_ary[i].rank = 'n'; log("choice=\"n\" />\n"); break; } /* switch ch */ break; } /* switch rank */ } /* for i */ log("</installsets>\n\n"); /* Now install the selected disk sets */ ret.errors = 0; ret.warnings = 0; for (i = 0; i < dat_count; i++) { switch (dat_ary[i].rank) { case 'Y': case 'y': this = set_install (dat_ary[i].name, &fromdir[2], &destdir[2]); ret.errors += this.errors; ret.warnings += this.warnings; break; } /* switch */ } /* for i */ /* close the log file, if user wanted it */ log("</install>\n"); closelog(); /* Done */ return (ret); }
int main(int argc, char *argv[]) { FILE *f; char buf[1024]; int pid, stat; struct stat ss; int fd; if (argc != 3) myerr("wrong number of arguments: %d", argc); #if defined EJUDGE_LOCAL_DIR snprintf(emupath, sizeof(emupath), "%s/dosemu/run", EJUDGE_LOCAL_DIR); #elif defined EJUDGE_CONTESTS_HOME_DIR snprintf(emupath, sizeof(emupath), "%s/dosemu/run", EJUDGE_CONTESTS_HOME_DIR); #else snprintf(emupath, sizeof(emupath), "/home/judges/dosemu/run"); #endif atexit(cleanup_hnd); if (chmod(emupath, 0700) < 0) myerr("chmod failed: %s", strerror(errno)); clean_dir(emupath); snprintf(buf, sizeof(buf), "%s/command.txt", emupath); if (!(f = fopen(buf, "w"))) myerr("fopen w failed on %s: %s", buf, strerror(errno)); fprintf(f, "\r\n" "\r\n" "output.txt\r\n" "errors.txt\r\n" "bcc\r\n" "-ml\r\n" "program.c\r\n"); fclose(f); snprintf(buf, sizeof(buf), "%s/output.txt", emupath); if (!(f = fopen(buf, "w"))) myerr("fopen failed on %s: %s", buf, strerror(errno)); fclose(f); snprintf(buf, sizeof(buf), "%s/errors.txt", emupath); if (!(f = fopen(buf, "w"))) myerr("fopen failed on %s: %s", buf, strerror(errno)); fclose(f); snprintf(buf, sizeof(buf), "%s/program.c", emupath); copy_file(argv[1], buf); fflush(0); if ((pid = fork()) < 0) myerr("fork failed: %s", strerror(errno)); if (!pid) { snprintf(buf, sizeof(buf), "%s/../bin/dos", emupath); if ((fd = open("/dev/null", O_RDONLY)) < 0) myerr("open(/dev/null failed: %s", strerror(errno)); dup2(fd, 0); close(fd); if ((fd = open("/dev/null", O_WRONLY)) < 0) myerr("open(/dev/null failed: %s", strerror(errno)); dup2(fd, 1); dup2(fd, 2); close(fd); execl(buf, buf, "-I", "keystroke \"\\r\" video { none } dpmi 4096", NULL); myerr("execl failed: %s", strerror(errno)); _exit(1); } wait(&stat); if (WIFSIGNALED(stat)) myerr("dos terminated by signal"); if (!WIFEXITED(stat)) myerr("dos terminated by unknown reason"); if (WEXITSTATUS(stat)) myerr("dos exited with code %d", WEXITSTATUS(stat)); snprintf(buf, sizeof(buf), "%s/output.txt", emupath); cat_file(buf); snprintf(buf, sizeof(buf), "%s/errors.txt", emupath); cat_file(buf); fprintf(stderr, "\n\n"); snprintf(buf, sizeof(buf), "%s/retcode.txt", emupath); if (!(f = fopen(buf, "r"))) myerr("fopen %s failed: %s",buf,strerror(errno)); if (fscanf(f, "%d", &stat) != 1) myerr("cannot parse retcode.txt"); fscanf(f, " "); if (fgetc(f) != EOF) myerr("garbage in retcode.txt"); fclose(f); if (stat != 0) { myerr("compilation process error code is %d", stat); } snprintf(buf, sizeof(buf), "%s/program.exe", emupath); if (lstat(buf, &ss) < 0) myerr("output file %s does not exist", buf); copy_file(buf, argv[2]); return 0; }
bool test_rtc(case_t *rtc_case) { int fd = -1; int ret = -1; struct rtc_time rtc; struct tm sys_clock; time_t tmp_time; struct timeval tv; char rtc_hardware[50] = "/sys/class/rtc/rtc0/ext_osc"; ret = cat_file(rtc_hardware); if(1 != ret) return false; fd = open("/dev/rtc0", O_RDWR); if(!fd) { printf("open rtc device error\n"); return false; } sscanf(rtc_case->nod_path, "%d-%d-%d %d:%d:%d", &rtc.tm_year, &rtc.tm_mon, &rtc.tm_mday,&rtc.tm_hour, &rtc.tm_min, &rtc.tm_sec); rtc.tm_year -= 1900; rtc.tm_mon -= 1; printf("\nCurrentRTC data/time is %d-%d-%d, %02d:%02d:%02d.\n", rtc.tm_mday, rtc.tm_mon + 1,rtc.tm_year + 1900, rtc.tm_hour, rtc.tm_min, rtc.tm_sec); ret = ioctl(fd, RTC_SET_TIME, &rtc); if(-1 == ret) { printf("set rtc device error\n"); printf("errno = %d\n", errno); return false; } direct_thread_sleep(5000000); // modified wait more time for rtc to set time ret = ioctl(fd, RTC_RD_TIME, &rtc); if(-1 == ret) { printf("read rtc device error\n"); return false; } printf("\nCurrentRTC data/time is %d-%d-%d, %02d:%02d:%02d.\n", rtc.tm_mday, rtc.tm_mon + 1,rtc.tm_year + 1900, rtc.tm_hour, rtc.tm_min, rtc.tm_sec); sys_clock.tm_sec = rtc.tm_sec; sys_clock.tm_min = rtc.tm_min; sys_clock.tm_hour = rtc.tm_hour; sys_clock.tm_mday = rtc.tm_mday; sys_clock.tm_mon = rtc.tm_mon; sys_clock.tm_year = rtc.tm_year; tmp_time = mktime(&sys_clock); tv.tv_sec = tmp_time; tv.tv_usec = 0; if(settimeofday(&tv, NULL) < 0) { printf("Set system datatime error!\n"); printf("errno = %d\n", errno); return false; } direct_thread_sleep(4000000); ret = ioctl(fd, RTC_RD_TIME, &rtc); if(-1 == ret) { printf("read rtc device error\n"); return false; } if(gettimeofday(&tv, NULL) < 0) { printf("get system datatime error!\n"); printf("errno = %d\n", errno); return false; } if(!compare_time(rtc, tv)) { printf("rtc != linux time\n"); return false; } else { sprintf(rtc_case->pass_string, "%s(%d-%d-%d, %02d:%02d:%02d)",rtc_case->pass_string, rtc.tm_mday, rtc.tm_mon + 1,rtc.tm_year + 1900, rtc.tm_hour, rtc.tm_min, rtc.tm_sec); } return true; }
/* Main entry point for cat, accepts an array of arguments */ int cmd_cat(char **argv) { unsigned int argc, i, ret = 0; size_t buffer = 0; int c, opt_ind; aoff64_t head = CAT_FULL_FILE, tail = CAT_FULL_FILE; bool hex = false; bool more = false; bool tailFirst = false; sysarg_t rows, cols; int rc; /* * reset global state * TODO: move to structure? */ paging_enabled = false; chars_remaining = 0; lines_remaining = 0; console_cols = 0; console_rows = 0; should_quit = false; console = console_init(stdin, stdout); number = false; lineno = 0; /* This enables printing of the first number. */ last_char_was_newline = true; argc = cli_count_args(argv); for (c = 0, optreset = 1, optind = 0, opt_ind = 0; c != -1;) { c = getopt_long(argc, argv, "xhvmH:t:b:s:n", long_options, &opt_ind); switch (c) { case 'h': help_cmd_cat(HELP_LONG); return CMD_SUCCESS; case 'v': printf("%s\n", CAT_VERSION); return CMD_SUCCESS; case 'H': if (!optarg || str_uint64_t(optarg, NULL, 10, false, &head) != EOK ) { puts("Invalid head size\n"); return CMD_FAILURE; } break; case 't': if (!optarg || str_uint64_t(optarg, NULL, 10, false, &tail) != EOK ) { puts("Invalid tail size\n"); return CMD_FAILURE; } if (head == CAT_FULL_FILE) tailFirst = true; break; case 'b': if (!optarg || str_size_t(optarg, NULL, 10, false, &buffer) != EOK ) { puts("Invalid buffer size\n"); return CMD_FAILURE; } break; case 'm': more = true; break; case 'x': hex = true; break; case 's': dash_represents_stdin = true; break; case 'n': number = true; break; } } argc -= optind; if (argc < 1) { printf("%s - incorrect number of arguments. Try `%s --help'\n", cmdname, cmdname); return CMD_FAILURE; } if (buffer < 4) buffer = CAT_DEFAULT_BUFLEN; if (more) { rc = console_get_size(console, &cols, &rows); if (rc != EOK) { printf("%s - cannot get console size\n", cmdname); return CMD_FAILURE; } console_cols = cols; console_rows = rows; paging_enabled = true; newpage(); } for (i = optind; argv[i] != NULL && !should_quit; i++) ret += cat_file(argv[i], buffer, hex, head, tail, tailFirst); if (ret) return CMD_FAILURE; else return CMD_SUCCESS; }
inst_t disk_install(const char *datfile, char *fromdir, char *destdir) { char lsmfile[MAXPATH]; /* Linux software map file */ char *s; int dat_count; /* size of the dat array */ int ret; int ch; int i; int pkg_yesToAll = 0; /* Assume default yes to all = not specified */ dat_t *dat_ary; /* the DAT array */ inst_t this; /* return: no. of errors,warnings */ /* Initialize variables */ this.errors = 0; this.warnings = 0; /* Read dat file */ dat_ary = dat_read (datfile, &dat_count); if (dat_ary == NULL) { s = catgets (cat, SET_ERRORS, MSG_ERROR, MSG_ERROR_STR); fprintf (stderr, s); log("<error msg=\"%s\" />\n", s); s = catgets (cat, SET_ERRORS, MSG_ERRALLOCMEMFDF, MSG_ERRALLOCMEMFDF_STR); fprintf (stderr, s); log("<error msg=\"%s\" />\n", s); pause(); return (this); } if (dat_count < 1) { s = catgets (cat, SET_ERRORS, MSG_ERROR, MSG_ERROR_STR); fprintf (stderr, s); log("<error msg=\"%s\" />\n", s); s = catgets (cat, SET_ERRORS, MSG_ERREMPTYFLOPPYDATAFILE, MSG_ERREMPTYFLOPPYDATAFILE_STR); fprintf (stderr, s); log("<error msg=\"%s\" />\n", s); pause(); free (dat_ary); return (this); } /* Run the install */ for (i = 0; i < dat_count; i++) { /* Print the screen and progress bargraph */ repaint_empty(); box (14, 16, 66, 18); gotoxy (15, 17); bargraph (i, dat_count, 50 /* width */); /* Print the package name */ gotoxy (2, 5); s = catgets (cat, SET_PKG_GENERAL, MSG_PACKAGE, MSG_PACKAGE_STR); cputs (s); cputs (dat_ary[i].name); /* Show the package description */ /* Generate the lsmfile name */ fnmerge (lsmfile, "", fromdir, dat_ary[i].name, "LSM"); if (isfile (lsmfile)) { lsm_description (8, 2, 10, lsmfile); } else { /* no lsm file. try it again with a plain txt file (or localized version) */ fnmerge (lsmfile, "", fromdir, dat_ary[i].name, ""); gotoxy (2, 8); cat_file (lsmfile, 10 /* no. lines */); } /* Find out which ones the user wants to install */ gotoxy (2, 25); switch (dat_ary[i].rank) { case 'n': case 'N': /* Do not install */ log("<package name=\"%s\" choice=\"n\" />\n", dat_ary[i].name); s = catgets (cat, SET_PKG_NEED, MSG_SKIPPED, MSG_SKIPPED_STR); cputs (s); break; case 'y': case 'Y': /* Always install */ log("<package name=\"%s\" choice=\"y\" ", dat_ary[i].name); s = catgets (cat, SET_PKG_NEED, MSG_REQUIRED, MSG_REQUIRED_STR); cputs (s); ret = unzip_file (dat_ary[i].name, fromdir, destdir); reregisterSIGINTHandler(); /* unzip installs its own SIGINT handler */ if (ret != 0) { /* Print an error message */ s = catgets (cat, SET_PKG_GENERAL, MSG_ERRREQPKG, MSG_ERRREQPKG_STR); cputs (s); log(">\n"); log("<error msg=\"%s\" />\n", s); log("</package>\n"); /* Return an error */ this.errors++; /* Does the user want to continue anyway? */ s = catgets (cat, SET_PROMPT_YN, MSG_CONTINSTDISK, MSG_CONTINSTDISK_STR); ch = select_yn(s, yes, no, NULL, NULL); if (ch) { log("<abort msg=\"User choose not to continue after error.\" />\n"); return (this); } } else /* ret == 0, ie no errors */ log("/>\n"); break; default: /* Optional */ s = catgets (cat, SET_PKG_NEED, MSG_OPTIONAL, MSG_OPTIONAL_STR); cputs (s); /* Ask the user if you want to install it */ s = catgets (cat, SET_PROMPT_YN, MSG_INSTALLPKG, MSG_INSTALLPKG_STR); if (!pkg_yesToAll) { ch = select_yn (s, yes, no, catgets (cat, SET_PROMPT_YN, MSG_YESTOALL, MSG_YESTOALL_STR), NULL); if (ch == 2) pkg_yesToAll = 1; } if (pkg_yesToAll || ch==0) /* Yes or YesToAll */ { log("<package name=\"%s\" choice=\"y\" ", dat_ary[i].name); ret = unzip_file (dat_ary[i].name, fromdir, destdir); reregisterSIGINTHandler(); /* unzip installs its own SIGINT handler */ if (ret != 0) { /* Print a warning message */ gotoxy (2, 13); s = catgets (cat, SET_PKG_GENERAL, MSG_WARNOPTPKG, MSG_WARNOPTPKG_STR); cputs (s); log(">\n"); log("<warning msg=\"%s\" />\n", s); log("</package>\n"); pause(); this.warnings++; } else log("/>\n"); } else /* user selected no */ log("<package name=\"%s\" choice=\"n\" />\n", dat_ary[i].name); break; } /* switch */ } /* for */ /* Print the screen and 100% complete progress bargraph */ repaint_empty(); box (14, 16, 66, 18); gotoxy (15, 17); bargraph (1, 1, 50 /* width */); /* Free memory for this disk */ free (dat_ary); return (this); }
/* Output startup string. */ bool send_init_strings(int fd GCC_UNUSED, TTY * old_settings) { int i; bool need_flush = FALSE; (void) old_settings; #ifdef TAB3 if (old_settings != 0 && old_settings->c_oflag & (TAB3 | ONLCR | OCRNL | ONLRET)) { old_settings->c_oflag &= (TAB3 | ONLCR | OCRNL | ONLRET); SET_TTY(fd, old_settings); } #endif if (use_reset || use_init) { if (VALID_STRING(init_prog)) { IGNORE_RC(system(init_prog)); } need_flush |= sent_string((use_reset && (reset_1string != 0)) ? reset_1string : init_1string); need_flush |= sent_string((use_reset && (reset_2string != 0)) ? reset_2string : init_2string); #if defined(set_lr_margin) if (VALID_STRING(set_lr_margin)) { need_flush |= sent_string(TPARM_2(set_lr_margin, 0, columns - 1)); } else #endif #if defined(set_left_margin_parm) && defined(set_right_margin_parm) if (VALID_STRING(set_left_margin_parm) && VALID_STRING(set_right_margin_parm)) { need_flush |= sent_string(TPARM_1(set_left_margin_parm, 0)); need_flush |= sent_string(TPARM_1(set_right_margin_parm, columns - 1)); } else #endif if (VALID_STRING(clear_margins) && VALID_STRING(set_left_margin) && VALID_STRING(set_right_margin)) { need_flush |= sent_string(clear_margins); need_flush |= to_left_margin(); need_flush |= sent_string(set_left_margin); if (VALID_STRING(parm_right_cursor)) { need_flush |= sent_string(TPARM_1(parm_right_cursor, columns - 1)); } else { for (i = 0; i < columns - 1; i++) { out_char(' '); need_flush = TRUE; } } need_flush |= sent_string(set_right_margin); need_flush |= to_left_margin(); } need_flush |= reset_tabstops(columns); need_flush |= cat_file((use_reset && reset_file) ? reset_file : init_file); need_flush |= sent_string((use_reset && (reset_3string != 0)) ? reset_3string : init_3string); } return need_flush; }
static bool run_output_check(const output_check oc, const atf::fs::path& path, const std::string& stdxxx) { bool result; if (oc.type == oc_empty) { const bool is_empty = file_empty(path); if (!oc.negated && !is_empty) { std::cerr << "Fail: " << stdxxx << " not empty\n"; print_diff(atf::fs::path("/dev/null"), path); result = false; } else if (oc.negated && is_empty) { std::cerr << "Fail: " << stdxxx << " is empty\n"; result = false; } else result = true; } else if (oc.type == oc_file) { const bool equals = compare_files(path, atf::fs::path(oc.value)); if (!oc.negated && !equals) { std::cerr << "Fail: " << stdxxx << " does not match golden " "output\n"; print_diff(atf::fs::path(oc.value), path); result = false; } else if (oc.negated && equals) { std::cerr << "Fail: " << stdxxx << " matches golden output\n"; cat_file(atf::fs::path(oc.value)); result = false; } else result = true; } else if (oc.type == oc_ignore) { result = true; } else if (oc.type == oc_inline) { atf::fs::path path2 = atf::fs::path(atf::config::get("atf_workdir")) / "inline.XXXXXX"; temp_file temp(path2); temp.write(decode(oc.value)); temp.close(); const bool equals = compare_files(path, temp.get_path()); if (!oc.negated && !equals) { std::cerr << "Fail: " << stdxxx << " does not match expected " "value\n"; print_diff(temp.get_path(), path); result = false; } else if (oc.negated && equals) { std::cerr << "Fail: " << stdxxx << " matches expected value\n"; cat_file(temp.get_path()); result = false; } else result = true; } else if (oc.type == oc_match) { const bool matches = grep_file(path, oc.value); if (!oc.negated && !matches) { std::cerr << "Fail: regexp " + oc.value + " not in " << stdxxx << "\n"; cat_file(path); result = false; } else if (oc.negated && matches) { std::cerr << "Fail: regexp " + oc.value + " is in " << stdxxx << "\n"; cat_file(path); result = false; } else result = true; } else if (oc.type == oc_save) { INV(!oc.negated); std::ifstream ifs(path.c_str(), std::fstream::binary); ifs >> std::noskipws; std::istream_iterator< char > begin(ifs), end; std::ofstream ofs(oc.value.c_str(), std::fstream::binary | std::fstream::trunc); std::ostream_iterator <char> obegin(ofs); std::copy(begin, end, obegin); result = true; } else {
static bool run_status_check(const status_check& sc, const atf::check::check_result& cr) { bool result; if (sc.type == sc_exit) { if (cr.exited() && sc.value != INT_MIN) { const int status = cr.exitcode(); if (!sc.negated && sc.value != status) { std::cerr << "Fail: incorrect exit status: " << status << ", expected: " << sc.value << "\n"; result = false; } else if (sc.negated && sc.value == status) { std::cerr << "Fail: incorrect exit status: " << status << ", expected: " << "anything else\n"; result = false; } else result = true; } else if (cr.exited() && sc.value == INT_MIN) { result = true; } else { std::cerr << "Fail: program did not exit cleanly\n"; result = false; } } else if (sc.type == sc_ignore) { result = true; } else if (sc.type == sc_signal) { if (cr.signaled() && sc.value != INT_MIN) { const int status = cr.termsig(); if (!sc.negated && sc.value != status) { std::cerr << "Fail: incorrect signal received: " << status << ", expected: " << sc.value << "\n"; result = false; } else if (sc.negated && sc.value == status) { std::cerr << "Fail: incorrect signal received: " << status << ", expected: " << "anything else\n"; result = false; } else result = true; } else if (cr.signaled() && sc.value == INT_MIN) { result = true; } else { std::cerr << "Fail: program did not receive a signal\n"; result = false; } } else { UNREACHABLE; result = false; } if (result == false) { std::cerr << "stdout:\n"; cat_file(atf::fs::path(cr.stdout_path())); std::cerr << "\n"; std::cerr << "stderr:\n"; cat_file(atf::fs::path(cr.stderr_path())); std::cerr << "\n"; } return result; }
void main(int argc, char *argv[]) { int i = 0, cmd = -1, fd = 0; char line[128], cname[64], temp_pathname[124], pathname[124] = "NULL", basename[124] = "NULL", dirname[124] = "NULL", parameter[124] = "NULL", *device; //GETS DISK NAME TO MOUNT /* printf("Enter the name of your disk image\n"); fgets(device, 128, stdin); device[strlen(device)-1] = 0; // kill the \n char at end */ device = "mydisk"; mount_root(device, &fd); while(1) { //printf("P%d running: ", running.uid); printf("nick's@linux:"); pwd(P0.cwd); printf("$ "); fgets(line, 128, stdin); line[strlen(line)-1] = 0; // kill the \n char at end if (line[0]==0) continue; sscanf(line, "%s %s %s", cname, pathname, parameter); if(strcmp(pathname,"NULL") != 0) strcpy(PATHNAME, pathname); if(strcmp(parameter,"NULL") != 0) strcpy(PARAMETER, parameter); cmd = findCmd(cname); // map cname to an index switch(cmd) { case 0 : menu(); break; case 1 : pwd(P0.cwd);printf("\n"); break; case 2 : ls(); break; case 3 : cd(); break; case 4 : make_dir(); break; case 5 : rmdir(); break; case 6 : creat_file(); break; case 7 : link(); break; case 8 : unlink(); break; case 9 : symlink(); break; case 10: rm_file(); break; case 11: chmod_file(); break; case 12: chown_file(); break; case 13: stat_file(); break; case 14: touch_file(); break; case 20: open_file(); break; //LEVEL 2 case 21: close_file((int)PATHNAME); break; case 22: pfd(); break; case 23: lseek_file(); break; case 24: //access_file(); break; break; case 25: //read_file(); break; case 26: write_file(); break; case 27: cat_file(); break; case 28: cp_file(); break; case 29: mv_file(); break; case 30: mount(); break; //LEVLEL 3 case 31: //umount(); break; case 32: //cs(); break; case 33: //do_fork(); break; case 34: //do_ps(); break; case 40: //sync(); break; case 41: quit(); break; case 42 : system("clear"); break; default: printf("invalid command\n"); break; } //RESET NAMES strcpy(parameter, "NULL"); strcpy(pathname, "NULL"); strcpy(PATHNAME, "NULL"); } }
inst_t disk_install(const char *datfile, const char *descfile, char *fromdir, char *destdir) { char *s; char lsmfile[_MAX_PATH]; /* Linux software map file */ int ret; int ch; int i; int dat_size = 30; /* malloc size of the dat array */ int dat_count; /* size of the dat array */ dat_t *dat_ary; /* the DAT array */ inst_t this; /* return: no. of errors,warnings */ /* Initialize variables */ this.errors = 0; this.warnings = 0; /* Read dat file */ dat_ary = malloc (sizeof (dat_t) * dat_size); if (dat_ary == NULL) { fprintf (stderr, "Error!\n"); fprintf (stderr, "Unable to allocate enough memory for install floppy data file!\n"); gotoxy (1, 25); s = catgets (cat, 1, 0, "Press any key to continue"); cputs (s); getch(); return (this); } dat_count = dat_read (datfile, dat_ary, dat_size); if (dat_count < 1) { fprintf (stderr, "Error!\n"); fprintf (stderr, "The install floppy data file is empty!\n"); gotoxy (1, 25); s = catgets (cat, 1, 0, "Press any key to continue"); cputs (s); getch(); free (dat_ary); return (this); } /* Run the install */ for (i = 0; i < dat_count; i++) { /* Print the screen and progress bargraph */ repaint_empty(); gotoxy (15, 20); bargraph (i, dat_count, 50 /* width */); /* Print the package name */ gotoxy (1, 5); s = catgets (cat, 3, 3, "Package: "); cputs (s); cputs (dat_ary[i].name); /* Show the package description */ /* Generate the lsmfile name */ _makepath (lsmfile, "", fromdir, dat_ary[i].name, "LSM"); if (isfile (lsmfile)) { lsm_description (8, 1, 10, lsmfile); } else { /* no lsm file. try it again with a plain txt file */ _makepath (lsmfile, "", fromdir, dat_ary[i].name, "TXT"); if (isfile (lsmfile)) { cat_file (lsmfile, 8 /* start line */, 10 /* no. lines */); } } /* Find out which ones the user wants to install */ gotoxy (1, 23); switch (dat_ary[i].rank) { case 'n': case 'N': /* Do not install */ s = catgets (cat, 4, 2, "SKIPPED"); cputs (s); break; case 'y': case 'Y': /* Always install */ s = catgets (cat, 4, 1, "REQUIRED"); cputs (s); ret = unzip_file (dat_ary[i].name, fromdir, destdir); if (ret != 0) { /* Print an error message */ s = catgets (cat, 3, 6, "ERROR! Failed to install REQUIRED package."); cputs (s); /* Return an error */ this.errors++; /* Does the user want to continue anyway? */ gotoxy (1, 25); s = catgets (cat, 2, 3, "Continue installing this disk? [yn]"); cputs (s); ch = getch_yn(); if ((ch != 'y') && (ch != 'Y')) { return (this); } } break; default: /* Optional */ s = catgets (cat, 4, 0, "OPTIONAL"); cputs (s); /* Ask the user if you want to install it */ gotoxy (1, 23); s = catgets (cat, 2, 4, "Install this package? [yn]"); cputs (s); ch = getch_yn(); if ((ch == 'y') || (ch == 'Y')) { ret = unzip_file (dat_ary[i].name, fromdir, destdir); if (ret != 0) { /* Print a warning message */ gotoxy (1, 23); s = catgets (cat, 3, 7, "WARNING! Failed to install OPTIONAL package."); cputs (s); gotoxy (1, 25); s = catgets (cat, 1, 0, "Press any key to continue"); cputs (s); getch(); this.warnings++; } } break; } /* switch */ } /* for */ /* Free memory for this disk */ free (dat_ary); return (this); }
dat_t *listbox(dat_t *dat_ary, int dat_count, char *fromdir) { int boxlength = dat_count / 5, centre = 12 - boxlength, i, j; key_t ch; char *thecwd = getcwd(NULL, 0); centre += 4; textbackground(BLUE); textcolor(WHITE); /* OK, lets draw all of the selections using some simple calculations */ for(i = 0, j = 0; i < dat_count; i++, j++) { gotoxy(8 + (j * 13), centre + (i / 5)); if(toupper(dat_ary[i].rank) == 'N') cputs("[ ] "); else { cputs("[X] "); dat_ary[i].rank = 'Y'; } /* Don't bother printing the pathname (if it exists) */ cputs(strrchr(dat_ary[i].name, '\\') != NULL ? &strrchr(dat_ary[i].name, '\\')[1] : dat_ary[i].name); if(j == 4) j = -1; } /* Draw the DONE button */ gotoxy(37, centre + (dat_count / 5) + 2); cputs("[DONE]"); gotoxy(8, centre); cputs(toupper(dat_ary[i].rank) == 'N' ? "< >" : "<X>"); gotoxy(9, centre); i = j = 0; /* Begin the selection loop; runs forever until ENTER is pressed */ for(;;) { unsigned x = wherex(), y = wherey(), k, l; for(k = 19; k < 22; k++) for(l = 2; l < 80; l++) { gotoxy(l, k); putch(' '); } gotoxy(2, 20); if(i != dat_count) { char lsmfile[MAXPATH]; unsigned total; chdir(fromdir); _dos_setdrive(toupper(fromdir[0]) - 'A' + 1, &total); fnmerge(lsmfile, "", fromdir, dat_ary[i].name, ".LSM"); if(isfile(lsmfile)) lsm_description(20, 2, 3, lsmfile); else cat_file(dat_ary[i].name, 3); chdir(thecwd); _dos_setdrive(toupper(thecwd[0]) - 'A' + 1, &total); } gotoxy(x, y); ch = getkey(); switch(ch.extended) { /* Moves the current selection to the next row */ case KEY_DOWN: if(i < (dat_count - 4)) i += 5; else { j = (dat_count - ((dat_count / 5) * 5) + 5) - 5; i = dat_count; } break; /* * Moves the current selection to the next column (or the first * column of the next row) */ case KEY_RIGHT: if(i < dat_count) { i++; j++; } break; /* * Moves the current selection to the previous row or to the * first column of the current row */ case KEY_UP: if(i > 4) i -= 5; else j = i = 0; break; /* * Moves the current selection to the previous column (or the * last column of the previous row */ case KEY_LEFT: if(i != 0) { i--; j--; } break; } switch(ch.key) { /* Complete the selection, return the results */ case KEY_ENTER: free(thecwd); return(dat_ary); /* * If pressed on the DONE button, return the results, else * toggle the current selection yes or no */ case ' ': if(i == dat_count) { free(thecwd); return(dat_ary); } dat_ary[i].rank = (toupper(dat_ary[i].rank) == 'Y') ? 'N' : 'Y'; break; } if(j > 4) j = 0; if(j < 0) j = 4; /* * Change the previous selection borders to [], move the current to * <> */ if (wherex() != 38) { gotoxy(wherex() - 1, wherey()); putch('['); gotoxy(wherex() + 1, wherey()); putch(']'); } if(i == dat_count) gotoxy(38, centre + (dat_count / 5) + 2); else { gotoxy(8 + (j * 13), centre + (i / 5)); cputs(toupper(dat_ary[i].rank) == 'Y' ? "<X>" : "< >"); gotoxy(9 + (j * 13), centre + (i / 5)); } } }
int main (int argc, char **argv) { int dat_count; /* size of the dat array */ int i; int mono = 0; /* running on monochrome monitor */ dat_t *dat_ary; /* the dat file array */ inst_t ret; /* no. of errors, warnings */ struct text_info ti; /* (borland) for gettextinfo */ /* Open the language catalog */ cat = catopen ("install", 0); /* Check command line */ for (i = 1; i < argc; i++) { if (strcmpi(argv[i], "/mono") == 0) mono = 1; else if (strcmpi(argv[i], "/nopause") == 0) nopauseflag = 1; else if (strcmpi(argv[i], "/nolog") == 0) wantlog = 0; else if ( (strcmpi(argv[i], "/src") == 0) && (i+1 < argc)) { fromdirflag = 1; i++; strcpy(fromdir+2, argv[i]); } else if ( (strcmpi(argv[i], "/dst") == 0) && (i+1 < argc)) { destdirflag = 1; i++; strcpy(destdir+2, argv[i]); } else { fprintf (stderr, catgets (cat, SET_USAGE, MSG_USAGE, MSG_USAGE_STR)); exit (1); } } /* unzip overwrites screen with warning if TZ not set, so check */ /* and if not set, then set for us to GMT0, which means no offsets */ if (getenv("TZ") == NULL) putenv("TZ=GMT0"); /* Read dat file */ dat_ary = dat_read ("INSTALL.DAT", &dat_count); if (dat_ary == NULL) { if (dat_count > 0) { fprintf (stderr, catgets (cat, SET_ERRORS, MSG_ERRALLOCMEMDF, MSG_ERRALLOCMEMDF_STR)); exit (2); } else /* Either error reading file, eg no file, or file has no entries */ { fprintf (stderr, catgets (cat, SET_ERRORS, MSG_ERREMPTYDATAFILE, MSG_ERREMPTYDATAFILE_STR)); exit (3); } } /* Get localized "Yes" and "No" strings */ getLocalizedYesNo(); /* register our SIGINT handler (Ctrl-C) */ registerSIGINTHandler(); /* Start the install */ /* save current setting so we can restore them */ gettextinfo (&ti); /* setup screen colors then draw the screen */ if (mono) { textbackground (BLACK); textcolor (LIGHTGRAY); } else { textbackground (BLUE); textcolor (WHITE); } repaint_empty(); gotoxy (2, 3); cat_file ("COPYR", 18); pause(); repaint_empty(); gotoxy (2, 3); cat_file ("OEM", 18); pause(); ret.errors = 0; ret.warnings = 0; ret = install_top (dat_ary, dat_count); /* Finished with install */ textattr (ti.attribute); /* restore user's screen */ clrscr(); if ((ret.errors == 0) && (ret.warnings == 0)) printf (catgets (cat, SET_GENERAL, MSG_INSTALLOK, MSG_INSTALLOK_STR)); else printf (catgets (cat, SET_GENERAL, MSG_INSTALLERRORS, MSG_INSTALLERRORS_STR), ret.errors, ret.warnings); /* Done */ free (dat_ary); free (yes); free (no); catclose (cat); /* restore original SIGINT handler */ unregisterSIGINTHandler(); return (0); }
/* Read ossec config */ int config_read(HWND hwnd) { char *tmp_str; char *delim = " - "; /* Clear config */ config_clear(); /* Get OSSEC status */ if (CheckServiceRunning()) { config_inst.status = ST_RUNNING; } else { config_inst.status = ST_STOPPED; } /* Get version/install date */ config_inst.version = cat_file(VERSION_FILE, NULL); if (config_inst.version) { config_inst.install_date = strstr(config_inst.version, delim); if (config_inst.install_date) { *config_inst.install_date = '\0'; config_inst.install_date += strlen(delim); } } /* Get number of messages sent */ tmp_str = cat_file(SENDER_FILE, NULL); if (tmp_str) { unsigned long int tmp_val = 0; char *to_free = tmp_str; tmp_val = atol(tmp_str); if (tmp_val) { config_inst.msg_sent = tmp_val * 9999; tmp_str = strchr(tmp_str, ':'); if (tmp_str) { tmp_str++; tmp_val = atol(tmp_str); config_inst.msg_sent += tmp_val; } } free(to_free); } /* Get agent ID, name and IP */ tmp_str = cat_file(AUTH_FILE, NULL); if (tmp_str) { /* Get base 64 */ config_inst.key = encode_base64(strlen(tmp_str), tmp_str); if (config_inst.key == NULL) { config_inst.key = FL_NOKEY; } /* Get ID */ config_inst.agentid = tmp_str; tmp_str = strchr(tmp_str, ' '); if (tmp_str) { *tmp_str = '\0'; tmp_str++; /* Get name */ config_inst.agentname = tmp_str; tmp_str = strchr(tmp_str, ' '); if (tmp_str) { *tmp_str = '\0'; tmp_str++; /* Get IP */ config_inst.agentip = tmp_str; tmp_str = strchr(tmp_str, ' '); if (tmp_str) { *tmp_str = '\0'; } } } } if (config_inst.agentip == NULL) { config_inst.agentid = strdup(ST_NOTSET); config_inst.agentname = strdup("Auth key not imported."); config_inst.agentip = ST_NOTSET; config_inst.status = ST_MISSING_IMPORT; } /* Get server IP */ if (!get_ossec_server()) { if (strcmp(config_inst.status, ST_MISSING_IMPORT) == 0) { config_inst.status = ST_MISSING_ALL; } else { config_inst.status = ST_MISSING_SERVER; } } return (0); }
bool test_pc(case_t *pc_case) { int drv_on = 0; int ret; while(true) { ret = cat_file(pc_case->nod_path); if(ret == -1) return false; if(ret) { draw_result(pc_case, true); if(!drv_on) { if (!strcmp(pc_case->dev_name, "7059")) { pcba_system("echo 0 > /sys/class/android_usb/android0/enable"); pcba_system("echo mass_storage > /sys/class/android_usb/android0/functions"); pcba_system("echo 1 > /sys/class/android_usb/android0/enable"); } else if (!strcmp(pc_case->dev_name, "7021")) { if(!insmod_drv("udc", "", 1)) return false; if(!insmod_drv("g_android", "", 1)) return false; pcba_system("echo 0 > /sys/class/android_usb/android0/enable"); pcba_system("echo mass_storage > /sys/class/android_usb/android0/functions"); pcba_system("echo 1 > /sys/class/android_usb/android0/enable"); } else if (!strcmp(pc_case->dev_name, "9009")) { if(!insmod_drv("libcomposite", "", 1)) return false; if(!insmod_drv("u_serial", "", 1)) return false; if(!insmod_drv("usb_f_acm", "", 1)) return false; if(!insmod_drv("g_android", "", 1)) return false; pcba_system("echo 0 > /sys/class/android_usb/android0/enable"); pcba_system("echo 10d6 > /sys/class/android_usb/android0/idVendor"); pcba_system("echo 0c02> /sys/class/android_usb/android0/idProduct"); pcba_system("echo mass_storage > /sys/class/android_usb/android0/functions"); pcba_system("echo 1 > /sys/class/android_usb/android0/enable"); //pcba_system("echo /dev/actk > /sys/class/android_usb/f_mass_storage/lun0/file"); } else { if(!insmod_drv("dwc3", "", 1)) return false; if(!insmod_drv("dwc3-actions", "", 1)) return false; if(!insmod_drv("g_android", "", 1)) return false; pcba_system("echo 0 > /sys/class/android_usb/android0/enable"); pcba_system("echo mass_storage > /sys/class/android_usb/android0/functions"); pcba_system("echo 1 > /sys/class/android_usb/android0/enable"); } drv_on = 1; } } else { if(drv_on) { if (!strcmp(pc_case->dev_name, "7059")) { ; //do nothing } else if (!strcmp(pc_case->dev_name, "7021")) { if(!insmod_drv("g_android", "", 0)) return false; if(!insmod_drv("udc", "", 0)) return false; } else if (!strcmp(pc_case->dev_name, "9009")) { /*if(!insmod_drv("g_android", "", 0)) return false; if(!insmod_drv("usb_f_acm", "", 0)) return false; if(!insmod_drv("u_serial", "", 0)) return false; if(!insmod_drv("libcomposite", "", 0)) return false;*/ } else { if(!insmod_drv("g_android", "", 0)) return false; if(!insmod_drv("dwc3-actions", "", 0)) return false; if(!insmod_drv("dwc3", "", 0)) return false; } drv_on = 0; } } direct_thread_sleep(1000000); } }