2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <sys/types.h>
28 #include "hardware_legacy/power.h"
31 int main(int argc, char **argv)
34 unsigned int delay = 0;
40 printf("Usage: %s [-f logfile] [-a] [-d delay] <program>\n", argv[0]);
43 close(0); open("/dev/null", 0);
48 while(**++argv == '-') {
61 delay = atoi(*++argv);
72 if(open(file, O_WRONLY|mode|O_CREAT, 0666) < 0) {
78 if(open("/dev/null", O_WRONLY) < 0) {
84 switch(pid = fork()) {
91 close(2); dup(1); /* join stdout and stderr */
96 for (fd = 3; fd < 256; fd++) {
100 snprintf(lockid, 32, "daemonize%d", (int) getpid());
101 acquire_wake_lock(PARTIAL_WAKE_LOCK, lockid);
104 switch(pid = fork()) {
111 execv(argv[0], argv);
112 execvp(argv[0], argv);
117 waitpid(pid, &status, 0);
118 release_wake_lock(lockid);
130 /* vim:ts=4:sw=4:softtabstop=4:smarttab:expandtab */