Projects
Browse Source     Search     Timeline     Wiki

Changeset 23544

Show
Ignore:
Timestamp:
03/10/08 14:09:42 (9 months ago)
Author:
zarzycki@…
Message:

<rdar://problem/5790562> dirname() is tricky

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/SULeopard/launchd/src/launchd_core_logic.c

    r23527 r23544  
    171171        int *fds; 
    172172        unsigned int junkfds:1, fd_cnt:31; 
    173         char name[0]; 
     173        union { 
     174                const char name[0]; 
     175                char name_init[0]; 
     176        }; 
    174177}; 
    175178 
     
    203206        SLIST_ENTRY(envitem) sle; 
    204207        char *value; 
    205         char key[0]; 
     208        union { 
     209                const char key[0]; 
     210                char key_init[0]; 
     211        }; 
    206212}; 
    207213 
     
    243249        semaphore_reason_t why; 
    244250        int fd; 
    245         char what[0]; 
     251        union { 
     252                const char what[0]; 
     253                char what_init[0]; 
     254        }; 
    246255}; 
    247256 
     
    280289        unsigned int normal_active_cnt; 
    281290        unsigned int sent_stop_to_normal_jobs:1, sent_stop_to_hopefully_last_jobs:1, shutting_down:1, session_initialized:1; 
    282         char name[0]; 
     291        union { 
     292                const char name[0]; 
     293                char name_init[0]; 
     294        }; 
    283295}; 
    284296 
     
    33353347semaphoreitem_watch(job_t j, struct semaphoreitem *si) 
    33363348{ 
    3337         char parentdir_path[PATH_MAX], *which_path = si->what; 
     3349        char *parentdir, tmp_path[PATH_MAX]; 
     3350        const char *which_path = si->what; 
    33383351        int saved_errno = 0; 
    33393352        int fflags = 0; 
    3340          
    3341         strlcpy(parentdir_path, dirname(si->what), sizeof(parentdir_path)); 
    33423353 
    33433354        switch (si->why) { 
     
    33533364                break; 
    33543365        default: 
     3366                return; 
     3367        } 
     3368 
     3369        /* dirname() may modify tmp_path */ 
     3370        strlcpy(tmp_path, si->what, sizeof(tmp_path)); 
     3371 
     3372        if (!job_assumes(j, (parentdir = dirname(tmp_path)))) { 
    33553373                return; 
    33563374        } 
     
    33603378                if (si->fd == -1) { 
    33613379                        if ((si->fd = _fd(open(which_path, O_EVTONLY|O_NOCTTY))) == -1) { 
    3362                                 which_path = parentdir_path; 
     3380                                which_path = parentdir; 
    33633381                                si->fd = _fd(open(which_path, O_EVTONLY|O_NOCTTY)); 
    33643382                        } 
     
    36013619 
    36023620        memcpy(sg->fds, fds, fd_cnt * sizeof(int)); 
    3603         strcpy(sg->name, name); 
     3621        strcpy(sg->name_init, name); 
    36043622 
    36053623        SLIST_INSERT_HEAD(&j->sockets, sg, sle); 
     
    36933711        } 
    36943712 
    3695         strcpy(ei->key, k); 
    3696         ei->value = ei->key + strlen(k) + 1; 
     3713        strcpy(ei->key_init, k); 
     3714        ei->value = ei->key_init + strlen(k) + 1; 
    36973715        strcpy(ei->value, v); 
    36983716 
     
    44024420 
    44034421        jmr->kqjobmgr_callback = jobmgr_callback; 
    4404         strcpy(jmr->name, name ? name : "Under construction"); 
     4422        strcpy(jmr->name_init, name ? name : "Under construction"); 
    44054423 
    44064424        jmr->req_port = requestorport; 
     
    44504468 
    44514469        if (!name) { 
    4452                 sprintf(jmr->name, "%u", MACH_PORT_INDEX(jmr->jm_port)); 
     4470                sprintf(jmr->name_init, "%u", MACH_PORT_INDEX(jmr->jm_port)); 
    44534471        } 
    44544472 
     
    48904908 
    48914909        if (what) { 
    4892                 strcpy(si->what, what); 
     4910                strcpy(si->what_init, what); 
    48934911        } 
    48944912 
     
    61696187 
    61706188                jobmgr_log(j->mgr, LOG_DEBUG, "Renaming to: %s", session_type); 
    6171                 strcpy(j->mgr->name, session_type); 
     6189                strcpy(j->mgr->name_init, session_type); 
    61726190 
    61736191                if (job_assumes(j, (j2 = jobmgr_init_session(j->mgr, session_type, false)))) {