1.1 --- a/librazor/rpm.c Fri Jul 03 18:02:33 2009 +0100
1.2 +++ b/librazor/rpm.c Fri Apr 23 21:07:15 2010 +0100
1.3 @@ -874,7 +874,8 @@
1.4 }
1.5
1.6 static int
1.7 -run_script_lua(const char *root, unsigned int script_tag, const char *script)
1.8 +run_script_lua(const char *root, unsigned int script_tag, const char *script,
1.9 + int arg1)
1.10 {
1.11 int root_fd, retval;
1.12 #if HAVE_LUA
1.13 @@ -898,7 +899,8 @@
1.14 break;
1.15 }
1.16 root_fd = chroot_push(root);
1.17 - retval = run_lua_script(root_fd < 0 ? root : NULL, name, script, -1);
1.18 + retval = run_lua_script(root_fd < 0 ? root : NULL, name, script, -1,
1.19 + arg1);
1.20 chroot_pop(root_fd);
1.21 #else /* HAVE_LUA */
1.22 fprintf(stderr, "lua not available to run script\n");
1.23 @@ -909,10 +911,12 @@
1.24 }
1.25
1.26 static int
1.27 -run_script_external(const char *root, const char *program, const char *script)
1.28 +run_script_external(const char *root, const char *program, const char *script,
1.29 + int arg1)
1.30 {
1.31 int root_fd, retval;
1.32 FILE *fp;
1.33 + char buf[32], *command;
1.34
1.35 if (program == NULL) {
1.36 #if MSWIN_API
1.37 @@ -930,7 +934,14 @@
1.38 }
1.39
1.40 root_fd = chroot_push(root);
1.41 - fp = popen(program, "w");
1.42 + if (arg1 >= 0) {
1.43 + sprintf(buf, "%d", arg1);
1.44 + command = malloc(strlen(program) + strlen(buf) + 2);
1.45 + sprintf(command, "%s %s", program, buf);
1.46 + } else
1.47 + command = strdup(program);
1.48 + fp = popen(command, "w");
1.49 + free(command);
1.50
1.51 if (!fp) {
1.52 perror(program);
1.53 @@ -950,12 +961,12 @@
1.54
1.55 static int
1.56 run_script(struct installer *installer,
1.57 - unsigned int program_tag, unsigned int script_tag)
1.58 + unsigned int program_tag, unsigned int script_tag, int arg1)
1.59 {
1.60 int i, retval;
1.61 struct razor_rpm *rpm = installer->rpm;
1.62 const char *script = NULL, *program = NULL, *prefix;
1.63 - char buf[32], *p;
1.64 + char buf[32];
1.65 struct environment env;
1.66
1.67 program = razor_rpm_get_indirect(rpm, program_tag, NULL);
1.68 @@ -975,9 +986,11 @@
1.69 }
1.70
1.71 if (program && strcmp(program, "<lua>") == 0)
1.72 - retval = run_script_lua(installer->root, script_tag, script);
1.73 + retval = run_script_lua(installer->root, script_tag, script,
1.74 + arg1);
1.75 else
1.76 - retval = run_script_external(installer->root, program, script);
1.77 + retval = run_script_external(installer->root, program, script,
1.78 + arg1);
1.79
1.80 if (rpm->relocations) {
1.81 environment_unset(&env);
1.82 @@ -989,7 +1002,7 @@
1.83
1.84 int
1.85 razor_run_script(const char *root, enum razor_property_flags script,
1.86 - const char *program, const char *body)
1.87 + const char *program, const char *body, int arg1)
1.88 {
1.89 int retval;
1.90 unsigned int script_tag;
1.91 @@ -1020,10 +1033,10 @@
1.92 script_tag = 0;
1.93 break;
1.94 }
1.95 - retval = run_script_lua(root, script_tag, body);
1.96 + retval = run_script_lua(root, script_tag, body, arg1);
1.97 }
1.98 else
1.99 - retval = run_script_external(root, program, body);
1.100 + retval = run_script_external(root, program, body, arg1);
1.101
1.102 return retval;
1.103 }
1.104 @@ -1101,7 +1114,7 @@
1.105 }
1.106
1.107 RAZOR_EXPORT int
1.108 -razor_rpm_install(struct razor_rpm *rpm, const char *root)
1.109 +razor_rpm_install(struct razor_rpm *rpm, const char *root, int install_count)
1.110 {
1.111 struct installer installer;
1.112 struct cpio_file_header *header;
1.113 @@ -1130,7 +1143,7 @@
1.114 if (installer_init(&installer))
1.115 return -1;
1.116
1.117 - run_script(&installer, RPMTAG_PREINPROG, RPMTAG_PREIN);
1.118 + run_script(&installer, RPMTAG_PREINPROG, RPMTAG_PREIN, install_count);
1.119
1.120 while (installer.stream.avail_in > 0) {
1.121 installer.rest = sizeof *header;
1.122 @@ -1167,7 +1180,7 @@
1.123 if (installer_finish(&installer))
1.124 return -1;
1.125
1.126 - run_script(&installer, RPMTAG_POSTINPROG, RPMTAG_POSTIN);
1.127 + run_script(&installer, RPMTAG_POSTINPROG, RPMTAG_POSTIN, install_count);
1.128
1.129 return 0;
1.130 }