| 1 | # et:ts=4 |
| 2 | # portreload.tcl |
| 3 | # $Id$ |
| 4 | # |
| 5 | # Copyright (c) 2007, 2009, 2011 The MacPorts Project |
| 6 | # Copyright (c) 2007 James D. Berry |
| 7 | # All rights reserved. |
| 8 | # |
| 9 | # Redistribution and use in source and binary forms, with or without |
| 10 | # modification, are permitted provided that the following conditions |
| 11 | # are met: |
| 12 | # 1. Redistributions of source code must retain the above copyright |
| 13 | # notice, this list of conditions and the following disclaimer. |
| 14 | # 2. Redistributions in binary form must reproduce the above copyright |
| 15 | # notice, this list of conditions and the following disclaimer in the |
| 16 | # documentation and/or other materials provided with the distribution. |
| 17 | # 3. Neither the name of The MacPorts Project nor the names of its contributors |
| 18 | # may be used to endorse or promote products derived from this software |
| 19 | # without specific prior written permission. |
| 20 | # |
| 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 31 | # POSSIBILITY OF SUCH DAMAGE. |
| 32 | # |
| 33 | |
| 34 | package provide portreload 1.0 |
| 35 | package require portutil 1.0 |
| 36 | |
| 37 | set org.macports.reload [target_new org.macports.reload portreload::reload_main] |
| 38 | target_runtype ${org.macports.reload} always |
| 39 | target_state ${org.macports.reload} no |
| 40 | target_provides ${org.macports.reload} reload |
| 41 | target_requires ${org.macports.reload} main |
| 42 | |
| 43 | namespace eval portreload { |
| 44 | } |
| 45 | |
| 46 | options reload.asroot |
| 47 | default reload.asroot yes |
| 48 | |
| 49 | set_ui_prefix |
| 50 | |
| 51 | proc portreload::reload_main {args} { |
| 52 | global startupitem.type startupitem.name startupitem.location startupitem.plist |
| 53 | set launchctl_path ${portutil::autoconf::launchctl_path} |
| 54 | |
| 55 | foreach { path } "/Library/${startupitem.location}/${startupitem.plist}" { |
| 56 | if {$launchctl_path eq ""} { |
| 57 | return -code error [format [msgcat::mc "launchctl command was not found by configure"]] |
| 58 | } elseif {![file exists $path]} { |
| 59 | return -code error [format [msgcat::mc "Launchd plist %s was not found"] $path] |
| 60 | } else { |
| 61 | exec $launchctl_path unload $path 2>@stderr |
| 62 | after 1000 |
| 63 | exec $launchctl_path load $path 2>@stderr |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | return |
| 68 | } |