-/*
- * Execute a particular fsck program, and link it into the list of
- * child processes we are waiting for.
- */
-static int execute(const char *type, const char *device, const char *mntpt,
- int interactive)
-{
- char *s, *argv[80];
- char *prog;
- int argc, i;
- struct fsck_instance *inst, *p;
- pid_t pid;
-
- inst = malloc(sizeof(struct fsck_instance));
- if (!inst)
- return ENOMEM;
- memset(inst, 0, sizeof(struct fsck_instance));
-
- prog = bb_xasprintf("fsck.%s", type);
- argv[0] = prog;
- argc = 1;
-
- for (i=0; i <num_args; i++)
- argv[argc++] = string_copy(args[i]);
-
- if (progress && !progress_active()) {
- if ((strcmp(type, "ext2") == 0) ||
- (strcmp(type, "ext3") == 0)) {
- char tmp[80];
- snprintf(tmp, 80, "-C%d", progress_fd);
- argv[argc++] = string_copy(tmp);
- inst->flags |= FLAG_PROGRESS;
- }
- }
-
- argv[argc++] = string_copy(device);
- argv[argc] = 0;
-
- s = find_fsck(prog);
- if (s == NULL) {
- bb_error_msg("%s: not found", prog);
- return ENOENT;
- }
-
- if (verbose || noexecute) {
- printf("[%s (%d) -- %s] ", s, num_running,
- mntpt ? mntpt : device);
- for (i=0; i < argc; i++)
- printf("%s ", argv[i]);
- printf("\n");
- }
-
- /* Fork and execute the correct program. */
- if (noexecute)
- pid = -1;
- else if ((pid = fork()) < 0) {
- perror("fork");
- return errno;
- } else if (pid == 0) {
- if (!interactive)
- close(0);
- (void) execv(s, argv);
- bb_perror_msg_and_die("%s", argv[0]);
- }
-
- for (i = 1; i < argc; i++)
- free(argv[i]);
-
- free(s);
- inst->pid = pid;
- inst->prog = prog;
- inst->type = string_copy(type);
- inst->device = string_copy(device);
- inst->base_device = base_device(device);
- inst->start_time = time(0);
- inst->next = NULL;
-
- /*
- * Find the end of the list, so we add the instance on at the end.
- */
- for (p = instance_list; p && p->next; p = p->next);
-
- if (p)
- p->next = inst;
- else
- instance_list = inst;
-
- return 0;
-}