static void __parse_options(int argc, char *argv[]) { int next_option; const char *progname = basename(argv[0]); /* Set the default option values before parsing args */ __set_default_options(progname); /* A string listing valid short options letters */ const char* const short_options = "hl:m:np:T:U:v"; /* An array describing valid long options */ const struct option long_options[] = { { "help", 0, NULL, 'h' }, { "loglevel", 1, NULL, 'l' }, { "tracemask", 1, NULL, 'm' }, { "nofork", 0, NULL, 'n' }, { "pidfile", 1, NULL, 'p' }, { "tracefile", 1, NULL, 'T' }, { "run-as", 1, NULL, 'U' }, { "version", 0, NULL, 'v' }, { NULL, 0, NULL, 0 } /* Required at end of array */ }; do { next_option = getopt_long(argc, argv, short_options, long_options, NULL); switch(next_option) { case 'h': /* -h or --help */ __print_usage(progname, stdout, EXIT_SUCCESS); case 'l': /* -l or --loglevel */ __logmask = level2mask(optarg); break; case 'm': /* -m or --tracemask */ __tracemask = strtoul(optarg, NULL, 0); break; case 'n': /* -n or --nofork */ __nofork = 1; break; case 'p': /* -p or --pidfile */ snprintf(__pidfile, sizeof(__pidfile), PKGPIDDIR "/%s", optarg); break; case 'T': /* -T or --tracefile */ snprintf(__tracefile, sizeof(__tracefile), "%s", optarg); break; case 'U': /* -U or --run-as */ snprintf(__runas_username, sizeof(__runas_username), "%s", optarg); break; case 'v': /* -v or --version */ /* TODO */ break; case '?': /* The user specified an invalid option */ __print_usage(progname, stderr, EXIT_FAILURE); case EOF: /* Done with options. */ break; default: /* Something else: unexpected */ abort(); } } while (next_option != EOF); }
static void create_sections(void *ttb, uint64_t virt, uint64_t phys, uint64_t size, uint64_t attr) { uint64_t block_size; uint64_t block_shift; uint64_t *pte; uint64_t idx; uint64_t addr; uint64_t *table; addr = virt; attr &= ~PTE_TYPE_MASK; table = ttb; while (1) { block_shift = level2shift(1); idx = (addr & level2mask(1)) >> block_shift; block_size = (1ULL << block_shift); pte = table + idx; *pte = phys | attr | PTE_TYPE_BLOCK; if (size < block_size) break; addr += block_size; phys += block_size; size -= block_size; } }
static void __set_default_options(const char *progname) { /* Set the default option values */ snprintf(__pidfile, sizeof(__pidfile), PKGPIDDIR "/%s.pid", progname); snprintf(__tracefile, sizeof(__tracefile), PKGLOGDIR "/%s", progname); if (strlen(__runas_username) == 0) { char *uname = getenv("OPENSAF_USER"); if (uname) snprintf(__runas_username, sizeof(__runas_username), "%s", uname); else snprintf(__runas_username, sizeof(__runas_username), DEFAULT_RUNAS_USERNAME); } __logmask = level2mask("notice"); }