From bfc407295d754c365cf3201350d531d3b2c864c6 Mon Sep 17 00:00:00 2001 From: Kim Kibum Date: Fri, 8 Jun 2012 14:54:15 +0900 Subject: [PATCH] apply FSL(Flora Software License) --- AUTHORS | 2 + CMakeLists.txt | 79 +++++ LICENSE | 75 +++++ debian/changelog | 8 + debian/compat | 1 + debian/control | 30 ++ debian/copyright | 1 + debian/rules | 126 ++++++++ debian/system-server-bin.install.in | 3 + debian/system-server-bin.postinst.in | 49 +++ include/ss_data.h | 100 ++++++ movi_format.sh | 34 +++ packaging/system-server.spec | 96 ++++++ predefine_act_plugin/CMakeLists.txt | 38 +++ predefine_act_plugin/build.sh | 7 + predefine_act_plugin/xxx-predefine.c | 40 +++ restarter/CMakeLists.txt | 34 +++ restarter/restart.c | 30 ++ ss_bs.c | 161 ++++++++++ ss_bs.h | 23 ++ ss_core.c | 122 ++++++++ ss_core.h | 27 ++ ss_cpu_handler.c | 322 ++++++++++++++++++++ ss_cpu_handler.h | 23 ++ ss_device_change_handler.c | 229 ++++++++++++++ ss_device_handler.h | 49 +++ ss_device_plugin.c | 64 ++++ ss_device_plugin.h | 30 ++ ss_launch.c | 342 +++++++++++++++++++++ ss_launch.h | 27 ++ ss_log.c | 35 +++ ss_log.h | 137 +++++++++ ss_lowbat_handler.c | 292 ++++++++++++++++++ ss_lowmem_handler.c | 266 ++++++++++++++++ ss_main.c | 128 ++++++++ ss_mmc_handler.c | 241 +++++++++++++++ ss_noti.c | 55 ++++ ss_noti.h | 26 ++ ss_pmon_handler.c | 227 ++++++++++++++ ss_pmon_handler.h | 22 ++ ss_predefine.c | 573 +++++++++++++++++++++++++++++++++++ ss_predefine.h | 24 ++ ss_procmgr.c | 373 +++++++++++++++++++++++ ss_procmgr.h | 26 ++ ss_queue.c | 301 ++++++++++++++++++ ss_queue.h | 66 ++++ ss_sig_handler.c | 74 +++++ ss_sig_handler.h | 23 ++ ss_sysnoti.c | 277 +++++++++++++++++ ss_sysnoti.h | 34 +++ ss_ta_handler.c | 45 +++ ss_timemgr.c | 162 ++++++++++ ss_timemgr.h | 23 ++ ss_usb_handler.c | 54 ++++ ss_usb_storage_handler.c | 265 ++++++++++++++++ sys_event/CMakeLists.txt | 31 ++ sys_event/sys_event.c | 30 ++ system_server.sh | 3 + udev-rules/91-system-server.rules.in | 27 ++ 59 files changed, 6012 insertions(+) create mode 100644 AUTHORS create mode 100644 CMakeLists.txt create mode 100755 LICENSE create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control create mode 100644 debian/copyright create mode 100755 debian/rules create mode 100644 debian/system-server-bin.install.in create mode 100644 debian/system-server-bin.postinst.in create mode 100644 include/ss_data.h create mode 100755 movi_format.sh create mode 100644 packaging/system-server.spec create mode 100644 predefine_act_plugin/CMakeLists.txt create mode 100755 predefine_act_plugin/build.sh create mode 100644 predefine_act_plugin/xxx-predefine.c create mode 100644 restarter/CMakeLists.txt create mode 100644 restarter/restart.c create mode 100644 ss_bs.c create mode 100644 ss_bs.h create mode 100644 ss_core.c create mode 100644 ss_core.h create mode 100644 ss_cpu_handler.c create mode 100644 ss_cpu_handler.h create mode 100644 ss_device_change_handler.c create mode 100644 ss_device_handler.h create mode 100644 ss_device_plugin.c create mode 100644 ss_device_plugin.h create mode 100644 ss_launch.c create mode 100644 ss_launch.h create mode 100644 ss_log.c create mode 100644 ss_log.h create mode 100644 ss_lowbat_handler.c create mode 100644 ss_lowmem_handler.c create mode 100644 ss_main.c create mode 100644 ss_mmc_handler.c create mode 100644 ss_noti.c create mode 100644 ss_noti.h create mode 100644 ss_pmon_handler.c create mode 100644 ss_pmon_handler.h create mode 100644 ss_predefine.c create mode 100644 ss_predefine.h create mode 100644 ss_procmgr.c create mode 100644 ss_procmgr.h create mode 100644 ss_queue.c create mode 100644 ss_queue.h create mode 100644 ss_sig_handler.c create mode 100644 ss_sig_handler.h create mode 100644 ss_sysnoti.c create mode 100644 ss_sysnoti.h create mode 100644 ss_ta_handler.c create mode 100644 ss_timemgr.c create mode 100644 ss_timemgr.h create mode 100644 ss_usb_handler.c create mode 100644 ss_usb_storage_handler.c create mode 100644 sys_event/CMakeLists.txt create mode 100644 sys_event/sys_event.c create mode 100755 system_server.sh create mode 100644 udev-rules/91-system-server.rules.in diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..67e6bd9 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,2 @@ +Jinkun Jang +DongGi Jang diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a7196e4 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,79 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(system_server C) + +SET(SRCS + ss_main.c + ss_sysnoti.c + ss_launch.c + ss_queue.c + ss_core.c + ss_sig_handler.c + ss_log.c + ss_device_change_handler.c + ss_predefine.c + ss_noti.c + ss_lowbat_handler.c + ss_lowmem_handler.c + ss_mmc_handler.c + ss_usb_handler.c + ss_ta_handler.c + ss_bs.c + ss_procmgr.c + ss_timemgr.c + ss_cpu_handler.c + ss_device_plugin.c + ss_usb_storage_handler.c) + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) + +SET(MOVINAND_FORMAT movi_format.sh) + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED + ecore + ecore-file + ecore-x + eina + sysman + vconf + heynoti + pmapi + tapi + dlog + syspopup-caller + devman + devman_plugin + x11) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions") + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +MESSAGE("FLAGS: ${CMAKE_C_FLAGS}") + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DFACTORYFS=\"$ENV{FACTORYFS}\"") +IF( $ENV{ARCH} MATCHES "arm" ) + ADD_DEFINITIONS("-DTARGET") +ENDIF() +ADD_DEFINITIONS("-DDEBUG -DENABLE_DLOG_OUT") + +SET(UDEV_RULES_PATH share/system-server/udev-rules) +SET(UDEV_RULES udev-rules/91-system-server.rules) + +CONFIGURE_FILE(${UDEV_RULES}.in ${UDEV_RULES} @ONLY) + +ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} "-ldl") + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) +INSTALL(FILES ${MOVINAND_FORMAT} DESTINATION bin) +INSTALL(FILES ${UDEV_RULES} DESTINATION ${UDEV_RULES_PATH}) +INSTALL(PROGRAMS ${CMAKE_BINARY_DIR}/system_server.sh DESTINATION /etc/rc.d/init.d) + +ADD_SUBDIRECTORY(restarter) +ADD_SUBDIRECTORY(sys_event) diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000..7ccb5b5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,75 @@ +Flora License + +Version 1.0, May, 2012 + +http://www.tizenopensource.org/license + +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. + +"Tizen Certified Platform" shall mean a software platform that complies with the standards set forth in the Compatibility Definition Document and passes the Compatibility Test Suite as defined from time to time by the Tizen Technical Steering Group and certified by the Tizen Association or its designated agent. + +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 solely as incorporated into a Tizen Certified Platform, 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 solely as incorporated into a Tizen Certified Platform 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 pursuant to the copyright license above, in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: + + 1. You must give any other recipients of the Work or Derivative Works a copy of this License; and + + 2. You must cause any modified files to carry prominent notices stating that You changed the files; and + + 3. 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 + + 4. 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 Flora License to your work + +To apply the Flora 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 Flora License, Version 1.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.tizenopensource.org/license + + 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. diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..ad19656 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,8 @@ +system-server (0.1.51-67) unstable; urgency=low + + * support battery err check + * Git: slp/pkgs/s/system-server + * Tag: system-server_0.1.51-67 + + -- Jinkun Jang Mon, 19 Mar 2012 11:00:59 +0900 + diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..7ed6ff8 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +5 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..566063b --- /dev/null +++ b/debian/control @@ -0,0 +1,30 @@ +Source: system-server +Section: tools +Priority: extra +Maintainer: Jonghoon Han Jinkun Jang DongGi Jang TAESOO JUN +Uploaders: Jinkun Jang Wonil Choi +Build-Depends: debhelper (>= 5), + libecore-dev, + libheynoti-dev, + libslp-setting-dev, + libslp-sysman-dev, + libslp-tapi-dev, + libslp-pm-dev, + libdevman-dev, + libdevman-plugin-dev, + libedbus-dev, + dlog-dev, + syspopup-caller-dev, + libattr1-dev +Standards-Version: 3.7.2 + +Package: system-server-bin +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: System server + +Package: system-server-bin-dbg +Section: debug +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, system-server-bin (= ${Source-Version}) +Description: System server degug package (unstripped) diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/debian/copyright @@ -0,0 +1 @@ + diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..cc5bfd5 --- /dev/null +++ b/debian/rules @@ -0,0 +1,126 @@ +#!/usr/bin/make -f + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +CFLAGS ?= -Wall -g +LDFLAGS ?= +PREFIX ?= /usr +DATADIR ?= /opt + +ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) + CFLAGS += -O0 +else + CFLAGS += -O2 +endif + +LDFLAGS += -Wl,--rpath=$(PREFIX)/lib -Wl,--as-needed + +configure: configure-stamp +configure-stamp: + dh_testdir + # Add here commands to configure the package. + CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" cmake . -DCMAKE_INSTALL_PREFIX=$(PREFIX) + + touch configure-stamp + + +build: build-stamp + +build-stamp: configure-stamp + dh_testdir + + # Add here commands to compile the package. + $(MAKE) + + for f in `find $(CURDIR)/debian/ -name "*.in"`; do \ + cat $$f > $${f%.in}; \ + sed -i -e "s#@PREFIX@#$(PREFIX)#g" $${f%.in}; \ + sed -i -e "s#@DATADIR@#$(DATADIR)#g" $${f%.in}; \ + done + + touch $@ + +clean: + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + + # Add here commands to clean up after the build process. + -$(MAKE) clean + + rm -rf CMakeCache.txt + rm -rf CMakeFiles + rm -rf cmake_install.cmake + rm -rf Makefile + rm -rf install_manifest.txt + rm -rf *.so + rm -rf ./restarter/CMakeCache.txt + rm -rf ./restarter/CMakeFiles + rm -rf ./restarter/cmake_install.cmake + rm -rf ./restarter/Makefile + rm -rf ./restarter/install_manifest.txt + rm -rf ./sys_event/CMakeCache.txt + rm -rf ./sys_event/CMakeFiles + rm -rf ./sys_event/cmake_install.cmake + rm -rf ./sys_event/Makefile + rm -rf ./sys_event/install_manifest.txt + rm -rf ./udev-rules/*.rules + + for f in `find $(CURDIR)/debian/ -name "*.in"`; do \ + rm -f $${f%.in}; \ + done + + + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + # Add here commands to install the package into debian/tmp. + $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install + + mkdir -p $(CURDIR)/debian/tmp/etc/rc.d/rc5.d/ + ln -s ../init.d/system_server.sh $(CURDIR)/debian/tmp/etc/rc.d/rc5.d/S00system-server + +# Build architecture-independent files here. +binary-indep: build install +# We have nothing to do by default. + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir + dh_testroot + dh_installchangelogs + dh_installdocs + dh_installexamples + dh_install --sourcedir=debian/tmp +# dh_installmenu +# dh_installdebconf +# dh_installlogrotate +# dh_installemacsen +# dh_installpam +# dh_installmime +# dh_python +# dh_installinit +# dh_installcron +# dh_installinfo + dh_installman + dh_link +# dh_strip + dh_strip --dbg-package=system-server-bin-dbg + dh_compress + dh_fixperms +# dh_perl + dh_makeshlibs + dh_installdeb + dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure diff --git a/debian/system-server-bin.install.in b/debian/system-server-bin.install.in new file mode 100644 index 0000000..3c1f907 --- /dev/null +++ b/debian/system-server-bin.install.in @@ -0,0 +1,3 @@ +@PREFIX@/bin/* +@PREFIX@/share/system-server/* +/etc/* diff --git a/debian/system-server-bin.postinst.in b/debian/system-server-bin.postinst.in new file mode 100644 index 0000000..0728a59 --- /dev/null +++ b/debian/system-server-bin.postinst.in @@ -0,0 +1,49 @@ +#!/bin/sh + +vconftool set -t int memory/Battery/Charger -1 -i +vconftool set -t int memory/Battery/Status/Low -1 -i +vconftool set -t int memory/Battery/Capacity -1 -i +vconftool set -t int memory/Device/EarJackKey 0 -i +vconftool set -t int db/system/timechange 0 -i +vconftool set -t int memory/sysman/low_memory 1 -i +vconftool set -t int memory/Connectivity/USB -1 -i +vconftool set -t int memory/Device/mmc_format 0 -i + +vconftool set -t int memory/Device/Mmc -1 -i +vconftool set -t int memory/Device/mmc_mount -1 -i +vconftool set -t int memory/Device/mmc_unmount -1 -i +vconftool set -t int memory/Device/mmc_format -1 -i + +vconftool set -t int db/MainLCD/Backlight/Normal -1 -i +vconftool set -t int memory/Device/EarJack -1 -i +vconftool set -t int memory/Device/Cradle/Status -1 -i +vconftool set -t int memory/Device/Sliding_keyboard -1 -i + +vconftool set -t int memory/Device/usbhost/added_storage 0 -i +vconftool set -t int memory/Device/usbhost/removed_storage 0 -i + +vconftool set -t string memory/Device/usbhost/added_storage_uevent "" -i +vconftool set -t string memory/Device/usbhost/removed_storage_uevent "" -i + +vconftool set -t int memory/Device/usbhost/connect -1 -i + +heynotitool set power_off_start + +heynotitool set mmcblk_add +heynotitool set mmcblk_remove + +heynotitool set device_usb_chgdet +heynotitool set device_ta_chgdet +heynotitool set device_earjack_chgdet +heynotitool set device_earkey_chgdet +heynotitool set device_tvout_chgdet +heynotitool set device_hdmi_chgdet +heynotitool set device_cradle_chgdet +heynotitool set device_charge_chgdet +heynotitool set device_keyboard_chgdet + +mkdir -p /etc/udev/rules.d +if ! [ -L /etc/udev/rules.d/91-system-server.rules ]; then + ln -s @PREFIX@/share/system-server/udev-rules/91-system-server.rules /etc/udev/rules.d/91-system-server.rules +fi + diff --git a/include/ss_data.h b/include/ss_data.h new file mode 100644 index 0000000..741c829 --- /dev/null +++ b/include/ss_data.h @@ -0,0 +1,100 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + +#ifndef __SS_DATA_H__ +#define __SS_DATA_H__ + +#include +#include + +enum { + WIN_CREATE = 0, + WIN_SHOW, + WIN_DELETE, + WIN_MAX +}; + +#define FM_RADIO_APP "FM_radio" +#define MULTIMEDIA_APP "music" +#define BLUETOOTH_APP "bluetooth" +#define VOICERECORDER_APP "voicerecorder" + +#define MMC_DEV "/dev/mmcblk" + +#define VCONFKEY_INTERNAL_ADDED_USB_STORAGE "memory/Device/usbhost/added_storage_uevent" +#define VCONFKEY_INTERNAL_REMOVED_USB_STORAGE "memory/Device/usbhost/removed_storage_uevent" + +#define PREDEF_CALL "call" +#define PREDEF_LOWMEM "lowmem" +#define PREDEF_LOWBAT "lowbat" +#define PREDEF_USBCON "usbcon" +#define PREDEF_POWEROFF "poweroff" +#define PREDEF_REBOOT "reboot" +#define PREDEF_PWROFF_POPUP "pwroff-popup" +#define PREDEF_BACKGRD "backgrd" +#define PREDEF_FOREGRD "foregrd" +#define PREDEF_ACTIVE "active" +#define PREDEF_USB_STORAGE_ADD "usbstorage-add" +#define PREDEF_USB_STORAGE_REMOVE "usbstorage-remove" +#define PREDEF_INACTIVE "inactive" + +#define OOMADJ_SET "oomadj_set" +#define LOW_MEM_ACT "low_mem_act" +#define OOM_MEM_ACT "oom_mem_act" + +#define WARNING_LOW_BAT_ACT "warning_low_bat_act" +#define CRITICAL_LOW_BAT_ACT "critical_low_bat_act" +#define POWER_OFF_BAT_ACT "power_off_bat_act" +#define CHARGE_BAT_ACT "charge_bat_act" +#define CHARGE_CHECK_ACT "charge_check_act" +#define CHARGE_ERROR_ACT "charge_error_act" + +#define PREDEF_EARJACKCON "earjack_predef_internal" + +#define PREDEF_SET_DATETIME "set_datetime" +#define PREDEF_SET_TIMEZONE "set_timezone" + +#define PREDEF_MOUNT_MMC "mountmmc" +#define PREDEF_UNMOUNT_MMC "unmountmmc" +#define PREDEF_FORMAT_MMC "formatmmc" + +#define PREDEF_SET_MAX_FREQUENCY "set_max_frequency" +#define PREDEF_SET_MIN_FREQUENCY "set_min_frequency" +#define PREDEF_RELEASE_MAX_FREQUENCY "release_max_frequency" +#define PREDEF_RELEASE_MIN_FREQUENCY "release_min_frequency" + +#define OOMADJ_SU (-17) +#define OOMADJ_INIT (-16) +#define OOMADJ_FOREGRD_LOCKED (-15) +#define OOMADJ_FOREGRD_UNLOCKED (-10) +#define OOMADJ_BACKGRD_LOCKED (-5) +#define OOMADJ_BACKGRD_UNLOCKED (1) + +#define OOMADJ_APP_LIMIT (-16) + +#define MOVINAND_MOUNT_POINT "/opt/media" +#define MMC_MOUNT_POINT "/opt/storage/sdcard" + +struct ui_contention_info { + +}; + +struct ss_main_data { + int sysnoti_fd; + int noti_fd; +}; + +#endif /* __SS_DATA_H__ */ diff --git a/movi_format.sh b/movi_format.sh new file mode 100755 index 0000000..dbc2f84 --- /dev/null +++ b/movi_format.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +fdisk -H 1 /dev/mmcblk0 << EOF +d +1 +d +2 +d +3 +n +p +1 +2 +728576 +n +p +2 + +990720 +n +p +3 + +1003520 +p +wq +EOF + +sleep 1 + +fat.format -s 32 -S 512 -F 32 /dev/mmcblk0p1 +fat.format -s 32 -S 512 -F 32 /dev/mmcblk0p2 +fat.format -s 4 -S 4096 -F 16 /dev/mmcblk0p3 + diff --git a/packaging/system-server.spec b/packaging/system-server.spec new file mode 100644 index 0000000..64f416a --- /dev/null +++ b/packaging/system-server.spec @@ -0,0 +1,96 @@ +Name: system-server +Summary: System server +Version: 0.1.51 +Release: 1 +Group: TO_BE/FILLED_IN +License: Flora Software License +Source0: system-server-%{version}.tar.gz +Requires(post): /usr/bin/vconftool +BuildRequires: cmake +BuildRequires: libattr-devel +BuildRequires: pkgconfig(ecore) +BuildRequires: pkgconfig(heynoti) +BuildRequires: pkgconfig(vconf) +BuildRequires: pkgconfig(sysman) +BuildRequires: pkgconfig(tapi) +BuildRequires: pkgconfig(devman) +BuildRequires: pkgconfig(pmapi) +BuildRequires: pkgconfig(edbus) +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(syspopup-caller) +BuildRequires: pkgconfig(devman_plugin) +BuildRequires: pkgconfig(x11) + +%description +Description: System server + + +%prep +%setup -q +cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} + +%build +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +%make_install + +mkdir -p %{buildroot}%{_sysconfdir}/rc.d/rc5.d/ +ln -s %{_sysconfdir}/init.d/system_server.sh %{buildroot}%{_sysconfdir}/rc.d/rc5.d/S00system-server + +%post + +vconftool set -t int memory/Battery/Charger -1 -i +vconftool set -t int memory/Battery/Status/Low -1 -i +vconftool set -t int memory/Battery/Capacity -1 -i +vconftool set -t int memory/Device/EarJackKey 0 -i +vconftool set -t int db/system/timechange 0 -i +vconftool set -t int memory/sysman/low_memory 1 -i +vconftool set -t int memory/Connectivity/USB -1 -i +vconftool set -t int memory/Device/mmc_format 0 -i +vconftool set -t int memory/Device/Sliding_keyboard -1 -i + +vconftool set -t int memory/Device/Mmc -1 -i +vconftool set -t int db/MainLCD/Backlight/Normal -1 -i +vconftool set -t int memory/Device/EarJack -1 -i +vconftool set -t int memory/Device/Cradle/Status -1 -i + +vconftool set -t int memory/Device/usbhost/added_storage 0 -i +vconftool set -t int memory/Device/usbhost/removed_storage 0 -i + +vconftool set -t string memory/Device/usbhost/added_storage_uevent "" -i +vconftool set -t string memory/Device/usbhost/removed_storage_uevent "" -i + +vconftool set -t int memory/Device/usbhost/connect -1 -i + +heynotitool set power_off_start + +heynotitool set mmcblk_add +heynotitool set mmcblk_remove + +heynotitool set device_usb_chgdet +heynotitool set device_ta_chgdet +heynotitool set device_earjack_chgdet +heynotitool set device_earkey_chgdet +heynotitool set device_tvout_chgdet +heynotitool set device_hdmi_chgdet +heynotitool set device_cradle_chgdet +heynotitool set device_charge_chgdet +heynotitool set device_keyboard_chgdet + +mkdir -p /etc/udev/rules.d +if ! [ -L /etc/udev/rules.d/91-system-server.rules ]; then + ln -s %{_datadir}/system-server/udev-rules/91-system-server.rules /etc/udev/rules.d/91-system-server.rules +fi + + +%files +%{_bindir}/system_server +%{_bindir}/restart +%{_bindir}/movi_format.sh +%{_bindir}/sys_event +%{_datadir}/system-server/udev-rules/91-system-server.rules +%{_sysconfdir}/rc.d/init.d/system_server.sh +%{_sysconfdir}/rc.d/rc5.d/S00system-server + diff --git a/predefine_act_plugin/CMakeLists.txt b/predefine_act_plugin/CMakeLists.txt new file mode 100644 index 0000000..100c04f --- /dev/null +++ b/predefine_act_plugin/CMakeLists.txt @@ -0,0 +1,38 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(xxx-predefine C) + +SET(SRCS xxx-predefine.c) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(EXEC_PREFIX "\${prefix}") +SET(LIBDIR "\${prefix}/lib") +SET(INCLUDEDIR "\${prefix}/include") +SET(VERSION 1.0) + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED sysman) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer") + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +MESSAGE("FLAGS: ${CMAKE_C_FLAGS}") + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DFACTORYFS=\"$ENV{FACTORYFS}\"") +ADD_DEFINITIONS("-DDEBUG") +IF( $ENV{ARCH} MATCHES "arm" ) + ADD_DEFINITIONS("-DTARGET") +ENDIF() + +SET(CMAKE_LDFLAGS "-Wl,zdefs") +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS}) + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib COMPONENT RuntimeLibraries) + diff --git a/predefine_act_plugin/build.sh b/predefine_act_plugin/build.sh new file mode 100755 index 0000000..c0cc290 --- /dev/null +++ b/predefine_act_plugin/build.sh @@ -0,0 +1,7 @@ +cd `dirname $0` + +. ../../../../../setup.conf || exit 1 + +. ${TPLDIR}/cmake.tpl +run + diff --git a/predefine_act_plugin/xxx-predefine.c b/predefine_act_plugin/xxx-predefine.c new file mode 100644 index 0000000..2aedac1 --- /dev/null +++ b/predefine_act_plugin/xxx-predefine.c @@ -0,0 +1,40 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#include +#include + +int SS_PREDEFINE_ACT_FUNC(int argc, char **argv) +{ + int i; + printf("kqwekrqkwerqwer\n"); + for (i = 0; i < argc; i++) + printf("%s\n", argv[i]); + return 0; +} + +int SS_IS_ACCESSABLE_FUNC(int pid) +{ + printf("qwerqerqewr %d\n", pid); + return 1; +} + +int SS_UI_VIEWABLE_FUNC() +{ + printf("kakak viewable\n"); + return 1; +} diff --git a/restarter/CMakeLists.txt b/restarter/CMakeLists.txt new file mode 100644 index 0000000..acc29a0 --- /dev/null +++ b/restarter/CMakeLists.txt @@ -0,0 +1,34 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(restart C) + +SET(SRCS restart.c) +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(EXEC_PREFIX "\${prefix}") +SET(LIBDIR "\${prefix}/lib") +SET(INCLUDEDIR "\${prefix}/include") +SET(VERSION 0.1.9) +INCLUDE(FindPkgConfig) +FOREACH(flag ${deep_pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_C_FLAGS_RELEASE "-O2") + +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") + +ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${deep_pkgs_LDFLAGS}) + +ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"") +ADD_DEFINITIONS("-DFACTORYFS=\"$ENV{FACTORYFS}\"") +ADD_DEFINITIONS("-DDATAFS=\"$ENV{DATADIR}\"") + + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME} DESTINATION bin) + + + diff --git a/restarter/restart.c b/restarter/restart.c new file mode 100644 index 0000000..23e50fd --- /dev/null +++ b/restarter/restart.c @@ -0,0 +1,30 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#include +#include +#include + +int main(int argc, char *argv[]) +{ + system("/etc/rc.d/rc.shutdown &"); + kill(-1, SIGTERM); + sleep(1); + sync(); + reboot(RB_AUTOBOOT); + return 0; +} diff --git a/ss_bs.c b/ss_bs.c new file mode 100644 index 0000000..e52ac80 --- /dev/null +++ b/ss_bs.c @@ -0,0 +1,161 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ss_log.h" +#include "ss_launch.h" + +#define BSNOTI_DIR "/opt/bs" +#define BSNOTI_FILE "curbs.log" +#define BSNOTI_FULL_PATH BSNOTI_DIR"/"BSNOTI_FILE +#define CRASH_WORKER_PATH "/usr/bin/crash-worker" + +static int noti_fd; +static int add_noti(void); + +static int make_noti_file(const char *path, const char *file) +{ + PRT_TRACE("Make Noti File"); + int fd; + char buf[PATH_MAX]; + + /* make a directory */ + if (access(path, F_OK) == -1) { + snprintf(buf, sizeof(buf), "mkdir -p %s", path); + system(buf); + snprintf(buf, sizeof(buf), "chown root:app %s", path); + system(buf); + } + + snprintf(buf, sizeof(buf), "%s/%s", path, file); + + if (access(buf, F_OK) == 0) + return -1; + + fd = open(buf, O_CREAT, S_IRUSR | S_IWUSR); + close(fd); + snprintf(buf, sizeof(buf), "chmod 666 %s/%s", path, file); + system(buf); + snprintf(buf, sizeof(buf), "chown root:app %s/%s", path, file); + system(buf); + + return 0; +} + +static void launch_crash_worker(void *data) +{ + FILE *fp; + char bsfile_name[NAME_MAX], bs_color[MAX_INPUT]; + char args[NAME_MAX + MAX_INPUT]; + int ret = -1, i; + + fp = fopen((char *)data, "r"); + if (fp == NULL) { + return; + } + /* launch bs process */ + while (fgets(args, NAME_MAX + MAX_INPUT, fp) != NULL) { + /* add rule for log */ + if (args[strlen(args) - 1] != '\n') { + PRT_TRACE_ERR("bsfile log must be terminated with new line character\n"); + break; + } + /* change last caracter from \n to \0 */ + args[strlen(args) - 1] = '\0'; + for (i = 0; i < NAME_MAX + MAX_INPUT; i++) { + if (args[i] == ' ') { + if (i >= NAME_MAX - 1) { + PRT_TRACE_ERR("bsfile name is over 254. 255(NAME_MAX) - 1(NULL Termination)\n"); + break; + } + strncpy(bsfile_name, args, i); + bsfile_name[i] = '\0'; + strncpy(bs_color, args + i + 1, MAX_INPUT); + bs_color[MAX_INPUT - 1] = '\0'; + snprintf(args, sizeof(args), "%s %s", + bsfile_name, bs_color); + PRT_TRACE("bsfile_name(size %d): %s\nargs: %s\n", i, bsfile_name, bs_color, args); + ret = ss_launch_evenif_exist(CRASH_WORKER_PATH, args); + break; + } + } + if (ret < 0) + break; + } + fclose(fp); + + if (ret != -1) { + fp = fopen((char *)data, "w"); + if (fp == NULL) { + return; + } + fclose(fp); + } + + return; +} + +static Ecore_File_Monitor *bs_file_monitor; + +static Ecore_File_Monitor_Cb __bs_file_cb(void *data, Ecore_File_Monitor *em, Ecore_File_Event event, const char *path) +{ + switch (event) { + case ECORE_FILE_EVENT_DELETED_DIRECTORY: + case ECORE_FILE_EVENT_DELETED_SELF: + if (0 > make_noti_file(BSNOTI_DIR, BSNOTI_FILE)) { + launch_crash_worker((void *)path); + } + break; + case ECORE_FILE_EVENT_MODIFIED: + default: + launch_crash_worker((void *)path); + break; + } + + return; +} + +int ss_bs_init(void) +{ + if (0 > make_noti_file(BSNOTI_DIR, BSNOTI_FILE)) { + PRT_TRACE_ERR("make_noti_file() failed"); + launch_crash_worker((void *)BSNOTI_FULL_PATH); + } + + if (0 == ecore_file_init()) { + PRT_TRACE_ERR("ecore_file_init() failed"); + launch_crash_worker((void *)BSNOTI_FULL_PATH); + } + + bs_file_monitor = ecore_file_monitor_add(BSNOTI_FULL_PATH,(void *) __bs_file_cb, NULL); + if (!bs_file_monitor) { + PRT_TRACE_ERR("ecore_file_monitor_add() failed"); + launch_crash_worker((void *)BSNOTI_FULL_PATH); + return -1; + } + + return 0; +} diff --git a/ss_bs.h b/ss_bs.h new file mode 100644 index 0000000..0866f55 --- /dev/null +++ b/ss_bs.h @@ -0,0 +1,23 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#ifndef __SS_BS_H__ +#define __SS_BS_H__ + +int ss_bs_init(void); + +#endif /* __SS_BS_H__ */ diff --git a/ss_core.c b/ss_core.c new file mode 100644 index 0000000..af97204 --- /dev/null +++ b/ss_core.c @@ -0,0 +1,122 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#include +#include "include/ss_data.h" +#include "ss_queue.h" +#include "ss_log.h" +#include "ss_predefine.h" +#include "ss_core.h" + +enum ss_core_cmd_type { + SS_CORE_ACT_RUN, + SS_CORE_ACT_CLEAR +}; + +struct _internal_msg { + int type; + int pid; +}; + +static int core_pipe[2]; + +static int _ss_core_action_run(void *user_data, + struct ss_run_queue_entry *rq_entry) +{ + struct ss_action_entry *act_entry = rq_entry->action_entry; + int ret; + char tmp[128]; + + rq_entry->state = SS_STATE_RUNNING; + ret = act_entry->predefine_action(rq_entry->argc, rq_entry->argv); + if (ret <= 0) { + if (ret < 0) + PRT_TRACE_ERR("[SYSMAN] predefine action failed"); + goto fast_done; + } else { + snprintf(tmp, sizeof(tmp), "/proc/%d/status", ret); + if (access(tmp, R_OK) == 0) + rq_entry->forked_pid = ret; + else + goto fast_done; + } + return 0; + + fast_done: + rq_entry->forked_pid = -1; + rq_entry->state = SS_STATE_DONE; + ss_core_action_clear(-1); + return 0; +} + +static int core_pipe_cb(void *userdata, Ecore_Fd_Handler * fd_handler) +{ + struct ss_main_data *ad = (struct ss_main_data *)userdata; + struct _internal_msg p_msg; + + if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) { + PRT_TRACE_ERR + ("ecore_main_fd_handler_active_get error , return\n"); + return 1; + } + + read(core_pipe[0], &p_msg, sizeof(struct _internal_msg)); + + switch (p_msg.type) { + case SS_CORE_ACT_RUN: + ss_run_queue_run(SS_STATE_INIT, _ss_core_action_run, ad); + break; + case SS_CORE_ACT_CLEAR: + ss_run_queue_del_bypid(p_msg.pid); + break; + } + return 1; +} + +int ss_core_action_run() +{ + struct _internal_msg p_msg; + + p_msg.type = SS_CORE_ACT_RUN; + p_msg.pid = 0; + write(core_pipe[1], &p_msg, sizeof(struct _internal_msg)); + + return 0; +} + +int ss_core_action_clear(int pid) +{ + struct _internal_msg p_msg; + + p_msg.type = SS_CORE_ACT_CLEAR; + p_msg.pid = pid; + write(core_pipe[1], &p_msg, sizeof(struct _internal_msg)); + + return 0; +} + +int ss_core_init(struct ss_main_data *ad) +{ + if (pipe(core_pipe) < 0) { + PRT_TRACE_ERR("pipe cannot create"); + exit(1); + } + + ecore_main_fd_handler_add(core_pipe[0], ECORE_FD_READ, + core_pipe_cb, ad, NULL, NULL); + return 0; +} diff --git a/ss_core.h b/ss_core.h new file mode 100644 index 0000000..d789024 --- /dev/null +++ b/ss_core.h @@ -0,0 +1,27 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#ifndef __SS_CORE_H__ +#define __SS_CORE_H__ + +#include "include/ss_data.h" + +int ss_core_action_run(); +int ss_core_action_clear(int pid); +int ss_core_init(struct ss_main_data *ad); + +#endif /* __SS_CORE_H__ */ diff --git a/ss_cpu_handler.c b/ss_cpu_handler.c new file mode 100644 index 0000000..38924c2 --- /dev/null +++ b/ss_cpu_handler.c @@ -0,0 +1,322 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#include + +#include "ss_device_plugin.h" +#include "ss_log.h" +#include "include/ss_data.h" + +#define DEFAULT_MAX_CPU_FREQ 12000000 +#define DEFAULT_MIN_CPU_FREQ 1000000 + +static int max_cpu_freq_limit = -1; +static int min_cpu_freq_limit = -1; +static int cur_max_cpu_freq = INT_MIN; +static int cur_min_cpu_freq = INT_MAX; + +static Eina_List *max_cpu_freq_list; +static Eina_List *min_cpu_freq_list; + +struct cpu_freq_entry { + int pid; + int freq; +}; + +static void __set_freq_limit(); +static int __is_entry_enble(int pid); +static int __remove_entry_from_max_cpu_freq_list(int pid); +static int __remove_entry_from_min_cpu_freq_list(int pid); +static int __add_entry_to_max_cpu_freq_list(int pid, int freq); +static int __add_entry_to_min_cpu_freq_list(int pid, int freq); +static int __write_max_cpu_freq(int freq); +static int __write_min_cpu_freq(int freq); + +int set_max_frequency_action(int argc, char **argv) +{ + int r = -1; + + if (argc < 2) + return -1; + + r = __add_entry_to_max_cpu_freq_list(atoi(argv[0]), atoi(argv[1])); + if (r < 0) { + PRT_TRACE_ERR("Add entry failed"); + return -1; + } + + r = __write_max_cpu_freq(cur_max_cpu_freq); + if (r < 0) { + PRT_TRACE_ERR("Write entry failed"); + return -1; + } + + return 0; +} + +int set_min_frequency_action(int argc, char **argv) +{ + int r = -1; + + if (argc < 2) + return -1; + + r = __add_entry_to_min_cpu_freq_list(atoi(argv[0]), atoi(argv[1])); + if (r < 0) { + PRT_TRACE_ERR("Add entry failed"); + return -1; + } + + r = __write_min_cpu_freq(cur_min_cpu_freq); + if (r < 0) { + PRT_TRACE_ERR("Write entry failed"); + return -1; + } + + return 0; +} + +int release_max_frequency_action(int argc, char **argv) +{ + int r = -1; + if (argc < 1) + return -1; + + r = __remove_entry_from_max_cpu_freq_list(atoi(argv[0])); + if (r < 0) { + PRT_TRACE_ERR("Remove entry failed"); + return -1; + } + + if (cur_max_cpu_freq == INT_MIN) + cur_max_cpu_freq = max_cpu_freq_limit; + + r = __write_max_cpu_freq(cur_max_cpu_freq); + if (r < 0) { + PRT_TRACE_ERR("Write freq failed"); + return -1; + } + + return 0; +} + +int release_min_frequency_action(int argc, char **argv) +{ + int r = -1; + + if (argc < 1) + return -1; + + r = __remove_entry_from_min_cpu_freq_list(atoi(argv[0])); + if (r < 0) { + PRT_TRACE_ERR("Remove entry failed"); + return -1; + } + + if (cur_min_cpu_freq == INT_MAX) + cur_min_cpu_freq = min_cpu_freq_limit; + + r = __write_min_cpu_freq(cur_min_cpu_freq); + if (r < 0) { + PRT_TRACE_ERR("Write entry failed"); + return -1; + } + + return 0; +} + +int ss_cpu_handler_init(void) +{ + __set_freq_limit(); + + ss_action_entry_add_internal(PREDEF_SET_MAX_FREQUENCY, set_max_frequency_action, NULL, NULL); + ss_action_entry_add_internal(PREDEF_SET_MIN_FREQUENCY, set_min_frequency_action, NULL, NULL); + ss_action_entry_add_internal(PREDEF_RELEASE_MAX_FREQUENCY, release_max_frequency_action, NULL, NULL); + ss_action_entry_add_internal(PREDEF_RELEASE_MIN_FREQUENCY, release_min_frequency_action, NULL, NULL); + + return 0; +} + +static void __set_freq_limit() +{ + int ret; + + ret = plugin_intf->OEM_sys_get_cpufreq_cpuinfo_max_freq(&max_cpu_freq_limit); + if (ret < 0) { + PRT_TRACE_ERR("get cpufreq cpuinfo max readerror: %s", strerror(errno)); + max_cpu_freq_limit = DEFAULT_MAX_CPU_FREQ; + } + + ret = plugin_intf->OEM_sys_get_cpufreq_cpuinfo_min_freq(&min_cpu_freq_limit); + if (ret < 0) { + PRT_TRACE_ERR("get cpufreq cpuinfo min readerror: %s", strerror(errno)); + min_cpu_freq_limit = DEFAULT_MIN_CPU_FREQ; + } +} + +static int __is_entry_enable(int pid) +{ + char pid_path[PATH_MAX]; + + snprintf(pid_path, PATH_MAX, "/proc/%d", pid); + if (access(pid_path, F_OK) < 0) { + return 0; + } + + return 1; +} + +static int __remove_entry_from_max_cpu_freq_list(int pid) +{ + Eina_List *tmp; + Eina_List *tmp_next; + struct cpu_freq_entry *entry; + + cur_max_cpu_freq = INT_MIN; + + EINA_LIST_FOREACH_SAFE(max_cpu_freq_list, tmp, tmp_next, entry) { + if (entry != NULL) { + if ((!__is_entry_enable(entry->pid)) || (entry->pid == pid)) { + max_cpu_freq_list = eina_list_remove(max_cpu_freq_list, entry); + free(entry); + continue; + } + + if (entry->freq > cur_max_cpu_freq) { + cur_max_cpu_freq = entry->freq; + } + } + } + + return 0; +} + +static int __remove_entry_from_min_cpu_freq_list(int pid) +{ + Eina_List *tmp; + Eina_List *tmp_next; + struct cpu_freq_entry *entry; + + cur_min_cpu_freq = INT_MAX; + + EINA_LIST_FOREACH_SAFE(min_cpu_freq_list, tmp, tmp_next, entry) { + if (entry != NULL) { + if ((!__is_entry_enable(entry->pid)) || (entry->pid == pid)) { + min_cpu_freq_list = eina_list_remove(min_cpu_freq_list, entry); + free(entry); + continue; + } + + if (entry->freq < cur_min_cpu_freq) { + cur_min_cpu_freq = entry->freq; + } + + } + } + + return 0; +} + +static int __add_entry_to_max_cpu_freq_list(int pid, int freq) +{ + int r = -1; + struct cpu_freq_entry *entry; + + r = __remove_entry_from_max_cpu_freq_list(pid); + if (r < 0) { + PRT_TRACE_ERR("Remove duplicated entry failed"); + } + + if (freq > cur_max_cpu_freq) { + cur_max_cpu_freq = freq; + } + + entry = malloc(sizeof(struct cpu_freq_entry)); + if (!entry) { + PRT_TRACE_ERR("Malloc failed"); + return -1; + } + + entry->pid = pid; + entry->freq = freq; + + max_cpu_freq_list = eina_list_prepend(max_cpu_freq_list, entry); + if (!max_cpu_freq_list) { + PRT_TRACE_ERR("eina_list_prepend failed"); + return -1; + } + + return 0; +} + +static int __add_entry_to_min_cpu_freq_list(int pid, int freq) +{ + int r = -1; + struct cpu_freq_entry *entry; + + r = __remove_entry_from_min_cpu_freq_list(pid); + if (r < 0) { + PRT_TRACE_ERR("Remove duplicated entry failed"); + } + + if (freq < cur_min_cpu_freq) { + cur_min_cpu_freq = freq; + } + + entry = malloc(sizeof(struct cpu_freq_entry)); + if (!entry) { + PRT_TRACE_ERR("Malloc failed"); + return -1; + } + + entry->pid = pid; + entry->freq = freq; + + min_cpu_freq_list = eina_list_prepend(min_cpu_freq_list, entry); + if (!min_cpu_freq_list) { + PRT_TRACE_ERR("eina_list_prepend failed"); + return -1; + } + + return 0; +} + +static int __write_max_cpu_freq(int freq) +{ + int ret; + + ret = plugin_intf->OEM_sys_set_cpufreq_scaling_max_freq(freq); + if (ret < 0) { + PRT_TRACE_ERR("set cpufreq max freq write error: %s", strerror(errno)); + return -1; + } + + return 0; +} + +static int __write_min_cpu_freq(int freq) +{ + int ret; + + ret = plugin_intf->OEM_sys_set_cpufreq_scaling_min_freq(freq); + if (ret < 0) { + PRT_TRACE_ERR("set cpufreq min freq write error: %s", strerror(errno)); + return -1; + } + + return 0; +} diff --git a/ss_cpu_handler.h b/ss_cpu_handler.h new file mode 100644 index 0000000..e94b0d6 --- /dev/null +++ b/ss_cpu_handler.h @@ -0,0 +1,23 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#ifndef __SS_CPU_HANDLER_H__ +#define __SS_CPU_HANDLER_H__ + +int ss_cpu_handler_init(void); + +#endif /* __SS_CPU_HANDKER_H__ */ diff --git a/ss_device_change_handler.c b/ss_device_change_handler.c new file mode 100644 index 0000000..0f9463e --- /dev/null +++ b/ss_device_change_handler.c @@ -0,0 +1,229 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ss_queue.h" +#include "ss_log.h" +#include "ss_device_handler.h" +#include "ss_device_plugin.h" +#include "ss_noti.h" +#include "include/ss_data.h" + +#define BUFF_MAX 255 +#define SYS_CLASS_INPUT "/sys/class/input" + +struct input_event { + long dummy[2]; + unsigned short type; + unsigned short code; + int value; +}; + +enum snd_jack_types { + SND_JACK_HEADPHONE = 0x0001, + SND_JACK_MICROPHONE = 0x0002, + SND_JACK_HEADSET = SND_JACK_HEADPHONE | SND_JACK_MICROPHONE, + SND_JACK_LINEOUT = 0x0004, + SND_JACK_MECHANICAL = 0x0008, /* If detected separately */ + SND_JACK_VIDEOOUT = 0x0010, + SND_JACK_AVOUT = SND_JACK_LINEOUT | SND_JACK_VIDEOOUT, +}; + +static void usb_chgdet_cb(struct ss_main_data *ad) +{ + PRT_TRACE("jack - usb changed\n"); + pm_change_state(LCD_NORMAL); + /* check charging now */ + ss_lowbat_is_charge_in_now(); + /* check current battery level */ + ss_lowbat_monitor(NULL); + ss_action_entry_call_internal(PREDEF_USBCON, 0); +} + +static void ta_chgdet_cb(struct ss_main_data *ad) +{ + PRT_TRACE("jack - ta changed\n"); + pm_change_state(LCD_NORMAL); + /* check charging now */ + ss_lowbat_is_charge_in_now(); + /* check current battery level */ + ss_lowbat_monitor(NULL); + + int val = -1; + int ret = -1; + int bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; + + if (plugin_intf->OEM_sys_get_jack_charger_online(&val) == 0) { + if (val == 0) { + pm_unlock_state(LCD_OFF, STAY_CUR_STATE); + + vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat_state); + if(bat_state < VCONFKEY_SYSMAN_BAT_NORMAL) { + bundle *b = NULL; + b = bundle_create(); + bundle_add(b, "_SYSPOPUP_CONTENT_", "warning"); + + ret = syspopup_launch("lowbat-syspopup", b); + if (ret < 0) { + PRT_TRACE_EM("popup lauch failed\n"); + } + bundle_free(b); + } + } else { + pm_lock_state(LCD_OFF, STAY_CUR_STATE, 0); + } + } + else + PRT_TRACE_ERR("failed to get ta status\n"); +} + +static void earjack_chgdet_cb(struct ss_main_data *ad) +{ + PRT_TRACE("jack - earjack changed\n"); + ss_action_entry_call_internal(PREDEF_EARJACKCON, 0); +} + +static void earkey_chgdet_cb(struct ss_main_data *ad) +{ + int val; + PRT_TRACE("jack - earkey changed\n"); + + if (plugin_intf->OEM_sys_get_jack_earkey_online(&val) == 0) + vconf_set_int(VCONFKEY_SYSMAN_EARJACKKEY, val); +} + +static void tvout_chgdet_cb(struct ss_main_data *ad) +{ + PRT_TRACE("jack - tvout changed\n"); + pm_change_state(LCD_NORMAL); +} + +static void hdmi_chgdet_cb(struct ss_main_data *ad) +{ + PRT_TRACE("jack - hdmi changed\n"); + pm_change_state(LCD_NORMAL); +} + +static void cradle_chgdet_cb(struct ss_main_data *ad) +{ + PRT_TRACE("jack - cradle changed\n"); +} + +static void keyboard_chgdet_cb(struct ss_main_data *ad) +{ + int val = -1; + int ret = -1; + PRT_TRACE("jack - keyboard changed\n"); + + ret = plugin_intf->OEM_sys_get_jack_keyboard_online(&val); + if( ret == 0) { + if(val != 1) + val = 0; + vconf_set_int(VCONFKEY_SYSMAN_SLIDING_KEYBOARD, val); + } else { + vconf_set_int(VCONFKEY_SYSMAN_SLIDING_KEYBOARD, VCONFKEY_SYSMAN_SLIDING_KEYBOARD_NOT_SUPPORTED); + } +} + +static void mmc_chgdet_cb(void *data) +{ + if (data == NULL) { + PRT_TRACE("mmc removed"); + ss_mmc_removed(); + } else { + PRT_TRACE("mmc added"); + ss_mmc_inserted(); + } +} + +static void ums_unmount_cb(void *data) +{ + umount(MOVINAND_MOUNT_POINT); +} + +static void charge_cb(struct ss_main_data *ad) +{ + int val = -1; + + if (plugin_intf->OEM_sys_get_battery_health(&val) == 0) { + if (val != BATTERY_GOOD) { + PRT_TRACE_ERR("Battery health status is not good (%d)", val); + ss_action_entry_call_internal(PREDEF_LOWBAT, 1, CHARGE_ERROR_ACT); + return; + } + } else { + PRT_TRACE_ERR("failed to get battery health status"); +} + + ss_action_entry_call_internal(PREDEF_LOWBAT, 1, CHARGE_CHECK_ACT); +} + +static void __usb_storage_cb(keynode_t *key, void *data) +{ + char *vconf_value; + + if (data == NULL) { + PRT_TRACE("USB Storage removed"); + vconf_value = vconf_get_str(VCONFKEY_INTERNAL_REMOVED_USB_STORAGE); + ss_action_entry_call_internal(PREDEF_USB_STORAGE_REMOVE, 1, vconf_value); + } else { + PRT_TRACE("USB Storage added"); + vconf_value = vconf_get_str(VCONFKEY_INTERNAL_ADDED_USB_STORAGE); + ss_action_entry_call_internal(PREDEF_USB_STORAGE_ADD, 1, vconf_value); + } +} + +int ss_device_change_init(struct ss_main_data *ad) +{ + /* for simple noti change cb */ + ss_noti_add("device_usb_chgdet", (void *)usb_chgdet_cb, (void *)ad); + ss_noti_add("device_ta_chgdet", (void *)ta_chgdet_cb, (void *)ad); + ss_noti_add("device_earjack_chgdet", (void *)earjack_chgdet_cb, (void *)ad); + ss_noti_add("device_earkey_chgdet", (void *)earkey_chgdet_cb, (void *)ad); + ss_noti_add("device_tvout_chgdet", (void *)tvout_chgdet_cb, (void *)ad); + ss_noti_add("device_hdmi_chgdet", (void *)hdmi_chgdet_cb, (void *)ad); + ss_noti_add("device_cradle_chgdet", (void *)cradle_chgdet_cb, (void *)ad); + ss_noti_add("device_keyboard_chgdet", (void *)keyboard_chgdet_cb, (void *)ad); + ss_noti_add("mmcblk_add", (void *)mmc_chgdet_cb, (void *)1); + ss_noti_add("mmcblk_remove", (void *)mmc_chgdet_cb, NULL); + + ss_noti_add("unmount_ums", (void *)ums_unmount_cb, NULL); + ss_noti_add("device_charge_chgdet", (void *)charge_cb, (void *)ad); + + if (vconf_notify_key_changed(VCONFKEY_INTERNAL_ADDED_USB_STORAGE, (void *)__usb_storage_cb, (void *)1) < 0) { + PRT_TRACE_ERR("Vconf notify key chaneged failed: KEY(%s)", VCONFKEY_SYSMAN_ADDED_USB_STORAGE); + } + + if (vconf_notify_key_changed(VCONFKEY_INTERNAL_REMOVED_USB_STORAGE, (void *)__usb_storage_cb, NULL) < 0) { + PRT_TRACE_ERR("Vconf notify key chaneged failed: KEY(%s)", VCONFKEY_SYSMAN_REMOVED_USB_STORAGE); + } + + cradle_chgdet_cb(NULL); + + return 0; +} diff --git a/ss_device_handler.h b/ss_device_handler.h new file mode 100644 index 0000000..0ba60c7 --- /dev/null +++ b/ss_device_handler.h @@ -0,0 +1,49 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#ifndef __SS_DEVICE_HANDLER_H__ +#define __SS_DEVICE_HANDLER_H__ + +#include "include/ss_data.h" + +/* MMC functions */ +int ss_mmc_init(); +int ss_mmc_inserted(); +int ss_mmc_removed(); + +/* USB Storage */ +int _ss_usb_storage_init(void); + +/* Battery functions */ +int ss_lowbat_init(struct ss_main_data *ad); +int ss_lowbat_is_charge_in_now(); +int ss_lowbat_set_charge_on(int onoff); +int ss_lowbat_monitor(void *data); + +/* Low memory functions */ +int ss_lowmem_init(struct ss_main_data *ad); + +/* USB functions */ +int ss_usb_init(); + +/* TA functions */ +int ss_ta_init(); + +/* device change init */ +int ss_device_change_init(struct ss_main_data *ad); + +#endif /* __SS_DEVICE_HANDLER_H__ */ diff --git a/ss_device_plugin.c b/ss_device_plugin.c new file mode 100644 index 0000000..a017506 --- /dev/null +++ b/ss_device_plugin.c @@ -0,0 +1,64 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#include +#include + +#include "ss_log.h" +#include "ss_device_plugin.h" + +static void *dlopen_handle; + +int _ss_devman_plugin_init() +{ + char *error; + + dlopen_handle = dlopen(DEVMAN_PLUGIN_PATH, RTLD_NOW); + if (!dlopen_handle) { + PRT_TRACE_ERR("dlopen() failed"); + return -1; + } + + const OEM_sys_devman_plugin_interface *(*get_devman_plugin_interface) (); + get_devman_plugin_interface = dlsym(dlopen_handle, "OEM_sys_get_devman_plugin_interface"); + if ((error = dlerror()) != NULL) { + PRT_TRACE_ERR("dlsym() failed: %s", error); + dlclose(dlopen_handle); + return -1; + } + + plugin_intf = get_devman_plugin_interface(); + if (!plugin_intf) { + PRT_TRACE_ERR("get_devman_plugin_interface() failed"); + dlclose(dlopen_handle); + return -1; + } + + return 0; +} + + +int _ss_devman_plugin_fini() +{ + if (dlopen_handle) { + dlclose(dlopen_handle); + } + + return 0; +} + + diff --git a/ss_device_plugin.h b/ss_device_plugin.h new file mode 100644 index 0000000..a49d6f6 --- /dev/null +++ b/ss_device_plugin.h @@ -0,0 +1,30 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#ifndef __SS_DEVICE_PLUGIN_H__ +#define __SS_DEVICE_PLUGIN_H__ + +#include "devman_plugin_intf.h" + +#define DEVMAN_PLUGIN_PATH "/usr/lib/libslp_devman_plugin.so" + +int _ss_devman_plugin_init(void); +int _ss_devman_plugin_fini(void); + +const OEM_sys_devman_plugin_interface *plugin_intf; + +#endif /* __SS_DEVICE_PLUGIN_H__ */ diff --git a/ss_launch.c b/ss_launch.c new file mode 100644 index 0000000..7c9966b --- /dev/null +++ b/ss_launch.c @@ -0,0 +1,342 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "vconf-keys.h" +#include "ss_log.h" +#include "ss_launch.h" + +#define MAX_ARGS 255 + +#define _S(str) ((str == NULL) ? "" : str) + +int ss_set_current_lang(void) +{ + char *lang; + int ret; + lang = vconf_get_str(VCONFKEY_LANGSET); + if (lang == NULL) + return -1; + ret = setenv("LANG", lang, 1); + if (ret < 0) + return -1; + free(lang); + return 0; +} + + +static void prepare_exec(void) +{ + int i; + int maxfd; + char buf[MAX_ARGS]; + FILE *fp; + + maxfd = getdtablesize(); + for (i = 3; i < maxfd; i++) + close(i); + + for (i = 0; i < _NSIG; i++) + signal(i, SIG_DFL); + + /* RESET oomadj value */ + sprintf(buf,"/proc/%d/oom_adj",getpid()); + fp = fopen(buf, "w"); + if (fp == NULL) + return; + fprintf(fp, "%d", 0); + fclose(fp); +} + +static int parse_cmd(const char *cmdline, char **argv, int max_args) +{ + const char *p; + char *buf, *bufp; + int nargs = 0; + int escape = 0, squote = 0, dquote = 0; + + if (cmdline == NULL || cmdline[0] == '\0') + return -1; + + bufp = buf = malloc(strlen(cmdline) + 1); + if (bufp == NULL || buf == NULL) + return -1; + + p = cmdline; + + while (*p) { + if (escape) { + *bufp++ = *p; + escape = 0; + } else { + switch (*p) { + case '\\': + escape = 1; + break; + case '"': + if (squote) + *bufp++ = *p; + else + dquote = !dquote; + break; + case '\'': + if (dquote) + *bufp++ = *p; + else + squote = !squote; + break; + case ' ': + if (!squote && !dquote) { + *bufp = '\0'; + if (nargs < max_args) + argv[nargs++] = strdup(buf); + bufp = buf; + break; + } + default: + *bufp++ = *p; + break; + } + } + p++; + } + + if (bufp != buf) { + *bufp = '\0'; + if (nargs < max_args) + argv[nargs++] = strdup(buf); + } + + argv[nargs++] = NULL; + + free(buf); + return nargs; +} + +int launch_app_with_nice(const char *file, char *const argv[], pid_t *pid, int _nice) +{ + int ret; + int _pid; + + if (file == NULL || access(file, X_OK) != 0) { + PRT_TRACE_ERR("launch app error: Invalid input"); + errno = EINVAL; + return -1; + } + + if (pid && (*pid > 0 && kill(*pid, 0) != -1)) + return *pid; + + _pid = fork(); + + if (_pid == -1) { + PRT_TRACE_ERR("fork error: %s", strerror(errno)); + /* keep errno */ + return -1; + } + + if (_pid > 0) { /* parent */ + if (pid) + *pid = _pid; + return _pid; + } + + /* child */ + prepare_exec(); + + ret = nice(_nice); + + if (ret == -1 && errno != 0) + PRT_TRACE_ERR("nice error: %s", strerror(errno)); + + ret = execvp(file, argv); + + /* If failed... */ + PRT_TRACE_ERR("exec. error: %s", strerror(errno)); + return -2; +} + +int launch_app_cmd_with_nice(const char *cmdline, int _nice) +{ + int i; + int nargs; + int ret; + char *argv[MAX_ARGS + 1]; + + nargs = parse_cmd(cmdline, argv, MAX_ARGS + 1); + if (nargs == -1) { + PRT_TRACE_ERR("launch app error: Invalid input"); + errno = EINVAL; + return -1; + } + + ret = launch_app_with_nice(argv[0], argv, NULL, _nice); + + for (i = 0; i < nargs; i++) + free(argv[i]); + + return ret; +} + +int launch_app_cmd(const char *cmdline) +{ + return launch_app_cmd_with_nice(cmdline, 0); +} + +int ss_launch_if_noexist(const char *execpath, const char *arg, ...) +{ + char *buf; + int pid; + int nice_value = 0; + int flag = 0; + int buf_size = -1; + va_list argptr; + + if (execpath == NULL) { + errno = EINVAL; + return -1; + } + if (pid = sysman_get_pid(execpath) > 0) + return pid; + + va_start(argptr, arg); + flag = va_arg(argptr, int); + + if (flag & SS_LAUNCH_NICE) + nice_value = va_arg(argptr, int); + + va_end(argptr); + + ss_set_current_lang(); + arg = _S(arg); + + buf_size = strlen(execpath) + strlen(arg) + 10; + buf = malloc(buf_size); + if (buf == NULL) { + /* Do something for not enought memory error */ + PRT_TRACE_ERR("Malloc failed"); + return -1; + } + + snprintf(buf, buf_size, "%s %s", execpath, arg); + pid = launch_app_cmd_with_nice(buf, nice_value); + if (pid == -2) + exit(0); + free(buf); + + return pid; +} + +int ss_launch_evenif_exist(const char *execpath, const char *arg, ...) +{ + char *buf; + int pid; + int nice_value = 0; + int flag = 0; + int buf_size = -1; + + va_list argptr; + + if (execpath == NULL) { + errno = EINVAL; + return -1; + } + + va_start(argptr, arg); + flag = va_arg(argptr, int); + + if (flag & SS_LAUNCH_NICE) + nice_value = va_arg(argptr, int); + + va_end(argptr); + + ss_set_current_lang(); + + arg = _S(arg); + + buf_size = strlen(execpath) + strlen(arg) + 10; + buf = malloc(buf_size); + if (buf == NULL) { + /* Do something for not enought memory error */ + PRT_TRACE_ERR("Malloc failed"); + return -1; + } + + snprintf(buf, buf_size, "%s %s", execpath, arg); + pid = launch_app_cmd_with_nice(buf, nice_value); + if (pid == -2) + exit(0); + free(buf); + + return pid; +} + +int ss_launch_after_kill_if_exist(const char *execpath, const char *arg, ...) +{ + char *buf; + int pid; + int nice_value = 0; + int flag = 0; + int buf_size = -1; + int exist_pid; + va_list argptr; + + if (execpath == NULL) { + errno = EINVAL; + return -1; + } + + if ((exist_pid = sysman_get_pid(execpath)) > 0) + kill(exist_pid, SIGTERM); + + va_start(argptr, arg); + flag = va_arg(argptr, int); + + if (flag & SS_LAUNCH_NICE) + nice_value = va_arg(argptr, int); + + va_end(argptr); + + ss_set_current_lang(); + + arg = _S(arg); + + buf_size = strlen(execpath) + strlen(arg) + 10; + buf = malloc(buf_size); + if (buf == NULL) { + /* Do something for not enought memory error */ + PRT_TRACE_ERR("Malloc Failed"); + return -1; + } + + snprintf(buf, buf_size, "%s %s", execpath, arg); + pid = launch_app_cmd_with_nice(buf, nice_value); + if (pid == -2) + exit(0); + free(buf); + + return pid; + +} diff --git a/ss_launch.h b/ss_launch.h new file mode 100644 index 0000000..5882ded --- /dev/null +++ b/ss_launch.h @@ -0,0 +1,27 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#ifndef __SS_LAUNCH_H__ +#define __SS_LAUNCH_H__ + +#define SS_LAUNCH_NICE 0x0002 + +int ss_launch_if_noexist(const char *execpath, const char *arg, ...); +int ss_launch_evenif_exist(const char *execpath, const char *arg, ...); +int ss_launch_after_kill_if_exist(const char *execpath, const char *arg, ...); + +#endif /* __SS_LAUNCH_H__ */ diff --git a/ss_log.c b/ss_log.c new file mode 100644 index 0000000..ac6134f --- /dev/null +++ b/ss_log.c @@ -0,0 +1,35 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#ifdef DEBUG +void __cyg_profile_func_enter(void *, void *) + __attribute__ ((no_instrument_function)); +void __cyg_profile_func_exit(void *, void *) + __attribute__ ((no_instrument_function)); + +int g_trace_depth = -2; + +void __cyg_profile_func_enter(void *func, void *caller) +{ + g_trace_depth++; +} + +void __cyg_profile_func_exit(void *func, void *caller) +{ + g_trace_depth--; +} +#endif diff --git a/ss_log.h b/ss_log.h new file mode 100644 index 0000000..d5c060f --- /dev/null +++ b/ss_log.h @@ -0,0 +1,137 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#ifndef __SS_LOG_H__ +#define __SS_LOG_H__ + +#include + +#if defined(ENABLE_DLOG_OUT) +#define LOG_TAG "SYSTEM_SERVER" +#include +#define DLOG_ERR DLOG_ERROR +#define __LOG(prio, fmt, arg...) \ + do { SLOG(prio, LOG_TAG, fmt, ##arg); } while (0) +#define __LOGD(prio, fmt, arg...) \ + do { SLOG(prio, LOG_TAG, "[%s:%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg); } while (0) +#define __PRT(prio, fmt, arg...) \ + do { fprintf(((D##prio) == DLOG_ERR ? stderr : stdout), fmt"\n", ##arg); } while (0) +#define __PRTD(prio, fmt, arg...) \ + do { \ + fprintf(((D##prio) == DLOG_ERR ? stderr : stdout), \ + "[%s:%d] "fmt"\n", __FILE__, __LINE__, ##arg); \ + } while (0) +#else +#include +#define __LOG(prio, fmt, arg...) \ + do { syslog(prio, fmt, ##arg); } while (0) +#define __LOGD(prio, fmt, arg...) \ + do { syslog(prio, "[%s:%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg); } while (0) +#define __PRT(prio, fmt, arg...) \ + do { fprintf(((prio) == LOG_ERR ? stderr : stdout), fmt"\n", ##arg); } while (0) +#define __PRTD(prio, fmt, arg...) \ + do { \ + fprintf(((prio) == LOG_ERR ? stderr : stdout), \ + "[%s:%d] "fmt"\n", __FILE__, __LINE__, ##arg); \ + } while (0) +#endif + +#ifdef DEBUG +extern int g_trace_depth; +#define __PRT_TRACE(prio, fmt, arg...) \ + do { __LOGD(prio, fmt, ##arg); } while (0) +/* do { \ + int ___i;\ + for(___i=0;___i +#include +#include +#include +#include +#include + +#include "ss_log.h" +#include "ss_launch.h" +#include "ss_noti.h" +#include "ss_queue.h" +#include "ss_device_plugin.h" +#include "include/ss_data.h" + +#define BAT_MON_INTERVAL 30 +#define BAT_MON_INTERVAL_MIN 2 + +#define BATTERY_CHARGING 65535 +#define BATTERY_UNKNOWN -1 +#define BATTERY_NORMAL 100 +#define BATTERY_WARNING_LOW 15 +#define BATTERY_CRITICAL_LOW 5 +#define BATTERY_POWER_OFF 1 +#define BATTERY_REAL_POWER_OFF 0 + +#define MAX_BATTERY_ERROR 10 +#define RESET_RETRY_COUNT 3 + +#define LOWBAT_EXEC_PATH PREFIX"/bin/lowbatt-popup" + +static int battery_level_table[] = { + 5, /* BATTERY_LEVEL0 */ + 15, /* 1 */ + 25, /* 2 */ + 40, /* 3 */ + 60, /* 4 */ + 80, /* 5 */ + 100, /* 6 */ +}; + +#define _SYS_LOW_POWER "LOW_POWER" + +struct lowbat_process_entry { + unsigned cur_bat_state; + unsigned new_bat_state; + int (*action) (void *); +}; + +static Ecore_Timer *lowbat_timer; +static int cur_bat_state = BATTERY_UNKNOWN; +static int cur_bat_capacity = -1; + +static int bat_err_count = 0; + +static int battery_warning_low_act(void *ad); +static int battery_critical_low_act(void *ad); +static int battery_power_off_act(void *ad); + +static struct lowbat_process_entry lpe[] = { + {BATTERY_NORMAL, BATTERY_WARNING_LOW, battery_warning_low_act}, + {BATTERY_WARNING_LOW, BATTERY_CRITICAL_LOW, battery_critical_low_act}, + {BATTERY_CRITICAL_LOW, BATTERY_POWER_OFF, battery_critical_low_act}, + {BATTERY_POWER_OFF, BATTERY_REAL_POWER_OFF, battery_power_off_act}, + {BATTERY_NORMAL, BATTERY_CRITICAL_LOW, battery_critical_low_act}, + {BATTERY_WARNING_LOW, BATTERY_POWER_OFF, battery_critical_low_act}, + {BATTERY_CRITICAL_LOW, BATTERY_REAL_POWER_OFF, battery_power_off_act}, + {BATTERY_NORMAL, BATTERY_POWER_OFF, battery_critical_low_act}, + {BATTERY_WARNING_LOW, BATTERY_REAL_POWER_OFF, battery_power_off_act}, + {BATTERY_NORMAL, BATTERY_REAL_POWER_OFF, battery_power_off_act}, +}; + +static int battery_warning_low_act(void *data) +{ + char lowbat_noti_name[NAME_MAX]; + + heynoti_get_snoti_name(_SYS_LOW_POWER, lowbat_noti_name, NAME_MAX); + ss_noti_send(lowbat_noti_name); + + ss_action_entry_call_internal(PREDEF_LOWBAT, 1, WARNING_LOW_BAT_ACT); + return 0; +} + +static int battery_critical_low_act(void *data) +{ + ss_action_entry_call_internal(PREDEF_LOWBAT, 1, CRITICAL_LOW_BAT_ACT); + return 0; +} + +static int battery_power_off_act(void *data) +{ + ss_action_entry_call_internal(PREDEF_LOWBAT, 1, POWER_OFF_BAT_ACT); + return 0; +} + +static int battery_charge_act(void *data) +{ + return 0; +} + +int ss_lowbat_set_charge_on(int onoff) +{ + if(vconf_set_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, onoff)!=0) { + PRT_TRACE_ERR("fail to set charge vconf value"); + return -1; + } + return 0; +} + +int ss_lowbat_is_charge_in_now() +{ + int val = 0; + if (0 > plugin_intf->OEM_sys_get_battery_charge_now(&val)) { + PRT_TRACE_ERR("fail to read charge now from kernel"); + ss_lowbat_set_charge_on(0); + return 0; + } + + if (val == 1) { + ss_lowbat_set_charge_on(1); + return 1; + } else { + ss_lowbat_set_charge_on(0); + return 0; + } +} + +static int lowbat_process(int bat_percent, void *ad) +{ + int new_bat_capacity; + int new_bat_state; + int vconf_state = -1; + int i, ret = 0; + + new_bat_capacity = bat_percent; + if (new_bat_capacity < 0) + return -1; + if (new_bat_capacity != cur_bat_capacity) { + if (vconf_set_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, new_bat_capacity) == 0) + cur_bat_capacity = new_bat_capacity; + PRT_TRACE("[BAT_MON] cur = %d new = %d", cur_bat_capacity, new_bat_capacity); + } + + if (0 > vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &vconf_state)) { + PRT_TRACE_ERR("vconf_get_int() failed"); + return -1; + } + + if (new_bat_capacity <= BATTERY_POWER_OFF) { + new_bat_state = BATTERY_POWER_OFF; + if (vconf_state != VCONFKEY_SYSMAN_BAT_POWER_OFF) + ret=vconf_set_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, VCONFKEY_SYSMAN_BAT_POWER_OFF); + } else if (new_bat_capacity <= BATTERY_CRITICAL_LOW) { + new_bat_state = BATTERY_CRITICAL_LOW; + if (vconf_state != VCONFKEY_SYSMAN_BAT_CRITICAL_LOW) + ret=vconf_set_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, VCONFKEY_SYSMAN_BAT_CRITICAL_LOW); + } else if (new_bat_capacity <= BATTERY_WARNING_LOW) { + new_bat_state = BATTERY_WARNING_LOW; + if (vconf_state != VCONFKEY_SYSMAN_BAT_WARNING_LOW) + ret=vconf_set_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, VCONFKEY_SYSMAN_BAT_WARNING_LOW); + } else { + new_bat_state = BATTERY_NORMAL; + if (vconf_state != VCONFKEY_SYSMAN_BAT_NORMAL) + ret=vconf_set_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, VCONFKEY_SYSMAN_BAT_NORMAL); + } + + if(ret < 0) + return -1; + + ss_lowbat_is_charge_in_now(); + + if (cur_bat_state == new_bat_state + && cur_bat_state != BATTERY_POWER_OFF) + return 0; + + if (cur_bat_state == BATTERY_UNKNOWN) { + for (i = 0; + i < sizeof(lpe) / sizeof(struct lowbat_process_entry); + i++) { + if (new_bat_state == lpe[i].new_bat_state) { + lpe[i].action(ad); + cur_bat_state = new_bat_state; + return 0; + } + } + } else { + for (i = 0; + i < sizeof(lpe) / sizeof(struct lowbat_process_entry); + i++) { + if ((cur_bat_state == lpe[i].cur_bat_state) + && (new_bat_state == lpe[i].new_bat_state)) { + lpe[i].action(ad); + cur_bat_state = new_bat_state; + return 0; + } + } + } + cur_bat_state = new_bat_state; + PRT_TRACE("[BATMON] Unknown battery state"); + return -1; +} + +static int lowbat_read() +{ + int bat_percent; + + plugin_intf->OEM_sys_get_battery_capacity(&bat_percent); + + return bat_percent; +} + +int ss_lowbat_monitor(void *data) +{ + struct ss_main_data *ad = (struct ss_main_data *)data; + int bat_percent; + + bat_percent = lowbat_read(); + if (bat_percent < 0) { + ecore_timer_interval_set(lowbat_timer, BAT_MON_INTERVAL_MIN); + bat_err_count++; + if (bat_err_count > MAX_BATTERY_ERROR) { + PRT_TRACE_ERR + ("[BATMON] Cannot read battery gage. stop read fuel gage"); + return 0; + } + return 1; + } + if (bat_percent > 100) + bat_percent = 100; + + if (lowbat_process(bat_percent, ad) < 0) + ecore_timer_interval_set(lowbat_timer, BAT_MON_INTERVAL_MIN); + else + ecore_timer_interval_set(lowbat_timer, BAT_MON_INTERVAL); + + return 1; +} + +static int wakeup_cb(keynode_t *key_nodes, void *data) +{ + int pm_state = 0; + + if ((pm_state = + vconf_keynode_get_int(key_nodes)) == VCONFKEY_PM_STATE_LCDOFF) + ss_lowbat_monitor(NULL); + + return 0; +} + +/* for debugging (request by kernel) */ +static int check_battery() +{ + int r; + int ret = -1; + + if (0 > plugin_intf->OEM_sys_get_battery_present(&ret)) { + PRT_TRACE_ERR("[BATMON] battery check : %d", ret); + } + PRT_TRACE("[BATMON] battery check : %d", ret); + + return ret; +} + +int ss_lowbat_init(struct ss_main_data *ad) +{ + int i; + + /* need check battery */ + lowbat_timer = + ecore_timer_add(BAT_MON_INTERVAL_MIN, ss_lowbat_monitor, ad); + ss_lowbat_is_charge_in_now(); + + vconf_notify_key_changed(VCONFKEY_PM_STATE, (void *)wakeup_cb, NULL); + + return 0; +} diff --git a/ss_lowmem_handler.c b/ss_lowmem_handler.c new file mode 100644 index 0000000..d650ff5 --- /dev/null +++ b/ss_lowmem_handler.c @@ -0,0 +1,266 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ss_device_plugin.h" +#include "ss_log.h" +#include "ss_noti.h" +#include "ss_queue.h" +#include "include/ss_data.h" + +#define DELETE_SM "sh -c "PREFIX"/bin/delete.sm" + +#define MEMNOTIFY_NORMAL 0x0000 +#define MEMNOTIFY_LOW 0xfaac +#define MEMNOTIFY_CRITICAL 0xdead +#define MEMNOTIFY_REBOOT 0xb00f + +#define _SYS_RES_CLEANUP "RES_CLEANUP" + +#define MEM_THRESHOLD_LV1 60 +#define MEM_THRESHOLD_LV2 40 + + +struct lowmem_process_entry { + unsigned cur_mem_state; + unsigned new_mem_state; + int (*action) (void *); +}; + +static int lowmem_fd = -1; +static int cur_mem_state = MEMNOTIFY_NORMAL; + +Ecore_Timer *oom_timer; +#define OOM_TIMER_INTERVAL 5 + +static int memory_low_act(void *ad); +static int memory_oom_act(void *ad); +static int memory_normal_act(void *ad); + +static struct lowmem_process_entry lpe[] = { + {MEMNOTIFY_NORMAL, MEMNOTIFY_LOW, memory_low_act}, + {MEMNOTIFY_NORMAL, MEMNOTIFY_CRITICAL, memory_oom_act}, + {MEMNOTIFY_LOW, MEMNOTIFY_CRITICAL, memory_oom_act}, + {MEMNOTIFY_CRITICAL, MEMNOTIFY_CRITICAL, memory_oom_act}, + {MEMNOTIFY_LOW, MEMNOTIFY_NORMAL, memory_normal_act}, + {MEMNOTIFY_CRITICAL, MEMNOTIFY_NORMAL, memory_normal_act}, + +}; + +unsigned int oom_delete_sm_time = 0; + +static int remove_shm() +{ + int maxid, shmid, id; + struct shmid_ds shmseg; + struct shm_info shm_info; + + maxid = shmctl(0, SHM_INFO, (struct shmid_ds *)(void *)&shm_info); + if (maxid < 0) { + PRT_TRACE_ERR("shared mem error\n"); + return -1; + } + + for (id = 0; id <= maxid; id++) { + shmid = shmctl(id, SHM_STAT, &shmseg); + if (shmid < 0) + continue; + if (shmseg.shm_nattch == 0) { + PRT_TRACE("shared memory killer ==> %d killed\n", + shmid); + shmctl(shmid, IPC_RMID, NULL); + } + } + return 0; +} + +static char *convert_to_str(unsigned int mem_state) +{ + char *tmp; + switch (mem_state) { + case MEMNOTIFY_NORMAL: + tmp = "mem normal"; + break; + case MEMNOTIFY_LOW: + tmp = "mem low"; + break; + case MEMNOTIFY_CRITICAL: + tmp = "mem critical"; + break; + case MEMNOTIFY_REBOOT: + tmp = "mem reboot"; + break; + default: + assert(0); + } + return tmp; +} + +static void print_lowmem_state(unsigned int mem_state) +{ + PRT_TRACE("[LOW MEM STATE] %s ==> %s", convert_to_str(cur_mem_state), + convert_to_str(mem_state)); +} + +static int memory_low_act(void *data) +{ + char lowmem_noti_name[NAME_MAX]; + + PRT_TRACE("[LOW MEM STATE] memory low state"); + remove_shm(); + + heynoti_get_snoti_name(_SYS_RES_CLEANUP, lowmem_noti_name, NAME_MAX); + ss_noti_send(lowmem_noti_name); + vconf_set_int(VCONFKEY_SYSMAN_LOW_MEMORY, + VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING); + + ss_action_entry_call_internal(PREDEF_LOWMEM, 1, LOW_MEM_ACT); + + return 0; +} + +static int memory_oom_act(void *data) +{ + unsigned int cur_time; + char lowmem_noti_name[NAME_MAX]; + + PRT_TRACE("[LOW MEM STATE] memory oom state"); + cur_time = time(NULL); + PRT_TRACE("cur=%d, old=%d, cur-old=%d", cur_time, oom_delete_sm_time, + cur_time - oom_delete_sm_time); + if (cur_time - oom_delete_sm_time > 15) { + remove_shm(); + oom_delete_sm_time = cur_time; + /* Also clean up unreturned memory of applications */ + heynoti_get_snoti_name(_SYS_RES_CLEANUP, lowmem_noti_name, + NAME_MAX); + ss_noti_send(lowmem_noti_name); + } + vconf_set_int(VCONFKEY_SYSMAN_LOW_MEMORY, + VCONFKEY_SYSMAN_LOW_MEMORY_HARD_WARNING); + + ss_action_entry_call_internal(PREDEF_LOWMEM, 1, OOM_MEM_ACT); + + return 1; +} + +static int memory_normal_act(void *data) +{ + PRT_TRACE("[LOW MEM STATE] memory normal state"); + vconf_set_int(VCONFKEY_SYSMAN_LOW_MEMORY, + VCONFKEY_SYSMAN_LOW_MEMORY_NORMAL); + return 0; +} + +static int lowmem_process(unsigned int mem_state, void *ad) +{ + int i; + for (i = 0; i < sizeof(lpe) / sizeof(struct lowmem_process_entry); i++) { + if ((cur_mem_state == lpe[i].cur_mem_state) + && (mem_state == lpe[i].new_mem_state)) { + + if(oom_timer != NULL) { + ecore_timer_del(oom_timer); + oom_timer = NULL; + } + lpe[i].action(ad); + if(mem_state == MEMNOTIFY_CRITICAL) + oom_timer = ecore_timer_add(OOM_TIMER_INTERVAL,lpe[i].action, ad); + return 0; + } + } + return 0; +} + +static unsigned int lowmem_read(int fd) +{ + unsigned int mem_state; + read(fd, &mem_state, sizeof(mem_state)); + return mem_state; +} + +static int lowmem_cb(void *data, Ecore_Fd_Handler * fd_handler) +{ + int fd; + struct ss_main_data *ad = (struct ss_main_data *)data; + unsigned int mem_state; + + if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) { + PRT_TRACE_ERR + ("ecore_main_fd_handler_active_get error , return\n"); + return 1; + } + + fd = ecore_main_fd_handler_fd_get(fd_handler); + + mem_state = lowmem_read(fd); + print_lowmem_state(mem_state); + lowmem_process(mem_state, ad); + cur_mem_state = mem_state; + + return 1; +} + +static int set_threshold() +{ + if (0 > plugin_intf->OEM_sys_set_memnotify_threshold_lv1(MEM_THRESHOLD_LV1)) { + PRT_TRACE_ERR("Set memnorify threshold lv1 failed"); + return -1; + } + + if (0 > plugin_intf->OEM_sys_set_memnotify_threshold_lv2(MEM_THRESHOLD_LV2)) { + PRT_TRACE_ERR("Set memnorify threshold lv2 failed"); + return -1; + } + + return 0; +} + +int ss_lowmem_init(struct ss_main_data *ad) +{ + char lowmem_dev_node[PATH_MAX]; + + if (0 > plugin_intf->OEM_sys_get_memnotify_node(lowmem_dev_node)) { + PRT_TRACE_ERR("Low memory handler fd init failed"); + return -1; + } + + lowmem_fd = open(lowmem_dev_node, O_RDONLY); + if (lowmem_fd < 0) { + PRT_TRACE_ERR("ss_lowmem_init fd open failed"); + return -1; + } + + oom_timer=NULL; + ecore_main_fd_handler_add(lowmem_fd, ECORE_FD_READ, lowmem_cb, ad, NULL, + NULL); + if (set_threshold() < 0) { + PRT_TRACE_ERR("Setting lowmem threshold is failed"); + return -1; + } + + return 0; +} diff --git a/ss_main.c b/ss_main.c new file mode 100644 index 0000000..7a32da4 --- /dev/null +++ b/ss_main.c @@ -0,0 +1,128 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#include +#include +#include +#include + +#include "ss_log.h" +#include "ss_core.h" +#include "ss_sig_handler.h" +#include "ss_device_handler.h" +#include "ss_sysnoti.h" +#include "ss_noti.h" +#include "ss_queue.h" +#include "ss_predefine.h" +#include "ss_bs.h" +#include "ss_procmgr.h" +#include "ss_timemgr.h" +#include "ss_cpu_handler.h" +#include "ss_device_plugin.h" +#include "include/ss_data.h" + +static void fini(struct ss_main_data *ad) +{ +} + +static void init_ad(struct ss_main_data *ad) +{ + memset(ad, 0x0, sizeof(struct ss_main_data)); +} + +static void writepid(char *pidpath) +{ + FILE *fp; + + fp = fopen(pidpath, "w"); + if (fp != NULL) { + fprintf(fp, "%d", getpid()); + fclose(fp); + } +} + +static void system_server_init(struct ss_main_data *ad) +{ + if (0 > _ss_devman_plugin_init()) { + PRT_TRACE_ERR("Device Manager Plugin Initialize failed"); + exit (-1); + } + + /* telephony initialize */ + int ret = 0; + ret = tel_init(); + if (ret != TAPI_API_SUCCESS) { + PRT_TRACE_ERR("tapi init error : [0x%x]", ret); + } + /* Register Telephony Client */ + ret = tel_register_app_name("slp.system.server"); + if (ret != TAPI_API_SUCCESS) { + PRT_TRACE_ERR("tapi app register error : [0x%x]", ret); + } + + ad->sysnoti_fd = ss_sysnoti_init(); + if (ss_noti_init() < 0) + PRT_TRACE_ERR("init noti error"); + + ss_queue_init(); + ss_core_init(ad); + ss_signal_init(); + ss_predefine_internal_init(); + ss_process_manager_init(); + ss_time_manager_init(); + ss_cpu_handler_init(); + + ss_lowmem_init(ad); + ss_lowbat_init(ad); + ss_usb_init(); + ss_ta_init(); + ss_device_change_init(ad); + ss_mmc_init(); + ss_bs_init(); + _ss_usb_storage_init(); +} + +#define SS_PIDFILE_PATH "/var/run/.system_server.pid" + +static int system_main(int argc, char **argv) +{ + struct ss_main_data ad; + + init_ad(&ad); + ad.noti_fd = heynoti_init(); + heynoti_attach_handler(ad.noti_fd); + system_server_init(&ad); + + ecore_main_loop_begin(); + + fini(&ad); + ecore_shutdown(); + + return 0; +} + +static int elm_main(int argc, char **argv) +{ + return system_main(argc, argv); +} + +int main(int argc, char **argv) +{ + writepid(SS_PIDFILE_PATH); + ecore_init(); + return elm_main(argc, argv); +} diff --git a/ss_mmc_handler.c b/ss_mmc_handler.c new file mode 100644 index 0000000..9ee6eb3 --- /dev/null +++ b/ss_mmc_handler.c @@ -0,0 +1,241 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include "ss_log.h" +#include "ss_device_handler.h" + +#define MOVINAND_DEV "/dev/mmcblk0p1" +#define FORMAT_MMC PREFIX"/sbin/mkfs.vfat " +#define FORMAT_MOVINAND PREFIX"/bin/movi_format.sh" + +int mmc_status; + +int get_mmcblk_num() +{ + DIR *dp; + struct dirent *dir; + struct stat stat; + char buf[255]; + int fd; + int r; + int mmcblk_num; + + if ((dp = opendir("/sys/block")) == NULL) { + PRT_TRACE_ERR("Can not open directory..\n"); + return -1; + } + chdir("/sys/block"); + + while (dir = readdir(dp)) { + memset(&stat, 0, sizeof(struct stat)); + lstat(dir->d_name, &stat); + if (S_ISDIR(stat.st_mode) || S_ISLNK(stat.st_mode)) { + if (strncmp(".", dir->d_name, 1) == 0 + || strncmp("..", dir->d_name, 2) == 0) + continue; + if (strncmp("mmcblk", dir->d_name, 6) == 0) { + snprintf(buf, 255, "/sys/block/%s/device/type", + dir->d_name); + + fd = open(buf, O_RDONLY); + if (fd == -1) + PRT_TRACE_ERR("%s open error: %s", buf, + strerror(errno)); + r = read(fd, buf, 10); + if ((r >= 0) && (r < 10)) + buf[r] = '\0'; + else + PRT_TRACE_ERR("%s read error: %s", buf, + strerror(errno)); + close(fd); + if (strncmp("SD", buf, 2) == 0) { + char *str_mmcblk_num = strndup((dir->d_name) + 6, 1); + if (str_mmcblk_num == NULL) { + PRT_TRACE_ERR("Memory Allocation Failed"); + closedir(dp); + return -1; + } + mmcblk_num = + atoi(str_mmcblk_num); + + free(str_mmcblk_num); + closedir(dp); + PRT_TRACE("%d \n", mmcblk_num); + return mmcblk_num; + } + } + + } + } + closedir(dp); + PRT_TRACE_ERR("Failed to find mmc block number\n"); + return -1; +} + +static int ss_mmc_format_tmp(keynode_t *key_nodes, void *data) +{ + PRT_TRACE_ERR("mmc_format called"); + if (vconf_keynode_get_int(key_nodes) == 1) { + PRT_TRACE_ERR("format start"); + device_set_property(DEVTYPE_MMC, MMC_PROP_FORMAT, 0); + + } + + return 0; +} + +static int ss_mmc_format(keynode_t *key_nodes, void *data) +{ + PRT_TRACE_ERR("mmc format called"); + device_set_property(DEVTYPE_MMC, MMC_PROP_FORMAT, 0); + + return 0; +} + +int ss_mmc_unmounted(int argc, char **argv) +{ + int option = -1; + + if (argc < 1) { + PRT_TRACE_ERR("Option is wong"); + return -1; + } + if ((option = atoi(argv[0])) < 0) { + PRT_TRACE_ERR("Option is wong : %d", option); + return -1; + } + + if (umount2(MMC_MOUNT_POINT, option) != 0) { + PRT_TRACE_ERR("Failed to unmount mmc card\n"); + vconf_set_int(VCONFKEY_SYSMAN_MMC_UNMOUNT, + VCONFKEY_SYSMAN_MMC_UNMOUNT_FAILED); + return -1; + + } + vconf_set_int(VCONFKEY_SYSMAN_MMC_STATUS, + VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED); + vconf_set_int(VCONFKEY_SYSMAN_MMC_UNMOUNT, + VCONFKEY_SYSMAN_MMC_UNMOUNT_COMPLETED); + mmc_status = VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED; + + return 0; +} + +int ss_mmc_init() +{ + /* mmc card mount */ + ss_mmc_inserted(); + + vconf_notify_key_changed("memory/mmc/format", (void *)ss_mmc_format_tmp, + NULL); + + ss_action_entry_add_internal(PREDEF_MOUNT_MMC, ss_mmc_inserted, NULL, + NULL); + ss_action_entry_add_internal(PREDEF_UNMOUNT_MMC, ss_mmc_unmounted, NULL, + NULL); + ss_action_entry_add_internal(PREDEF_FORMAT_MMC, ss_mmc_format, NULL, + NULL); + return 0; +} + +int ss_mmc_inserted() +{ + char buf[NAME_MAX]; + int blk_num, ret, retry = 0; + char opt[NAME_MAX]; + char *popt = opt; + + if (mmc_status == VCONFKEY_SYSMAN_MMC_MOUNTED) { + PRT_DBG("Mmc is already mounted.\n"); + vconf_set_int(VCONFKEY_SYSMAN_MMC_STATUS, + VCONFKEY_SYSMAN_MMC_MOUNTED); + vconf_set_int(VCONFKEY_SYSMAN_MMC_MOUNT, + VCONFKEY_SYSMAN_MMC_MOUNT_ALREADY); + return -1; + } + + if (access(MMC_MOUNT_POINT, R_OK) != 0) + mkdir(MMC_MOUNT_POINT, 0755); + + if ((blk_num = get_mmcblk_num()) == -1) { + vconf_set_int(VCONFKEY_SYSMAN_MMC_STATUS, + VCONFKEY_SYSMAN_MMC_REMOVED); + vconf_set_int(VCONFKEY_SYSMAN_MMC_MOUNT, + VCONFKEY_SYSMAN_MMC_MOUNT_FAILED); + mmc_status = VCONFKEY_SYSMAN_MMC_REMOVED; + return 0; + } + popt = NULL; + + snprintf(buf, sizeof(buf), "%s%d", MMC_DEV, blk_num); + if (mount + (buf, MMC_MOUNT_POINT, "vfat", 0, + "uid=0,gid=0,dmask=0000,fmask=0111,iocharset=iso8859-1,utf8,shortname=mixed") + == 0) { + PRT_DBG("Mounted mmc card\n"); + vconf_set_int(VCONFKEY_SYSMAN_MMC_STATUS, + VCONFKEY_SYSMAN_MMC_MOUNTED); + vconf_set_int(VCONFKEY_SYSMAN_MMC_MOUNT, + VCONFKEY_SYSMAN_MMC_MOUNT_COMPLETED); + mmc_status = VCONFKEY_SYSMAN_MMC_MOUNTED; + return 0; + } + do { + snprintf(buf, sizeof(buf), "%s%dp1", MMC_DEV, blk_num); + if ((ret = + mount(buf, MMC_MOUNT_POINT, "vfat", 0, + "uid=0,gid=0,dmask=0000,fmask=0111,iocharset=iso8859-1,utf8,shortname=mixed")) + == 0) { + PRT_DBG("Mounted mmc card partition 1(%s)\n", buf); + vconf_set_int(VCONFKEY_SYSMAN_MMC_STATUS, + VCONFKEY_SYSMAN_MMC_MOUNTED); + vconf_set_int(VCONFKEY_SYSMAN_MMC_MOUNT, + VCONFKEY_SYSMAN_MMC_MOUNT_COMPLETED); + mmc_status = VCONFKEY_SYSMAN_MMC_MOUNTED; + return 0; + } + usleep(100000); + } while (ret == -1 && errno == ENOENT && retry++ < 10); + + vconf_set_int(VCONFKEY_SYSMAN_MMC_STATUS, + VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED); + vconf_set_int(VCONFKEY_SYSMAN_MMC_MOUNT, + VCONFKEY_SYSMAN_MMC_MOUNT_FAILED); + mmc_status = VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED; + PRT_TRACE_ERR("Failed to mount mmc card\n"); + return -1; +} + +int ss_mmc_removed() +{ + vconf_set_int(VCONFKEY_SYSMAN_MMC_STATUS, VCONFKEY_SYSMAN_MMC_REMOVED); + + if (umount2(MMC_MOUNT_POINT, MNT_DETACH) != 0) { + PRT_TRACE_ERR("Failed to unmount mmc card\n"); + } + mmc_status = VCONFKEY_SYSMAN_MMC_REMOVED; + + return 0; +} diff --git a/ss_noti.c b/ss_noti.c new file mode 100644 index 0000000..97a8938 --- /dev/null +++ b/ss_noti.c @@ -0,0 +1,55 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#include +#include "ss_log.h" + +static int noti_fd; + +int ss_noti_getfd() +{ + return noti_fd; +} + +int ss_noti_send(char *filename) +{ + return heynoti_publish(filename); +} + +int ss_noti_init() +{ + noti_fd = heynoti_init(); + if (noti_fd < 0) { + PRT_TRACE_ERR("heynoti_init error"); + return -1; + } + + if (heynoti_attach_handler(noti_fd) < 0) { + PRT_TRACE_ERR("heynoti_attach_handler error"); + return -1; + } + + return 0; +} + +int ss_noti_add(const char *noti, void (*cb) (void *), void *data) +{ + if (noti_fd < 0) + return -1; + + return heynoti_subscribe(noti_fd, noti, cb, data); +} diff --git a/ss_noti.h b/ss_noti.h new file mode 100644 index 0000000..58c5abe --- /dev/null +++ b/ss_noti.h @@ -0,0 +1,26 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#ifndef __SS_NOTI_H__ +#define __SS_NOTI_H__ + +int ss_noti_getfd(void); +int ss_noti_send(char *filename); +int ss_noti_add(const char *noti, void (*cb) (void *), void *data); +int ss_noti_init(void); + +#endif /* __SS_NOTI_H__ */ diff --git a/ss_pmon_handler.c b/ss_pmon_handler.c new file mode 100644 index 0000000..cdb2122 --- /dev/null +++ b/ss_pmon_handler.c @@ -0,0 +1,227 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ +#include "ss_log.h" +#include "ss_launch.h" + +#include +#include +#include +#include +#include + +#define PMON_DEV_NODE "/dev/pmon" +#define PMON_PERMANENT_DIR "/tmp/permanent" + +static int pmon_fd = -1; + +static int replace_char(int size, char *t) +{ + while (size > 0) { + if (*t == 0) + *t = ' '; + size--; + t++; + } + return 0; +} + +#define PERNAMENT_DIR "/tmp/permanent" + +static char *pmon_get_permanent_pname(int pid) +{ + int fd; + char buf[PATH_MAX]; + struct stat st; + char *cmdline = NULL; + + snprintf(buf, sizeof(buf), "%s/%d", PERNAMENT_DIR, pid); + fd = open(buf, O_RDONLY); + if (fd == -1) { + PRT_TRACE_ERR("file open error"); + return NULL; + } + + if (fstat(fd, &st) < 0) { + PRT_TRACE_ERR("fstat error"); + return NULL; + } + + PRT_TRACE("size = %d", (int)st.st_size); + + cmdline = malloc(st.st_size + 1); + if (cmdline == NULL) { + PRT_TRACE_ERR("Not enough memory"); + return NULL; + } + memset(cmdline, 0, st.st_size + 1); + + read(fd, cmdline, st.st_size); + /* TODO - must change more smarter */ + replace_char(st.st_size - 1, cmdline); + close(fd); + + return cmdline; +} + +static void print_pmon_state(unsigned int dead_pid) +{ + PRT_TRACE("[Process MON] %d killed", dead_pid); +} + +static int pmon_process(unsigned int pid, void *ad) +{ + char *cmdline; + int new_pid; + char old_file[PATH_MAX]; + int fd; + + if (sysconf_is_vip(pid)) { + PRT_TRACE_ERR("======================================="); + PRT_TRACE_ERR("[Process MON] VIP process dead."); + PRT_TRACE_ERR("======================================="); + } + /* If there is NOT a .hibernation_start file, run following codes + * On hibernation processing, just ignore relaunching */ + else if (access("/tmp/.hibernation_start", R_OK) != 0) { + cmdline = pmon_get_permanent_pname(pid); + if (cmdline != NULL) { + PRT_TRACE("[Process MON] %s relaunch", cmdline); + new_pid = ss_launch_evenif_exist(cmdline, ""); + free(cmdline); + if (new_pid > 0) { + /* TODO - set oom */ + char buf[PATH_MAX]; + char filepath[PATH_MAX]; + size_t cnt; + + if (access("/tmp/permanent", R_OK) < 0) { + PRT_TRACE + ("no predefined matrix dir = /tmp/permanent, so created"); + mkdir("/tmp/permanent", 0777); + } + + snprintf(filepath, sizeof(filepath), + "/tmp/permanent/%d", pid); + fd = open(filepath, O_RDONLY); + if (fd == -1) { + PRT_TRACE("Failed to open"); + return -1; + } + + cnt = read(fd, buf, PATH_MAX); + close(fd); + + if (cnt <= 0) { + PRT_TRACE("Failed to read"); + return -1; + } + + snprintf(filepath, sizeof(filepath), "%s/%d", + "/tmp/permanent", new_pid); + + fd = open(filepath, O_CREAT | O_WRONLY, 0644); + if (fd == -1) { + PRT_TRACE("Failed to open"); + return -1; + } + + if (write(fd, buf, cnt) == -1) { + PRT_TRACE("Failed to write"); + close(fd); + return -1; + } + close(fd); + + fd = open("/sys/class/pmon/mp_pnp", O_WRONLY); + + if (fd == -1) { + PRT_TRACE("Failed to open"); + return -1; + } + + write(fd, &new_pid, sizeof(int)); + + close(fd); + PRT_TRACE("[Process MON] %d ", new_pid); + + FILE *fp; + + PRT_TRACE + ("[Process MON] OOMADJ_SET : pid %d, new_oomadj %d", + new_pid, (-17)); + snprintf(buf, sizeof(buf), "/proc/%d/oom_adj", + new_pid); + fp = fopen(buf, "w"); + if (fp == NULL) + return -1; + fprintf(fp, "%d", (-17)); + fclose(fp); + + snprintf(old_file, sizeof(old_file), "%s/%d", + PMON_PERMANENT_DIR, pid); + unlink(old_file); + } else { + PRT_TRACE_ERR("[Process MON] failed relaunching"); + } + } + } + return 0; +} +/* +static unsigned int pmon_read(int fd) +{ + unsigned int pid; + read(fd, &pid, sizeof(pid)); + return pid; +} +*/ + +static int pmon_cb(void *data, Ecore_Fd_Handler * fd_handler) +{ + int fd; + struct ss_main_data *ad = (struct ss_main_data *)data; + int dead_pid; + + if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) { + PRT_TRACE_ERR + ("ecore_main_fd_handler_active_get error , return\n"); + return 1; + } + + fd = ecore_main_fd_handler_fd_get(fd_handler); + + if ((read(fd, &dead_pid, sizeof(dead_pid))) < 0) { + PRT_TRACE_ERR("Reading DEAD_PID failed, Return"); + return 1; + } + + print_pmon_state(dead_pid); + pmon_process(dead_pid, ad); + + return 1; +} + +int ss_pmon_init(struct ss_main_data *ad) +{ + pmon_fd = open(PMON_DEV_NODE, O_RDONLY); + if (pmon_fd < 0) { + PRT_TRACE_ERR("ss_pmon_init fd open failed"); + return -1; + } + ecore_main_fd_handler_add(pmon_fd, ECORE_FD_READ, pmon_cb, ad, NULL, + NULL); + return 0; +} diff --git a/ss_pmon_handler.h b/ss_pmon_handler.h new file mode 100644 index 0000000..a1c0fac --- /dev/null +++ b/ss_pmon_handler.h @@ -0,0 +1,22 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ +#define __SS_PMON_HANDLER_H__ + +#include "include/ss_data.h" + +int ss_pmon_init(struct ss_main_data *ad); + +#endif /* __SS_PMON_HANDLER_H__ */ diff --git a/ss_predefine.c b/ss_predefine.c new file mode 100644 index 0000000..e5ece31 --- /dev/null +++ b/ss_predefine.c @@ -0,0 +1,573 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ss_log.h" +#include "ss_launch.h" +#include "ss_queue.h" +#include "ss_device_handler.h" +#include "ss_device_plugin.h" +#include "ss_predefine.h" +#include "ss_procmgr.h" +#include "include/ss_data.h" + +#define PREDEFINE_SO_DIR PREFIX"/lib/ss_predefine/" + +#define CALL_EXEC_PATH PREFIX"/bin/call" +#define LOWMEM_EXEC_PATH PREFIX"/bin/lowmem-popup" +#define LOWBAT_EXEC_PATH PREFIX"/bin/lowbatt-popup" +#define USBCON_EXEC_PATH PREFIX"/bin/usb_setting" +#define TVOUT_EXEC_PATH PREFIX"/bin/tvout-selector" +#define PWROFF_EXEC_PATH PREFIX"/bin/poweroff-popup" +#define MEMPS_EXEC_PATH PREFIX"/bin/memps" + +/* wait for 5 sec as victim process be dead */ +#define WAITING_INTERVAL 5 + +#define TVOUT_X_BIN "/usr/bin/xberc" +#define TVOUT_FLAG 0x00000001 +#define MEMPS_LOG_FILE "/var/log/memps" +#define MAX_RETRY 2 + +#define POWEROFF_DURATION 2 +#define POWEROFF_ANIMATION_PATH "/usr/bin/boot-animation" +#define POWEROFF_NOTI_NAME "power_off_start" + +#define VCONFKEY_TESTMODE_LOW_BATT_POPUP "db/testmode/low_batt_popup" + +#define LOWBAT_OPT_WARNING 1 +#define LOWBAT_OPT_POWEROFF 2 +#define LOWBAT_OPT_CHARGEERR 3 +#define LOWBAT_OPT_CHECK 4 + +static Ecore_Timer *lowbat_popup_id = NULL; +static int lowbat_popup_option = 0; + +static struct timeval tv_start_poweroff; +static void powerdown_ap(TelTapiEvent_t *event, void *data); + +static int ss_flags = 0; + +static unsigned int power_subscription_id = 0; + +static void make_memps_log(char *file, pid_t pid, char *victim_name) +{ + time_t now; + struct tm *cur_tm; + char params[4096]; + char new_log[NAME_MAX]; + static pid_t old_pid = 0; + int ret=-1; + + if (old_pid == pid) + return; + old_pid = pid; + + now = time(NULL); + cur_tm = (struct tm *)malloc(sizeof(struct tm)); + if (cur_tm == NULL) { + PRT_TRACE_ERR("Fail to memory allocation"); + return; + } + + if (localtime_r(&now, cur_tm) == NULL) { + PRT_TRACE_ERR("Fail to get localtime"); + return; + } + + PRT_TRACE("%s_%s_%d_%.4d%.2d%.2d_%.2d%.2d%.2d.log", file, victim_name, + pid, (1900 + cur_tm->tm_year), 1 + cur_tm->tm_mon, + cur_tm->tm_mday, cur_tm->tm_hour, cur_tm->tm_min, + cur_tm->tm_sec); + snprintf(new_log, sizeof(new_log), + "%s_%s_%d_%.4d%.2d%.2d_%.2d%.2d%.2d.log", file, victim_name, + pid, (1900 + cur_tm->tm_year), 1 + cur_tm->tm_mon, + cur_tm->tm_mday, cur_tm->tm_hour, cur_tm->tm_min, + cur_tm->tm_sec); + + snprintf(params, sizeof(params), "-f %s", new_log); + ret = ss_launch_evenif_exist(MEMPS_EXEC_PATH, params); + + if(ret > 0) { + char buf[PATH_MAX]; + FILE *fp; + snprintf(buf, sizeof(buf), "/proc/%d/oom_adj", ret); + fp = fopen(buf, "w"); + if (fp != NULL) { + fprintf(fp, "%d", (-17)); + fclose(fp); + } + } + free(cur_tm); +} + +static int lowmem_get_victim_pid() +{ + pid_t pid; + int fd; + + if (0 > plugin_intf->OEM_sys_get_memnotify_victim_task(&pid)) { + PRT_TRACE_ERR("Get victim task failed"); + return -1; + } + + return pid; +} + +int lowmem_def_predefine_action(int argc, char **argv) +{ + int pid, ret, oom_adj; + char appname[PATH_MAX]; + + if (argc < 1) + return -1; + + if (!strcmp(argv[0], OOM_MEM_ACT)) { + pid = lowmem_get_victim_pid(); + if (pid > 0 && pid != sysman_get_pid(LOWMEM_EXEC_PATH) && pid != sysman_get_pid(MEMPS_EXEC_PATH)) { + if ((sysman_get_cmdline_name(pid, appname, PATH_MAX)) == + 0) { + PRT_TRACE_EM + ("we will kill, lowmem lv2 = %d (%s)\n", + pid, appname); + + make_memps_log(MEMPS_LOG_FILE, pid, appname); + + if(get_app_oomadj(pid, &oom_adj) < 0) { + PRT_TRACE_ERR("Failed to get oom_adj"); + } + PRT_TRACE("%d will be killed with %d oom_adj value", pid, oom_adj); + + kill(pid, SIGTERM); + + if (oom_adj >= OOMADJ_BACKGRD_UNLOCKED) { + return 0; + } + + bundle *b = NULL; + + b = bundle_create(); + bundle_add(b, "_APP_NAME_", appname); + ret = syspopup_launch("lowmem-syspopup", b); + bundle_free(b); + if (ret < 0) { + PRT_TRACE_EM("popup lauch failed\n"); + return -1; + } + + if (set_app_oomadj(ret, OOMADJ_SU) < 0) { + PRT_TRACE_ERR("Failed to set oom_adj"); + } + } + } + } else { + PRT_TRACE_EM("making memps log for low memory\n"); + make_memps_log(MEMPS_LOG_FILE, 1, "LOWMEM_WARNING"); + } + + return 0; +} + +int usbcon_def_predefine_action(int argc, char **argv) +{ + int pid; + int val = -1; + int ret = -1; + int bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; + + if (plugin_intf->OEM_sys_get_jack_usb_online(&val) == 0) { + if (val == 0) { + vconf_set_int(VCONFKEY_SYSMAN_USB_STATUS, + VCONFKEY_SYSMAN_USB_DISCONNECTED); + pm_unlock_state(LCD_OFF, STAY_CUR_STATE); + + vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat_state); + if(bat_state < VCONFKEY_SYSMAN_BAT_NORMAL) { + bundle *b = NULL; + b = bundle_create(); + bundle_add(b, "_SYSPOPUP_CONTENT_", "warning"); + + ret = syspopup_launch("lowbat-syspopup", b); + if (ret < 0) { + PRT_TRACE_EM("popup lauch failed\n"); + } + bundle_free(b); + } + return 0; + } + + vconf_set_int(VCONFKEY_SYSMAN_USB_STATUS, + VCONFKEY_SYSMAN_USB_AVAILABLE); + pm_lock_state(LCD_OFF, STAY_CUR_STATE, 0); + pid = ss_launch_if_noexist(USBCON_EXEC_PATH, NULL); + if (pid < 0) { + PRT_TRACE_ERR("usb predefine action failed\n"); + return -1; + } + return pid; + } + PRT_TRACE_ERR("failed to get usb status\n"); + return -1; +} + +int earjackcon_def_predefine_action(int argc, char **argv) +{ + int val; + + PRT_TRACE_EM("earjack_normal predefine action\n"); + if (plugin_intf->OEM_sys_get_jack_earjack_online(&val) == 0) { + return vconf_set_int(VCONFKEY_SYSMAN_EARJACK, val); + } + + return -1; +} + +int lowbat_popup(void *data) +{ + int ret = -1, state = 0; + ret = vconf_get_int("memory/boot-animation/finished", &state); + if (state == 1 || ret != 0) { + bundle *b = NULL; + b = bundle_create(); + if(lowbat_popup_option == LOWBAT_OPT_WARNING) { + bundle_add(b, "_SYSPOPUP_CONTENT_", "warning"); + } else if(lowbat_popup_option == LOWBAT_OPT_POWEROFF) { + bundle_add(b, "_SYSPOPUP_CONTENT_", "poweroff"); + } else if(lowbat_popup_option == LOWBAT_OPT_CHARGEERR) { + bundle_add(b, "_SYSPOPUP_CONTENT_", "chargeerr"); + } else { + bundle_add(b, "_SYSPOPUP_CONTENT_", "check"); + } + + ret = syspopup_launch("lowbat-syspopup", b); + if (ret < 0) { + PRT_TRACE_EM("popup lauch failed\n"); + bundle_free(b); + return 1; + } + lowbat_popup_id = NULL; + lowbat_popup_option = 0; + bundle_free(b); + } else { + PRT_TRACE_EM("boot-animation running yet"); + return 1; + } + + return 0; +} + +int lowbat_def_predefine_action(int argc, char **argv) +{ + int ret, state=0; + char argstr[128]; + char* option = NULL; + + if (argc < 1) + return -1; + + if(lowbat_popup_id != NULL) { + ecore_timer_del(lowbat_popup_id); + lowbat_popup_id = NULL; + } + + bundle *b = NULL; + b = bundle_create(); + if(!strcmp(argv[0],WARNING_LOW_BAT_ACT) || !strcmp(argv[0],CRITICAL_LOW_BAT_ACT)) { + bundle_add(b, "_SYSPOPUP_CONTENT_", "warning"); + lowbat_popup_option = LOWBAT_OPT_WARNING; + } else if(!strcmp(argv[0],POWER_OFF_BAT_ACT)) { + bundle_add(b, "_SYSPOPUP_CONTENT_", "poweroff"); + lowbat_popup_option = LOWBAT_OPT_POWEROFF; + } else if(!strcmp(argv[0],CHARGE_ERROR_ACT)) { + bundle_add(b, "_SYSPOPUP_CONTENT_", "chargeerr"); + lowbat_popup_option = LOWBAT_OPT_CHARGEERR; + } else { + bundle_add(b, "_SYSPOPUP_CONTENT_", "check"); + lowbat_popup_option = LOWBAT_OPT_CHECK; + } + + ret = vconf_get_int("memory/boot-animation/finished", &state); + if (state == 1 || ret != 0) { + ret = syspopup_launch("lowbat-syspopup", b); + if (ret < 0) { + PRT_TRACE_EM("popup lauch failed\n"); + bundle_free(b); + lowbat_popup_option = 0; + return -1; + } + } else { + PRT_TRACE_EM("boot-animation running yet"); + lowbat_popup_id = ecore_timer_add(1, lowbat_popup, NULL); + } + bundle_free(b); + return 0; +} + +Eina_Bool powerdown_ap_by_force(void *data) +{ + struct timeval now; + int poweroff_duration = POWEROFF_DURATION; + char *buf; + + /* Getting poweroff duration */ + buf = getenv("PWROFF_DUR"); + if (buf != NULL && strlen(buf) < 1024) + poweroff_duration = atoi(buf); + if (poweroff_duration < 0 || poweroff_duration > 60) + poweroff_duration = POWEROFF_DURATION; + + gettimeofday(&now, NULL); + /* Waiting until power off duration and displaying animation */ + while (now.tv_sec - tv_start_poweroff.tv_sec < poweroff_duration) { + usleep(100000); + gettimeofday(&now, NULL); + } + + PRT_TRACE("Power off by force\n"); + kill(-1, SIGTERM); + /* give a chance to be terminated for each process */ + sleep(1); + sync(); + reboot(RB_POWER_OFF); + return EINA_TRUE; +} + +static void powerdown_ap(TelTapiEvent_t *event, void *data) +{ + struct timeval now; + int poweroff_duration = POWEROFF_DURATION; + char *buf; + + if (power_subscription_id) { + tel_deregister_event(power_subscription_id); + power_subscription_id = 0; + } + PRT_TRACE("Power off \n"); + + /* Getting poweroff duration */ + buf = getenv("PWROFF_DUR"); + if (buf != NULL && strlen(buf) < 1024) + poweroff_duration = atoi(buf); + if (poweroff_duration < 0 || poweroff_duration > 60) + poweroff_duration = POWEROFF_DURATION; + + gettimeofday(&now, NULL); + /* Waiting until power off duration and displaying animation */ + while (now.tv_sec - tv_start_poweroff.tv_sec < poweroff_duration) { + usleep(100000); + gettimeofday(&now, NULL); + } + + kill(-1, SIGTERM); + /* give a chance to be terminated for each process */ + sleep(1); + sync(); + reboot(RB_POWER_OFF); +} + +int poweroff_def_predefine_action(int argc, char **argv) +{ + int ret; + + heynoti_publish(POWEROFF_NOTI_NAME); + + pm_change_state(LCD_NORMAL); + system("/etc/rc.d/rc.shutdown &"); + sync(); + + gettimeofday(&tv_start_poweroff, NULL); + ret = + tel_register_event(TAPI_EVENT_POWER_PHONE_OFF, + &power_subscription_id, + (TelAppCallback) & powerdown_ap, NULL); + if (ret != TAPI_API_SUCCESS) { + PRT_TRACE_ERR + ("tel_register_event is not subscribed. error %d\n", ret); + powerdown_ap_by_force(NULL); + return 0; + } + + ret = tel_process_power_command(TAPI_PHONE_POWER_OFF); + if (ret != TAPI_API_SUCCESS) { + PRT_TRACE_ERR("tel_process_power_command() error %d\n", ret); + powerdown_ap_by_force(NULL); + return 0; + } + + return 0; +} + +static void restart_ap(TelTapiEvent_t *event, void *data); + +Eina_Bool restart_ap_ecore(void *data) +{ + restart_ap(NULL, (void *)-1); + return EINA_TRUE; +} + +static void restart_ap(TelTapiEvent_t *event, void *data) +{ + struct timeval now; + int poweroff_duration = POWEROFF_DURATION; + char *buf; + + if (power_subscription_id) { + tel_deregister_event(power_subscription_id); + power_subscription_id = 0; + } + + PRT_INFO("Restart\n"); + sync(); + + buf = getenv("PWROFF_DUR"); + if (buf != NULL && strlen(buf) < 1024) + poweroff_duration = atoi(buf); + if (poweroff_duration < 0 || poweroff_duration > 60) + poweroff_duration = POWEROFF_DURATION; + gettimeofday(&now, NULL); + while (now.tv_sec - tv_start_poweroff.tv_sec < poweroff_duration) { + usleep(100000); + gettimeofday(&now, NULL); + } + + reboot(RB_AUTOBOOT); +} + +int restart_def_predefine_action(int argc, char **argv) +{ + int ret; + + pm_change_state(LCD_NORMAL); + system("/etc/rc.d/rc.shutdown &"); + sync(); + + gettimeofday(&tv_start_poweroff, NULL); + + ret = + tel_register_event(TAPI_EVENT_POWER_PHONE_OFF, + &power_subscription_id, + (TelAppCallback) & restart_ap, NULL); + if (ret != TAPI_API_SUCCESS) { + PRT_TRACE_ERR + ("tel_register_event is not subscribed. error %d\n", ret); + restart_ap(NULL, (void *)-1); + return 0; + } + + ret = tel_process_power_command(TAPI_PHONE_POWER_OFF); + if (ret != TAPI_API_SUCCESS) { + PRT_TRACE_ERR("tel_process_power_command() error %d\n", ret); + restart_ap(NULL, (void *)-1); + return 0; + } + + return 0; +} + +int launching_predefine_action(int argc, char **argv) +{ + int ret; + + if (argc < 0) + return -1; + + /* current just launching poweroff-popup */ + ret = syspopup_launch("poweroff-syspopup", NULL); + if (ret < 0) { + PRT_TRACE_ERR("poweroff popup predefine action failed"); + return -1; + } + return 0; +} + +static void ss_action_entry_load_from_sodir() +{ + DIR *dp; + struct dirent *dentry; + struct sysnoti *msg; + char *ext; + char tmp[128]; + + dp = opendir(PREDEFINE_SO_DIR); + if (!dp) { + ERR("fail open %s", PREDEFINE_SO_DIR); + return; + } + + msg = malloc(sizeof(struct sysnoti)); + if (msg == NULL) { + ERR("Malloc failed"); + closedir(dp); + return; + } + + msg->pid = getpid(); + + while ((dentry = readdir(dp)) != NULL) { + if ((ext = strstr(dentry->d_name, ".so")) == NULL) + continue; + + snprintf(tmp, sizeof(tmp), "%s/%s", PREDEFINE_SO_DIR, + dentry->d_name); + msg->path = tmp; + *ext = 0; + msg->type = &(dentry->d_name[3]); + ss_action_entry_add(msg); + } + free(msg); + + closedir(dp); +} + +void ss_predefine_internal_init(void) +{ + ss_action_entry_add_internal(PREDEF_LOWMEM, lowmem_def_predefine_action, + NULL, NULL); + ss_action_entry_add_internal(PREDEF_LOWBAT, lowbat_def_predefine_action, + NULL, NULL); + ss_action_entry_add_internal(PREDEF_USBCON, usbcon_def_predefine_action, + NULL, NULL); + ss_action_entry_add_internal(PREDEF_EARJACKCON, + earjackcon_def_predefine_action, NULL, + NULL); + ss_action_entry_add_internal(PREDEF_POWEROFF, + poweroff_def_predefine_action, NULL, NULL); + ss_action_entry_add_internal(PREDEF_PWROFF_POPUP, + launching_predefine_action, NULL, NULL); + ss_action_entry_add_internal(PREDEF_REBOOT, + restart_def_predefine_action, NULL, NULL); + + ss_action_entry_load_from_sodir(); + + /* check and set earjack init status */ + earjackcon_def_predefine_action(0, NULL); +} diff --git a/ss_predefine.h b/ss_predefine.h new file mode 100644 index 0000000..e117deb --- /dev/null +++ b/ss_predefine.h @@ -0,0 +1,24 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#ifndef __SS_PREDEFINE_H__ +#define __SS_PREDEFINE_H__ + +int call_predefine_action(int argc, char **argv); +void ss_predefine_internal_init(void); + +#endif /* __SS_PREDEFINE_H__ */ diff --git a/ss_procmgr.c b/ss_procmgr.c new file mode 100644 index 0000000..e09d396 --- /dev/null +++ b/ss_procmgr.c @@ -0,0 +1,373 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#include +#include +#include +#include +#include + +#include +#include "include/ss_data.h" +#include "ss_queue.h" +#include "ss_log.h" + +#define LIMITED_PROCESS_OOMADJ 15 + +int get_app_oomadj(int pid, int *oomadj) +{ + if (pid < 0) + return -1; + + char buf[PATH_MAX]; + FILE *fp = NULL; + + snprintf(buf, sizeof(buf), "/proc/%d/oom_adj", pid); + fp = fopen(buf, "r"); + if (fp == NULL) + return -1; + if (fgets(buf, PATH_MAX, fp) == NULL) { + fclose(fp); + return -1; + } + (*oomadj) = atoi(buf); + fclose(fp); + return 0; +} + +int set_app_oomadj(pid_t pid, int new_oomadj) +{ + char buf[PATH_MAX]; + FILE *fp; + int old_oomadj; + char exe_name[PATH_MAX]; + + if (sysman_get_cmdline_name(pid, exe_name, PATH_MAX) < 0) + snprintf(exe_name, sizeof(exe_name), "Unknown (maybe dead)"); + + snprintf(buf, sizeof(buf), "/proc/%d/oom_adj", pid); + fp = fopen(buf, "r"); + if (fp == NULL) + return -1; + if (fgets(buf, PATH_MAX, fp) == NULL) { + fclose(fp); + return -1; + } + old_oomadj = atoi(buf); + fclose(fp); + PRT_TRACE_EM("Process %s, pid %d, old_oomadj %d", exe_name, pid, + old_oomadj); + + if (old_oomadj < OOMADJ_APP_LIMIT) + return 0; + + PRT_TRACE_EM("Process %s, pid %d, new_oomadj %d", exe_name, pid, + new_oomadj); + snprintf(buf, sizeof(buf), "/proc/%d/oom_adj", pid); + fp = fopen(buf, "w"); + if (fp == NULL) + return -1; + + fprintf(fp, "%d", new_oomadj); + fclose(fp); + + return 0; +} + +int set_oomadj_action(int argc, char **argv) +{ + int pid = -1; + int new_oomadj = -20; + + if (argc < 2) + return -1; + if ((pid = atoi(argv[0])) < 0 || (new_oomadj = atoi(argv[1])) <= -20) + return -1; + + char buf[255]; + FILE *fp; + + PRT_TRACE_EM("OOMADJ_SET : pid %d, new_oomadj %d", pid, new_oomadj); + snprintf(buf, sizeof(buf), "/proc/%d/oom_adj", pid); + fp = fopen(buf, "w"); + if (fp == NULL) + return -1; + fprintf(fp, "%d", new_oomadj); + fclose(fp); + + return 0; +} + +int check_and_set_old_backgrd() +{ + int pid = -1; + DIR *dp; + struct dirent *dentry; + FILE *fp; + char buf[PATH_MAX]; + int token =0; + + dp = opendir("/proc"); + if (!dp) { + PRT_TRACE_EM("BACKGRD MANAGE : fail to open /proc : %s", strerror(errno)); + return -1; + } + + while ((dentry = readdir(dp)) != NULL) { + if (!isdigit(dentry->d_name[0])) + continue; + + pid = atoi(dentry->d_name); + + snprintf(buf, sizeof(buf), "/proc/%d/oom_adj", pid); + fp = fopen(buf, "r"); + if (fp == NULL) + continue; + if (fgets(buf, sizeof(buf), fp) == NULL) { + fclose(fp); + continue; + } + if(atoi(buf) == OOMADJ_BACKGRD_UNLOCKED) { + fclose(fp); + PRT_TRACE("BACKGRD MANAGE : process wchich has OOMADJ_BACKGRD_UNLOCKED exists"); + break; + } + fclose(fp); + } + closedir(dp); + + if(dentry != NULL ) { + int cur_oom=-1; + dp = opendir("/proc"); + if (!dp) { + PRT_TRACE_EM("BACKGRD MANAGE : fail to open /proc : %s", strerror(errno)); + return -1; + } + while ((dentry = readdir(dp)) != NULL) { + + if (!isdigit(dentry->d_name[0])) + continue; + + pid = atoi(dentry->d_name); + + snprintf(buf, sizeof(buf), "/proc/%d/oom_adj", pid); + fp = fopen(buf, "r+"); + if (fp == NULL) + continue; + if (fgets(buf, sizeof(buf), fp) == NULL) { + fclose(fp); + continue; + } + cur_oom = atoi(buf); + if(cur_oom >= LIMITED_PROCESS_OOMADJ) { + PRT_TRACE("BACKGRD MANAGE : kill the process %d (oom_adj %d)", pid, cur_oom); + kill(pid, SIGTERM); + } + else if(cur_oom >= OOMADJ_BACKGRD_UNLOCKED) { + PRT_TRACE("BACKGRD MANAGE : process %d set oom_adj %d (before %d)", pid, cur_oom+1, cur_oom); + fprintf(fp, "%d", ++cur_oom); + } + fclose(fp); + } + closedir(dp); + } + return 0; +} + +int set_active_action(int argc, char **argv) +{ + int pid = -1; + int ret = 0; + int oomadj = 0; + + if (argc < 1) + return -1; + if ((pid = atoi(argv[0])) < 0) + return -1; + + if (get_app_oomadj(pid, &oomadj) < 0) + return -1; + + switch (oomadj) { + case OOMADJ_FOREGRD_LOCKED: + case OOMADJ_BACKGRD_LOCKED: + case OOMADJ_SU: + ret = 0; + break; + case OOMADJ_FOREGRD_UNLOCKED: + ret = set_app_oomadj((pid_t) pid, OOMADJ_FOREGRD_LOCKED); + break; + case OOMADJ_BACKGRD_UNLOCKED: + ret = set_app_oomadj((pid_t) pid, OOMADJ_BACKGRD_LOCKED); + break; + case OOMADJ_INIT: + ret = set_app_oomadj((pid_t) pid, OOMADJ_BACKGRD_LOCKED); + break; + default: + if(oomadj > OOMADJ_BACKGRD_UNLOCKED) { + ret = set_app_oomadj((pid_t) pid, OOMADJ_BACKGRD_LOCKED); + } else { + PRT_TRACE_EM("Unknown oomadj value (%d) !", oomadj); + ret = -1; + } + break; + } + return ret; +} + +int set_inactive_action(int argc, char **argv) +{ + int pid = -1; + int ret = 0; + int oomadj = 0; + + if (argc < 1) + return -1; + if ((pid = atoi(argv[0])) < 0) + return -1; + + if (get_app_oomadj(pid, &oomadj) < 0) + return -1; + + switch (oomadj) { + case OOMADJ_FOREGRD_UNLOCKED: + case OOMADJ_BACKGRD_UNLOCKED: + case OOMADJ_SU: + ret = 0; + break; + case OOMADJ_FOREGRD_LOCKED: + ret = set_app_oomadj((pid_t) pid, OOMADJ_FOREGRD_UNLOCKED); + break; + case OOMADJ_BACKGRD_LOCKED: + check_and_set_old_backgrd(); + ret = set_app_oomadj((pid_t) pid, OOMADJ_BACKGRD_UNLOCKED); + break; + case OOMADJ_INIT: + check_and_set_old_backgrd(); + ret = set_app_oomadj((pid_t) pid, OOMADJ_BACKGRD_UNLOCKED); + break; + default: + if(oomadj > OOMADJ_BACKGRD_UNLOCKED) { + ret = 0; + } else { + PRT_TRACE_EM("Unknown oomadj value (%d) !", oomadj); + ret = -1; + } + break; + + } + return ret; +} + +int set_foregrd_action(int argc, char **argv) +{ + int pid = -1; + int ret = 0; + int oomadj = 0; + + if (argc < 1) + return -1; + if ((pid = atoi(argv[0])) < 0) + return -1; + + if (get_app_oomadj(pid, &oomadj) < 0) + return -1; + + switch (oomadj) { + case OOMADJ_FOREGRD_LOCKED: + case OOMADJ_FOREGRD_UNLOCKED: + case OOMADJ_SU: + ret = 0; + break; + case OOMADJ_BACKGRD_LOCKED: + ret = set_app_oomadj((pid_t) pid, OOMADJ_FOREGRD_LOCKED); + break; + case OOMADJ_BACKGRD_UNLOCKED: + ret = set_app_oomadj((pid_t) pid, OOMADJ_FOREGRD_UNLOCKED); + break; + case OOMADJ_INIT: + ret = set_app_oomadj((pid_t) pid, OOMADJ_FOREGRD_UNLOCKED); + break; + default: + if(oomadj > OOMADJ_BACKGRD_UNLOCKED) { + ret = set_app_oomadj((pid_t) pid, OOMADJ_FOREGRD_UNLOCKED); + } else { + PRT_TRACE_EM("Unknown oomadj value (%d) !", oomadj); + ret = -1; + } + break; + + } + return ret; +} + +int set_backgrd_action(int argc, char **argv) +{ + int pid = -1; + int ret = 0; + int oomadj = 0; + + if (argc < 1) + return -1; + if ((pid = atoi(argv[0])) < 0) + return -1; + + if (get_app_oomadj(pid, &oomadj) < 0) + return -1; + + switch (oomadj) { + case OOMADJ_BACKGRD_LOCKED: + case OOMADJ_BACKGRD_UNLOCKED: + case OOMADJ_SU: + ret = 0; + break; + case OOMADJ_FOREGRD_LOCKED: + ret = set_app_oomadj((pid_t) pid, OOMADJ_BACKGRD_LOCKED); + break; + case OOMADJ_FOREGRD_UNLOCKED: + check_and_set_old_backgrd(); + ret = set_app_oomadj((pid_t) pid, OOMADJ_BACKGRD_UNLOCKED); + break; + case OOMADJ_INIT: + check_and_set_old_backgrd(); + ret = set_app_oomadj((pid_t) pid, OOMADJ_BACKGRD_UNLOCKED); + break; + default: + if(oomadj > OOMADJ_BACKGRD_UNLOCKED) { + ret = 0; + } else { + PRT_TRACE_EM("Unknown oomadj value (%d) !", oomadj); + ret = -1; + } + break; + } + return ret; +} + +int ss_process_manager_init(void) +{ + ss_action_entry_add_internal(PREDEF_FOREGRD, set_foregrd_action, NULL, + NULL); + ss_action_entry_add_internal(PREDEF_BACKGRD, set_backgrd_action, NULL, + NULL); + ss_action_entry_add_internal(PREDEF_ACTIVE, set_active_action, NULL, + NULL); + ss_action_entry_add_internal(PREDEF_INACTIVE, set_inactive_action, NULL, + NULL); + ss_action_entry_add_internal(OOMADJ_SET, set_oomadj_action, NULL, NULL); + return 0; +} diff --git a/ss_procmgr.h b/ss_procmgr.h new file mode 100644 index 0000000..450b35e --- /dev/null +++ b/ss_procmgr.h @@ -0,0 +1,26 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#ifndef __SS_PROCMGR_H__ +#define __SS_PROCMGR_H__ + +int ss_process_manager_init(void); + +int get_app_oomadj(int pid, int *oomadj); +int set_app_oomadj(int pid, int new_oomadj); + +#endif /* __SS_PROCMGR_H__ */ diff --git a/ss_queue.c b/ss_queue.c new file mode 100644 index 0000000..76cd4eb --- /dev/null +++ b/ss_queue.c @@ -0,0 +1,301 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#include +#include +#include "include/ss_data.h" +#include "ss_core.h" +#include "ss_queue.h" +#include "ss_log.h" + +#define SS_PREDEFINE_ACT_FUNC_STR "ss_predefine_action" +#define SS_IS_ACCESSABLE_FUNC_STR "ss_is_accessable" +#define SS_UI_VIEWABLE_FUNC_STR "ss_ui_viewable" + +static Eina_List *predef_act_list; +static Eina_List *run_queue; + +static struct ss_action_entry *ss_action_entry_find(char *type) +{ + Eina_List *tmp; + Eina_List *tmp_next; + struct ss_action_entry *data; + + EINA_LIST_FOREACH_SAFE(predef_act_list, tmp, tmp_next, data) { + if ((data != NULL) && (!strcmp(data->type, type))) + return data; + } + + return NULL; +} + +int ss_action_entry_add_internal(char *type, + int (*predefine_action) (), + int (*ui_viewable) (), + int (*is_accessable) (int)) +{ + struct ss_action_entry *data; + + data = malloc(sizeof(struct ss_action_entry)); + + if (data == NULL) { + PRT_TRACE_ERR("Malloc failed"); + return -1; + } + + data->type = NULL; + if (ss_action_entry_find(type) != NULL) + goto err; + + data->handle = NULL; + data->predefine_action = predefine_action; + if (data->predefine_action == NULL) + goto err; + + data->is_accessable = is_accessable; + data->ui_viewable = ui_viewable; + data->owner_pid = getpid(); + data->type = strdup(type); + data->path = strdup(""); + + predef_act_list = eina_list_prepend(predef_act_list, data); + + PRT_TRACE_ERR("[SYSMAN] add predefine action entry suceessfully - %s", + data->type); + return 0; + err: + if (data->type != NULL) + PRT_TRACE_ERR("[SYSMAN] add predefine action entry -%s", + data->type); + free(data); + return -1; +} + +int ss_action_entry_add(struct sysnoti *msg) +{ + struct ss_action_entry *data; + + data = malloc(sizeof(struct ss_action_entry)); + + if (data == NULL) { + PRT_TRACE_ERR("Malloc failed"); + return -1; + } + + if (ss_action_entry_find(msg->type) != NULL) + goto err; + + data->handle = dlopen(msg->path, RTLD_LAZY); + if (!data->handle) { + PRT_TRACE_ERR("cannot find such library"); + goto err; + } + + data->predefine_action = dlsym(data->handle, SS_PREDEFINE_ACT_FUNC_STR); + if (data->predefine_action == NULL) { + PRT_TRACE_ERR("cannot find predefine_action symbol : %s", + SS_PREDEFINE_ACT_FUNC_STR); + goto err; + } + + data->is_accessable = dlsym(data->handle, SS_IS_ACCESSABLE_FUNC_STR); + data->ui_viewable = dlsym(data->handle, SS_UI_VIEWABLE_FUNC_STR); + data->owner_pid = msg->pid; + data->type = strdup(msg->type); + data->path = strdup(msg->path); + + predef_act_list = eina_list_prepend(predef_act_list, data); + + PRT_TRACE_ERR("[SYSMAN]add predefine action entry suceessfully - %s", + data->type); + return 0; + err: + PRT_TRACE_ERR("[SYSMAN] FAIL predefine action entry - %s", msg->type); + free(data); + return -1; +} + +int ss_action_entry_call_internal(char *type, int argc, ...) +{ + Eina_List *tmp; + Eina_List *tmp_next; + struct ss_action_entry *data; + va_list argptr; + int i; + char *args = NULL; + char *argv[SYSMAN_MAXARG]; + + if (argc > SYSMAN_MAXARG || type == NULL) + return -1; + + EINA_LIST_FOREACH_SAFE(predef_act_list, tmp, tmp_next, data) { + if ((data != NULL) && (!strcmp(data->type, type))) { + va_start(argptr, argc); + for (i = 0; i < argc; i++) { + args = va_arg(argptr, char *); + if (args != NULL) + argv[i] = strdup(args); + else + argv[i] = NULL; + } + va_end(argptr); + + int ret; + ret=ss_run_queue_add(data, argc, argv); + PRT_TRACE_ERR("ss_run_queue_add : %d",ret); + ret=ss_core_action_run(); + PRT_TRACE_ERR("ss_core_action_run : %d",ret); + return 0; + } + } + + return 0; +} + +int ss_action_entry_call(struct sysnoti *msg, int argc, char **argv) +{ + Eina_List *tmp; + Eina_List *tmp_next; + struct ss_action_entry *data; + + EINA_LIST_FOREACH_SAFE(predef_act_list, tmp, tmp_next, data) { + if ((data != NULL) && (!strcmp(data->type, msg->type))) { + if (data->is_accessable != NULL + && data->is_accessable(msg->pid) == 0) { + PRT_TRACE_ERR + ("%d cannot call that predefine module", + msg->pid); + return -1; + } + int ret; + ret=ss_run_queue_add(data, argc, argv); + PRT_TRACE_ERR("ss_run_queue_add : %d",ret); + ret=ss_core_action_run(); + PRT_TRACE_ERR("ss_core_action_run : %d",ret); + return 0; + } + } + + PRT_TRACE_EM("[SYSMAN] cannot found action"); + return -1; +} + +int ss_run_queue_add(struct ss_action_entry *act_entry, int argc, char **argv) +{ + struct ss_run_queue_entry *rq_entry; + int i; + + rq_entry = malloc(sizeof(struct ss_run_queue_entry)); + + if (rq_entry == NULL) { + PRT_TRACE_ERR("Malloc failed"); + return -1; + } + + rq_entry->state = SS_STATE_INIT; + rq_entry->action_entry = act_entry; + rq_entry->forked_pid = 0; + rq_entry->argc = argc; + for (i = 0; i < argc; i++) + rq_entry->argv[i] = argv[i]; + + run_queue = eina_list_prepend(run_queue, rq_entry); + + PRT_TRACE_EM("[SYSMAN] new action called : %s", act_entry->type); + return 0; +} + +int ss_run_queue_run(enum ss_run_state state, + int (*run_func) (void *, struct ss_run_queue_entry *), + void *user_data) +{ + Eina_List *tmp; + Eina_List *tmp_next; + struct ss_run_queue_entry *rq_entry; + + EINA_LIST_FOREACH_SAFE(run_queue, tmp, tmp_next, rq_entry) { + if ((rq_entry != NULL) && (rq_entry->state == state)) + run_func(user_data, rq_entry); + } + + return 0; +} + +struct ss_run_queue_entry *ss_run_queue_find_bypid(int pid) +{ + Eina_List *tmp; + Eina_List *tmp_next; + struct ss_run_queue_entry *rq_entry; + + EINA_LIST_FOREACH_SAFE(run_queue, tmp, tmp_next, rq_entry) { + if ((rq_entry != NULL) && (rq_entry->forked_pid == pid)) + return rq_entry; + } + + return NULL; +} + +int ss_run_queue_del(struct ss_run_queue_entry *entry) +{ + Eina_List *tmp; + Eina_List *tmp_next; + struct ss_run_queue_entry *rq_entry; + int i; + + EINA_LIST_FOREACH_SAFE(run_queue, tmp, tmp_next, rq_entry) { + if ((rq_entry != NULL) && (rq_entry == entry)) { + run_queue = eina_list_remove(run_queue, rq_entry); + PRT_TRACE_EM("[SYSMAN] action deleted : %s", + rq_entry->action_entry->type); + for (i = 0; i < rq_entry->argc; i++) { + if (rq_entry->argv[i]) + free(rq_entry->argv[i]); + } + free(rq_entry); + } + } + + return 0; +} + +int ss_run_queue_del_bypid(int pid) +{ + Eina_List *tmp; + Eina_List *tmp_next; + struct ss_run_queue_entry *rq_entry; + int i; + + EINA_LIST_FOREACH_SAFE(run_queue, tmp, tmp_next, rq_entry) { + if ((rq_entry != NULL) && (rq_entry->forked_pid == pid)) { + run_queue = eina_list_remove(run_queue, rq_entry); + PRT_TRACE_EM("[SYSMAN] action deleted : %s", + rq_entry->action_entry->type); + for (i = 0; i < rq_entry->argc; i++) { + if (rq_entry->argv[i]) + free(rq_entry->argv[i]); + } + free(rq_entry); + } + } + + return 0; +} + +void ss_queue_init() +{ + +} diff --git a/ss_queue.h b/ss_queue.h new file mode 100644 index 0000000..7f274e5 --- /dev/null +++ b/ss_queue.h @@ -0,0 +1,66 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#ifndef __SS_QUEUE_H__ +#define __SS_QUEUE_H__ + +#include "ss_sysnoti.h" + +struct ss_action_entry { + int owner_pid; + void *handle; + char *type; + char *path; + int (*predefine_action) (); + int (*ui_viewable) (); + int (*is_accessable) (int caller_pid); +}; + +enum ss_run_state { + SS_STATE_INIT, + SS_STATE_RUNNING, + SS_STATE_DONE +}; + +struct ss_run_queue_entry { + enum ss_run_state state; + struct ss_action_entry *action_entry; + int forked_pid; + int argc; + char *argv[SYSMAN_MAXARG]; +}; + +int ss_action_entry_add_internal(char *type, + int (*predefine_action) (), + int (*ui_viewable) (), + int (*is_accessable) (int)); +int ss_action_entry_add(struct sysnoti *msg); +int ss_action_entry_call_internal(char *type, int argc, ...); +int ss_action_entry_call(struct sysnoti *msg, int argc, char **argv); + +int ss_run_queue_run(enum ss_run_state state, + int (*run_func) (void *, struct ss_run_queue_entry *), + void *user_data); + +struct ss_run_queue_entry *ss_run_queue_find_bypid(int pid); +int ss_run_queue_add(struct ss_action_entry *act_entry, int argc, char **argv); +int ss_run_queue_del(struct ss_run_queue_entry *entry); +int ss_run_queue_del_bypid(int pid); + +void ss_queue_init(); + +#endif /* __SS_QUEUE_H__ */ diff --git a/ss_sig_handler.c b/ss_sig_handler.c new file mode 100644 index 0000000..155df8d --- /dev/null +++ b/ss_sig_handler.c @@ -0,0 +1,74 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#include +#include +#include +#include "ss_core.h" + +#define PRT_TRACE_ERR(format, args...) do { \ + char buf[255];\ + snprintf(buf, 255, format, ##args);\ + write(2, buf, strlen(buf));\ +} while (0); + +#define PRT_TRACE(format, args...) do { \ + char buf[255];\ + snprintf(buf, 255, format, ##args);\ + write(1, buf, strlen(buf));\ +} while (0); + +static struct sigaction sig_child_old_act; +static struct sigaction sig_pipe_old_act; + +static void sig_child_handler(int signo, siginfo_t *info, void *data) +{ + pid_t pid; + int status; + + pid = waitpid(info->si_pid, &status, 0); + if (pid == -1) { + PRT_TRACE_ERR("SIGCHLD received\n"); + return; + } + + PRT_TRACE("sig child actend call - %d\n", info->si_pid); + + ss_core_action_clear(info->si_pid); +} + +static void sig_pipe_handler(int signo, siginfo_t *info, void *data) +{ + +} + +void ss_signal_init() +{ + struct sigaction sig_act; + + sig_act.sa_handler = NULL; + sig_act.sa_sigaction = sig_child_handler; + sig_act.sa_flags = SA_SIGINFO; + sigemptyset(&sig_act.sa_mask); + sigaction(SIGCHLD, &sig_act, &sig_child_old_act); + + sig_act.sa_handler = NULL; + sig_act.sa_sigaction = sig_pipe_handler; + sig_act.sa_flags = SA_SIGINFO; + sigemptyset(&sig_act.sa_mask); + sigaction(SIGPIPE, &sig_act, &sig_pipe_old_act); +} diff --git a/ss_sig_handler.h b/ss_sig_handler.h new file mode 100644 index 0000000..340a8be --- /dev/null +++ b/ss_sig_handler.h @@ -0,0 +1,23 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#ifndef __SS_SIG_HANDLER_H__ +#define __SS_SIG_HANDLER_H__ + +void ss_signal_init(void); + +#endif /* __SS_SIG_HANDLER_H__ */ diff --git a/ss_sysnoti.c b/ss_sysnoti.c new file mode 100644 index 0000000..0d404ea --- /dev/null +++ b/ss_sysnoti.c @@ -0,0 +1,277 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#include +#include +#include +#include +#include +#include +#include "include/ss_data.h" +#include "ss_log.h" +#include "ss_queue.h" + +#define SYSNOTI_SOCKET_PATH "/tmp/sn" + +enum sysnoti_cmd { + ADD_SYSMAN_ACTION, + CALL_SYSMAN_ACTION +}; + +static void print_sysnoti_msg(const char *title, struct sysnoti *msg) +{ + int i; + char exe_name[PATH_MAX]; + + if (sysman_get_cmdline_name(msg->pid, exe_name, PATH_MAX) < 0) + snprintf(exe_name, sizeof(exe_name), "Unknown (maybe dead)"); + + PRT_TRACE_ERR("====================="); + PRT_TRACE_ERR("pid : %d", msg->pid); + PRT_TRACE_ERR("process name : %s", exe_name); + PRT_TRACE_ERR("cmd : %d", msg->cmd); + PRT_TRACE_ERR("type : %s", msg->type); + PRT_TRACE_ERR("path : %s", msg->path); + for (i = 0; i < msg->argc; i++) + PRT_TRACE_ERR("arg%d : %s", i, msg->argv[i]); + PRT_TRACE_ERR("====================="); +} + +static inline int recv_int(int fd) +{ + int val, r = -1; + while(1) { + r = read(fd, &val, sizeof(int)); + if (r < 0) { + if(errno == EINTR) { + PRT_TRACE_ERR("Re-read for error(EINTR)"); + continue; + } + else { + PRT_TRACE_ERR("Read fail for int"); + return -1; + } + } else { + return val; + } + } +} + +static inline char *recv_str(int fd) +{ + int len, r = -1; + char *str; + + while(1) { + r = read(fd, &len, sizeof(int)); + if (r < 0) { + if(errno == EINTR) { + PRT_TRACE_ERR("Re-read for error(EINTR)"); + continue; + } + else { + PRT_TRACE_ERR("Read fail for str length"); + return NULL; + } + } else + break; + } + + if (len <= 0) { + PRT_TRACE_ERR("str is null"); + return NULL; + } + + if (len >= INT_MAX) { + PRT_TRACE_ERR("size is over INT_MAX"); + return NULL; + } + + str = (char *)malloc(len + 1); + if (str == NULL) { + PRT_TRACE_ERR("Not enough memory"); + return NULL; + } + + while(1) { + r = read(fd, str, len); + if(r < 0) { + if(errno == EINTR) { + PRT_TRACE_ERR("Re-read for error(EINTR)"); + continue; + } + else { + PRT_TRACE_ERR("Read fail for str"); + return NULL; + } + } else + break; + } + str[len] = 0; + + return str; +} + +static int read_message(int fd, struct sysnoti *msg) +{ + int i; + + msg->pid = recv_int(fd); + msg->cmd = recv_int(fd); + msg->type = recv_str(fd); + msg->path = recv_str(fd); + msg->argc = recv_int(fd); + + for (i = 0; i < msg->argc; i++) + msg->argv[i] = recv_str(fd); + + return 0; +} + +static inline void internal_free(char *str) +{ + if (!str) + free(str); +} + +static inline void free_message(struct sysnoti *msg) +{ + internal_free(msg->type); + internal_free(msg->path); + free(msg); +} + +static int sysnoti_cb(void *data, Ecore_Fd_Handler * fd_handler) +{ + int fd; + struct sysnoti *msg; + int ret = -1; + struct sockaddr_un client_address; + int client_sockfd; + int client_len; + + if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) { + PRT_TRACE_ERR + ("ecore_main_fd_handler_active_get error , return\n"); + return 1; + } + + fd = ecore_main_fd_handler_fd_get(fd_handler); + + msg = malloc(sizeof(struct sysnoti)); + if (msg == NULL) { + PRT_TRACE_ERR("%s : Not enough memory", __FUNCTION__); + return 1; + } + + client_len = sizeof(client_address); + client_sockfd = + accept(fd, (struct sockaddr *)&client_address, + (socklen_t *)&client_len); + if(client_sockfd == -1) { + PRT_TRACE_ERR("socket accept error"); + return 1; + } + + if (read_message(client_sockfd, msg) < 0) { + PRT_TRACE_ERR("%s : recv error msg", __FUNCTION__); + free(msg); + write(client_sockfd, &ret, sizeof(int)); + close(client_sockfd); + return 1; + } + + print_sysnoti_msg(__FUNCTION__, msg); + if (msg->argc > SYSMAN_MAXARG) { + PRT_TRACE_ERR("%s : error argument", __FUNCTION__); + free_message(msg); + write(client_sockfd, &ret, sizeof(int)); + close(client_sockfd); + return 1; + } + + switch (msg->cmd) { + case CALL_SYSMAN_ACTION: + ret = ss_action_entry_call(msg, msg->argc, msg->argv); + break; + default: + ret = -1; + } + + write(client_sockfd, &ret, sizeof(int)); + close(client_sockfd); + + free_message(msg); + + return 1; +} + +static int ss_sysnoti_server_init(void) +{ + int fd; + struct sockaddr_un serveraddr; + + if (access(SYSNOTI_SOCKET_PATH, F_OK) == 0) + unlink(SYSNOTI_SOCKET_PATH); + + fd = socket(AF_UNIX, SOCK_STREAM, 0); + if (fd < 0) { + PRT_ERR("%s: socket create failed\n", __FUNCTION__); + return -1; + } + + if((fsetxattr(fd, "security.SMACK64IPOUT", "@", 2, 0)) < 0 ) { + PRT_ERR("%s: Socket SMACK labeling failed\n", __FUNCTION__); + if(errno != EOPNOTSUPP) + return -1; + } + + if((fsetxattr(fd, "security.SMACK64IPIN", "*", 2, 0)) < 0 ) { + PRT_ERR("%s: Socket SMACK labeling failed\n", __FUNCTION__); + if(errno != EOPNOTSUPP) + return -1; + } + + bzero(&serveraddr, sizeof(struct sockaddr_un)); + serveraddr.sun_family = AF_UNIX; + strncpy(serveraddr.sun_path, SYSNOTI_SOCKET_PATH, + sizeof(serveraddr.sun_path)); + + if (bind(fd, (struct sockaddr *)&serveraddr, sizeof(struct sockaddr)) < + 0) { + PRT_ERR("%s: socket bind failed\n", __FUNCTION__); + return -1; + } + + if (chmod(SYSNOTI_SOCKET_PATH, (S_IRWXU | S_IRWXG | S_IRWXO)) < 0) /* 0777 */ + PRT_ERR("failed to change the socket permission"); + + listen(fd, 5); + + PRT_INFO("socket create & listen ok\n"); + + return fd; +} + +int ss_sysnoti_init(void) +{ + int fd; + fd = ss_sysnoti_server_init(); + ecore_main_fd_handler_add(fd, ECORE_FD_READ, sysnoti_cb, NULL, NULL, + NULL); + return fd; +} diff --git a/ss_sysnoti.h b/ss_sysnoti.h new file mode 100644 index 0000000..432392e --- /dev/null +++ b/ss_sysnoti.h @@ -0,0 +1,34 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#ifndef __SS_SYSNOTI_H__ +#define __SS_SYSNOTI_H__ + +#define SYSMAN_MAXARG 16 + +struct sysnoti { + int pid; + int cmd; + char *type; + char *path; + int argc; + char *argv[SYSMAN_MAXARG]; +}; + +int ss_sysnoti_init(void); + +#endif /* __SS_SYSNOTI_H__ */ diff --git a/ss_ta_handler.c b/ss_ta_handler.c new file mode 100644 index 0000000..03560e8 --- /dev/null +++ b/ss_ta_handler.c @@ -0,0 +1,45 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#include +#include +#include + +#include "ss_device_plugin.h" +#include "ss_log.h" +#include "include/ss_data.h" + +#define RETRY 3 + +int ss_ta_init() +{ + int val = -1, i = 0, pid; + + PRT_TRACE("check ta connection"); + if (plugin_intf->OEM_sys_get_jack_charger_online(&val) == 0) { + if (val==1) { + while (i < RETRY + && pm_lock_state(LCD_OFF, STAY_CUR_STATE, + 0) == -1) { + i++; + sleep(1); + } + PRT_TRACE("ta is connected"); + } + } + return 0; +} diff --git a/ss_timemgr.c b/ss_timemgr.c new file mode 100644 index 0000000..1cb3b12 --- /dev/null +++ b/ss_timemgr.c @@ -0,0 +1,162 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "include/ss_data.h" +#include "ss_queue.h" +#include "ss_log.h" + +#include +#include +#include +#include + +#include + +static const char default_rtc0[] = "/dev/rtc0"; +static const char default_rtc1[] = "/dev/rtc1"; +static const char default_localtime[] = "/opt/etc/localtime"; + +char *substring(const char *str, size_t begin, size_t len) +{ + if (str == 0 || strlen(str) == 0 || strlen(str) < begin + || strlen(str) < (begin + len)) + return 0; + + return strndup(str + begin, len); +} + +int handle_timezone(char *str) +{ + int ret; + struct stat sts; + const char *sympath = default_localtime; + + if (str == NULL) + return -1; + const char *tzpath = str; + + PRT_TRACE("TZPATH = %s\n", tzpath); + + /* unlink current link + * eg. rm /opt/etc/localtime */ + if (stat(sympath, &sts) == -1 && errno == ENOENT) { + /* DO NOTHING */ + } else { + ret = unlink(sympath); + if (ret < 0) { + PRT_TRACE("unlink error : [%d]%s\n", ret, + strerror(errno)); + return -1; + } else + PRT_TRACE("unlink success\n"); + + } + + /* symlink new link + * eg. ln -s /usr/share/zoneinfo/Asia/Seoul /opt/etc/localtime */ + ret = symlink(tzpath, sympath); + if (ret < 0) { + PRT_TRACE("symlink error : [%d]%s\n", ret, strerror(errno)); + return -1; + } else + PRT_TRACE("symlink success\n"); + + tzset(); + return 0; +} + +/* + * TODO : error handling code should be added here. + */ +int handle_date(char *str) +{ + long int tmp = 0; + time_t timet = 0; + time_t before = 0; + + if (str == NULL) + return -1; + + tmp = (long int)atoi(str); + timet = (time_t) tmp; + + PRT_TRACE("ctime = %s", ctime(&timet)); + vconf_set_int(VCONFKEY_SYSTEM_TIMECHANGE, timet); + + return 0; +} + +int set_datetime_action(int argc, char **argv) +{ + int ret = 0; + unsigned int pm_state; + if (argc < 1) + return -1; + if (vconf_get_int(VCONFKEY_PM_STATE, &ret) != 0) + PRT_TRACE("Fail to get vconf value for pm state\n"); + if (ret == 1) + pm_state = 0x1; + else if (ret == 2) + pm_state = 0x2; + else + pm_state = 0x4; + + pm_lock_state(pm_state, STAY_CUR_STATE, 0); + ret = handle_date(argv[0]); + pm_unlock_state(pm_state, STAY_CUR_STATE); + return ret; +} + +int set_timezone_action(int argc, char **argv) +{ + int ret; + unsigned int pm_state; + if (argc < 1) + return -1; + if (vconf_get_int(VCONFKEY_PM_STATE, &ret) != 0) + PRT_TRACE("Fail to get vconf value for pm state\n"); + if (ret == 1) + pm_state = 0x1; + else if (ret == 2) + pm_state = 0x2; + else + pm_state = 0x4; + + pm_lock_state(pm_state, STAY_CUR_STATE, 0); + ret = handle_timezone(argv[0]); + pm_unlock_state(pm_state, STAY_CUR_STATE); + return ret; +} + +int ss_time_manager_init(void) +{ + ss_action_entry_add_internal(PREDEF_SET_DATETIME, set_datetime_action, + NULL, NULL); + ss_action_entry_add_internal(PREDEF_SET_TIMEZONE, set_timezone_action, + NULL, NULL); + return 0; +} diff --git a/ss_timemgr.h b/ss_timemgr.h new file mode 100644 index 0000000..1a2e28c --- /dev/null +++ b/ss_timemgr.h @@ -0,0 +1,23 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#ifndef __SS_TIMEMGR_H__ +#define __SS_TIMEMGR_H__ + +int ss_time_manager_init(void); + +#endif /* __SS_TIMEMGR_H__ */ diff --git a/ss_usb_handler.c b/ss_usb_handler.c new file mode 100644 index 0000000..94a61af --- /dev/null +++ b/ss_usb_handler.c @@ -0,0 +1,54 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#include +#include +#include + +#include "ss_log.h" +#include "ss_device_plugin.h" +#include "ss_launch.h" +#include "include/ss_data.h" + +#define USBCON_EXEC_PATH PREFIX"/bin/usb_setting" +#define RETRY 3 + +int ss_usb_init() +{ + int val = -1, i = 0, pid; + + PRT_TRACE("check usb connection"); + if (plugin_intf->OEM_sys_get_jack_usb_online(&val) == 0) { + if (val) { + vconf_set_int(VCONFKEY_SYSMAN_USB_STATUS, + VCONFKEY_SYSMAN_USB_AVAILABLE); + while (i < RETRY + && pm_lock_state(LCD_OFF, STAY_CUR_STATE, + 0) == -1) { + i++; + sleep(1); + } + pid = ss_launch_if_noexist(USBCON_EXEC_PATH, NULL); + if (pid < 0) { + PRT_TRACE_ERR("usb appl launching failed\n"); + return -1; + } + } + } + + return 0; +} diff --git a/ss_usb_storage_handler.c b/ss_usb_storage_handler.c new file mode 100644 index 0000000..d7c443c --- /dev/null +++ b/ss_usb_storage_handler.c @@ -0,0 +1,265 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ss_device_handler.h" +#include "ss_log.h" + +#define BUF_MAX 512 + +#define FS_TYPE_CHECKER "/sbin/fs-type-checker" +#define TEMP_FILE "/tmp/mountd.tmp" +#define MTAB_FILE "/etc/mtab" +#define MOUNT_POINT "/opt/storage/usb" + +static int added_noti_value = 0; +static int removed_noti_value = 0; + +static int __ss_mount_device(char *dev) +{ + if (access(dev, F_OK) != 0) { + PRT_TRACE_ERR("Failed to find device: DEVICE(%s)", dev); + return -1; + } + + int fd = -1; + int r = -1; + char *rel_mnt_point; + char buf_mnt_point[BUF_MAX]; + + rel_mnt_point = strrchr(dev, '/'); + if (rel_mnt_point == NULL) { + PRT_TRACE_ERR("Get Relative Mount Path Failed"); + return -1; + } + + snprintf(buf_mnt_point, BUF_MAX, "%s%s", MOUNT_POINT, rel_mnt_point); + + /* Make directory to mount */ + r = mkdir(buf_mnt_point, 0755); + if (r < 0) { + if (errno == EEXIST) { + PRT_TRACE("Directory is already exsited: PATH(%s)", buf_mnt_point); + } else { + PRT_TRACE_ERR("Make Directory Failed: PATH(%s)", buf_mnt_point); + return -1; + } + } + + /* Mount block device on mount point */ + r = mount(dev, buf_mnt_point, "vfat", 0, "uid=0,gid=0,dmask=0000,fmask=0111,iocharset=iso8859-1,utf8,shortname=mixed"); + if (r < 0) { + r = rmdir(buf_mnt_point); + PRT_TRACE_ERR("Mount failed: MOUNT PATH(%s", buf_mnt_point); + return -1; + } + PRT_TRACE("Mount Complete: MOUNT PATH(%s)", buf_mnt_point); + + return 0; +} + +static int __ss_unmount_device(char *mnt_point) +{ + if (access(mnt_point, F_OK) != 0) { + PRT_TRACE_ERR("Failed to find path: MOUNT PATH(%s)", mnt_point); + return -1; + } + + int r = -1; + + /* Umount block device */ + r = umount2(mnt_point, MNT_DETACH); + if (r < 0) { + PRT_TRACE_ERR("Unmounting is unabled: MOUNT PATH(%s)", mnt_point); + r = rmdir(mnt_point); + if (r < 0) { + PRT_TRACE_ERR("Removing Directory is unabled: PATH(%s)", mnt_point); + } + return -1; + } + + /* Clean up unmounted directory */ + r = rmdir(mnt_point); + if (r < 0) { + PRT_TRACE_ERR("Removing Directory is unabled: PATH(%s)", mnt_point); + } + PRT_TRACE("Unmount/Remove Complete: MOUNT PATH(%s)", mnt_point); + + return 0; +} + +static int __ss_usb_storage_added(int argc, char *argv[]) +{ + if (argc != 1 || argv[0] == NULL) { + PRT_TRACE_ERR("Get Vconf Value Failed: KEY(%s)", VCONFKEY_SYSMAN_ADDED_USB_STORAGE); + return -1; + } + + int fd = -1; + int part_num = 0; + + char *buf_dev = argv[0]; + char buf_part_dev[BUF_MAX]; + char *disk_path; + char *mounted_check; + + /* Check whether mount point directory is exist */ + if (access(MOUNT_POINT, F_OK) < 0) { + if (mkdir(MOUNT_POINT, 0755) < 0) { + PRT_TRACE_ERR("Make Mount Directory Failed: DIRECTORY(%s)", MOUNT_POINT); + return -1; + } + } + + /* Mount tmpfs for protecting user data */ + if (mount("tmpfs", MOUNT_POINT, "tmpfs", 0, "") < 0) { + if (errno != EBUSY) { + PRT_TRACE_ERR("Failed to mount USB Storage Mount Directory: DIRECTORY(%s)", MOUNT_POINT); + return -1; + } + } + + /* Change permission to avoid to write user data on tmpfs */ + if (chmod(MOUNT_POINT, 0755) < 0) { + PRT_TRACE_ERR("Failed to change mode: DIRCTORY(%s)", MOUNT_POINT); + return -1; + } + + /* Mount a single partition storage device */ + if (__ss_mount_device(buf_dev) < 0) { + /* Mount a multi partition storage device */ + for (part_num = 1; part_num < 10; part_num++) { + snprintf(buf_part_dev, BUF_MAX, "%s%d", buf_dev, part_num); + if (__ss_mount_device(buf_part_dev) < 0) { + PRT_TRACE("Mounting partition is unabled: PARTITION(%s)", buf_part_dev); + continue; + } + } + } + + FILE *file = setmntent(MTAB_FILE, "r"); + struct mntent *mnt_entry; + + /* Check whether block deivce is mounted */ + while (mnt_entry = getmntent(file)) { + mounted_check = strstr(mnt_entry->mnt_fsname, buf_dev); + if (mounted_check != NULL) { + if (added_noti_value < INT_MAX) { + ++added_noti_value; + } else { + added_noti_value = 1; + } + /* Broadcast mounting notification */ + if (vconf_set_int(VCONFKEY_SYSMAN_ADDED_USB_STORAGE, added_noti_value) < 0) { + PRT_TRACE_ERR("Setting vconf value is failed: KEY(%s)", VCONFKEY_SYSMAN_ADDED_USB_STORAGE); + vconf_set_int(VCONFKEY_SYSMAN_ADDED_USB_STORAGE, -1); + } + + PRT_TRACE("Setting vconf value: KEY(%s) DEVICE(%s)", VCONFKEY_SYSMAN_ADDED_USB_STORAGE, buf_dev); + fclose(file); + return 0; + } + } + + /* Failed to mount storage device */ + PRT_TRACE_ERR("Nothing to be mounted: DEVICE(%s)", buf_dev); + fclose(file); + return -1; +} + +static int __ss_usb_storage_removed(int argc, char *argv[]) +{ + if (argc != 1 || argv[0] == NULL) { + PRT_TRACE_ERR("Get Vonf Value Failed: KEY(%s)", VCONFKEY_SYSMAN_REMOVED_USB_STORAGE); + return -1; + } + + int fd = -1; + int part_num = 0; + + char *buf_dev_name = argv[0]; + char buf_mnt_point[BUF_MAX]; + char *mounted_check; + + snprintf(buf_mnt_point, BUF_MAX, "%s/%s", MOUNT_POINT, buf_dev_name); + + if (__ss_unmount_device(buf_mnt_point) == 0) { + umount2(MOUNT_POINT, MNT_DETACH); + + if (removed_noti_value < INT_MAX) { + ++removed_noti_value; + } else { + removed_noti_value = 1; + } + if (vconf_set_int(VCONFKEY_SYSMAN_REMOVED_USB_STORAGE, removed_noti_value) < 0) { + PRT_TRACE_ERR("Setting vconf value is failed: KEY(%s)", VCONFKEY_SYSMAN_REMOVED_USB_STORAGE); + vconf_set_int(VCONFKEY_SYSMAN_ADDED_USB_STORAGE, -1); + } + + PRT_TRACE("Setting vconf value: KEY(%s) DEVICE(%s)", VCONFKEY_SYSMAN_REMOVED_USB_STORAGE, buf_dev_name); + return 0; + } + + FILE *file = setmntent(MTAB_FILE, "r"); + struct mntent *mnt_entry; + + while (mnt_entry = getmntent(file)) { + mounted_check = strstr(mnt_entry->mnt_dir, buf_mnt_point); + if (mounted_check != NULL) { + if (__ss_unmount_device(mnt_entry->mnt_dir) < 0) { + PRT_TRACE_ERR("Unmount Failed: MOUNT PATH(%s)", mnt_entry->mnt_dir); + } + PRT_TRACE("Unmount Success: MOUNT PATH(%s)", mnt_entry->mnt_dir); + } + } + fclose(file); + + umount2(MOUNT_POINT, MNT_DETACH); + + if (removed_noti_value < INT_MAX) { + ++removed_noti_value; + } else { + removed_noti_value = 1; + } + if (vconf_set_int(VCONFKEY_SYSMAN_REMOVED_USB_STORAGE, removed_noti_value) < 0) { + PRT_TRACE_ERR("Setting vconf value is failed: KEY(%s)", VCONFKEY_SYSMAN_REMOVED_USB_STORAGE); + vconf_set_int(VCONFKEY_SYSMAN_ADDED_USB_STORAGE, -1); + } + + PRT_TRACE("Setting vconf value: KEY(%s) DEVICE(%s)", VCONFKEY_SYSMAN_REMOVED_USB_STORAGE, buf_dev_name); + return 0; +} + +int _ss_usb_storage_init() +{ + ss_action_entry_add_internal(PREDEF_USB_STORAGE_ADD, __ss_usb_storage_added, NULL, NULL); + ss_action_entry_add_internal(PREDEF_USB_STORAGE_REMOVE, __ss_usb_storage_removed, NULL, NULL); + + return 0; +} + diff --git a/sys_event/CMakeLists.txt b/sys_event/CMakeLists.txt new file mode 100644 index 0000000..f41228f --- /dev/null +++ b/sys_event/CMakeLists.txt @@ -0,0 +1,31 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(sys_event C) + +SET(SRCS sys_event.c) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED heynoti) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions") + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +MESSAGE("FLAGS: ${CMAKE_C_FLAGS}") + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DFACTORYFS=\"$ENV{FACTORYFS}\"") +IF( $ENV{ARCH} MATCHES "arm" ) + ADD_DEFINITIONS("-DTARGET") +ENDIF() +ADD_DEFINITIONS("-DSLP_DEBUG") +ADD_DEFINITIONS("-DSLP_PROF") + +ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS}) + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) + diff --git a/sys_event/sys_event.c b/sys_event/sys_event.c new file mode 100644 index 0000000..19bec4a --- /dev/null +++ b/sys_event/sys_event.c @@ -0,0 +1,30 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. +*/ + + +#include +#include + +int main(int argc, char **argv) +{ + if (argc != 2) { + printf("[usage] sys_event \n"); + return -1; + } + + heynoti_publish(argv[1]); + return 0; +} diff --git a/system_server.sh b/system_server.sh new file mode 100755 index 0000000..3db1e64 --- /dev/null +++ b/system_server.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +/usr/bin/system_server & diff --git a/udev-rules/91-system-server.rules.in b/udev-rules/91-system-server.rules.in new file mode 100644 index 0000000..b1e15ea --- /dev/null +++ b/udev-rules/91-system-server.rules.in @@ -0,0 +1,27 @@ +#MMC +ACTION=="add", KERNEL=="mmcblk[0-9]", SUBSYSTEM=="block", RUN+="@PREFIX@/bin/sys_event mmcblk_add" +ACTION=="remove", KERNEL=="mmcblk[0-9]", SUBSYSTEM=="block", RUN+="@PREFIX@/bin/sys_event mmcblk_remove" + +#Process Monitor +#ACTION=="change" SUBSYSTEM=="pmon", RUN+="@PREFIX@/bin/restart" + +#Jack +ACTION=="change" DEVPATH=="/devices/platform/jack", ENV{CHGDET}=="usb" RUN+="@PREFIX@/bin/sys_event device_usb_chgdet" +ACTION=="change" DEVPATH=="/devices/platform/jack", ENV{CHGDET}=="charger" RUN+="@PREFIX@/bin/sys_event device_ta_chgdet" +ACTION=="change" DEVPATH=="/devices/platform/jack", ENV{CHGDET}=="earjack" RUN+="@PREFIX@/bin/sys_event device_earjack_chgdet" +ACTION=="change" DEVPATH=="/devices/platform/jack", ENV{CHGDET}=="earkey" RUN+="@PREFIX@/bin/sys_event device_earkey_chgdet" +ACTION=="change" DEVPATH=="/devices/platform/jack", ENV{CHGDET}=="tvout" RUN+="@PREFIX@/bin/sys_event device_tvout_chgdet" +ACTION=="change" DEVPATH=="/devices/platform/jack", ENV{CHGDET}=="hdmi" RUN+="@PREFIX@/bin/sys_event device_hdmi_chgdet" +ACTION=="change" DEVPATH=="/devices/platform/jack", ENV{CHGDET}=="cdrom" RUN+="@PREFIX@/bin/start_composite.sh" +ACTION=="change" DEVPATH=="/devices/platform/jack", ENV{CHGDET}=="cradle" RUN+="@PREFIX@/bin/sys_event device_cradle_chgdet" + +#USB Host Device +ACTION=="add", SUBSYSTEM=="host_notify", RUN+="@PREFIX@/bin/vconftool set -t int memory/Device/usbhost/status 1" +ACTION=="remove", SUBSYSTEM=="host_notify", RUN+="@PREFIX@/bin/vconftool set -t int memory/Device/usbhost/status 0" + +#USB Storage +ACTION=="add", KERNEL=="sd[a-z]", SUBSYSTEM=="block", RUN+="@PREFIX@/bin/vconftool set -t string memory/Device/usbhost/added_storage_uevent %N" +ACTION=="remove", KERNEL=="sd[a-z]", SUBSYSTEM=="block", RUN+="@PREFIX@/bin/vconftool set -t string memory/Device/usbhost/removed_storage_uevent $name" + +#charge +ACTION=="change" DEVPATH=="/devices/platform/charger-manager.0" RUN+="@PREFIX@/bin/sys_event device_charge_chgdet" -- 2.7.4