Changeset 23143
- Timestamp:
- 03/07/07 10:01:26 (21 months ago)
- Files:
-
- 1 modified
-
trunk/launchd/src/launchctl.c (modified) (31 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/launchd/src/launchctl.c
r23142 r23143 279 279 280 280 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])) { 282 282 return cmds[i].func(argc, argv); 283 } 283 284 } 284 285 … … 350 351 351 352 /* XXX escape the double quotes */ 352 if (*is_csh) 353 if (*is_csh) { 353 354 fprintf(stdout, "setenv %s \"%s\";\n", key, launch_data_get_string(obj)); 354 else355 } else { 355 356 fprintf(stdout, "%s=\"%s\"; export %s;\n", key, launch_data_get_string(obj), key); 357 } 356 358 } 357 359 … … 361 363 const char *k = context; 362 364 363 if (!strcmp(key, k)) 365 if (!strcmp(key, k)) { 364 366 fprintf(stdout, "%s\n", launch_data_get_string(obj)); 367 } 365 368 } 366 369 … … 374 377 if (!strcmp(argv[0], "export")) { 375 378 char *s = getenv("SHELL"); 376 if (s) 379 if (s) { 377 380 is_csh = strstr(s, "csh") ? true : false; 381 } 378 382 } else if (argc != 2) { 379 383 fprintf(stderr, "%s usage: getenv <key>\n", getprogname()); … … 389 393 390 394 if (resp) { 391 if (!strcmp(argv[0], "export")) 395 if (!strcmp(argv[0], "export")) { 392 396 launch_data_dict_iterate(resp, print_launchd_env, &is_csh); 393 else397 } else { 394 398 launch_data_dict_iterate(resp, print_key_value, k); 399 } 395 400 launch_data_free(resp); 396 401 } else { … … 424 429 } 425 430 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))) { 427 432 fprintf(stderr, "%s\n", strerror(e)); 433 } 428 434 } 429 435 launch_data_free(resp); … … 442 448 443 449 if (editondisk) { 444 if (load) 450 if (load) { 445 451 CFDictionaryRemoveValue((CFMutableDictionaryRef)plist, CFSTR(LAUNCH_JOBKEY_DISABLED)); 446 else452 } else { 447 453 CFDictionarySetValue((CFMutableDictionaryRef)plist, CFSTR(LAUNCH_JOBKEY_DISABLED), kCFBooleanTrue); 454 } 448 455 WriteMyPropertyListToFile(plist, file); 449 456 } … … 472 479 break; 473 480 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++) { 475 482 delay_to_second_pass2(launch_data_array_get_index(o, i), NULL, context); 483 } 476 484 break; 477 485 default: … … 487 495 launch_data_t socks = launch_data_dict_lookup(o, LAUNCH_JOBKEY_SOCKETS); 488 496 489 if (NULL == socks) 497 if (NULL == socks) { 490 498 return false; 499 } 491 500 492 501 delay_to_second_pass2(socks, NULL, &res); … … 526 535 for (i = 0; i < c; i++) { 527 536 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))) { 529 538 goto out_bad; 539 } 530 540 } 531 541 } … … 536 546 for (i = 0; i < c; i++) { 537 547 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))) { 539 549 break; 540 } 541 542 if (i == c) 550 } 551 } 552 553 if (i == c) { 543 554 goto out_bad; 555 } 544 556 } 545 557 … … 583 595 } 584 596 585 if ((tmpd = launch_data_dict_lookup(thejob, LAUNCH_JOBKEY_DISABLED))) 597 if ((tmpd = launch_data_dict_lookup(thejob, LAUNCH_JOBKEY_DISABLED))) { 586 598 job_disabled = launch_data_get_bool(tmpd); 587 588 if (lus->forceload) 599 } 600 601 if (lus->forceload) { 589 602 job_disabled = false; 590 591 if (job_disabled && lus->load) 603 } 604 605 if (job_disabled && lus->load) { 592 606 goto out_bad; 593 594 if (delay_to_second_pass(thejob)) 607 } 608 609 if (delay_to_second_pass(thejob)) { 595 610 launch_data_array_append(lus->pass2, thejob); 596 else611 } else { 597 612 launch_data_array_append(lus->pass1, thejob); 598 599 if (verbose) 613 } 614 615 if (verbose) { 600 616 fprintf(stdout, "Will load: %s\n", what); 617 } 601 618 602 619 return; 603 620 out_bad: 604 if (verbose) 621 if (verbose) { 605 622 fprintf(stdout, "Ignored: %s\n", what); 623 } 606 624 launch_data_free(thejob); 607 625 } … … 617 635 } 618 636 619 if (forceload) 637 if (forceload) { 620 638 return true; 639 } 621 640 622 641 if (sb.st_mode & (S_IWOTH|S_IWGRP)) { … … 646 665 DIR *d; 647 666 648 if (!path_goodness_check(what, lus->forceload)) 667 if (!path_goodness_check(what, lus->forceload)) { 649 668 return; 650 651 if (stat(what, &sb) == -1) 669 } 670 671 if (stat(what, &sb) == -1) { 652 672 return; 673 } 653 674 654 675 if (S_ISREG(sb.st_mode)) { … … 661 682 662 683 while ((de = readdir(d))) { 663 if ((de->d_name[0] == '.')) 684 if ((de->d_name[0] == '.')) { 664 685 continue; 686 } 665 687 snprintf(buf, sizeof(buf), "%s/%s", what, de->d_name); 666 688 667 if (!path_goodness_check(buf, lus->forceload)) 689 if (!path_goodness_check(buf, lus->forceload)) { 668 690 continue; 691 } 669 692 670 693 readfile(buf, lus); … … 739 762 } 740 763 741 if ((val = launch_data_dict_lookup(tmp, LAUNCH_JOBSOCKETKEY_PASSIVE))) 764 if ((val = launch_data_dict_lookup(tmp, LAUNCH_JOBSOCKETKEY_PASSIVE))) { 742 765 passive = launch_data_get_bool(val); 766 } 743 767 744 768 if ((val = launch_data_dict_lookup(tmp, LAUNCH_JOBSOCKETKEY_SECUREWITHKEY))) { … … 773 797 strncpy(sun.sun_path, launch_data_get_string(val), sizeof(sun.sun_path)); 774 798 775 if ((sfd = _fd(socket(AF_UNIX, st, 0))) == -1) 799 if ((sfd = _fd(socket(AF_UNIX, st, 0))) == -1) { 776 800 return; 801 } 777 802 778 803 if ((val = launch_data_dict_lookup(tmp, LAUNCH_JOBSOCKETKEY_PATHMODE))) { … … 796 821 chmod(sun.sun_path, sun_mode); 797 822 } 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) { 800 824 close(sfd); 801 825 return; … … 819 843 820 844 hints.ai_socktype = st; 821 if (passive) 845 if (passive) { 822 846 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))) { 825 850 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))) { 827 853 mgroup = launch_data_get_string(val); 854 } 828 855 if ((val = launch_data_dict_lookup(tmp, LAUNCH_JOBSOCKETKEY_SERVICENAME))) { 829 856 if (LAUNCH_DATA_INTEGER == launch_data_get_type(val)) { … … 835 862 } 836 863 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))) { 838 865 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))) { 840 867 hints.ai_family = AF_INET6; 868 } 841 869 } 842 870 if ((val = launch_data_dict_lookup(tmp, LAUNCH_JOBSOCKETKEY_PROTOCOL))) { … … 901 929 do_mgroup_join(sfd, res->ai_family, res->ai_socktype, res->ai_protocol, mgroup); 902 930 } 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) { 905 932 fprintf(stderr, "listen(): %s\n", strerror(errno)); 906 933 return; … … 915 942 if (NULL == rnames) { 916 943 rvs_fd = do_rendezvous_magic(res, serv); 917 if (rvs_fd) 944 if (rvs_fd) { 918 945 launch_data_array_append(rvs_fds, rvs_fd); 946 } 919 947 } else if (LAUNCH_DATA_STRING == launch_data_get_type(rnames)) { 920 948 rvs_fd = do_rendezvous_magic(res, launch_data_get_string(rnames)); 921 if (rvs_fd) 949 if (rvs_fd) { 922 950 launch_data_array_append(rvs_fds, rvs_fd); 951 } 923 952 } else if (LAUNCH_DATA_ARRAY == launch_data_get_type(rnames)) { 924 953 size_t rn_i, rn_ac = launch_data_array_get_count(rnames); … … 928 957 929 958 rvs_fd = do_rendezvous_magic(res, launch_data_get_string(rn_tmp)); 930 if (rvs_fd) 959 if (rvs_fd) { 931 960 launch_data_array_append(rvs_fds, rvs_fd); 961 } 932 962 } 933 963 } … … 1007 1037 static int statres = 1; 1008 1038 1009 if (1 == statres) 1039 if (1 == statres) { 1010 1040 statres = stat("/usr/sbin/mDNSResponder", &sb); 1011 1012 if (-1 == statres) 1041 } 1042 1043 if (-1 == statres) { 1013 1044 return NULL; 1045 } 1014 1046 1015 1047 sprintf(rvs_buf, "_%s._%s.", serv, res->ai_socktype == SOCK_STREAM ? "tcp" : "udp"); 1016 1048 1017 if (res->ai_family == AF_INET) 1049 if (res->ai_family == AF_INET) { 1018 1050 port = ((struct sockaddr_in *)res->ai_addr)->sin_port; 1019 else1051 } else { 1020 1052 port = ((struct sockaddr_in6 *)res->ai_addr)->sin6_port; 1053 } 1021 1054 1022 1055 error = DNSServiceRegister(&service, 0, 0, NULL, rvs_buf, NULL, NULL, port, 0, NULL, NULL, NULL); 1023 1056 1024 if (error == kDNSServiceErr_NoError) 1057 if (error == kDNSServiceErr_NoError) { 1025 1058 return launch_data_new_fd(DNSServiceRefSockFD(service)); 1059 } 1026 1060 1027 1061 fprintf(stderr, "DNSServiceRegister(\"%s\"): %d\n", serv, error); … … 1039 1073 1040 1074 fileURL = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8 *)posixfile, strlen(posixfile), false); 1041 if (!fileURL) 1075 if (!fileURL) { 1042 1076 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)) { 1044 1079 fprintf(stderr, "%s: CFURLCreateDataAndPropertiesFromResource(%s) failed: %d\n", getprogname(), posixfile, (int)errorCode); 1080 } 1045 1081 propertyList = CFPropertyListCreateFromXMLData(kCFAllocatorDefault, resourceData, kCFPropertyListMutableContainers, &errorString); 1046 if (!propertyList) 1082 if (!propertyList) { 1047 1083 fprintf(stderr, "%s: propertyList is NULL\n", getprogname()); 1084 } 1048 1085 1049 1086 return propertyList; … … 1058 1095 1059 1096 fileURL = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8 *)posixfile, strlen(posixfile), false); 1060 if (!fileURL) 1097 if (!fileURL) { 1061 1098 fprintf(stderr, "%s: CFURLCreateFromFileSystemRepresentation(%s) failed\n", getprogname(), posixfile); 1099 } 1062 1100 resourceData = CFPropertyListCreateXMLData(kCFAllocatorDefault, plist); 1063 if (resourceData == NULL) 1101 if (resourceData == NULL) { 1064 1102 fprintf(stderr, "%s: CFPropertyListCreateXMLData(%s) failed", getprogname(), posixfile); 1065 if (!CFURLWriteDataAndPropertiesToResource(fileURL, resourceData, NULL, &errorCode)) 1103 } 1104 if (!CFURLWriteDataAndPropertiesToResource(fileURL, resourceData, NULL, &errorCode)) { 1066 1105 fprintf(stderr, "%s: CFURLWriteDataAndPropertiesToResource(%s) failed: %d\n", getprogname(), posixfile, (int)errorCode); 1106 } 1067 1107 } 1068 1108 … … 1163 1203 } 1164 1204 1165 for (i = 0; i < (sizeof cmds / sizeof cmds[0]); i++) 1205 for (i = 0; i < (sizeof cmds / sizeof cmds[0]); i++) { 1166 1206 fprintf(where, "\t%-*s\t%s\n", cmdwidth, cmds[i].name, cmds[i].desc); 1207 } 1167 1208 1168 1209 return 0; … … 1565 1606 submit_job_pass(lus.pass2); 1566 1607 } 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++) { 1568 1609 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++) { 1570 1612 unloadjob(launch_data_array_get_index(lus.pass2, i)); 1613 } 1571 1614 } 1572 1615 … … 2763 2806 2764 2807 while ((val = fgetln(sf, &ln_len))) { 2765 if (ln_len == 0) 2808 if (ln_len == 0) { 2766 2809 continue; 2767 if (!assumes((tmpstr = malloc(ln_len + 1)) != NULL)) 2810 } 2811 if (!assumes((tmpstr = malloc(ln_len + 1)) != NULL)) { 2768 2812 continue; 2813 } 2769 2814 memcpy(tmpstr, val, ln_len); 2770 2815 tmpstr[ln_len] = 0; … … 2773 2818 while (*val && isspace(*val)) 2774 2819 val++; 2775 if (*val == '\0' || *val == '#') 2820 if (*val == '\0' || *val == '#') { 2776 2821 goto skip_sysctl_tool; 2822 } 2777 2823 sysctl_tool[2] = val; 2778 2824 assumes(fwexec(sysctl_tool, true) != -1); … … 2800 2846 } 2801 2847 2802 if (buf[0] != '\0') 2848 if (buf[0] != '\0') { 2803 2849 return; 2850 } 2804 2851 2805 2852 versdict = _CFCopySystemVersionDictionary();

