diff --git a/scl-utils.spec b/scl-utils.spec index 89cac0e..5fe4d4f 100644 --- a/scl-utils.spec +++ b/scl-utils.spec @@ -1,6 +1,6 @@ Summary: Utilities for alternative packaging Name: scl-utils -Version: 20120125 +Version: 20120209 Release: 1%{?dist} License: GPLv2+ Group: Applications/File @@ -47,6 +47,13 @@ rm -rf %buildroot %{_sysconfdir}/rpm/macros.scl %changelog +* Thu Feb 09 2012 Jindrich Novy 20120209-1 +- fix minor bugs (#788194) + - clear temp files + - handle commands from stdin properly + - run command even if ran as "scl enable SCL command" from already + enabled SCL + * Wed Jan 25 2012 Jindrich Novy 20120125-1 - remove dsc macros - trigger scl-utils-build BR inclusion while using scl macros diff --git a/scl.c b/scl.c index 5409a68..5ab3d3f 100644 --- a/scl.c +++ b/scl.c @@ -58,7 +58,13 @@ int main(int argc, char **argv) { int i, tfd, ffd, stdin_read = 0; if (!strcmp(argv[argc-1], "-")) { /* reading command from stdin */ - size_t r = 0; + size_t r; + + if (argc < 4) { + fprintf(stderr, "Need at least 3 arguments.\nRun %s without arguments to get help.\n", argv[0]); + exit(EXIT_FAILURE); + } + cmd = malloc(BUFSIZ); if (!cmd) { @@ -66,9 +72,9 @@ int main(int argc, char **argv) { exit(EXIT_FAILURE); } - for (;(r += fread(cmd+r, 1, BUFSIZ, stdin));) { + for (r=0; (r += fread(cmd+r, 1, BUFSIZ, stdin));) { if (feof(stdin)) break; - cmd = realloc(cmd, r); + cmd = realloc(cmd, r+BUFSIZ); if (!cmd) { fprintf(stderr, "Can't reallocate memory.\n"); exit(EXIT_FAILURE); @@ -92,10 +98,10 @@ int main(int argc, char **argv) { tfd = mkstemp(tmp); - check_asprintf(&enabled, "scl_enabled %s\n[ $? == 0 ] && exit 1\n" - "eval \"SCLS=( ${x_scls[*]} )\"\n" - "SCLS+=(%s)\n" - "export X_SCLS=$(printf '%%q ' \"${SCLS[@]}\")\n", argv[2], argv[2]); + check_asprintf(&enabled, "scl_enabled %s\nif [ $? != 0 ]; then\n" + " eval \"SCLS=( ${x_scls[*]} )\"\n" + " SCLS+=(%s)\n" + " export X_SCLS=$(printf '%%q ' \"${SCLS[@]}\")\nfi\n", argv[2], argv[2]); write_script(tfd, enabled); free(enabled); @@ -107,11 +113,13 @@ int main(int argc, char **argv) { check_asprintf(&path, "/etc/scl/prefixes/%s", argv[i]); if (!(f=fopen(path,"r"))) { fprintf(stderr, "Unable to open %s!\n", path); + unlink(tmp); exit(EXIT_FAILURE); } r = fread(scl_dir, 1, BUFSIZ, f); if (!r) { fprintf(stderr, "Unable to read or file empty %s!\n", path); + unlink(tmp); exit(EXIT_FAILURE); } scl_dir[r-1] = '\0'; @@ -124,10 +132,12 @@ int main(int argc, char **argv) { check_asprintf(&path, "%s", scl_dir); if (lstat(path, &st)) { fprintf(stderr, "%s doesn't exist\n", path); + unlink(tmp); exit(EXIT_FAILURE); } if (!S_ISDIR(st.st_mode)) { fprintf(stderr, "%s is not a directory\n", path); + unlink(tmp); exit(EXIT_FAILURE); } check_asprintf(&enablepath, "%s/%s", path, argv[1]); @@ -139,6 +149,7 @@ int main(int argc, char **argv) { write_script(tfd, echo); } else { fprintf(stderr, "WARNING: %s scriptlet does not exist!\n", enablepath); + unlink(tmp); exit(EXIT_FAILURE); } @@ -155,6 +166,7 @@ int main(int argc, char **argv) { check_asprintf(&bash_cmd, "/bin/bash %s", tmp); i = system(bash_cmd); free(bash_cmd); + unlink(tmp); return WEXITSTATUS(i); }