Paparazzi UAS  v5.15_devel-230-gc96ce27
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
board.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 The Paparazzi Team
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <unistd.h>
32 #include "mcu.h"
33 #include "boards/bebop.h"
34 #include "subsystems/gps.h"
35 
36 static int kill_gracefull(char *process_name)
37 {
38  /* "pidof" always in /bin on Bebop firmware tested 1.98, 2.0.57, no need for "which" */
39  char pidof_commandline[200] = "/bin/pidof ";
40  strcat(pidof_commandline, process_name);
41  /* Bebop Busybox a
42  $ cat /proc/sys/kernel/pid_max
43  Gives max 32768, makes sure it never kills existing other process
44  */
45  char pid[7] = "";
46  int ret = 0; /* Return code of kill system call */
47  FILE *fp;
48 
49  while (ret == 0) {
50  fp = popen(pidof_commandline, "r");
51  if (fp != NULL) { /* Could open the pidof with line */
52  if (fgets(pid, sizeof(pid) - 1, fp) != NULL) {
53  //printf("Process ID deducted: \"%s\"\n", pid);
54  if (atoi(pid) > 0) { /* To make sure we end 0 > There is a real process id found */
55  char kill_command_and_process[200] = "kill -9 "; /* BTW there is no pkill on this Busybox */
56  strcat(kill_command_and_process, pid);
57  ret = system(kill_command_and_process);
58  /* No need to wait, since if it is not closed the next pidof scan still will still find it and try to kill it */
59  }
60  } else {
61  ret = 256; /* Could not get handle */
62  pclose(fp);
63  }
64  } else {
65  ret = 256; /* fp NULL, so no process, just return */
66  return 0;
67  }
68  } /* end while */
69  return 0;
70 }
71 
72 void board_init(void)
73 {
74  /*
75  * Process running by default for firmware >= v1.98
76  *
77  * - /bin/sh - /usr/bin/DragonStarter.sh -out2null
78  * - //usr/bin/dragon-prog
79  *
80  * Thus two process to kill, the DragonStarter first
81  * This to make sure OEM program does not get re-started
82  *
83  */
84  int ret __attribute__((unused)) = system("killall -q -15 DragonStarter.sh");
85  usleep(50000); /* Give DragonStarter 50ms time to end on a busy system */
86  kill_gracefull("dragon-prog");
87 #if GpsId(PRIMARY_GPS) == GPS_DATALINK_ID
88  kill_gracefull("ephemerisd");
89 #endif
90 }
91 
92 void board_init2(void)
93 {
94 }
void board_init2(void)
Optional board init function called at the end of mcu_init().
Definition: board.c:92
Device independent GPS code (interface)
void board_init(void)
Optional board init function called at the start of mcu_init().
Definition: board.c:130
Arch independent mcu ( Micro Controller Unit ) utilities.
static int kill_gracefull(char *process_name)
Definition: board.c:36