Projects
Browse Source     Search     Timeline     Wiki

Changeset 23543

Show
Ignore:
Timestamp:
03/10/08 13:49:07 (9 months ago)
Author:
zarzycki@…
Message:

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

Files:
1 modified

Legend:

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

    r23540 r23543  
    173173        int *fds; 
    174174        unsigned int junkfds:1, fd_cnt:31; 
    175         char name[0]; 
     175        union { 
     176                const char name[0]; 
     177                char name_init[0]; 
     178        }; 
    176179}; 
    177180 
     
    205208        SLIST_ENTRY(envitem) sle; 
    206209        char *value; 
    207         char key[0]; 
     210        union { 
     211                const char key[0]; 
     212                char key_init[0]; 
     213        }; 
    208214}; 
    209215 
     
    245251        semaphore_reason_t why; 
    246252        int fd; 
    247         char what[0]; 
     253        union { 
     254                const char what[0]; 
     255                char what_init[0]; 
     256        }; 
    248257}; 
    249258 
     
    283292        unsigned int normal_active_cnt; 
    284293        unsigned int sent_stop_to_normal_jobs:1, sent_stop_to_hopefully_last_jobs:1, shutting_down:1, session_initialized:1, __junk:28; 
    285         char name[0]; 
     294        union { 
     295                const char name[0]; 
     296                char name_init[0]; 
     297        }; 
    286298}; 
    287299 
     
    35003512semaphoreitem_watch(job_t j, struct semaphoreitem *si) 
    35013513{ 
    3502         char parentdir_path[PATH_MAX], *which_path = si->what; 
     3514        char *parentdir, tmp_path[PATH_MAX]; 
     3515        const char *which_path = si->what; 
    35033516        int saved_errno = 0; 
    35043517        int fflags = 0; 
    3505          
    3506         strlcpy(parentdir_path, dirname(si->what), sizeof(parentdir_path)); 
    35073518 
    35083519        switch (si->why) { 
     
    35183529                break; 
    35193530        default: 
     3531                return; 
     3532        } 
     3533 
     3534        /* dirname() may modify tmp_path */ 
     3535        strlcpy(tmp_path, si->what, sizeof(tmp_path)); 
     3536 
     3537        if (!job_assumes(j, (parentdir = dirname(tmp_path)))) { 
    35203538                return; 
    35213539        } 
     
    35253543                if (si->fd == -1) { 
    35263544                        if ((si->fd = _fd(open(which_path, O_EVTONLY|O_NOCTTY))) == -1) { 
    3527                                 which_path = parentdir_path; 
     3545                                which_path = parentdir; 
    35283546                                si->fd = _fd(open(which_path, O_EVTONLY|O_NOCTTY)); 
    35293547                        } 
     
    37663784 
    37673785        memcpy(sg->fds, fds, fd_cnt * sizeof(int)); 
    3768         strcpy(sg->name, name); 
     3786        strcpy(sg->name_init, name); 
    37693787 
    37703788        SLIST_INSERT_HEAD(&j->sockets, sg, sle); 
     
    38583876        } 
    38593877 
    3860         strcpy(ei->key, k); 
    3861         ei->value = ei->key + strlen(k) + 1; 
     3878        strcpy(ei->key_init, k); 
     3879        ei->value = ei->key_init + strlen(k) + 1; 
    38623880        strcpy(ei->value, v); 
    38633881 
     
    45564574 
    45574575        jmr->kqjobmgr_callback = jobmgr_callback; 
    4558         strcpy(jmr->name, name ? name : "Under construction"); 
     4576        strcpy(jmr->name_init, name ? name : "Under construction"); 
    45594577 
    45604578        jmr->req_port = requestorport; 
     
    46044622 
    46054623        if (!name) { 
    4606                 sprintf(jmr->name, "%u", MACH_PORT_INDEX(jmr->jm_port)); 
     4624                sprintf(jmr->name_init, "%u", MACH_PORT_INDEX(jmr->jm_port)); 
    46074625        } 
    46084626 
     
    50465064 
    50475065        if (what) { 
    5048                 strcpy(si->what, what); 
     5066                strcpy(si->what_init, what); 
    50495067        } 
    50505068 
     
    63266344 
    63276345                jobmgr_log(j->mgr, LOG_DEBUG, "Renaming to: %s", session_type); 
    6328                 strcpy(j->mgr->name, session_type); 
     6346                strcpy(j->mgr->name_init, session_type); 
    63296347 
    63306348                if (job_assumes(j, (j2 = jobmgr_init_session(j->mgr, session_type, false)))) {