From owner-p4-projects@FreeBSD.ORG Wed Nov 28 04:35:15 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 3B14A16A46B; Wed, 28 Nov 2007 04:35:15 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D8E5A16A468 for ; Wed, 28 Nov 2007 04:35:14 +0000 (UTC) (envelope-from gcooper@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id C94E113C4E1 for ; Wed, 28 Nov 2007 04:35:14 +0000 (UTC) (envelope-from gcooper@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id lAS4ZDS8036849 for ; Wed, 28 Nov 2007 04:35:13 GMT (envelope-from gcooper@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id lAS4ZDWS036846 for perforce@freebsd.org; Wed, 28 Nov 2007 04:35:13 GMT (envelope-from gcooper@FreeBSD.org) Date: Wed, 28 Nov 2007 04:35:13 GMT Message-Id: <200711280435.lAS4ZDWS036846@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to gcooper@FreeBSD.org using -f From: Garrett Cooper To: Perforce Change Reviews Cc: Subject: PERFORCE change 129672 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Nov 2007 04:35:15 -0000 http://perforce.freebsd.org/chv.cgi?CH=129672 Change 129672 by gcooper@shiina-ibook on 2007/11/28 04:34:41 Finish off post deinstall scripts.. The way that it was I had to split the deinstall script up into pre and post portions because pkg_install(1) has that functionality. I'm not sure why you would really want to do pre and post deinstall deinstall checks, because it seems extremely overkill.. but whatever.. gotta be backwards compatible.. Affected files ... .. //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/contrib/libpkg/pkg.h#2 edit .. //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/contrib/libpkg/pkg_db_freebsd.c#4 edit .. //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/contrib/libpkg/pkg_freebsd.c#3 edit Differences ... ==== //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/contrib/libpkg/pkg.h#2 (text+ko) ==== @@ -102,7 +102,8 @@ pkg_script_mtree, /**< Mtree */ pkg_script_require, /**< Requirement check */ pkg_script_require_deinstall, /**< Removal Requirement check */ - pkg_script_deinstall, /**< Deinstall check */ + pkg_script_deinstall_pre, /**< Pre-deinstall check */ + pkg_script_deinstall_post, /**< Post-deinstall check */ pkg_script_pre_deinstall, /**< Pre-removal */ pkg_script_post_deinstall /**< Post-removal */ } pkg_script; ==== //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/contrib/libpkg/pkg_db_freebsd.c#4 (text+ko) ==== @@ -522,7 +522,7 @@ /* Try +DEINSTALL */ if (pkg_run_script(real_pkg, NULL, - pkg_script_deinstall) != 0 && + pkg_script_deinstall_pre) != 0 && errno != ENOFILE && force == 0) { warnx("deinstall +REQUIRE script execution failed"); return -1; @@ -578,13 +578,28 @@ return -1; } + /* Let's run the scripts at the end of the deinstall, mmk? */ if (fake == 0 && exec_pkg_scripts == 1) { - /** @todo Run +POST-DEINSTALL /+DEINSTALL POST-DEINSTALL */ - if (pkg_run_script(real_pkg, NULL, pkg_script_post_deinstall) != 0 && - force != 0) { - warnx("post-deinstall script execution failed"); + + /* Run post-deinstall script.. */ + if (pkg_run_script(real_pkg, NULL, + pkg_script_post_deinstall) != 0 && + errno != ENOFILE && force != 0) { + warnx("post deinstall script execution failed"); return -1; } + /* Try deinstall script with POST-DEINSTALL arguments.. */ + else if(errno == ENOFILE) { + + if (pkg_run_script(real_pkg, NULL, + pkg_script_deinstall_post) != 0 && + errno != ENOFILE && force != 0) { + warnx("post deinstall script execution failed"); + return -1; + } + + } + } return 0; ==== //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/contrib/libpkg/pkg_freebsd.c#3 (text+ko) ==== @@ -968,7 +968,10 @@ data = pkgfile_get_data(control[pos]); if (data != NULL) { str1 = data; - /* @todo Write comment on what this does */ + /* + * Split lines tokenized by newlines + * and attempt to add packages.. + */ while ((str2 = strchr(str1, '\n')) != NULL) { unsigned int len = str2-str1; strncpy(pkg_name, str1, len); @@ -977,6 +980,10 @@ str1 = str2+1; } + /* + * @Todo: what the heck does this do + * (in the big picture, that is..)? + */ size = pkgfile_get_size(control[pos]); if ((unsigned int)(str1 - data) != size) { unsigned int len = data + size - str1; @@ -1037,7 +1044,12 @@ } break; case pkg_script_pre_deinstall: + script_file = pkg_get_control_file(pkg, "+PRE-DEINSTALL"); + snprintf(arg, FILENAME_MAX, "PRE-DEINSTALL"); + break; case pkg_script_post_deinstall: + script_file = pkg_get_control_file(pkg, "+POST-DEINSTALL"); + snprintf(arg, FILENAME_MAX, "POST-DEINSTALL"); break; case pkg_script_mtree: assert(script_file == NULL); @@ -1052,9 +1064,14 @@ snprintf(arg, FILENAME_MAX, "DEINSTALL"); } break; - case pkg_script_deinstall: + case pkg_script_deinstall_pre: + case pkg_script_deinstall_post: script_file = pkg_get_control_file(pkg, "+DEINSTALL"); - snprintf(arg, FILENAME_MAX, "DEINSTALL"); + if (script == pkg_script_deinstall_pre) + snprintf(arg, FILENAME_MAX, "DEINSTALL"); + } else { + snprintf(arg, FILENAME_MAX, "DEINSTALL POST-DEINSTALL"); + } break; case pkg_script_noop: return -1; @@ -1067,21 +1084,41 @@ } if (fpkg->pkg_type == fpkg_from_file) { + /** - * @todo Add a lock around mkdtemp as - * arc4random is not thread safe + * Andrew Turner: @todo Add a lock around + * mkdtemp as arc4random is not thread safe + * + * Garrett Cooper: What? Do you mean use + * flock(1), or another randomizing algorithm + * to produce a filename in place of "XXXXXXX"? + * *confused*... */ snprintf(dir, FILENAME_MAX, "/tmp/libpkg_XXXXXXX"); - mkdtemp(dir); + + /* + * mkdtemp(3) returns NULL if the directory + * couldn't be created.. + */ + if(mkdtemp(dir) != NULL) { + + /* + * Change to the temp dir and back up the + * current dir to return here + */ + cwd = getcwd(NULL, 0); + chdir(dir); + + /* Extract the script */ + pkgfile_write(script_file); - /* Change to the temp dir and back up the current dir to return here */ - cwd = getcwd(NULL, 0); - chdir(dir); + } - /* Extract the script */ - pkgfile_write(script_file); } + /* + * Now, to execute the script... + */ switch(script) { case pkg_script_mtree: { @@ -1097,7 +1134,8 @@ case pkg_script_require_deinstall: case pkg_script_pre_deinstall: case pkg_script_post_deinstall: - case pkg_script_deinstall: + case pkg_script_deinstall_pre: + case pkg_script_deinstall_post: /* Check the script has the execute bit set */ pkg_chmod_file(pkgfile_get_name(script_file));