On Sat 20 Oct 2007 13:10, Beat Gtzi wrote:
> Rong-en Fan wrote:
> >> Known issues:
> >> - pkg_updating needs a colon at the end of the date line. Some entries
> >> don't have this colon. This patch adds the missing colons:
> >> http://tmp.chruetertee.ch/pkg_updating/UPDATING.patch
> > 
> > I just committed this. Thanks!
> 
> Thanks!
> 
> >> pkg_updating is available here:
> >> http://tmp.chruetertee.ch/pkg_updating/
> > 
> > One question, do you support PORTSDIR environment variable?
> 
> No, pkg_updating doesn't support the PORTSDIR environment variable yet.
> But I think this would be useful therefore I will add it.
> 
> Beat

Here's a little patch.

It changes:
- variable tmpfile was renamed to tmp_file, I got a warning that it
        shadowed a global declaration
- Add support for PORTSDIR and PKG_DBDIR
- Don't exit if we can't open +CONTENTS file, since pkgdb may be in
        /var/db/pkg
- Add Makefile for sourcetree

TODO:
Write a manpage

Note that I'm so hungry that I'm almost falling down (I always forget
to eat...) and than I'm not a particular good C programmer, but I
needed to modify it anyway to get it running...

Regards,
Martin Tournoij
diff -urN updating/Makefile /usr/src/usr.sbin/pkg_install/updating/Makefile
--- updating/Makefile   1970-01-01 01:00:00.000000000 +0100
+++ /usr/src/usr.sbin/pkg_install/updating/Makefile     2007-10-20 
14:08:20.000000000 +0200
@@ -0,0 +1,9 @@
+PROG=  pkg_updating
+SRCS=  pkg_updating.c
+
+CFLAGS+= -I${.CURDIR}/../lib
+
+WARNS?=        6
+WFORMAT?=      1
+
+.include <bsd.prog.mk>
diff -urN updating/pathnames.h 
/usr/src/usr.sbin/pkg_install/updating/pathnames.h
--- updating/pathnames.h        2007-10-20 14:09:56.000000000 +0200
+++ /usr/src/usr.sbin/pkg_install/updating/pathnames.h  2007-10-20 
13:54:05.000000000 +0200
@@ -7,5 +7,19 @@
  * ----------------------------------------------------------------------------
  */
 
-#define _PATH_UPDATING "/usr/ports/UPDATING"
-#define _PATH_PKGDB "/var/db/pkg"
+/* Copy from ../version/version.h, shouldn't this go in lib/lib.h? */
+/* Where the ports lives by default */
+#define DEF_PORTS_DIR "/usr/ports/UPDATING"
+/* just in case we change the environment variable name */
+#define PORTSDIR  "PORTSDIR"
+/* macro to get name of directory where we put logging information */
+#define UPDATING (getenv(PORTSDIR) ? strcat(getenv(PORTSDIR), "/UPDATING") : 
DEF_PORTS_DIR)
+
+/* Including lib/lib.h gives an error(?!) */
+/* Where we put logging information by default, else ${PKG_DBDIR} if set */
+#define DEF_LOG_DIR    "/var/db/pkg"
+/* just in case we change the environment variable name */
+#define PKG_DBDIR      "PKG_DBDIR"
+/* macro to get name of directory where we put logging information */
+#define LOG_DIR                (getenv(PKG_DBDIR) ? getenv(PKG_DBDIR) : 
DEF_LOG_DIR)
+
diff -urN updating/pkg_updating.c 
/usr/src/usr.sbin/pkg_install/updating/pkg_updating.c
--- updating/pkg_updating.c     2007-10-20 14:10:01.000000000 +0200
+++ /usr/src/usr.sbin/pkg_install/updating/pkg_updating.c       2007-10-20 
14:18:48.000000000 +0200
@@ -43,14 +43,14 @@
        const char *end = "20";
        /* Keyword for searching origin portname of installed port */
        const char *origin = "@comment ORIGIN:";
-       const char *pkgdbpath = _PATH_PKGDB;            /* Location of pkgdb */
-       const char *updatingfile = _PATH_UPDATING;      /* Location of UPDATING 
*/
+       const char *pkgdbpath = LOG_DIR;                /* Location of pkgdb */
+       const char *updatingfile = UPDATING;    /* Location of UPDATING */
 
        char *date;                                                             
/* Passed -d argument */
        char *dateline;                                                 /* 
Saved date of an entry */
        char *portname;                                                 /* 
Passed -p argument */
        /* Temporary variable to create path to +CONTENTS for installed ports */
-       char tmpfile[MAXPATHLEN];
+       char tmp_file[MAXPATHLEN];
        /* Tmp lines for parsing file */
        char *tmpline1;
        char *tmpline2;
@@ -100,23 +100,23 @@
        /* UPDATING will be parsed for all installed ports if -p is not set */
        if (pflag == 0) {
                /* Opens /var/db/pkg and search for all installed ports */
-               if((dir = opendir(_PATH_PKGDB)) != NULL) {
+               if((dir = opendir(pkgdbpath)) != NULL) {
                        while ((pkgdbdir = readdir(dir)) != NULL) {
                                if (strcmp(pkgdbdir->d_name, ".") != 0 && 
                                        strcmp(pkgdbdir->d_name, "..") !=0) {
 
                                        /* Create path to +CONTENTS file for 
each installed port */
-                                       n = strlcpy(tmpfile, pkgdbpath, 
strlen(pkgdbpath)+1);
-                                       n = strlcpy(tmpfile + n, "/", 
sizeof(tmpfile) - n);
-                                       n = strlcat(tmpfile + n, 
pkgdbdir->d_name, sizeof(tmpfile) - n);
-                                       (void)strlcat(tmpfile + n, 
"/+CONTENTS", sizeof(tmpfile) - n);
+                                       n = strlcpy(tmp_file, pkgdbpath, 
strlen(pkgdbpath)+1);
+                                       n = strlcpy(tmp_file + n, "/", 
sizeof(tmp_file) - n);
+                                       n = strlcat(tmp_file + n, 
pkgdbdir->d_name, sizeof(tmp_file) - n);
+                                       (void)strlcat(tmp_file + n, 
"/+CONTENTS", sizeof(tmp_file) - n);
 
                                        /* Open +CONTENT file */
-                                       fd = fopen(tmpfile, "r");
+                                       fd = fopen(tmp_file, "r");
                                        if(fd == NULL) {
-                                               fprintf(stderr, "can't open %s: 
%s\n",
-                                               tmpfile, strerror(errno));
-                                               exit(EX_UNAVAILABLE);
+                                               fprintf(stderr, "Warning: can't 
open %s: %s\n",
+                                               tmp_file, strerror(errno));
+                                               continue;
                                        }
 
                                        /* Parses +CONTENT for ORIGIN line and 
_______________________________________________
freebsd-ports@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-ports
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to