automotive-dlt
dlt-system-shell.c
Go to the documentation of this file.
1 /*
2  * @licence app begin@
3  * SPDX license identifier: MPL-2.0
4  *
5  * Copyright (C) 2011-2015, BMW AG
6  *
7  * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
8  *
9  * This Source Code Form is subject to the terms of the
10  * Mozilla Public License (MPL), v. 2.0.
11  * If a copy of the MPL was not distributed with this file,
12  * You can obtain one at http://mozilla.org/MPL/2.0/.
13  *
14  * For further information see http://www.genivi.org/.
15  * @licence end@
16  */
17 
27 /*******************************************************************************
28 ** **
29 ** SRC-MODULE: dlt-system-shell.c **
30 ** **
31 ** TARGET : linux **
32 ** **
33 ** PROJECT : DLT **
34 ** **
35 ** AUTHOR : Lassi Marttala <lassi.lm.marttala@partner.bmw.de> **
36 ** Alexander Wenzel Alexander.AW.Wenzel@bmw.de **
37 ** **
38 ** PURPOSE : **
39 ** **
40 ** REMARKS : **
41 ** **
42 ** PLATFORM DEPENDANT [yes/no]: yes **
43 ** **
44 ** TO BE CHANGED BY USER [yes/no]: no **
45 ** **
46 *******************************************************************************/
47 
48 /*******************************************************************************
49 ** Author Identity **
50 ********************************************************************************
51 ** **
52 ** Initials Name Company **
53 ** -------- ------------------------- ---------------------------------- **
54 ** lm Lassi Marttala BMW **
55 *******************************************************************************/
56 #include "dlt.h"
57 #include "dlt-system.h"
58 
59 #include <string.h>
60 #include <stdlib.h>
61 
62 #define DLT_SHELL_COMMAND_MAX_LENGTH 1024
63 
65 DLT_DECLARE_CONTEXT(shellContext)
66 
67 int dlt_shell_injection_callback(uint32_t service_id, void *data, uint32_t length)
68 {
69  (void) length;
70 
71  DLT_LOG(shellContext,DLT_LOG_DEBUG,
72  DLT_STRING("dlt-system-shell, injection callback"));
74  int syserr = 0;
75 
76  if(length<=DLT_SHELL_COMMAND_MAX_LENGTH-1)
77  {
78  strncpy(text,data,length);
79  text[length] = 0;
80  }
81  else
82  {
83  strncpy(text,data,DLT_SHELL_COMMAND_MAX_LENGTH-1);
84  text[DLT_SHELL_COMMAND_MAX_LENGTH-1] = 0;
85  }
86 
87  DLT_LOG(shellContext,DLT_LOG_DEBUG,
88  DLT_STRING("dlt-system-shell, injection injection id:"),
89  DLT_UINT32(service_id));
90  DLT_LOG(shellContext,DLT_LOG_DEBUG,
91  DLT_STRING("dlt-system-shell, injection data:"),
92  DLT_STRING(text));
93 
94  switch(service_id)
95  {
96  case 0x1001:
97  if((syserr = system(text)) != 0)
98  {
99  DLT_LOG(shellContext,DLT_LOG_ERROR,
100  DLT_STRING("dlt-system-shell, abnormal exit status."),
101  DLT_STRING(text),
102  DLT_INT(syserr));
103  }
104  else
105  {
106  DLT_LOG(shellContext,DLT_LOG_INFO,
107  DLT_STRING("Shell command executed:"),
108  DLT_STRING(text));
109  }
110  break;
111  default:
112  DLT_LOG(shellContext,DLT_LOG_ERROR,
113  DLT_STRING("dlt-system-shell, unknown command received."),
114  DLT_UINT32(service_id),
115  DLT_STRING(text));
116  break;
117  }
118  return 0;
119 }
120 
122 {
123  DLT_LOG(dltsystem,DLT_LOG_DEBUG,
124  DLT_STRING("dlt-system-shell, register callback"));
125  DLT_REGISTER_CONTEXT(shellContext,"CMD","Execute Shell commands");
126  DLT_REGISTER_INJECTION_CALLBACK(shellContext, 0x1001, dlt_shell_injection_callback);
127 }
#define DLT_REGISTER_INJECTION_CALLBACK(CONTEXT, SERVICEID, CALLBACK)
#define DLT_INT(INT_VAR)
#define DLT_SHELL_COMMAND_MAX_LENGTH
static char * service_id[]
Definition: dlt_common.c:85
static char data[kDataSize]
Definition: city-test.cc:40
#define DLT_DECLARE_CONTEXT(CONTEXT)
#define DLT_STRING(TEXT)
#define DLT_REGISTER_CONTEXT(CONTEXT, CONTEXTID, DESCRIPTION)
#define DLT_LOG(CONTEXT, LOGLEVEL, ARGS...)
DLT_IMPORT_CONTEXT(dltsystem)
void init_shell()
#define DLT_UINT32(UINT_VAR)