Changeset 23478
- Timestamp:
- 01/09/08 09:35:12 (11 months ago)
- Location:
- trunk/launchd/src
- Files:
-
- 3 modified
-
launchd.plist.5 (modified) (1 diff)
-
launchd_core_logic.c (modified) (33 diffs)
-
liblaunch_public.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/launchd/src/launchd.plist.5
r23406 r23478 227 227 The month on which this job will be run. 228 228 .El 229 .It Sy StandardInPath <string> 230 This optional key specifies what file should be used for data being supplied to stdin when using 231 .Xr stdio 3 . 229 232 .It Sy StandardOutPath <string> 230 233 This optional key specifies what file should be used for data being sent to stdout when using -
trunk/launchd/src/launchd_core_logic.c
r23477 r23478 332 332 char *username; 333 333 char *groupname; 334 char *stdinpath; 334 335 char *stdoutpath; 335 336 char *stderrpath; … … 344 345 int argc; 345 346 int last_exit_status; 346 int forkfd; 347 int stdin_fd; 348 int fork_fd; 347 349 int log_redirect_fd; 348 350 int nice; … … 459 461 static mach_port_t the_exception_server; 460 462 static bool did_first_per_user_launchd_BootCache_hack; 461 #define JOB_BOOTCACHE_HACK_CHECK(j) ( j->per_user && !did_first_per_user_launchd_BootCache_hack && (j->mach_uid >= 500) && (j->mach_uid != (uid_t)-2))463 #define JOB_BOOTCACHE_HACK_CHECK(j) (unlikely(j->per_user && !did_first_per_user_launchd_BootCache_hack && (j->mach_uid >= 500) && (j->mach_uid != (uid_t)-2))) 462 464 static jobmgr_t background_jobmgr; 463 465 static job_t workaround_5477111; … … 576 578 if (j->prog && (tmp = launch_data_new_string(j->prog))) { 577 579 launch_data_dict_insert(r, tmp, LAUNCH_JOBKEY_PROGRAM); 580 } 581 if (j->stdinpath && (tmp = launch_data_new_string(j->stdinpath))) { 582 launch_data_dict_insert(r, tmp, LAUNCH_JOBKEY_STANDARDINPATH); 578 583 } 579 584 if (j->stdoutpath && (tmp = launch_data_new_string(j->stdoutpath))) { … … 811 816 } 812 817 813 if (!job_assumes(j, j->forkfd == 0)) { 814 job_assumes(j, runtime_close(j->forkfd) != -1); 818 if (!job_assumes(j, j->fork_fd == 0)) { 819 job_assumes(j, runtime_close(j->fork_fd) != -1); 820 } 821 822 if (j->stdin_fd) { 823 job_assumes(j, runtime_close(j->stdin_fd) != -1); 815 824 } 816 825 … … 872 881 if (j->groupname) { 873 882 free(j->groupname); 883 } 884 if (j->stdinpath) { 885 free(j->stdinpath); 874 886 } 875 887 if (j->stdoutpath) { … … 1500 1512 } else if (strcasecmp(key, LAUNCH_JOBKEY_STANDARDERRORPATH) == 0) { 1501 1513 where2put = &j->stderrpath; 1514 } else if (strcasecmp(key, LAUNCH_JOBKEY_STANDARDINPATH) == 0) { 1515 where2put = &j->stdinpath; 1516 j->stdin_fd = _fd(open(value, O_RDONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, DEFFILEMODE)); 1517 if (job_assumes(j, j->stdin_fd != -1)) { 1518 /* open() should not block, but regular IO by the job should */ 1519 job_assumes(j, fcntl(j->stdin_fd, F_SETFL, 0) != -1); 1520 /* XXX -- EV_CLEAR should make named pipes happy? */ 1521 job_assumes(j, kevent_mod(j->stdin_fd, EVFILT_READ, EV_ADD|EV_CLEAR, 0, 0, j) != -1); 1522 } else { 1523 j->stdin_fd = 0; 1524 } 1502 1525 } else if (strcasecmp(key, LAUNCH_JOBKEY_SANDBOXPROFILE) == 0) { 1503 1526 where2put = &j->seatbelt_profile; … … 2095 2118 } 2096 2119 2097 if (j->fork fd) {2098 job_assumes(j, runtime_close(j->fork fd) != -1);2099 j->fork fd = 0;2120 if (j->fork_fd) { 2121 job_assumes(j, runtime_close(j->fork_fd) != -1); 2122 j->fork_fd = 0; 2100 2123 } 2101 2124 … … 2461 2484 if (ident == j->log_redirect_fd) { 2462 2485 job_log_stdouterr(j); 2486 } else if (ident == j->stdin_fd) { 2487 job_dispatch(j, true); 2463 2488 } else { 2464 2489 socketgroup_callback(j); … … 2581 2606 } 2582 2607 2583 if ( job_active(j)) {2608 if (unlikely(job_active(j))) { 2584 2609 job_log(j, LOG_DEBUG, "Already started"); 2585 2610 return; … … 2612 2637 j->sent_sigterm_time = 0; 2613 2638 2614 if ( !j->legacy_mach_job) {2639 if (likely(!j->legacy_mach_job)) { 2615 2640 sipc = (!SLIST_EMPTY(&j->sockets) || !SLIST_EMPTY(&j->machservices)); 2616 2641 } … … 2624 2649 job_assumes(j, socketpair(AF_UNIX, SOCK_STREAM, 0, execspair) != -1); 2625 2650 2626 if ( !j->legacy_mach_job&& job_assumes(j, pipe(oepair) != -1)) {2651 if (likely(!j->legacy_mach_job) && job_assumes(j, pipe(oepair) != -1)) { 2627 2652 j->log_redirect_fd = _fd(oepair[0]); 2628 2653 job_assumes(j, fcntl(j->log_redirect_fd, F_SETFL, O_NONBLOCK) != -1); … … 2641 2666 job_assumes(j, runtime_close(spair[1]) == 0); 2642 2667 } 2643 if ( !j->legacy_mach_job) {2668 if (likely(!j->legacy_mach_job)) { 2644 2669 job_assumes(j, runtime_close(oepair[0]) != -1); 2645 2670 job_assumes(j, runtime_close(oepair[1]) != -1); … … 2648 2673 break; 2649 2674 case 0: 2650 if ( _vproc_post_fork_ping()) {2675 if (unlikely(_vproc_post_fork_ping())) { 2651 2676 _exit(EXIT_FAILURE); 2652 2677 } … … 2680 2705 } 2681 2706 2682 if ( !j->legacy_mach_job) {2707 if (likely(!j->legacy_mach_job)) { 2683 2708 job_assumes(j, runtime_close(oepair[1]) != -1); 2684 2709 } 2685 2710 j->p = c; 2686 if ( j->hopefully_exits_first) {2711 if (unlikely(j->hopefully_exits_first)) { 2687 2712 j->mgr->hopefully_first_cnt++; 2688 } else if ( !j->hopefully_exits_last) {2713 } else if (likely(!j->hopefully_exits_last)) { 2689 2714 j->mgr->normal_active_cnt++; 2690 2715 } 2691 j->fork fd = _fd(execspair[0]);2716 j->fork_fd = _fd(execspair[0]); 2692 2717 job_assumes(j, runtime_close(execspair[1]) == 0); 2693 2718 if (sipc) { … … 2701 2726 } 2702 2727 2703 if ( !j->stall_before_exec) {2728 if (likely(!j->stall_before_exec)) { 2704 2729 job_uncork_fork(j); 2705 2730 } … … 2746 2771 job_setup_attributes(j); 2747 2772 2748 if ( j->argv && j->globargv) {2773 if (unlikely(j->argv && j->globargv)) { 2749 2774 g.gl_offs = 1; 2750 2775 for (i = 0; i < j->argc; i++) { … … 2773 2798 } 2774 2799 2775 if ( !j->inetcompat) {2800 if (likely(!j->inetcompat)) { 2776 2801 argv++; 2777 2802 } 2778 2803 2779 if ( j->wait4debugger) {2804 if (unlikely(j->wait4debugger)) { 2780 2805 job_log(j, LOG_WARNING, "Spawned and waiting for the debugger to attach before continuing..."); 2781 2806 spflags |= POSIX_SPAWN_START_SUSPENDED; … … 2784 2809 job_assumes(j, posix_spawnattr_setflags(&spattr, spflags) == 0); 2785 2810 2786 if ( j->j_binpref_cnt) {2811 if (unlikely(j->j_binpref_cnt)) { 2787 2812 job_assumes(j, posix_spawnattr_setbinpref_np(&spattr, j->j_binpref_cnt, j->j_binpref, &binpref_out_cnt) == 0); 2788 2813 job_assumes(j, binpref_out_cnt == j->j_binpref_cnt); … … 2812 2837 psf = j->prog ? posix_spawn : posix_spawnp; 2813 2838 2814 if ( !j->inetcompat) {2839 if (likely(!j->inetcompat)) { 2815 2840 file2exec = j->prog ? j->prog : argv[0]; 2816 2841 } … … 2965 2990 strlcpy(homedir, pwe->pw_dir, sizeof(homedir)); 2966 2991 2967 if ( pwe->pw_expire && time(NULL) >= pwe->pw_expire) {2992 if (unlikely(pwe->pw_expire && time(NULL) >= pwe->pw_expire)) { 2968 2993 job_log(j, LOG_ERR, "Expired account"); 2969 2994 _exit(EXIT_FAILURE); … … 2971 2996 2972 2997 2973 if ( j->username && strcmp(j->username, loginname) != 0) {2998 if (unlikely(j->username && strcmp(j->username, loginname) != 0)) { 2974 2999 job_log(j, LOG_WARNING, "Suspicious setup: User \"%s\" maps to user: %s", j->username, loginname); 2975 } else if ( j->mach_uid && (j->mach_uid != desired_uid)) {3000 } else if (unlikely(j->mach_uid && (j->mach_uid != desired_uid))) { 2976 3001 job_log(j, LOG_WARNING, "Suspicious setup: UID %u maps to UID %u", j->mach_uid, desired_uid); 2977 3002 } … … 2980 3005 struct group *gre; 2981 3006 2982 if ( (gre = getgrnam(j->groupname)) == NULL) {3007 if (unlikely((gre = getgrnam(j->groupname)) == NULL)) { 2983 3008 job_log(j, LOG_ERR, "getgrnam(\"%s\") failed", j->groupname); 2984 3009 _exit(EXIT_FAILURE); … … 3001 3026 */ 3002 3027 3003 if ( !j->no_init_groups) {3028 if (likely(!j->no_init_groups)) { 3004 3029 if (!job_assumes(j, initgroups(loginname, desired_gid) != -1)) { 3005 3030 _exit(EXIT_FAILURE); … … 3013 3038 r = confstr(_CS_DARWIN_USER_TEMP_DIR, tmpdirpath, sizeof(tmpdirpath)); 3014 3039 3015 if ( r > 0 && r < sizeof(tmpdirpath)) {3040 if (likely(r > 0 && r < sizeof(tmpdirpath))) { 3016 3041 setenv("TMPDIR", tmpdirpath, 0); 3017 3042 } … … 3029 3054 struct envitem *ei; 3030 3055 3031 if ( j->setnice) {3056 if (unlikely(j->setnice)) { 3032 3057 job_assumes(j, setpriority(PRIO_PROCESS, 0, j->nice) != -1); 3033 3058 } … … 3052 3077 } 3053 3078 3054 if ( !j->inetcompat && j->session_create) {3079 if (unlikely(!j->inetcompat && j->session_create)) { 3055 3080 launchd_SessionCreate(); 3056 3081 } 3057 3082 3058 if ( j->low_pri_io) {3083 if (unlikely(j->low_pri_io)) { 3059 3084 job_assumes(j, setiopolicy_np(IOPOL_TYPE_DISK, IOPOL_SCOPE_PROCESS, IOPOL_THROTTLE) != -1); 3060 3085 } 3061 if ( j->rootdir) {3086 if (unlikely(j->rootdir)) { 3062 3087 job_assumes(j, chroot(j->rootdir) != -1); 3063 3088 job_assumes(j, chdir(".") != -1); … … 3066 3091 job_postfork_become_user(j); 3067 3092 3068 if ( j->workingdir) {3093 if (unlikely(j->workingdir)) { 3069 3094 job_assumes(j, chdir(j->workingdir) != -1); 3070 3095 } 3071 3096 3072 if ( j->setmask) {3097 if (unlikely(j->setmask)) { 3073 3098 umask(j->mask); 3074 3099 } 3075 3100 3076 job_setup_fd(j, STDOUT_FILENO, j->stdoutpath, O_WRONLY|O_APPEND|O_CREAT); 3077 job_setup_fd(j, STDERR_FILENO, j->stderrpath, O_WRONLY|O_APPEND|O_CREAT); 3101 if (j->stdin_fd) { 3102 job_assumes(j, dup2(j->stdin_fd, STDIN_FILENO) != -1); 3103 } else { 3104 job_setup_fd(j, STDIN_FILENO, j->stdinpath, O_RDONLY|O_CREAT); 3105 } 3106 job_setup_fd(j, STDOUT_FILENO, j->stdoutpath, O_WRONLY|O_CREAT|O_APPEND); 3107 job_setup_fd(j, STDERR_FILENO, j->stderrpath, O_WRONLY|O_CREAT|O_APPEND); 3078 3108 3079 3109 jobmgr_setup_env_from_other_jobs(j->mgr); … … 3120 3150 bool r = 0; 3121 3151 3122 if ( !dd) {3152 if (unlikely(!dd)) { 3123 3153 return -1; 3124 3154 } … … 3186 3216 time_string_len = strlen(time_string); 3187 3217 3188 if ( time_string_len && time_string[time_string_len - 1] == '\n') {3218 if (likely(time_string_len && time_string[time_string_len - 1] == '\n')) { 3189 3219 time_string[time_string_len - 1] = '\0'; 3190 3220 } … … 3288 3318 } 3289 3319 3290 if ( j->debug) {3320 if (unlikely(j->debug)) { 3291 3321 oldmask = setlogmask(LOG_UPTO(LOG_DEBUG)); 3292 3322 } … … 3294 3324 runtime_vsyslog(&attr, newmsg, ap); 3295 3325 3296 if ( j->debug) {3326 if (unlikely(j->debug)) { 3297 3327 setlogmask(oldmask); 3298 3328 } … … 4415 4445 /* this unblocks the child and avoids a race 4416 4446 * between the above fork() and the kevent_mod() */ 4417 job_assumes(j, write(j->fork fd, &c, sizeof(c)) == sizeof(c));4418 job_assumes(j, runtime_close(j->fork fd) != -1);4419 j->fork fd = 0;4447 job_assumes(j, write(j->fork_fd, &c, sizeof(c)) == sizeof(c)); 4448 job_assumes(j, runtime_close(j->fork_fd) != -1); 4449 j->fork_fd = 0; 4420 4450 } 4421 4451 -
trunk/launchd/src/liblaunch_public.h
r23406 r23478 86 86 #define LAUNCH_JOBKEY_SOFTRESOURCELIMITS "SoftResourceLimits" 87 87 #define LAUNCH_JOBKEY_HARDRESOURCELIMITS "HardResourceLimits" 88 #define LAUNCH_JOBKEY_STANDARDINPATH "StandardInPath" 88 89 #define LAUNCH_JOBKEY_STANDARDOUTPATH "StandardOutPath" 89 90 #define LAUNCH_JOBKEY_STANDARDERRORPATH "StandardErrorPath"

