The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <stdio.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <string.h> |
| 20 | #include <unistd.h> |
| 21 | #include <fcntl.h> |
| 22 | #include <ctype.h> |
| 23 | #include <signal.h> |
| 24 | #include <sys/wait.h> |
| 25 | #include <sys/mount.h> |
| 26 | #include <sys/stat.h> |
| 27 | #include <sys/poll.h> |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 28 | #include <errno.h> |
| 29 | #include <stdarg.h> |
| 30 | #include <mtd/mtd-user.h> |
| 31 | #include <sys/types.h> |
| 32 | #include <sys/socket.h> |
| 33 | #include <sys/un.h> |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 34 | |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 35 | #include <selinux/selinux.h> |
| 36 | #include <selinux/label.h> |
Stephen Smalley | ae6f3d7 | 2012-05-01 15:02:53 -0400 | [diff] [blame] | 37 | #include <selinux/android.h> |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 38 | |
Colin Cross | f83d0b9 | 2010-04-21 12:04:20 -0700 | [diff] [blame] | 39 | #include <libgen.h> |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 40 | |
Dima Zavin | da04c52 | 2011-09-01 17:09:44 -0700 | [diff] [blame] | 41 | #include <cutils/list.h> |
Nick Kralevich | 56fa0ac | 2013-06-24 17:41:40 -0700 | [diff] [blame] | 42 | #include <cutils/android_reboot.h> |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 43 | #include <cutils/sockets.h> |
San Mehat | 4e221f0 | 2010-02-25 14:19:50 -0800 | [diff] [blame] | 44 | #include <cutils/iosched_policy.h> |
Colin Cross | f83d0b9 | 2010-04-21 12:04:20 -0700 | [diff] [blame] | 45 | #include <private/android_filesystem_config.h> |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 46 | #include <termios.h> |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 47 | |
| 48 | #include <sys/system_properties.h> |
| 49 | |
| 50 | #include "devices.h" |
| 51 | #include "init.h" |
Colin Cross | ed8a7d8 | 2010-04-19 17:05:34 -0700 | [diff] [blame] | 52 | #include "log.h" |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 53 | #include "property_service.h" |
The Android Open Source Project | 35237d1 | 2008-12-17 18:08:08 -0800 | [diff] [blame] | 54 | #include "bootchart.h" |
Colin Cross | 9c5366b | 2010-04-13 19:48:59 -0700 | [diff] [blame] | 55 | #include "signal_handler.h" |
Colin Cross | a866695 | 2010-04-13 19:20:44 -0700 | [diff] [blame] | 56 | #include "keychords.h" |
Colin Cross | 6310a82 | 2010-04-20 14:29:05 -0700 | [diff] [blame] | 57 | #include "init_parser.h" |
Colin Cross | 3899e9f | 2010-04-13 20:35:46 -0700 | [diff] [blame] | 58 | #include "util.h" |
Colin Cross | f83d0b9 | 2010-04-21 12:04:20 -0700 | [diff] [blame] | 59 | #include "ueventd.h" |
Arve Hjønnevåg | d97d907 | 2012-06-13 21:51:56 -0700 | [diff] [blame] | 60 | #include "watchdogd.h" |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 61 | |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 62 | struct selabel_handle *sehandle; |
rpcraig | 63207cd | 2012-08-09 10:05:49 -0400 | [diff] [blame] | 63 | struct selabel_handle *sehandle_prop; |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 64 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 65 | static int property_triggers_enabled = 0; |
| 66 | |
| 67 | #if BOOTCHART |
| 68 | static int bootchart_count; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 69 | #endif |
| 70 | |
| 71 | static char console[32]; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 72 | static char bootmode[32]; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 73 | static char hardware[32]; |
| 74 | static unsigned revision = 0; |
| 75 | static char qemu[32]; |
| 76 | |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 77 | static struct action *cur_action = NULL; |
| 78 | static struct command *cur_command = NULL; |
| 79 | static struct listnode *command_queue = NULL; |
| 80 | |
Colin Cross | 9c5366b | 2010-04-13 19:48:59 -0700 | [diff] [blame] | 81 | void notify_service_state(const char *name, const char *state) |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 82 | { |
| 83 | char pname[PROP_NAME_MAX]; |
| 84 | int len = strlen(name); |
| 85 | if ((len + 10) > PROP_NAME_MAX) |
| 86 | return; |
| 87 | snprintf(pname, sizeof(pname), "init.svc.%s", name); |
| 88 | property_set(pname, state); |
| 89 | } |
| 90 | |
| 91 | static int have_console; |
Hong-Mei Li | 1146718 | 2013-04-01 11:17:51 +0800 | [diff] [blame] | 92 | static char console_name[PROP_VALUE_MAX] = "/dev/console"; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 93 | static time_t process_needs_restart; |
| 94 | |
| 95 | static const char *ENV[32]; |
| 96 | |
| 97 | /* add_environment - add "key=value" to the current environment */ |
| 98 | int add_environment(const char *key, const char *val) |
| 99 | { |
| 100 | int n; |
Vladimir Chtchetkine | 2b99543 | 2011-09-28 09:55:31 -0700 | [diff] [blame] | 101 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 102 | for (n = 0; n < 31; n++) { |
| 103 | if (!ENV[n]) { |
| 104 | size_t len = strlen(key) + strlen(val) + 2; |
| 105 | char *entry = malloc(len); |
| 106 | snprintf(entry, len, "%s=%s", key, val); |
| 107 | ENV[n] = entry; |
| 108 | return 0; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | return 1; |
| 113 | } |
| 114 | |
| 115 | static void zap_stdio(void) |
| 116 | { |
| 117 | int fd; |
| 118 | fd = open("/dev/null", O_RDWR); |
| 119 | dup2(fd, 0); |
| 120 | dup2(fd, 1); |
| 121 | dup2(fd, 2); |
| 122 | close(fd); |
| 123 | } |
| 124 | |
| 125 | static void open_console() |
| 126 | { |
| 127 | int fd; |
| 128 | if ((fd = open(console_name, O_RDWR)) < 0) { |
| 129 | fd = open("/dev/null", O_RDWR); |
| 130 | } |
Colin Cross | 50fb5a6 | 2012-03-18 15:38:19 -0700 | [diff] [blame] | 131 | ioctl(fd, TIOCSCTTY, 0); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 132 | dup2(fd, 0); |
| 133 | dup2(fd, 1); |
| 134 | dup2(fd, 2); |
| 135 | close(fd); |
| 136 | } |
| 137 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 138 | static void publish_socket(const char *name, int fd) |
| 139 | { |
| 140 | char key[64] = ANDROID_SOCKET_ENV_PREFIX; |
| 141 | char val[64]; |
| 142 | |
| 143 | strlcpy(key + sizeof(ANDROID_SOCKET_ENV_PREFIX) - 1, |
| 144 | name, |
| 145 | sizeof(key) - sizeof(ANDROID_SOCKET_ENV_PREFIX)); |
| 146 | snprintf(val, sizeof(val), "%d", fd); |
| 147 | add_environment(key, val); |
| 148 | |
| 149 | /* make sure we don't close-on-exec */ |
| 150 | fcntl(fd, F_SETFD, 0); |
| 151 | } |
| 152 | |
San Mehat | f24e252 | 2009-05-19 13:30:46 -0700 | [diff] [blame] | 153 | void service_start(struct service *svc, const char *dynamic_args) |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 154 | { |
| 155 | struct stat s; |
| 156 | pid_t pid; |
| 157 | int needs_console; |
| 158 | int n; |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 159 | char *scon = NULL; |
| 160 | int rc; |
Kenny Root | b5982bf | 2012-10-16 23:07:05 -0700 | [diff] [blame] | 161 | |
Ken Sumrall | 752923c | 2010-12-03 16:33:31 -0800 | [diff] [blame] | 162 | /* starting a service removes it from the disabled or reset |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 163 | * state and immediately takes it out of the restarting |
| 164 | * state if it was in there |
| 165 | */ |
Mike Kasick | b54f39f | 2012-01-25 23:48:46 -0500 | [diff] [blame] | 166 | svc->flags &= (~(SVC_DISABLED|SVC_RESTARTING|SVC_RESET|SVC_RESTART)); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 167 | svc->time_started = 0; |
Vladimir Chtchetkine | 2b99543 | 2011-09-28 09:55:31 -0700 | [diff] [blame] | 168 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 169 | /* running processes require no additional work -- if |
| 170 | * they're in the process of exiting, we've ensured |
| 171 | * that they will immediately restart on exit, unless |
| 172 | * they are ONESHOT |
| 173 | */ |
| 174 | if (svc->flags & SVC_RUNNING) { |
| 175 | return; |
| 176 | } |
| 177 | |
| 178 | needs_console = (svc->flags & SVC_CONSOLE) ? 1 : 0; |
| 179 | if (needs_console && (!have_console)) { |
| 180 | ERROR("service '%s' requires console\n", svc->name); |
| 181 | svc->flags |= SVC_DISABLED; |
| 182 | return; |
| 183 | } |
| 184 | |
| 185 | if (stat(svc->args[0], &s) != 0) { |
| 186 | ERROR("cannot find '%s', disabling '%s'\n", svc->args[0], svc->name); |
| 187 | svc->flags |= SVC_DISABLED; |
| 188 | return; |
| 189 | } |
| 190 | |
San Mehat | f24e252 | 2009-05-19 13:30:46 -0700 | [diff] [blame] | 191 | if ((!(svc->flags & SVC_ONESHOT)) && dynamic_args) { |
San Mehat | d4cdd13 | 2009-05-20 09:52:16 -0700 | [diff] [blame] | 192 | ERROR("service '%s' must be one-shot to use dynamic args, disabling\n", |
| 193 | svc->args[0]); |
San Mehat | f24e252 | 2009-05-19 13:30:46 -0700 | [diff] [blame] | 194 | svc->flags |= SVC_DISABLED; |
| 195 | return; |
| 196 | } |
| 197 | |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 198 | if (is_selinux_enabled() > 0) { |
Stephen Smalley | 30f3033 | 2012-11-16 14:34:27 -0500 | [diff] [blame] | 199 | if (svc->seclabel) { |
| 200 | scon = strdup(svc->seclabel); |
| 201 | if (!scon) { |
| 202 | ERROR("Out of memory while starting '%s'\n", svc->name); |
| 203 | return; |
| 204 | } |
| 205 | } else { |
| 206 | char *mycon = NULL, *fcon = NULL; |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 207 | |
Stephen Smalley | 30f3033 | 2012-11-16 14:34:27 -0500 | [diff] [blame] | 208 | INFO("computing context for service '%s'\n", svc->args[0]); |
| 209 | rc = getcon(&mycon); |
| 210 | if (rc < 0) { |
| 211 | ERROR("could not get context while starting '%s'\n", svc->name); |
| 212 | return; |
| 213 | } |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 214 | |
Stephen Smalley | 30f3033 | 2012-11-16 14:34:27 -0500 | [diff] [blame] | 215 | rc = getfilecon(svc->args[0], &fcon); |
| 216 | if (rc < 0) { |
| 217 | ERROR("could not get context while starting '%s'\n", svc->name); |
| 218 | freecon(mycon); |
| 219 | return; |
| 220 | } |
| 221 | |
| 222 | rc = security_compute_create(mycon, fcon, string_to_security_class("process"), &scon); |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 223 | freecon(mycon); |
Stephen Smalley | 30f3033 | 2012-11-16 14:34:27 -0500 | [diff] [blame] | 224 | freecon(fcon); |
| 225 | if (rc < 0) { |
| 226 | ERROR("could not get context while starting '%s'\n", svc->name); |
| 227 | return; |
| 228 | } |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 229 | } |
| 230 | } |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 231 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 232 | NOTICE("starting '%s'\n", svc->name); |
| 233 | |
| 234 | pid = fork(); |
| 235 | |
| 236 | if (pid == 0) { |
| 237 | struct socketinfo *si; |
| 238 | struct svcenvinfo *ei; |
| 239 | char tmp[32]; |
| 240 | int fd, sz; |
| 241 | |
Nick Kralevich | 6ebf12f | 2012-03-26 09:09:11 -0700 | [diff] [blame] | 242 | umask(077); |
Colin Cross | 3294bbb | 2010-04-19 17:11:33 -0700 | [diff] [blame] | 243 | if (properties_inited()) { |
| 244 | get_property_workspace(&fd, &sz); |
| 245 | sprintf(tmp, "%d,%d", dup(fd), sz); |
| 246 | add_environment("ANDROID_PROPERTY_WORKSPACE", tmp); |
| 247 | } |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 248 | |
| 249 | for (ei = svc->envvars; ei; ei = ei->next) |
| 250 | add_environment(ei->name, ei->value); |
| 251 | |
| 252 | for (si = svc->sockets; si; si = si->next) { |
Mike Lockwood | 912ff85 | 2010-10-01 08:20:36 -0400 | [diff] [blame] | 253 | int socket_type = ( |
| 254 | !strcmp(si->type, "stream") ? SOCK_STREAM : |
| 255 | (!strcmp(si->type, "dgram") ? SOCK_DGRAM : SOCK_SEQPACKET)); |
| 256 | int s = create_socket(si->name, socket_type, |
Stephen Smalley | 8348d27 | 2013-05-13 12:37:04 -0400 | [diff] [blame] | 257 | si->perm, si->uid, si->gid, si->socketcon ?: scon); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 258 | if (s >= 0) { |
| 259 | publish_socket(si->name, s); |
| 260 | } |
| 261 | } |
| 262 | |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 263 | freecon(scon); |
| 264 | scon = NULL; |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 265 | |
San Mehat | 4e221f0 | 2010-02-25 14:19:50 -0800 | [diff] [blame] | 266 | if (svc->ioprio_class != IoSchedClass_NONE) { |
| 267 | if (android_set_ioprio(getpid(), svc->ioprio_class, svc->ioprio_pri)) { |
| 268 | ERROR("Failed to set pid %d ioprio = %d,%d: %s\n", |
| 269 | getpid(), svc->ioprio_class, svc->ioprio_pri, strerror(errno)); |
| 270 | } |
| 271 | } |
| 272 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 273 | if (needs_console) { |
| 274 | setsid(); |
| 275 | open_console(); |
| 276 | } else { |
| 277 | zap_stdio(); |
| 278 | } |
| 279 | |
| 280 | #if 0 |
| 281 | for (n = 0; svc->args[n]; n++) { |
| 282 | INFO("args[%d] = '%s'\n", n, svc->args[n]); |
| 283 | } |
| 284 | for (n = 0; ENV[n]; n++) { |
| 285 | INFO("env[%d] = '%s'\n", n, ENV[n]); |
| 286 | } |
| 287 | #endif |
| 288 | |
| 289 | setpgid(0, getpid()); |
| 290 | |
The Android Open Source Project | 5ae090e | 2009-01-09 17:51:25 -0800 | [diff] [blame] | 291 | /* as requested, set our gid, supplemental gids, and uid */ |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 292 | if (svc->gid) { |
Nick Kralevich | 2268718 | 2010-11-17 16:55:42 -0800 | [diff] [blame] | 293 | if (setgid(svc->gid) != 0) { |
| 294 | ERROR("setgid failed: %s\n", strerror(errno)); |
| 295 | _exit(127); |
| 296 | } |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 297 | } |
| 298 | if (svc->nr_supp_gids) { |
Nick Kralevich | 2268718 | 2010-11-17 16:55:42 -0800 | [diff] [blame] | 299 | if (setgroups(svc->nr_supp_gids, svc->supp_gids) != 0) { |
| 300 | ERROR("setgroups failed: %s\n", strerror(errno)); |
| 301 | _exit(127); |
| 302 | } |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 303 | } |
| 304 | if (svc->uid) { |
Nick Kralevich | 2268718 | 2010-11-17 16:55:42 -0800 | [diff] [blame] | 305 | if (setuid(svc->uid) != 0) { |
| 306 | ERROR("setuid failed: %s\n", strerror(errno)); |
| 307 | _exit(127); |
| 308 | } |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 309 | } |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 310 | if (svc->seclabel) { |
| 311 | if (is_selinux_enabled() > 0 && setexeccon(svc->seclabel) < 0) { |
| 312 | ERROR("cannot setexeccon('%s'): %s\n", svc->seclabel, strerror(errno)); |
| 313 | _exit(127); |
| 314 | } |
| 315 | } |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 316 | |
San Mehat | 8ad1568 | 2009-05-20 08:50:40 -0700 | [diff] [blame] | 317 | if (!dynamic_args) { |
| 318 | if (execve(svc->args[0], (char**) svc->args, (char**) ENV) < 0) { |
| 319 | ERROR("cannot execve('%s'): %s\n", svc->args[0], strerror(errno)); |
| 320 | } |
| 321 | } else { |
Colin Cross | 6310a82 | 2010-04-20 14:29:05 -0700 | [diff] [blame] | 322 | char *arg_ptrs[INIT_PARSER_MAXARGS+1]; |
San Mehat | d4cdd13 | 2009-05-20 09:52:16 -0700 | [diff] [blame] | 323 | int arg_idx = svc->nargs; |
San Mehat | f24e252 | 2009-05-19 13:30:46 -0700 | [diff] [blame] | 324 | char *tmp = strdup(dynamic_args); |
San Mehat | d4cdd13 | 2009-05-20 09:52:16 -0700 | [diff] [blame] | 325 | char *next = tmp; |
| 326 | char *bword; |
San Mehat | f24e252 | 2009-05-19 13:30:46 -0700 | [diff] [blame] | 327 | |
| 328 | /* Copy the static arguments */ |
San Mehat | d4cdd13 | 2009-05-20 09:52:16 -0700 | [diff] [blame] | 329 | memcpy(arg_ptrs, svc->args, (svc->nargs * sizeof(char *))); |
San Mehat | f24e252 | 2009-05-19 13:30:46 -0700 | [diff] [blame] | 330 | |
San Mehat | d4cdd13 | 2009-05-20 09:52:16 -0700 | [diff] [blame] | 331 | while((bword = strsep(&next, " "))) { |
| 332 | arg_ptrs[arg_idx++] = bword; |
Colin Cross | 6310a82 | 2010-04-20 14:29:05 -0700 | [diff] [blame] | 333 | if (arg_idx == INIT_PARSER_MAXARGS) |
San Mehat | f24e252 | 2009-05-19 13:30:46 -0700 | [diff] [blame] | 334 | break; |
San Mehat | f24e252 | 2009-05-19 13:30:46 -0700 | [diff] [blame] | 335 | } |
| 336 | arg_ptrs[arg_idx] = '\0'; |
| 337 | execve(svc->args[0], (char**) arg_ptrs, (char**) ENV); |
Ivan Djelic | 165de92 | 2008-11-23 22:26:39 +0100 | [diff] [blame] | 338 | } |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 339 | _exit(127); |
| 340 | } |
| 341 | |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 342 | freecon(scon); |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 343 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 344 | if (pid < 0) { |
| 345 | ERROR("failed to start '%s'\n", svc->name); |
| 346 | svc->pid = 0; |
| 347 | return; |
| 348 | } |
| 349 | |
| 350 | svc->time_started = gettime(); |
| 351 | svc->pid = pid; |
| 352 | svc->flags |= SVC_RUNNING; |
| 353 | |
Colin Cross | 3294bbb | 2010-04-19 17:11:33 -0700 | [diff] [blame] | 354 | if (properties_inited()) |
| 355 | notify_service_state(svc->name, "running"); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Mike Kasick | b54f39f | 2012-01-25 23:48:46 -0500 | [diff] [blame] | 358 | /* The how field should be either SVC_DISABLED, SVC_RESET, or SVC_RESTART */ |
Ken Sumrall | 752923c | 2010-12-03 16:33:31 -0800 | [diff] [blame] | 359 | static void service_stop_or_reset(struct service *svc, int how) |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 360 | { |
Mike Kasick | 7e36edd | 2012-02-06 10:32:13 -0500 | [diff] [blame] | 361 | /* The service is still SVC_RUNNING until its process exits, but if it has |
| 362 | * already exited it shoudn't attempt a restart yet. */ |
| 363 | svc->flags &= (~SVC_RESTARTING); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 364 | |
Mike Kasick | b54f39f | 2012-01-25 23:48:46 -0500 | [diff] [blame] | 365 | if ((how != SVC_DISABLED) && (how != SVC_RESET) && (how != SVC_RESTART)) { |
Ken Sumrall | 752923c | 2010-12-03 16:33:31 -0800 | [diff] [blame] | 366 | /* Hrm, an illegal flag. Default to SVC_DISABLED */ |
| 367 | how = SVC_DISABLED; |
| 368 | } |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 369 | /* if the service has not yet started, prevent |
| 370 | * it from auto-starting with its class |
| 371 | */ |
Ken Sumrall | a286480 | 2011-10-26 16:56:00 -0700 | [diff] [blame] | 372 | if (how == SVC_RESET) { |
| 373 | svc->flags |= (svc->flags & SVC_RC_DISABLED) ? SVC_DISABLED : SVC_RESET; |
| 374 | } else { |
| 375 | svc->flags |= how; |
| 376 | } |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 377 | |
| 378 | if (svc->pid) { |
| 379 | NOTICE("service '%s' is being killed\n", svc->name); |
Ken Sumrall | 752923c | 2010-12-03 16:33:31 -0800 | [diff] [blame] | 380 | kill(-svc->pid, SIGKILL); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 381 | notify_service_state(svc->name, "stopping"); |
| 382 | } else { |
| 383 | notify_service_state(svc->name, "stopped"); |
| 384 | } |
| 385 | } |
| 386 | |
Ken Sumrall | 752923c | 2010-12-03 16:33:31 -0800 | [diff] [blame] | 387 | void service_reset(struct service *svc) |
| 388 | { |
| 389 | service_stop_or_reset(svc, SVC_RESET); |
| 390 | } |
| 391 | |
| 392 | void service_stop(struct service *svc) |
| 393 | { |
| 394 | service_stop_or_reset(svc, SVC_DISABLED); |
| 395 | } |
| 396 | |
Mike Kasick | b54f39f | 2012-01-25 23:48:46 -0500 | [diff] [blame] | 397 | void service_restart(struct service *svc) |
| 398 | { |
| 399 | if (svc->flags & SVC_RUNNING) { |
| 400 | /* Stop, wait, then start the service. */ |
| 401 | service_stop_or_reset(svc, SVC_RESTART); |
| 402 | } else if (!(svc->flags & SVC_RESTARTING)) { |
| 403 | /* Just start the service since it's not running. */ |
| 404 | service_start(svc, NULL); |
| 405 | } /* else: Service is restarting anyways. */ |
| 406 | } |
| 407 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 408 | void property_changed(const char *name, const char *value) |
| 409 | { |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 410 | if (property_triggers_enabled) |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 411 | queue_property_triggers(name, value); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 412 | } |
| 413 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 414 | static void restart_service_if_needed(struct service *svc) |
| 415 | { |
| 416 | time_t next_start_time = svc->time_started + 5; |
| 417 | |
| 418 | if (next_start_time <= gettime()) { |
| 419 | svc->flags &= (~SVC_RESTARTING); |
San Mehat | f24e252 | 2009-05-19 13:30:46 -0700 | [diff] [blame] | 420 | service_start(svc, NULL); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 421 | return; |
| 422 | } |
| 423 | |
| 424 | if ((next_start_time < process_needs_restart) || |
| 425 | (process_needs_restart == 0)) { |
| 426 | process_needs_restart = next_start_time; |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | static void restart_processes() |
| 431 | { |
| 432 | process_needs_restart = 0; |
| 433 | service_for_each_flags(SVC_RESTARTING, |
| 434 | restart_service_if_needed); |
| 435 | } |
| 436 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 437 | static void msg_start(const char *name) |
| 438 | { |
Hong-Mei Li | 1146718 | 2013-04-01 11:17:51 +0800 | [diff] [blame] | 439 | struct service *svc = NULL; |
San Mehat | f24e252 | 2009-05-19 13:30:46 -0700 | [diff] [blame] | 440 | char *tmp = NULL; |
| 441 | char *args = NULL; |
| 442 | |
| 443 | if (!strchr(name, ':')) |
| 444 | svc = service_find_by_name(name); |
| 445 | else { |
| 446 | tmp = strdup(name); |
Hong-Mei Li | 1146718 | 2013-04-01 11:17:51 +0800 | [diff] [blame] | 447 | if (tmp) { |
| 448 | args = strchr(tmp, ':'); |
| 449 | *args = '\0'; |
| 450 | args++; |
San Mehat | f24e252 | 2009-05-19 13:30:46 -0700 | [diff] [blame] | 451 | |
Hong-Mei Li | 1146718 | 2013-04-01 11:17:51 +0800 | [diff] [blame] | 452 | svc = service_find_by_name(tmp); |
| 453 | } |
San Mehat | f24e252 | 2009-05-19 13:30:46 -0700 | [diff] [blame] | 454 | } |
Vladimir Chtchetkine | 2b99543 | 2011-09-28 09:55:31 -0700 | [diff] [blame] | 455 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 456 | if (svc) { |
San Mehat | f24e252 | 2009-05-19 13:30:46 -0700 | [diff] [blame] | 457 | service_start(svc, args); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 458 | } else { |
| 459 | ERROR("no such service '%s'\n", name); |
| 460 | } |
San Mehat | f24e252 | 2009-05-19 13:30:46 -0700 | [diff] [blame] | 461 | if (tmp) |
| 462 | free(tmp); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | static void msg_stop(const char *name) |
| 466 | { |
| 467 | struct service *svc = service_find_by_name(name); |
| 468 | |
| 469 | if (svc) { |
| 470 | service_stop(svc); |
| 471 | } else { |
Dima Zavin | 770354d | 2009-05-05 18:33:07 -0700 | [diff] [blame] | 472 | ERROR("no such service '%s'\n", name); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 473 | } |
| 474 | } |
| 475 | |
Mike Kasick | b54f39f | 2012-01-25 23:48:46 -0500 | [diff] [blame] | 476 | static void msg_restart(const char *name) |
| 477 | { |
| 478 | struct service *svc = service_find_by_name(name); |
| 479 | |
| 480 | if (svc) { |
| 481 | service_restart(svc); |
| 482 | } else { |
| 483 | ERROR("no such service '%s'\n", name); |
| 484 | } |
| 485 | } |
| 486 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 487 | void handle_control_message(const char *msg, const char *arg) |
| 488 | { |
| 489 | if (!strcmp(msg,"start")) { |
| 490 | msg_start(arg); |
| 491 | } else if (!strcmp(msg,"stop")) { |
| 492 | msg_stop(arg); |
Wink Saville | cfa0d84 | 2010-10-03 13:30:11 -0700 | [diff] [blame] | 493 | } else if (!strcmp(msg,"restart")) { |
Mike Kasick | b54f39f | 2012-01-25 23:48:46 -0500 | [diff] [blame] | 494 | msg_restart(arg); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 495 | } else { |
| 496 | ERROR("unknown control msg '%s'\n", msg); |
| 497 | } |
| 498 | } |
| 499 | |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 500 | static struct command *get_first_command(struct action *act) |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 501 | { |
| 502 | struct listnode *node; |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 503 | node = list_head(&act->commands); |
Dima Zavin | 3bea079 | 2011-08-26 13:59:18 -0700 | [diff] [blame] | 504 | if (!node || list_empty(&act->commands)) |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 505 | return NULL; |
| 506 | |
| 507 | return node_to_item(node, struct command, clist); |
| 508 | } |
| 509 | |
| 510 | static struct command *get_next_command(struct action *act, struct command *cmd) |
| 511 | { |
| 512 | struct listnode *node; |
| 513 | node = cmd->clist.next; |
| 514 | if (!node) |
| 515 | return NULL; |
| 516 | if (node == &act->commands) |
| 517 | return NULL; |
| 518 | |
| 519 | return node_to_item(node, struct command, clist); |
| 520 | } |
| 521 | |
| 522 | static int is_last_command(struct action *act, struct command *cmd) |
| 523 | { |
| 524 | return (list_tail(&act->commands) == &cmd->clist); |
| 525 | } |
| 526 | |
| 527 | void execute_one_command(void) |
| 528 | { |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 529 | int ret; |
| 530 | |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 531 | if (!cur_action || !cur_command || is_last_command(cur_action, cur_command)) { |
| 532 | cur_action = action_remove_queue_head(); |
Colin Cross | ebd4613 | 2010-04-22 11:52:23 -0700 | [diff] [blame] | 533 | cur_command = NULL; |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 534 | if (!cur_action) |
| 535 | return; |
| 536 | INFO("processing action %p (%s)\n", cur_action, cur_action->name); |
| 537 | cur_command = get_first_command(cur_action); |
| 538 | } else { |
| 539 | cur_command = get_next_command(cur_action, cur_command); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 540 | } |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 541 | |
| 542 | if (!cur_command) |
| 543 | return; |
| 544 | |
| 545 | ret = cur_command->func(cur_command->nargs, cur_command->args); |
| 546 | INFO("command '%s' r=%d\n", cur_command->args[0], ret); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 547 | } |
| 548 | |
Colin Cross | f83d0b9 | 2010-04-21 12:04:20 -0700 | [diff] [blame] | 549 | static int wait_for_coldboot_done_action(int nargs, char **args) |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 550 | { |
Colin Cross | f83d0b9 | 2010-04-21 12:04:20 -0700 | [diff] [blame] | 551 | int ret; |
| 552 | INFO("wait for %s\n", coldboot_done); |
| 553 | ret = wait_for_file(coldboot_done, COMMAND_RETRY_TIMEOUT); |
| 554 | if (ret) |
| 555 | ERROR("Timed out waiting for %s\n", coldboot_done); |
| 556 | return ret; |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 557 | } |
| 558 | |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 559 | static int keychord_init_action(int nargs, char **args) |
| 560 | { |
| 561 | keychord_init(); |
| 562 | return 0; |
| 563 | } |
| 564 | |
| 565 | static int console_init_action(int nargs, char **args) |
| 566 | { |
| 567 | int fd; |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 568 | |
| 569 | if (console[0]) { |
Hong-Mei Li | 1146718 | 2013-04-01 11:17:51 +0800 | [diff] [blame] | 570 | snprintf(console_name, sizeof(console_name), "/dev/%s", console); |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | fd = open(console_name, O_RDWR); |
| 574 | if (fd >= 0) |
| 575 | have_console = 1; |
| 576 | close(fd); |
| 577 | |
Marcin Chojnacki | 50dc936 | 2013-10-16 17:39:16 +0200 | [diff] [blame] | 578 | fd = open("/dev/tty0", O_WRONLY); |
| 579 | if (fd >= 0) { |
| 580 | const char *msg; |
| 581 | msg = "\n" |
| 582 | "\n" |
| 583 | "\n" |
| 584 | "\n" |
| 585 | "\n" |
| 586 | "\n" |
| 587 | "\n" // console is 40 cols x 30 lines |
| 588 | "\n" |
| 589 | "\n" |
| 590 | "\n" |
| 591 | "\n" |
| 592 | "\n" |
| 593 | "\n" |
| 594 | "\n" |
| 595 | " A N D R O I D "; |
| 596 | write(fd, msg, strlen(msg)); |
| 597 | close(fd); |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 598 | } |
Marcin Chojnacki | 50dc936 | 2013-10-16 17:39:16 +0200 | [diff] [blame] | 599 | |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 600 | return 0; |
| 601 | } |
| 602 | |
Dima Zavin | 5511c84 | 2011-12-19 11:21:32 -0800 | [diff] [blame] | 603 | static void import_kernel_nv(char *name, int for_emulator) |
| 604 | { |
| 605 | char *value = strchr(name, '='); |
| 606 | int name_len = strlen(name); |
| 607 | |
| 608 | if (value == 0) return; |
| 609 | *value++ = 0; |
| 610 | if (name_len == 0) return; |
| 611 | |
| 612 | if (for_emulator) { |
| 613 | /* in the emulator, export any kernel option with the |
| 614 | * ro.kernel. prefix */ |
| 615 | char buff[PROP_NAME_MAX]; |
| 616 | int len = snprintf( buff, sizeof(buff), "ro.kernel.%s", name ); |
| 617 | |
| 618 | if (len < (int)sizeof(buff)) |
| 619 | property_set( buff, value ); |
| 620 | return; |
| 621 | } |
| 622 | |
| 623 | if (!strcmp(name,"qemu")) { |
| 624 | strlcpy(qemu, value, sizeof(qemu)); |
| 625 | } else if (!strncmp(name, "androidboot.", 12) && name_len > 12) { |
| 626 | const char *boot_prop_name = name + 12; |
| 627 | char prop[PROP_NAME_MAX]; |
| 628 | int cnt; |
| 629 | |
| 630 | cnt = snprintf(prop, sizeof(prop), "ro.boot.%s", boot_prop_name); |
| 631 | if (cnt < PROP_NAME_MAX) |
| 632 | property_set(prop, value); |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | static void export_kernel_boot_props(void) |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 637 | { |
| 638 | char tmp[PROP_VALUE_MAX]; |
Colin Cross | 1a6f4c3 | 2013-01-28 17:13:35 -0800 | [diff] [blame] | 639 | int ret; |
Dima Zavin | 5511c84 | 2011-12-19 11:21:32 -0800 | [diff] [blame] | 640 | unsigned i; |
| 641 | struct { |
| 642 | const char *src_prop; |
| 643 | const char *dest_prop; |
| 644 | const char *def_val; |
| 645 | } prop_map[] = { |
| 646 | { "ro.boot.serialno", "ro.serialno", "", }, |
| 647 | { "ro.boot.mode", "ro.bootmode", "unknown", }, |
| 648 | { "ro.boot.baseband", "ro.baseband", "unknown", }, |
Dima Zavin | 5511c84 | 2011-12-19 11:21:32 -0800 | [diff] [blame] | 649 | { "ro.boot.bootloader", "ro.bootloader", "unknown", }, |
| 650 | }; |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 651 | |
Dima Zavin | 5511c84 | 2011-12-19 11:21:32 -0800 | [diff] [blame] | 652 | for (i = 0; i < ARRAY_SIZE(prop_map); i++) { |
Colin Cross | 1a6f4c3 | 2013-01-28 17:13:35 -0800 | [diff] [blame] | 653 | ret = property_get(prop_map[i].src_prop, tmp); |
Colin Cross | 5e484e9 | 2013-06-17 16:20:08 -0700 | [diff] [blame] | 654 | if (ret > 0) |
| 655 | property_set(prop_map[i].dest_prop, tmp); |
| 656 | else |
Colin Cross | 1a6f4c3 | 2013-01-28 17:13:35 -0800 | [diff] [blame] | 657 | property_set(prop_map[i].dest_prop, prop_map[i].def_val); |
Dima Zavin | 5511c84 | 2011-12-19 11:21:32 -0800 | [diff] [blame] | 658 | } |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 659 | |
Colin Cross | 1a6f4c3 | 2013-01-28 17:13:35 -0800 | [diff] [blame] | 660 | ret = property_get("ro.boot.console", tmp); |
| 661 | if (ret) |
| 662 | strlcpy(console, tmp, sizeof(console)); |
Dima Zavin | 5511c84 | 2011-12-19 11:21:32 -0800 | [diff] [blame] | 663 | |
| 664 | /* save a copy for init's usage during boot */ |
Colin Cross | 1a6f4c3 | 2013-01-28 17:13:35 -0800 | [diff] [blame] | 665 | property_get("ro.bootmode", tmp); |
| 666 | strlcpy(bootmode, tmp, sizeof(bootmode)); |
Dima Zavin | 5511c84 | 2011-12-19 11:21:32 -0800 | [diff] [blame] | 667 | |
| 668 | /* if this was given on kernel command line, override what we read |
| 669 | * before (e.g. from /proc/cpuinfo), if anything */ |
Colin Cross | 1a6f4c3 | 2013-01-28 17:13:35 -0800 | [diff] [blame] | 670 | ret = property_get("ro.boot.hardware", tmp); |
| 671 | if (ret) |
| 672 | strlcpy(hardware, tmp, sizeof(hardware)); |
Dima Zavin | 5511c84 | 2011-12-19 11:21:32 -0800 | [diff] [blame] | 673 | property_set("ro.hardware", hardware); |
| 674 | |
| 675 | snprintf(tmp, PROP_VALUE_MAX, "%d", revision); |
| 676 | property_set("ro.revision", tmp); |
| 677 | |
| 678 | /* TODO: these are obsolete. We should delete them */ |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 679 | if (!strcmp(bootmode,"factory")) |
| 680 | property_set("ro.factorytest", "1"); |
| 681 | else if (!strcmp(bootmode,"factory2")) |
| 682 | property_set("ro.factorytest", "2"); |
| 683 | else |
| 684 | property_set("ro.factorytest", "0"); |
Dima Zavin | 5511c84 | 2011-12-19 11:21:32 -0800 | [diff] [blame] | 685 | } |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 686 | |
Dima Zavin | 5511c84 | 2011-12-19 11:21:32 -0800 | [diff] [blame] | 687 | static void process_kernel_cmdline(void) |
| 688 | { |
| 689 | /* don't expose the raw commandline to nonpriv processes */ |
| 690 | chmod("/proc/cmdline", 0440); |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 691 | |
Dima Zavin | 5511c84 | 2011-12-19 11:21:32 -0800 | [diff] [blame] | 692 | /* first pass does the common stuff, and finds if we are in qemu. |
| 693 | * second pass is only necessary for qemu to export all kernel params |
| 694 | * as props. |
| 695 | */ |
| 696 | import_kernel_cmdline(0, import_kernel_nv); |
| 697 | if (qemu[0]) |
| 698 | import_kernel_cmdline(1, import_kernel_nv); |
| 699 | |
| 700 | /* now propogate the info given on command line to internal variables |
| 701 | * used by init as well as the current required properties |
| 702 | */ |
| 703 | export_kernel_boot_props(); |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | static int property_service_init_action(int nargs, char **args) |
| 707 | { |
| 708 | /* read any property files on system or data and |
| 709 | * fire up the property service. This must happen |
| 710 | * after the ro.foo properties are set above so |
| 711 | * that /data/local.prop cannot interfere with them. |
| 712 | */ |
| 713 | start_property_service(); |
| 714 | return 0; |
| 715 | } |
| 716 | |
| 717 | static int signal_init_action(int nargs, char **args) |
| 718 | { |
| 719 | signal_init(); |
| 720 | return 0; |
| 721 | } |
| 722 | |
| 723 | static int check_startup_action(int nargs, char **args) |
| 724 | { |
| 725 | /* make sure we actually have all the pieces we need */ |
Colin Cross | f83d0b9 | 2010-04-21 12:04:20 -0700 | [diff] [blame] | 726 | if ((get_property_set_fd() < 0) || |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 727 | (get_signal_fd() < 0)) { |
| 728 | ERROR("init startup failure\n"); |
| 729 | exit(1); |
| 730 | } |
Brian Swetland | 8d48c8e | 2011-03-24 15:45:30 -0700 | [diff] [blame] | 731 | |
| 732 | /* signal that we hit this point */ |
| 733 | unlink("/dev/.booting"); |
| 734 | |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 735 | return 0; |
| 736 | } |
| 737 | |
| 738 | static int queue_property_triggers_action(int nargs, char **args) |
| 739 | { |
| 740 | queue_all_property_triggers(); |
| 741 | /* enable property triggers */ |
| 742 | property_triggers_enabled = 1; |
| 743 | return 0; |
| 744 | } |
| 745 | |
| 746 | #if BOOTCHART |
| 747 | static int bootchart_init_action(int nargs, char **args) |
| 748 | { |
| 749 | bootchart_count = bootchart_init(); |
| 750 | if (bootchart_count < 0) { |
| 751 | ERROR("bootcharting init failure\n"); |
| 752 | } else if (bootchart_count > 0) { |
| 753 | NOTICE("bootcharting started (period=%d ms)\n", bootchart_count*BOOTCHART_POLLING_MS); |
| 754 | } else { |
| 755 | NOTICE("bootcharting ignored\n"); |
| 756 | } |
Carl-Emil Lagerstedt | 9ab8190 | 2011-01-14 09:35:30 +0100 | [diff] [blame] | 757 | |
| 758 | return 0; |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 759 | } |
| 760 | #endif |
| 761 | |
rpcraig | 63207cd | 2012-08-09 10:05:49 -0400 | [diff] [blame] | 762 | static const struct selinux_opt seopts_prop[] = { |
repo sync | 49be240 | 2013-05-17 12:48:34 -0700 | [diff] [blame] | 763 | { SELABEL_OPT_PATH, "/data/security/property_contexts" }, |
rpcraig | 63207cd | 2012-08-09 10:05:49 -0400 | [diff] [blame] | 764 | { SELABEL_OPT_PATH, "/property_contexts" }, |
| 765 | { 0, NULL } |
| 766 | }; |
| 767 | |
| 768 | struct selabel_handle* selinux_android_prop_context_handle(void) |
| 769 | { |
| 770 | int i = 0; |
| 771 | struct selabel_handle* sehandle = NULL; |
| 772 | while ((sehandle == NULL) && seopts_prop[i].value) { |
| 773 | sehandle = selabel_open(SELABEL_CTX_ANDROID_PROP, &seopts_prop[i], 1); |
| 774 | i++; |
| 775 | } |
| 776 | |
| 777 | if (!sehandle) { |
| 778 | ERROR("SELinux: Could not load property_contexts: %s\n", |
| 779 | strerror(errno)); |
| 780 | return NULL; |
| 781 | } |
| 782 | INFO("SELinux: Loaded property contexts from %s\n", seopts_prop[i - 1].value); |
| 783 | return sehandle; |
| 784 | } |
| 785 | |
Stephen Smalley | ae6f3d7 | 2012-05-01 15:02:53 -0400 | [diff] [blame] | 786 | void selinux_init_all_handles(void) |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 787 | { |
Stephen Smalley | ae6f3d7 | 2012-05-01 15:02:53 -0400 | [diff] [blame] | 788 | sehandle = selinux_android_file_context_handle(); |
rpcraig | 63207cd | 2012-08-09 10:05:49 -0400 | [diff] [blame] | 789 | sehandle_prop = selinux_android_prop_context_handle(); |
Stephen Smalley | ae6f3d7 | 2012-05-01 15:02:53 -0400 | [diff] [blame] | 790 | } |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 791 | |
Nick Kralevich | 935bd3e | 2013-06-26 15:37:26 -0700 | [diff] [blame] | 792 | static bool selinux_is_disabled(void) |
| 793 | { |
| 794 | char tmp[PROP_VALUE_MAX]; |
| 795 | |
| 796 | if (access("/sys/fs/selinux", F_OK) != 0) { |
| 797 | /* SELinux is not compiled into the kernel, or has been disabled |
| 798 | * via the kernel command line "selinux=0". |
| 799 | */ |
| 800 | return true; |
| 801 | } |
| 802 | |
| 803 | if ((property_get("ro.boot.selinux", tmp) != 0) && (strcmp(tmp, "disabled") == 0)) { |
| 804 | /* SELinux is compiled into the kernel, but we've been told to disable it. */ |
| 805 | return true; |
| 806 | } |
| 807 | |
| 808 | return false; |
| 809 | } |
| 810 | |
| 811 | static bool selinux_is_enforcing(void) |
| 812 | { |
| 813 | char tmp[PROP_VALUE_MAX]; |
| 814 | |
| 815 | if (property_get("ro.boot.selinux", tmp) == 0) { |
| 816 | /* Property is not set. Assume enforcing */ |
| 817 | return true; |
| 818 | } |
| 819 | |
| 820 | if (strcmp(tmp, "permissive") == 0) { |
| 821 | /* SELinux is in the kernel, but we've been told to go into permissive mode */ |
| 822 | return false; |
| 823 | } |
| 824 | |
| 825 | if (strcmp(tmp, "enforcing") != 0) { |
| 826 | ERROR("SELinux: Unknown value of ro.boot.selinux. Got: \"%s\". Assuming enforcing.\n", tmp); |
| 827 | } |
| 828 | |
| 829 | return true; |
| 830 | } |
| 831 | |
Stephen Smalley | ae6f3d7 | 2012-05-01 15:02:53 -0400 | [diff] [blame] | 832 | int selinux_reload_policy(void) |
| 833 | { |
Nick Kralevich | 935bd3e | 2013-06-26 15:37:26 -0700 | [diff] [blame] | 834 | if (selinux_is_disabled()) { |
| 835 | return -1; |
| 836 | } |
| 837 | |
Stephen Smalley | ae6f3d7 | 2012-05-01 15:02:53 -0400 | [diff] [blame] | 838 | INFO("SELinux: Attempting to reload policy files\n"); |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 839 | |
Stephen Smalley | ae6f3d7 | 2012-05-01 15:02:53 -0400 | [diff] [blame] | 840 | if (selinux_android_reload_policy() == -1) { |
| 841 | return -1; |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 842 | } |
| 843 | |
Stephen Smalley | ae6f3d7 | 2012-05-01 15:02:53 -0400 | [diff] [blame] | 844 | if (sehandle) |
| 845 | selabel_close(sehandle); |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 846 | |
rpcraig | 63207cd | 2012-08-09 10:05:49 -0400 | [diff] [blame] | 847 | if (sehandle_prop) |
| 848 | selabel_close(sehandle_prop); |
| 849 | |
Stephen Smalley | ae6f3d7 | 2012-05-01 15:02:53 -0400 | [diff] [blame] | 850 | selinux_init_all_handles(); |
| 851 | return 0; |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 852 | } |
rpcraig | 63207cd | 2012-08-09 10:05:49 -0400 | [diff] [blame] | 853 | |
| 854 | int audit_callback(void *data, security_class_t cls, char *buf, size_t len) |
| 855 | { |
| 856 | snprintf(buf, len, "property=%s", !data ? "NULL" : (char *)data); |
| 857 | return 0; |
| 858 | } |
| 859 | |
Nick Kralevich | 56fa0ac | 2013-06-24 17:41:40 -0700 | [diff] [blame] | 860 | static void selinux_initialize(void) |
| 861 | { |
Nick Kralevich | 935bd3e | 2013-06-26 15:37:26 -0700 | [diff] [blame] | 862 | if (selinux_is_disabled()) { |
Nick Kralevich | 56fa0ac | 2013-06-24 17:41:40 -0700 | [diff] [blame] | 863 | return; |
| 864 | } |
| 865 | |
| 866 | INFO("loading selinux policy\n"); |
| 867 | if (selinux_android_load_policy() < 0) { |
| 868 | ERROR("SELinux: Failed to load policy; rebooting into recovery mode\n"); |
| 869 | android_reboot(ANDROID_RB_RESTART2, 0, "recovery"); |
| 870 | while (1) { pause(); } // never reached |
| 871 | } |
| 872 | |
| 873 | selinux_init_all_handles(); |
Nick Kralevich | 935bd3e | 2013-06-26 15:37:26 -0700 | [diff] [blame] | 874 | bool is_enforcing = selinux_is_enforcing(); |
| 875 | INFO("SELinux: security_setenforce(%d)\n", is_enforcing); |
| 876 | security_setenforce(is_enforcing); |
Nick Kralevich | 56fa0ac | 2013-06-24 17:41:40 -0700 | [diff] [blame] | 877 | } |
| 878 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 879 | int main(int argc, char **argv) |
| 880 | { |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 881 | int fd_count = 0; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 882 | struct pollfd ufds[4]; |
| 883 | char *tmpdev; |
The Android Open Source Project | 5ae090e | 2009-01-09 17:51:25 -0800 | [diff] [blame] | 884 | char* debuggable; |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 885 | char tmp[32]; |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 886 | int property_set_fd_init = 0; |
| 887 | int signal_fd_init = 0; |
| 888 | int keychord_fd_init = 0; |
Dima Zavin | d7634c9 | 2011-12-16 14:18:06 -0800 | [diff] [blame] | 889 | bool is_charger = false; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 890 | |
Colin Cross | f83d0b9 | 2010-04-21 12:04:20 -0700 | [diff] [blame] | 891 | if (!strcmp(basename(argv[0]), "ueventd")) |
| 892 | return ueventd_main(argc, argv); |
| 893 | |
Arve Hjønnevåg | d97d907 | 2012-06-13 21:51:56 -0700 | [diff] [blame] | 894 | if (!strcmp(basename(argv[0]), "watchdogd")) |
| 895 | return watchdogd_main(argc, argv); |
| 896 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 897 | /* clear the umask */ |
| 898 | umask(0); |
| 899 | |
| 900 | /* Get the basic filesystem setup we need put |
| 901 | * together in the initramdisk on / and then we'll |
| 902 | * let the rc file figure out the rest. |
| 903 | */ |
| 904 | mkdir("/dev", 0755); |
| 905 | mkdir("/proc", 0755); |
| 906 | mkdir("/sys", 0755); |
| 907 | |
Nick Kralevich | 150f19e | 2010-06-22 16:35:43 -0700 | [diff] [blame] | 908 | mount("tmpfs", "/dev", "tmpfs", MS_NOSUID, "mode=0755"); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 909 | mkdir("/dev/pts", 0755); |
| 910 | mkdir("/dev/socket", 0755); |
| 911 | mount("devpts", "/dev/pts", "devpts", 0, NULL); |
| 912 | mount("proc", "/proc", "proc", 0, NULL); |
| 913 | mount("sysfs", "/sys", "sysfs", 0, NULL); |
| 914 | |
Brian Swetland | 8d48c8e | 2011-03-24 15:45:30 -0700 | [diff] [blame] | 915 | /* indicate that booting is in progress to background fw loaders, etc */ |
| 916 | close(open("/dev/.booting", O_WRONLY | O_CREAT, 0000)); |
| 917 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 918 | /* We must have some place other than / to create the |
| 919 | * device nodes for kmsg and null, otherwise we won't |
| 920 | * be able to remount / read-only later on. |
| 921 | * Now that tmpfs is mounted on /dev, we can actually |
| 922 | * talk to the outside world. |
| 923 | */ |
| 924 | open_devnull_stdio(); |
Dima Zavin | 8f91282 | 2011-08-31 18:26:17 -0700 | [diff] [blame] | 925 | klog_init(); |
Dima Zavin | 5511c84 | 2011-12-19 11:21:32 -0800 | [diff] [blame] | 926 | property_init(); |
Vladimir Chtchetkine | 2b99543 | 2011-09-28 09:55:31 -0700 | [diff] [blame] | 927 | |
Colin Cross | f83d0b9 | 2010-04-21 12:04:20 -0700 | [diff] [blame] | 928 | get_hardware_name(hardware, &revision); |
Dima Zavin | d7634c9 | 2011-12-16 14:18:06 -0800 | [diff] [blame] | 929 | |
Dima Zavin | 5511c84 | 2011-12-19 11:21:32 -0800 | [diff] [blame] | 930 | process_kernel_cmdline(); |
| 931 | |
rpcraig | 63207cd | 2012-08-09 10:05:49 -0400 | [diff] [blame] | 932 | union selinux_callback cb; |
| 933 | cb.func_log = klog_write; |
| 934 | selinux_set_callback(SELINUX_CB_LOG, cb); |
| 935 | |
| 936 | cb.func_audit = audit_callback; |
| 937 | selinux_set_callback(SELINUX_CB_AUDIT, cb); |
| 938 | |
Nick Kralevich | 56fa0ac | 2013-06-24 17:41:40 -0700 | [diff] [blame] | 939 | selinux_initialize(); |
Stephen Smalley | ae6f3d7 | 2012-05-01 15:02:53 -0400 | [diff] [blame] | 940 | /* These directories were necessarily created before initial policy load |
Stephen Smalley | e096e36 | 2012-06-11 13:37:39 -0400 | [diff] [blame] | 941 | * and therefore need their security context restored to the proper value. |
| 942 | * This must happen before /dev is populated by ueventd. |
| 943 | */ |
| 944 | restorecon("/dev"); |
| 945 | restorecon("/dev/socket"); |
Geremy Condra | 8e15eab | 2013-02-28 17:29:58 -0800 | [diff] [blame] | 946 | restorecon("/dev/__properties__"); |
Nick Kralevich | ae76f6d | 2013-07-11 15:38:26 -0700 | [diff] [blame] | 947 | restorecon_recursive("/sys"); |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 948 | |
Dima Zavin | d7634c9 | 2011-12-16 14:18:06 -0800 | [diff] [blame] | 949 | is_charger = !strcmp(bootmode, "charger"); |
| 950 | |
| 951 | INFO("property init\n"); |
Dima Zavin | 5511c84 | 2011-12-19 11:21:32 -0800 | [diff] [blame] | 952 | if (!is_charger) |
| 953 | property_load_boot_defaults(); |
Dima Zavin | d7634c9 | 2011-12-16 14:18:06 -0800 | [diff] [blame] | 954 | |
| 955 | INFO("reading config file\n"); |
| 956 | init_parse_config_file("/init.rc"); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 957 | |
| 958 | action_for_each_trigger("early-init", action_add_queue_tail); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 959 | |
Colin Cross | f83d0b9 | 2010-04-21 12:04:20 -0700 | [diff] [blame] | 960 | queue_builtin_action(wait_for_coldboot_done_action, "wait_for_coldboot_done"); |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 961 | queue_builtin_action(keychord_init_action, "keychord_init"); |
| 962 | queue_builtin_action(console_init_action, "console_init"); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 963 | |
Dima Zavin | ca47cef | 2011-08-24 15:28:23 -0700 | [diff] [blame] | 964 | /* execute all the boot actions to get us started */ |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 965 | action_for_each_trigger("init", action_add_queue_tail); |
Dima Zavin | ca47cef | 2011-08-24 15:28:23 -0700 | [diff] [blame] | 966 | |
| 967 | /* skip mounting filesystems in charger mode */ |
Dima Zavin | d7634c9 | 2011-12-16 14:18:06 -0800 | [diff] [blame] | 968 | if (!is_charger) { |
Dima Zavin | ca47cef | 2011-08-24 15:28:23 -0700 | [diff] [blame] | 969 | action_for_each_trigger("early-fs", action_add_queue_tail); |
| 970 | action_for_each_trigger("fs", action_add_queue_tail); |
| 971 | action_for_each_trigger("post-fs", action_add_queue_tail); |
| 972 | action_for_each_trigger("post-fs-data", action_add_queue_tail); |
| 973 | } |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 974 | |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 975 | queue_builtin_action(property_service_init_action, "property_service_init"); |
| 976 | queue_builtin_action(signal_init_action, "signal_init"); |
| 977 | queue_builtin_action(check_startup_action, "check_startup"); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 978 | |
Dima Zavin | d7634c9 | 2011-12-16 14:18:06 -0800 | [diff] [blame] | 979 | if (is_charger) { |
Dima Zavin | ca47cef | 2011-08-24 15:28:23 -0700 | [diff] [blame] | 980 | action_for_each_trigger("charger", action_add_queue_tail); |
| 981 | } else { |
| 982 | action_for_each_trigger("early-boot", action_add_queue_tail); |
| 983 | action_for_each_trigger("boot", action_add_queue_tail); |
| 984 | } |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 985 | |
| 986 | /* run all property triggers based on current state of the properties */ |
Chris Dearman | 469b7b2 | 2012-03-01 15:29:20 -0800 | [diff] [blame] | 987 | queue_builtin_action(queue_property_triggers_action, "queue_property_triggers"); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 988 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 989 | |
| 990 | #if BOOTCHART |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 991 | queue_builtin_action(bootchart_init_action, "bootchart_init"); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 992 | #endif |
| 993 | |
| 994 | for(;;) { |
The Android Open Source Project | 5ae090e | 2009-01-09 17:51:25 -0800 | [diff] [blame] | 995 | int nr, i, timeout = -1; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 996 | |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 997 | execute_one_command(); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 998 | restart_processes(); |
| 999 | |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 1000 | if (!property_set_fd_init && get_property_set_fd() > 0) { |
| 1001 | ufds[fd_count].fd = get_property_set_fd(); |
| 1002 | ufds[fd_count].events = POLLIN; |
| 1003 | ufds[fd_count].revents = 0; |
| 1004 | fd_count++; |
| 1005 | property_set_fd_init = 1; |
| 1006 | } |
| 1007 | if (!signal_fd_init && get_signal_fd() > 0) { |
| 1008 | ufds[fd_count].fd = get_signal_fd(); |
| 1009 | ufds[fd_count].events = POLLIN; |
| 1010 | ufds[fd_count].revents = 0; |
| 1011 | fd_count++; |
| 1012 | signal_fd_init = 1; |
| 1013 | } |
| 1014 | if (!keychord_fd_init && get_keychord_fd() > 0) { |
| 1015 | ufds[fd_count].fd = get_keychord_fd(); |
| 1016 | ufds[fd_count].events = POLLIN; |
| 1017 | ufds[fd_count].revents = 0; |
| 1018 | fd_count++; |
| 1019 | keychord_fd_init = 1; |
| 1020 | } |
| 1021 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1022 | if (process_needs_restart) { |
| 1023 | timeout = (process_needs_restart - gettime()) * 1000; |
| 1024 | if (timeout < 0) |
| 1025 | timeout = 0; |
| 1026 | } |
| 1027 | |
Colin Cross | ebd4613 | 2010-04-22 11:52:23 -0700 | [diff] [blame] | 1028 | if (!action_queue_empty() || cur_action) |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 1029 | timeout = 0; |
| 1030 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1031 | #if BOOTCHART |
| 1032 | if (bootchart_count > 0) { |
| 1033 | if (timeout < 0 || timeout > BOOTCHART_POLLING_MS) |
| 1034 | timeout = BOOTCHART_POLLING_MS; |
| 1035 | if (bootchart_step() < 0 || --bootchart_count == 0) { |
| 1036 | bootchart_finish(); |
| 1037 | bootchart_count = 0; |
| 1038 | } |
| 1039 | } |
| 1040 | #endif |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 1041 | |
The Android Open Source Project | 5ae090e | 2009-01-09 17:51:25 -0800 | [diff] [blame] | 1042 | nr = poll(ufds, fd_count, timeout); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1043 | if (nr <= 0) |
| 1044 | continue; |
| 1045 | |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 1046 | for (i = 0; i < fd_count; i++) { |
Amir Goldstein | 1d4e86c | 2013-11-10 15:36:58 +0200 | [diff] [blame^] | 1047 | if (ufds[i].revents & POLLIN) { |
Colin Cross | f83d0b9 | 2010-04-21 12:04:20 -0700 | [diff] [blame] | 1048 | if (ufds[i].fd == get_property_set_fd()) |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 1049 | handle_property_set_fd(); |
| 1050 | else if (ufds[i].fd == get_keychord_fd()) |
| 1051 | handle_keychord(); |
| 1052 | else if (ufds[i].fd == get_signal_fd()) |
| 1053 | handle_signal(); |
| 1054 | } |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1055 | } |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | return 0; |
| 1059 | } |