static void lockfile_remove_stale (char *path) { int fd; int pid; char apid[20]; int length; fd = open (path, O_RDONLY); if (fd < 0) return; length = read (fd, apid, sizeof (apid) - 1); if (length < 0) length = 0; apid[length] = 0; pid = 0; if (length == sizeof (pid) || sscanf (apid, "%d", &pid) != 1 || pid == 0) { int *p = (int *)apid; pid = *p; } close (fd); if ((kill (pid, 0) < 0) && (errno == ESRCH)) { surfman_warning ("removing stale lock file %s (no pid %d)\n", path, pid); unlink (path); } }
dbus_bool_t dbus_notify_death (DBusMessage *msg, DBusMessage *reply) { DBusError err; dbus_bool_t ret; int32_t domid, sstate; struct domain *d; dbus_error_init (&err); ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &domid, DBUS_TYPE_INT32, &sstate, DBUS_TYPE_INVALID); if (!ret) { surfman_error ("Error getting message args: %s", err.message); return FALSE; } surfman_info ("notify_death(%d,%d)", domid, sstate); #if 1 surfman_warning ("THIS RPC IS DEPRECATED AND SHOULD NOT BE USED ANY MORE."); #else d = domain_by_domid (domid); if (!d) { surfman_error ("Domain %d not found", domid); return FALSE; } domain_destroy (d); #endif if (reply && ret) dbus_message_append_args (reply, DBUS_TYPE_INVALID); return ret; }