4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
30 static int parent(pid_t pid)
35 if (waitpid(pid, &status, 0) != -1) {
36 /* terminated normally */
37 if (WIFEXITED(status)) {
38 _I("%d terminated by exit(%d)", pid, WEXITSTATUS(status));
39 return WEXITSTATUS(status);
40 } else if (WIFSIGNALED(status))
41 _I("%d terminated by signal %d", pid, WTERMSIG(status));
42 else if (WIFSTOPPED(status))
43 _I("%d stopped by signal %d", pid, WSTOPSIG(status));
45 _I("%d waitpid() failed : %s", pid, strerror(errno));
50 static void child(int argc, const char *argv[])
54 for (i = 0; i < _NSIG; ++i)
57 r = execv(argv[0], (char **)argv);
62 int run_child(int argc, const char *argv[])
65 struct sigaction act, oldact;
71 /* Use default signal handler */
72 act.sa_handler = SIG_DFL;
73 act.sa_sigaction = NULL;
75 sigemptyset(&act.sa_mask);
77 if (sigaction(SIGCHLD, &act, &oldact) < 0)
84 } else if (pid == 0) {
89 if (sigaction(SIGCHLD, &oldact, NULL) < 0)
90 _E("failed to restore sigaction");