• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3  * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this list of
9  *    conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12  *    of conditions and the following disclaimer in the documentation and/or other materials
13  *    provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16  *    to endorse or promote products derived from this software without specific prior written
17  *    permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <errno.h>
35 #include <unistd.h>
36 #include <sys/wait.h>
37 
38 #ifdef LOSCFG_QUICK_START
39 #include <sys/types.h>
40 #include <sys/stat.h>
41 #include <sys/mman.h>
42 #include <fcntl.h>
43 #include <sys/ioctl.h>
44 
45 #define QUICKSTART_IOC_MAGIC    'T'
46 #define QUICKSTART_INITSTEP2    _IO(QUICKSTART_IOC_MAGIC, 0)
47 #define WAIT_FOR_SAMPLE         300000  // wait 300ms for sample
48 #endif
main(int argc,char * const * argv)49 int main(int argc, char * const *argv)
50 {
51     (void)argv;
52     int ret;
53     pid_t gid;
54     const char *shellPath = "/bin/mksh";
55 
56 #ifdef LOSCFG_QUICK_START
57     const char *samplePath = "/dev/shm/sample_quickstart";
58 
59     ret = fork();
60     if (ret < 0) {
61         printf("Failed to fork for sample_quickstart\n");
62     } else if (ret == 0) {
63         (void)execve(samplePath, NULL, NULL);
64         exit(0);
65     }
66 
67     usleep(WAIT_FOR_SAMPLE);
68 
69     int fd = open("/dev/quickstart", O_RDONLY);
70     if (fd != -1) {
71         ioctl(fd, QUICKSTART_INITSTEP2);
72         close(fd);
73     }
74 #endif
75     ret = fork();
76     if (ret < 0) {
77         printf("Failed to fork for shell\n");
78     } else if (ret == 0) {
79         gid = getpgrp();
80         if (gid < 0) {
81             printf("get group id failed, pgrpid %d, errno %d\n", gid, errno);
82             exit(0);
83         }
84         ret = tcsetpgrp(STDIN_FILENO, gid);
85         if (ret != 0) {
86             printf("tcsetpgrp failed, errno %d\n", errno);
87             exit(0);
88         }
89         (void)execve(shellPath, NULL, NULL);
90         exit(0);
91     }
92 
93     while (1) {
94         ret = waitpid(-1, 0, WNOHANG);
95         if (ret == 0) {
96             sleep(1);
97         }
98     };
99 }
100