Projects
Browse Source     Search     Timeline     Wiki

Changeset 23308

Show
Ignore:
Timestamp:
07/12/07 13:43:08 (17 months ago)
Author:
zarzycki@…
Message:

<rdar://problem/5326137> launchd dynamic enable/disable of services based on machine

Location:
trunk/launchd/src
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/launchd/src/launchctl.c

    r23304 r23308  
    2020 
    2121static const char *const __rcs_file_version__ = "$Revision$"; 
     22 
     23#include "liblaunch_public.h" 
     24#include "liblaunch_private.h" 
     25#include "libbootstrap_public.h" 
     26#include "libvproc_public.h" 
     27#include "libvproc_private.h" 
     28#include "libvproc_internal.h" 
    2229 
    2330#include <CoreFoundation/CoreFoundation.h> 
     
    6673#include <util.h> 
    6774 
    68 #include "libbootstrap_public.h" 
    69 #include "libvproc_public.h" 
    70 #include "libvproc_private.h" 
    71 #include "libvproc_internal.h" 
    72 #include "liblaunch_public.h" 
    73 #include "liblaunch_private.h" 
    7475 
    7576#define LAUNCH_SECDIR "/tmp/launch-XXXXXX" 
     
    144145static bool do_single_user_mode2(void); 
    145146static void read_launchd_conf(void); 
     147static bool job_disabled_logic(launch_data_t obj); 
    146148 
    147149typedef enum { 
     
    613615 
    614616        if ((tmpd = launch_data_dict_lookup(thejob, LAUNCH_JOBKEY_DISABLED))) { 
    615                 job_disabled = launch_data_get_bool(tmpd); 
     617                job_disabled = job_disabled_logic(tmpd); 
    616618        } 
    617619 
     
    640642        } 
    641643        launch_data_free(thejob); 
     644} 
     645 
     646static bool 
     647sysctl_hw_streq(int mib_slot, const char *str) 
     648{ 
     649        char buf[1000]; 
     650        size_t bufsz = sizeof(buf); 
     651        int mib[] = { CTL_HW, mib_slot }; 
     652 
     653        if (sysctl(mib, 2, buf, &bufsz, NULL, 0) != -1) { 
     654                if (strcmp(buf, str) == 0) { 
     655                        return true; 
     656                } 
     657        } 
     658 
     659        return false; 
     660} 
     661 
     662static void 
     663job_disabled_dict_logic(launch_data_t obj, const char *key, void *context) 
     664{ 
     665        bool *r = context; 
     666 
     667        if (launch_data_get_type(obj) != LAUNCH_DATA_STRING) { 
     668                return; 
     669        } 
     670 
     671        if (strcasecmp(key, LAUNCH_JOBKEY_DISABLED_MACHINETYPE) == 0) { 
     672                if (sysctl_hw_streq(HW_MACHINE, launch_data_get_string(obj))) { 
     673                        *r = true; 
     674                } 
     675        } else if (strcasecmp(key, LAUNCH_JOBKEY_DISABLED_MODELNAME) == 0) { 
     676                if (sysctl_hw_streq(HW_MODEL, launch_data_get_string(obj))) { 
     677                        *r = true; 
     678                } 
     679        } 
     680} 
     681 
     682bool 
     683job_disabled_logic(launch_data_t obj) 
     684{ 
     685        bool r = false; 
     686 
     687        switch (launch_data_get_type(obj)) { 
     688        case LAUNCH_DATA_DICTIONARY: 
     689                launch_data_dict_iterate(obj, job_disabled_dict_logic, &r); 
     690                break; 
     691        case LAUNCH_DATA_BOOL: 
     692                r = launch_data_get_bool(obj); 
     693                break; 
     694        default: 
     695                break; 
     696        } 
     697 
     698        return r; 
    642699} 
    643700 
  • trunk/launchd/src/liblaunch_public.h

    r23235 r23308  
    127127#define LAUNCH_JOBKEY_RESOURCELIMIT_STACK       "Stack" 
    128128 
     129#define LAUNCH_JOBKEY_DISABLED_MACHINETYPE      "MachineType" 
     130#define LAUNCH_JOBKEY_DISABLED_MODELNAME        "ModelName" 
     131 
    129132#define LAUNCH_JOBSOCKETKEY_TYPE                "SockType" 
    130133#define LAUNCH_JOBSOCKETKEY_PASSIVE             "SockPassive"