X-Git-Url: https://git.saurik.com/uikittools.git/blobdiff_plain/b9124f59d08f47be8897f521315ef5f9d129dde7..250d7de50e2d2a10f16311aab8a7b2d185b073a0:/sbreload.c diff --git a/sbreload.c b/sbreload.c index e499118..3db5a68 100644 --- a/sbreload.c +++ b/sbreload.c @@ -1,3 +1,42 @@ +/* UIKit Tools - command-line utilities for UIKit + * Copyright (C) 2008-2012 Jay Freeman (saurik) +*/ + +/* Modified BSD License {{{ */ +/* + * Redistribution and use in source and binary + * forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the + * above copyright notice, this list of conditions + * and the following disclaimer. + * 2. Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions + * and the following disclaimer in the documentation + * and/or other materials provided with the + * distribution. + * 3. The name of the author may not be used to endorse + * or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/* }}} */ + #include #include @@ -121,13 +160,12 @@ void stop() { sleep(1); } +#define SpringBoard_plist "/System/Library/LaunchDaemons/com.apple.SpringBoard.plist" + int main(int argc, const char *argv[]) { - if (argc > 1) { - fprintf(stderr, "usage: sbreload\n"); - return 1; - } + _assert(argc == 1, "usage: sbreload"); - CFDictionaryRef plist = CreateMyPropertyListFromFile("/System/Library/LaunchDaemons/com.apple.SpringBoard.plist"); + CFDictionaryRef plist = CreateMyPropertyListFromFile(SpringBoard_plist); _assert(plist != NULL, "CreateMyPropertyListFromFile() == NULL"); launch_data_t job = CF2launch_data(plist); @@ -160,8 +198,18 @@ int main(int argc, const char *argv[]) { launch_data_free(response); - fprintf(stderr, "notify_post(com.apple.mobile.springboard_teardown)\n"); - notify_post("com.apple.mobile.springboard_teardown"); + // 600 is being used to approximate 4.x/5.x boundary + if (kCFCoreFoundationVersionNumber < 600) { + fprintf(stderr, "notify_post(com.apple.mobile.springboard_teardown)\n"); + notify_post("com.apple.mobile.springboard_teardown"); + } else { + // XXX: this code is preferable to launchctl unoad but it requires libvproc? :( + //vproc_err_t *error = _vproc_send_signal_by_label(label, VPROC_MAGIC_UNLOAD_SIGNAL); + //_assert(error == NULL, "_vproc_send_signal_by_label(UNLOAD) != NULL"); + + fprintf(stderr, "launchctl unload SpringBoard.plist\n"); + system("launchctl unload " SpringBoard_plist); + } if (pid != -1) { fprintf(stderr, "waiting for kill(%u) != 0...\n", pid); @@ -175,23 +223,23 @@ int main(int argc, const char *argv[]) { request = launch_data_alloc(LAUNCH_DATA_DICTIONARY); launch_data_dict_insert(request, job, LAUNCH_KEY_SUBMITJOB); - launch_msg: - response = launch_msg(request); - _assert(response != NULL, "launch_msg(SubmitJob) == NULL"); + for (;;) { + response = launch_msg(request); + _assert(response != NULL, "launch_msg(SubmitJob) == NULL"); - _assert(launch_data_get_type(response) == LAUNCH_DATA_ERRNO, "launch_data_get_type() != ERRNO"); - int error = launch_data_get_errno(response); - launch_data_free(response); + _assert(launch_data_get_type(response) == LAUNCH_DATA_ERRNO, "launch_data_get_type() != ERRNO"); + int error = launch_data_get_errno(response); + launch_data_free(response); - const char *string = strerror(error); + const char *string = strerror(error); - if (error == EEXIST) { - fprintf(stderr, "SubmitJob(%s): %s, retrying...\n", label, string); - stop(); - goto launch_msg; - } else if (error != 0) { - fprintf(stderr, "SubmitJob(%s): %s\n", label, string); - return 6; + if (error == EEXIST) { + fprintf(stderr, "SubmitJob(%s): %s, retrying...\n", label, string); + stop(); + } else { + _assert(error == 0, "SubmitJob(%s): %s", label, string); + break; + } } launch_data_free(request);