summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Muck <christian.muck@bmw.de>2012-05-08 09:55:26 +0200
committerChristian Muck <christian.muck@bmw.de>2012-05-08 09:58:09 +0200
commit425c366dc147652c9b2b0af8a26f66d7a457feff (patch)
treea66ddfe45817a6d64c1cd87ab26eda4ce5359d7b
parentf7828cf1a677b0d651c0477176099d66550037fd (diff)
downloadDLT-daemon-425c366dc147652c9b2b0af8a26f66d7a457feff.tar.gz
Added define statement for initial value of file descriptor and (-1). Updated the user_handle of the daemon and user
Signed-off-by: Christian Muck <christian.muck@bmw.de>
-rwxr-xr-xinclude/dlt/dlt_common.h7
-rw-r--r--src/daemon/dlt-daemon.c5
-rw-r--r--src/daemon/dlt_daemon_common.c30
-rwxr-xr-xsrc/lib/dlt_user.c10
4 files changed, 29 insertions, 23 deletions
diff --git a/include/dlt/dlt_common.h b/include/dlt/dlt_common.h
index 19ee4d5..690c2bd 100755
--- a/include/dlt/dlt_common.h
+++ b/include/dlt/dlt_common.h
@@ -175,6 +175,13 @@
*/
#define DLT_DAEMON_TCP_PORT 3490
+
+/* Initi value for file descritpor */
+#define DLT_FD_INIT -1
+
+/* Minimum value for a file descriptor except the POSIX Standards: stdin=0, stdout=1, stderr=2 */
+#define DLT_FD_MINIMUM 3
+
/**
* The size of a DLT ID
*/
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c
index 69e4072..476f442 100644
--- a/src/daemon/dlt-daemon.c
+++ b/src/daemon/dlt-daemon.c
@@ -1582,7 +1582,7 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, DltDaemo
dlt_message_free(&msg, verbose);
}
- if (context->user_handle!=0)
+ if (context->user_handle >= DLT_FD_MINIMUM)
{
/* This call also replaces the default values with the values defined for default */
if (dlt_daemon_user_send_log_level(daemon, context, verbose)==-1)
@@ -2125,8 +2125,7 @@ int dlt_daemon_process_user_message_set_app_ll_ts(DltDaemon *daemon, DltDaemonLo
context->trace_status = usercontext->trace_status; /* No endianess conversion necessary */
/* The folowing function sends also the trace status */
- if ((context->user_handle==0) ||
- (dlt_daemon_user_send_log_level(daemon, context, verbose)!=0))
+ if (context->user_handle >= DLT_FD_MINIMUM && dlt_daemon_user_send_log_level(daemon, context, verbose)!=0)
{
context->log_level = old_log_level;
context->trace_status = old_trace_status;
diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c
index 3bf940e..9a2cbea 100644
--- a/src/daemon/dlt_daemon_common.c
+++ b/src/daemon/dlt_daemon_common.c
@@ -223,7 +223,7 @@ int dlt_daemon_applications_invalidate_fd(DltDaemon *daemon,int fd,int verbose)
{
if (daemon->applications[i].user_handle==fd)
{
- daemon->applications[i].user_handle = 0;
+ daemon->applications[i].user_handle = DLT_FD_INIT;
}
}
@@ -316,7 +316,7 @@ DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon,char *apid,pi
application->pid = pid;
application->application_description = 0;
application->num_contexts = 0;
- application->user_handle = -1;
+ application->user_handle = DLT_FD_INIT;
new_application = 1;
@@ -344,7 +344,7 @@ DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon,char *apid,pi
}
}
- if( application->user_handle != -1 )
+ if( application->user_handle != DLT_FD_INIT )
{
if( application->pid != pid )
{
@@ -354,13 +354,13 @@ DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon,char *apid,pi
dlt_log(LOG_ERR, str);
}
- application->user_handle = -1;
+ application->user_handle = DLT_FD_INIT;
application->pid = pid;
}
}
/* open user pipe only if it is not yet opened */
- if (application->user_handle==-1 && pid!=0)
+ if (application->user_handle==DLT_FD_INIT && pid!=0)
{
sprintf(filename,"%s/dlt%d",DLT_USER_DIR,application->pid);
@@ -405,10 +405,10 @@ int dlt_daemon_application_del(DltDaemon *daemon, DltDaemonApplication *applicat
if (daemon->num_applications>0)
{
/* Check if user handle is open; if yes, close it */
- if (application->user_handle!=-1)
+ if (application->user_handle >= DLT_FD_MINIMUM)
{
close(application->user_handle);
- application->user_handle=-1;
+ application->user_handle=DLT_FD_INIT;
}
/* Free description of application to be deleted */
@@ -749,7 +749,7 @@ int dlt_daemon_contexts_invalidate_fd(DltDaemon *daemon,int fd,int verbose)
{
if (daemon->contexts[i].user_handle==fd)
{
- daemon->contexts[i].user_handle = 0;
+ daemon->contexts[i].user_handle = DLT_FD_INIT;
}
}
@@ -1028,7 +1028,7 @@ int dlt_daemon_user_send_log_level(DltDaemon *daemon,DltDaemonContext *context,i
{
/* Close connection */
close(context->user_handle);
- context->user_handle=0;
+ context->user_handle=DLT_FD_INIT;
}
}
@@ -1064,7 +1064,7 @@ int dlt_daemon_user_send_log_state(DltDaemon *daemon,DltDaemonApplication *app,i
{
/* Close connection */
close(app->user_handle);
- app->user_handle=0;
+ app->user_handle=DLT_FD_INIT;
}
}
@@ -1327,7 +1327,7 @@ void dlt_daemon_control_callsw_cinjection(int sock, DltDaemon *daemon, DltMessag
{
/* Close connection */
close(context->user_handle);
- context->user_handle=0;
+ context->user_handle=DLT_FD_INIT;
}
dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
}
@@ -1376,7 +1376,7 @@ void dlt_daemon_control_set_log_level(int sock, DltDaemon *daemon, DltMessage *m
old_log_level = context->log_level;
context->log_level = req->log_level; /* No endianess conversion necessary*/
- if ((context->user_handle!=0) &&
+ if ((context->user_handle >= DLT_FD_MINIMUM) &&
(dlt_daemon_user_send_log_level(daemon, context, verbose)==0))
{
dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_OK, verbose);
@@ -1424,7 +1424,7 @@ void dlt_daemon_control_set_trace_status(int sock, DltDaemon *daemon, DltMessage
old_trace_status = context->trace_status;
context->trace_status = req->log_level; /* No endianess conversion necessary */
- if ((context->user_handle!=0) &&
+ if ((context->user_handle >= DLT_FD_MINIMUM ) &&
(dlt_daemon_user_send_log_level(daemon, context, verbose)==0))
{
dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_OK, verbose);
@@ -2297,7 +2297,7 @@ void dlt_daemon_user_send_default_update(DltDaemon *daemon, int verbose)
if ((context->log_level == DLT_LOG_DEFAULT) ||
(context->trace_status == DLT_TRACE_STATUS_DEFAULT))
{
- if (context->user_handle!=0)
+ if (context->user_handle >= DLT_FD_MINIMUM)
{
if (dlt_daemon_user_send_log_level(daemon, context, verbose)==-1)
{
@@ -2327,7 +2327,7 @@ void dlt_daemon_user_send_all_log_state(DltDaemon *daemon, int verbose)
if (app)
{
- if (app->user_handle!=0)
+ if (app->user_handle >= DLT_FD_MINIMUM)
{
if (dlt_daemon_user_send_log_state(daemon, app, verbose)==-1)
{
diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c
index cdaa93a..370a1ca 100755
--- a/src/lib/dlt_user.c
+++ b/src/lib/dlt_user.c
@@ -164,7 +164,7 @@ int dlt_init(void)
}
dlt_user.dlt_user_handle = open(filename, O_RDWR | O_CLOEXEC);
- if (dlt_user.dlt_user_handle == -1)
+ if (dlt_user.dlt_user_handle == DLT_FD_INIT)
{
sprintf(str,"Loging disabled, FIFO user %s cannot be opened!\n",filename);
dlt_log(LOG_WARNING, str);
@@ -264,7 +264,7 @@ int dlt_init_common(void)
dlt_user.log_state = -1;
dlt_user.dlt_log_handle=-1;
- dlt_user.dlt_user_handle=-1;
+ dlt_user.dlt_user_handle=DLT_FD_INIT;
dlt_set_id(dlt_user.ecuID,DLT_USER_DEFAULT_ECU_ID);
dlt_set_id(dlt_user.appID,"");
@@ -382,12 +382,12 @@ int dlt_free(void)
pthread_cancel(dlt_receiverthread_handle);
}
- if (dlt_user.dlt_user_handle!=-1)
+ if (dlt_user.dlt_user_handle!=DLT_FD_INIT)
{
sprintf(filename,"%s/dlt%d",DLT_USER_DIR,getpid());
close(dlt_user.dlt_user_handle);
- dlt_user.dlt_user_handle=-1;
+ dlt_user.dlt_user_handle=DLT_FD_INIT;
unlink(filename);
}
@@ -2644,7 +2644,7 @@ int dlt_user_log_check_user_message(void)
delayed_injection_callback.injection_callback = 0;
delayed_injection_callback.service_id = 0;
- if (dlt_user.dlt_user_handle!=-1)
+ if (dlt_user.dlt_user_handle!=DLT_FD_INIT)
{
while (1)
{