void storage_register_task(struct plugin_instance *p) { int fd; char name[256]; memset(name, 0, sizeof(name)); snprintf(name, sizeof(name), "%s%s", DATABASE_DIR, p->name); fd = open(name, O_RDWR); if (fd < 0) { fd = storage_create_db(name, p->schedule_int, p->block_entries, p->cells_per_block); if (fd < 0) panic("Cannot create database!\n"); printd("timedb database %s created!\n", name); } p->timedb_fd = fd; if (!ioprio_set_flag) { ioprio_setpid(getpid(), 4, ioprio_class_rt); ioprio_set_flag = 1; } }
int main(int argc, char **argv) { int data = 4, set = 0, ioclass = IOPRIO_CLASS_BE, c; pid_t pid = 0; static const struct option longopts[] = { { "classdata", required_argument, NULL, 'n' }, { "class", required_argument, NULL, 'c' }, { "help", no_argument, NULL, 'h' }, { "ignore", no_argument, NULL, 't' }, { "pid", required_argument, NULL, 'p' }, { "version", no_argument, NULL, 'V' }, { NULL, 0, NULL, 0 } }; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); atexit(close_stdout); while ((c = getopt_long(argc, argv, "+n:c:p:tVh", longopts, NULL)) != EOF) switch (c) { case 'n': data = strtos32_or_err(optarg, _("invalid class data argument")); set |= 1; break; case 'c': if (isdigit(*optarg)) ioclass = strtos32_or_err(optarg, _("invalid class argument")); else { ioclass = parse_ioclass(optarg); if (ioclass < 0) errx(EXIT_FAILURE, _("unknown scheduling class: '%s'"), optarg); } set |= 2; break; case 'p': pid = strtos32_or_err(optarg, _("invalid PID argument")); break; case 't': tolerant = 1; break; case 'V': printf(_("%s from %s\n"), program_invocation_short_name, PACKAGE_STRING); return EXIT_SUCCESS; case 'h': usage(stdout); default: usage(stderr); } switch (ioclass) { case IOPRIO_CLASS_NONE: if ((set & 1) && !tolerant) warnx(_("ignoring given class data for none class")); data = 0; break; case IOPRIO_CLASS_RT: case IOPRIO_CLASS_BE: break; case IOPRIO_CLASS_IDLE: if ((set & 1) && !tolerant) warnx(_("ignoring given class data for idle class")); data = 7; break; default: if (!tolerant) warnx(_("unknown prio class %d"), ioclass); break; } if (!set && !pid && optind == argc) /* * ionice without options, print the current ioprio */ ioprio_print(0); else if (!set && pid) { /* * ionice -p PID [PID ...] */ ioprio_print(pid); for(; argv[optind]; ++optind) { pid = strtos32_or_err(argv[optind], _("invalid PID argument")); ioprio_print(pid); } } else if (set && pid) { /* * ionice -c CLASS -p PID [PID ...] */ ioprio_setpid(pid, ioclass, data); for(; argv[optind]; ++optind) { pid = strtos32_or_err(argv[optind], _("invalid PID argument")); ioprio_setpid(pid, ioclass, data); } } else if (argv[optind]) { /* * ionice [-c CLASS] COMMAND */ ioprio_setpid(0, ioclass, data); execvp(argv[optind], &argv[optind]); err(EXIT_FAILURE, _("failed to execute %s"), argv[optind]); } else usage(stderr); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { int ioprio = 4, set = 0, ioclass = IOPRIO_CLASS_BE, c; pid_t pid = 0; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); while ((c = getopt(argc, argv, "+n:c:p:th")) != EOF) { switch (c) { case 'n': ioprio = strtol_or_err(optarg, _("failed to parse class data")); set |= 1; break; case 'c': ioclass = strtol_or_err(optarg, _("failed to parse class")); set |= 2; break; case 'p': pid = strtol_or_err(optarg, _("failed to parse pid")); break; case 't': tolerant = 1; break; case 'h': usage(EXIT_SUCCESS); default: usage(EXIT_FAILURE); } } switch (ioclass) { case IOPRIO_CLASS_NONE: if (set & 1) warnx(_("ignoring given class data for none class")); ioprio = 0; break; case IOPRIO_CLASS_RT: case IOPRIO_CLASS_BE: break; case IOPRIO_CLASS_IDLE: if (set & 1) warnx(_("ignoring given class data for idle class")); ioprio = 7; break; default: errx(EXIT_FAILURE, _("bad prio class %d"), ioclass); } if (!set) { ioprio_print(pid); for(; argv[optind]; ++optind) { pid = strtol_or_err(argv[optind], _("failed to parse pid")); ioprio_print(pid); } } else { if (pid) { ioprio_setpid(pid, ioprio, ioclass); for(; argv[optind]; ++optind) { pid = strtol_or_err(argv[optind], _("failed to parse pid")); ioprio_setpid(pid, ioprio, ioclass); } } else if (argv[optind]) { ioprio_setpid(0, ioprio, ioclass); execvp(argv[optind], &argv[optind]); /* execvp should never return */ err(EXIT_FAILURE, _("executing %s failed"), argv[optind]); } } exit(EXIT_SUCCESS); }