Projects
Browse Source     Search     Timeline     Wiki

Changeset 23143

Show
Ignore:
Timestamp:
03/07/07 10:01:26 (21 months ago)
Author:
zarzycki@…
Message:

Wow, I don't touch launchctl.c enough. My style has changed over time.

(Always use {}, you're going to need them eventually, and when you do, it makes for a more clear diff.)

Files:
1 modified

Legend:

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

    r23142 r23143  
    279279 
    280280        for (i = 0; i < (sizeof cmds / sizeof cmds[0]); i++) { 
    281                 if (!strcmp(cmds[i].name, argv[0])) 
     281                if (!strcmp(cmds[i].name, argv[0])) { 
    282282                        return cmds[i].func(argc, argv); 
     283                } 
    283284        } 
    284285 
     
    350351 
    351352        /* XXX escape the double quotes */ 
    352         if (*is_csh) 
     353        if (*is_csh) { 
    353354                fprintf(stdout, "setenv %s \"%s\";\n", key, launch_data_get_string(obj)); 
    354         else 
     355        } else { 
    355356                fprintf(stdout, "%s=\"%s\"; export %s;\n", key, launch_data_get_string(obj), key); 
     357        } 
    356358} 
    357359 
     
    361363        const char *k = context; 
    362364 
    363         if (!strcmp(key, k)) 
     365        if (!strcmp(key, k)) { 
    364366                fprintf(stdout, "%s\n", launch_data_get_string(obj)); 
     367        } 
    365368} 
    366369 
     
    374377        if (!strcmp(argv[0], "export")) { 
    375378                char *s = getenv("SHELL"); 
    376                 if (s) 
     379                if (s) { 
    377380                        is_csh = strstr(s, "csh") ? true : false; 
     381                } 
    378382        } else if (argc != 2) { 
    379383                fprintf(stderr, "%s usage: getenv <key>\n", getprogname()); 
     
    389393 
    390394        if (resp) { 
    391                 if (!strcmp(argv[0], "export")) 
     395                if (!strcmp(argv[0], "export")) { 
    392396                        launch_data_dict_iterate(resp, print_launchd_env, &is_csh); 
    393                 else 
     397                } else { 
    394398                        launch_data_dict_iterate(resp, print_key_value, k); 
     399                } 
    395400                launch_data_free(resp); 
    396401        } else { 
     
    424429        } 
    425430        if (LAUNCH_DATA_ERRNO == launch_data_get_type(resp)) { 
    426                 if ((e = launch_data_get_errno(resp))) 
     431                if ((e = launch_data_get_errno(resp))) { 
    427432                        fprintf(stderr, "%s\n", strerror(e)); 
     433                } 
    428434        } 
    429435        launch_data_free(resp); 
     
    442448 
    443449        if (editondisk) { 
    444                 if (load) 
     450                if (load) { 
    445451                        CFDictionaryRemoveValue((CFMutableDictionaryRef)plist, CFSTR(LAUNCH_JOBKEY_DISABLED)); 
    446                 else 
     452                } else { 
    447453                        CFDictionarySetValue((CFMutableDictionaryRef)plist, CFSTR(LAUNCH_JOBKEY_DISABLED), kCFBooleanTrue); 
     454                } 
    448455                WriteMyPropertyListToFile(plist, file); 
    449456        } 
     
    472479                break; 
    473480        case LAUNCH_DATA_ARRAY: 
    474                 for (i = 0; i < launch_data_array_get_count(o); i++) 
     481                for (i = 0; i < launch_data_array_get_count(o); i++) { 
    475482                        delay_to_second_pass2(launch_data_array_get_index(o, i), NULL, context); 
     483                } 
    476484                break; 
    477485        default: 
     
    487495        launch_data_t socks = launch_data_dict_lookup(o, LAUNCH_JOBKEY_SOCKETS); 
    488496 
    489         if (NULL == socks) 
     497        if (NULL == socks) { 
    490498                return false; 
     499        } 
    491500 
    492501        delay_to_second_pass2(socks, NULL, &res); 
     
    526535                for (i = 0; i < c; i++) { 
    527536                        launch_data_t oai = launch_data_array_get_index(tmpa, i); 
    528                         if (!strcasecmp(ourhostname, launch_data_get_string(oai))) 
     537                        if (!strcasecmp(ourhostname, launch_data_get_string(oai))) { 
    529538                                goto out_bad; 
     539                        } 
    530540                } 
    531541        } 
     
    536546                for (i = 0; i < c; i++) { 
    537547                        launch_data_t oai = launch_data_array_get_index(tmpa, i); 
    538                         if (!strcasecmp(ourhostname, launch_data_get_string(oai))) 
     548                        if (!strcasecmp(ourhostname, launch_data_get_string(oai))) { 
    539549                                break; 
    540                 } 
    541  
    542                 if (i == c) 
     550                        } 
     551                } 
     552 
     553                if (i == c) { 
    543554                        goto out_bad; 
     555                } 
    544556        } 
    545557 
     
    583595        } 
    584596 
    585         if ((tmpd = launch_data_dict_lookup(thejob, LAUNCH_JOBKEY_DISABLED))) 
     597        if ((tmpd = launch_data_dict_lookup(thejob, LAUNCH_JOBKEY_DISABLED))) { 
    586598                job_disabled = launch_data_get_bool(tmpd); 
    587  
    588         if (lus->forceload) 
     599        } 
     600 
     601        if (lus->forceload) { 
    589602                job_disabled = false; 
    590  
    591         if (job_disabled && lus->load) 
     603        } 
     604 
     605        if (job_disabled && lus->load) { 
    592606                goto out_bad; 
    593  
    594         if (delay_to_second_pass(thejob)) 
     607        } 
     608 
     609        if (delay_to_second_pass(thejob)) { 
    595610                launch_data_array_append(lus->pass2, thejob); 
    596         else 
     611        } else { 
    597612                launch_data_array_append(lus->pass1, thejob); 
    598  
    599         if (verbose) 
     613        } 
     614 
     615        if (verbose) { 
    600616                fprintf(stdout, "Will load: %s\n", what); 
     617        } 
    601618 
    602619        return; 
    603620out_bad: 
    604         if (verbose) 
     621        if (verbose) { 
    605622                fprintf(stdout, "Ignored: %s\n", what); 
     623        } 
    606624        launch_data_free(thejob); 
    607625} 
     
    617635        } 
    618636 
    619         if (forceload) 
     637        if (forceload) { 
    620638                return true; 
     639        } 
    621640 
    622641        if (sb.st_mode & (S_IWOTH|S_IWGRP)) { 
     
    646665        DIR *d; 
    647666 
    648         if (!path_goodness_check(what, lus->forceload)) 
     667        if (!path_goodness_check(what, lus->forceload)) { 
    649668                return; 
    650  
    651         if (stat(what, &sb) == -1) 
     669        } 
     670 
     671        if (stat(what, &sb) == -1) { 
    652672                return; 
     673        } 
    653674 
    654675        if (S_ISREG(sb.st_mode)) { 
     
    661682 
    662683                while ((de = readdir(d))) { 
    663                         if ((de->d_name[0] == '.')) 
     684                        if ((de->d_name[0] == '.')) { 
    664685                                continue; 
     686                        } 
    665687                        snprintf(buf, sizeof(buf), "%s/%s", what, de->d_name); 
    666688 
    667                         if (!path_goodness_check(buf, lus->forceload)) 
     689                        if (!path_goodness_check(buf, lus->forceload)) { 
    668690                                continue; 
     691                        } 
    669692 
    670693                        readfile(buf, lus); 
     
    739762        } 
    740763 
    741         if ((val = launch_data_dict_lookup(tmp, LAUNCH_JOBSOCKETKEY_PASSIVE))) 
     764        if ((val = launch_data_dict_lookup(tmp, LAUNCH_JOBSOCKETKEY_PASSIVE))) { 
    742765                passive = launch_data_get_bool(val); 
     766        } 
    743767 
    744768        if ((val = launch_data_dict_lookup(tmp, LAUNCH_JOBSOCKETKEY_SECUREWITHKEY))) { 
     
    773797                strncpy(sun.sun_path, launch_data_get_string(val), sizeof(sun.sun_path)); 
    774798         
    775                 if ((sfd = _fd(socket(AF_UNIX, st, 0))) == -1) 
     799                if ((sfd = _fd(socket(AF_UNIX, st, 0))) == -1) { 
    776800                        return; 
     801                } 
    777802 
    778803                if ((val = launch_data_dict_lookup(tmp, LAUNCH_JOBSOCKETKEY_PATHMODE))) { 
     
    796821                                chmod(sun.sun_path, sun_mode); 
    797822                        } 
    798                         if ((st == SOCK_STREAM || st == SOCK_SEQPACKET) 
    799                                         && listen(sfd, SOMAXCONN) == -1) { 
     823                        if ((st == SOCK_STREAM || st == SOCK_SEQPACKET) && listen(sfd, SOMAXCONN) == -1) { 
    800824                                close(sfd); 
    801825                                return; 
     
    819843 
    820844                hints.ai_socktype = st; 
    821                 if (passive) 
     845                if (passive) { 
    822846                        hints.ai_flags |= AI_PASSIVE; 
    823  
    824                 if ((val = launch_data_dict_lookup(tmp, LAUNCH_JOBSOCKETKEY_NODENAME))) 
     847                } 
     848 
     849                if ((val = launch_data_dict_lookup(tmp, LAUNCH_JOBSOCKETKEY_NODENAME))) { 
    825850                        node = launch_data_get_string(val); 
    826                 if ((val = launch_data_dict_lookup(tmp, LAUNCH_JOBSOCKETKEY_MULTICASTGROUP))) 
     851                } 
     852                if ((val = launch_data_dict_lookup(tmp, LAUNCH_JOBSOCKETKEY_MULTICASTGROUP))) { 
    827853                        mgroup = launch_data_get_string(val); 
     854                } 
    828855                if ((val = launch_data_dict_lookup(tmp, LAUNCH_JOBSOCKETKEY_SERVICENAME))) { 
    829856                        if (LAUNCH_DATA_INTEGER == launch_data_get_type(val)) { 
     
    835862                } 
    836863                if ((val = launch_data_dict_lookup(tmp, LAUNCH_JOBSOCKETKEY_FAMILY))) { 
    837                         if (!strcasecmp("IPv4", launch_data_get_string(val))) 
     864                        if (!strcasecmp("IPv4", launch_data_get_string(val))) { 
    838865                                hints.ai_family = AF_INET; 
    839                         else if (!strcasecmp("IPv6", launch_data_get_string(val))) 
     866                        } else if (!strcasecmp("IPv6", launch_data_get_string(val))) { 
    840867                                hints.ai_family = AF_INET6; 
     868                        } 
    841869                } 
    842870                if ((val = launch_data_dict_lookup(tmp, LAUNCH_JOBSOCKETKEY_PROTOCOL))) { 
     
    901929                                        do_mgroup_join(sfd, res->ai_family, res->ai_socktype, res->ai_protocol, mgroup); 
    902930                                } 
    903                                 if ((res->ai_socktype == SOCK_STREAM || res->ai_socktype == SOCK_SEQPACKET) 
    904                                                 && listen(sfd, SOMAXCONN) == -1) { 
     931                                if ((res->ai_socktype == SOCK_STREAM || res->ai_socktype == SOCK_SEQPACKET) && listen(sfd, SOMAXCONN) == -1) { 
    905932                                        fprintf(stderr, "listen(): %s\n", strerror(errno)); 
    906933                                        return; 
     
    915942                                        if (NULL == rnames) { 
    916943                                                rvs_fd = do_rendezvous_magic(res, serv); 
    917                                                 if (rvs_fd) 
     944                                                if (rvs_fd) { 
    918945                                                        launch_data_array_append(rvs_fds, rvs_fd); 
     946                                                } 
    919947                                        } else if (LAUNCH_DATA_STRING == launch_data_get_type(rnames)) { 
    920948                                                rvs_fd = do_rendezvous_magic(res, launch_data_get_string(rnames)); 
    921                                                 if (rvs_fd) 
     949                                                if (rvs_fd) { 
    922950                                                        launch_data_array_append(rvs_fds, rvs_fd); 
     951                                                } 
    923952                                        } else if (LAUNCH_DATA_ARRAY == launch_data_get_type(rnames)) { 
    924953                                                size_t rn_i, rn_ac = launch_data_array_get_count(rnames); 
     
    928957 
    929958                                                        rvs_fd = do_rendezvous_magic(res, launch_data_get_string(rn_tmp)); 
    930                                                         if (rvs_fd) 
     959                                                        if (rvs_fd) { 
    931960                                                                launch_data_array_append(rvs_fds, rvs_fd); 
     961                                                        } 
    932962                                                } 
    933963                                        } 
     
    10071037        static int statres = 1; 
    10081038 
    1009         if (1 == statres) 
     1039        if (1 == statres) { 
    10101040                statres = stat("/usr/sbin/mDNSResponder", &sb); 
    1011  
    1012         if (-1 == statres) 
     1041        } 
     1042 
     1043        if (-1 == statres) { 
    10131044                return NULL; 
     1045        } 
    10141046 
    10151047        sprintf(rvs_buf, "_%s._%s.", serv, res->ai_socktype == SOCK_STREAM ? "tcp" : "udp"); 
    10161048 
    1017         if (res->ai_family == AF_INET) 
     1049        if (res->ai_family == AF_INET) { 
    10181050                port = ((struct sockaddr_in *)res->ai_addr)->sin_port; 
    1019         else 
     1051        } else { 
    10201052                port = ((struct sockaddr_in6 *)res->ai_addr)->sin6_port; 
     1053        } 
    10211054 
    10221055        error = DNSServiceRegister(&service, 0, 0, NULL, rvs_buf, NULL, NULL, port, 0, NULL, NULL, NULL); 
    10231056 
    1024         if (error == kDNSServiceErr_NoError) 
     1057        if (error == kDNSServiceErr_NoError) { 
    10251058                return launch_data_new_fd(DNSServiceRefSockFD(service)); 
     1059        } 
    10261060 
    10271061        fprintf(stderr, "DNSServiceRegister(\"%s\"): %d\n", serv, error); 
     
    10391073 
    10401074        fileURL = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8 *)posixfile, strlen(posixfile), false); 
    1041         if (!fileURL) 
     1075        if (!fileURL) { 
    10421076                fprintf(stderr, "%s: CFURLCreateFromFileSystemRepresentation(%s) failed\n", getprogname(), posixfile); 
    1043         if (!CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, fileURL, &resourceData, NULL, NULL, &errorCode)) 
     1077        } 
     1078        if (!CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, fileURL, &resourceData, NULL, NULL, &errorCode)) { 
    10441079                fprintf(stderr, "%s: CFURLCreateDataAndPropertiesFromResource(%s) failed: %d\n", getprogname(), posixfile, (int)errorCode); 
     1080        } 
    10451081        propertyList = CFPropertyListCreateFromXMLData(kCFAllocatorDefault, resourceData, kCFPropertyListMutableContainers, &errorString); 
    1046         if (!propertyList) 
     1082        if (!propertyList) { 
    10471083                fprintf(stderr, "%s: propertyList is NULL\n", getprogname()); 
     1084        } 
    10481085 
    10491086        return propertyList; 
     
    10581095 
    10591096        fileURL = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8 *)posixfile, strlen(posixfile), false); 
    1060         if (!fileURL) 
     1097        if (!fileURL) { 
    10611098                fprintf(stderr, "%s: CFURLCreateFromFileSystemRepresentation(%s) failed\n", getprogname(), posixfile); 
     1099        } 
    10621100        resourceData = CFPropertyListCreateXMLData(kCFAllocatorDefault, plist); 
    1063         if (resourceData == NULL) 
     1101        if (resourceData == NULL) { 
    10641102                fprintf(stderr, "%s: CFPropertyListCreateXMLData(%s) failed", getprogname(), posixfile); 
    1065         if (!CFURLWriteDataAndPropertiesToResource(fileURL, resourceData, NULL, &errorCode)) 
     1103        } 
     1104        if (!CFURLWriteDataAndPropertiesToResource(fileURL, resourceData, NULL, &errorCode)) { 
    10661105                fprintf(stderr, "%s: CFURLWriteDataAndPropertiesToResource(%s) failed: %d\n", getprogname(), posixfile, (int)errorCode); 
     1106        } 
    10671107} 
    10681108 
     
    11631203        } 
    11641204 
    1165         for (i = 0; i < (sizeof cmds / sizeof cmds[0]); i++) 
     1205        for (i = 0; i < (sizeof cmds / sizeof cmds[0]); i++) { 
    11661206                fprintf(where, "\t%-*s\t%s\n", cmdwidth, cmds[i].name, cmds[i].desc); 
     1207        } 
    11671208 
    11681209        return 0; 
     
    15651606                submit_job_pass(lus.pass2); 
    15661607        } else { 
    1567                 for (i = 0; i < launch_data_array_get_count(lus.pass1); i++) 
     1608                for (i = 0; i < launch_data_array_get_count(lus.pass1); i++) { 
    15681609                        unloadjob(launch_data_array_get_index(lus.pass1, i)); 
    1569                 for (i = 0; i < launch_data_array_get_count(lus.pass2); i++) 
     1610                } 
     1611                for (i = 0; i < launch_data_array_get_count(lus.pass2); i++) { 
    15701612                        unloadjob(launch_data_array_get_index(lus.pass2, i)); 
     1613                } 
    15711614        } 
    15721615 
     
    27632806 
    27642807        while ((val = fgetln(sf, &ln_len))) { 
    2765                 if (ln_len == 0) 
     2808                if (ln_len == 0) { 
    27662809                        continue; 
    2767                 if (!assumes((tmpstr = malloc(ln_len + 1)) != NULL)) 
     2810                } 
     2811                if (!assumes((tmpstr = malloc(ln_len + 1)) != NULL)) { 
    27682812                        continue; 
     2813                } 
    27692814                memcpy(tmpstr, val, ln_len); 
    27702815                tmpstr[ln_len] = 0; 
     
    27732818                while (*val && isspace(*val)) 
    27742819                        val++; 
    2775                 if (*val == '\0' || *val == '#') 
     2820                if (*val == '\0' || *val == '#') { 
    27762821                        goto skip_sysctl_tool; 
     2822                } 
    27772823                sysctl_tool[2] = val; 
    27782824                assumes(fwexec(sysctl_tool, true) != -1); 
     
    28002846        } 
    28012847 
    2802         if (buf[0] != '\0') 
     2848        if (buf[0] != '\0') { 
    28032849                return; 
     2850        } 
    28042851 
    28052852        versdict = _CFCopySystemVersionDictionary();