--- /dev/null
+/*
+ * DA manager
+ *
+ * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ *
+ * Cherepanov Vitaliy <v.cherepanov@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ * - Samsung RnD Institute Russia
+ *
+ */
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <errno.h>
+#include "dahelper.h"
+
+static inline int __redirect(int old, int new)
+{
+ int ret = 0;
+
+ if (dup2(old, new) == -1) {
+ /* fail to print up there. there is no sdterr */
+ /* TODO inform about problem */
+ fprintf(stderr, "dup2 fail\n");
+ ret = -1;
+ }
+
+ return ret;
+}
+
+int __redirect_std(void)
+{
+#ifdef STDTOFILE
+ char STDOUT[MAX_PATH_LENGTH];
+ snprintf(STDOUT,sizeof(STDOUT), "/tmp/da_preloaded_%d_%d.log", getppid(), getpid());
+#else
+ #define STDOUT "/dev/null"
+#endif
+
+ int ret = 0;
+ int fd = open(STDOUT, O_WRONLY | O_CREAT | O_TRUNC, 0777);
+ if (fd != -1) {
+ if (__redirect(fd, 1) != 0 ||
+ __redirect(fd, 2) != 0) {
+ /* fail to print up there. there is no sdterr */
+ /* TODO inform about problem */
+ /* fprintf(sdterr, "duplicate fd fail\n"); */
+ ret = -1;
+ }
+
+ close(fd);
+ } else {
+ /* TODO inform about problem */
+ close(1);
+ close(2);
+ }
+
+ close(0);
+ return ret;
+}
--- /dev/null
+/*
+ * DA manager
+ *
+ * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ *
+ * Cherepanov Vitaliy <v.cherepanov@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ * - Samsung RnD Institute Russia
+ *
+ */
+
+#ifndef __DASDTOUT_H__
+#define __DASDTOUT_H__
+
+int __redirect_std(void);
+
+#endif /* __DASDTOUT_H__ */
* Woojin Jung <woojin2.jung@samsung.com>
* Juyoung Kim <j0.kim@samsung.com>
* Nikita Kalyazin <n.kalyazin@samsung.com>
+ * Vitaliy Cherepanov <v.cherepanov@samsung.com>
* Anastasia Lyupa <a.lyupa@samsung.com>
*
* This library is free software; you can redistribute it and/or modify it under
#include "binproto.h"
#include "daforkexec.h"
#include "damaps.h"
+#include "dastdout.h"
#include "common_probe_init.h"
#define APP_INSTALL_PATH "/opt/apps"
while (((recved & MSG_CONFIG_RECV) == 0) ||
((recved & MSG_MAPS_INST_LIST_RECV) == 0))
{
- fprintf(stderr, "wait message\n");
- PRINTMSG("wait incoming message");
+ PRINTMSG("wait incoming message %d\n",
+ gTraceInfo.socket.daemonSock);
/* recv header */
recvlen = recv(gTraceInfo.socket.daemonSock, &log,
sizeof(log.type) + sizeof(log.length),
free(data_buf);
} else if (recvlen < 0) {
- fprintf(stderr, "recv failed in socket creation with error(%d)\n", recvlen);
+ close(gTraceInfo.socket.daemonSock);
+ gTraceInfo.socket.daemonSock = -1;
+ PRINTERR("recv failed with error(%d)\n",
+ recvlen);
ret = -1;
application_exit();
break;
} else {
/* closed by other peer */
+ close(gTraceInfo.socket.daemonSock);
+ gTraceInfo.socket.daemonSock = -1;
+ PRINTERR("closed by other peer\n");
ret = -1;
application_exit();
break;
} else {
close(gTraceInfo.socket.daemonSock);
gTraceInfo.socket.daemonSock = -1;
+ PRINTERR("cannot connect to da_manager. err <%s>\n",
+ strerror(errno));
ret = -1;
}
} else {
+ PRINTERR("cannot create socket. err <%s>\n",
+ strerror(errno));
ret = -1;
}
{
probeBlockStart();
+ /* redirect stderr and stdout.*/
+ /* if there is no std - print call will crash app */
+ __redirect_std();
+
init_exec_fork();
initialize_hash_table();
/************************************************************************
* manipulate and print log functions
************************************************************************/
+const char *msg_code_to_srt(enum MessageType type)
+{
+ switch (type) {
+ case MSG_MSG:
+ return "[INF]";
+ case MSG_ERROR:
+ return "[ERR]";
+ case MSG_WARNING:
+ return "[WRN]";
+ default:
+ return "[???]";
+ }
+}
+
bool printLog(log_t *log, int msgType)
{
ssize_t res, len;
*/
bool print_log_fmt(int msgType, const char *func_name, int line, ...)
{
- ssize_t res, len;
+ ssize_t res = 0, len = 0;
char *fmt, *p;
int n;
log_t log;
va_list ap;
/* Check connection status */
- if(unlikely(gTraceInfo.socket.daemonSock == -1))
- return false;
probeBlockStart();
/* lock socket and send */
real_pthread_mutex_lock(&(gTraceInfo.socket.sockMutex));
- res = send(gTraceInfo.socket.daemonSock, &log, len, MSG_DONTWAIT);
+
+ if(unlikely(gTraceInfo.socket.daemonSock != -1)) {
+ res = send(gTraceInfo.socket.daemonSock, &log, len, MSG_DONTWAIT);
+ } else {
+ /* if socket is not connected, out to stderr */
+ fprintf(stderr, "%s %s\n", msg_code_to_srt(msgType), log.data);
+ fflush(stderr);
+ }
+
real_pthread_mutex_unlock(&(gTraceInfo.socket.sockMutex));
probeBlockEnd();
symbol = dlsym(RTLD_NEXT, symname);
if (symbol == NULL || dlerror() != NULL) {
- fprintf(stderr, "dlsym failed <%s>\n", symname);
+ PRINTERR("dlsym failed <%s>\n", symname);
exit(41);
}