<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre, #msg p { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[23544] branches/SULeopard/launchd/src/launchd_core_logic.c</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.macosforge.org/projects/launchd/changeset/23544">23544</a></dd>
<dt>Author</dt> <dd>zarzycki@apple.com</dd>
<dt>Date</dt> <dd>2008-03-10 14:09:42 -0700 (Mon, 10 Mar 2008)</dd>
</dl>
<h3>Log Message</h3>
<pre><rdar://problem/5790562> dirname() is tricky</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#branchesSULeopardlaunchdsrclaunchd_core_logicc">branches/SULeopard/launchd/src/launchd_core_logic.c</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchesSULeopardlaunchdsrclaunchd_core_logicc"></a>
<div class="modfile"><h4>Modified: branches/SULeopard/launchd/src/launchd_core_logic.c (23543 => 23544)</h4>
<pre class="diff"><span>
<span class="info">--- branches/SULeopard/launchd/src/launchd_core_logic.c        2008-03-10 20:49:07 UTC (rev 23543)
+++ branches/SULeopard/launchd/src/launchd_core_logic.c        2008-03-10 21:09:42 UTC (rev 23544)
</span><span class="lines">@@ -170,7 +170,10 @@
</span><span class="cx">         SLIST_ENTRY(socketgroup) sle;
</span><span class="cx">         int *fds;
</span><span class="cx">         unsigned int junkfds:1, fd_cnt:31;
</span><del>-        char name[0];
</del><ins>+        union {
+                const char name[0];
+                char name_init[0];
+        };
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> static bool socketgroup_new(job_t j, const char *name, int *fds, unsigned int fd_cnt, bool junkfds);
</span><span class="lines">@@ -202,7 +205,10 @@
</span><span class="cx"> struct envitem {
</span><span class="cx">         SLIST_ENTRY(envitem) sle;
</span><span class="cx">         char *value;
</span><del>-        char key[0];
</del><ins>+        union {
+                const char key[0];
+                char key_init[0];
+        };
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> static bool envitem_new(job_t j, const char *k, const char *v, bool global);
</span><span class="lines">@@ -242,7 +248,10 @@
</span><span class="cx">         SLIST_ENTRY(semaphoreitem) sle;
</span><span class="cx">         semaphore_reason_t why;
</span><span class="cx">         int fd;
</span><del>-        char what[0];
</del><ins>+        union {
+                const char what[0];
+                char what_init[0];
+        };
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> struct semaphoreitem_dict_iter_context {
</span><span class="lines">@@ -279,7 +288,10 @@
</span><span class="cx">         unsigned int hopefully_first_cnt;
</span><span class="cx">         unsigned int normal_active_cnt;
</span><span class="cx">         unsigned int sent_stop_to_normal_jobs:1, sent_stop_to_hopefully_last_jobs:1, shutting_down:1, session_initialized:1;
</span><del>-        char name[0];
</del><ins>+        union {
+                const char name[0];
+                char name_init[0];
+        };
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> #define jobmgr_assumes(jm, e)        \
</span><span class="lines">@@ -3334,11 +3346,10 @@
</span><span class="cx"> void
</span><span class="cx"> semaphoreitem_watch(job_t j, struct semaphoreitem *si)
</span><span class="cx"> {
</span><del>-        char parentdir_path[PATH_MAX], *which_path = si->what;
</del><ins>+        char *parentdir, tmp_path[PATH_MAX];
+        const char *which_path = si->what;
</ins><span class="cx">         int saved_errno = 0;
</span><span class="cx">         int fflags = 0;
</span><del>-        
-        strlcpy(parentdir_path, dirname(si->what), sizeof(parentdir_path));
</del><span class="cx">
</span><span class="cx">         switch (si->why) {
</span><span class="cx">         case PATH_EXISTS:
</span><span class="lines">@@ -3355,11 +3366,18 @@
</span><span class="cx">                 return;
</span><span class="cx">         }
</span><span class="cx">
</span><ins>+        /* dirname() may modify tmp_path */
+        strlcpy(tmp_path, si->what, sizeof(tmp_path));
+
+        if (!job_assumes(j, (parentdir = dirname(tmp_path)))) {
+                return;
+        }
+
</ins><span class="cx">         /* See 5321044 for why we do the do-while loop and 5415523 for why ENOENT is checked */
</span><span class="cx">         do {
</span><span class="cx">                 if (si->fd == -1) {
</span><span class="cx">                         if ((si->fd = _fd(open(which_path, O_EVTONLY|O_NOCTTY))) == -1) {
</span><del>-                                which_path = parentdir_path;
</del><ins>+                                which_path = parentdir;
</ins><span class="cx">                                 si->fd = _fd(open(which_path, O_EVTONLY|O_NOCTTY));
</span><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="lines">@@ -3600,7 +3618,7 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         memcpy(sg->fds, fds, fd_cnt * sizeof(int));
</span><del>-        strcpy(sg->name, name);
</del><ins>+        strcpy(sg->name_init, name);
</ins><span class="cx">
</span><span class="cx">         SLIST_INSERT_HEAD(&j->sockets, sg, sle);
</span><span class="cx">
</span><span class="lines">@@ -3692,8 +3710,8 @@
</span><span class="cx">                 return false;
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        strcpy(ei->key, k);
-        ei->value = ei->key + strlen(k) + 1;
</del><ins>+        strcpy(ei->key_init, k);
+        ei->value = ei->key_init + strlen(k) + 1;
</ins><span class="cx">         strcpy(ei->value, v);
</span><span class="cx">
</span><span class="cx">         if (global) {
</span><span class="lines">@@ -4401,7 +4419,7 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         jmr->kqjobmgr_callback = jobmgr_callback;
</span><del>-        strcpy(jmr->name, name ? name : "Under construction");
</del><ins>+        strcpy(jmr->name_init, name ? name : "Under construction");
</ins><span class="cx">
</span><span class="cx">         jmr->req_port = requestorport;
</span><span class="cx">
</span><span class="lines">@@ -4449,7 +4467,7 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         if (!name) {
</span><del>-                sprintf(jmr->name, "%u", MACH_PORT_INDEX(jmr->jm_port));
</del><ins>+                sprintf(jmr->name_init, "%u", MACH_PORT_INDEX(jmr->jm_port));
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         /* Sigh... at the moment, MIG has maxsize == sizeof(reply union) */
</span><span class="lines">@@ -4889,7 +4907,7 @@
</span><span class="cx">         si->why = why;
</span><span class="cx">
</span><span class="cx">         if (what) {
</span><del>-                strcpy(si->what, what);
</del><ins>+                strcpy(si->what_init, what);
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         SLIST_INSERT_HEAD(&j->semaphores, si, sle);
</span><span class="lines">@@ -6168,7 +6186,7 @@
</span><span class="cx">                 }
</span><span class="cx">
</span><span class="cx">                 jobmgr_log(j->mgr, LOG_DEBUG, "Renaming to: %s", session_type);
</span><del>-                strcpy(j->mgr->name, session_type);
</del><ins>+                strcpy(j->mgr->name_init, session_type);
</ins><span class="cx">
</span><span class="cx">                 if (job_assumes(j, (j2 = jobmgr_init_session(j->mgr, session_type, false)))) {
</span><span class="cx">                         job_assumes(j, job_dispatch(j2, true));
</span></span></pre>
</div>
</div>
</body>
</html>