X-Git-Url: https://git.distorted.org.uk/~mdw/sw-tools/blobdiff_plain/3315e8b31a4707ef2c5491d0c9a9c9a09816bcb2..65712207f6586ef1a710e5d535baec4316451887:/src/sw_info.c diff --git a/src/sw_info.c b/src/sw_info.c index 3b4a611..2dad0ca 100644 --- a/src/sw_info.c +++ b/src/sw_info.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: sw_info.c,v 1.1 1999/06/02 16:53:35 mdw Exp $ + * $Id: sw_info.c,v 1.6 2004/04/08 01:52:19 mdw Exp $ * * Maintenance of `.sw-info' files * @@ -26,20 +26,13 @@ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: sw_info.c,v $ - * Revision 1.1 1999/06/02 16:53:35 mdw - * Initial revision - * - */ - /*----- Header files ------------------------------------------------------*/ #include "config.h" #include #include +#include #include #include #include @@ -47,9 +40,14 @@ #include #include +#include #include #include +#ifndef DECL_ENVIRON + extern char **environ; +#endif + #include #include #include @@ -57,6 +55,7 @@ #include #include "sw_arch.h" +#include "sw_env.h" #include "sw_info.h" /*----- Static variables --------------------------------------------------*/ @@ -412,8 +411,8 @@ int sw_commit(int argc, char *argv[]) aa = arch_filter(all, sw.only_arch, archFlag_built, 0); if (aa) { - char *sep = " "; - fprintf(stderr, "%s: not built for", QUIS); + const char *sep = ""; + fprintf(stderr, "%s: not built for ", QUIS); for (a = aa; a; a = a->cdr) { fprintf(stderr, "%s%s", sep, a->car->arch); sep = ", "; @@ -424,12 +423,73 @@ int sw_commit(int argc, char *argv[]) arch_free(aa); } + /* --- Run the local precommit check script --- */ + + { + pid_t kid; + struct sigaction sa, sa_int, sa_quit; + int status; + + /* --- Make sure I can trap the child's death --- */ + + sa.sa_handler = SIG_IGN; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + if (sigaction(SIGINT, &sa, &sa_int) || sigaction(SIGQUIT, &sa, &sa_quit)) + die(1, "couldn't set signal dispositions: %s", strerror(errno)); + + /* --- Spawn off a child process --- */ + + fflush(0); + kid = fork(); + if (kid < 0) + die(1, "error from fork: %s", strerror(errno)); + if (kid == 0) { + sym_table t; + + /* --- Re-enable signals --- */ + + sigaction(SIGINT, &sa_int, 0); + sigaction(SIGQUIT, &sa_quit, 0); + + /* --- Set up the environment --- */ + + sym_create(&t); + env_import(&t, environ); + env_put(&t, "SW_PACKAGE", sw.package); + env_put(&t, "SW_VERSION", sw.version); + env_put(&t, "SW_MAINTAINER", sw.maintainer); + env_put(&t, "SW_DATE", sw.date); + env_put(&t, "SW_ARCHLIST", sw.arch); + env_put(&t, "SW_PREFIX", PREFIX); + environ = env_export(&t); + + /* --- Run the commit check script --- */ + + execl(PREFIX "/share/sw-precommit", "sw-precommit", + sw.package, (char *)0); + if (errno == ENOENT) + _exit(0); + die(1, "couldn't run " PREFIX "/share/sw-precommit: %s", + strerror(errno)); + } + + /* --- Wait for the child to finish --- */ + + if (waitpid(kid, &status, 0) < 0) + die(1, "error waiting for child: %s", strerror(errno)); + if (!(WIFEXITED(status) && WEXITSTATUS(status) == 0)) + die(1, "sw-precommit failed"); + sigaction(SIGINT, &sa_int, 0); + sigaction(SIGQUIT, &sa_quit, 0); + } + /* --- Write to the index file --- */ { FILE *fp = fopen(PREFIX "/sw-index", "a"); swfield *f; - char *sep = ""; + const char *sep = ""; if (!fp) die(1, "couldn't open index file: %s", strerror(errno));