[launchd-changes] [23274] trunk/launchd/src
source_changes at macosforge.org
source_changes at macosforge.org
Thu Jun 7 16:00:51 PDT 2007
Revision: 23274
http://trac.macosforge.org/projects/launchd/changeset/23274
Author: zarzycki at apple.com
Date: 2007-06-07 16:00:50 -0700 (Thu, 07 Jun 2007)
Log Message:
-----------
<rdar://problem/5257979> merge launchd's two kqueues into one
Modified Paths:
--------------
trunk/launchd/src/launchd.c
trunk/launchd/src/launchd.h
trunk/launchd/src/launchd_core_logic.c
trunk/launchd/src/launchd_runtime.c
trunk/launchd/src/launchd_runtime.h
trunk/launchd/src/launchd_unix_ipc.c
trunk/launchd/src/launchd_unix_ipc.h
trunk/launchd/src/liblaunch.c
Modified: trunk/launchd/src/launchd.c
===================================================================
--- trunk/launchd/src/launchd.c 2007-06-06 16:04:51 UTC (rev 23273)
+++ trunk/launchd/src/launchd.c 2007-06-07 23:00:50 UTC (rev 23274)
@@ -102,7 +102,6 @@
static bool shutdown_in_progress = false;
bool debug_shutdown_hangs = false;
bool network_up = false;
-int batch_disabler_count = 0;
int
main(int argc, char *const *argv)
@@ -315,24 +314,6 @@
}
}
-void
-batch_job_enable(bool e, struct conncb *c)
-{
- if (e && c->disabled_batch) {
- batch_disabler_count--;
- c->disabled_batch = 0;
- if (batch_disabler_count == 0) {
- runtime_force_on_demand(false);
- }
- } else if (!e && !c->disabled_batch) {
- if (batch_disabler_count == 0) {
- runtime_force_on_demand(true);
- }
- batch_disabler_count++;
- c->disabled_batch = 1;
- }
-}
-
bool
get_network_state(void)
{
Modified: trunk/launchd/src/launchd.h
===================================================================
--- trunk/launchd/src/launchd.h 2007-06-06 16:04:51 UTC (rev 23273)
+++ trunk/launchd/src/launchd.h 2007-06-07 23:00:50 UTC (rev 23274)
@@ -33,13 +33,10 @@
extern bool debug_shutdown_hangs;
extern bool network_up;
-extern int batch_disabler_count;
extern mach_port_t inherited_bootstrap_port;
bool init_check_pid(pid_t);
-void batch_job_enable(bool e, struct conncb *c);
-
launch_data_t launchd_setstdio(int d, launch_data_t o);
void launchd_SessionCreate(void);
void launchd_shutdown(void);
Modified: trunk/launchd/src/launchd_core_logic.c
===================================================================
--- trunk/launchd/src/launchd_core_logic.c 2007-06-06 16:04:51 UTC (rev 23273)
+++ trunk/launchd/src/launchd_core_logic.c 2007-06-07 23:00:50 UTC (rev 23274)
@@ -335,7 +335,7 @@
unsigned int start_interval;
unsigned int checkedin:1, anonymous:1, debug:1, inetcompat:1, inetcompat_wait:1,
ondemand:1, session_create:1, low_pri_io:1, no_init_groups:1, priv_port_has_senders:1,
- importing_global_env:1, importing_hard_limits:1, setmask:1, legacy_mach_job:1, runatload:1;
+ importing_global_env:1, importing_hard_limits:1, setmask:1, legacy_mach_job:1, start_pending:1;
mode_t mask;
unsigned int globargv:1, wait4debugger:1, unload_at_exit:1, stall_before_exec:1, only_once:1,
currently_ignored:1, forced_peers_to_demand_mode:1, setnice:1, hopefully_exits_last:1, removal_pending:1,
@@ -1224,7 +1224,10 @@
case 'r':
case 'R':
if (strcasecmp(key, LAUNCH_JOBKEY_RUNATLOAD) == 0) {
- j->runatload = value;
+ if (value) {
+ /* We don't want value == false to change j->start_pending */
+ j->start_pending = true;
+ }
found_key = true;
}
break;
@@ -1942,7 +1945,11 @@
}
LIST_FOREACH_SAFE(ji, &jm->jobs, sle, jn) {
- job_dispatch(ji, newmounthack ? ji->start_on_mount : false);
+ if (newmounthack && ji->start_on_mount) {
+ ji->start_pending = true;
+ }
+
+ job_dispatch(ji, false);
}
}
@@ -2067,8 +2074,11 @@
void
job_callback_timer(job_t j, void *ident)
{
- if (j == ident || &j->start_interval == ident) {
+ if (j == ident) {
job_dispatch(j, true);
+ } else if (&j->start_interval == ident) {
+ j->start_pending = true;
+ job_dispatch(j, false);
} else if (&j->exit_timeout == ident) {
if (j->sent_sigkill) {
struct timeval tvd, tve;
@@ -2262,6 +2272,8 @@
default:
job_log(j, LOG_DEBUG, "Started as PID: %u", c);
+ j->start_pending = false;
+
total_children++;
LIST_INSERT_HEAD(&j->mgr->active_jobs[ACTIVE_JOB_HASH(c)], j, pid_hash_sle);
@@ -2994,13 +3006,44 @@
job_log(j, LOG_DEBUG, "Watch path modified: %s", si->what);
- job_dispatch(j, si->why == PATH_CHANGES ? true : false);
+ if (si->why == PATH_CHANGES) {
+ j->start_pending = true;
+ }
+
+ job_dispatch(j, false);
}
+static void
+calendarinterval_new_from_obj_dict_walk(launch_data_t obj, const char *key, void *context)
+{
+ struct tm *tmptm = context;
+ int64_t val;
+
+ if (LAUNCH_DATA_INTEGER != launch_data_get_type(obj)) {
+ /* hack to let caller know something went wrong */
+ tmptm->tm_sec = -1;
+ return;
+ }
+
+ val = launch_data_get_integer(obj);
+
+ if (strcasecmp(key, LAUNCH_JOBKEY_CAL_MINUTE) == 0) {
+ tmptm->tm_min = val;
+ } else if (strcasecmp(key, LAUNCH_JOBKEY_CAL_HOUR) == 0) {
+ tmptm->tm_hour = val;
+ } else if (strcasecmp(key, LAUNCH_JOBKEY_CAL_DAY) == 0) {
+ tmptm->tm_mday = val;
+ } else if (strcasecmp(key, LAUNCH_JOBKEY_CAL_WEEKDAY) == 0) {
+ tmptm->tm_wday = val;
+ } else if (strcasecmp(key, LAUNCH_JOBKEY_CAL_MONTH) == 0) {
+ tmptm->tm_mon = val;
+ tmptm->tm_mon -= 1; /* 4798263 cron compatibility */
+ }
+}
+
bool
calendarinterval_new_from_obj(job_t j, launch_data_t obj)
{
- launch_data_t tmp_k;
struct tm tmptm;
memset(&tmptm, 0, sizeof(0));
@@ -3019,22 +3062,11 @@
return false;
}
- if ((tmp_k = launch_data_dict_lookup(obj, LAUNCH_JOBKEY_CAL_MINUTE))) {
- tmptm.tm_min = launch_data_get_integer(tmp_k);
+ launch_data_dict_iterate(obj, calendarinterval_new_from_obj_dict_walk, &tmptm);
+
+ if (tmptm.tm_sec == -1) {
+ return false;
}
- if ((tmp_k = launch_data_dict_lookup(obj, LAUNCH_JOBKEY_CAL_HOUR))) {
- tmptm.tm_hour = launch_data_get_integer(tmp_k);
- }
- if ((tmp_k = launch_data_dict_lookup(obj, LAUNCH_JOBKEY_CAL_DAY))) {
- tmptm.tm_mday = launch_data_get_integer(tmp_k);
- }
- if ((tmp_k = launch_data_dict_lookup(obj, LAUNCH_JOBKEY_CAL_WEEKDAY))) {
- tmptm.tm_wday = launch_data_get_integer(tmp_k);
- }
- if ((tmp_k = launch_data_dict_lookup(obj, LAUNCH_JOBKEY_CAL_MONTH))) {
- tmptm.tm_mon = launch_data_get_integer(tmp_k);
- tmptm.tm_mon -= 1; /* 4798263 cron compatibility */
- }
return calendarinterval_new(j, &tmptm);
}
@@ -3080,7 +3112,8 @@
if (job_assumes(j, ci != NULL)) {
calendarinterval_setalarm(j, ci);
- job_dispatch(j, true);
+ j->start_pending = true;
+ job_dispatch(j, false);
}
}
@@ -3355,7 +3388,7 @@
return false;
}
- if (j->runatload && j->start_time == 0) {
+ if (j->start_pending && j->start_time == 0) {
job_log(j, LOG_DEBUG, "KeepAlive check: job needs to run at least once.");
return true;
}
@@ -4360,7 +4393,7 @@
} else if (strcasecmp(key, LAUNCH_JOBKEY_KEEPALIVE_SUCCESSFULEXIT) == 0) {
why = launch_data_get_bool(obj) ? SUCCESSFUL_EXIT : FAILED_EXIT;
semaphoreitem_new(j, why, NULL);
- j->runatload = true;
+ j->start_pending = true;
} else {
job_assumes(j, false);
}
Modified: trunk/launchd/src/launchd_runtime.c
===================================================================
--- trunk/launchd/src/launchd_runtime.c 2007-06-06 16:04:51 UTC (rev 23273)
+++ trunk/launchd/src/launchd_runtime.c 2007-06-07 23:00:50 UTC (rev 23274)
@@ -69,7 +69,6 @@
static mach_port_t demand_port_set;
static mach_port_t launchd_internal_port;
static int mainkq;
-static int asynckq;
#define BULK_KEV_MAX 100
static struct kevent *bulk_kev;
@@ -83,9 +82,6 @@
static void *kqueue_demand_loop(void *arg);
static void log_kevent_struct(int level, struct kevent *kev, int indx);
-static void async_callback(void);
-static kq_callback kqasync_callback = (kq_callback)async_callback;
-
static void record_caller_creds(mach_msg_header_t *mh);
static void launchd_runtime2(mach_msg_size_t msg_size, mig_reply_error_t *bufRequest, mig_reply_error_t *bufReply);
static mach_msg_size_t max_msg_size;
@@ -102,10 +98,7 @@
pthread_attr_t attr;
launchd_assert((mainkq = kqueue()) != -1);
- launchd_assert((asynckq = kqueue()) != -1);
- launchd_assert(kevent_mod(asynckq, EVFILT_READ, EV_ADD, 0, 0, &kqasync_callback) != -1);
-
launchd_assert((errno = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_PORT_SET, &demand_port_set)) == KERN_SUCCESS);
launchd_assert((errno = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_PORT_SET, &ipc_port_set)) == KERN_SUCCESS);
@@ -691,17 +684,11 @@
kevent_mod(uintptr_t ident, short filter, u_short flags, u_int fflags, intptr_t data, void *udata)
{
struct kevent kev;
- int q = mainkq;
switch (filter) {
case EVFILT_READ:
case EVFILT_WRITE:
break;
- case EVFILT_TIMER:
- case EVFILT_VNODE:
- case EVFILT_FS:
- q = asynckq;
- /* fall through */
default:
flags |= EV_CLEAR;
break;
@@ -714,27 +701,9 @@
EV_SET(&kev, ident, filter, flags, fflags, data, udata);
- return kevent(q, &kev, 1, NULL, 0, NULL);
+ return kevent(mainkq, &kev, 1, NULL, 0, NULL);
}
-void
-async_callback(void)
-{
- struct timespec timeout = { 0, 0 };
- struct kevent kev;
-
- if (launchd_assumes(kevent(asynckq, NULL, 0, &kev, 1, &timeout) == 1)) {
- log_kevent_struct(LOG_DEBUG, &kev, 0);
- (*((kq_callback *)kev.udata))(kev.udata, &kev);
- }
-}
-
-void
-runtime_force_on_demand(bool b)
-{
- launchd_assumes(kevent_mod(asynckq, EVFILT_READ, b ? EV_DISABLE : EV_ENABLE, 0, 0, &kqasync_callback) != -1);
-}
-
boolean_t
launchd_internal_demux(mach_msg_header_t *Request, mach_msg_header_t *Reply)
{
Modified: trunk/launchd/src/launchd_runtime.h
===================================================================
--- trunk/launchd/src/launchd_runtime.h 2007-06-06 16:04:51 UTC (rev 23273)
+++ trunk/launchd/src/launchd_runtime.h 2007-06-07 23:00:50 UTC (rev 23274)
@@ -61,7 +61,6 @@
int runtime_close(int fd);
-void runtime_force_on_demand(bool);
void runtime_set_timeout(timeout_callback to_cb, mach_msg_timeout_t to);
kern_return_t runtime_add_mport(mach_port_t name, mig_callback demux, mach_msg_size_t msg_size);
kern_return_t runtime_remove_mport(mach_port_t name);
Modified: trunk/launchd/src/launchd_unix_ipc.c
===================================================================
--- trunk/launchd/src/launchd_unix_ipc.c 2007-06-06 16:04:51 UTC (rev 23273)
+++ trunk/launchd/src/launchd_unix_ipc.c 2007-06-07 23:00:50 UTC (rev 23274)
@@ -369,9 +369,6 @@
struct rusage rusage;
getrusage(RUSAGE_CHILDREN, &rusage);
resp = launch_data_new_opaque(&rusage, sizeof(rusage));
- } else if (!strcmp(cmd, LAUNCH_KEY_BATCHQUERY)) {
- resp = launch_data_alloc(LAUNCH_DATA_BOOL);
- launch_data_set_bool(resp, batch_disabler_count == 0);
}
} else if (!strcmp(cmd, LAUNCH_KEY_STARTJOB)) {
if ((j = job_find(launch_data_get_string(data))) != NULL) {
@@ -415,9 +412,6 @@
resp = job_export(j);
ipc_revoke_fds(resp);
}
- } else if (!strcmp(cmd, LAUNCH_KEY_BATCHCONTROL)) {
- batch_job_enable(launch_data_get_bool(data), rmc->c);
- resp = launch_data_new_errno(0);
}
rmc->resp = resp;
@@ -426,8 +420,6 @@
void
ipc_close(struct conncb *c)
{
- batch_job_enable(true, c);
-
LIST_REMOVE(c, sle);
launchd_close(c->conn, runtime_close);
free(c);
Modified: trunk/launchd/src/launchd_unix_ipc.h
===================================================================
--- trunk/launchd/src/launchd_unix_ipc.h 2007-06-06 16:04:51 UTC (rev 23273)
+++ trunk/launchd/src/launchd_unix_ipc.h 2007-06-07 23:00:50 UTC (rev 23274)
@@ -31,7 +31,6 @@
LIST_ENTRY(conncb) sle;
launch_t conn;
job_t j;
- int disabled_batch:1, futureflags:31;
};
extern char *sockpath;
Modified: trunk/launchd/src/liblaunch.c
===================================================================
--- trunk/launchd/src/liblaunch.c 2007-06-06 16:04:51 UTC (rev 23273)
+++ trunk/launchd/src/liblaunch.c 2007-06-07 23:00:50 UTC (rev 23274)
@@ -1067,41 +1067,24 @@
return r;
}
-void launchd_batch_enable(bool val)
+void
+launchd_batch_enable(bool b)
{
- launch_data_t resp, tmp, msg;
+ int64_t val = b;
- tmp = launch_data_alloc(LAUNCH_DATA_BOOL);
- launch_data_set_bool(tmp, val);
-
- msg = launch_data_alloc(LAUNCH_DATA_DICTIONARY);
- launch_data_dict_insert(msg, tmp, LAUNCH_KEY_BATCHCONTROL);
-
- resp = launch_msg(msg);
-
- launch_data_free(msg);
-
- if (resp)
- launch_data_free(resp);
+ vproc_swap_integer(NULL, VPROC_GSK_GLOBAL_ON_DEMAND, &val, NULL);
}
-bool launchd_batch_query(void)
+bool
+launchd_batch_query(void)
{
- launch_data_t resp, msg = launch_data_alloc(LAUNCH_DATA_STRING);
- bool rval = true;
+ int64_t val;
- launch_data_set_string(msg, LAUNCH_KEY_BATCHQUERY);
-
- resp = launch_msg(msg);
-
- launch_data_free(msg);
-
- if (resp) {
- if (launch_data_get_type(resp) == LAUNCH_DATA_BOOL)
- rval = launch_data_get_bool(resp);
- launch_data_free(resp);
+ if (vproc_swap_integer(NULL, VPROC_GSK_GLOBAL_ON_DEMAND, NULL, &val) == NULL) {
+ return (bool)val;
}
- return rval;
+
+ return false;
}
static int _fd(int fd)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070607/65bb7a55/attachment.html
More information about the launchd-changes
mailing list