int maintainer_script_new(struct pkginfo *pkg, const char *scriptname, const char *desc, const char *cidir, char *cidirrest, ...) { struct command cmd; struct stat stab; va_list args; char buf[100]; strcpy(cidirrest, scriptname); sprintf(buf, _("new %s script"), desc); va_start(args, cidirrest); command_init(&cmd, cidir, buf); command_add_arg(&cmd, scriptname); command_add_argv(&cmd, args); va_end(args); if (stat(cidir,&stab)) { command_destroy(&cmd); if (errno == ENOENT) { debug(dbg_scripts,"maintainer_script_new nonexistent %s `%s'",scriptname,cidir); return 0; } ohshite(_("unable to stat %s `%.250s'"), buf, cidir); } do_script(pkg, &pkg->available, &cmd, &stab, 0); command_destroy(&cmd); post_script_tasks(); return 1; }
static void DPKG_ATTR_SENTINEL fd_fd_filter(int fd_in, int fd_out, const char *desc, const char *delenv[], const char *file, ...) { va_list args; struct command cmd; pid_t pid; int i; pid = subproc_fork(); if (pid == 0) { if (fd_in != 0) { m_dup2(fd_in, 0); close(fd_in); } if (fd_out != 1) { m_dup2(fd_out, 1); close(fd_out); } for (i = 0; delenv[i]; i++) unsetenv(delenv[i]); command_init(&cmd, file, desc); command_add_arg(&cmd, file); va_start(args, file); command_add_argv(&cmd, args); va_end(args); command_exec(&cmd); } subproc_reap(pid, desc, 0); }
static int vmaintainer_script_installed(struct pkginfo *pkg, const char *scriptname, const char *desc, va_list args) { struct command cmd; const char *scriptpath; struct stat stab; char buf[100]; scriptpath = pkgadminfile(pkg, &pkg->installed, scriptname); sprintf(buf, _("installed %s script"), desc); command_init(&cmd, scriptpath, buf); command_add_arg(&cmd, scriptname); command_add_argv(&cmd, args); if (stat(scriptpath,&stab)) { command_destroy(&cmd); if (errno == ENOENT) { debug(dbg_scripts, "vmaintainer_script_installed nonexistent %s", scriptname); return 0; } ohshite(_("unable to stat %s `%.250s'"), buf, scriptpath); } do_script(pkg, &pkg->installed, &cmd, &stab, 0); command_destroy(&cmd); return 1; }
/** * Append a variable list of argument to the command's argv. * * @param cmd The command structure to act on. * @param ... The NULL terminated variable list of argument to append to argv. */ void command_add_args(struct command *cmd, ...) { va_list args; va_start(args, cmd); command_add_argv(cmd, args); va_end(args); }