Ticket #20330: portutil.tcl.patch

File portutil.tcl.patch, 1.5 KB (added by mtalexander (Mike Alexander), 15 years ago)
  • base/src/port1.0/portutil.tcl

     
    911911            return -code error "reinplace copy failed"
    912912        }
    913913
    914         eval file attributes {$file} $attributes
     914        fileAttrsAsRoot $file $attributes
    915915
    916916        file delete "$tmpfile"
    917917    }
     
    12191219
    12201220    if {$procedure != ""} {
    12211221        set targetname [ditem_key $ditem name]
    1222         if { [tbool ${targetname}.asroot] } {
     1222        set target [ditem_key $ditem provides]
     1223        global ${target}.asroot
     1224        if { [tbool ${target}.asroot] } {
    12231225            elevateToRoot $targetname
    12241226        }
    12251227
     
    23542356}
    23552357
    23562358##
     2359# Change attributes of file while running as root
     2360#
     2361# @param file the file in question
     2362# @param attributes the attributes for the file
     2363proc fileAttrsAsRoot {file attributes} {
     2364    global euid macportsuser
     2365    if {[getuid] == 0 && [geteuid] != 0} {
     2366        # Started as root, but not root now
     2367        seteuid $euid
     2368        ui_debug "euid changed to: [geteuid]"
     2369        eval file attributes {$file} $attributes
     2370        seteuid [name_to_uid "$macportsuser"]
     2371        ui_debug "euid changed to: [geteuid]"
     2372    } else {
     2373        eval file attributes {$file} $attributes
     2374    }
     2375}
     2376
     2377##
    23572378# Elevate privileges back to root.
    23582379#
    23592380# @param action the action for which privileges are being elevated