You are not logged in.

#1 2005-05-20 10:18:46

Michel
Member
From: Belgium
Registered: 2004-07-31
Posts: 286

ldconfig - speed of pacman

Heya,

I was just updating xfce4-packages which are not so big in comparison with others. While pacman was/is updating I've looked for a moment which processes where running. What I noticed is that ldconfig runs mostly at least as long as pacman itself. I say atleast. Soemtimes I've more the impression it takes ~3x-x4 as long, anyway a long time. Maybe it is possible to time this?

Anyway, I know that the developpers run ldconfig each time a package is installed, ... for convenience, but I think if this was only run one time for each pacman-command where it is needed, there is mayeb potential to speed up thinsg a lot. What I noticed was that the files itself where installed pretty quickly ... but I have to say that there were quite soem packages and the total space they occupied was ~13 MB.

Anyway, as far as I know ldconfig only needs t be run when shared-libraries are installed. Couldn't something like the file-command be used when a package is created to check if any shared-libraries are in it and then add a flag to the package that says that it contains shared libraries. Maybe one can check on the extension .so ... If needed the user could add the flag himself and override the default behaviour this way.
During install pacman should install, ...  the packages like normal, but should check if a package has the shared-library-flag set. If it is checked pacman should run ldconfig at the end of the pacman-command

Another solution: only run ldconfig at the end of the pacman-command.

One possible problem maybe ... Does any package check on installed shared libraries when installed/...? This could be a problem.

greetz,

Michel

Offline

#2 2005-05-20 14:12:16

i3839
Member
Registered: 2004-02-04
Posts: 1,185

Re: ldconfig - speed of pacman

A quick look at Pacman's source says that Pacman is doing too many ldconfig's. Here a quick patch to fix that and do it only once at exit time:

diff -rup pacman-2.9.5/src/pacman.c 
Edit: REMOVED, was a bad patch, see the one in the next post

Only caveat is that if a lib which is used by /bin/sh is updated then the system() call which calls ldconfig may fail. So it's probably better to use execl() instead of system().

Offline

#3 2005-05-20 17:30:32

i3839
Member
Registered: 2004-02-04
Posts: 1,185

Re: ldconfig - speed of pacman

Newest version, one which should work and with execve instead of system():

diff -pru pacman-2.9.5/src/pacman.c pacman-2.9.5-ldconfig/src/pacman.c
--- pacman-2.9.5/src/pacman.c    2005-01-12 00:14:16.000000000 +0100
+++ pacman-2.9.5-ldconfig/src/pacman.c    2005-05-20 19:38:48.000000000 +0200
@@ -112,6 +112,7 @@ char *workfile = NULL;
 enum {READ_ONLY, READ_WRITE} pm_access;
 int maxcols = 80;
 int neednl = 0; /* for cleaner message output */
+int runldconfig = 0;
 
 int main(int argc, char *argv[])
 {
@@ -2051,17 +2052,7 @@ int pacman_add(pacdb_t *db, PMList *targ
     }
     FREELIST(alltargs);
 
-    /* run ldconfig if it exists */
-    snprintf(expath, PATH_MAX, "%setc/ld.so.conf", pmo_root);
-    if(!stat(expath, &buf)) {
-        snprintf(expath, PATH_MAX, "%ssbin/ldconfig", pmo_root);
-        if(!stat(expath, &buf)) {
-            char cmd[PATH_MAX];
-            snprintf(cmd, PATH_MAX, "%s -r %s", expath, pmo_root);
-            vprint("running "%s"n", cmd);
-            system(cmd);
-        }
-    }
+    runldconfig = 1;
     
     return(ret);
 }
@@ -2315,17 +2306,7 @@ int pacman_remove(pacdb_t *db, PMList *t
 
     FREELISTPKGS(alltargs);
 
-    /* run ldconfig if it exists */
-    snprintf(line, PATH_MAX, "%setc/ld.so.conf", pmo_root);
-    if(!stat(line, &buf)) {
-        snprintf(line, PATH_MAX, "%ssbin/ldconfig", pmo_root);
-        if(!stat(line, &buf)) {
-            char cmd[PATH_MAX];
-            snprintf(cmd, PATH_MAX, "%s -r %s", line, pmo_root);
-            vprint("running "%s"n", cmd);
-            system(cmd);
-        }
-    }
+    runldconfig = 1;
 
     return(0);
 }
@@ -3880,6 +3861,18 @@ int lckrm(char *file)
     return(unlink(file));
 }
 
+void ldconfig(void)
+{
+    if (fork() == 0){
+        char expath[PATH_MAX];
+        snprintf(expath, PATH_MAX, "%ssbin/ldconfig", pmo_root);
+        execl(expath, "-r", pmo_root, NULL);
+        /* this should never be reached */
+        printf("ERROR: running ldconfig failed!n");
+        exit(1);
+    }
+}
+
 void cleanup(int signum)
 {
     PMList *lp;
@@ -3899,6 +3892,10 @@ void cleanup(int signum)
         fclose(logfd);
     }
 
+    if (runldconfig){
+        ldconfig();
+    }
+
     /* free memory */
     for(lp = pmc_syncs; lp; lp = lp->next) {
         sync_t *sync = (sync_t *)lp->data;
diff -pru pacman-2.9.5/src/pacman.h pacman-2.9.5-ldconfig/src/pacman.h
--- pacman-2.9.5/src/pacman.h    2005-01-12 00:14:16.000000000 +0100
+++ pacman-2.9.5-ldconfig/src/pacman.h    2005-05-20 16:01:17.000000000 +0200
@@ -59,6 +59,7 @@ int yesno(char* fmt, ...);
 int lckmk(char *file, int retries, unsigned int sleep_secs);
 int lckrm(char *lckfile);
 void cleanup(int signum);
+void ldconfig(void);
 
 #endif /* PACMAN_H */
 

It's unclear why the ldconfig from the pmo_root is run instead of always /sbin/ldconfig, if that was wanted we'd better chroot instead.

I'll post it on the bugtracker too.

Offline

#4 2005-05-20 18:49:07

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: ldconfig - speed of pacman

i3839 wrote:

It's unclear why the ldconfig from the pmo_root is run instead of always /sbin/ldconfig, if that was wanted we'd better chroot instead.

I'll post it on the bugtracker too.

That was the first thing I noticed when I was reading the diff.... the only time pmo_root is set, however, is during the install, so that may have something to do with it... (you're not supposed to use a different root unless doing an install)

Offline

#5 2005-05-20 19:04:14

i3839
Member
Registered: 2004-02-04
Posts: 1,185

Re: ldconfig - speed of pacman

I think it's better to get rid of the -r option then and to make a --chroot option instead, which lets Pacman chroot to a dir and do there its stuff. That would simplify the code, by getting rid of all the scattered pmo_root copying around.

(Note: the advantage of letting Pacman do chroot instead of the user is that Pacman doesn't have to be in the chrooted dir.)

Offline

Board footer

Powered by FluxBB