Browse Source

Removed duplicate code that was used to exec maintainer scripts, and moved
it to a single function. In the future, this single function could be used
for tracking script execution.

Adam Heath 25 years ago
parent
commit
a59a84b26a
4 changed files with 37 additions and 52 deletions
  1. 7 0
      ChangeLog
  2. 3 3
      main/cleanup.c
  3. 24 46
      main/help.c
  4. 3 3
      main/processarc.c

+ 7 - 0
ChangeLog

@@ -1,3 +1,10 @@
+Sun Jan 14 02:37:05 CST 2001 Adam Heath <doogie@debian.org>
+
+  * main/cleanup.c, main/help.c, main/processarc.c:  Removed duplicate
+    code that was used to exec maintainer scripts, and moved it to a
+    single function.  In the future, this single function could be used
+    for tracking script execution.
+
 Sun Jan 14 02:27:48 CST 2001 Adam Heath <doogie@debian.org>
 
   * main/main.h, main/main.c:  Change --{status,command}-pipe to

+ 3 - 3
main/cleanup.c

@@ -161,7 +161,7 @@ void cu_preinstverynew(int argc, void **argv) {
   char *cidirrest= (char*)argv[2];
 
   if (cleanup_pkg_failed++) return;
-  maintainer_script_new(POSTRMFILE,"post-removal",cidir,cidirrest,
+  maintainer_script_new(pkg->name, POSTRMFILE,"post-removal",cidir,cidirrest,
                         "abort-install",(char*)0);
   pkg->status= stat_notinstalled;
   pkg->eflag &= ~eflagf_reinstreq;
@@ -175,7 +175,7 @@ void cu_preinstnew(int argc, void **argv) {
   char *cidirrest= (char*)argv[2];
 
   if (cleanup_pkg_failed++) return;
-  maintainer_script_new(POSTRMFILE,"post-removal",cidir,cidirrest,
+  maintainer_script_new(pkg->name, POSTRMFILE,"post-removal",cidir,cidirrest,
                         "abort-install", versiondescribe(&pkg->installed.version,
                                                          vdew_nonambig),
                         (char*)0);
@@ -192,7 +192,7 @@ void cu_preinstupgrade(int argc, void **argv) {
   enum pkgstatus *oldstatusp= (enum pkgstatus*)argv[3];
 
   if (cleanup_pkg_failed++) return;
-  maintainer_script_new(POSTRMFILE,"post-removal",cidir,cidirrest,
+  maintainer_script_new(pkg->name, POSTRMFILE,"post-removal",cidir,cidirrest,
                         "abort-upgrade",
                         versiondescribe(&pkg->installed.version,
                                         vdew_nonambig),

+ 24 - 46
main/help.c

@@ -252,6 +252,22 @@ static void setexecute(const char *path, struct stat *stab) {
   if (!chmod(path,0755)) return;
   ohshite(_("unable to set execute permissions on `%.250s'"),path);
 }
+static int do_script(const char *pkg, const char *scriptname, const char *scriptpath, struct stat *stab, char *const *arglist, const char *desc, const char *name, int warn) {
+  const char *scriptexec;
+  int c1, r;
+  setexecute(scriptpath,stab);
+
+  c1= m_fork();
+  if (!c1) {
+    scriptexec= preexecscript(scriptpath,arglist);
+    execv(scriptexec,arglist);
+    ohshite(desc,name);
+  }
+  script_catchsignals(); /* This does a push_cleanup() */
+  r= waitsubproc(c1,name,0,warn);
+  pop_cleanup(ehflag_normaltidy);
+  return r;
+}
 
 int maintainer_script_installed(struct pkginfo *pkg, const char *scriptname,
                                 const char *description, ...) {
@@ -276,22 +292,13 @@ int maintainer_script_installed(struct pkginfo *pkg, const char *scriptname,
     }
     ohshite(_("unable to stat installed %s script `%.250s'"),description,scriptpath);
   }
-  setexecute(scriptpath,&stab);
-  c1= m_fork();
-  if (!c1) {
-    scriptexec= preexecscript(scriptpath,arglist);
-    execv(scriptexec,arglist);
-    ohshite(_("unable to execute %s"),buf);
-  }
-  script_catchsignals(); /* This does a push_cleanup() */
-  waitsubproc(c1,buf,0,0);
-  pop_cleanup(ehflag_normaltidy);
-
+  do_script(pkg->name, scriptname, scriptpath, &stab, arglist, _("unable to execute %s"), buf, 0);
   ensure_diversions();
   return 1;
 }
   
-int maintainer_script_new(const char *scriptname, const char *description,
+int maintainer_script_new(const char *pkgname,
+			  const char *scriptname, const char *description,
                           const char *cidir, char *cidirrest, ...) {
   char *const *arglist;
   const char *scriptexec;
@@ -313,17 +320,7 @@ int maintainer_script_new(const char *scriptname, const char *description,
     }
     ohshite(_("unable to stat new %s script `%.250s'"),description,cidir);
   }
-  setexecute(cidir,&stab);
-  c1= m_fork();
-  if (!c1) {
-    scriptexec= preexecscript(cidir,arglist);
-    execv(scriptexec,arglist);
-    ohshite(_("unable to execute new %s"),buf);
-  }
-  script_catchsignals(); /* This does a push_cleanup() */
-  waitsubproc(c1,buf,0,0);
-  pop_cleanup(ehflag_normaltidy);
-
+  do_script(pkgname, scriptname, cidir, &stab, arglist, _("unable to execute new %s"), buf, 0);
   ensure_diversions();
   return 1;
 }
@@ -337,7 +334,7 @@ int maintainer_script_alternative(struct pkginfo *pkg,
   struct stat stab;
   int c1, n, status;
   char buf[100];
-  int r;
+  pid_t r;
 
   oldscriptpath= pkgadminfile(pkg,scriptname);
   arglist= buildarglist(scriptname,
@@ -355,17 +352,8 @@ int maintainer_script_alternative(struct pkginfo *pkg,
             _("dpkg: warning - unable to stat %s `%.250s': %s\n"),
             buf,oldscriptpath,strerror(errno));
   } else {
-    setexecute(oldscriptpath,&stab);
-    c1= m_fork();
-    if (!c1) {
-      scriptexec= preexecscript(oldscriptpath,arglist);
-      execv(scriptexec, arglist);
-      ohshite(_("unable to execute %s"),buf);
-    }
-    script_catchsignals(); /* This does a push_cleanup() */
-    r= waitsubproc(c1,buf,0,1);
-    pop_cleanup(ehflag_normaltidy);
-    if (!r) return 1;
+    if (!do_script(pkg->name, scriptname, oldscriptpath, &stab, arglist, _("unable to execute %s"), buf, 1))
+      return 1;
     ensure_diversions();
   }
   fprintf(stderr, _("dpkg - trying script from the new package instead ...\n"));
@@ -384,17 +372,7 @@ int maintainer_script_alternative(struct pkginfo *pkg,
       ohshite(_("unable to stat %s `%.250s'"),buf,cidir);
   }
 
-  setexecute(cidir,&stab);
-
-  c1= m_fork();
-  if (!c1) {
-    scriptexec= preexecscript(cidir,arglist);
-    execv(scriptexec, arglist);
-    ohshite(_("unable to execute %s"),buf);
-  }
-  script_catchsignals(); /* This does a push_cleanup() */
-  waitsubproc(c1,buf,0,1);
-  pop_cleanup(ehflag_normaltidy);
+  do_script(pkg->name, scriptname, cidir, &stab, arglist, _("unable to execute %s"), buf, 0);
   fprintf(stderr, _("dpkg: ... it looks like that went OK.\n"));
 
   ensure_diversions();

+ 3 - 3
main/processarc.c

@@ -412,19 +412,19 @@ void process_archive(const char *filename) {
   if (oldversionstatus == stat_notinstalled) {
     push_cleanup(cu_preinstverynew,~ehflag_normaltidy, 0,0,
                  3,(void*)pkg,(void*)cidir,(void*)cidirrest);
-    maintainer_script_new(PREINSTFILE, "pre-installation", cidir, cidirrest,
+    maintainer_script_new(pkg->name, PREINSTFILE, "pre-installation", cidir, cidirrest,
                           "install", (char*)0);
   } else if (oldversionstatus == stat_configfiles) {
     push_cleanup(cu_preinstnew,~ehflag_normaltidy, 0,0,
                  3,(void*)pkg,(void*)cidir,(void*)cidirrest);
-    maintainer_script_new(PREINSTFILE, "pre-installation", cidir, cidirrest,
+    maintainer_script_new(pkg->name, PREINSTFILE, "pre-installation", cidir, cidirrest,
                           "install", versiondescribe(&pkg->installed.version,
                                                      vdew_nonambig),
                           (char*)0);
   } else {
     push_cleanup(cu_preinstupgrade,~ehflag_normaltidy, 0,0,
                  4,(void*)pkg,(void*)cidir,(void*)cidirrest,(void*)&oldversionstatus);
-    maintainer_script_new(PREINSTFILE, "pre-installation", cidir, cidirrest,
+    maintainer_script_new(pkg->name, PREINSTFILE, "pre-installation", cidir, cidirrest,
                           "upgrade", versiondescribe(&pkg->installed.version,
                                                      vdew_nonambig),
                           (char*)0);