librazor/rpm.c
changeset 328 45ea57d83f28
parent 327 c85643dd7164
child 329 d675c5ac6d07
     1.1 --- a/librazor/rpm.c	Thu Jan 08 13:51:07 2009 +0000
     1.2 +++ b/librazor/rpm.c	Thu Jan 08 14:35:18 2009 +0000
     1.3 @@ -567,7 +567,11 @@
     1.4  run_script(struct installer *installer,
     1.5  	   unsigned int program_tag, unsigned int script_tag)
     1.6  {
     1.7 +#if HAVE_CHROOT
     1.8  	int pid, status, fd[2];
     1.9 +#else
    1.10 +	FILE *fp;
    1.11 +#endif
    1.12  	const char *script = NULL, *program = NULL;
    1.13  
    1.14  	program = razor_rpm_get_indirect(installer->rpm, program_tag, NULL);
    1.15 @@ -575,9 +579,21 @@
    1.16  	if (program == NULL && script == NULL) {
    1.17  		return 0;
    1.18  	} else if (program == NULL) {
    1.19 +#if MSWIN_API
    1.20 +		program = getenv("COMSPEC");
    1.21 +		if (program) {
    1.22 +			program = strchr(program, '=');
    1.23 +			if (program)
    1.24 +				program++;
    1.25 +		}
    1.26 +		if (!program)
    1.27 +			program = "c:\\windows\\system32\\cmd.exe";
    1.28 +#else
    1.29  		program = "/bin/sh";
    1.30 +#endif
    1.31  	}
    1.32  
    1.33 +#if HAVE_CHROOT
    1.34  	if (pipe(fd) < 0) {
    1.35  		fprintf(stderr, "failed to create pipe\n");
    1.36  		return -1;
    1.37 @@ -621,6 +637,14 @@
    1.38  		if (status)
    1.39  			printf("script exited with status %d\n", status);
    1.40  	}
    1.41 +#else
    1.42 +	fp = popen(program, "w");
    1.43 +	if (fwrite(script, strlen(script), 1, fp) != 1) {
    1.44 +		fprintf(stderr, "failed to pipe script, %m\n");
    1.45 +		return -1;
    1.46 +	}
    1.47 +	pclose(fp);
    1.48 +#endif
    1.49  
    1.50  	return 0;
    1.51  }