diff options
author | woojin <woojin2.jung@samsung.com> | 2013-04-16 07:55:47 +0900 |
---|---|---|
committer | woojin <woojin2.jung@samsung.com> | 2013-04-16 07:55:47 +0900 |
commit | 1dc2afb67afde731948e3e002fc780ce98f381e7 (patch) | |
tree | 5b04db183201a1a6ae8282eb8d7949e102712ff5 | |
parent | 0d49a40a84b8dd13ccd0bfe826a044e69da9cd41 (diff) | |
download | dynamic-analysis-manager-tizen_2.2.tar.gz dynamic-analysis-manager-tizen_2.2.tar.bz2 dynamic-analysis-manager-tizen_2.2.zip |
remove files moved to other git, modify license2.2.1_releasetizen_2.2
Change-Id: I7226c136e2d97086f5fecd6a78445375ae984fd0
-rw-r--r-- | LICENSE.APLv2 | 204 | ||||
-rw-r--r-- | NOTICE | 7 | ||||
-rw-r--r-- | activator/MacOSWindowActivator | bin | 15260 -> 0 bytes | |||
-rw-r--r-- | activator/Makefile | 20 | ||||
-rw-r--r-- | activator/WindowActivator | bin | 13885 -> 0 bytes | |||
-rw-r--r-- | activator/WindowActivator.cpp | 365 | ||||
-rw-r--r-- | activator/WindowActivator.exe | bin | 105984 -> 0 bytes | |||
-rw-r--r-- | activator/WindowActivator.h | 62 | ||||
-rw-r--r-- | activator/macoswindowactivator.sh | 15 | ||||
-rw-r--r-- | activator/main.cpp | 63 | ||||
-rw-r--r-- | activator/windowactivator.bat | 10 | ||||
-rw-r--r-- | activator/windowactivator.sh | 15 | ||||
-rw-r--r-- | activator/windowactivator.vbs | 11 | ||||
-rw-r--r-- | daemon/Makefile | 53 | ||||
-rw-r--r-- | daemon/Makefile_arm | 31 | ||||
-rw-r--r-- | daemon/Makefile_dibs | 41 | ||||
-rw-r--r-- | daemon/Makefile_x86 | 34 | ||||
-rw-r--r-- | daemon/da_daemon.c | 1670 | ||||
-rw-r--r-- | daemon/da_debug.h | 54 | ||||
-rw-r--r-- | daemon/sys_stat.c | 2019 | ||||
-rw-r--r-- | daemon/sys_stat.h | 158 | ||||
-rw-r--r-- | daemon/utils.c | 260 | ||||
-rw-r--r-- | daemon/utils.h | 86 | ||||
-rw-r--r-- | eventutil/Makefile | 19 | ||||
-rw-r--r-- | eventutil/eventutil.c | 378 | ||||
-rwxr-xr-x[-rw-r--r--] | package/build.linux | 64 | ||||
-rw-r--r-- | package/pkginfo.manifest | 10 |
27 files changed, 12 insertions, 5637 deletions
diff --git a/LICENSE.APLv2 b/LICENSE.APLv2 deleted file mode 100644 index 9fc6203..0000000 --- a/LICENSE.APLv2 +++ /dev/null @@ -1,204 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - 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. - - - @@ -1,7 +1,4 @@ Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved. -Except as noted, this software is licensed under Apache License, Version 2. -Please, see the LICENSE.APLv2 file for Apache License terms and conditions. +Except as noted, this software is licensed under GNU Public License, Version 3. +Please, see the LICENSE.GPLv3 file for GNU Public License, Version 3 terms and conditions. -readelf_arm, readelf_x86 file is licensed under GNU Public License , Version 3. -Please, see LICENSE.GPLv3 file for GNU Public License , Version 3 terms and conditions. - diff --git a/activator/MacOSWindowActivator b/activator/MacOSWindowActivator Binary files differdeleted file mode 100644 index 74f6290..0000000 --- a/activator/MacOSWindowActivator +++ /dev/null diff --git a/activator/Makefile b/activator/Makefile deleted file mode 100644 index 642e0f0..0000000 --- a/activator/Makefile +++ /dev/null @@ -1,20 +0,0 @@ - -HEADER = WindowActivator.h - -SRCS = main.cpp WindowActivator.cpp - -TARGET = WindowActivator - -FLAGS = -Wall - -#LDFLAGS = -lstdc++ -lX11 -LDFLAGS = -lstdc++ -framework IOKit -framework ApplicationServices - -all: $(TARGET) - -$(TARGET): $(SRCS) $(HEADER) - $(CC) -o $@ $(FLAGS) $(SRCS) $(LDFLAGS) - -clean: - rm $(TARGET) - diff --git a/activator/WindowActivator b/activator/WindowActivator Binary files differdeleted file mode 100644 index 8fe0876..0000000 --- a/activator/WindowActivator +++ /dev/null diff --git a/activator/WindowActivator.cpp b/activator/WindowActivator.cpp deleted file mode 100644 index 49584bd..0000000 --- a/activator/WindowActivator.cpp +++ /dev/null @@ -1,365 +0,0 @@ -/* - * Window Activator - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: - * - * Jaewon Lim <jaewon81.lim@samsung.com> - * Juyoung Kim <j0.kim@samsung.com> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Contributors: - * - S-Core Co., Ltd - * - */ - - - -/** - * @summary - * @create date : 2011. 8. 16. - * @author(create) : Lee JaeYeol / jaeyeol148.lee@samsung.com / S-Core - * @revision date : 2011. 8. 16. - * @author(revision) : Lee JaeYeol / jaeyeol148.lee@samsung.com / S-Core - * @refactoring date : 2012. 4. 14 - * @author(refactoring) : Jaewon Lim / jaewon81.lim@samsung.com / S-Core - */ - -#include "WindowActivator.h" -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -WindowActivator::WindowActivator() -{ -} - -WindowActivator::~WindowActivator() -{ -} - -bool WindowActivator::ActivateWindow(const std::string pid) -{ - return ActivateWindow(atoi(pid.c_str())); -} - - -#ifdef _WIN32 || _WIN64 -#include <windows.h> -//#using <System.dll> -//using namespace System; -//using namespace System::Diagnostics; -//using namespace System::ComponentModel; - -ULONG ProcIDFromWnd(HWND hwnd); -HWND GetWinHandle(ULONG pid); -void ActiveWindow(HWND hWnd); - -bool WindowActivator::ActivateWindow(int pid) -{ - ActiveWindow(GetWinHandle(pid)); - return true; -} - -ULONG ProcIDFromWnd(HWND hwnd) -{ - ULONG idProc; - GetWindowThreadProcessId( hwnd, &idProc ); - return idProc; -} - -HWND GetWinHandle(ULONG pid) -{ -// Process^ fproc = Process::GetProcessById(pid); -// return (HWND)fproc->MainWindowHandle.ToPointer(); - - HWND tempHwnd = FindWindow(NULL,NULL); - - while(tempHwnd != NULL ) - { - if(GetParent(tempHwnd) == NULL ) - { - if(GetWindow(tempHwnd, GW_OWNER) == NULL) - { - if( pid == ProcIDFromWnd(tempHwnd) ) - return tempHwnd; - } - } - tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT); - } - return NULL; -} - -void ActiveWindow(HWND hWnd) -{ - HWND hWndForeground = ::GetForegroundWindow(); - if(hWndForeground == hWnd) - { - printf("same as foreground window\n"); - return; - } - - DWORD Strange = ::GetWindowThreadProcessId(hWndForeground, NULL); - DWORD My = ::GetWindowThreadProcessId(hWnd, NULL); - if( !::AttachThreadInput(Strange, My, TRUE) ) - { - // ASSERT(0); - } - ::SetForegroundWindow(hWnd); - ::BringWindowToTop(hWnd); - if( !::AttachThreadInput(Strange, My, FALSE) ) - { - // ASSERT(0); - } - if (::IsIconic(hWnd)) - ::ShowWindow(hWnd, SW_RESTORE); -} - -#elif __linux // if Linux - -#include <X11/Xlib.h> -#include <X11/Xatom.h> - -#define PERROR(...) fprintf(stderr, __VA_ARGS__) - -bool findWindow(Display *disp, int idepid); -Window* getClientList(Display *disp, unsigned long *size); -char *getProperty(Display *disp, Window win, Atom xaPropType, const char *propName, unsigned long *size); -char *getWindowTitle(Display *disp, Window win); -int findProcessID(Display *disp, Window win); -void activateWindow(Display *disp, Window win); -bool sendEvent(Display *disp, Window win, char *msg, unsigned long data0, unsigned long data1, unsigned long data2, unsigned long data3, unsigned long data4); - -bool WindowActivator::ActivateWindow(int pid) -{ - - Display *disp; - - if (!(disp = XOpenDisplay(NULL))) - { - PERROR("XOpenDisplay error"); - return false; - } - - findWindow(disp, pid); - return true; -} - -bool findWindow(Display *disp, int idepid) -{ - unsigned long clientListSize; - unsigned long i; - Window *clientList; - Window activate = 0; - - if ((clientList = getClientList(disp, &clientListSize)) == NULL) - { - return false; - } - - for (i = 0; i < clientListSize / sizeof(Window); i++) - { - int pid = 0; - pid = findProcessID(disp, clientList[i]); - - if (pid == 0) - { - continue; - } - - if(pid == idepid) - { - activate = clientList[i]; - break; - } - } - - free(clientList); - - if (activate) - { - activateWindow(disp, activate); - return true; - } - else - { - return false; - } -} - -Window* getClientList(Display *disp, unsigned long *size) -{ - Window *clientList; - - if ((clientList = (Window *)getProperty(disp, DefaultRootWindow(disp), XA_WINDOW, (char*)"_NET_CLIENT_LIST", size)) == NULL) - { - if ((clientList = (Window *)getProperty(disp, DefaultRootWindow(disp), XA_CARDINAL, (char*)"_WIN_CLIENT_LIST", size)) == NULL) - { - PERROR("Can not get a client list"); - return NULL; - } - } - return clientList; -} - -char* getProperty(Display *disp, Window win, Atom xaPropType, const char *propName, unsigned long *size) -{ - Atom xaPropName; - Atom xaRetType; - int retFormat; - unsigned long retItems; - unsigned long retBytesAfter; - unsigned long tmpSize; - unsigned char *retProp; - char *ret; - - xaPropName = XInternAtom(disp, propName, False); - - int returnValue = XGetWindowProperty(disp, win, xaPropName, 0, 1024, False, xaPropType, &xaRetType, &retFormat, &retItems, &retBytesAfter, &retProp); - PERROR("XGetWindowProperty %d ", returnValue); - - if (returnValue != Success) - { - PERROR("Can not get a %s property", propName); - return NULL; - } - - if (xaRetType != xaPropType) - { - PERROR("Invalid type of %s property.", propName); - XFree(retProp); - return NULL; - } - - // null terminate the result to make string handling easier / - tmpSize = (retFormat / 8) * retItems; - // Correct 64 Architecture implementation of 32 bit data / - if(retFormat==32) tmpSize *= sizeof(long)/4; - ret = (char*)malloc(tmpSize + 1); - memcpy(ret, retProp, tmpSize); - ret[tmpSize] = '\0'; - - if (size) { - *size = tmpSize; - } - - XFree(retProp); - return ret; -} - -int findProcessID(Display *disp, Window win) -{ - int pid = 0; - unsigned long *netWmPid; - - netWmPid = (unsigned long*)getProperty(disp, win, XA_CARDINAL, (const char*)"_NET_WM_PID", NULL); - - if(netWmPid) - { - pid = (int)*netWmPid; - free(netWmPid); - } - - PERROR("findProcessID %d ", pid); - return pid; -} - -bool sendEvent(Display *disp, Window win, char *msg, - unsigned long data0, unsigned long data1, - unsigned long data2, unsigned long data3, - unsigned long data4) -{ - XEvent event; - long mask = SubstructureRedirectMask | SubstructureNotifyMask; - - event.xclient.type = ClientMessage; - event.xclient.serial = 0; - event.xclient.send_event = True; - event.xclient.message_type = XInternAtom(disp, msg, False); - event.xclient.window = win; - event.xclient.format = 32; - event.xclient.data.l[0] = data0; - event.xclient.data.l[1] = data1; - event.xclient.data.l[2] = data2; - event.xclient.data.l[3] = data3; - event.xclient.data.l[4] = data4; - - if (XSendEvent(disp, DefaultRootWindow(disp), False, mask, &event)) - { - return true; - } - else - { - PERROR("Can not send %s event", msg); - return false; - } -} - - -void activateWindow (Display *disp, Window win) -{ - unsigned long *desktop = NULL; - - // desktop ID / - if ((desktop = (unsigned long *)getProperty(disp, win, XA_CARDINAL, (const char*)"_NET_WM_DESKTOP", NULL)) == NULL) - { - if ((desktop = (unsigned long *)getProperty(disp, win, XA_CARDINAL, (const char*)"_WIN_WORKSPACE", NULL)) == NULL) - { - PERROR("Can not find desktop ID"); - } - } - - if (desktop) - { - if (sendEvent(disp, DefaultRootWindow(disp), (char*)"_NET_CURRENT_DESKTOP", *desktop, 0, 0, 0, 0) != EXIT_SUCCESS) - { - PERROR("Can not switch desktop."); - } - free(desktop); - } - - sendEvent(disp, win, (char*)"_NET_ACTIVE_WINDOW", 0, 0, 0, 0, 0); - XMapRaised(disp, win); - - XFlush(disp); - XCloseDisplay (disp); -} -#elif __APPLE__ - -#include <getopt.h> -#include <IOKit/graphics/IOGraphicsLib.h> -#include <ApplicationServices/ApplicationServices.h> - -bool WindowActivator::ActivateWindow(int pid) -{ - - ProcessSerialNumber psn; - if(noErr == GetProcessForPID(pid, &psn)) - { - SetFrontProcess(&psn); - exit(0); - } - return 0; -} - -#endif // end Linux diff --git a/activator/WindowActivator.exe b/activator/WindowActivator.exe Binary files differdeleted file mode 100644 index 7f873c1..0000000 --- a/activator/WindowActivator.exe +++ /dev/null diff --git a/activator/WindowActivator.h b/activator/WindowActivator.h deleted file mode 100644 index 100b791..0000000 --- a/activator/WindowActivator.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Window Activator - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: - * - * Jaewon Lim <jaewon91.lim@samsung.com> - * Juyoung Kim <j0.kim@samsung.com> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Contributors: - * - S-Core Co., Ltd - * - */ - - -/** - * @summary : - * @create date : 2011. 8. 16. - * @author(create) : Lee JaeYeol / jaeyeol148.lee@samsung.com / S-Core - * @revision date : 2011. 8. 16. - * @author(revision) : Lee JaeYeol / jaeyeol148.lee@samsung.com / S-Core - */ - - -#ifndef WINDOWACTIVATOR_H_ -#define WINDOWACTIVATOR_H_ - -#include <string> - -class WindowActivator -{ -private: - WindowActivator(); - virtual ~WindowActivator(); - -public: - static bool ActivateWindow(const std::string pid); - static bool ActivateWindow(int pid); -}; - -#endif /* WINDOWACTIVATOR_H_ */ diff --git a/activator/macoswindowactivator.sh b/activator/macoswindowactivator.sh deleted file mode 100644 index 9ef0fa0..0000000 --- a/activator/macoswindowactivator.sh +++ /dev/null @@ -1,15 +0,0 @@ -#! /bin/bash - -abspath="$(cd "${0%/*}" 2>/dev/null; echo $PWD/${0##*/})" -absdir=`dirname "$abspath"` - -PWD=`pwd` - -ACTIVATOR=MacOSWindowActivator -ACTIVATOR_PATH=${absdir} - -# for coredump file -ulimit -c unlimited - -${ACTIVATOR_PATH}/${ACTIVATOR} "$@" - diff --git a/activator/main.cpp b/activator/main.cpp deleted file mode 100644 index d2b6a67..0000000 --- a/activator/main.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Window Activator - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: - * - * Changhun Lim <changhun.lim@samsung.com> - * Gyeongmin Ju <gyeongmin.ju@samsung.com> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Contributors: - * - S-Core Co., Ltd - * - */ - -#include <iostream> -#include <string> -#include "WindowActivator.h" - -using namespace std; - -static void printUsage(const string appname) -{ - cout << "* error : missing required paramaters" << endl; - cout << "* usage : " << endl; - cout << "\t to activate a window :" << endl; - cout << "\t\t" << appname << " pid" << endl; -} - -int main(int argc, char **argv) -{ - if (argc < 2) - { - printUsage(argv[0]); - } - else - { - WindowActivator::ActivateWindow(argv[1]); - } - - return 0; -} - diff --git a/activator/windowactivator.bat b/activator/windowactivator.bat deleted file mode 100644 index 0655f2e..0000000 --- a/activator/windowactivator.bat +++ /dev/null @@ -1,10 +0,0 @@ -rem # find & move absolute path -set ABS_PATH=%~dp0 -cd %ABS_PATH% - -set PWD=%CD% -set ACTIVATOR_PATH=%PWD% -set ACTIVATOR_BIN=WindowActivator.exe -set PATH=%ACTIVATOR_PATH%;%PATH% - -%ACTIVATOR_PATH%\%ACTIVATOR_BIN% %* diff --git a/activator/windowactivator.sh b/activator/windowactivator.sh deleted file mode 100644 index 2adf516..0000000 --- a/activator/windowactivator.sh +++ /dev/null @@ -1,15 +0,0 @@ -#! /bin/bash - -abspath="$(cd "${0%/*}" 2>/dev/null; echo $PWD/${0##*/})" -absdir=`dirname "$abspath"` - -PWD=`pwd` - -ACTIVATOR=WindowActivator -ACTIVATOR_PATH=${absdir} - -# for coredump file -ulimit -c unlimited - -${ACTIVATOR_PATH}/${ACTIVATOR} "$@" - diff --git a/activator/windowactivator.vbs b/activator/windowactivator.vbs deleted file mode 100644 index 3e63501..0000000 --- a/activator/windowactivator.vbs +++ /dev/null @@ -1,11 +0,0 @@ -Set fso = CreateObject("Scripting.FileSystemObject") -activatorPath = fso.GetParentFolderName(Wscript.scriptFullName) -activatorScript=activatorPath & "\windowactivator.bat" - -For i = 0 To WScript.Arguments.Count - 1 - args = args & Chr(34) & WScript.Arguments(i) & Chr(34) & " " -Next - -set WshShell=WScript.CreateObject("WScript.Shell") -WshShell.run activatorScript & " " & args,0,False -Set WshShell=Nothing diff --git a/daemon/Makefile b/daemon/Makefile deleted file mode 100644 index 6b00a14..0000000 --- a/daemon/Makefile +++ /dev/null @@ -1,53 +0,0 @@ -CURDIR = `pwd` - -INC := -I$(ROOTSTRAP)/usr/include \ - -I$(ROOTSTRAP)/usr/include/system \ - -I$(ROOTSTRAP)/usr/include/telephony \ - -I$(ROOTSTRAP)/usr/include/vconf - -DAEMON_SRCS := \ - da_daemon.c \ - utils.c \ - sys_stat.c - -LDLIBS_PATH := -L$(ROOTSTRAP)/usr/lib -L./lib/ -LIBS_TIZEN :=# -lcapi-system-runtime-info \ - -lcapi-telephony-network-info \ - -lcapi-telephony-call \ - -lSLP-tapi \ - -lsecurity-server-client \ - -lbundle \ - -lail \ - -lxdgmime \ - -ldlog \ - -lSLP-db-util -LIBS_COMMON := -lglib-2.0 \ - -lvconf \ - -laul \ - -lcapi-system-info - -ifeq ($(ARCH),arm) - DEVICE = -DDEVICE_ONLY -endif - -DEBUG_ON := -DDEBUG=1 -FLAGS = -pthread -Wall - -TARGET = da_manager - -all: $(TARGET) - -$(TARGET): $(DAEMON_SRCS) - $(CC) $(SYSROOT) $(INC) $(FLAGS) $(DEBUG_ON) $(DEVICE) -o $@ $(DAEMON_SRCS) $(LDLIBS_PATH) $(LIBS_COMMON) $(LIBS_TIZEN) - -localtest: - $(CC) $(SYSROOT) -DLOCALTEST $(INC) $(FLAGS) -o $(TARGET) $(DEBUG_ON) $(DEVICE) $(LDLIBS_PATH) $(LIBS_COMMON) $(DAEMON_SRCS) - -install: - [ -d "$(CURDIR)/bin" ] || mkdir -p $(CURDIR)/bin - [ -d "$(CURDIR)/bin/$(ARCH)" ] || mkdir -p $(CURDIR)/bin/$(ARCH) - cp $(TARGET) $(CURDIR)/bin/$(ARCH) - -clean: - rm $(TARGET) - diff --git a/daemon/Makefile_arm b/daemon/Makefile_arm deleted file mode 100644 index 9f9f64e..0000000 --- a/daemon/Makefile_arm +++ /dev/null @@ -1,31 +0,0 @@ -SYSROOT = --sysroot=$(HOME)/tizen_sdk/SDK/build-system/rootstraps/tizen-device-1.0 -DAEMON_SRCS := \ - da_daemon.c \ - utils.c \ - sys_stat.c - -ROOTSTRAP = $(HOME)/tizen_sdk/SDK/build-system/rootstraps/tizen-device-1.0 - -INCDIR := -I$(ROOTSTRAP)/usr/include \ - -I$(ROOTSTRAP)/usr/include/system \ - -I$(ROOTSTRAP)/usr/include/telephony \ - -I$(ROOTSTRAP)/usr/include/vconf -LDLIBS_PATH := -L$(ROOTSTRAP)/usr/lib -L./lib/ - -LDLIBS := -lcapi-system-runtime-info -lcapi-telephony-network-info -lcapi-system-info -lcapi-telephony-call -lSLP-tapi -lsecurity-server-client -lvconf -laul -lbundle -lail -lxdgmime -ldlog -lSLP-db-util -lglib-2.0 -#SYSROOT = --sysroot=$(ROOTSTRAP) - -DEVICE = -DDEVICE_ONLY -ARM_CC = $(HOME)/tizen_sdk/SDK/build-system/toolchains/arm-linux-gnueabi-gcc-4.5/bin/arm-linux-gnueabi-gcc -TARGET = da_manager - -DEBUG_ON := -DDEBUG=1 - -all: $(TARGET) - -$(TARGET): - $(ARM_CC) $(SYSROOT) -pthread -o $@ -Wall $(INCDIR) $(DEBUG_ON) $(DEVICE) $(LDLIBS_PATH) $(LDLIBS) $(DAEMON_SRCS) - -clean: - rm $(TARGET) - diff --git a/daemon/Makefile_dibs b/daemon/Makefile_dibs deleted file mode 100644 index d6c6c43..0000000 --- a/daemon/Makefile_dibs +++ /dev/null @@ -1,41 +0,0 @@ -CURDIR = `pwd` - -INC := -I$(ROOTSTRAP)/usr/include \ - -I$(ROOTSTRAP)/usr/include/system \ - -I$(ROOTSTRAP)/usr/include/telephony \ - -I$(ROOTSTRAP)/usr/include/vconf - -DAEMON_SRCS := \ - da_daemon.c \ - utils.c \ - sys_stat.c - -LDLIBS_PATH := -L$(ROOTSTRAP)/usr/lib -L./lib/ -LDLIBS_TIZEN := -lcapi-system-runtime-info -lcapi-telephony-network-info -lcapi-system-info -lcapi-telephony-call -lSLP-tapi -lsecurity-server-client -lvconf -laul -lbundle -lail -lxdgmime -ldlog -lSLP-db-util -LDLIBS_COMMON := -lglib-2.0 - -ifeq ($(ARCH),arm) - DEVICE = -DDEVICE_ONLY -endif - -DEBUG_ON := -DDEBUG=1 -FLAGS = -pthread -Wall - -TARGET = da_manager - -all: $(TARGET) - -$(TARGET): $(DAEMON_SRCS) - $(CC) $(SYSROOT) $(INC) $(FLAGS) -o $@ $(DEBUG_ON) $(DEVICE) $(LDLIBS_PATH) $(LDLIBS_TIZEN) $(LDLIBS_COMMON) $(DAEMON_SRCS) - -localtest: - $(CC) $(SYSROOT) -DLOCALTEST $(INC) $(FLAGS) -o $(TARGET) $(DEBUG_ON) $(DEVICE) $(LDLIBS_PATH) $(LDLIBS_COMMON) $(DAEMON_SRCS) - -install: - [ -d "$(CURDIR)/bin" ] || mkdir -p $(CURDIR)/bin - [ -d "$(CURDIR)/bin/$(ARCH)" ] || mkdir -p $(CURDIR)/bin/$(ARCH) - cp $(TARGET) $(CURDIR)/bin/$(ARCH) - -clean: - rm $(TARGET) - diff --git a/daemon/Makefile_x86 b/daemon/Makefile_x86 deleted file mode 100644 index 79098fa..0000000 --- a/daemon/Makefile_x86 +++ /dev/null @@ -1,34 +0,0 @@ - -DAEMON_SRCS := \ - da_daemon.c \ - utils.c \ - sys_stat.c - -ROOTSTRAP = $(HOME)/tizen_sdk/SDK/build-system/rootstraps/tizen-emulator-1.0 - - -INCDIR := -I$(ROOTSTRAP)/usr/include \ - -I$(ROOTSTRAP)/usr/include/system \ - -I$(ROOTSTRAP)/usr/include/telephony \ - -I$(ROOTSTRAP)/usr/include/vconf -LDLIBS_PATH := -L$(ROOTSTRAP)/usr/lib -L./lib/ - -LDLIBS_TIZEN := -lcapi-system-runtime-info -lcapi-telephony-network-info -lcapi-system-info -lcapi-telephony-call -lSLP-tapi -lsecurity-server-client -lvconf -laul -lbundle -lail -lxdgmime -ldlog -lSLP-db-util -LDLIBS_COMMON := -lglib-2.0 -#SYSROOT = --sysroot=$(ROOTSTRAP) - -TARGET = da_manager - -DEBUG_ON := -DDEBUG=1 - -all: $(TARGET) - -$(TARGET): - $(CC) -pthread -o $@ -Wall $(INCDIR) $(DEBUG_ON) $(DEVICE) $(LDLIBS_PATH) $(LDLIBS_TIZEN) $(LDLIBS_COMMON) $(DAEMON_SRCS) - -localtest: - $(CC) -pthread -o $(TARGET) -Wall $(INCDIR) $(DEBUG_ON) $(DEVICE) -DLOCALTEST $(LDLIBS_PATH) $(LDLIBS_COMMON) $(DAEMON_SRCS) - -clean: - rm $(TARGET) - diff --git a/daemon/da_daemon.c b/daemon/da_daemon.c deleted file mode 100644 index 10f6e89..0000000 --- a/daemon/da_daemon.c +++ /dev/null @@ -1,1670 +0,0 @@ -/* -* DA manager -* -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. -* -* Contact: -* -* Jaewon Lim <jaewon81.lim@samsung.com> -* Woojin Jung <woojin2.jung@samsung.com> -* Juyoung Kim <j0.kim@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 -* -*/ - -#include <stdio.h> -#include <stdlib.h> // for realpath -#include <string.h> // for strtok, strcpy, strncpy -#include <assert.h> // for assert -#include <limits.h> // for realpath - -#define __USE_GNU -#include <sys/types.h> // for socket, mkdir, opendir, readdir -#include <sys/socket.h> // for socket -#include <sys/un.h> // for sockaddr_un -#include <arpa/inet.h> // for sockaddr_in, socklen_t -#include <sys/stat.h> // for chmod, mkdir -#include <sys/time.h> // for setitimer -#include <signal.h> // for sigemptyset, sigset_t, sigaddset, ... -#include <unistd.h> // for unlink -#include <pthread.h> // for pthread_mutex_t -#include <sys/epoll.h> // for epoll apis -#include <sys/ipc.h> // for shmctl -#include <sys/shm.h> // for shared memory operation -#include <dirent.h> // for opendir, readdir - -#include "utils.h" -#include "sys_stat.h" -#include "da_debug.h" - -#define MAX_PATH_LENGTH 256 -#define TARGET_CLIENT_COUNT_MAX 8 -#define READ_BUF_MAX 4096+8 -#define DA_LOG_MAX 4096 -#define APP_INSTALL_PATH_MAX 1024 -#define UDS_NAME "/tmp/da.socket" -#define DA_INSTALL_DIR "/home/developer/sdk_tools/da/" -#define DA_INSTALL_PATH "/home/developer/sdk_tools/da/da_install_path" -#define DA_BUILD_OPTION "/home/developer/sdk_tools/da/da_build_option" -#define DA_BASE_ADDRESS "/home/developer/sdk_tools/da/da_base_address" -#define DA_READELF_PATH "/home/developer/sdk_tools/da/readelf" -#define SCREENSHOT_DIR "/tmp/da" -#define HOST_MSG_LENGTH 3 -#define SHAREDMEMKEY ((key_t)463825) - -#define TIMER_INTERVAL_SEC 1 -#define TIMER_INTERVAL_USEC 0 - -#define SECOND_INTERVAL -#define MONITORING_INTERVAL 1 // 1 second - -#ifdef SECOND_INTERVAL -#define __sleep sleep -#else -#define __sleep usleep -#endif - -#define RUN_APP_LOADER 1 - -enum TargetMessageType -{ - MSG_DEVICE = 1, - MSG_TIME = 2, - MSG_SAMPLE = 3, - MSG_RESOURCE = 4, - MSG_LOG = 5, - MSG_IMAGE = 6, - MSG_TERMINATE = 7, - MSG_PID = 8, - MSG_MSG = 9, - MSG_APPNAME = 10, - MSG_ERROR = 11 -}; - -enum HostMessageType -{ - MSG_HOST_BEGIN = 100, - MSG_START = 100, - MSG_STOP = 101, - MSG_PAUSE = 102, - MSG_OPTION = 103, - MSG_ISALIVE = 104, - MSG_ALIVE = 105, - MSG_BATT_START = 106, - MSG_BATT_STOP = 107, - MSG_HOST_END = 107 -}; - -enum DAState -{ - DAS_NONE = 0, - DAS_START_BEGIN = 1, - DAS_TARGET_ARM_START = 1, - DAS_TARGET_X86_START = 2, - DAS_EMUL_ARM_START = 3, - DAS_EMUL_X86_START = 4, - DAS_TARGET_ARM_BATT_START = 5, - DAS_TARGET_X86_BATT_START = 6, - DAS_EMUL_ARM_BATT_START = 7, - DAS_EMUL_X86_BATT_START = 8, - DAS_START_END = 8, - DAS_STOP = 9, - DAS_TERMINATE = 10 -}; - -typedef struct -{ - int type; - int length; - char data[DA_LOG_MAX]; -} log_t; - -//TODO : -typedef struct -{ - enum DAState status; - int serverSockFD; - int clientSockFD; -} __daHostInfo; - -typedef struct -{ - enum DAState status; - int serverSockFD; - int connectCount; - int pidCount; - int clientSockFD[TARGET_CLIENT_COUNT_MAX]; - int execPID[TARGET_CLIENT_COUNT_MAX]; // exec PID by target -} __daTargetInfo; - -typedef struct -{ - long long allocsize; - long launch_flag; -} __daSharedInfo; - -typedef struct -{ - int memid; - __daSharedInfo* pvalue; -} __daSharedMem; - -typedef struct -{ - pthread_t timer_thread; - pthread_mutex_t sendMutex; - char appPath[128]; // application executable path - __daSharedMem sharedmem; - __daHostInfo iHost; - __daTargetInfo iTarget; -}__daManager; - -__daManager manager = -{ - -1, // timer_thread handle - PTHREAD_MUTEX_INITIALIZER, // pthread_mutex_t sendMutex - { 0, }, // char appPath[128] - { -1, (void*)-1 }, // __daSharedMem sharedmem - { DAS_NONE, -1, -1 }, // __daHostInfo iHost - { DAS_NONE, -1, 0, 0, {0, }, {0, }} // __daTargetInfo iTarget -}; - -int aul_terminate_pid(int pid); -static void* terminate_thread(void* data); -static void terminate_error(char* errstr, int sendtohost); - -#ifdef LOCALTEST -int aul_terminate_pid(int pid) -{ - return kill(pid, SIGTERM); -} -#endif - -int _terminate_pid(int pid) -{ - int ret; - pid_t* pids; - pthread_t term_thread; - - ret = aul_terminate_pid(pid); - - pids = (pid_t*)malloc(2 * sizeof(pid_t)); - pids[0] = pid; - pids[1] = -2; - - pthread_create(&term_thread, NULL, terminate_thread, pids); - - return ret; -} - -// return 0 if succeed -// return -1 if error occured -static int remove_indir(const char *dirname) -{ - DIR *dir; - struct dirent *entry; - char path[MAX_PATH_LENGTH]; - - dir = opendir(dirname); - if(dir == NULL) - { - return -1; - } - - while((entry = readdir(dir)) != NULL) - { - if (strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..")) - { - snprintf(path, (size_t) MAX_PATH_LENGTH, "%s/%s", dirname, entry->d_name); - if (entry->d_type != DT_DIR) // file - { - unlink(path); - } - else { } // directory - } - } - closedir(dir); - - return 0; -} - -// index is started from 0 -int set_launch_flag(int index, int bOn) -{ - int ret = 0; - // set launch flag before execute application - if(__builtin_expect(manager.sharedmem.pvalue != (void*)-1, 1)) - { - if(bOn != 0) - manager.sharedmem.pvalue->launch_flag |= (1 << index); - else - manager.sharedmem.pvalue->launch_flag &= ~(1 << index); - } - else - ret = -1; - - return ret; -} - -long long get_total_alloc_size() -{ - if(__builtin_expect(manager.sharedmem.pvalue != (void*)-1, 1)) - { - return manager.sharedmem.pvalue->allocsize; - } - else - { - return 0L; - } -} - -// return 0 for normal case -static int __makeTargetServerSockFD() -{ - struct sockaddr_un serverAddrUn; - - if(manager.iTarget.serverSockFD != -1) - return -1; // should be never happend - - // remove pre unix domain socket file - // remove(UDS_NAME); - unlink(UDS_NAME); - - if ((manager.iTarget.serverSockFD = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) - { - LOGE("Target server socket creation failed\n"); - return -1; - } - bzero(&serverAddrUn, sizeof(serverAddrUn)); - serverAddrUn.sun_family = AF_UNIX; - sprintf(serverAddrUn.sun_path, "%s", UDS_NAME); - - if (-1 == bind(manager.iTarget.serverSockFD, (struct sockaddr*) &serverAddrUn, - sizeof(serverAddrUn))) - { - LOGE("Target server socket binding failed\n"); - close(manager.iTarget.serverSockFD); - return -1; - } - - chmod(serverAddrUn.sun_path, 0777); - - if (-1 == listen(manager.iTarget.serverSockFD, 5)) - { - LOGE("Target server socket listening failed\n"); - close(manager.iTarget.serverSockFD); - return -1; - } - - LOGI("Created TargetSock %d\n", manager.iTarget.serverSockFD); - return 0; -} - -// return 0 for normal case -static int __makeHostServerSockFD() -{ - struct sockaddr_in serverAddrIn; - int opt = 1; - - if(manager.iHost.serverSockFD != -1) - return -1; // should be never happened - - if ((manager.iHost.serverSockFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) - { - LOGE("Host server socket creation failed\n"); - return -1; - } - - setsockopt(manager.iHost.serverSockFD, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); - memset(&serverAddrIn, 0, sizeof(serverAddrIn)); - serverAddrIn.sin_family = AF_INET; - serverAddrIn.sin_addr.s_addr = htonl(INADDR_ANY); - serverAddrIn.sin_port = htons(8001); - - // bind address to server socket - if (-1 == bind(manager.iHost.serverSockFD, (struct sockaddr*) &serverAddrIn, sizeof(serverAddrIn))) - { - LOGE("Host server socket binding failed\n"); - close(manager.iHost.serverSockFD); - return -1; - } - - // enter listen state from client - if (-1 == listen(manager.iHost.serverSockFD, 5)) - { - LOGE("Host server socket listening failed\n"); - close(manager.iHost.serverSockFD); - return -1; - } - - LOGI("Created HostSock %d\n", manager.iHost.serverSockFD); - return 0; -} - -static int __destroySharedMemory() -{ - int ret = 0; - if(manager.sharedmem.pvalue != (void*)-1) - { - ret = shmdt(manager.sharedmem.pvalue); - if(ret == 0) - manager.sharedmem.pvalue = (void*)-1; - } - - if(manager.sharedmem.memid != -1) - { - ret = shmctl(manager.sharedmem.memid, IPC_RMID, 0); - if(ret == 0) - manager.sharedmem.memid = -1; - } - - return ret; -} - -// return 0 for normal case -// return -1 for error case -static int __createSharedMemory() -{ - manager.sharedmem.memid = shmget(SHAREDMEMKEY, sizeof(__daSharedInfo), IPC_CREAT | 0666); - if(manager.sharedmem.memid == -1) - { - return -1; - } - else - { - manager.sharedmem.pvalue = (__daSharedInfo*)shmat(manager.sharedmem.memid, NULL, 0); - if(manager.sharedmem.pvalue == (void*)-1) - { - __destroySharedMemory(); - return -1; - } - else - { - manager.sharedmem.pvalue->allocsize = 0; - manager.sharedmem.pvalue->launch_flag = 0; - return 0; - } - } -} - -/* -static log_t * parsLogData(log_t * log, char* logStr) -{ -#if 1 - int i, nPos; - - if (logStr == NULL || log == NULL) - return NULL; - - //msgType - for (i = 0, nPos = 0; i < READ_BUF_MAX; i++) - { - if (logStr[i] == '|') - { - logStr[i] = '\0'; - log->type = atoi(&logStr[nPos]); - i++; - break; - } - if (logStr[i] == '\0') - return NULL; - } - //length - for (nPos = i; i < READ_BUF_MAX; i++) - { - if (logStr[i] == '|' || logStr[i] == '\0') - { - logStr[i] = '\0'; - log->length = atoi(&logStr[nPos]); - i++; - break; - } - } - //data - if ((log->length > 0) && (log->length < DA_LOG_MAX)) - { - strncpy(log->data, &logStr[i], log->length); - log->data[log->length] = '\0'; - } - - return log; - -#else - - int i; - char * startPos = logStr; - char tempBuf[READ_BUF_MAX]; - - if(logStr && log) - { - log->type = -1; - log->length = 0; - log->data[0]='\0'; - //type,length - for(i=0; i<READ_BUF_MAX; i++) - { - if(logStr[i]=='|') - { - logStr[i]='\0'; - if(log->type == -1) - { - log->type = atoi(startPos); - startPos = &logStr[i+1]; - } - else { - log->length = atoi(startPos); - startPos = &logStr[i+1]; - break; - } - } - } - //data - if((log->length > 0) && (log->length < DA_LOG_MAX) && (startPos)) - { - strncpy(log->data, startPos, log->length); - log->data[log->length] = '\0'; - } - LOGI("log type : %d, length : %d, data : %s\n", log->type, log->length, log->data); - return log; - } - else - return NULL; -#endif -} -*/ - -static int get_app_type(void) -{ - int fd; - char buf[DA_LOG_MAX]; - - sprintf(buf, "%s.exe", manager.appPath); - fd = open(buf, O_RDONLY); - if(fd != -1) - { - close(fd); - return APP_TYPE_OSP; - } - else - { - return APP_TYPE_TIZEN; - } -} - -static int get_executable(char* buf, int buflen) -{ - int fd; - - sprintf(buf, "%s.exe", manager.appPath); - fd = open(buf, O_RDONLY); - if(fd != -1) - { - close(fd); - } - else - { - strcpy(buf, manager.appPath); - } - return 0; -} - -static int get_app_install_path(char *strAppInstall, int length) -{ - FILE *fp; - char buf[DA_LOG_MAX]; - char *p; - int i; - - if ((fp = fopen(DA_INSTALL_PATH, "r")) == NULL) - { - LOGE("Failed to open %s\n", DA_INSTALL_PATH); - return -1; - } - - /*ex : <15> DW_AT_comp_dir : (indirect string, offset: 0x25f): /home/yt/workspace/templatetest/Debug-Tizen-Emulator */ - while (fgets(buf, DA_LOG_MAX, fp) != NULL) - { - //name - p = buf; - for (i = 0; i < DA_LOG_MAX; i++) - { - if (*p == ':') - break; - p++; - } - - if (*p != ':') - break; - else - p++; - - //(...,offset:...) - for (; i < DA_LOG_MAX; i++) - { - if (*p == '(') - { - while (*p != ')') - { - p++; - } - } - if (*p == ':') - break; - p++; - } - - //find - if (*p != ':') - break; - for (; i < DA_LOG_MAX; i++) - { - if (*p == ':' || *p == ' ' || *p == '\t') - p++; - else - break; - } - - //name - if (strlen(p) <= length) - { - sprintf(strAppInstall, "%s", p); - for (i = 0; i < strlen(p); i++) - { - if (strAppInstall[i] == '\n' || strAppInstall[i] == '\t') - { - strAppInstall[i] = '\0'; - break; - } - } - fclose(fp); - return 1; - } - } - fclose(fp); - return -1; -} - -static int is_app_built_pie(void) -{ - int result; - FILE *fp; - char buf[DA_LOG_MAX]; - - if((fp = fopen(DA_BUILD_OPTION, "r")) == NULL) - { - LOGE("Failed to open %s\n", DA_BUILD_OPTION); - return -1; - } - - if(fgets(buf, DA_LOG_MAX, fp) != NULL) - { - if(strcmp(buf, "DYN\n") == 0) - result = 1; - else if(strcmp(buf, "EXEC\n") == 0) - result = 0; - else - result = -1; - } - else - { - result = -1; - } - fclose(fp); - - return result; -} - -static int get_app_base_address(int *baseAddress) -{ - int res; - FILE *fp; - char buf[DA_LOG_MAX]; - - if((fp = fopen(DA_BASE_ADDRESS, "r")) == NULL) - { - LOGE("Failed to open %s\n", DA_BASE_ADDRESS); - return -1; - } - - if(fgets(buf, DA_LOG_MAX, fp) != NULL) - { - res = sscanf(buf, "%x", baseAddress); - } - else - { - res = -1; - } - fclose(fp); - - return res; -} - -static int is_same_app_process(int pid) -{ - int ret = 0; - FILE *fp; - char buf[DA_LOG_MAX]; - char cmdPath[PATH_MAX]; - char execPath[PATH_MAX]; - - get_executable(execPath, PATH_MAX); - sprintf(cmdPath, "/proc/%d/cmdline", pid); - - if((fp = fopen(cmdPath, "r")) == NULL) - { - return 0; - } - - if(fgets(buf, DA_LOG_MAX, fp) != NULL) - { -#if RUN_APP_LOADER - if(strcmp(buf, manager.appPath) == 0) -#else - // use execPath instead of manager.appPath - if(strcmp(buf, execPath) == 0) -#endif - ret = 1; - else - ret = 0; - } - fclose(fp); - - return ret; -} - -static int sendMsgStrToHost(char* str, int msgType, int targetNo) -{ - static int initialized = 0; - int pid; - int is_pie_build; - int base_address; - int app_type; - char log[DA_LOG_MAX]; - char bufDeviceInfo[DA_LOG_MAX]; - char bufAppInstall[APP_INSTALL_PATH_MAX]; - - switch (msgType) - { - case MSG_LOG: - case MSG_RESOURCE: - case MSG_SAMPLE: - case MSG_ERROR: - if(__builtin_expect(initialized == 0, 0)) - return -1; - sprintf(log, "%d|%s\n", msgType, str); - break; - case MSG_PID: - LOGI("MSG_PID handling : %s\n", str); - pid = atoi(str); - if ((manager.iTarget.execPID[targetNo] != -1) && (pid != manager.iTarget.execPID[targetNo])) - { - LOGE("Failed to check pid, pid of msg(%d), stored pid(%d)\n", pid, manager.iTarget.execPID[targetNo]); - return -1; - } - LOGI("pid[%d]=%d\n",targetNo,pid); - manager.iTarget.execPID[targetNo] = pid; - manager.iTarget.pidCount++; - - { - char execPath[PATH_MAX]; - char realPath[PATH_MAX]; - char mapsPath[PATH_MAX]; - char appInstallCommand[PATH_MAX]; - - get_executable(execPath, PATH_MAX); - if(realpath(execPath, realPath) == NULL) - { - LOGW("Failed to get realpath of app\n"); - strcpy(realPath, execPath); - } - - sprintf(mapsPath, "/proc/%d/maps", manager.iTarget.execPID[targetNo]); - sprintf(appInstallCommand, - "cat %s | grep %s | cut -d\"-\" -f1 > %s", mapsPath, - realPath, DA_BASE_ADDRESS); - LOGI("appInstallCommand is %s\n", appInstallCommand); - - do { - if(access(mapsPath, F_OK) != 0) - return -1; - if(is_same_app_process(manager.iTarget.execPID[targetNo]) == 0) - return -1; - - system(appInstallCommand); - if(get_app_base_address(&base_address) == 1) - break; - sleep(0); - } - while(1); - } - return 0; - break; - case MSG_TIME: - LOGI("MSG_TIME handling : %s\n", str); - if (strlen(manager.appPath) > 0) - { - is_pie_build = is_app_built_pie(); - get_app_base_address(&base_address); - app_type = get_app_type(); - bufAppInstall[0] = '\0'; - get_app_install_path(bufAppInstall, APP_INSTALL_PATH_MAX); - get_device_info(bufDeviceInfo, DA_LOG_MAX); - if (strlen(bufAppInstall) > 0) - { - char buf[PATH_MAX]; - get_executable(buf, PATH_MAX); - sprintf(log, "%d|%s`,%d`,%s`,%d`,%u`,%d`,%s/%s\n", MSG_DEVICE, bufDeviceInfo, - manager.iTarget.execPID[targetNo], str, is_pie_build, base_address, app_type, - bufAppInstall, get_app_name(buf)); - } - else - sprintf(log, "%d|%s`,%d`,%s`,%d`,%u`,%d`,\n", MSG_DEVICE, bufDeviceInfo, - manager.iTarget.execPID[targetNo], str, is_pie_build, base_address, app_type); - LOGI("MSG_DEVICE msg : %s\n", log); - } - else - { - sprintf(log, "%d|%d`,%s", MSG_PID, manager.iTarget.execPID[targetNo], str); - LOGI("MSG_DEVICE msg without appname : %s\n", log); - } - initialized = 1; - break; - case MSG_TERMINATE: - LOGI("MSG_TERMINATE handling : connectCount(%d)\n", manager.iTarget.connectCount); - if(manager.iTarget.connectCount == 1 ){ - sprintf(log, "%d|\n", msgType); - pthread_mutex_lock(&(manager.sendMutex)); -#ifndef LOCALTEST - send(manager.iHost.clientSockFD, log, strlen(log), 0); -#else - LOGI("send to host : %s\n", log); -#endif - pthread_mutex_unlock(&(manager.sendMutex)); - } - return 0; - default: - sprintf(log, "%d|%s\n", msgType, str); - break; - } - - if(manager.iHost.status >= DAS_TARGET_ARM_BATT_START && manager.iHost.status <= DAS_EMUL_X86_BATT_START) - { - LOGI("write batt log\n"); - write_batt_log(log); - } - else - { - if (manager.iHost.clientSockFD != -1) - { - pthread_mutex_lock(&(manager.sendMutex)); -#ifndef LOCALTEST - send(manager.iHost.clientSockFD, log, strlen(log), 0); -#else - LOGI("send to host : %s\n", log); -#endif - pthread_mutex_unlock(&(manager.sendMutex)); - } - } - return 0; -} - -static void* timerThread(void* data) -{ - int err, signo; - char buf[DA_LOG_MAX]; - sigset_t waitsigmask; - - LOGI("Timer thread started\n"); - - sigemptyset(&waitsigmask); - sigaddset(&waitsigmask, SIGALRM); - sigaddset(&waitsigmask, SIGUSR1); - - while(1) - { - err = sigwait(&waitsigmask, &signo); - if(err != 0) - { - LOGE("Failed to sigwait() in timer thread\n"); - continue; - } - - if(signo == SIGALRM) - { - get_resource_info(buf, DA_LOG_MAX, manager.iTarget.execPID, manager.iTarget.pidCount); - sendMsgStrToHost(buf, MSG_RESOURCE, -1); - - if (manager.iTarget.status < DAS_START_BEGIN || manager.iTarget.status > DAS_START_END ) - break; - } - else if(signo == SIGUSR1) - { - // end this thread - break; - } - else - { - // not happened - LOGE("This should not be happend in timer thread\n"); - } - } - - LOGI("Timer thread ended\n"); - return NULL; -} - -// return 0 if normal case -// return minus value if critical error -// return plus value if non-critical error -static int timerStart() -{ - sigset_t newsigmask; - struct itimerval timerval; -// char buf[DA_LOG_MAX]; - - if(manager.timer_thread != -1) // already started - return 1; - - sigemptyset(&newsigmask); - sigaddset(&newsigmask, SIGALRM); - sigaddset(&newsigmask, SIGUSR1); - if(pthread_sigmask(SIG_BLOCK, &newsigmask, NULL) != 0) - { - LOGE("Failed to signal masking for main thread\n"); - return -1; - } - - if(pthread_create(&(manager.timer_thread), NULL, timerThread, NULL) < 0) - { - LOGE("Failed to create timer thread\n"); - return -1; - } - - timerval.it_interval.tv_sec = TIMER_INTERVAL_SEC; - timerval.it_interval.tv_usec = TIMER_INTERVAL_USEC; - timerval.it_value.tv_sec = TIMER_INTERVAL_SEC; - timerval.it_value.tv_usec = TIMER_INTERVAL_USEC; - setitimer(ITIMER_REAL, &timerval, NULL); - - // commected because this resource log send to host before receiving MSG_TIME message from target process - // send initial value of profiling -// get_resource_info(buf, DA_LOG_MAX, manager.iTarget.execPID, manager.iTarget.pidCount); -// sendMsgStrToHost(buf, MSG_RESOURCE, -1); - - return 0; -} - -static int timerStop() -{ - if(manager.timer_thread != -1) - { -// int status; -// sigset_t oldsigmask; - struct itimerval stopval; - -// sigemptyset(&oldsigmask); -// sigaddset(&oldsigmask, SIGALRM); -// sigaddset(&oldsigmask, SIGUSR1); - - stopval.it_interval.tv_sec = 0; - stopval.it_interval.tv_usec = 0; - stopval.it_value.tv_sec = 0; - stopval.it_value.tv_usec = 0; - - // stop timer - setitimer(ITIMER_REAL, &stopval, NULL); - - pthread_kill(manager.timer_thread, SIGUSR1); -// pthread_join(manager.timer_thread, (void**) &status); - -// if(sigprocmask(SIG_UNBLOCK, &oldsigmask, NULL) < 0) -// { -// LOGE("Failed to pthread_sigmask\n"); -// } - manager.timer_thread = -1; - } - __destroySharedMemory(); - - return 0; -} - -#ifdef USE_BATT_LOG -static void wait_for_starting() -{ - static int chargerfd = -1; - while (get_file_status(&chargerfd, CHARGERFD)) - { - LOGI("wait for starting ... \n"); - __sleep(MONITORING_INTERVAL); - } -} -#endif - -static int startProfiling(char* execpath, enum DAState status, long launchflag) -{ - if(__createSharedMemory() < 0) - { - LOGE("Failed to create shared memory\n"); - return -1; - } - - // set launch flag before execute application - manager.sharedmem.pvalue->launch_flag = launchflag; - - // remove previous screen capture files - remove_indir(SCREENSHOT_DIR); - mkdir(SCREENSHOT_DIR, 0777); - - // execute application - if (exec_app(execpath, get_app_type())) - { - manager.iTarget.status = status; - if(timerStart() < 0) - { - return -1; - } - LOGI("Timer Started\n"); - } - else - { - return -1; - } - - return 0; -} - -static void* terminate_thread(void* data) -{ - int i; - FILE* fp; - size_t readbyte; - char cmd[MAX_PATH_LENGTH]; - pid_t* pids = (pid_t*)data; - - sleep(1); - for(i = 0; pids[i] != -2; i++) - { - if(pids[i] != -1) - { - sprintf(cmd, "ps ax | grep %d | grep -v grep", pids[i]); - fp = popen(cmd, "r"); - if(fp) - { - readbyte = fread(cmd, MAX_PATH_LENGTH - 1, 1, fp); - if(readbyte > 0) // process is still alive - { - sprintf(cmd, "kill -9 %d", pids[i]); - system(cmd); - } - pclose(fp); - } - } - } - - free(pids); - - return NULL; -} - -static void terminate_all_target() -{ - int i; - pthread_t term_thread; - pid_t* pids; - - pids = (pid_t*)malloc((manager.iTarget.pidCount + 1) * sizeof(pid_t)); - - for (i = 0; i < manager.iTarget.pidCount; i++) - { - pids[i] = manager.iTarget.execPID[i]; - if(manager.iTarget.execPID[i] != -1) - { - LOGI("TERMINATE process(%d) by terminate_all_target()\n", manager.iTarget.execPID[i]); - aul_terminate_pid(manager.iTarget.execPID[i]); - manager.iTarget.execPID[i] = -1; - } - } - pids[manager.iTarget.pidCount] = -2; - - pthread_create(&term_thread, NULL, terminate_thread, pids); - - manager.iTarget.pidCount = 0; -} - -static void terminate_error(char* errstr, int sendtohost) -{ - LOGE("%s, status(%d)\n", errstr, manager.iHost.status); - manager.iHost.status = DAS_STOP; - - terminate_all_target(); - - timerStop(); - - if(sendtohost) - sendMsgStrToHost(errstr, MSG_ERROR, -1); -} - - -// return 0 if normal case -// return plus value if non critical error occur -// return minus value if critical error occur -static int hostMessageHandler(log_t * log) -{ - int ret = 0; - long flag = 0; - char *barloc, *tmploc; - char execPath[PATH_MAX]; - - if (log == NULL) - return 1; - - switch (log->type) - { - case MSG_START: - LOGI("MSG_START handling : %s\n", log->data); - if (manager.iHost.status >= DAS_START_BEGIN && manager.iHost.status <= DAS_START_END) - { - LOGE("MSG_START status check : %d\n", manager.iHost.status); - return 1; // already started, then ignore this MSG_START message - } - - if(log->length == 0) - return -1; // wrong message format - - // parsing for host start status - tmploc = log->data; - barloc = strchr(tmploc, '|'); - if(barloc != NULL) - { - manager.iHost.status = 0; - while(tmploc < barloc) - { - manager.iHost.status = (manager.iHost.status * 2) + (*tmploc - '0'); - tmploc++; - } - manager.iHost.status += 1; - - if(manager.iHost.status < DAS_START_BEGIN || manager.iHost.status > DAS_START_END) - { - manager.iHost.status = DAS_EMUL_X86_START; - ret = 1; - } - } - else - { - return -1; // wrong message format - } - - // parsing for target launch option flag - tmploc = barloc + 1; - barloc = strchr(tmploc, '|'); - if(barloc != NULL) - { - while(tmploc < barloc) - { - flag = (flag * 2) + (*tmploc - '0'); - tmploc++; - } - } - else - { - return -1; // wrong message format - } - - // parsing for application package name - tmploc = barloc + 1; - strcpy(manager.appPath, tmploc); - -#ifdef USE_BATT_LOG - if(manager.iHost.status == DAS_EMUL_ARM_BATT_START || - manager.iHost.status == DAS_EMUL_X86_BATT_START) - wait_for_starting(); -#endif - - get_executable(execPath, PATH_MAX); // get exact app executable file name -#if RUN_APP_LOADER - kill_app(manager.appPath); -#else - // use execPath instead of manager.appPath - kill_app(execPath); -#endif - sleep(0); - - LOGI("executable app path %s\n", manager.appPath); - - { - char appInstallCommand[PATH_MAX]; - - //save app install path - mkdir(DA_INSTALL_DIR, 0775); - sprintf(appInstallCommand, - "%s -Wwi %s | grep DW_AT_comp_dir > %s", DA_READELF_PATH, - execPath, DA_INSTALL_PATH); - LOGI("appInstallCommand %s\n", appInstallCommand); - system(appInstallCommand); - - sprintf(appInstallCommand, - "%s -h %s | grep Type | cut -d\" \" -f33 > %s", DA_READELF_PATH, - execPath, DA_BUILD_OPTION); - LOGI("appInstallCommand %s\n", appInstallCommand); - system(appInstallCommand); - -#if RUN_APP_LOADER - if(startProfiling(manager.appPath, manager.iHost.status, flag) < 0) -#else - // use execPath instead of manager.appPath - if(startProfiling(execPath, manager.iHost.status, flag) < 0) -#endif - { - terminate_error("Cannot start profiling", 1); - return -1; - } - } - break; - case MSG_STOP: - LOGI("MSG_STOP handling\n"); - if (manager.iHost.status < DAS_START_BEGIN || manager.iHost.status > DAS_START_END) - { - // already stopped, not possible, ignore MSG_STOP message - LOGE("MSG_STOP status check : %d\n", manager.iHost.status); - return 1; - } - - manager.iHost.status = DAS_STOP; - terminate_all_target(); - timerStop(); - break; - case MSG_OPTION: - if(log->length > 0) - { - if(log->data[0] == '0') - { - set_launch_flag(1, 0); - LOGI("Snapshot disabled\n"); - } - else if(log->data[0] == '1') - { - set_launch_flag(1, 1); - LOGI("Snapshot enabled\n"); - } - else - { - LOGI("Wrong option message from host\n"); - } - } - break; - case MSG_ISALIVE: - sendMsgStrToHost(NULL, MSG_ALIVE, 0); - break; - -#ifdef USE_BATT_LOG - case MSG_BATT_START: - { - manager.iHost.status = DAS_BATT_START; - sprintf(manager.appPath, "%s", log->data); - create_open_batt_log(get_app_name(manager.appPath)); - wait_for_starting(); - if(startProfiling(manager.appPath, DAS_BATT_START, flag) < 0) - { - terminate_error("Cannot start profiling", 1); - return -1; - } -// batt_start(manager.appPath); - } - break; - case MSG_BATT_STOP: - manager.iHost.status = DAS_BATT_STOP; - timerStop(); -// batt_stop(); - break; -#endif - - default: - LOGW("Unknown msg\n"); - } - - return ret; -} - -static int parseHostMessage(log_t* log, char* msg) -{ - int i; - int bfind = 0; - - if(log == NULL || msg == NULL) - return 0; - - // Host message looks like this - // MSG_TYPE|MSG_LENGTH|MSG_STRING - // MSG_TYPE is always 3 digits number - if(msg[3] == '|') - { - msg[3] = '\0'; - log->type = atoi(msg); - - if(log->type < MSG_HOST_BEGIN || log->type > MSG_HOST_END) - return 0; - - msg = msg + 4; - for(i = 0; msg[i] != '\0'; i++) - { - if(msg[i] == '|') - { - bfind = 1; - msg[i] = '\0'; - break; - } - } - - if(bfind != 0) - { - int msglen; - log->length = atoi(msg); - msg = msg + i + 1; - msglen = strlen(msg); - - if(log->length == 0) - { - log->data[0] = '\0'; - } - else - { - if(msglen == log->length) - strcpy(log->data, msg); - else if(msglen > log->length) // parsing error but deal as nonerror - strncpy(log->data, msg, log->length); - else - return 0; // parsing error - - log->data[log->length] = '\0'; - } - } - else - { - return 0; // parsing error - } - - return 1; // parsing success - } - else - { - return 0; // parsing error - } -} - -#define EPOLL_SIZE 10 -#define MAX_CONNECT_SIZE 12 -#define MAX_INAROW_TARGET_MSG 10 - -// return 0 for normal case -static int work() -{ - struct sockaddr_un clientAddrUn; //target - struct sockaddr_in clientAddrIn; //host - int i, k, find; - ssize_t recvLen; - char recvBuf[READ_BUF_MAX]; - log_t log; - - struct epoll_event ev, *events; - int efd; // epoll fd - int numevent; // number of occured events - - // initialize epoll event pool - events = (struct epoll_event*) malloc(sizeof(struct epoll_event) * EPOLL_SIZE); - if(events == NULL) - { - LOGE("Out of memory when allocate epoll event pool\n"); - return -1; - } - if((efd = epoll_create(MAX_CONNECT_SIZE)) < 0) - { - LOGE("epoll creation error\n"); - free(events); - return -1; - } - - // add server sockets to epoll event pool - ev.events = EPOLLIN; - ev.data.fd = manager.iHost.serverSockFD; - if(epoll_ctl(efd, EPOLL_CTL_ADD, manager.iHost.serverSockFD, &ev) < 0) - { - LOGE("Host server socket epoll_ctl error\n"); - free(events); - close(efd); - return -1; - } - ev.events = EPOLLIN; - ev.data.fd = manager.iTarget.serverSockFD; - if(epoll_ctl(efd, EPOLL_CTL_ADD, manager.iTarget.serverSockFD, &ev) < 0) - { - LOGE("Target server socket epoll_ctl error\n"); - free(events); - close(efd); - return -1; - } - - // handler loop - while (1) - { - numevent = epoll_wait(efd, events, EPOLL_SIZE, -1); - if(numevent <= 0) - { - LOGE("Failed to epoll_wait : num of event(%d), errno(%d)\n", numevent, errno); - continue; - } - - for(i = 0; i < numevent; i++) - { - find = 0; - for(k = 0; k < manager.iTarget.connectCount; k++) - { - if(events[i].data.fd == manager.iTarget.clientSockFD[k]) - { - // read from target process - recvLen = recv(manager.iTarget.clientSockFD[k], &log, - sizeof(log.type) + sizeof(log.length), 0); - - // send to host - if (recvLen > 0) - { - int count = 0; - do { - if (log.length > 0) - recv(manager.iTarget.clientSockFD[k], log.data, log.length, 0); - log.data[log.length] = '\0'; - if(log.type == 5) // MSG_LOG - { - switch(log.data[0]) - { - case '2': // UI control creation log - case '3': // UI event log - case '6': // UI lifecycle log - case '7': // screnshot log - case '8': // scene transition log - LOGI("%dclass|%s\n", log.data[0] - '0', log.data); - break; - default: - break; - } - } - else if(log.type == 6) // MSG_IMAGE - { - LOGI("MSG_IMAGE received\n"); - } - else // not MSG_LOG and not MSG_IMAGE - { - LOGI("Extra MSG TYPE (%d|%d|%s)\n", log.type, log.length, log.data); - } - sendMsgStrToHost(log.data, log.type, k); - if(count++ > MAX_INAROW_TARGET_MSG) - break; - } while ((recvLen = recv(manager.iTarget.clientSockFD[k], - &log, sizeof(log.type) + sizeof(log.length), MSG_DONTWAIT)) > 0); - } - - // close request from target client socket - if(recvLen == 0) - { - LOGI("target close = %d(total %d)\n", manager.iTarget.clientSockFD[k], manager.iTarget.connectCount - 1); - if(epoll_ctl(efd, EPOLL_CTL_DEL, manager.iTarget.clientSockFD[k], NULL) < 0) - { - LOGE("Failed to epoll_ctl delete fd from event poll\n"); - } - close(manager.iTarget.clientSockFD[k]); - LOGI("Terminate %dth pid(%d)\n", k, manager.iTarget.execPID[k]); - // consume that target process is already in terminating phase -// _terminate_pid(manager.iTarget.execPID[k]); - manager.iTarget.connectCount--; - if(manager.iTarget.execPID[k] != -1) - manager.iTarget.pidCount--; -// assert(manager.iTarget.connectCount == manager.iTarget.pidCount); - if (manager.iTarget.connectCount == 0) // all target client are closed - { - manager.iTarget.status = DAS_TERMINATE; - - LOGI("Exit daemon process\n"); - manager.iTarget.clientSockFD[k] = -1; - manager.iTarget.execPID[k] = -1; - timerStop(); - free(events); - close(efd); - return 0; - } - else - { - manager.iTarget.clientSockFD[k] = manager.iTarget.clientSockFD[manager.iTarget.connectCount]; - manager.iTarget.clientSockFD[manager.iTarget.connectCount] = -1; - manager.iTarget.execPID[k] = manager.iTarget.execPID[manager.iTarget.pidCount]; - manager.iTarget.execPID[manager.iTarget.pidCount] = -1; - } - } - - find = 1; - break; - } - } - if(find == 0) // this event is not from target client socket - { - // connect request from target - if(events[i].data.fd == manager.iTarget.serverSockFD) - { - socklen_t addrlen; - addrlen = sizeof(clientAddrUn); - manager.iTarget.clientSockFD[manager.iTarget.connectCount] = - accept(manager.iTarget.serverSockFD, (struct sockaddr *) &clientAddrUn, &addrlen); - - if(manager.iTarget.clientSockFD[manager.iTarget.connectCount] >= 0) // accept succeed - { - ev.events = EPOLLIN; - ev.data.fd = manager.iTarget.clientSockFD[manager.iTarget.connectCount]; - if(epoll_ctl(efd, EPOLL_CTL_ADD, manager.iTarget.clientSockFD[manager.iTarget.connectCount], &ev) < 0) - { - // consider as accept fail - LOGE("Target client epoll_ctl error\n"); - manager.iTarget.clientSockFD[manager.iTarget.connectCount] = -1; - } - else - { - LOGI("target connect = %d(total%d)\n", - manager.iTarget.clientSockFD[manager.iTarget.connectCount], manager.iTarget.connectCount + 1); - manager.iTarget.connectCount++; - } - } - else // accept error - { - LOGE("Failed to accept from target server socket\n"); - } - } - // connect request from host - else if(events[i].data.fd == manager.iHost.serverSockFD) - { - socklen_t addrlen; - addrlen = sizeof(clientAddrIn); - if(manager.iHost.clientSockFD != -1) - { - if(epoll_ctl(efd, EPOLL_CTL_DEL, manager.iHost.clientSockFD, NULL) < 0) - { - LOGE("Failed to delete host client socket from epoll ctrl queue\n"); - } - close(manager.iHost.clientSockFD); - LOGI("Host client socket is closed, fd(%d)\n", manager.iHost.clientSockFD); - } - manager.iHost.clientSockFD = accept(manager.iHost.serverSockFD, (struct sockaddr *) &clientAddrIn, &addrlen); - - if(manager.iHost.clientSockFD >= 0) // accept succeed - { - ev.events = EPOLLIN; - ev.data.fd = manager.iHost.clientSockFD; - if(epoll_ctl(efd, EPOLL_CTL_ADD, manager.iHost.clientSockFD, &ev) < 0) - { - // consider as accept fail - close(manager.iHost.clientSockFD); - manager.iHost.clientSockFD = -1; - terminate_error("Host client epoll_ctl error", 1); - } - else - { - LOGI("host connect = %d\n", manager.iHost.clientSockFD); - } - } - else // accept error - { - LOGE("Failed to accept from host server socket\n"); - } - } - // message from host - else if(events[i].data.fd == manager.iHost.clientSockFD) - { - // host log format xxx|length|str - LOGI("Host client socket selected(Message from host)\n"); - recvLen = recv(manager.iHost.clientSockFD, recvBuf, READ_BUF_MAX, 0); - - if (recvLen > 0) - { - recvBuf[recvLen] = '\0'; - LOGI("host sent this msg len(%d) str(%s)\n", recvLen, recvBuf); - if(parseHostMessage(&log, recvBuf) == 0) - { - // error to parse host message - sendMsgStrToHost("host log message is unrecognizable", MSG_ERROR, -1); - continue; - } - - //host msg command handling - if(hostMessageHandler(&log) < 0) - { - terminate_error("Host message handling error", 1); - free(events); - close(efd); - return 0; - } - } - else // close request from HOST - { - // work loop quit - if(manager.iHost.status >= DAS_START_BEGIN && manager.iHost.status <= DAS_START_END) - { - // host client socket end unexpectly - terminate_error("Host client socket closed unexpectly", 0); - } - LOGI("host close = %d\n", manager.iHost.clientSockFD); - free(events); - close(efd); - return 0; - } - } - else - { - // never happened - LOGW("Unknown socket fd\n"); - } - } - } - } - - free(events); - close(efd); - return 0; -} - -// return 0 for normal case -static int initialize_manager() -{ - int i; - // make server socket - if(__makeTargetServerSockFD() != 0) - return -1; - if(__makeHostServerSockFD() != 0) - return -1; - - // initialize target client sockets - for (i = 0; i < TARGET_CLIENT_COUNT_MAX; i++) - { - manager.iTarget.clientSockFD[i] = -1; - manager.iTarget.execPID[i] = -1; - } - - // initialize sendMutex - pthread_mutex_init(&(manager.sendMutex), NULL); - - if(initialize_system_info() < 0) - return -1; - - return 0; -} - -static int finalize_manager() -{ - int i; - - finalize_system_info(); - - terminate_all_target(); - - LOGI("Finalize daemon\n"); - - // finalize target client sockets - for (i = 0; i < TARGET_CLIENT_COUNT_MAX; i++) - { - if(manager.iTarget.clientSockFD[i] != -1) - close(manager.iTarget.clientSockFD[i]); - } - - // close host client socket - if(manager.iHost.clientSockFD != -1) - close(manager.iHost.clientSockFD); - - // close server socket - if(manager.iHost.serverSockFD != -1) - close(manager.iHost.serverSockFD); - if(manager.iTarget.serverSockFD != -1) - close(manager.iTarget.serverSockFD); - - return 0; -} - -static void __attribute((destructor)) exit_func() -{ - __destroySharedMemory(); -} - -int main() -{ -#if DEBUG - write_log(); -#endif - - //for terminal exit - signal(SIGHUP, SIG_IGN); - chdir("/"); - - //new session reader - setsid(); - - // initialize manager - if(initialize_manager() == 0) - { - //daemon work - work(); - - finalize_manager(); - return 0; - } - else - return 1; -} diff --git a/daemon/da_debug.h b/daemon/da_debug.h deleted file mode 100644 index 9d53da9..0000000 --- a/daemon/da_debug.h +++ /dev/null @@ -1,54 +0,0 @@ -/* -* DA manager -* -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. -* -* Contact: -* -* Jaewon Lim <jaewon81.lim@samsung.com> -* Woojin Jung <woojin2.jung@samsung.com> -* Juyoung Kim <j0.kim@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 -* -*/ - -#ifndef _DA_DEBUG_H_ -#define _DA_DEBUG_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#if DEBUG - #define LOGI(...) do{ fprintf(stderr, "[INF]" __VA_ARGS__ ); fflush(stderr); } while(0) - #define LOGE(...) do{ fprintf(stderr, "[ERR]" __VA_ARGS__ ); fflush(stderr); } while(0) - #define LOGW(...) do{ fprintf(stderr, "[WRN]" __VA_ARGS__ ); fflush(stderr); } while(0) -#else - #define LOGI(...) do{} while(0) - #define LOGE(...) do{} while(0) - #define LOGW(...) do{} while(0) -#endif - - - - - -#ifdef __cplusplus -} -#endif - -#endif // _DA_DEBUG_H_ diff --git a/daemon/sys_stat.c b/daemon/sys_stat.c deleted file mode 100644 index 9bc4350..0000000 --- a/daemon/sys_stat.c +++ /dev/null @@ -1,2019 +0,0 @@ -/* -* DA manager -* -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. -* -* Contact: -* -* Jaewon Lim <jaewon81.lim@samsung.com> -* Woojin Jung <woojin2.jung@samsung.com> -* Juyoung Kim <j0.kim@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 -* -*/ - -#include <stdio.h> -#include <stdbool.h> -#include <ctype.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <unistd.h> -#include <dirent.h> - -#ifndef LOCALTEST -#include <system_info.h> -#include <runtime_info.h> -#include <telephony_network.h> -#include <call.h> -#endif - -#define USE_VCONF - -#ifdef USE_VCONF -#include "vconf.h" -#endif - -#include "sys_stat.h" -#include "da_debug.h" - -// defines for runtime environment -#define FOR_EACH_CPU - - -#define BUFFER_MAX 1024 -#define LARGE_BUFFER 512 -#define MIDDLE_BUFFER 256 -#define SMALL_BUFFER 64 -#define PROCPATH_MAX 32 -#define STATUS_STRING_MAX 16 -#define MAX_NUM_OF_FREQ 16 - -#define MEM_SLOT_TOTAL 0 -#define MEM_SLOT_FREE 1 -#define MEM_SLOT_BUFFER 2 -#define MEM_SLOT_CACHED 3 -#define MEM_SLOT_MAX 4 - -#define MIN_TICKS_FOR_LOAD 8 -#define MIN_TOTAL_TICK 10 -#define SYS_INFO_TICK 100 // TODO : change to (Hertz * profiling period) - -#define CPUMHZ "cpu MHz" -#define DA_PROBE_TIZEN_SONAME "da_probe_tizen.so" -#define DA_PROBE_OSP_SONAME "da_probe_osp.so" - -#ifndef likely -#define likely(x) __builtin_expect((x), 1) -#define unlikely(x) __builtin_expect((x), 0) -#endif - -enum PROCESS_DATA -{ - PROCDATA_STAT, - PROCDATA_SMAPS -}; - -long long get_total_alloc_size(); - -// declared by greatim -static int Hertz = 0; -static int num_of_cpu = 0; -static int num_of_freq = 0; -static unsigned long mem_slot_array[MEM_SLOT_MAX]; -static CPU_t* cpus = NULL; -static unsigned long probe_so_size = 0; - -// utility function -int get_flag_num(unsigned int flag) -{ - int i; - for(i = 0; flag != 0; i++) - { - flag &= (flag - 1); - } - return i; -} - - - -// daemon api : get status from file -// pfd must not be null -int get_file_status(int* pfd, const char* filename) -{ - int status = 0; - -#ifndef LOCALTEST - if(likely(pfd != NULL)) - { - char buf[STATUS_STRING_MAX]; - - if(unlikely(*pfd < 0)) // open file first - { - *pfd = open(filename, O_RDONLY); - if(unlikely(*pfd == -1)) - { - return -(errno); - } - } - else - { - lseek(*pfd, 0, SEEK_SET); // rewind to start of file - } - - // read from file - if(unlikely(read(*pfd, buf, STATUS_STRING_MAX) == -1)) - { - status = -(errno); - } - else - { - status = atoi(buf); - } - } -#endif - - return status; -} - -// ============================================================================== -// device status information getter functions -// ============================================================================== -static int get_wifi_status() -{ - int wifi_status = 0; - -#ifndef LOCALTEST - #ifdef USE_VCONF - if (unlikely(vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_status) < 0)) - { - wifi_status = VCONFKEY_WIFI_OFF; - } - #else - if (unlikely(runtime_info_get_value_int( - RUNTIME_INFO_KEY_WIFI_STATUS, &wifi_status) < 0)) - { - wifi_status = RUNTIME_INFO_WIFI_STATUS_DISABLED; - } - #endif // USE_VCONF -#endif - - return wifi_status; -} - -static int get_bt_status() -{ - int bt_status = false; - -#ifndef LOCALTEST - #ifdef USE_VCONF - if (unlikely(vconf_get_int(VCONFKEY_BT_STATUS, &bt_status) < 0)) - { - bt_status = VCONFKEY_BT_STATUS_OFF; - } - #else - if (unlikely(runtime_info_get_value_bool( - RUNTIME_INFO_KEY_BLUETOOTH_ENABLED, (bool*)&bt_status) < 0)) - { - bt_status = 0; - } - #endif // USE_VCONF -#endif - - return bt_status; -} - -static int get_gps_status() -{ - int gps_status = 0; - -#ifndef LOCALTEST - #ifdef USE_VCONF - if(unlikely(vconf_get_bool(VCONFKEY_LOCATION_ENABLED, &gps_status) < 0)) - { - gps_status = VCONFKEY_LOCATION_GPS_OFF; - } - else if(gps_status != 0) - { - if (unlikely(vconf_get_int(VCONFKEY_LOCATION_GPS_STATE, &gps_status) < 0)) - { - gps_status = VCONFKEY_LOCATION_GPS_OFF; - } - } - #else - if (unlikely(runtime_info_get_value_bool( - RUNTIME_INFO_KEY_LOCATION_SERVICE_ENABLED, (bool*)&gps_status) < 0)) - { - gps_status = 0; - } - else if(gps_status != 0) - { - if (unlikely(runtime_info_get_value_bool( - RUNTIME_INFO_KEY_LOCATION_ADVANCED_GPS_ENABLED, (bool*)&gps_status) < 0)) - { - gps_status = 0; - } - else if(gps_status != 0) - { - if(unlikely(runtime_info_get_value_int( - RUNTIME_INFO_KEY_GPS_STATUS, &gps_status) < 0)) - { - gps_status = 0; - } - else - { - // do nothing (gps_status is real gps status) - } - } - else - { - // do nothing (gps_status == 0) - } - } - else - { - // do nothing (gps_status == 0) - } - #endif // USE_VCONF -#endif - - return gps_status; -} - -static int get_brightness_status() -{ - static int brightnessfd = -1; - int brightness_status = 0; - -#ifndef LOCALTEST - #ifdef DEVICE_ONLY - DIR* dir_info; - struct dirent* dir_entry; - char fullpath[PATH_MAX]; - - dir_info = opendir(BRIGHTNESS_PARENT_DIR); - if(dir_info != NULL) - { - while((dir_entry = readdir(dir_info)) != NULL) - { - if(strcmp(dir_entry->d_name, ".") == 0 || strcmp(dir_entry->d_name, "..") == 0) - continue; - else // first directory - { - sprintf(fullpath, BRIGHTNESS_PARENT_DIR "/%s/" BRIGHTNESS_FILENAME, dir_entry->d_name); - brightness_status = get_file_status(&brightnessfd, fullpath); - } - } - } - else - { - // do nothing - } - #else - brightness_status = get_file_status(&brightnessfd, EMUL_BRIGHTNESSFD); - #endif -#endif // LOCALTEST - - return brightness_status; -} - -static int get_max_brightness() -{ - int maxbrightnessfd = -1; - static int max_brightness = -1; - -#ifndef LOCALTEST - if(__builtin_expect(max_brightness < 0, 0)) - { - #ifdef DEVICE_ONLY - DIR* dir_info; - struct dirent* dir_entry; - char fullpath[PATH_MAX]; - - dir_info = opendir(BRIGHTNESS_PARENT_DIR); - if(dir_info != NULL) - { - while((dir_entry = readdir(dir_info)) != NULL) - { - if(strcmp(dir_entry->d_name, ".") == 0 || strcmp(dir_entry->d_name, "..") == 0) - continue; - else // first directory - { - sprintf(fullpath, BRIGHTNESS_PARENT_DIR "/%s/" MAX_BRIGHTNESS_FILENAME, dir_entry->d_name); - max_brightness = get_file_status(&maxbrightnessfd, fullpath); - } - } - } - else - { - // do nothing - } - #else - max_brightness = get_file_status(&maxbrightnessfd, EMUL_MAX_BRIGHTNESSFD); - #endif - } - - if(maxbrightnessfd != -1) - close(maxbrightnessfd); -#endif // LOCALTEST - - return max_brightness; -} - -static int get_video_status() -{ - static int videofd = -1; - int video_status = 0; - -#ifndef LOCALTEST - video_status = get_file_status(&videofd, MFCFD); - if (video_status > 1) - video_status = 0; -#endif - - return video_status; -} - -static int get_rssi_status() -{ -#ifndef LOCALTEST - int flightmode_status; - - #ifdef USE_VCONF - int rssi_status; - if(unlikely(vconf_get_bool(VCONFKEY_SETAPPL_FLIGHT_MODE_BOOL, - &flightmode_status) < 0)) - { - flightmode_status = 0; - } - - if(!flightmode_status) - { - if(unlikely(vconf_get_int(VCONFKEY_TELEPHONY_RSSI, &rssi_status) < 0)) - { - rssi_status = VCONFKEY_TELEPHONY_RSSI_0; - } - } - else - { - rssi_status = VCONFKEY_TELEPHONY_RSSI_0; - } - - return rssi_status; - #else - network_info_rssi_e rssi_status; - - if(unlikely(runtime_info_get_value_bool( - RUNTIME_INFO_KEY_FLIGHT_MODE_ENABLED, (bool*)&flightmode_status) < 0)) - { - flightmode_status = 0; - } - - if(!flightmode_status) - { - if(unlikely(network_info_get_rssi(&rssi_status) < 0)) - { - rssi_status = NETWORK_INFO_RSSI_0; - } - } - else - { - rssi_status = NETWORK_INFO_RSSI_0; - } - - return (int)rssi_status; - #endif // USE_VCONF -#else - return 0; -#endif -} - -static int get_call_status() -{ - int call_status = 0; - -#ifndef LOCALTEST - #ifdef USE_VCONF - if(unlikely(vconf_get_int(VCONFKEY_CALL_STATE, &call_status) < 0)) - { - call_status = VCONFKEY_CALL_OFF; - } - #else - call_state_e call_state; - if(unlikely(call_get_voice_call_state(&call_state) < 0)) - { - if(unlikely(call_get_video_call_state(&call_state) < 0)) - { - call_status = 0; // call idle - } - else - { - // return video call state - if(call_state == CALL_STATE_CONNECTING) - call_status = 3; - else if(call_state == CALL_STATE_ACTIVE) - call_status = 4; - } - } - else if(call_state == CALL_STATE_IDLE) // voice call state is idle - { - if(unlikely(call_get_video_call_state(&call_state) < 0)) - { - call_status = 0; - } - else - { - // return video call state - if(call_state == CALL_STATE_CONNECTING) - call_status = 3; - else if(call_state == CALL_STATE_ACTIVE) - call_status = 4; - } - } - else - { - // return voice call state - if(call_state == CALL_STATE_CONNECTING) - call_status = 1; - else if(call_state == CALL_STATE_ACTIVE) - call_status = 2; - } - #endif // USE_VCONF -#endif - - return call_status; -} - -// dnet means 3G? -static int get_dnet_status() -{ - int dnet_status = false; - -#ifndef LOCALTEST - #ifdef USE_VCONF - if(unlikely(vconf_get_int(VCONFKEY_DNET_STATE, &dnet_status) < 0)) - { - dnet_status = VCONFKEY_DNET_OFF; - } - #else - if(unlikely(runtime_info_get_value_bool( - RUNTIME_INFO_KEY_PACKET_DATA_ENABLED, (bool*)&dnet_status) < 0)) - { - dnet_status = 0; - } - #endif // USE_VCONF -#endif - - return dnet_status; -} - -static int get_camera_status() -{ - int camera_status = 0; - -#ifndef LOCALTEST -#if 0 - #ifdef USE_VCONF - if(unlikely(vconf_get_int(VCONFKEY_CAMERA_STATE, &camera_status) < 0)) - { - camera_status = VCONFKEY_CAMERA_OFF; - } - #endif // USE_VCONF -#endif -#endif - - return camera_status; -} - -// this means silent mode? -static int get_sound_status() -{ - int sound_status = 0; - -#ifndef LOCALTEST - #ifdef USE_VCONF - if(unlikely(vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, - &sound_status) < 0)) - { - sound_status = 0; - } - #else - if(unlikely(runtime_info_get_value_bool( - RUNTIME_INFO_KEY_SILENT_MODE_ENABLED, (bool*)&sound_status) < 0)) - { - sound_status = 0; - } - else - { - sound_status = (sound_status == 1) ? 0 : 1; // slient mode - } - #endif // USE_VCONF -#endif - - return sound_status; -} - -static int get_audio_status() -{ - int audio_state = 0; - -#ifndef LOCALTEST - -#ifdef DEVICE_ONLY - int ret = 0; - char dev[40]; - char state[3]; - FILE *fp = NULL; - - fp = fopen(AUDIOFD, "r"); - if(fp == NULL) - return -1; - - while(ret != EOF) - { - ret = fscanf(fp, "%[^:] %*c %[^\n] ", dev, state); - if(strncmp(dev,"SPKR",4) == 0 && strncmp(state, "On",2) == 0) - { - audio_state = 1; - } - else if(ret == 2 && strncmp(dev,"Head",4) == 0 && strncmp(state, "On",2) == 0) - { - audio_state = 2; - break; - } - } - - fclose(fp); -#endif - -#endif // LOCALTEST - - return audio_state; -} - -static int get_vibration_status() -{ - int vibration_status = 0; - -#ifndef LOCALTEST - #ifdef USE_VCONF - if(unlikely(vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, - &vibration_status) < 0)) - { - vibration_status = 0; - } - #else - if(unlikely(runtime_info_get_value_bool( - RUNTIME_INFO_KEY_VIBRATION_ENABLED, (bool*)&vibration_status) < 0)) - { - vibration_status = 0; - } - #endif // USE_VCONF -#endif - - return vibration_status; -} - -static int get_voltage_status() -{ - static int voltagefd = -2; - return get_file_status(&voltagefd, VOLTAGEFD); -} - -// ===================================================================== -// cpu information getter functions -// ===================================================================== -static int get_cpu_frequency() -{ - static int frequencyfd = -2; - int ret = -1; - - if(frequencyfd != -1) // first time or file is exist - ret = get_file_status(&frequencyfd, FREQFD); - - if(ret < 0) // error occured - { - FILE* cpufp; - char buf[SMALL_BUFFER]; - int strsize = strlen(CPUMHZ); - double freq; - - cpufp = fopen(PROCCPUINFO, "r"); - if(likely(cpufp != NULL)) - { - while(fgets(buf, SMALL_BUFFER, cpufp) != NULL) - { - if(strncmp(buf, CPUMHZ, strsize) == 0) - { - freq = atof(strchr(buf, ':') + 1); - ret = (int)(freq * 1000.0); - break; - } - } - - fclose(cpufp); - } - else - { // do nothing - } - } - - if(ret < 0) - ret = 0; - - return ret; -} - -// ======================================================================== -// get cpu and memory info for each process and whole system -// ======================================================================== -typedef struct _proc_node { - proc_t proc_data; - unsigned long long saved_utime; - unsigned long long saved_stime; - int found; - struct _proc_node *next; -} procNode; - -static procNode *prochead = NULL; -static procNode *thread_prochead = NULL; - -static procNode* find_node(procNode *head, pid_t pid) -{ - procNode *t = head; - - while (t != NULL) { - if (t->proc_data.pid == pid) - { - t->found = 1; - break; - } - t = t->next; - } - return t; -} - -static procNode* add_node(procNode **head, pid_t pid) -{ - procNode *n; - - n = (procNode *) malloc(sizeof(procNode)); - if (n == NULL) { - LOGE("Not enough memory, add cpu info node failied"); - return NULL; - } - - n->proc_data.pid = pid; - n->found = 1; - n->next = *head; - *head = n; - - return n; -} - -static int del_node(procNode **head, pid_t pid) -{ - procNode *t; - procNode *prev; - - t = *head; - prev = NULL; - while (t != NULL) { - if (t->proc_data.pid == pid) { - if (prev != NULL) - prev->next = t->next; - else - *head = (*head)->next; - free(t); - break; - } - prev = t; - t = t->next; - } - - return 0; -} - -static int del_notfound_node(procNode **head) -{ - procNode *proc, *prev; - prev = NULL; - for(proc = *head; proc != NULL; ) - { - if(proc->found == 0) - { - if(prev != NULL) - { - prev->next = proc->next; - free(proc); - proc = prev->next; - } - else - { - *head = (*head)->next; - free(proc); - proc = *head; - } - } - else - { - prev = proc; - proc = proc->next; - } - } - return 0; -} - -static int reset_found_node(procNode *head) -{ - procNode* proc; - for(proc = head; proc != NULL; proc = proc->next) - { - proc->found = 0; - } - return 0; -} - -// return 0 for normal case -// return negative value for error case -static int parse_proc_stat_file_bypid(char *path, proc_t* P) -{ - char filename[PROCPATH_MAX]; - char buf[BUFFER_MAX]; - int fd, num; - char *abuf, *bbuf; - - // read from stat file - sprintf(filename, "%s/stat", path); - fd = open(filename, O_RDONLY, 0); - - if(unlikely(fd == -1)) - return -1; - - num = read(fd, buf, BUFFER_MAX); - close(fd); - - if(unlikely(num <= 0)) - return -1; - - buf[num] = '\0'; - - // scan from buffer - // copy command name - abuf = strchr(buf, '(') + 1; - bbuf = strrchr(buf, ')'); - num = bbuf - abuf; - if(unlikely(num >= sizeof(P->command))) - num = sizeof(P->command) - 1; - memcpy(P->command, abuf, num); - P->command[num] = '\0'; - abuf = bbuf + 2; - - // scan data - - sscanf(abuf, - "%c " - "%d %d %d %d %d " - "%lu %lu %lu %lu %lu " - "%Lu %Lu %Lu %Lu " // utime stime cutime cstime - "%ld %ld " - "%d " - "%ld " - "%Lu " // start_time - "%lu " - "%ld", - &P->state, - &P->ppid, &P->pgrp, &P->sid, &P->tty_nr, &P->tty_pgrp, - &P->flags, &P->minor_fault, &P->cminor_fault, &P->major_fault, &P->cmajor_fault, - &P->utime, &P->stime, &P->cutime, &P->cstime, - &P->priority, &P->nice, - &P->numofthread, - &P->dummy, - &P->start_time, - &P->vir_mem, - &P->res_memblock - ); - - if(P->numofthread == 0) - P->numofthread = 1; - - return 0; -} - -// return 0 for normal case -// return negative value for error case -static int parse_proc_smaps_file_bypid(char *path, proc_t* P) -{ -#define MIN_SMAP_BLOCKLINE 50 - - char filename[PROCPATH_MAX]; - char buf[MIDDLE_BUFFER]; - char numbuf[SMALL_BUFFER]; - FILE* fp; - - // reset pss size of proc_t - P->pss = 0; - - // read from smaps file - sprintf(filename, "%s/smaps", path); - fp = fopen(filename, "r"); - - if(fp == NULL) - return -1; - - if(unlikely(probe_so_size == 0)) // probe so size is not abtained - { - int is_probe_so = 0; - while(fgets(buf, MIDDLE_BUFFER, fp) != NULL) - { - if(strncmp(buf, "Pss:", 4) == 0) // line is started with "Pss:" - { - sscanf(buf, "Pss:%s kB", numbuf); - P->pss += atoi(numbuf); - if(is_probe_so == 1) - { - probe_so_size += atoi(numbuf); - is_probe_so = 0; // reset search flag - } - } - else // not Pss line - { - if(is_probe_so == 0 && strlen(buf) > MIN_SMAP_BLOCKLINE) // first we find probe so section - { - if(strstr(buf, DA_PROBE_TIZEN_SONAME) != NULL || - strstr(buf, DA_PROBE_OSP_SONAME) != NULL) // found probe.so - { - is_probe_so = 1; - } - else - { - // do nothing - } - } - else - { - // do nothing - } - } - } - } - else // we know about probe.so size already - { - while(fgets(buf, MIDDLE_BUFFER, fp) != NULL) - { - if(strncmp(buf, "Pss:", 4) == 0) - { - sscanf(buf, "Pss:%s kB", numbuf); - P->pss += atoi(numbuf); - } - } - } - - P->pss -= probe_so_size; - - fclose(fp); - - return 0; -} - -// return 0 for normal case -// return positive value for non critical case -// return negative value for critical case -static int update_process_data(int* pidarray, int pidcount, enum PROCESS_DATA datatype) -{ - static struct stat sb; - int i, ret = 0; - char buf[PROCPATH_MAX]; - procNode* procnode; - - for(i = 0; i < pidcount; i++) - { - if (pidarray[i] == 0) // pid is invalid - { - ret = 1; - continue; - } - - sprintf(buf, "/proc/%d", pidarray[i]); - if (unlikely(stat(buf, &sb) == -1)) // cannot access anymore - { - del_node(&prochead, pidarray[i]); - ret = errno; - continue; - } - - if ((procnode = find_node(prochead, pidarray[i])) == NULL) // new process - { - procnode = add_node(&prochead, pidarray[i]); - if(datatype == PROCDATA_STAT) - { - if (unlikely((ret = parse_proc_stat_file_bypid(buf, &(procnode->proc_data))) < 0)) - { - LOGE("Failed to get proc stat file by pid(%d)\n", pidarray[i]); - } - else - { - procnode->saved_utime = procnode->proc_data.utime; - procnode->saved_stime = procnode->proc_data.stime; - } - } - else if(datatype == PROCDATA_SMAPS) - { - if (unlikely((ret = parse_proc_smaps_file_bypid(buf, &(procnode->proc_data))) < 0)) - { - LOGE("Failed to get proc smaps file by pid(%d)\n", pidarray[i]); - } - else - { // do nothing - } - } - else - { // impossible - } - } - else - { - if(datatype == PROCDATA_STAT) - { - if (unlikely((ret = parse_proc_stat_file_bypid(buf, &(procnode->proc_data))) < 0)) - { - LOGE("Failed to get proc stat file by pid(%d)\n", pidarray[i]); - } - else - { // do nothing - } - } - else if(datatype == PROCDATA_SMAPS) - { - if (unlikely((ret = parse_proc_smaps_file_bypid(buf, &(procnode->proc_data))) < 0)) - { - LOGE("Failed to get proc smaps file by pid(%d)\n", pidarray[i]); - } - else - { // do nothing - } - } - else - { // impossible - } - } - } - - del_notfound_node(&prochead); - reset_found_node(prochead); - - return ret; -} - -static int update_system_cpu_frequency(int cur_index) -{ - char buf[SMALL_BUFFER]; - char filename[SMALL_BUFFER]; - int i, j; - FILE* fp; - - // execute this block only once - if(unlikely(num_of_freq <= 0)) - { - FILE* fp; - num_of_freq = 0; - if((fp = fopen(CPUNUM_OF_FREQ, "r")) != NULL) - { - while(fgets(buf, SMALL_BUFFER, fp) != NULL) - { - num_of_freq++; - } - fclose(fp); - } - else - { - LOGW("Cannot open cpu0 frequency file\n"); - return -11; - } - - for(i = 0; i < num_of_cpu; i++) - { - if(cpus[i].pfreq == NULL) - { - cpus[i].pfreq = (cpufreq_t*) calloc(num_of_freq, sizeof(cpufreq_t)); - } - } - } - - sprintf(filename, CPUNUM_OF_FREQ); - // update cpu frequency information - for(i = 0; i < num_of_cpu; i++) - { - filename[27] = (char)('0' + i); - fp = fopen(filename, "r"); - if(fp != NULL) - { - for(j = 0; j < num_of_freq; j++) - { - if(fgets(buf, SMALL_BUFFER, fp) != NULL) - { - sscanf(buf, "%lu %Lu", &(cpus[i].pfreq[j].freq), - &(cpus[i].pfreq[j].tick)); - } - else // cannot read anymore from frequency info file - break; - } - - fclose(fp); - cpus[i].cur_freq_index = cur_index; - } - else // cannot load cpu frequency information - { // do nothing - } - } - - return 0; -} - -// return 0 for normal case -// return negative value for error -static int update_system_cpu_data(int cur_index) -{ - static FILE* fp = NULL; - int num; - char buf[BUFFER_MAX]; - - if(fp == NULL) - { - if((fp = fopen(PROCSTAT, "r")) == NULL) - { - LOGE("Failed to open " PROCSTAT "\n"); - return -1; - } - } - - rewind(fp); - fflush(fp); - - if(fgets(buf, sizeof(buf), fp) == NULL) - { - LOGE("Failed to read first line of " PROCSTAT "\n"); -// fclose(fp); - return -1; - } - - cpus[num_of_cpu].x = 0; - cpus[num_of_cpu].y = 0; - cpus[num_of_cpu].z = 0; - num = sscanf(buf, "cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu", - &cpus[num_of_cpu].u, - &cpus[num_of_cpu].n, - &cpus[num_of_cpu].s, - &cpus[num_of_cpu].i, - &cpus[num_of_cpu].w, - &cpus[num_of_cpu].x, - &cpus[num_of_cpu].y, - &cpus[num_of_cpu].z - ); - cpus[num_of_cpu].cur_load_index = cur_index; - if(num < 4) - { - LOGE("Failed to read from " PROCSTAT "\n"); -// fclose(fp); - return -1; - } - -#ifdef FOR_EACH_CPU - // and just in case we're 2.2.xx compiled without SMP support... - if(num_of_cpu == 1) - { - cpus[0].id = cpus[1].id = 0; - memcpy(cpus, &cpus[1], sizeof(tic_t) * 8); - cpus[0].cur_load_index = cur_index; - } - else if(num_of_cpu > 1) - { - int i; - // now value each separate cpu's tics - for(i = 0; i < num_of_cpu; i++) - { - if(fgets(buf, sizeof(buf), fp) != NULL) - { - cpus[i].x = 0; - cpus[i].y = 0; - cpus[i].z = 0; - num = sscanf(buf, "cpu%u %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu", - &cpus[i].id, - &cpus[i].u, &cpus[i].n, &cpus[i].s, &cpus[i].i, - &cpus[i].w, &cpus[i].x, &cpus[i].y, &cpus[i].z); - if(num > 4) - { - LOGI("Readed %d stats of %dth cpu\n", num, i); - cpus[i].cur_load_index = cur_index; - } - else // buf is not cpu core tick information - { // do nothing - } - } - else // cannot read anymore from /proc/stat file - { // do nothing - } - } - } - else - { - // not possible -// fclose(fp); - return -1; - } -#endif - -// fclose(fp); - return 0; -} - -// return 0 for normal case -// return negative value for error -static int update_system_memory_data(unsigned long *memtotal, unsigned long *memused) -{ - static int meminfo_fd = -1; - char *head, *tail; - int i, num; - char buf[BUFFER_MAX]; - static const mem_t mem_table[] = { - {"Buffers", &mem_slot_array[MEM_SLOT_BUFFER]}, - {"Cached", &mem_slot_array[MEM_SLOT_CACHED]}, - {"MemFree", &mem_slot_array[MEM_SLOT_FREE]}, - {"MemTotal", &mem_slot_array[MEM_SLOT_TOTAL]}, - }; - const int mem_table_size = sizeof(mem_table) / sizeof(mem_t); - - if(meminfo_fd == -1 && (meminfo_fd = open(PROCMEMINFO, O_RDONLY)) == -1) - { - LOGE("Failed to open " PROCMEMINFO "\n"); - return -1; - } - lseek(meminfo_fd, 0L, SEEK_SET); - if((num = read(meminfo_fd, buf, BUFFER_MAX)) < 0) - { - LOGE("Failed to read from " PROCMEMINFO "\n"); - return -1; - } - buf[num] = '\0'; - - num = 0; // number of found element - head = buf; - for( ;num < mem_table_size ; ) - { - tail = strchr(head, ':'); - if(!tail) - break; - *tail = '\0'; - for(i = 0; i < mem_table_size; i++) - { - if(strcmp(head, mem_table[i].name) == 0) // found - { - head = tail + 1; - *(mem_table[i].slot) = strtoul(head, &tail, 10); - num++; - break; - } - } - if(i == mem_table_size) // cannot find entry - head = tail + 1; - tail = strchr(head, '\n'); - if(tail == NULL) - break; - head = tail + 1; - } - - if(num == mem_table_size) // find all element - { - *memtotal = mem_slot_array[MEM_SLOT_TOTAL]; - *memused = mem_slot_array[MEM_SLOT_TOTAL] - mem_slot_array[MEM_SLOT_FREE] - - mem_slot_array[MEM_SLOT_BUFFER] - mem_slot_array[MEM_SLOT_CACHED]; - - *memtotal *= 1024; // change to Byte - *memused *= 1024; // change to Byte - return 0; - } - else - { - LOGE("Cannot find all neccessary element in meminfo\n"); - return -1; - } -} - -// return 0 for error case -// return system total memory in MB -static unsigned long get_system_total_memory() -{ - int meminfo_fd = -1; - char *head, *tail; - int num; - char buf[BUFFER_MAX]; - static const char* memtotalstr = "MemTotal"; - unsigned long totalmem = 0; - - if((meminfo_fd = open(PROCMEMINFO, O_RDONLY)) == -1) - { - LOGE("Failed to open " PROCMEMINFO "\n"); - return 0; - } - if((num = read(meminfo_fd, buf, BUFFER_MAX)) < 0) - { - LOGE("Failed to read from " PROCMEMINFO "\n"); - return 0; - } - buf[num] = '\0'; - close(meminfo_fd); - - head = buf; - for( ; ; ) - { - tail = strchr(head, ':'); - if(!tail) - break; - *tail = '\0'; - if(strcmp(head, memtotalstr) == 0) // found - { - head = tail + 1; - totalmem = strtoul(head, &tail, 10); - break; - } - - head = tail + 1; - tail = strchr(head, '\n'); - if(tail == NULL) - break; - head = tail + 1; - } - - return (totalmem * 1024); -} - -// =============================================================== -// disk information getter functions -// =============================================================== -static int get_fsinfo(const char* path, int type) -{ - struct statfs buf; - int total; - int free; - - if (statfs(path, &buf) < 0) - { - return -errno; - } - - total = (int)((long long)(buf.f_bsize / 1024LL * buf.f_blocks) / 1024LL); - free = (int)((long long)(buf.f_bsize / 1024LL * buf.f_bavail) / 1024LL); - - LOGI("File storage total(%d), free(%d)\n", total, free); - if (type == FSINFO_TYPE_TOTAL) - { - return total; - } - else if (type == FSINFO_TYPE_FREE) - { - return free; - } - - return -1; -} - -static int stat_get_storageinfo(int type) -{ - return get_fsinfo(UMSFD, type); -} - -static int stat_get_cardinfo(int type) -{ - if (access(MMCBLKFD, F_OK) < 0) - { - return -1; - } - - return get_fsinfo(MMCFD, type); -} - - -static int get_total_drive() -{ - int total = 0; - int storage = stat_get_storageinfo(FSINFO_TYPE_TOTAL); - int card = stat_get_cardinfo(FSINFO_TYPE_TOTAL); - - if (storage < 0 && card < 0) - { - return -1; - } - - total = storage + card; - - return total; -} - -static int get_total_used_drive() -{ - int total = 0; - int free = 0; - int storage = stat_get_storageinfo(FSINFO_TYPE_FREE); - int card = stat_get_cardinfo(FSINFO_TYPE_FREE); - - if (storage < 0 && card < 0) - { - return -1; - } - - free = storage + card; - total = get_total_drive() - free; - - return total; -} - -static int update_thread_data(int pid) -{ - static struct stat sb; - int ret = 0; - char path[PROCPATH_MAX]; - char buf[PROCPATH_MAX]; - procNode* procnode; - DIR *taskdir = NULL; - struct dirent *entry = NULL; - unsigned int tid; - - sprintf(path, "/proc/%d/task", pid); - - if(!(taskdir = opendir(path))) - { - return -1; - } - - while((entry = readdir(taskdir)) != NULL) - { - if(*entry->d_name > '0' && *entry->d_name <= '9') - { - tid = atoi(entry->d_name); - sprintf(buf, "/proc/%d/task/%d", pid, tid); - - if(unlikely(stat(buf, &sb) == -1)) - { - del_node(&thread_prochead, tid); - ret = errno; - continue; - } - - if((procnode = find_node(thread_prochead, tid)) == NULL) - { - procnode = add_node(&thread_prochead, tid); - if(unlikely((ret = parse_proc_stat_file_bypid(buf, &(procnode->proc_data))) < 0)) - { - LOGE("Failed to get proc stat file by tid(%d)\n", tid); - } - else - { - procnode->saved_utime = procnode->proc_data.utime; - procnode->saved_stime = procnode->proc_data.stime; - } - } - else - { - if(unlikely((ret = parse_proc_stat_file_bypid(buf, &(procnode->proc_data))) < 0)) - { - LOGE("Failed to get proc stat file by tid(%d)\n", tid); - } - } - } - } - - del_notfound_node(&thread_prochead); - reset_found_node(thread_prochead); - - closedir(taskdir); - return ret; -} - -// ======================================================================== -// overall information getter functions -// ======================================================================== - -// this code is not necessary anymore -/* -static void get_app_info(const char* binary_path, char* width, - char* height, char* theme, char* version, - char* scale, char* removable, - char* comment) -{ - int fd = 0; - int res = 0; - int i = 0; - int j = 0; - char pkg_info_path [PATH_MAX]; - char buffer [BUFFER_MAX]; - - sprintf(pkg_info_path, "/opt/share/applications/%s.desktop", pkg_name); - - fd = open(pkg_info_path, O_RDONLY); - if (fd < 0) - { - LOGE("Cannot open %s", pkg_info_path); - return; - } - - fcntl( fd, F_SETFD, FD_CLOEXEC ); - - LOGI("get_app_info - After open pkg_info_path\n"); - - for (;;) - { - res = read(fd, buffer, BUFFER_MAX); - if (res == 0) - { - break; - } - if (res < 0) - { - if (errno == EINTR) - continue; - else - break; - } - - LOGI("read buffer ===%s===\n", buffer); - for (i = 0; i < res; i++) - { - if (i < res - 22 && strncmp(&buffer[i], "X-SLP-BaseLayoutWidth=", 22) == 0) - { - for (j = 0; j < res; j ++) - { - if (buffer[i+j] == '\n' || buffer[i+j] == '\t') - { - LOGI("width :::: "); - strncpy(width, &(buffer[i+22]), j-22); - LOGI("%s\n", width); - break; - } - } - i = i + j; - } - else if (i < res - 23 && strncmp(&buffer[i], "X-SLP-BaseLayoutHeight=", 23) == 0) - { - for (j = 0; j < res; j ++) - { - if (buffer[i+j] == '\n' || buffer[i+j] == '\t') - { - LOGI("height :::: "); - strncpy(height, &(buffer[i+23]), j-23); - LOGI("%s\n", height); - break; - } - } - i = i + j; - } - else if (i < res - 6 && (strncmp(&buffer[i], "theme=", 6) == 0 || strncmp(&buffer[i], "Theme=", 6) == 0)) - { - for (j = 0; j < res; j ++) - { - if (buffer[i+j] == '\n' || buffer[i+j] == '\t') - { - LOGI("theme :::: "); - strncpy(theme, &(buffer[i+6]), j-6); - LOGI("%s\n", theme); - break; - } - } - i = i + j; - } - else if (i < res - 8 && (strncmp(&buffer[i], "Version=", 8) == 0 || strncmp(&buffer[i], "version=", 8) == 0)) - { - for (j = 0; j < res; j ++) - { - if (buffer[i+j] == '\n' || buffer[i+j] == '\t') - { - LOGI("version :::: "); - strncpy(version, &(buffer[i+8]), j-8); - LOGI("%s\n", version); - break; - } - } - i = i + j; - } - else if (i < res - 24 && strncmp(&buffer[i], "X-SLP-IsHorizontalScale=", 24) == 0) - { - for (j = 0; j < res; j ++) - { - if (buffer[i+j] == '\n' || buffer[i+j] == '\t') - { - LOGI("scale :::: "); - strncpy(scale, &(buffer[i+24]), j-24); - LOGI("%s\n", scale); - break; - } - } - i = i + j; - } - else if (i < res - 16 && strncmp(&buffer[i], "X-SLP-Removable=", 16) == 0) - { - for (j = 0; j < res; j ++) - { - if (buffer[i+j] == '\n' || buffer[i+j] == '\t') - { - LOGI("removable :::: "); - strncpy(removable, &(buffer[i+16]), j-16); - LOGI("%s\n", removable); - break; - } - } - i = i + j; - } - else if (i < res - 8 && (strncmp(&buffer[i], "Comment=", 8) == 0 || strncmp(&buffer[i], "comment=", 8) == 0)) - { - for (j = 0; j < res; j ++) - { - if (buffer[i+j] == '\n' || buffer[i+j] == '\t') - { - LOGI("comments :::: "); - strncpy(comment, &(buffer[i+8]), j-8); - LOGI("%s\n", comment); - break; - } - } - i = i + j; - } - } - } - - close(fd); -} -*/ - -static int get_device_availability_info(char* buf, int buflen) -{ - int camera_count = 0; - bool blue_support = false; - bool gps_support = false; - bool wifi_support = false; - char* networktype = NULL; - int loglen = 0; - -#ifndef LOCALTEST - system_info_get_value_bool(SYSTEM_INFO_KEY_BLUETOOTH_SUPPORTED, &blue_support); - system_info_get_value_int(SYSTEM_INFO_KEY_CAMERA_COUNT, &camera_count); - system_info_get_value_bool(SYSTEM_INFO_KEY_GPS_SUPPORTED, &gps_support); - system_info_get_value_string(SYSTEM_INFO_KEY_NETWORK_TYPE, &networktype); - system_info_get_value_bool(SYSTEM_INFO_KEY_WIFI_SUPPORTED, &wifi_support); -#endif - - loglen += sprintf(buf, "%d`,%d`,%d`,%d`,", - (int)blue_support, - (int)gps_support, - (int)wifi_support, - camera_count); - - if(networktype != NULL) - { - loglen += sprintf(buf + loglen, "%s", networktype); - free(networktype); - } - else - { - // do nothing - } - - return loglen; -} - -int get_device_info(char* buffer, int buffer_len) -{ - int res = 0; -/* - char width[BUFFER_MAX]; - char height[BUFFER_MAX]; - char theme[BUFFER_MAX]; - char version[BUFFER_MAX]; - char scale[BUFFER_MAX]; - char removable[BUFFER_MAX]; - char comment[BUFFER_MAX * 2]; - - memset(width, 0, sizeof(width)); - memset(height, 0, sizeof(height)); - memset(theme, 0, sizeof(theme)); - memset(version, 0, sizeof(version)); - memset(scale, 0, sizeof(scale)); - memset(removable, 0, sizeof(removable)); - memset(comment, 0, sizeof(comment)); -*/ - res += sprintf(buffer, "%lu`,%d`,", get_system_total_memory(), get_total_drive()); - res += get_device_availability_info(buffer + res, buffer_len - res); - res += sprintf(buffer + res, "`,%d", get_max_brightness()); - - res += sprintf(buffer + res, "`,`,`,`,`,`,`,"); -// res += sprintf(buffer + res, "`,%s`,%s`,%s`,%s`,%s`,%s`,%s", width, height, theme, version, scale, removable, comment); - - return res; -} - -// return log length (>0) for normal case -// return negative value for error -int get_resource_info(char* buffer, int buffer_len, int* pidarray, int pidcount) -{ - static struct timeval old_time = {0, 0}; - static int event_num = 0; - - int res = 0; - int i, j; - float elapsed; - float factor; - procNode* proc; - CPU_t* cpuptr; - struct timeval current_time; - - // data variable - unsigned long virtual = 0; - unsigned long resident = 0; - unsigned long shared = 0; - unsigned long pssmem = 0; - int num_thread = 0; - unsigned long long ticks = 0, freqsum; - float app_cpu_usage, sys_usage, thread_load; - unsigned long sysmemtotal = 0; - unsigned long sysmemused = 0; - unsigned long curtime; -// long long idle_tick_sum = 0, total_tick_sum = 0; - int call_time = 0; - int rssi_time = 0; - - // buffers - char thread_loadbuf[LARGE_BUFFER] = {0, }; - char thread_loadtmpbuf[SMALL_BUFFER]; - char freqbuf[MIDDLE_BUFFER]; - char cpuload[SMALL_BUFFER]; - int freqbufpos = 0; - int cpuloadpos = 0; -// unsigned int failed_cpu = 0; - - LOGI("PID count : %d\n", pidcount); - - if(update_process_data(pidarray, pidcount, PROCDATA_STAT) < 0) - { - LOGE("Failed to update process stat data\n"); - return -1; - } - - // this position is optimized position of timestamp. - // just before get system cpu data and just after get process cpu data - // because cpu data is changed so fast and variance is so remarkable - gettimeofday(¤t_time, NULL); // DO NOT MOVE THIS SENTENCE! - - if(update_system_cpu_data(event_num) < 0) - { - LOGE("Failed to update system cpu data\n"); - return -1; - } - - // freqbufpos is temporary used - freqbufpos = update_system_cpu_frequency(event_num); - - // memory data is changed slowly and variance is not remarkable - // so memory data is less related with timestamp then cpu data - if(update_process_data(pidarray, pidcount, PROCDATA_SMAPS) < 0) - { - LOGE("Failed to update process smaps data\n"); - return -1; - } - - if(update_thread_data(pidarray[0]) < 0) - { - LOGE("Failed to update thread stat data\n"); - return -1; - } - - if(update_system_memory_data(&sysmemtotal, &sysmemused) < 0) - { - LOGE("Failed to update system memory data\n"); - return -1; - } - - // prepare calculate - elapsed = (current_time.tv_sec - old_time.tv_sec) + - ((float)(current_time.tv_usec - old_time.tv_usec) / 1000000.0f); - old_time.tv_sec = current_time.tv_sec; - old_time.tv_usec = current_time.tv_usec; - curtime = ((unsigned long)current_time.tv_sec * 10000) + - ((unsigned long)current_time.tv_usec / 100); - - factor = 100.0f / ((float)Hertz * elapsed * num_of_cpu); - - - // calculate process for process - for(proc = prochead; proc != NULL; proc = proc->next) - { - num_thread += proc->proc_data.numofthread; - virtual += proc->proc_data.vir_mem; // Byte - resident += (proc->proc_data.res_memblock * 4); // KByte - pssmem += (proc->proc_data.pss); // KByte - ticks += (proc->proc_data.utime + proc->proc_data.stime - proc->saved_utime - proc->saved_stime); - - proc->saved_utime = proc->proc_data.utime; - proc->saved_stime = proc->proc_data.stime; - } - app_cpu_usage = (float)ticks * factor; - if(app_cpu_usage > 100.0f) - app_cpu_usage = 100.0f; - resident = resident * 1024; // change to Byte - pssmem = pssmem * 1024; // change to Byte - - // calculate thread load - for(proc = thread_prochead; proc != NULL; proc = proc->next) - { - thread_load = (float)(proc->proc_data.utime + proc->proc_data.stime - proc->saved_utime - proc->saved_stime) - * factor; - if(thread_load > 100.0f) - thread_load = 100.0f; - - sprintf(thread_loadtmpbuf, "%d,%.1f,", proc->proc_data.pid, thread_load); - strcat(thread_loadbuf, thread_loadtmpbuf); - - proc->saved_utime = proc->proc_data.utime; - proc->saved_stime = proc->proc_data.stime; - } - - // calculate for system cpu load -#ifdef FOR_EACH_CPU - for(i = 0; i < num_of_cpu; i++) -#else - for(i = num_of_cpu; i <= num_of_cpu; i++) -#endif - { - cpuptr = &(cpus[i]); - - if(cpuptr->cur_load_index == event_num) - { - if(cpuptr->sav_load_index == event_num - 1) // previous sampling is just before 1 period - { - cpuptr->idle_ticks = cpuptr->i - cpuptr->i_sav; - if(unlikely(cpuptr->idle_ticks < 0)) - { - cpuptr->idle_ticks = 0; - } - cpuptr->total_ticks = (cpuptr->u - cpuptr->u_sav) + - (cpuptr->s - cpuptr->s_sav) + - (cpuptr->n - cpuptr->n_sav) + - cpuptr->idle_ticks + - (cpuptr->w - cpuptr->w_sav) + - (cpuptr->x - cpuptr->x_sav) + - (cpuptr->y - cpuptr->y_sav) + - (cpuptr->z - cpuptr->z_sav); - if(cpuptr->total_ticks < MIN_TOTAL_TICK) - { - cpuptr->cpu_usage = 0.0f; - } - else - { - cpuptr->cpu_usage = (1.0f - ((float)cpuptr->idle_ticks / (float)cpuptr->total_ticks)) * 100.0f; - } -// if(i != num_of_cpu) -// { -// idle_tick_sum += cpuptr->idle_ticks; -// total_tick_sum += cpuptr->total_ticks; -// } - LOGI("System cpu usage log : %d, %Ld, %Ld\n", i, cpuptr->idle_ticks, cpuptr->total_ticks); - if(unlikely(cpuptr->cpu_usage < 0)) - { - cpuptr->cpu_usage = 0.0f; - } - } - else // previous sampling is not just before 1 period - { - // assume non idle ticks happen in 1 profiling period - // because sampling is not available just before 1 profiling period - cpuptr->idle_ticks = (cpuptr->u - cpuptr->u_sav) + - (cpuptr->s - cpuptr->s_sav) + - (cpuptr->n - cpuptr->n_sav) + - (cpuptr->w - cpuptr->w_sav) + - (cpuptr->x - cpuptr->x_sav) + - (cpuptr->y - cpuptr->y_sav) + - (cpuptr->z - cpuptr->z_sav); - cpuptr->total_ticks = (long long)(Hertz * elapsed); - if(unlikely(cpuptr->total_ticks < 1)) - cpuptr->total_ticks = 1; - cpuptr->cpu_usage = ((float)cpuptr->idle_ticks / (float)cpuptr->total_ticks) * 100.0f; - if(unlikely(cpuptr->cpu_usage > 100.0f)) - { - cpuptr->cpu_usage = 100.0f; - } - } - - // save new value - cpuptr->u_sav = cpuptr->u; - cpuptr->s_sav = cpuptr->s; - cpuptr->n_sav = cpuptr->n; - cpuptr->i_sav = cpuptr->i; - cpuptr->w_sav = cpuptr->w; - cpuptr->x_sav = cpuptr->x; - cpuptr->y_sav = cpuptr->y; - cpuptr->z_sav = cpuptr->z; - cpuptr->sav_load_index = cpuptr->cur_load_index; - } - else - { - cpuptr->cpu_usage = 0.0f; - } - } - -#ifdef FOR_EACH_CPU - // calculate for cpu core load that failed to get tick information -/* - if(failed_cpu != 0) - { - LOGI("ticks1 : %Ld, %Ld\n", idle_tick_sum, total_tick_sum); - idle_tick_sum = cpus[num_of_cpu].idle_ticks - idle_tick_sum; - total_tick_sum = cpus[num_of_cpu].total_ticks - total_tick_sum; - LOGI("ticks2 : %Ld, %Ld\n", idle_tick_sum, total_tick_sum); - if(total_tick_sum >= MIN_TICKS_FOR_LOAD) - sys_usage = (1.0f - ((float)idle_tick_sum / (float)total_tick_sum)) * 100.0f; - else - sys_usage = 0.0f; - if(sys_usage < 0.0f) sys_usage = 0.0f; - else if(sys_usage > 100.0f) sys_usage = 100.0f; - - for(i = 0; i < num_of_cpu; i++) - { - if(failed_cpu & (1 << i)) - { - cpus[i].cpu_usage = sys_usage; - } - } - } -*/ - - // calculate for whole cpu load by average all core load - sys_usage = 0.0f; - for(i = 0 ; i < num_of_cpu; i++) - { - sys_usage += cpus[i].cpu_usage; - } - cpus[num_of_cpu].cpu_usage = sys_usage / num_of_cpu; - - // make cpu load string - for(i = 0; i <= num_of_cpu; i++) - { - cpuloadpos += sprintf(cpuload + cpuloadpos, "%.1f,", cpus[i].cpu_usage); - } - cpuload[cpuloadpos - 1] = '\0'; // remove last , -#else - sprintf(cpuload, "%.1f", cpus[num_of_cpu].cpu_usage); -#endif - - // calculate for system cpu frequency - if(freqbufpos >= 0) - { - sys_usage = 0.0f; - freqbufpos = 0; - ticks = 0; - freqsum = 0; - for(i = 0; i < num_of_cpu; i++) - { - cpuptr = &(cpus[i]); - - if(cpuptr->cur_freq_index == event_num) - { - if(cpuptr->sav_freq_index == event_num - 1) - { - for(j = 0; j < num_of_freq; j++) - { - freqsum += (cpuptr->pfreq[j].freq * - (cpuptr->pfreq[j].tick - cpuptr->pfreq[j].tick_sav)); - ticks += (cpuptr->pfreq[j].tick - cpuptr->pfreq[j].tick_sav); - } - } - else - { // do nothing - } - - for(j = 0; j < num_of_freq; j++) - { - cpuptr->pfreq[j].tick_sav = cpuptr->pfreq[j].tick; // restore last tick value - } - cpuptr->sav_freq_index = cpuptr->cur_freq_index; - } - -#ifdef FOR_EACH_CPU - if(ticks != 0) - { - if(sys_usage == 0.0f) - sys_usage = (float)freqsum / (float)ticks; - freqbufpos += sprintf(freqbuf + freqbufpos, "%.0f,", (float)freqsum / (float)ticks); - } - else - { - freqbufpos += sprintf(freqbuf + freqbufpos, "%.0f,", sys_usage); - } - ticks = 0; - freqsum = 0; -#endif - } -#ifndef FOR_EACH_CPU - freqbufpos += sprintf(freqbuf + freqbufpos, "%.0f", (float)freqsum / (float)ticks); -#else - freqbuf[freqbufpos - 1] = '\0'; // remove last , -#endif - } - else // update system cpu frequency is failed - { - freqbufpos = get_cpu_frequency(); - sprintf(freqbuf, "%d", (freqbufpos > 0)? freqbufpos : 0); - } - - // print log - res = sprintf(buffer, "9`," - "%d`,%d`,%lu`," // event number, reserved, current time - "%d`,%d`,%d`," // device status(wifi, bt, gps) - "%d`,%d`,%d`," // device status(bright, camera, sound) - "%d`,%d`,%d`," // device status(audio, vibration, voltage) - "%d`,%d`,%d`,%d`," // device status(rssi, video, call, dnet status) - "%d`,%d`," // device status(call_time, rssi_time) - "%s`,%.1f`,%s`," // cpu frequency and usage (app, system) - "%lu`,%lu`,%lu`,%lu`,%Ld`," // process memory - "%lu`,%lu`," // system total memory, used memory - "%d`," // system drive - "%d`," // number of thread - "%s`,\n", // thread load - event_num, 0, curtime, // 0 is reserved value - get_wifi_status(), get_bt_status(), get_gps_status(), - get_brightness_status(), get_camera_status(), get_sound_status(), - get_audio_status(), get_vibration_status(), get_voltage_status(), - get_rssi_status(), get_video_status(), get_call_status(), get_dnet_status(), - call_time, rssi_time, - freqbuf, app_cpu_usage, cpuload, - virtual, resident, shared, pssmem, get_total_alloc_size(), - sysmemtotal, sysmemused, - get_total_used_drive(), - num_thread, - thread_loadbuf - ); - - LOGI("get_resource_info result : %s", buffer); - - event_num++; - return res; -} - -int initialize_system_info() -{ - int i; - - num_of_cpu = sysconf(_SC_NPROCESSORS_ONLN); - if(num_of_cpu < 1) - num_of_cpu = 1; - Hertz = sysconf(_SC_CLK_TCK); - LOGI("Hertz : %d\n", Hertz); - - // alloc for cpus - if(cpus == NULL) - cpus = (CPU_t*) calloc((num_of_cpu + 1), sizeof(CPU_t)); - if(cpus != NULL) - { - for(i = 0; i <= num_of_cpu; i++) - { - cpus[i].cur_load_index = cpus[i].sav_load_index = -1; - cpus[i].cur_freq_index = cpus[i].sav_freq_index = -1; - } - } - else - { - LOGE("Failed to alloc memory for cpu information\n"); - return -1; - } - - return 0; -} - -int finalize_system_info() -{ - int i; - - if(cpus != NULL) - { - for(i = 0; i < num_of_cpu; i++) - { - if(cpus[i].pfreq != NULL) - free(cpus[i].pfreq); - } - - free(cpus); - } - - return 0; -} - diff --git a/daemon/sys_stat.h b/daemon/sys_stat.h deleted file mode 100644 index 91e2091..0000000 --- a/daemon/sys_stat.h +++ /dev/null @@ -1,158 +0,0 @@ -/* -* DA manager -* -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. -* -* Contact: -* -* Jaewon Lim <jaewon81.lim@samsung.com> -* Woojin Jung <woojin2.jung@samsung.com> -* Juyoung Kim <j0.kim@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 -* -*/ - -#ifndef _SYS_STAT_ -#define _SYS_STAT_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include <stdio.h> -#include <stdlib.h> -#include <dirent.h> -#include <string.h> -#include <pthread.h> -#include <errno.h> -#include <unistd.h> -#include <fcntl.h> -#include <sys/time.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <sys/vfs.h> - -#define CHARGERFD "/sys/class/power_supply/battery/charge_now" -#define VOLTAGEFD "/sys/class/power_supply/battery/voltage_now" - -#define BRIGHTNESS_FILENAME "brightness" -#define MAX_BRIGHTNESS_FILENAME "max_brightness" -#define BRIGHTNESS_PARENT_DIR "/sys/class/backlight" - -#define EMUL_BRIGHTNESSFD "/sys/class/backlight/emulator/brightness" -#define EMUL_MAX_BRIGHTNESSFD "/sys/class/backlight/emulator/max_brightness" - - -#define AUDIOFD "/sys/devices/platform/soc-audio/dapm_widget" - -#define MFCFD "/sys/devices/platform/s3c-mfc/mfc/mfc_status" - -#define FREQFD "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq" - -#define CPUDIR "/sys/devices/system/cpu" -#define CPUFREQ_FILE "cpufreq/stats/time_in_state" -#define CPUNUM_OF_FREQ CPUDIR"/cpu0/"CPUFREQ_FILE - - -#define MEMINFOFD "/sys/class/memnotify/meminfo" -#define UMSFD "/mnt/ums" -#define MMCBLKFD "/dev/mmcblk1" -#define MMCFD "/mnt/mmc" - -#define PROCSTAT "/proc/stat" -#define PROCMEMINFO "/proc/meminfo" -#define PROCCPUINFO "/proc/cpuinfo" - -#define MEM_TYPE_TOTAL 1 -#define MEM_TYPE_USED 2 -#define MEM_TYPE_FREE 3 - -#define FSINFO_TYPE_TOTAL 1 -#define FSINFO_TYPE_FREE 2 - -#define MAXNAMESIZE 16 - -typedef unsigned long long tic_t; - -typedef struct { - unsigned int pid; - char command[MAXNAMESIZE]; - char state; - int ppid; - int pgrp; - int sid; - int tty_nr; - int tty_pgrp; - unsigned long flags; - unsigned long minor_fault; - unsigned long cminor_fault; - unsigned long major_fault; - unsigned long cmajor_fault; - unsigned long long utime; - unsigned long long stime; - unsigned long long cutime; - unsigned long long cstime; - long priority; - long nice; - int numofthread; - long dummy; - unsigned long long start_time; - unsigned long vir_mem; - long res_memblock; - unsigned long pss; -} proc_t; - -typedef struct { - unsigned long freq; - tic_t tick; - tic_t tick_sav; -} cpufreq_t; - -typedef struct { - tic_t u, n, s, i, w, x, y, z; - tic_t u_sav, n_sav, s_sav, i_sav, w_sav, x_sav, y_sav, z_sav; - unsigned int id; // cpu id - float cpu_usage; // cpu load for this core - int sav_load_index; // saved cpu load sampling index - int cur_load_index; // current cpu load sampling index - cpufreq_t* pfreq; // frequency information of cpu - int sav_freq_index; // sav cpu frequency sampling index - int cur_freq_index; // current cpu frequency sampling index - long long idle_ticks; - long long total_ticks; -} CPU_t; // for each cpu core - -typedef struct _mem_t { - const char* name; // memory slot name - unsigned long* slot; // memory value slot -} mem_t; - -int get_device_info(char* buffer, int buffer_len); - -int get_resource_info(char* buffer, int buffer_len, int* pidarray, int pidcount); - -int get_file_status(int* pfd, const char* filename); - -int initialize_system_info(); - -int finalize_system_info(); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/daemon/utils.c b/daemon/utils.c deleted file mode 100644 index 13070ff..0000000 --- a/daemon/utils.c +++ /dev/null @@ -1,260 +0,0 @@ -/* -* DA manager -* -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. -* -* Contact: -* -* Jaewon Lim <jaewon81.lim@samsung.com> -* Woojin Jung <woojin2.jung@samsung.com> -* Juyoung Kim <j0.kim@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 -* -*/ - -#include <stdlib.h> -#include <pthread.h> -#include "utils.h" -#include "da_debug.h" - -#define BUFFER_MAX 1024 - -static int file_fd = -1; - -static pthread_mutex_t write_mutex; - -// get application name from executable binary path -char* get_app_name(char* binary_path) -{ - char* pos; - - pos = strrchr(binary_path, '/'); - if(pos != NULL) - pos++; - - return pos; -} - -// execute applcation with executable binary path -// return 0 to fail to execute -// return 1 to succeed to execute -int exec_app(const char* exec_path, int app_type) -{ - pid_t pid; - char command[PATH_MAX]; - - if (exec_path == NULL || strlen(exec_path) <= 0) - { - LOGE("Executable path is not correct\n"); - return 0; - } - - if (( pid = fork()) < 0) // fork error - return 0; - - else if(pid > 0) - return 1; // exit parent process with successness - - sprintf(command, "%s %s", DA_PRELOAD(app_type), exec_path); - LOGI("launch app path is %s, executable path is %s\n", LAUNCH_APP_PATH, exec_path); - execl(SHELL_CMD, SHELL_CMD, "-c", command, NULL); - - return 1; -} - -#ifdef USE_LAUNCH_PAD -// execute application by launch pad -// return 0 to fail to execute -// return 1 to succeed to execute -int exec_app_by_launchpad(const char* pkg_name) -{ - pid_t pid; - - if (pkg_name == NULL || strlen(pkg_name) <= 0) - { - LOGE("Package name is not correct\n"); - return 0; - } - - if (( pid = fork()) < 0) // fork error - return 0; - - else if(pid > 0) - return 1; // exit parent process with successness - - LOGI("launch app path is %s, pkg name is %s\n", LAUNCH_APP_PATH, pkg_name); - execl(LAUNCH_APP_PATH, LAUNCH_APP_NAME, pkg_name, DA_PRELOAD_EXEC, NULL); - - return 1; -} -#endif - -#if 0 -void kill_app(const char* binary_path) // fork version -{ - pid_t pid; - pid_t pkg_pid; - char command[PATH_MAX]; - - if (( pid = fork()) < 0) - return; - - //exit parent process - else if(pid > 0) - return; - - pkg_pid = find_pid_from_path(binary_path); - - if(pkg_pid > 0) - { - sprintf(command, "kill -9 %d", pkg_pid); - LOGI(" : %s\n", command); - execl(SHELL_CMD, SHELL_CMD, "-c", command, NULL); - } - else - { - exit(0); - } -} -#else -void kill_app(const char* binary_path) // non fork version -{ - pid_t pkg_pid; - char command[PATH_MAX]; - - pkg_pid = find_pid_from_path(binary_path); - - if(pkg_pid > 0) - { - sprintf(command, "kill -9 %d", pkg_pid); - LOGI("kill app : %s\n", command); - system(command); - } -} -#endif - -// find process id from executable binary path -pid_t find_pid_from_path(const char* path) -{ - pid_t status = -1; - - char buffer [BUFFER_MAX]; - char command [BUFFER_MAX]; - - sprintf(command, "/bin/pidof %s", path); - - FILE *fp = popen(command, "r"); - if (!fp) - { - LOGE("Getting pidof %s is failed\n", path); - return status; - } - - while (fgets(buffer, BUFFER_MAX, fp) != NULL) - { - LOGI("result of 'pidof' is %s\n", buffer); - } - - pclose(fp); - - if (strlen(buffer) > 0) - { - if (sscanf(buffer,"%d\n", &status) != 1) - { - LOGE("Failed to read result buffer of 'pidof', status(%d)\n", status); - return -1; - } - } - - return status; -} - -static void mkdirs() -{ - mkdir("/home/developer/sdk_tools/da", 0775); - mkdir("/home/developer/sdk_tools/da/battery", 0775); -} - -int create_open_batt_log(const char* app_name) -{ - char log_path[PATH_MAX]; - - pthread_mutex_init(&write_mutex, NULL); - sprintf(log_path, "%s%s", BATT_LOG_FILE, app_name); - - if ((file_fd = open(log_path, O_WRONLY|O_CREAT|O_TRUNC)) == -1) - { - mkdirs(); - if ((file_fd = open(log_path, O_WRONLY|O_CREAT|O_TRUNC)) == -1) - { - LOGE("Failed to open batt log file\n"); - return 0; - } - } - - return file_fd; -} - -int get_batt_fd() -{ - return file_fd; -} - -int write_batt_log(const char* msg) -{ - int length = -1; - - if (file_fd == -1 ) - { - return -1; - } - - pthread_mutex_lock(&write_mutex); - - length = write(file_fd, msg, strlen(msg)); - - pthread_mutex_unlock(&write_mutex); - - return length; -} - -void close_batt_fd() -{ - close(file_fd); - file_fd = -1; -} - -#if DEBUG -void write_log() -{ - int fd; - - fd = open("/dev/null", O_RDONLY); - dup2(fd, 0); - - fd = open("/tmp/da_daemon.log", O_WRONLY | O_CREAT | O_TRUNC, 0640); - if(fd < 0) { - fd = open("/dev/null", O_WRONLY); - } - dup2(fd, 1); - dup2(fd, 2); - - fprintf(stderr,"--- da starting (pid %d) ---\n", getpid()); -} -#endif - - diff --git a/daemon/utils.h b/daemon/utils.h deleted file mode 100644 index ac00787..0000000 --- a/daemon/utils.h +++ /dev/null @@ -1,86 +0,0 @@ -/* -* DA manager -* -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. -* -* Contact: -* -* Jaewon Lim <jaewon81.lim@samsung.com> -* Woojin Jung <woojin2.jung@samsung.com> -* Juyoung Kim <j0.kim@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 -* -*/ - -#ifndef _UTILS_ -#define _UTILS_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include <stdio.h> -#include <unistd.h> -#include <string.h> -#include <fcntl.h> -#include <errno.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <linux/limits.h> - -#define LAUNCH_APP_PATH "/usr/bin/launch_app" -#define KILL_APP_PATH "/usr/bin/pkill" -#define LAUNCH_APP_NAME "launch_app" -#define DA_PRELOAD_EXEC "__AUL_SDK_DYNAMIC_ANALYSIS" -#define DA_PRELOAD(AppType) AppType ? DA_PRELOAD_OSP : DA_PRELOAD_TIZEN -#define DA_PRELOAD_TIZEN "LD_PRELOAD=/home/developer/sdk_tools/da/da_probe_tizen.so" -#define DA_PRELOAD_OSP "LD_PRELOAD=/home/developer/sdk_tools/da/da_probe_osp.so" -#define BATT_LOG_FILE "/home/developer/sdk_tools/da/battery/" -#define SHELL_CMD "/bin/sh" - -enum ApplicationType -{ - APP_TYPE_TIZEN = 0, - APP_TYPE_OSP = 1 -}; - -char* get_app_name(char* binary_path); - -int exec_app(const char* exec_path, int app_type); - -void kill_app(const char* binary_path); - -pid_t find_pid_from_path(const char* path); - -int create_open_batt_log(const char* app_name); - -int get_batt_fd(); - -int write_batt_log(const char* message); - -void close_batt_fd(); - -#if DEBUG -void write_log(); -#endif - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/eventutil/Makefile b/eventutil/Makefile deleted file mode 100644 index 3daa9f5..0000000 --- a/eventutil/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -CURDIR = `pwd` - -SRCS := eventutil.c - -TARGET = da_event - -all: $(TARGET) - -$(TARGET): $(SRCS) - $(CC) $(SYSROOT) -Wall -o $@ $(SRCS) - -install: - [ -d "$(CURDIR)/bin" ] || mkdir -p $(CURDIR)/bin - [ -d "$(CURDIR)/bin/$(ARCH)" ] || mkdir -p $(CURDIR)/bin/$(ARCH) - cp $(TARGET) $(CURDIR)/bin/$(ARCH) - -clean: - rm $(TARGET) - diff --git a/eventutil/eventutil.c b/eventutil/eventutil.c deleted file mode 100644 index 8cefefd..0000000 --- a/eventutil/eventutil.c +++ /dev/null @@ -1,378 +0,0 @@ -/* -* DA manager -* -* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. -* -* Contact: -* -* Jaewon Lim <jaewon81.lim@samsung.com> -* Woojin Jung <woojin2.jung@samsung.com> -* Juyoung Kim <j0.kim@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 -* -*/ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <fcntl.h> -#include <unistd.h> -#include <pthread.h> -#include <dirent.h> -#include <signal.h> -#include <linux/input.h> - -#define BUF_SIZE 1024 -#define INPUT_ID_STR_KEY "ID_INPUT_KEY=1" -#define INPUT_ID_STR_TOUCH "ID_INPUT_TOUCHSCREEN=1" -#define INPUT_ID_STR_KEYBOARD "ID_INPUT_KEYBOARD=1" -#define INPUT_ID_STR_TABLET "ID_INPUT_TABLET=1" -#define MAX_DEVICE 10 -#define MAX_FILENAME 128 - -#define INPUT_ID_TOUCH 0 -#define INPUT_ID_KEY 1 -#define STR_TOUCH "TOUCH" -#define STR_KEY "KEY" -#define ARRAY_END (-11) - -#define DAEMON_SENDER 0x01 -#define DAEMON_RECEIVER 0x10 - -typedef struct _input_dev -{ - int fd; - char fileName[MAX_FILENAME]; -} input_dev; - -// ==================================================================== -// helper functions -// ==================================================================== - -// return bytes size of readed data -// return 0 if no data readed or error occurred -static int _file_read(FILE* fp, char *buffer, int size) -{ - int ret = 0; - - if(fp != NULL && size > 0) - { - ret = fread((void*)buffer, sizeof(char), size, fp); - } - else - { - // fp is null - if(size > 0) - buffer[0] = '\0'; - - ret = 0; // error case - } - - return ret; -} - -// get input id of given input device -static int get_input_id(char* inputname) -{ - static int query_cmd_type = 0; // 1 if /lib/udev/input_id, 2 if udevadm - FILE* cmd_fp; - char buffer[BUF_SIZE]; - char command[MAX_FILENAME]; - int ret = -1; - - // determine input_id query command - if(__builtin_expect(query_cmd_type == 0, 0)) - { - sprintf(command, "ls /lib/udev/input_id; echo cmd_ret:$?;"); - cmd_fp = popen(command, "r"); - _file_read(cmd_fp, buffer, BUF_SIZE); - if(strstr(buffer, "cmd_ret:0")) // there is /lib/udev/input_id - { - query_cmd_type = 1; - } - else // there is not /lib/udev/input_id - { - query_cmd_type = 2; - } - pclose(cmd_fp); - } - - // make command string - if(query_cmd_type == 1) - { - sprintf(command, "/lib/udev/input_id /class/input/%s", inputname); - } - else if(query_cmd_type == 2) - { - sprintf(command, "udevadm info --name=input/%s --query=property", inputname); - } - else - { - // not impossible - perror("query cmd type is not valid"); - exit(0); - } - - // run command - cmd_fp = popen(command, "r"); - _file_read(cmd_fp, buffer, BUF_SIZE); - - // determine input id - if(strstr(buffer, INPUT_ID_STR_KEY)) // key - { - ret = INPUT_ID_KEY; - } - else if(strstr(buffer, INPUT_ID_STR_TOUCH)) // touch - { - ret = INPUT_ID_TOUCH; - } - else if(strstr(buffer, INPUT_ID_STR_KEYBOARD)) // keyboard - { - ret = INPUT_ID_KEY; - } - else if(strstr(buffer, INPUT_ID_STR_TABLET)) // touch (emulator) - { - ret = INPUT_ID_TOUCH; - } - - pclose(cmd_fp); - return ret; -} - -// get filename and fd of given input type devices -static void _get_fds(input_dev *dev, int input_id) -{ - DIR *dp; - struct dirent *d; - int count = 0; - - dp = opendir("/sys/class/input"); - - while((d = readdir(dp)) != NULL) - { - if(!strncmp(d->d_name, "event", 5)) // start with "event" - { - // event file - if(input_id == get_input_id(d->d_name)) - { - sprintf(dev[count].fileName, "/dev/input/%s", d->d_name); - dev[count].fd = open(dev[count].fileName, O_RDWR); - count++; - } - } - } - - closedir(dp); - - dev[count].fd = ARRAY_END; // end of input_dev array -} - -// ================================================================ -// device write function -// ================================================================ - -static void _device_write(input_dev *dev, struct input_event* in_ev) -{ - int i; - for(i = 0; dev[i].fd != ARRAY_END; i++) - { - if(dev[i].fd >= 0) - write(dev[i].fd, in_ev, sizeof(struct input_event)); - } -} - -// ================================================================= -// file descriptor manipulation functions -// ================================================================= - -static void _fd_insert(fd_set* fdset, input_dev *dev) -{ - int i; - for(i = 0; dev[i].fd != ARRAY_END; i++) - { - if(dev[i].fd >= 0) - { - FD_SET(dev[i].fd, fdset); - } - } -} - -static int _fd_isset(fd_set* fdset, input_dev *dev) -{ - int i; - for(i = 0; dev[i].fd != ARRAY_END; i++) - { - if(dev[i].fd >= 0) - { - if(FD_ISSET(dev[i].fd, fdset)) - { - return i; - } - } - } - - return -1; -} - - -int _get_maxfd(input_dev *touch, input_dev *key) -{ - int i; - int maxfd = -1; - - for(i = 0 ; touch[i].fd != ARRAY_END; i++) - { - if(touch[i].fd > maxfd) - maxfd = touch[i].fd; - } - - for(i = 0 ; key[i].fd != ARRAY_END; i++) - { - if(key[i].fd > maxfd) - maxfd = key[i].fd; - } - - return maxfd; -} - -// ============================================================================ -// sender and receiver functions -// ============================================================================ - -static int sender() -{ - struct input_event in_ev; - char eventType[MAX_FILENAME]; - - input_dev key_dev[MAX_DEVICE]; - input_dev touch_dev[MAX_DEVICE]; - - _get_fds(key_dev, INPUT_ID_KEY); - _get_fds(touch_dev, INPUT_ID_TOUCH); - - while(1) - { - scanf("%s %hx %hx %d", eventType, &in_ev.type, &in_ev.code, &in_ev.value); - if(!strncmp(eventType, STR_TOUCH, strlen(STR_TOUCH))) - { - _device_write(touch_dev, &in_ev); - } - else if(!strncmp(eventType, STR_KEY, strlen(STR_KEY))) - { - _device_write(key_dev, &in_ev); - } - } - - return 0; -} - -static int receiver() -{ - fd_set allfds, readfds; - int maxfd; - int index; - struct input_event in_ev; - - input_dev key_dev[MAX_DEVICE]; - input_dev touch_dev[MAX_DEVICE]; - - _get_fds(key_dev, INPUT_ID_KEY); - _get_fds(touch_dev, INPUT_ID_TOUCH); - - FD_ZERO(&readfds); - _fd_insert(&readfds, key_dev); - _fd_insert(&readfds, touch_dev); - - maxfd = _get_maxfd(touch_dev, key_dev); - - while(1) - { - allfds = readfds; - - select(maxfd + 1, &allfds, NULL, NULL, NULL); - - if((index = _fd_isset(&allfds, touch_dev)) != -1) - { - //touch read - read(touch_dev[index].fd, &in_ev, sizeof(struct input_event)); - printf("%s %s %ld %ld %x %x %d\n", - STR_TOUCH, touch_dev[index].fileName, in_ev.time.tv_sec, - in_ev.time.tv_usec, in_ev.type, in_ev.code, in_ev.value); - } - else if ((index = _fd_isset(&allfds, key_dev)) != -1) - { - //key read - read(key_dev[index].fd, &in_ev, sizeof(struct input_event)); - printf("%s %s %ld %ld %x %x %d\n", - STR_KEY, key_dev[index].fileName, in_ev.time.tv_sec, - in_ev.time.tv_usec, in_ev.type, in_ev.code, in_ev.value); - } - } - - return 0; -} - -// ====================================================================== -// main function and end signal handler -// ====================================================================== - -static void end_program(int sig) -{ - exit(0); -} - -int main(int argc, char **argv) -{ - int opt; - unsigned int commandType = 0; - signal(SIGINT, end_program); - - while((opt = getopt(argc, argv, "sr")) != -1) - { - switch(opt) - { - case 's': // send - commandType |= DAEMON_SENDER; - break; - case 'r': // receive - commandType |= DAEMON_RECEIVER; - break; - default: // unknown option - commandType = 0; - break; - } - - if(commandType == 0) - break; - } - - if(commandType == DAEMON_SENDER) - { - sender(); - } - else if(commandType == DAEMON_RECEIVER) - { - receiver(); - } - else - { - // TODO : print help text - } - - return 0; -} - diff --git a/package/build.linux b/package/build.linux index 6e09d2f..9e68aa7 100644..100755 --- a/package/build.linux +++ b/package/build.linux @@ -1,42 +1,5 @@ #!/bin/sh -e -__build_x86() -{ - export ARCH=x86 - export ROOTSTRAP=${ROOTDIR}/platforms/tizen2.0/rootstraps/tizen-emulator-2.0.devel - export SYSROOT="--sysroot=${ROOTDIR}/platforms/tizen2.0/rootstraps/tizen-emulator-2.0.devel" - export CC=${ROOTDIR}/tools/i386-linux-gnueabi-gcc-4.5/bin/i386-linux-gnueabi-gcc - - cd ${SRCDIR}/daemon - make - make install - make clean - - cd ${SRCDIR}/eventutil - make - make install - make clean -} - -__build_arm() -{ - export ARCH=arm - export ROOTSTRAP=${ROOTDIR}/platforms/tizen2.0/rootstraps/tizen-device-2.0.devel - export SYSROOT="--sysroot=${ROOTDIR}/platforms/tizen2.0/rootstraps/tizen-device-2.0.devel" - export CC=${ROOTDIR}/tools/arm-linux-gnueabi-gcc-4.5/bin/arm-linux-gnueabi-gcc - - cd ${SRCDIR}/daemon - make - make install - make clean - - cd ${SRCDIR}/eventutil - make - make install - make clean -} - -# clean clean() { rm -rf ${SRCDIR}/*.zip @@ -47,34 +10,17 @@ clean() # build build() { - __build_x86 - __build_arm + echo "nothing to build" } # install install() { - TARGET_MANAGER_DIR=${SRCDIR}/package/dynamic-analysis-manager-2.0.package.${BUILD_TARGET_OS}/data/platforms/tizen2.0/dynamic-analyzer - TARGET_BIN_DIR=${SRCDIR}/package/dynamic-analysis-manager-2.0.package.${BUILD_TARGET_OS}/data/tools/dynamic-analyzer/target - TOOL_DIR=${SRCDIR}/package/dynamic-analysis-manager-2.0.package.${BUILD_TARGET_OS}/data/tools/dynamic-analyzer/tool - mkdir -p ${TARGET_MANAGER_DIR} - mkdir -p ${TARGET_BIN_DIR}/x86 - mkdir -p ${TARGET_BIN_DIR}/arm - mkdir -p ${TOOL_DIR} - - cp -rf ${SRCDIR}/daemon/bin/* ${TARGET_MANAGER_DIR} - cp -rf ${SRCDIR}/eventutil/bin/* ${TARGET_MANAGER_DIR} - - cp ${SRCDIR}/activator/windowactivator.sh ${TOOL_DIR} - cp ${SRCDIR}/activator/WindowActivator ${TOOL_DIR} - cp ${SRCDIR}/activator/windowactivator.vbs ${TOOL_DIR} - cp ${SRCDIR}/activator/windowactivator.bat ${TOOL_DIR} - cp ${SRCDIR}/activator/WindowActivator.exe ${TOOL_DIR} - cp ${SRCDIR}/activator/macoswindowactivator.sh ${TOOL_DIR} - cp ${SRCDIR}/activator/MacOSWindowActivator ${TOOL_DIR} + INSTALL_DIR=${SRCDIR}/package/dynamic-analysis-manager.package.${BUILD_TARGET_OS}/data/tools/dynamic-analyzer/target + mkdir -p ${INSTALL_DIR} - cp ${SRCDIR}/binutils/readelf_x86 ${TARGET_BIN_DIR}/x86/readelf - cp ${SRCDIR}/binutils/readelf_arm ${TARGET_BIN_DIR}/arm/readelf + cp ${SRCDIR}/binutils/readelf_x86 ${INSTALL_DIR}/x86/readelf + cp ${SRCDIR}/binutils/readelf_arm ${INSTALL_DIR}/arm/readelf } [ "$1" = "clean" ] && clean diff --git a/package/pkginfo.manifest b/package/pkginfo.manifest index 8f4ee69..cd223b3 100644 --- a/package/pkginfo.manifest +++ b/package/pkginfo.manifest @@ -2,31 +2,31 @@ Source:dynamic-analysis-manager Version:0.2.6 Maintainer:Woojin Jung <woojin2.jung@samsung.com>, Jaewon Lim <jaewon81.lim@samsung.com>, Juyoung Kim <j0.kim@samsung.com> -Package:dynamic-analysis-manager-2.0 +Package:dynamic-analysis-manager OS:ubuntu-32 Build-host-os:ubuntu-32 Build-dependency:cross-arm-gcc-4.5 [ubuntu-32], cross-i386-gcc-4.5 [ubuntu-32], rs-device-2.0.devel [ubuntu-32], rs-emulator-2.0.devel [ubuntu-32] Description:Dynamic Analyzer daemon and tools -Package:dynamic-analysis-manager-2.0 +Package:dynamic-analysis-manager OS:windows-32 Build-host-os:ubuntu-32 Build-dependency:cross-arm-gcc-4.5 [ubuntu-32], cross-i386-gcc-4.5 [ubuntu-32], rs-device-2.0.devel [ubuntu-32], rs-emulator-2.0.devel [ubuntu-32] Description:Dynamic Analyzer daemon and tools -Package:dynamic-analysis-manager-2.0 +Package:dynamic-analysis-manager OS:ubuntu-64 Build-host-os:ubuntu-32 Build-dependency:cross-arm-gcc-4.5 [ubuntu-32], cross-i386-gcc-4.5 [ubuntu-32], rs-device-2.0.devel [ubuntu-32], rs-emulator-2.0.devel [ubuntu-32] Description:Dynamic Analyzer daemon and tools -Package:dynamic-analysis-manager-2.0 +Package:dynamic-analysis-manager OS:windows-64 Build-host-os:ubuntu-32 Build-dependency:cross-arm-gcc-4.5 [ubuntu-32], cross-i386-gcc-4.5 [ubuntu-32], rs-device-2.0.devel [ubuntu-32], rs-emulator-2.0.devel [ubuntu-32] Description:Dynamic Analyzer daemon and tools -Package:dynamic-analysis-manager-2.0 +Package:dynamic-analysis-manager OS:macos-64 Build-host-os:ubuntu-32 Build-dependency:cross-arm-gcc-4.5 [ubuntu-32], cross-i386-gcc-4.5 [ubuntu-32], rs-device-2.0.devel [ubuntu-32], rs-emulator-2.0.devel [ubuntu-32] |